2023-11-14 01:20:34 +00:00
|
|
|
#!powershell
|
|
|
|
|
2024-06-17 20:32:46 +00:00
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
2024-02-16 01:15:09 +00:00
|
|
|
function amdGPUs {
|
|
|
|
if ($env:AMDGPU_TARGETS) {
|
|
|
|
return $env:AMDGPU_TARGETS
|
|
|
|
}
|
2024-07-10 18:01:22 +00:00
|
|
|
# Current supported rocblas list from ROCm v6.1.2 on windows
|
2024-07-19 22:07:26 +00:00
|
|
|
# https://rocm.docs.amd.com/projects/install-on-windows/en/latest/reference/system-requirements.html#windows-supported-gpus
|
2024-02-16 01:15:09 +00:00
|
|
|
$GPU_LIST = @(
|
|
|
|
"gfx1030"
|
|
|
|
"gfx1100"
|
|
|
|
"gfx1101"
|
|
|
|
"gfx1102"
|
|
|
|
)
|
|
|
|
$GPU_LIST -join ';'
|
|
|
|
}
|
|
|
|
|
2024-04-26 04:41:33 +00:00
|
|
|
|
2023-11-14 01:20:34 +00:00
|
|
|
function init_vars {
|
2024-04-26 04:41:33 +00:00
|
|
|
if (!$script:SRC_DIR) {
|
|
|
|
$script:SRC_DIR = $(resolve-path "..\..\")
|
|
|
|
}
|
|
|
|
if (!$script:llamacppDir) {
|
|
|
|
$script:llamacppDir = "../llama.cpp"
|
|
|
|
}
|
2024-04-26 22:10:42 +00:00
|
|
|
if (!$script:cmakeTargets) {
|
|
|
|
$script:cmakeTargets = @("ollama_llama_server")
|
|
|
|
}
|
2024-02-16 01:15:09 +00:00
|
|
|
$script:cmakeDefs = @(
|
|
|
|
"-DBUILD_SHARED_LIBS=on",
|
2024-07-05 17:25:58 +00:00
|
|
|
"-DGGML_NATIVE=off",
|
|
|
|
"-DGGML_OPENMP=off"
|
2024-02-16 01:15:09 +00:00
|
|
|
)
|
2024-04-26 04:41:33 +00:00
|
|
|
$script:commonCpuDefs = @("-DCMAKE_POSITION_INDEPENDENT_CODE=on")
|
2024-04-27 05:34:12 +00:00
|
|
|
$script:ARCH = $Env:PROCESSOR_ARCHITECTURE.ToLower()
|
2024-04-23 19:19:17 +00:00
|
|
|
$script:DIST_BASE = "${script:SRC_DIR}\dist\windows-${script:ARCH}\ollama_runners"
|
2024-04-26 22:36:34 +00:00
|
|
|
md "$script:DIST_BASE" -ea 0 > $null
|
2023-11-14 01:20:34 +00:00
|
|
|
if ($env:CGO_CFLAGS -contains "-g") {
|
2024-02-16 01:15:09 +00:00
|
|
|
$script:cmakeDefs += @("-DCMAKE_VERBOSE_MAKEFILE=on", "-DLLAMA_SERVER_VERBOSE=on", "-DCMAKE_BUILD_TYPE=RelWithDebInfo")
|
2023-12-20 22:46:15 +00:00
|
|
|
$script:config = "RelWithDebInfo"
|
2023-11-14 01:20:34 +00:00
|
|
|
} else {
|
2024-02-16 01:15:09 +00:00
|
|
|
$script:cmakeDefs += @("-DLLAMA_SERVER_VERBOSE=off", "-DCMAKE_BUILD_TYPE=Release")
|
2023-12-20 22:46:15 +00:00
|
|
|
$script:config = "Release"
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
2024-02-16 01:15:09 +00:00
|
|
|
if ($null -ne $env:CMAKE_SYSTEM_VERSION) {
|
|
|
|
$script:cmakeDefs += @("-DCMAKE_SYSTEM_VERSION=${env:CMAKE_SYSTEM_VERSION}")
|
|
|
|
}
|
2024-01-13 00:28:00 +00:00
|
|
|
# Try to find the CUDA dir
|
|
|
|
if ($env:CUDA_LIB_DIR -eq $null) {
|
|
|
|
$d=(get-command -ea 'silentlycontinue' nvcc).path
|
|
|
|
if ($d -ne $null) {
|
|
|
|
$script:CUDA_LIB_DIR=($d| split-path -parent)
|
2023-12-27 00:03:45 +00:00
|
|
|
$script:CUDA_INCLUDE_DIR=($script:CUDA_LIB_DIR|split-path -parent)+"\include"
|
2024-01-13 00:28:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$script:CUDA_LIB_DIR=$env:CUDA_LIB_DIR
|
|
|
|
}
|
|
|
|
$script:DUMPBIN=(get-command -ea 'silentlycontinue' dumpbin).path
|
2024-01-20 20:15:50 +00:00
|
|
|
if ($null -eq $env:CMAKE_CUDA_ARCHITECTURES) {
|
|
|
|
$script:CMAKE_CUDA_ARCHITECTURES="50;52;61;70;75;80"
|
|
|
|
} else {
|
|
|
|
$script:CMAKE_CUDA_ARCHITECTURES=$env:CMAKE_CUDA_ARCHITECTURES
|
|
|
|
}
|
2024-03-07 18:54:21 +00:00
|
|
|
# Note: Windows Kits 10 signtool crashes with GCP's plugin
|
|
|
|
if ($null -eq $env:SIGN_TOOL) {
|
|
|
|
${script:SignTool}="C:\Program Files (x86)\Windows Kits\8.1\bin\x64\signtool.exe"
|
|
|
|
} else {
|
|
|
|
${script:SignTool}=${env:SIGN_TOOL}
|
|
|
|
}
|
2024-02-16 23:33:16 +00:00
|
|
|
if ("${env:KEY_CONTAINER}") {
|
|
|
|
${script:OLLAMA_CERT}=$(resolve-path "${script:SRC_DIR}\ollama_inc.crt")
|
|
|
|
}
|
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
|
2024-06-17 20:32:46 +00:00
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
2024-01-04 17:40:15 +00:00
|
|
|
& git submodule update --force "${script:llamacppDir}"
|
2024-06-17 20:32:46 +00:00
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function apply_patches {
|
2023-12-22 17:51:53 +00:00
|
|
|
# Wire up our CMakefile
|
2024-03-12 20:51:44 +00:00
|
|
|
if (!(Select-String -Path "${script:llamacppDir}/CMakeLists.txt" -Pattern 'ollama')) {
|
|
|
|
Add-Content -Path "${script:llamacppDir}/CMakeLists.txt" -Value 'add_subdirectory(../ext_server ext_server) # ollama'
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
2024-01-25 21:46:20 +00:00
|
|
|
|
|
|
|
# Apply temporary patches until fix is upstream
|
|
|
|
$patches = Get-ChildItem "../patches/*.diff"
|
|
|
|
foreach ($patch in $patches) {
|
|
|
|
# Extract file paths from the patch file
|
|
|
|
$filePaths = Get-Content $patch.FullName | Where-Object { $_ -match '^\+\+\+ ' } | ForEach-Object {
|
|
|
|
$parts = $_ -split ' '
|
|
|
|
($parts[1] -split '/', 2)[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Checkout each file
|
|
|
|
foreach ($file in $filePaths) {
|
2024-03-14 17:24:13 +00:00
|
|
|
git -C "${script:llamacppDir}" checkout $file
|
2024-01-25 21:46:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Apply each patch
|
|
|
|
foreach ($patch in $patches) {
|
2024-03-14 17:24:13 +00:00
|
|
|
git -C "${script:llamacppDir}" apply $patch.FullName
|
2024-01-25 21:46:20 +00:00
|
|
|
}
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function build {
|
2024-01-04 17:40:15 +00:00
|
|
|
write-host "generating config with: cmake -S ${script:llamacppDir} -B $script:buildDir $script:cmakeDefs"
|
2023-11-14 01:20:34 +00:00
|
|
|
& cmake --version
|
2024-01-04 17:40:15 +00:00
|
|
|
& cmake -S "${script:llamacppDir}" -B $script:buildDir $script:cmakeDefs
|
2024-06-17 20:32:46 +00:00
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
2024-06-17 20:44:46 +00:00
|
|
|
if ($cmakeDefs -contains "-G") {
|
|
|
|
$extra=@("-j8")
|
|
|
|
} else {
|
|
|
|
$extra= @("--", "/p:CL_MPcount=8")
|
|
|
|
}
|
|
|
|
write-host "building with: cmake --build $script:buildDir --config $script:config $($script:cmakeTargets | ForEach-Object { `"--target`", $_ }) $extra"
|
|
|
|
& cmake --build $script:buildDir --config $script:config ($script:cmakeTargets | ForEach-Object { "--target", $_ }) $extra
|
2024-06-17 20:32:46 +00:00
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
2024-03-14 17:24:13 +00:00
|
|
|
# Rearrange output to be consistent between different generators
|
|
|
|
if ($null -ne ${script:config} -And (test-path -path "${script:buildDir}/bin/${script:config}" ) ) {
|
|
|
|
mv -force "${script:buildDir}/bin/${script:config}/*" "${script:buildDir}/bin/"
|
|
|
|
remove-item "${script:buildDir}/bin/${script:config}"
|
2024-01-13 00:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-27 00:03:45 +00:00
|
|
|
function sign {
|
|
|
|
if ("${env:KEY_CONTAINER}") {
|
2024-03-14 17:24:13 +00:00
|
|
|
write-host "Signing ${script:buildDir}/bin/*.exe ${script:buildDir}/bin/*.dll"
|
|
|
|
foreach ($file in @(get-childitem "${script:buildDir}/bin/*.exe") + @(get-childitem "${script:buildDir}/bin/*.dll")){
|
|
|
|
& "${script:SignTool}" sign /v /fd sha256 /t http://timestamp.digicert.com /f "${script:OLLAMA_CERT}" `
|
2023-12-27 00:03:45 +00:00
|
|
|
/csp "Google Cloud KMS Provider" /kc "${env:KEY_CONTAINER}" $file
|
2024-06-17 20:32:46 +00:00
|
|
|
if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)}
|
2023-12-27 00:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-23 19:19:17 +00:00
|
|
|
function install {
|
|
|
|
write-host "Installing binaries to dist dir ${script:distDir}"
|
|
|
|
mkdir ${script:distDir} -ErrorAction SilentlyContinue
|
2024-03-14 17:24:13 +00:00
|
|
|
$binaries = dir "${script:buildDir}/bin/*.exe"
|
|
|
|
foreach ($file in $binaries) {
|
2024-04-23 19:19:17 +00:00
|
|
|
copy-item -Path $file -Destination ${script:distDir} -Force
|
2024-03-14 17:24:13 +00:00
|
|
|
}
|
|
|
|
|
2024-04-23 19:19:17 +00:00
|
|
|
write-host "Installing dlls to dist dir ${script:distDir}"
|
2024-04-04 13:27:33 +00:00
|
|
|
$dlls = dir "${script:buildDir}/bin/*.dll"
|
2024-03-14 17:24:13 +00:00
|
|
|
foreach ($file in $dlls) {
|
2024-04-23 19:19:17 +00:00
|
|
|
copy-item -Path $file -Destination ${script:distDir} -Force
|
2024-01-13 00:28:00 +00:00
|
|
|
}
|
2023-12-23 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2023-12-22 17:51:53 +00:00
|
|
|
function cleanup {
|
2023-12-27 00:03:45 +00:00
|
|
|
$patches = Get-ChildItem "../patches/*.diff"
|
|
|
|
foreach ($patch in $patches) {
|
|
|
|
# Extract file paths from the patch file
|
|
|
|
$filePaths = Get-Content $patch.FullName | Where-Object { $_ -match '^\+\+\+ ' } | ForEach-Object {
|
|
|
|
$parts = $_ -split ' '
|
|
|
|
($parts[1] -split '/', 2)[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Checkout each file
|
|
|
|
foreach ($file in $filePaths) {
|
2024-03-14 17:24:13 +00:00
|
|
|
git -C "${script:llamacppDir}" checkout $file
|
2023-12-27 00:03:45 +00:00
|
|
|
}
|
2024-03-14 17:24:13 +00:00
|
|
|
git -C "${script:llamacppDir}" checkout CMakeLists.txt
|
2023-12-27 00:03:45 +00:00
|
|
|
}
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
|
|
|
|
2023-12-20 22:46:15 +00:00
|
|
|
|
2024-07-05 17:25:58 +00:00
|
|
|
# -DGGML_AVX -- 2011 Intel Sandy Bridge & AMD Bulldozer
|
|
|
|
# -DGGML_AVX2 -- 2013 Intel Haswell & 2015 AMD Excavator / 2017 AMD Zen
|
|
|
|
# -DGGML_FMA (FMA3) -- 2013 Intel Haswell & 2012 AMD Piledriver
|
2024-01-10 04:29:58 +00:00
|
|
|
|
2024-03-07 18:54:21 +00:00
|
|
|
|
2024-04-26 04:41:33 +00:00
|
|
|
function build_static() {
|
2024-04-26 22:36:34 +00:00
|
|
|
if ((-not "${env:OLLAMA_SKIP_STATIC_GENERATE}") -and ((-not "${env:OLLAMA_CPU_TARGET}") -or ("${env:OLLAMA_CPU_TARGET}" -eq "static"))) {
|
2024-04-26 04:41:33 +00:00
|
|
|
# GCC build for direct linking into the Go binary
|
|
|
|
init_vars
|
|
|
|
# cmake will silently fallback to msvc compilers if mingw isn't in the path, so detect and fail fast
|
|
|
|
# as we need this to be compiled by gcc for golang to be able to link with itx
|
|
|
|
write-host "Checking for MinGW..."
|
|
|
|
# error action ensures we exit on failure
|
|
|
|
get-command gcc
|
|
|
|
get-command mingw32-make
|
2024-04-26 22:10:42 +00:00
|
|
|
$oldTargets = $script:cmakeTargets
|
2024-04-26 04:41:33 +00:00
|
|
|
$script:cmakeTargets = @("llama", "ggml")
|
|
|
|
$script:cmakeDefs = @(
|
|
|
|
"-G", "MinGW Makefiles"
|
|
|
|
"-DCMAKE_C_COMPILER=gcc.exe",
|
|
|
|
"-DCMAKE_CXX_COMPILER=g++.exe",
|
|
|
|
"-DBUILD_SHARED_LIBS=off",
|
2024-07-05 17:25:58 +00:00
|
|
|
"-DGGML_NATIVE=off",
|
|
|
|
"-DGGML_AVX=off",
|
|
|
|
"-DGGML_AVX2=off",
|
|
|
|
"-DGGML_AVX512=off",
|
|
|
|
"-DGGML_F16C=off",
|
|
|
|
"-DGGML_FMA=off",
|
|
|
|
"-DGGML_OPENMP=off")
|
2024-04-26 04:41:33 +00:00
|
|
|
$script:buildDir="../build/windows/${script:ARCH}_static"
|
|
|
|
write-host "Building static library"
|
|
|
|
build
|
2024-04-26 22:10:42 +00:00
|
|
|
$script:cmakeTargets = $oldTargets
|
2024-04-26 04:41:33 +00:00
|
|
|
} else {
|
|
|
|
write-host "Skipping CPU generation step as requested"
|
|
|
|
}
|
2024-03-07 18:54:21 +00:00
|
|
|
}
|
2023-12-20 22:46:15 +00:00
|
|
|
|
2024-06-17 20:32:46 +00:00
|
|
|
function build_cpu($gen_arch) {
|
2024-04-26 22:36:34 +00:00
|
|
|
if ((-not "${env:OLLAMA_SKIP_CPU_GENERATE}" ) -and ((-not "${env:OLLAMA_CPU_TARGET}") -or ("${env:OLLAMA_CPU_TARGET}" -eq "cpu"))) {
|
2024-04-26 04:41:33 +00:00
|
|
|
# remaining llama.cpp builds use MSVC
|
|
|
|
init_vars
|
2024-07-05 17:25:58 +00:00
|
|
|
$script:cmakeDefs = $script:commonCpuDefs + @("-A", $gen_arch, "-DGGML_AVX=off", "-DGGML_AVX2=off", "-DGGML_AVX512=off", "-DGGML_FMA=off", "-DGGML_F16C=off") + $script:cmakeDefs
|
2024-04-26 04:41:33 +00:00
|
|
|
$script:buildDir="../build/windows/${script:ARCH}/cpu"
|
|
|
|
$script:distDir="$script:DIST_BASE\cpu"
|
|
|
|
write-host "Building LCD CPU"
|
|
|
|
build
|
|
|
|
sign
|
|
|
|
install
|
|
|
|
} else {
|
|
|
|
write-host "Skipping CPU generation step as requested"
|
2024-01-13 00:28:00 +00:00
|
|
|
}
|
2024-04-26 04:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_cpu_avx() {
|
2024-04-26 22:36:34 +00:00
|
|
|
if ((-not "${env:OLLAMA_SKIP_CPU_GENERATE}" ) -and ((-not "${env:OLLAMA_CPU_TARGET}") -or ("${env:OLLAMA_CPU_TARGET}" -eq "cpu_avx"))) {
|
2024-04-26 04:41:33 +00:00
|
|
|
init_vars
|
2024-07-05 17:25:58 +00:00
|
|
|
$script:cmakeDefs = $script:commonCpuDefs + @("-A", "x64", "-DGGML_AVX=on", "-DGGML_AVX2=off", "-DGGML_AVX512=off", "-DGGML_FMA=off", "-DGGML_F16C=off") + $script:cmakeDefs
|
2024-04-26 04:41:33 +00:00
|
|
|
$script:buildDir="../build/windows/${script:ARCH}/cpu_avx"
|
|
|
|
$script:distDir="$script:DIST_BASE\cpu_avx"
|
|
|
|
write-host "Building AVX CPU"
|
|
|
|
build
|
|
|
|
sign
|
|
|
|
install
|
|
|
|
} else {
|
2024-04-26 22:36:34 +00:00
|
|
|
write-host "Skipping CPU AVX generation step as requested"
|
2024-04-18 23:27:16 +00:00
|
|
|
}
|
2024-04-26 04:41:33 +00:00
|
|
|
}
|
2024-04-26 05:02:10 +00:00
|
|
|
|
2024-04-26 04:41:33 +00:00
|
|
|
function build_cpu_avx2() {
|
2024-04-26 22:36:34 +00:00
|
|
|
if ((-not "${env:OLLAMA_SKIP_CPU_GENERATE}" ) -and ((-not "${env:OLLAMA_CPU_TARGET}") -or ("${env:OLLAMA_CPU_TARGET}" -eq "cpu_avx2"))) {
|
2024-04-26 04:41:33 +00:00
|
|
|
init_vars
|
2024-07-05 17:25:58 +00:00
|
|
|
$script:cmakeDefs = $script:commonCpuDefs + @("-A", "x64", "-DGGML_AVX=on", "-DGGML_AVX2=on", "-DGGML_AVX512=off", "-DGGML_FMA=on", "-DGGML_F16C=on") + $script:cmakeDefs
|
2024-04-26 04:41:33 +00:00
|
|
|
$script:buildDir="../build/windows/${script:ARCH}/cpu_avx2"
|
|
|
|
$script:distDir="$script:DIST_BASE\cpu_avx2"
|
|
|
|
write-host "Building AVX2 CPU"
|
|
|
|
build
|
|
|
|
sign
|
|
|
|
install
|
|
|
|
} else {
|
2024-04-26 22:36:34 +00:00
|
|
|
write-host "Skipping CPU AVX2 generation step as requested"
|
2024-04-26 04:41:33 +00:00
|
|
|
}
|
2024-01-13 00:28:00 +00:00
|
|
|
}
|
2023-11-29 19:00:37 +00:00
|
|
|
|
2024-04-26 04:41:33 +00:00
|
|
|
function build_cuda() {
|
2024-04-26 22:36:34 +00:00
|
|
|
if ((-not "${env:OLLAMA_SKIP_CUDA_GENERATE}") -and ("${script:CUDA_LIB_DIR}")) {
|
2024-04-26 04:41:33 +00:00
|
|
|
# Then build cuda as a dynamically loaded library
|
|
|
|
$nvcc = "$script:CUDA_LIB_DIR\nvcc.exe"
|
|
|
|
$script:CUDA_VERSION=(get-item ($nvcc | split-path | split-path)).Basename
|
|
|
|
if ($null -ne $script:CUDA_VERSION) {
|
|
|
|
$script:CUDA_VARIANT="_"+$script:CUDA_VERSION
|
|
|
|
}
|
|
|
|
init_vars
|
|
|
|
$script:buildDir="../build/windows/${script:ARCH}/cuda$script:CUDA_VARIANT"
|
|
|
|
$script:distDir="$script:DIST_BASE\cuda$script:CUDA_VARIANT"
|
2024-06-17 20:44:46 +00:00
|
|
|
$script:cmakeDefs += @(
|
|
|
|
"-A", "x64",
|
2024-07-05 17:25:58 +00:00
|
|
|
"-DGGML_CUDA=ON",
|
|
|
|
"-DGGML_AVX=on",
|
|
|
|
"-DGGML_AVX2=off",
|
2024-06-17 20:44:46 +00:00
|
|
|
"-DCUDAToolkit_INCLUDE_DIR=$script:CUDA_INCLUDE_DIR",
|
|
|
|
"-DCMAKE_CUDA_FLAGS=-t8",
|
|
|
|
"-DCMAKE_CUDA_ARCHITECTURES=${script:CMAKE_CUDA_ARCHITECTURES}"
|
|
|
|
)
|
2024-04-26 04:41:33 +00:00
|
|
|
if ($null -ne $env:OLLAMA_CUSTOM_CUDA_DEFS) {
|
|
|
|
write-host "OLLAMA_CUSTOM_CUDA_DEFS=`"${env:OLLAMA_CUSTOM_CUDA_DEFS}`""
|
|
|
|
$script:cmakeDefs +=@("${env:OLLAMA_CUSTOM_CUDA_DEFS}")
|
|
|
|
write-host "building custom CUDA GPU"
|
|
|
|
}
|
|
|
|
build
|
|
|
|
sign
|
|
|
|
install
|
|
|
|
|
2024-06-15 20:17:20 +00:00
|
|
|
rm -ea 0 -recurse -force -path "${script:SRC_DIR}\dist\windows-${script:ARCH}\cuda\"
|
|
|
|
md "${script:SRC_DIR}\dist\windows-${script:ARCH}\cuda\" -ea 0 > $null
|
|
|
|
write-host "copying CUDA dependencies to ${script:SRC_DIR}\dist\windows-${script:ARCH}\cuda\"
|
|
|
|
cp "${script:CUDA_LIB_DIR}\cudart64_*.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\cuda\"
|
|
|
|
cp "${script:CUDA_LIB_DIR}\cublas64_*.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\cuda\"
|
|
|
|
cp "${script:CUDA_LIB_DIR}\cublasLt64_*.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\cuda\"
|
2024-04-26 22:36:34 +00:00
|
|
|
} else {
|
|
|
|
write-host "Skipping CUDA generation step"
|
2024-02-16 01:15:09 +00:00
|
|
|
}
|
2024-04-26 04:41:33 +00:00
|
|
|
}
|
2024-02-16 01:15:09 +00:00
|
|
|
|
2024-05-24 03:18:27 +00:00
|
|
|
function build_oneapi() {
|
2024-06-07 15:32:49 +00:00
|
|
|
if ((-not "${env:OLLAMA_SKIP_ONEAPI_GENERATE}") -and ("${env:ONEAPI_ROOT}")) {
|
2024-05-24 03:18:27 +00:00
|
|
|
# Get oneAPI version
|
|
|
|
$script:ONEAPI_VERSION = icpx --version
|
|
|
|
$script:ONEAPI_VERSION = [regex]::Match($script:ONEAPI_VERSION, '(?<=oneAPI DPC\+\+/C\+\+ Compiler )(?<version>\d+\.\d+\.\d+)').Value
|
|
|
|
if ($null -ne $script:ONEAPI_VERSION) {
|
|
|
|
$script:ONEAPI_VARIANT = "_v" + $script:ONEAPI_VERSION
|
|
|
|
}
|
|
|
|
init_vars
|
|
|
|
$script:buildDir = "../build/windows/${script:ARCH}/oneapi$script:ONEAPI_VARIANT"
|
|
|
|
$script:distDir ="$script:DIST_BASE\oneapi$script:ONEAPI_VARIANT"
|
|
|
|
$script:cmakeDefs += @(
|
|
|
|
"-G", "MinGW Makefiles",
|
2024-07-05 17:25:58 +00:00
|
|
|
"-DGGML_SYCL=ON",
|
2024-05-24 03:18:27 +00:00
|
|
|
"-DCMAKE_C_COMPILER=icx",
|
|
|
|
"-DCMAKE_CXX_COMPILER=icx",
|
|
|
|
"-DCMAKE_BUILD_TYPE=Release"
|
|
|
|
)
|
|
|
|
|
|
|
|
Write-Host "Building oneAPI"
|
|
|
|
build
|
|
|
|
# Ninja doesn't prefix with config name
|
|
|
|
if ($null -ne $script:DUMPBIN) {
|
|
|
|
& "$script:DUMPBIN" /dependents "${script:buildDir}/bin/ollama_llama_server.exe" | Select-String ".dll"
|
|
|
|
}
|
|
|
|
sign
|
|
|
|
install
|
|
|
|
|
2024-06-15 20:17:20 +00:00
|
|
|
rm -ea 0 -recurse -force -path "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
|
|
|
md "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\" -ea 0 > $null
|
|
|
|
cp "${env:ONEAPI_ROOT}\compiler\latest\bin\libirngmd.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
|
|
|
cp "${env:ONEAPI_ROOT}\compiler\latest\bin\libmmd.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
|
|
|
cp "${env:ONEAPI_ROOT}\compiler\latest\bin\pi_level_zero.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
|
|
|
cp "${env:ONEAPI_ROOT}\compiler\latest\bin\pi_unified_runtime.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
|
|
|
cp "${env:ONEAPI_ROOT}\compiler\latest\bin\pi_win_proxy_loader.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
|
|
|
cp "${env:ONEAPI_ROOT}\compiler\latest\bin\svml_dispmd.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
|
|
|
cp "${env:ONEAPI_ROOT}\compiler\latest\bin\sycl7.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
|
|
|
cp "${env:ONEAPI_ROOT}\mkl\latest\bin\mkl_core.2.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
|
|
|
cp "${env:ONEAPI_ROOT}\mkl\latest\bin\mkl_sycl_blas.4.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
|
|
|
cp "${env:ONEAPI_ROOT}\mkl\latest\bin\mkl_tbb_thread.2.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\oneapi\"
|
2024-05-24 03:18:27 +00:00
|
|
|
} else {
|
|
|
|
Write-Host "Skipping oneAPI generation step"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-26 04:41:33 +00:00
|
|
|
function build_rocm() {
|
2024-04-26 22:36:34 +00:00
|
|
|
if ((-not "${env:OLLAMA_SKIP_ROCM_GENERATE}") -and ("${env:HIP_PATH}")) {
|
2024-04-26 04:41:33 +00:00
|
|
|
$script:ROCM_VERSION=(get-item $env:HIP_PATH).Basename
|
|
|
|
if ($null -ne $script:ROCM_VERSION) {
|
|
|
|
$script:ROCM_VARIANT="_v"+$script:ROCM_VERSION
|
|
|
|
}
|
2024-02-16 01:15:09 +00:00
|
|
|
|
2024-04-26 04:41:33 +00:00
|
|
|
init_vars
|
|
|
|
$script:buildDir="../build/windows/${script:ARCH}/rocm$script:ROCM_VARIANT"
|
|
|
|
$script:distDir="$script:DIST_BASE\rocm$script:ROCM_VARIANT"
|
|
|
|
$script:cmakeDefs += @(
|
|
|
|
"-G", "Ninja",
|
|
|
|
"-DCMAKE_C_COMPILER=clang.exe",
|
|
|
|
"-DCMAKE_CXX_COMPILER=clang++.exe",
|
2024-07-05 17:25:58 +00:00
|
|
|
"-DGGML_HIPBLAS=on",
|
2024-07-05 19:46:28 +00:00
|
|
|
"-DLLAMA_CUDA_NO_PEER_COPY=on",
|
2024-04-26 04:41:33 +00:00
|
|
|
"-DHIP_PLATFORM=amd",
|
2024-07-05 17:25:58 +00:00
|
|
|
"-DGGML_AVX=on",
|
|
|
|
"-DGGML_AVX2=off",
|
2024-04-26 04:41:33 +00:00
|
|
|
"-DCMAKE_POSITION_INDEPENDENT_CODE=on",
|
|
|
|
"-DAMDGPU_TARGETS=$(amdGPUs)",
|
|
|
|
"-DGPU_TARGETS=$(amdGPUs)"
|
|
|
|
)
|
2024-02-16 01:15:09 +00:00
|
|
|
|
2024-04-26 04:41:33 +00:00
|
|
|
# Make sure the ROCm binary dir is first in the path
|
|
|
|
$env:PATH="$env:HIP_PATH\bin;$env:PATH"
|
|
|
|
|
|
|
|
# We have to clobber the LIB var from the developer shell for clang to work properly
|
|
|
|
$env:LIB=""
|
|
|
|
if ($null -ne $env:OLLAMA_CUSTOM_ROCM_DEFS) {
|
|
|
|
write-host "OLLAMA_CUSTOM_ROCM_DEFS=`"${env:OLLAMA_CUSTOM_ROCM_DEFS}`""
|
|
|
|
$script:cmakeDefs += @("${env:OLLAMA_CUSTOM_ROCM_DEFS}")
|
|
|
|
write-host "building custom ROCM GPU"
|
|
|
|
}
|
|
|
|
write-host "Building ROCm"
|
|
|
|
build
|
|
|
|
# Ninja doesn't prefix with config name
|
|
|
|
${script:config}=""
|
|
|
|
if ($null -ne $script:DUMPBIN) {
|
|
|
|
& "$script:DUMPBIN" /dependents "${script:buildDir}/bin/ollama_llama_server.exe" | select-string ".dll"
|
|
|
|
}
|
|
|
|
sign
|
|
|
|
install
|
2024-04-26 05:02:10 +00:00
|
|
|
|
2024-04-26 04:41:33 +00:00
|
|
|
rm -ea 0 -recurse -force -path "${script:SRC_DIR}\dist\windows-${script:ARCH}\rocm\"
|
|
|
|
md "${script:SRC_DIR}\dist\windows-${script:ARCH}\rocm\rocblas\library\" -ea 0 > $null
|
|
|
|
cp "${env:HIP_PATH}\bin\hipblas.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\rocm\"
|
|
|
|
cp "${env:HIP_PATH}\bin\rocblas.dll" "${script:SRC_DIR}\dist\windows-${script:ARCH}\rocm\"
|
|
|
|
# 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\"
|
2024-04-26 22:36:34 +00:00
|
|
|
} else {
|
|
|
|
write-host "Skipping ROCm generation step"
|
2024-04-26 04:41:33 +00:00
|
|
|
}
|
2024-02-16 01:15:09 +00:00
|
|
|
}
|
2023-12-22 17:51:53 +00:00
|
|
|
|
2024-04-26 04:41:33 +00:00
|
|
|
init_vars
|
|
|
|
if ($($args.count) -eq 0) {
|
|
|
|
git_module_setup
|
|
|
|
apply_patches
|
2024-06-17 20:32:46 +00:00
|
|
|
build_static
|
|
|
|
if ($script:ARCH -eq "arm64") {
|
|
|
|
build_cpu("ARM64")
|
|
|
|
} else { # amd64
|
|
|
|
build_cpu("x64")
|
|
|
|
build_cpu_avx
|
|
|
|
build_cpu_avx2
|
|
|
|
build_cuda
|
|
|
|
build_oneapi
|
|
|
|
build_rocm
|
2024-04-27 05:41:23 +00:00
|
|
|
}
|
2024-03-14 17:24:13 +00:00
|
|
|
|
2024-04-26 04:41:33 +00:00
|
|
|
cleanup
|
|
|
|
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])
|
|
|
|
}
|
|
|
|
}
|