2023-11-14 01:20:34 +00:00
|
|
|
#!powershell
|
|
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
|
function init_vars {
|
|
|
|
$script:patches = @("0001-Expose-callable-API-for-server.patch")
|
2023-12-20 22:46:15 +00:00
|
|
|
$script:cmakeDefs = @("-DBUILD_SHARED_LIBS=on", "-DLLAMA_NATIVE=off", "-DLLAMA_F16C=off", "-DLLAMA_FMA=off", "-DLLAMA_AVX512=off", "-DLLAMA_AVX2=off", "-DLLAMA_AVX=on", "-DLLAMA_K_QUANTS=on", "-DLLAMA_ACCELERATE=on", "-A","x64")
|
2023-11-14 01:20:34 +00:00
|
|
|
|
|
|
|
if ($env:CGO_CFLAGS -contains "-g") {
|
2023-12-22 16:47:18 +00:00
|
|
|
$script:cmakeDefs += @("-DCMAKE_VERBOSE_MAKEFILE=on", "-DLLAMA_SERVER_VERBOSE=on")
|
2023-12-20 22:46:15 +00:00
|
|
|
$script:config = "RelWithDebInfo"
|
2023-11-14 01:20:34 +00:00
|
|
|
} else {
|
2023-12-22 16:47:18 +00:00
|
|
|
$script:cmakeDefs += @("-DLLAMA_SERVER_VERBOSE=off")
|
2023-12-20 22:46:15 +00:00
|
|
|
$script:config = "Release"
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function git_module_setup {
|
|
|
|
# TODO add flags to skip the init/patch logic to make it easier to mod llama.cpp code in-repo
|
|
|
|
& git submodule init
|
2023-12-20 22:46:15 +00:00
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
2023-11-14 01:20:34 +00:00
|
|
|
& git submodule update --force gguf
|
2023-12-20 22:46:15 +00:00
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function apply_patches {
|
|
|
|
rm -erroraction ignore -path "gguf/examples/server/server.h"
|
2023-12-20 22:46:15 +00:00
|
|
|
foreach ($patch in $script:patches) {
|
2023-11-14 01:20:34 +00:00
|
|
|
write-host "Applying patch $patch"
|
|
|
|
& git -C gguf apply ../patches/$patch
|
2023-12-20 22:46:15 +00:00
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function build {
|
2023-12-20 22:46:15 +00:00
|
|
|
write-host "generating config with: cmake -S gguf -B $script:buildDir $script:cmakeDefs"
|
2023-11-14 01:20:34 +00:00
|
|
|
& cmake --version
|
2023-12-20 22:46:15 +00:00
|
|
|
& cmake -S gguf -B $script:buildDir $script:cmakeDefs
|
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
|
|
|
write-host "building with: cmake --build $script:buildDir --config $script:config"
|
|
|
|
& cmake --build $script:buildDir --config $script:config
|
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function install {
|
2023-12-20 22:46:15 +00:00
|
|
|
rm -erroraction ignore -recurse -force -path $script:installDir
|
|
|
|
& cmake --install $script:buildDir --prefix $script:installDir --config $script:config
|
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
2023-11-14 01:20:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
init_vars
|
|
|
|
git_module_setup
|
|
|
|
apply_patches
|
2023-12-20 22:46:15 +00:00
|
|
|
|
|
|
|
# first build CPU based
|
|
|
|
$script:buildDir="gguf/build/wincpu"
|
|
|
|
$script:installDir="gguf/build/wincpu/dist"
|
|
|
|
|
|
|
|
build
|
|
|
|
# install
|
|
|
|
|
|
|
|
md gguf/build/lib -ea 0
|
|
|
|
md gguf/build/wincpu/dist/lib -ea 0
|
|
|
|
mv gguf/build/wincpu/bin/$script:config/ext_server_shared.dll gguf/build/wincpu/dist/lib/cpu_server.dll
|
|
|
|
|
|
|
|
|
|
|
|
# Nope, this barfs on lots of symbol problems
|
|
|
|
#mv gguf/build/wincpu/examples/server/$script:config/ext_server_shared.dll gguf/build/wincpu/dist/lib/cpu_server.lib
|
|
|
|
# Nope: this needs lots of include paths to pull in things like msvcprt.lib and other deps
|
|
|
|
# & cl.exe `
|
|
|
|
# gguf/build/wincpu/examples/server/$script:config/ext_server.lib `
|
|
|
|
# gguf/build/wincpu/common/$script:config/common.lib `
|
|
|
|
# gguf/build/wincpu/$script:config/llama.lib `
|
|
|
|
# gguf/build/wincpu/$script:config/ggml_static.lib `
|
|
|
|
# /link /DLL /DEF:cpu_server.def /NOENTRY /MACHINE:X64 /OUT:gguf/build/wincpu/dist/lib/cpu_server.dll
|
|
|
|
# if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
|
|
|
|
|
|
|
# Then build cuda as a dynamically loaded library
|
|
|
|
init_vars
|
|
|
|
$script:buildDir="gguf/build/wincuda"
|
|
|
|
$script:installDir="gguf/build/wincuda/dist"
|
|
|
|
$script:cmakeDefs += @("-DLLAMA_CUBLAS=ON", "-DBUILD_SHARED_LIBS=on")
|
2023-11-14 01:20:34 +00:00
|
|
|
build
|
2023-11-29 19:00:37 +00:00
|
|
|
install
|
2023-12-20 22:46:15 +00:00
|
|
|
cp gguf/build/wincuda/dist/bin/ext_server_shared.dll gguf/build/lib/cuda_server.dll
|
|
|
|
|
|
|
|
# TODO - more to do here to create a usable dll
|
|
|
|
|
2023-11-29 19:00:37 +00:00
|
|
|
|
|
|
|
# TODO - implement ROCm support on windows
|
|
|
|
md gguf/build/winrocm/lib -ea 0
|
|
|
|
echo $null >> gguf/build/winrocm/lib/.generated
|