From 86e67fc4a97656ac008f70d267cb9f639c884fd3 Mon Sep 17 00:00:00 2001 From: Hernan Martinez Date: Fri, 26 Apr 2024 22:24:53 -0600 Subject: [PATCH 1/5] Add import declaration for windows,arm64 to llm.go --- llm/llm.go | 1 + 1 file changed, 1 insertion(+) diff --git a/llm/llm.go b/llm/llm.go index 33949c76..c81e2edf 100644 --- a/llm/llm.go +++ b/llm/llm.go @@ -4,6 +4,7 @@ package llm // #cgo darwin,arm64 LDFLAGS: ${SRCDIR}/build/darwin/arm64_static/libllama.a -lstdc++ // #cgo darwin,amd64 LDFLAGS: ${SRCDIR}/build/darwin/x86_64_static/libllama.a -lstdc++ // #cgo windows,amd64 LDFLAGS: ${SRCDIR}/build/windows/amd64_static/libllama.a -static -lstdc++ +// #cgo windows,arm64 LDFLAGS: ${SRCDIR}/build/windows/arm64_static/libllama.a -static -lstdc++ // #cgo linux,amd64 LDFLAGS: ${SRCDIR}/build/linux/x86_64_static/libllama.a -lstdc++ // #cgo linux,arm64 LDFLAGS: ${SRCDIR}/build/linux/arm64_static/libllama.a -lstdc++ // #include From 204349b17bce5b00579ee2b40714dac1e84e032a Mon Sep 17 00:00:00 2001 From: Hernan Martinez Date: Fri, 26 Apr 2024 23:26:03 -0600 Subject: [PATCH 2/5] Use architecture specific folders in the build script --- scripts/build_windows.ps1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/build_windows.ps1 b/scripts/build_windows.ps1 index 7db56887..d0fb4db5 100644 --- a/scripts/build_windows.ps1 +++ b/scripts/build_windows.ps1 @@ -7,6 +7,8 @@ $ErrorActionPreference = "Stop" function checkEnv() { + $script:TARGET_ARCH=$Env:PROCESSOR_ARCHITECTURE.ToLower() + Write-host "Building for ${script:TARGET_ARCH}" write-host "Locating required tools and paths" $script:SRC_DIR=$PWD if (!$env:VCToolsRedistDir) { @@ -30,7 +32,7 @@ function checkEnv() { $script:INNO_SETUP_DIR=(get-item "C:\Program Files*\Inno Setup*\")[0] - $script:DEPS_DIR="${script:SRC_DIR}\dist\windows-amd64" + $script:DEPS_DIR="${script:SRC_DIR}\dist\windows-${script:TARGET_ARCH}" $env:CGO_ENABLED="1" echo "Checking version" if (!$env:VERSION) { @@ -81,8 +83,8 @@ function buildOllama() { /csp "Google Cloud KMS Provider" /kc ${env:KEY_CONTAINER} ollama.exe if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)} } - New-Item -ItemType Directory -Path .\dist\windows-amd64\ -Force - cp .\ollama.exe .\dist\windows-amd64\ + New-Item -ItemType Directory -Path .\dist\windows-${script:TARGET_ARCH}\ -Force + cp .\ollama.exe .\dist\windows-${script:TARGET_ARCH}\ } function buildApp() { @@ -135,8 +137,8 @@ function buildInstaller() { } function distZip() { - write-host "Generating stand-alone distribution zip file ${script:SRC_DIR}\dist\ollama-windows-amd64.zip" - Compress-Archive -Path "${script:SRC_DIR}\dist\windows-amd64\*" -DestinationPath "${script:SRC_DIR}\dist\ollama-windows-amd64.zip" -Force + write-host "Generating stand-alone distribution zip file ${script:SRC_DIR}\dist\ollama-windows-${script:TARGET_ARCH}.zip" + Compress-Archive -Path "${script:SRC_DIR}\dist\windows-${script:TARGET_ARCH}\*" -DestinationPath "${script:SRC_DIR}\dist\ollama-windows-${script:TARGET_ARCH}.zip" -Force } try { From b438d485f19f21419708e82a3131ef2585bc97f4 Mon Sep 17 00:00:00 2001 From: Hernan Martinez Date: Fri, 26 Apr 2024 23:34:12 -0600 Subject: [PATCH 3/5] Use architecture specific folders in the generate script --- llm/generate/gen_windows.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llm/generate/gen_windows.ps1 b/llm/generate/gen_windows.ps1 index 4a1f22a3..3f27b599 100644 --- a/llm/generate/gen_windows.ps1 +++ b/llm/generate/gen_windows.ps1 @@ -42,7 +42,7 @@ function init_vars { "-DLLAMA_NATIVE=off" ) $script:commonCpuDefs = @("-DCMAKE_POSITION_INDEPENDENT_CODE=on") - $script:ARCH = "amd64" # arm not yet supported. + $script:ARCH = $Env:PROCESSOR_ARCHITECTURE.ToLower() $script:DIST_BASE = "${script:SRC_DIR}\dist\windows-${script:ARCH}\ollama_runners" md "$script:DIST_BASE" -ea 0 > $null if ($env:CGO_CFLAGS -contains "-g") { @@ -217,7 +217,11 @@ function build_cpu() { if ((-not "${env:OLLAMA_SKIP_CPU_GENERATE}" ) -and ((-not "${env:OLLAMA_CPU_TARGET}") -or ("${env:OLLAMA_CPU_TARGET}" -eq "cpu"))) { # remaining llama.cpp builds use MSVC 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 + $gen_arch = "x64" + if ($scrip:ARCH -eq "arm64") { + $gen_arch = "ARM64" + } + $script:cmakeDefs = $script:commonCpuDefs + @("-A", $gen_arch, "-DLLAMA_AVX=off", "-DLLAMA_AVX2=off", "-DLLAMA_AVX512=off", "-DLLAMA_FMA=off", "-DLLAMA_F16C=off") + $script:cmakeDefs $script:buildDir="../build/windows/${script:ARCH}/cpu" $script:distDir="$script:DIST_BASE\cpu" write-host "Building LCD CPU" From 6d3152a98aa59d6a5d54aa68e744e2fbd8b9dc7f Mon Sep 17 00:00:00 2001 From: Hernan Martinez Date: Fri, 26 Apr 2024 23:35:16 -0600 Subject: [PATCH 4/5] Use architecture specific folders in installer script --- app/ollama.iss | 4 ++-- scripts/build_windows.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/ollama.iss b/app/ollama.iss index 2c6de90f..9dc61abb 100644 --- a/app/ollama.iss +++ b/app/ollama.iss @@ -88,8 +88,8 @@ DialogFontSize=12 [Files] Source: ".\app.exe"; DestDir: "{app}"; DestName: "{#MyAppExeName}" ; Flags: ignoreversion 64bit Source: "..\ollama.exe"; DestDir: "{app}"; Flags: ignoreversion 64bit -Source: "..\dist\windows-amd64\*.dll"; DestDir: "{app}"; Flags: ignoreversion 64bit -Source: "..\dist\windows-amd64\ollama_runners\*"; DestDir: "{app}\ollama_runners"; Flags: ignoreversion 64bit recursesubdirs +Source: "..\dist\windows-{#ARCH}\*.dll"; DestDir: "{app}"; Flags: ignoreversion 64bit +Source: "..\dist\windows-{#ARCH}\ollama_runners\*"; DestDir: "{app}\ollama_runners"; Flags: ignoreversion 64bit recursesubdirs Source: "..\dist\ollama_welcome.ps1"; DestDir: "{app}"; Flags: ignoreversion Source: ".\assets\app.ico"; DestDir: "{app}"; Flags: ignoreversion #if DirExists("..\dist\windows-amd64\rocm") diff --git a/scripts/build_windows.ps1 b/scripts/build_windows.ps1 index d0fb4db5..60de0307 100644 --- a/scripts/build_windows.ps1 +++ b/scripts/build_windows.ps1 @@ -129,9 +129,9 @@ function buildInstaller() { cd "${script:SRC_DIR}\app" $env:PKG_VERSION=$script:PKG_VERSION if ("${env:KEY_CONTAINER}") { - & "${script:INNO_SETUP_DIR}\ISCC.exe" /SMySignTool="${script:SignTool} sign /fd sha256 /t http://timestamp.digicert.com /f ${script:OLLAMA_CERT} /csp `$qGoogle Cloud KMS Provider`$q /kc ${env:KEY_CONTAINER} `$f" .\ollama.iss + & "${script:INNO_SETUP_DIR}\ISCC.exe" /DARCH=$script:TARGET_ARCH /SMySignTool="${script:SignTool} sign /fd sha256 /t http://timestamp.digicert.com /f ${script:OLLAMA_CERT} /csp `$qGoogle Cloud KMS Provider`$q /kc ${env:KEY_CONTAINER} `$f" .\ollama.iss } else { - & "${script:INNO_SETUP_DIR}\ISCC.exe" .\ollama.iss + & "${script:INNO_SETUP_DIR}\ISCC.exe" /DARCH=$script:TARGET_ARCH .\ollama.iss } if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)} } From 8a65717f556b7fb1d72d5aa66fa99263ca3b8624 Mon Sep 17 00:00:00 2001 From: Hernan Martinez Date: Fri, 26 Apr 2024 23:41:23 -0600 Subject: [PATCH 5/5] Do not build AVX runners on ARM64 --- llm/generate/gen_windows.ps1 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/llm/generate/gen_windows.ps1 b/llm/generate/gen_windows.ps1 index 3f27b599..9bdfb9d3 100644 --- a/llm/generate/gen_windows.ps1 +++ b/llm/generate/gen_windows.ps1 @@ -213,14 +213,10 @@ function build_static() { } } -function build_cpu() { +function build_cpu($gen_arch) { if ((-not "${env:OLLAMA_SKIP_CPU_GENERATE}" ) -and ((-not "${env:OLLAMA_CPU_TARGET}") -or ("${env:OLLAMA_CPU_TARGET}" -eq "cpu"))) { # remaining llama.cpp builds use MSVC init_vars - $gen_arch = "x64" - if ($scrip:ARCH -eq "arm64") { - $gen_arch = "ARM64" - } $script:cmakeDefs = $script:commonCpuDefs + @("-A", $gen_arch, "-DLLAMA_AVX=off", "-DLLAMA_AVX2=off", "-DLLAMA_AVX512=off", "-DLLAMA_FMA=off", "-DLLAMA_F16C=off") + $script:cmakeDefs $script:buildDir="../build/windows/${script:ARCH}/cpu" $script:distDir="$script:DIST_BASE\cpu" @@ -353,11 +349,15 @@ if ($($args.count) -eq 0) { git_module_setup apply_patches build_static - build_cpu - build_cpu_avx - build_cpu_avx2 - build_cuda - build_rocm + if ($script:ARCH -eq "arm64") { + build_cpu("ARM64") + } else { # amd64 + build_cpu("x64") + build_cpu_avx + build_cpu_avx2 + build_cuda + build_rocm + } cleanup write-host "`ngo generate completed. LLM runners: $(get-childitem -path $script:DIST_BASE)"