development.md 3.96 KB
Newer Older
Bruce MacDonald's avatar
Bruce MacDonald committed
1
2
# Development

Michael Yang's avatar
Michael Yang committed
3
Install prerequisites:
4

Michael Yang's avatar
Michael Yang committed
5
- [Go](https://go.dev/doc/install)
6
- C/C++ Compiler e.g. Clang on macOS, [TDM-GCC](https://github.com/jmeubank/tdm-gcc/releases/latest) (Windows amd64) or [llvm-mingw](https://github.com/mstorsjo/llvm-mingw) (Windows arm64), GCC/Clang on Linux.
7

Michael Yang's avatar
Michael Yang committed
8
Then build and run Ollama from the root directory of the repository:
9

10
```shell
Michael Yang's avatar
Michael Yang committed
11
go run . serve
12
13
```

14
15
16
17
> [!NOTE]
> Ollama includes native code compiled with CGO.  From time to time these data structures can change and CGO can get out of sync resulting in unexpected crashes.  You can force a full build of the native code by running `go clean -cache` first. 


Michael Yang's avatar
Michael Yang committed
18
## macOS (Apple Silicon)
19

Michael Yang's avatar
Michael Yang committed
20
macOS Apple Silicon supports Metal which is built-in to the Ollama binary. No additional steps are required.
21

Michael Yang's avatar
Michael Yang committed
22
## macOS (Intel)
23

Michael Yang's avatar
Michael Yang committed
24
Install prerequisites:
25

Michael Yang's avatar
Michael Yang committed
26
- [CMake](https://cmake.org/download/) or `brew install cmake`
27

Michael Yang's avatar
Michael Yang committed
28
Then, configure and build the project:
29

30
```shell
Michael Yang's avatar
Michael Yang committed
31
32
cmake -B build
cmake --build build
33
34
```

Michael Yang's avatar
Michael Yang committed
35
Lastly, run Ollama:
36

37
```shell
Michael Yang's avatar
Michael Yang committed
38
go run . serve
39
40
```

Michael Yang's avatar
Michael Yang committed
41
## Windows
42

Michael Yang's avatar
Michael Yang committed
43
Install prerequisites:
44

Michael Yang's avatar
Michael Yang committed
45
46
47
- [CMake](https://cmake.org/download/)
- [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) including the Native Desktop Workload
- (Optional) AMD GPU support
Chuanhui Liu's avatar
Chuanhui Liu committed
48
    - [ROCm](https://rocm.docs.amd.com/en/latest/)
Michael Yang's avatar
Michael Yang committed
49
50
51
    - [Ninja](https://github.com/ninja-build/ninja/releases)
- (Optional) NVIDIA GPU support
    - [CUDA SDK](https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=11&target_type=exe_network)
52

Michael Yang's avatar
Michael Yang committed
53
Then, configure and build the project:
54

55
```shell
Michael Yang's avatar
Michael Yang committed
56
57
cmake -B build
cmake --build build --config Release
58
59
```

60
61
62
63
64
65
66
67
> [!IMPORTANT]
> Building for ROCm requires additional flags:
> ```
> cmake -B build -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
> cmake --build build --config Release
> ```


Michael Yang's avatar
Michael Yang committed
68
Lastly, run Ollama:
69

70
```shell
Michael Yang's avatar
Michael Yang committed
71
72
go run . serve
```
73

Michael Yang's avatar
Michael Yang committed
74
## Windows (ARM)
75

Daniel Hiltgen's avatar
Daniel Hiltgen committed
76
Windows ARM does not support additional acceleration libraries at this time.  Do not use cmake, simply `go run` or `go build`.
77

Michael Yang's avatar
Michael Yang committed
78
## Linux
79

Michael Yang's avatar
Michael Yang committed
80
Install prerequisites:
81

Michael Yang's avatar
Michael Yang committed
82
83
84
85
86
- [CMake](https://cmake.org/download/) or `sudo apt install cmake` or `sudo dnf install cmake`
- (Optional) AMD GPU support
    - [ROCm](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/install/quick-start.html)
- (Optional) NVIDIA GPU support
    - [CUDA SDK](https://developer.nvidia.com/cuda-downloads)
87

Michael Yang's avatar
Michael Yang committed
88
89
> [!IMPORTANT]
> Ensure prerequisites are in `PATH` before running CMake.
90
91


Michael Yang's avatar
Michael Yang committed
92
Then, configure and build the project:
93

94
```shell
Michael Yang's avatar
Michael Yang committed
95
96
cmake -B build
cmake --build build
97
98
```

Michael Yang's avatar
Michael Yang committed
99
Lastly, run Ollama:
100

101
```shell
Michael Yang's avatar
Michael Yang committed
102
go run . serve
103
104
```

Michael Yang's avatar
Michael Yang committed
105
## Docker
106

107
```shell
Michael Yang's avatar
Michael Yang committed
108
docker build .
109
110
```

Michael Yang's avatar
Michael Yang committed
111
112
### ROCm

113
```shell
Michael Yang's avatar
Michael Yang committed
114
docker build --build-arg FLAVOR=rocm .
115
116
```

Michael Yang's avatar
Michael Yang committed
117
118
119
## Running tests

To run tests, use `go test`:
120

121
```shell
Michael Yang's avatar
Michael Yang committed
122
go test ./...
123
```
124

125
> NOTE: In rare circumstances, you may need to change a package using the new
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
> "synctest" package in go1.24.
>
> If you do not have the "synctest" package enabled, you will not see build or
> test failures resulting from your change(s), if any, locally, but CI will
> break.
>
> If you see failures in CI, you can either keep pushing changes to see if the
> CI build passes, or you can enable the "synctest" package locally to see the
> failures before pushing.
>
> To enable the "synctest" package for testing, run the following command:
>
> ```shell
> GOEXPERIMENT=synctest go test ./...
> ```
>
> If you wish to enable synctest for all go commands, you can set the
> `GOEXPERIMENT` environment variable in your shell profile or by using:
>
> ```shell
> go env -w GOEXPERIMENT=synctest
> ```
>
> Which will enable the "synctest" package for all go commands without needing
> to set it for all shell sessions.
>
> The synctest package is not required for production builds.

154
155
156
157
158
159
160
161
162
## Library detection

Ollama looks for acceleration libraries in the following paths relative to the `ollama` executable:

* `./lib/ollama` (Windows)
* `../lib/ollama` (Linux)
* `.` (macOS)
* `build/lib/ollama` (for development)

Chuanhui Liu's avatar
Chuanhui Liu committed
163
If the libraries are not found, Ollama will not run with any acceleration libraries.