Skip to content

Commit b1a4256

Browse files
authored
Add metal support (#80)
1 parent 3f10005 commit b1a4256

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

.github/workflows/test.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,22 @@ jobs:
3535
- name: Test
3636
run: |
3737
make test
38+
39+
macOS-metal-latest:
40+
runs-on: macOS-latest
41+
42+
steps:
43+
- name: Clone
44+
uses: actions/checkout@v3
45+
with:
46+
submodules: true
47+
48+
- name: Dependencies
49+
run: |
50+
brew update
51+
brew install sdl2
52+
53+
- name: Test
54+
run: |
55+
make BUILD_TYPE=metal test
56+
CGO_LDFLAGS="-framework Foundation -framework Metal -framework MetalKit -framework MetalPerformanceShaders" LIBRARY_PATH=$PWD C_INCLUDE_PATH=$PWD go build -o testbuild ./examples

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ ifeq ($(BUILD_TYPE),clblas)
143143
EXTRA_TARGETS+=llama.cpp/ggml-opencl.o
144144
endif
145145

146+
ifeq ($(BUILD_TYPE),metal)
147+
EXTRA_LIBS=
148+
CMAKE_ARGS+=-DLLAMA_METAL=ON
149+
EXTRA_TARGETS+=llama.cpp/ggml-metal.o
150+
endif
151+
146152
ifdef CLBLAST_DIR
147153
CMAKE_ARGS+=-DCLBlast_dir=$(CLBLAST_DIR)
148154
endif
@@ -178,6 +184,9 @@ llama.cpp/ggml-cuda.o: llama.cpp/ggml.o
178184
llama.cpp/ggml-opencl.o: llama.cpp/ggml.o
179185
cd build && cp -rf CMakeFiles/ggml.dir/ggml-opencl.cpp.o ../llama.cpp/ggml-opencl.o
180186

187+
llama.cpp/ggml-metal.o: llama.cpp/ggml.o
188+
cd build && cp -rf CMakeFiles/ggml.dir/ggml-metal.m.o ../llama.cpp/ggml-metal.o
189+
181190
llama.cpp/llama.o:
182191
$(MAKE) -C llama.cpp llama.o
183192

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ BUILD_TYPE=clblas CLBLAS_DIR=... make libbinding.a
5858
CGO_LDFLAGS="-lOpenCL -lclblast -L/usr/local/lib64/" LIBRARY_PATH=$PWD C_INCLUDE_PATH=$PWD go run ./examples -m "/model/path/here" -t 14
5959
```
6060

61+
6162
You should see something like this from the output when using the GPU:
6263

6364
```
@@ -66,6 +67,15 @@ ggml_opencl: selecting device: 'Intel(R) Graphics [0x46a6]'
6667
ggml_opencl: device FP16 support: true
6768
```
6869

70+
## GPU offloading
71+
72+
### Metal (Apple Silicon)
73+
74+
```
75+
BUILD_TYPE=metal make libbinding.a
76+
CGO_LDFLAGS="-framework Foundation -framework Metal -framework MetalKit -framework MetalPerformanceShaders" LIBRARY_PATH=$PWD C_INCLUDE_PATH=$PWD go run ./examples -m "/model/path/here" -t 14
77+
```
78+
6979
Enjoy!
7080

7181
The documentation is available [here](https://pkg.go.dev/github.com/go-skynet/go-llama.cpp) and the full example code is [here](https://github.com/go-skynet/go-llama.cpp/blob/master/examples/main.go).

llama.cpp

0 commit comments

Comments
 (0)