Skip to content

Commit dcfb7a1

Browse files
mxyngjmorgancadhiltgen
authored
next build (ollama#8539)
* add build to .dockerignore * test: only build one arch * add build to .gitignore * fix ccache path * filter amdgpu targets * only filter if autodetecting * Don't clobber gpu list for default runner This ensures the GPU specific environment variables are set properly * explicitly set CXX compiler for HIP * Update build_windows.ps1 This isn't complete, but is close. Dependencies are missing, and it only builds the "default" preset. * build: add ollama subdir * add .git to .dockerignore * docs: update development.md * update build_darwin.sh * remove unused scripts * llm: add cwd and build/lib/ollama to library paths * default DYLD_LIBRARY_PATH to LD_LIBRARY_PATH in runner on macOS * add additional cmake output vars for msvc * interim edits to make server detection logic work with dll directories like lib/ollama/cuda_v12 * remove unncessary filepath.Dir, cleanup * add hardware-specific directory to path * use absolute server path * build: linux arm * cmake install targets * remove unused files * ml: visit each library path once * build: skip cpu variants on arm * build: install cpu targets * build: fix workflow * shorter names * fix rocblas install * docs: clean up development.md * consistent build dir removal in development.md * silence -Wimplicit-function-declaration build warnings in ggml-cpu * update readme * update development readme * llm: update library lookup logic now that there is one runner (ollama#8587) * tweak development.md * update docs * add windows cuda/rocm tests --------- Co-authored-by: jmorganca <[email protected]> Co-authored-by: Daniel Hiltgen <[email protected]>
1 parent 2ef3c80 commit dcfb7a1

File tree

542 files changed

+5778
-11451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

542 files changed

+5778
-11451
lines changed

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ ollama
33
app
44
macapp
55
dist
6+
build
67
.env
78
.cache
89
test_data
9-
llama/build
10+
.git
11+

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,14 @@ llama/**/*.cuh linguist-vendored
77
llama/**/*.m linguist-vendored
88
llama/**/*.metal linguist-vendored
99

10+
ml/backend/**/*.c linguist-vendored
11+
ml/backend/**/*.h linguist-vendored
12+
ml/backend/**/*.cpp linguist-vendored
13+
ml/backend/**/*.hpp linguist-vendored
14+
ml/backend/**/*.cu linguist-vendored
15+
ml/backend/**/*.cuh linguist-vendored
16+
ml/backend/**/*.m linguist-vendored
17+
ml/backend/**/*.metal linguist-vendored
18+
1019
* text=auto
1120
*.go text eol=lf

.github/workflows/release.yaml

Lines changed: 266 additions & 631 deletions
Large diffs are not rendered by default.

.github/workflows/test.yaml

Lines changed: 88 additions & 264 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
.venv
55
.swp
66
dist
7+
build
78
ollama
89
.cache
910
*.exe
1011
.idea
1112
test_data
1213
*.crt
13-
llama/build
1414
__debug_bin*
15-
llama/vendor
15+
llama/build
16+
llama/vendor

CMakeLists.txt

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
3+
project(Ollama C CXX)
4+
5+
include(CheckLanguage)
6+
7+
find_package(Threads REQUIRED)
8+
9+
set(CMAKE_BUILD_TYPE Release)
10+
set(BUILD_SHARED_LIBS ON)
11+
12+
set(CMAKE_CXX_STANDARD 17)
13+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
14+
set(CMAKE_CXX_EXTENSIONS OFF)
15+
16+
set(GGML_BUILD ON)
17+
set(GGML_SHARED ON)
18+
set(GGML_CCACHE ON)
19+
set(GGML_BACKEND_DL ON)
20+
set(GGML_BACKEND_SHARED ON)
21+
set(GGML_SCHED_MAX_COPIES 4)
22+
23+
set(GGML_LLAMAFILE ON)
24+
set(GGML_CUDA_PEER_MAX_BATCH_SIZE 128)
25+
set(GGML_CUDA_GRAPHS ON)
26+
27+
if((NOT CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
28+
OR (NOT CMAKE_OSX_ARCHITECTURES AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64|ARM64|ARMv[0-9]+"))
29+
set(GGML_CPU_ALL_VARIANTS ON)
30+
endif()
31+
32+
set(OLLAMA_BUILD_DIR ${CMAKE_BINARY_DIR}/lib/ollama)
33+
set(OLLAMA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib/ollama)
34+
35+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OLLAMA_BUILD_DIR})
36+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${OLLAMA_BUILD_DIR})
37+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${OLLAMA_BUILD_DIR})
38+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OLLAMA_BUILD_DIR})
39+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${OLLAMA_BUILD_DIR})
40+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${OLLAMA_BUILD_DIR})
41+
42+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src)
43+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src/include)
44+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src/ggml-cpu)
45+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src/ggml-cpu/amx)
46+
47+
set(GGML_CPU ON)
48+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src)
49+
set_property(TARGET ggml PROPERTY EXCLUDE_FROM_ALL TRUE)
50+
51+
get_target_property(CPU_VARIANTS ggml-cpu MANUALLY_ADDED_DEPENDENCIES)
52+
if(NOT CPU_VARIANTS)
53+
set(CPU_VARIANTS "ggml-cpu")
54+
endif()
55+
56+
install(TARGETS ggml-base ${CPU_VARIANTS}
57+
RUNTIME_DEPENDENCIES
58+
PRE_EXCLUDE_REGEXES ".*"
59+
RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
60+
LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
61+
FRAMEWORK DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
62+
)
63+
64+
check_language(CUDA)
65+
if(CMAKE_CUDA_COMPILER)
66+
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24" AND NOT CMAKE_CUDA_ARCHITECTURES)
67+
set(CMAKE_CUDA_ARCHITECTURES "native")
68+
endif()
69+
70+
find_package(CUDAToolkit)
71+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src/ggml-cuda)
72+
set(OLLAMA_CUDA_INSTALL_DIR ${OLLAMA_INSTALL_DIR}/cuda_v${CUDAToolkit_VERSION_MAJOR})
73+
install(TARGETS ggml-cuda
74+
RUNTIME_DEPENDENCIES
75+
DIRECTORIES ${CUDAToolkit_BIN_DIR} ${CUDAToolkit_LIBRARY_DIR}
76+
PRE_INCLUDE_REGEXES cublas cublasLt cudart
77+
PRE_EXCLUDE_REGEXES ".*"
78+
RUNTIME DESTINATION ${OLLAMA_CUDA_INSTALL_DIR} COMPONENT CUDA
79+
LIBRARY DESTINATION ${OLLAMA_CUDA_INSTALL_DIR} COMPONENT CUDA
80+
)
81+
endif()
82+
83+
check_language(HIP)
84+
if(CMAKE_HIP_COMPILER)
85+
set(HIP_PLATFORM "amd")
86+
87+
find_package(hip REQUIRED)
88+
if(NOT AMDGPU_TARGETS)
89+
list(FILTER AMDGPU_TARGETS INCLUDE REGEX "^gfx(900|94[012]|101[02]|1030|110[012])$")
90+
endif()
91+
92+
if(AMDGPU_TARGETS)
93+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src/ggml-hip)
94+
set(OLLAMA_HIP_INSTALL_DIR ${OLLAMA_INSTALL_DIR}/rocm)
95+
install(TARGETS ggml-hip
96+
RUNTIME_DEPENDENCIES
97+
DIRECTORIES ${HIP_BIN_INSTALL_DIR} ${HIP_LIB_INSTALL_DIR}
98+
PRE_INCLUDE_REGEXES amdhip64 hipblas rocblas amd_comgr hsa_runtime64 rocprofiler-register drm_amdgpu drm numa
99+
PRE_EXCLUDE_REGEXES ".*"
100+
POST_EXCLUDE_REGEXES "system32"
101+
RUNTIME DESTINATION ${OLLAMA_HIP_INSTALL_DIR} COMPONENT HIP
102+
LIBRARY DESTINATION ${OLLAMA_HIP_INSTALL_DIR} COMPONENT HIP
103+
)
104+
105+
foreach(HIP_LIB_BIN_INSTALL_DIR IN ITEMS ${HIP_BIN_INSTALL_DIR} ${HIP_LIB_INSTALL_DIR})
106+
if(EXISTS ${HIP_LIB_BIN_INSTALL_DIR}/rocblas)
107+
install(DIRECTORY ${HIP_LIB_BIN_INSTALL_DIR}/rocblas DESTINATION ${OLLAMA_HIP_INSTALL_DIR} COMPONENT HIP)
108+
break()
109+
endif()
110+
endforeach()
111+
endif()
112+
endif()

CMakePresets.json

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"version": 3,
3+
"configurePresets": [
4+
{
5+
"name": "Default",
6+
"binaryDir": "${sourceDir}/build",
7+
"installDir": "${sourceDir}/dist",
8+
"cacheVariables": {
9+
"CMAKE_BUILD_TYPE": "Release"
10+
}
11+
},
12+
{
13+
"name": "CPU",
14+
"inherits": [ "Default" ]
15+
},
16+
{
17+
"name": "CUDA",
18+
"inherits": [ "Default" ]
19+
},
20+
{
21+
"name": "CUDA 11",
22+
"inherits": [ "CUDA" ],
23+
"cacheVariables": {
24+
"CMAKE_CUDA_ARCHITECTURES": "50;52;53;60;61;62;70;72;75;80;86"
25+
}
26+
},
27+
{
28+
"name": "CUDA 12",
29+
"inherits": [ "CUDA" ],
30+
"cacheVariables": {
31+
"CMAKE_CUDA_ARCHITECTURES": "60;61;62;70;72;75;80;86;87;89;90;90a"
32+
}
33+
},
34+
{
35+
"name": "JetPack 5",
36+
"inherits": [ "CUDA" ],
37+
"cacheVariables": {
38+
"CMAKE_CUDA_ARCHITECTURES": "72;87"
39+
}
40+
},
41+
{
42+
"name": "JetPack 6",
43+
"inherits": [ "CUDA" ],
44+
"cacheVariables": {
45+
"CMAKE_CUDA_ARCHITECTURES": "87"
46+
}
47+
},
48+
{
49+
"name": "ROCm",
50+
"inherits": [ "Default" ],
51+
"cacheVariables": {
52+
"CMAKE_HIP_PLATFORM": "amd"
53+
}
54+
},
55+
{
56+
"name": "ROCm 6",
57+
"inherits": [ "ROCm" ],
58+
"cacheVariables": {
59+
"AMDGPU_TARGETS": "gfx900;gfx940;gfx941;gfx942;gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102"
60+
}
61+
}
62+
],
63+
"buildPresets": [
64+
{
65+
"name": "Default",
66+
"configurePreset": "Default",
67+
"configuration": "Release"
68+
},
69+
{
70+
"name": "CPU",
71+
"configurePreset": "Default",
72+
"targets": [ "ggml-cpu" ]
73+
},
74+
{
75+
"name": "CUDA",
76+
"configurePreset": "CUDA",
77+
"targets": [ "ggml-cuda" ]
78+
},
79+
{
80+
"name": "CUDA 11",
81+
"inherits": [ "CUDA" ],
82+
"configurePreset": "CUDA 11"
83+
},
84+
{
85+
"name": "CUDA 12",
86+
"inherits": [ "CUDA" ],
87+
"configurePreset": "CUDA 12"
88+
},
89+
{
90+
"name": "JetPack 5",
91+
"inherits": [ "CUDA" ],
92+
"configurePreset": "JetPack 5"
93+
},
94+
{
95+
"name": "JetPack 6",
96+
"inherits": [ "CUDA" ],
97+
"configurePreset": "JetPack 6"
98+
},
99+
{
100+
"name": "ROCm",
101+
"configurePreset": "ROCm",
102+
"targets": [ "ggml-hip" ]
103+
},
104+
{
105+
"name": "ROCm 6",
106+
"inherits": [ "ROCm" ],
107+
"configurePreset": "ROCm 6"
108+
}
109+
]
110+
}

0 commit comments

Comments
 (0)