Refactor windows generate for more modular usage
This commit is contained in:
parent
2619850fb4
commit
8671fdeda6
1 changed files with 180 additions and 140 deletions
|
@ -26,14 +26,20 @@ function amdGPUs {
|
||||||
$GPU_LIST -join ';'
|
$GPU_LIST -join ';'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$script:cmakeTargets = @("ollama_llama_server")
|
||||||
|
|
||||||
function init_vars {
|
function init_vars {
|
||||||
|
if (!$script:SRC_DIR) {
|
||||||
$script:SRC_DIR = $(resolve-path "..\..\")
|
$script:SRC_DIR = $(resolve-path "..\..\")
|
||||||
|
}
|
||||||
|
if (!$script:llamacppDir) {
|
||||||
$script:llamacppDir = "../llama.cpp"
|
$script:llamacppDir = "../llama.cpp"
|
||||||
|
}
|
||||||
$script:cmakeDefs = @(
|
$script:cmakeDefs = @(
|
||||||
"-DBUILD_SHARED_LIBS=on",
|
"-DBUILD_SHARED_LIBS=on",
|
||||||
"-DLLAMA_NATIVE=off"
|
"-DLLAMA_NATIVE=off"
|
||||||
)
|
)
|
||||||
$script:cmakeTargets = @("ollama_llama_server")
|
$script:commonCpuDefs = @("-DCMAKE_POSITION_INDEPENDENT_CODE=on")
|
||||||
$script:ARCH = "amd64" # arm not yet supported.
|
$script:ARCH = "amd64" # arm not yet supported.
|
||||||
$script:DIST_BASE = "${script:SRC_DIR}\dist\windows-${script:ARCH}\ollama_runners"
|
$script:DIST_BASE = "${script:SRC_DIR}\dist\windows-${script:ARCH}\ollama_runners"
|
||||||
if ($env:CGO_CFLAGS -contains "-g") {
|
if ($env:CGO_CFLAGS -contains "-g") {
|
||||||
|
@ -166,18 +172,14 @@ function cleanup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init_vars
|
|
||||||
git_module_setup
|
|
||||||
apply_patches
|
|
||||||
|
|
||||||
# -DLLAMA_AVX -- 2011 Intel Sandy Bridge & AMD Bulldozer
|
# -DLLAMA_AVX -- 2011 Intel Sandy Bridge & AMD Bulldozer
|
||||||
# -DLLAMA_AVX2 -- 2013 Intel Haswell & 2015 AMD Excavator / 2017 AMD Zen
|
# -DLLAMA_AVX2 -- 2013 Intel Haswell & 2015 AMD Excavator / 2017 AMD Zen
|
||||||
# -DLLAMA_FMA (FMA3) -- 2013 Intel Haswell & 2012 AMD Piledriver
|
# -DLLAMA_FMA (FMA3) -- 2013 Intel Haswell & 2012 AMD Piledriver
|
||||||
|
|
||||||
$script:commonCpuDefs = @("-DCMAKE_POSITION_INDEPENDENT_CODE=on")
|
|
||||||
|
|
||||||
|
function build_static() {
|
||||||
if ($null -eq ${env:OLLAMA_SKIP_CPU_GENERATE}) {
|
if ($null -eq ${env:OLLAMA_SKIP_CPU_GENERATE}) {
|
||||||
|
|
||||||
# GCC build for direct linking into the Go binary
|
# GCC build for direct linking into the Go binary
|
||||||
init_vars
|
init_vars
|
||||||
# cmake will silently fallback to msvc compilers if mingw isn't in the path, so detect and fail fast
|
# cmake will silently fallback to msvc compilers if mingw isn't in the path, so detect and fail fast
|
||||||
|
@ -201,7 +203,13 @@ $script:cmakeDefs = @(
|
||||||
$script:buildDir="../build/windows/${script:ARCH}_static"
|
$script:buildDir="../build/windows/${script:ARCH}_static"
|
||||||
write-host "Building static library"
|
write-host "Building static library"
|
||||||
build
|
build
|
||||||
|
} else {
|
||||||
|
write-host "Skipping CPU generation step as requested"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_cpu() {
|
||||||
|
if ($null -eq ${env:OLLAMA_SKIP_CPU_GENERATE}) {
|
||||||
# remaining llama.cpp builds use MSVC
|
# remaining llama.cpp builds use MSVC
|
||||||
init_vars
|
init_vars
|
||||||
$script:cmakeDefs = $script:commonCpuDefs + @("-A", "x64", "-DLLAMA_AVX=off", "-DLLAMA_AVX2=off", "-DLLAMA_AVX512=off", "-DLLAMA_FMA=off", "-DLLAMA_F16C=off") + $script:cmakeDefs
|
$script:cmakeDefs = $script:commonCpuDefs + @("-A", "x64", "-DLLAMA_AVX=off", "-DLLAMA_AVX2=off", "-DLLAMA_AVX512=off", "-DLLAMA_FMA=off", "-DLLAMA_F16C=off") + $script:cmakeDefs
|
||||||
|
@ -211,7 +219,13 @@ build
|
||||||
build
|
build
|
||||||
sign
|
sign
|
||||||
install
|
install
|
||||||
|
} else {
|
||||||
|
write-host "Skipping CPU generation step as requested"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_cpu_avx() {
|
||||||
|
if ($null -eq ${env:OLLAMA_SKIP_CPU_GENERATE}) {
|
||||||
init_vars
|
init_vars
|
||||||
$script:cmakeDefs = $script:commonCpuDefs + @("-A", "x64", "-DLLAMA_AVX=on", "-DLLAMA_AVX2=off", "-DLLAMA_AVX512=off", "-DLLAMA_FMA=off", "-DLLAMA_F16C=off") + $script:cmakeDefs
|
$script:cmakeDefs = $script:commonCpuDefs + @("-A", "x64", "-DLLAMA_AVX=on", "-DLLAMA_AVX2=off", "-DLLAMA_AVX512=off", "-DLLAMA_FMA=off", "-DLLAMA_F16C=off") + $script:cmakeDefs
|
||||||
$script:buildDir="../build/windows/${script:ARCH}/cpu_avx"
|
$script:buildDir="../build/windows/${script:ARCH}/cpu_avx"
|
||||||
|
@ -220,7 +234,13 @@ build
|
||||||
build
|
build
|
||||||
sign
|
sign
|
||||||
install
|
install
|
||||||
|
} else {
|
||||||
|
write-host "Skipping CPU generation step as requested"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_cpu_avx2() {
|
||||||
|
if ($null -eq ${env:OLLAMA_SKIP_CPU_GENERATE}) {
|
||||||
init_vars
|
init_vars
|
||||||
$script:cmakeDefs = $script:commonCpuDefs + @("-A", "x64", "-DLLAMA_AVX=on", "-DLLAMA_AVX2=on", "-DLLAMA_AVX512=off", "-DLLAMA_FMA=on", "-DLLAMA_F16C=on") + $script:cmakeDefs
|
$script:cmakeDefs = $script:commonCpuDefs + @("-A", "x64", "-DLLAMA_AVX=on", "-DLLAMA_AVX2=on", "-DLLAMA_AVX512=off", "-DLLAMA_FMA=on", "-DLLAMA_F16C=on") + $script:cmakeDefs
|
||||||
$script:buildDir="../build/windows/${script:ARCH}/cpu_avx2"
|
$script:buildDir="../build/windows/${script:ARCH}/cpu_avx2"
|
||||||
|
@ -232,7 +252,9 @@ build
|
||||||
} else {
|
} else {
|
||||||
write-host "Skipping CPU generation step as requested"
|
write-host "Skipping CPU generation step as requested"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_cuda() {
|
||||||
if ($null -ne $script:CUDA_LIB_DIR) {
|
if ($null -ne $script:CUDA_LIB_DIR) {
|
||||||
# Then build cuda as a dynamically loaded library
|
# Then build cuda as a dynamically loaded library
|
||||||
$nvcc = "$script:CUDA_LIB_DIR\nvcc.exe"
|
$nvcc = "$script:CUDA_LIB_DIR\nvcc.exe"
|
||||||
|
@ -258,7 +280,9 @@ if ($null -ne $script:CUDA_LIB_DIR) {
|
||||||
cp "${script:CUDA_LIB_DIR}\cublas64_*.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\"
|
cp "${script:CUDA_LIB_DIR}\cublas64_*.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\"
|
||||||
cp "${script:CUDA_LIB_DIR}\cublasLt64_*.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\"
|
cp "${script:CUDA_LIB_DIR}\cublasLt64_*.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_rocm() {
|
||||||
if ($null -ne $env:HIP_PATH) {
|
if ($null -ne $env:HIP_PATH) {
|
||||||
$script:ROCM_VERSION=(get-item $env:HIP_PATH).Basename
|
$script:ROCM_VERSION=(get-item $env:HIP_PATH).Basename
|
||||||
if ($null -ne $script:ROCM_VERSION) {
|
if ($null -ne $script:ROCM_VERSION) {
|
||||||
|
@ -309,7 +333,23 @@ if ($null -ne $env:HIP_PATH) {
|
||||||
# amdhip64.dll dependency comes from the driver and must be installed on the host to use AMD GPUs
|
# amdhip64.dll dependency comes from the driver and must be installed on the host to use AMD GPUs
|
||||||
cp "${env:HIP_PATH}\bin\rocblas\library\*" "${script:SRC_DIR}\dist\windows-${script:ARCH}\rocm\rocblas\library\"
|
cp "${env:HIP_PATH}\bin\rocblas\library\*" "${script:SRC_DIR}\dist\windows-${script:ARCH}\rocm\rocblas\library\"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init_vars
|
||||||
|
if ($($args.count) -eq 0) {
|
||||||
|
git_module_setup
|
||||||
|
apply_patches
|
||||||
|
build_static
|
||||||
|
build_cpu_avx
|
||||||
|
build_cpu_avx2
|
||||||
|
build_cuda
|
||||||
|
build_rocm
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
write-host "`ngo generate completed. LLM runners: $(get-childitem -path $script:DIST_BASE)"
|
write-host "`ngo generate completed. LLM runners: $(get-childitem -path $script:DIST_BASE)"
|
||||||
|
} else {
|
||||||
|
for ( $i = 0; $i -lt $args.count; $i++ ) {
|
||||||
|
write-host "performing $($args[$i])"
|
||||||
|
& $($args[$i])
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue