Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
orangecat
ollama
Commits
8671fded
"LinuxGUI/git@developer.sourcefind.cn:dadigang/Ventoy.git" did not exist on "1840cb8f38f3ee14a50a5779ecbf7897f8f02bd9"
Commit
8671fded
authored
Apr 25, 2024
by
Daniel Hiltgen
Browse files
Refactor windows generate for more modular usage
parent
2619850f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
169 additions
and
129 deletions
+169
-129
llm/generate/gen_windows.ps1
llm/generate/gen_windows.ps1
+169
-129
No files found.
llm/generate/gen_windows.ps1
View file @
8671fded
...
@@ -26,14 +26,20 @@ function amdGPUs {
...
@@ -26,14 +26,20 @@ function amdGPUs {
$GPU_LIST
-join
';'
$GPU_LIST
-join
';'
}
}
$
script
:
cmakeTargets
=
@(
"ollama_llama_server"
)
function
init_vars
{
function
init_vars
{
$
script
:
SRC_DIR
=
$
(
resolve-path
"..\..\"
)
if
(
!
$
script
:
SRC_DIR
)
{
$
script
:
llamacppDir
=
"../llama.cpp"
$
script
:
SRC_DIR
=
$
(
resolve-path
"..\..\"
)
}
if
(
!
$
script
:
llamacppDir
)
{
$
script
:
llamacppDir
=
"../llama.cpp"
}
$
script
:
cmakeDefs
=
@(
$
script
:
cmakeDefs
=
@(
"-DBUILD_SHARED_LIBS=on"
,
"-DBUILD_SHARED_LIBS=on"
,
"-DLLAMA_NATIVE=off"
"-DLLAMA_NATIVE=off"
)
)
$
script
:
c
makeTargets
=
@(
"ollama_llama_server
"
)
$
script
:
c
ommonCpuDefs
=
@(
"-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,150 +172,184 @@ function cleanup {
...
@@ -166,150 +172,184 @@ 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
")
if (
$null
-eq
${env:OLLAMA_SKIP_CPU_GENERATE}
) {
# 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
$
script
:
cmakeTargets
= @("
llama
", "
ggml
")
$
script
:
cmakeDefs
= @(
"
-G
", "
MinGW
Makefiles
"
"
-DCMAKE_C_COMPILER
=
gcc.exe
",
"
-DCMAKE_CXX_COMPILER
=
g
++.
exe
",
"
-DBUILD_SHARED_LIBS
=
off
",
"
-DLLAMA_NATIVE
=
off
",
"
-DLLAMA_AVX
=
off
",
"
-DLLAMA_AVX2
=
off
",
"
-DLLAMA_AVX512
=
off
",
"
-DLLAMA_F16C
=
off
",
"
-DLLAMA_FMA
=
off
")
$
script
:
buildDir
="
..
/build/windows/
${script:ARCH}
_static
"
write-host "
Building
static
library
"
build
# 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
$
script
:
buildDir
="
..
/build/windows/
${script:ARCH}
/cpu
"
$
script
:
distDir
="
$
script
:
DIST_BASE
\cpu
"
write-host "
Building
LCD
CPU
"
build
sign
install
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
:
buildDir
="
..
/build/windows/
${script:ARCH}
/cpu_avx
"
$
script
:
distDir
="
$
script
:
DIST_BASE
\cpu_avx
"
write-host "
Building
AVX
CPU
"
build
sign
install
init_vars
function build_static() {
$
script
:
cmakeDefs
=
$
script
:
commonCpuDefs
+ @("
-A
", "
x64
", "
-DLLAMA_AVX
=
on
", "
-DLLAMA_AVX2
=
on
", "
-DLLAMA_AVX512
=
off
", "
-DLLAMA_FMA
=
on
", "
-DLLAMA_F16C
=
on
") +
$
script
:
cmakeDefs
if (
$null
-eq
${env:OLLAMA_SKIP_CPU_GENERATE}
) {
$
script
:
buildDir
="
..
/build/windows/
${script:ARCH}
/cpu_avx2
"
# GCC build for direct linking into the Go binary
$
script
:
distDir
="
$
script
:
DIST_BASE
\cpu_avx2
"
init_vars
write-host "
Building
AVX2
CPU
"
# cmake will silently fallback to msvc compilers if mingw isn't in the path, so detect and fail fast
build
# as we need this to be compiled by gcc for golang to be able to link with itx
sign
write-host "
Checking
for
MinGW...
"
install
# error action ensures we exit on failure
} else {
get-command gcc
write-host "
Skipping
CPU
generation
step
as
requested
"
get-command mingw32-make
$
script
:
cmakeTargets
= @("
llama
", "
ggml
")
$
script
:
cmakeDefs
= @(
"
-G
", "
MinGW
Makefiles
"
"
-DCMAKE_C_COMPILER
=
gcc.exe
",
"
-DCMAKE_CXX_COMPILER
=
g
++.
exe
",
"
-DBUILD_SHARED_LIBS
=
off
",
"
-DLLAMA_NATIVE
=
off
",
"
-DLLAMA_AVX
=
off
",
"
-DLLAMA_AVX2
=
off
",
"
-DLLAMA_AVX512
=
off
",
"
-DLLAMA_F16C
=
off
",
"
-DLLAMA_FMA
=
off
")
$
script
:
buildDir
="
..
/build/windows/
${script:ARCH}
_static
"
write-host "
Building
static
library
"
build
} else {
write-host "
Skipping
CPU
generation
step
as
requested
"
}
}
}
if (
$null
-ne
$
script
:
CUDA_LIB_DIR
) {
function build_cpu() {
# Then build cuda as a dynamically loaded library
if (
$null
-eq
${env:OLLAMA_SKIP_CPU_GENERATE}
) {
$nvcc
= "
$
script
:
CUDA_LIB_DIR
\nvcc.exe
"
# remaining llama.cpp builds use MSVC
$
script
:
CUDA_VERSION
=(get-item (
$nvcc
| split-path | split-path)).Basename
init_vars
if (
$null
-ne
$
script
:
CUDA_VERSION
) {
$
script
:
cmakeDefs
=
$
script
:
commonCpuDefs
+ @("
-A
", "
x64
", "
-DLLAMA_AVX
=
off
", "
-DLLAMA_AVX2
=
off
", "
-DLLAMA_AVX512
=
off
", "
-DLLAMA_FMA
=
off
", "
-DLLAMA_F16C
=
off
") +
$
script
:
cmakeDefs
$
script
:
CUDA_VARIANT
="
_
"+
$
script
:
CUDA_VERSION
$
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
"
}
}
init_vars
}
$
script
:
buildDir
="
..
/build/windows/
${script:ARCH}
/cuda
$
script
:
CUDA_VARIANT
"
$
script
:
distDir
="
$
script
:
DIST_BASE
\cuda
$
script
:
CUDA_VARIANT
"
function build_cpu_avx() {
$
script
:
cmakeDefs
+= @("
-A
", "
x64
", "
-DLLAMA_CUDA
=
ON
", "
-DLLAMA_AVX
=
on
", "
-DLLAMA_AVX2
=
off
", "
-DCUDAToolkit_INCLUDE_DIR
=
$
script
:
CUDA_INCLUDE_DIR
", "
-DCMAKE_CUDA_ARCHITECTURES
=
${script:CMAKE_CUDA_ARCHITECTURES}
")
if (
$null
-eq
${env:OLLAMA_SKIP_CPU_GENERATE}
) {
if (
$null
-ne
$
env
:
OLLAMA_CUSTOM_CUDA_DEFS
) {
init_vars
write-host "
OLLAMA_CUSTOM_CUDA_DEFS
=
`
"
${env:OLLAMA_CUSTOM_CUDA_DEFS}
`"
"
$
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
+=
@(
"
${env:OLLAMA_CUSTOM_CUDA_DEFS}
"
)
$
script
:
buildDir
="
..
/build/windows/
${script:ARCH}
/cpu_avx
"
write-host
"building custom CUDA GPU"
$
script
:
distDir
="
$
script
:
DIST_BASE
\cpu_avx
"
write-host "
Building
AVX
CPU
"
build
sign
install
} else {
write-host "
Skipping
CPU
generation
step
as
requested
"
}
}
build
}
sign
install
write-host
"copying CUDA dependencies to
${script:SRC_DIR}
\dist\windows-
${script:ARCH}
\"
function build_cpu_avx2() {
cp
"
${script:CUDA_LIB_DIR}
\cudart64_*.dll"
"
${script:SRC_DIR}
\dist\windows-
${script:ARCH}
\"
if (
$null
-eq
${env:OLLAMA_SKIP_CPU_GENERATE}
) {
cp
"
${script:CUDA_LIB_DIR}
\cublas64_*.dll"
"
${script:SRC_DIR}
\dist\windows-
${script:ARCH}
\"
init_vars
cp
"
${script:CUDA_LIB_DIR}
\cublasLt64_*.dll"
"
${script:SRC_DIR}
\dist\windows-
${script:ARCH}
\"
$
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
:
distDir
="
$
script
:
DIST_BASE
\cpu_avx2
"
write-host "
Building
AVX2
CPU
"
build
sign
install
} else {
write-host "
Skipping
CPU
generation
step
as
requested
"
}
}
}
if
(
$null
-ne
$
env
:
HIP_PATH
)
{
function build_cuda() {
$
script
:
ROCM_VERSION
=
(
get-item
$
env
:
HIP_PATH
)
.
Basename
if (
$null
-ne
$
script
:
CUDA_LIB_DIR
) {
if
(
$null
-ne
$
script
:
ROCM_VERSION
)
{
# Then build cuda as a dynamically loaded library
$
script
:
ROCM_VARIANT
=
"_v"
+
$
script
:
ROCM_VERSION
$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
"
$
script
:
cmakeDefs
+= @("
-A
", "
x64
", "
-DLLAMA_CUDA
=
ON
", "
-DLLAMA_AVX
=
on
", "
-DLLAMA_AVX2
=
off
", "
-DCUDAToolkit_INCLUDE_DIR
=
$
script
:
CUDA_INCLUDE_DIR
", "
-DCMAKE_CUDA_ARCHITECTURES
=
${script:CMAKE_CUDA_ARCHITECTURES}
")
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
write-host
"copying CUDA dependencies to
${script:SRC_DIR}
\dist\windows-
${script:ARCH}
\"
cp
"
${script:CUDA_LIB_DIR}
\cudart64_*.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}
\"
}
}
}
init_vars
function
build_rocm
()
{
$
script
:
buildDir
=
"../build/windows/
${script:ARCH}
/rocm
$
script
:
ROCM_VARIANT
"
if
(
$null
-ne
$
env
:
HIP_PATH
)
{
$
script
:
distDir
=
"
$
script
:
DIST_BASE
\rocm
$
script
:
ROCM_VARIANT
"
$
script
:
ROCM_VERSION
=
(
get-item
$
env
:
HIP_PATH
)
.
Basename
$
script
:
cmakeDefs
+=
@(
if
(
$null
-ne
$
script
:
ROCM_VERSION
)
{
"-G"
,
"Ninja"
,
$
script
:
ROCM_VARIANT
=
"_v"
+
$
script
:
ROCM_VERSION
"-DCMAKE_C_COMPILER=clang.exe"
,
}
"-DCMAKE_CXX_COMPILER=clang++.exe"
,
"-DLLAMA_HIPBLAS=on"
,
"-DHIP_PLATFORM=amd"
,
"-DLLAMA_AVX=on"
,
"-DLLAMA_AVX2=off"
,
"-DCMAKE_POSITION_INDEPENDENT_CODE=on"
,
"-DAMDGPU_TARGETS=
$(
amdGPUs
)
",
"
-DGPU_TARGETS
=
$
(
amdGPUs
)
"
)
# Make sure the ROCm binary dir is first in the path
init_vars
$
env
:
PATH
="
$
env
:
HIP_PATH
\bin
;
$
env
:
PATH
"
$
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"
,
"-DLLAMA_HIPBLAS=on"
,
"-DHIP_PLATFORM=amd"
,
"-DLLAMA_AVX=on"
,
"-DLLAMA_AVX2=off"
,
"-DCMAKE_POSITION_INDEPENDENT_CODE=on"
,
"-DAMDGPU_TARGETS=
$(
amdGPUs
)
",
"
-DGPU_TARGETS
=
$
(
amdGPUs
)
"
)
# We have to clobber the LIB var from the developer shell for clang to work properly
# Make sure the ROCm binary dir is first in the path
$
env
:
LIB
=""
$
env
:
PATH
="
$
env
:
HIP_PATH
\bin
;
$
env
:
PATH
"
if (
$null
-ne
$
env
:
OLLAMA_CUSTOM_ROCM_DEFS
) {
write-host "
OLLAMA_CUSTOM_ROCM_DEFS
=
`
"
${env:OLLAMA_CUSTOM_ROCM_DEFS}
`"
"
# We have to clobber the LIB var from the developer shell for clang to work properly
$
script
:
cmakeDefs
+=
@(
"
${env:OLLAMA_CUSTOM_ROCM_DEFS}
"
)
$
env
:
LIB
=""
write-host
"building custom ROCM GPU"
if (
$null
-ne
$
env
:
OLLAMA_CUSTOM_ROCM_DEFS
) {
}
write-host "
OLLAMA_CUSTOM_ROCM_DEFS
=
`
"
${env:OLLAMA_CUSTOM_ROCM_DEFS}
`"
"
write-host
"Building ROCm"
$
script
:
cmakeDefs
+=
@(
"
${env:OLLAMA_CUSTOM_ROCM_DEFS}
"
)
build
write-host
"building custom ROCM GPU"
# Ninja doesn't prefix with config name
}
${script:config}
=
""
write-host
"Building ROCm"
if
(
$null
-ne
$
script
:
DUMPBIN
)
{
build
& "
$
script
:
DUMPBIN
" /dependents "
${script:buildDir}
/bin/ollama_llama_server.exe
" | select-string "
.dll
"
# Ninja doesn't prefix with config name
}
${script:config}
=
""
sign
if
(
$null
-ne
$
script
:
DUMPBIN
)
{
install
& "
$
script
:
DUMPBIN
" /dependents "
${script:buildDir}
/bin/ollama_llama_server.exe
" | select-string "
.dll
"
}
sign
install
# Assumes v5.7, may need adjustments for v6
# Assumes v5.7, may need adjustments for v6
rm -ea 0 -recurse -force -path "
${script:SRC_DIR}
\dist\windows-
${script:ARCH}
\rocm\
"
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
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\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\
"
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
# 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
]
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment