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
OpenDAS
ollama
Commits
652c273f
Unverified
Commit
652c273f
authored
Aug 19, 2024
by
Daniel Hiltgen
Committed by
GitHub
Aug 19, 2024
Browse files
Merge pull request #5049 from dhiltgen/cuda_v12
Cuda v12
parents
88e77050
f9e31da9
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
27 deletions
+101
-27
scripts/build_windows.ps1
scripts/build_windows.ps1
+59
-20
scripts/install.sh
scripts/install.sh
+30
-5
scripts/rh_linux_deps.sh
scripts/rh_linux_deps.sh
+12
-2
No files found.
scripts/build_windows.ps1
View file @
652c273f
...
...
@@ -7,6 +7,7 @@
$Error
ActionPreference
=
"Stop"
function
checkEnv
()
{
$
script
:
ARCH
=
$
Env
:
PROCESSOR_ARCHITECTURE
.
ToLower
()
$
script
:
TARGET_ARCH
=
$
Env
:
PROCESSOR_ARCHITECTURE
.
ToLower
()
Write-host
"Building for
${script:TARGET_ARCH}
"
write-host
"Locating required tools and paths"
...
...
@@ -15,26 +16,23 @@ function checkEnv() {
$MSVC_INSTALL
=
(
Get-CimInstance
MSFT_VSInstance
-Namespace
root/cimv2/vs
)[
0
]
.
InstallLocation
$
env
:
VCToolsRedistDir
=
(
get-item
"
${MSVC_INSTALL}
\VC\Redist\MSVC\*"
)[
0
]
}
# Try to find the CUDA dir
if
(
$null
-eq
$
env
:
NVIDIA_DIR
)
{
# Locate CUDA versions
# Note: this assumes every version found will be built
$cudaList
=
(
get-item
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v*\bin\"
-ea
'silentlycontinue'
)
if
(
$cudaList
.
length
-eq
0
)
{
$d
=
(
get-command
-ea
'silentlycontinue'
nvcc
)
.
path
if
(
$d
-ne
$null
)
{
$
script
:
NVIDIA_DIR
=
(
$d
|
split-path
-parent
)
}
else
{
$cudaList
=
(
get-item
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v*\bin\"
-ea
'silentlycontinue'
)
if
(
$cudaList
.
length
>
0
)
{
$
script
:
NVIDIA_DIR
=
$cudaList
[
0
]
}
if
(
$null
-ne
$d
)
{
$
script
:
CUDA_DIRS
=
@(
$d
|
split-path
-parent
)
}
}
else
{
$
script
:
NVIDI
A_DIR
=
$
env
:
NVIDIA_DIR
$
script
:
CUD
A_DIR
S
=
$
cudaList
}
$
script
:
INNO_SETUP_DIR
=
(
get-item
"C:\Program Files*\Inno Setup*\"
)[
0
]
$
script
:
DEPS_DIR
=
"
${script:SRC_DIR}
\dist\windows-
${script:TARGET_ARCH}
"
$
env
:
CGO_ENABLED
=
"1"
echo
"Checking version"
Write-Output
"Checking version"
if
(
!
$
env
:
VERSION
)
{
$data
=
(
git
describe
--tags
--first-parent
--abbrev
=
7
--long
--dirty
--always
)
$pattern
=
"v(.+)"
...
...
@@ -71,7 +69,48 @@ function checkEnv() {
function
buildOllama
()
{
write-host
"Building ollama CLI"
if
(
$null
-eq
${env:OLLAMA_SKIP_GENERATE}
)
{
&
go
generate
.
/...
Remove-Item
-ea
0
-recurse
-force
-path
"
${script:SRC_DIR}
\dist\windows-
${script:ARCH}
"
# TODO - consider trying to parallelize this with Start-ThreadJob, but env vars can't be used to toggle
# which targets to build
# Start by skipping CUDA to build everything else
pwsh
-Command
{
$
env
:
OLLAMA_SKIP_CUDA_GENERATE
=
"1"
;
&
go
generate
.
/...
}
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
# Then skip everyhting else and build all the CUDA variants
foreach
(
$
env
:
CUDA_LIB_DIR
in
$
script
:
CUDA_DIRS
)
{
write-host
"Building CUDA
${env:CUDA_LIB_DIR}
"
if
(
$
env
:
CUDA_LIB_DIR
.
Contains
(
"v12"
))
{
pwsh
-Command
{
$
env
:
OLLAMA_SKIP_CUDA_GENERATE
=
""
$
env
:
OLLAMA_SKIP_STATIC_GENERATE
=
"1"
$
env
:
OLLAMA_SKIP_CPU_GENERATE
=
"1"
$
env
:
OLLAMA_SKIP_ONEAPI_GENERATE
=
"1"
$
env
:
OLLAMA_SKIP_ROCM_GENERATE
=
"1"
$
env
:
CMAKE_CUDA_ARCHITECTURES
=
"60;61;62;70;72;75;80;86;87;89;90;90a"
$
env
:
OLLAMA_CUSTOM_CUDA_DEFS
=
"-DGGML_CUDA_USE_GRAPHS=on"
$
env
:
CUDA_PATH
=
split-path
-path
$
env
:
CUDA_LIB_DIR
-parent
$
env
:
PATH
=
"
$
envs
:
CUDA_LIB_DIR
;
$
env
:
PATH
"
&
go
generate
.
/...
}
}
else
{
pwsh
-Command
{
$
env
:
OLLAMA_SKIP_CUDA_GENERATE
=
""
$
env
:
OLLAMA_SKIP_STATIC_GENERATE
=
"1"
$
env
:
OLLAMA_SKIP_CPU_GENERATE
=
"1"
$
env
:
OLLAMA_SKIP_ONEAPI_GENERATE
=
"1"
$
env
:
OLLAMA_SKIP_ROCM_GENERATE
=
"1"
$
env
:
CMAKE_CUDA_ARCHITECTURES
=
"50;52;53;60;61;62;70;72;75;80;86"
$
env
:
OLLAMA_CUSTOM_CUDA_DEFS
=
""
$
env
:
CUDA_PATH
=
split-path
-path
$
env
:
CUDA_LIB_DIR
-parent
$
env
:
PATH
=
"
$
envs
:
CUDA_LIB_DIR
;
$
env
:
PATH
"
&
go
generate
.
/...
}
}
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
}
if
(
$LASTEXITCODE
-ne
0
)
{
exit
(
$LASTEXITCODE
)}
}
else
{
write-host
"Skipping generate step with OLLAMA_SKIP_GENERATE set"
...
...
@@ -83,8 +122,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-
${script:TARGET_ARCH}
\
-Force
cp
.
\ollama.exe
.
\dist\windows-
${script:TARGET_ARCH}
\
New-Item
-ItemType
Directory
-Path
.
\dist\windows-
${script:TARGET_ARCH}
\
bin\
-Force
cp
.
\ollama.exe
.
\dist\windows-
${script:TARGET_ARCH}
\
bin\
}
function
buildApp
()
{
...
...
@@ -103,22 +142,22 @@ function buildApp() {
function
gatherDependencies
()
{
write-host
"Gathering runtime dependencies"
cd
"
${script:SRC_DIR}
"
md
"
${script:DEPS_DIR}
\ollama
_runners
"
-ea
0
>
$null
md
"
${script:DEPS_DIR}
\
lib\
ollama"
-ea
0
>
$null
# TODO - this varies based on host build system and MSVC version - drive from dumpbin output
# currently works for Win11 + MSVC 2019 + Cuda V11
cp
"
${env:VCToolsRedistDir}
\x64\Microsoft.VC*.CRT\msvcp140*.dll"
"
${script:DEPS_DIR}
\ollama
_runners
\"
cp
"
${env:VCToolsRedistDir}
\x64\Microsoft.VC*.CRT\vcruntime140.dll"
"
${script:DEPS_DIR}
\ollama
_runners
\"
cp
"
${env:VCToolsRedistDir}
\x64\Microsoft.VC*.CRT\vcruntime140_1.dll"
"
${script:DEPS_DIR}
\ollama
_runners
\"
cp
"
${env:VCToolsRedistDir}
\x64\Microsoft.VC*.CRT\msvcp140*.dll"
"
${script:DEPS_DIR}
\
lib\
ollama\"
cp
"
${env:VCToolsRedistDir}
\x64\Microsoft.VC*.CRT\vcruntime140.dll"
"
${script:DEPS_DIR}
\
lib\
ollama\"
cp
"
${env:VCToolsRedistDir}
\x64\Microsoft.VC*.CRT\vcruntime140_1.dll"
"
${script:DEPS_DIR}
\
lib\
ollama\"
foreach
(
$part
in
$
(
"runtime"
,
"stdio"
,
"filesystem"
,
"math"
,
"convert"
,
"heap"
,
"string"
,
"time"
,
"locale"
,
"environment"
))
{
cp
"
$
env
:
VCToolsRedistDir
\..\..\..\Tools\Llvm\x64\bin\api-ms-win-crt-
${part}
*.dll"
"
${script:DEPS_DIR}
\ollama
_runners
\"
cp
"
$
env
:
VCToolsRedistDir
\..\..\..\Tools\Llvm\x64\bin\api-ms-win-crt-
${part}
*.dll"
"
${script:DEPS_DIR}
\
lib\
ollama\"
}
cp
"
${script:SRC_DIR}
\app\ollama_welcome.ps1"
"
${script:SRC_DIR}
\dist\"
if
(
"
${env:KEY_CONTAINER}
"
)
{
write-host
"about to sign"
foreach
(
$file
in
(
get-childitem
"
${script:DEPS_DIR}
\
cud
a\cu*.dll"
)
+
@(
"
${script:SRC_DIR}
\dist\ollama_welcome.ps1"
)){
foreach
(
$file
in
(
get-childitem
"
${script:DEPS_DIR}
\
lib\ollam
a\cu*.dll"
)
+
@(
"
${script:SRC_DIR}
\dist\ollama_welcome.ps1"
)){
write-host
"signing
$file
"
&
"
${script:SignTool}
"
sign
/v
/fd
sha256
/t
http://timestamp.digicert.com
/f
"
${script:OLLAMA_CERT}
"
`
/csp
"Google Cloud KMS Provider"
/kc
${env:KEY_CONTAINER}
$file
...
...
scripts/install.sh
View file @
652c273f
...
...
@@ -63,16 +63,36 @@ if [ -n "$NEEDS" ]; then
exit
1
fi
status
"Downloading ollama..."
curl
--fail
--show-error
--location
--progress-bar
-o
$TEMP_DIR
/ollama
"https://ollama.com/download/ollama-linux-
${
ARCH
}${
VER_PARAM
}
"
for
BINDIR
in
/usr/local/bin /usr/bin /bin
;
do
echo
$PATH
|
grep
-q
$BINDIR
&&
break
||
continue
done
OLLAMA_INSTALL_DIR
=
$(
dirname
${
BINDIR
}
)
status
"Installing ollama to
$
BINDIR
...
"
status
"Installing ollama to
$
OLLAMA_INSTALL_DIR
"
$SUDO
install
-o0
-g0
-m755
-d
$BINDIR
$SUDO
install
-o0
-g0
-m755
$TEMP_DIR
/ollama
$BINDIR
/ollama
$SUDO
install
-o0
-g0
-m755
-d
"
$OLLAMA_INSTALL_DIR
"
if
curl
-I
--silent
--fail
--location
"https://ollama.com/download/ollama-linux-
${
ARCH
}
.tgz
${
VER_PARAM
}
"
>
/dev/null
;
then
status
"Downloading Linux
${
ARCH
}
bundle"
curl
--fail
--show-error
--location
--progress-bar
\
"https://ollama.com/download/ollama-linux-
${
ARCH
}
.tgz
${
VER_PARAM
}
"
|
\
$SUDO
tar
-xzf
-
-C
"
$OLLAMA_INSTALL_DIR
"
BUNDLE
=
1
if
[
"
$OLLAMA_INSTALL_DIR
/bin/ollama"
!=
"
$BINDIR
/ollama"
]
;
then
status
"Making ollama accessible in the PATH in
$BINDIR
"
$SUDO
ln
-sf
"
$OLLAMA_INSTALL_DIR
/ollama"
"
$BINDIR
/ollama"
fi
else
status
"Downloading Linux
${
ARCH
}
CLI"
curl
--fail
--show-error
--location
--progress-bar
-o
"
$TEMP_DIR
/ollama"
\
"https://ollama.com/download/ollama-linux-
${
ARCH
}${
VER_PARAM
}
"
$SUDO
install
-o0
-g0
-m755
$TEMP_DIR
/ollama
$OLLAMA_INSTALL_DIR
/ollama
BUNDLE
=
0
if
[
"
$OLLAMA_INSTALL_DIR
/ollama"
!=
"
$BINDIR
/ollama"
]
;
then
status
"Making ollama accessible in the PATH in
$BINDIR
"
$SUDO
ln
-sf
"
$OLLAMA_INSTALL_DIR
/ollama"
"
$BINDIR
/ollama"
fi
fi
install_success
()
{
status
'The Ollama API is now available at 127.0.0.1:11434.'
...
...
@@ -178,6 +198,11 @@ if ! check_gpu lspci nvidia && ! check_gpu lshw nvidia && ! check_gpu lspci amdg
fi
if
check_gpu lspci amdgpu
||
check_gpu lshw amdgpu
;
then
if
[
$BUNDLE
-ne
0
]
;
then
install_success
status
"AMD GPU ready."
exit
0
fi
# Look for pre-existing ROCm v6 before downloading the dependencies
for
search
in
"
${
HIP_PATH
:-
''
}
"
"
${
ROCM_PATH
:-
''
}
"
"/opt/rocm"
"/usr/lib64"
;
do
if
[
-n
"
${
search
}
"
]
&&
[
-e
"
${
search
}
/libhipblas.so.2"
-o
-e
"
${
search
}
/lib/libhipblas.so.2"
]
;
then
...
...
scripts/rh_linux_deps.sh
View file @
652c273f
...
...
@@ -3,6 +3,7 @@
# Script for common Dockerfile dependency installation in redhat linux based images
set
-ex
set
-o
pipefail
MACHINE
=
$(
uname
-m
)
if
grep
-i
"centos"
/etc/system-release
>
/dev/null
;
then
...
...
@@ -29,7 +30,7 @@ if grep -i "centos" /etc/system-release >/dev/null; then
dnf
install
-y
rh-git227-git
ln
-s
/opt/rh/rh-git227/root/usr/bin/git /usr/local/bin/git
fi
dnf
install
-y
devtoolset-10-gcc devtoolset-10-gcc-c++
dnf
install
-y
devtoolset-10-gcc devtoolset-10-gcc-c++
pigz
elif
grep
-i
"rocky"
/etc/system-release
>
/dev/null
;
then
# Temporary workaround until rocky 8 AppStream ships GCC 10.4 (10.3 is incompatible with NVCC)
cat
<<
EOF
> /etc/yum.repos.d/Rocky-Vault.repo
...
...
@@ -43,12 +44,21 @@ gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
EOF
dnf
install
-y
git
\
gcc-toolset-10-gcc-10.2.1-8.2.el8
\
gcc-toolset-10-gcc-c++-10.2.1-8.2.el8
gcc-toolset-10-gcc-c++-10.2.1-8.2.el8
\
pigz
else
echo
"ERROR Unexpected distro"
exit
1
fi
if
[
"
${
MACHINE
}
"
=
"x86_64"
]
;
then
curl
-s
-L
https://github.com/ccache/ccache/releases/download/v4.10.2/ccache-4.10.2-linux-x86_64.tar.xz |
tar
-Jx
-C
/tmp
--strip-components
1
&&
\
mv
/tmp/ccache /usr/local/bin/
else
yum
-y
install
epel-release
yum
install
-y
ccache
fi
if
[
-n
"
${
CMAKE_VERSION
}
"
]
;
then
curl
-s
-L
https://github.com/Kitware/CMake/releases/download/v
${
CMAKE_VERSION
}
/cmake-
${
CMAKE_VERSION
}
-linux-
$(
uname
-m
)
.tar.gz |
tar
-zx
-C
/usr
--strip-components
1
fi
...
...
Prev
1
2
Next
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