1
1
# Define the default target now so that it is always the first target
2
- BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot train-text-from-scratch simple server libembdinput.so embd-input-test
2
+ BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot train-text-from-scratch simple server embd-input-test
3
+
4
+ # Binaries only useful for tests
5
+ TEST_TARGETS = tests/test-double-float tests/test-grad0 tests/test-opt tests/test-quantize-fns tests/test-quantize-perf tests/test-sampling tests/test-tokenizer-0
3
6
4
7
default : $(BUILD_TARGETS )
5
8
@@ -90,6 +93,28 @@ ifeq ($(UNAME_S),Haiku)
90
93
CXXFLAGS += -pthread
91
94
endif
92
95
96
+ # detect Windows
97
+ ifneq ($(findstring _NT,$(UNAME_S ) ) ,)
98
+ _WIN32 := 1
99
+ endif
100
+
101
+ # library name prefix
102
+ ifneq ($(_WIN32 ) ,1)
103
+ LIB_PRE := lib
104
+ endif
105
+
106
+ # Dynamic Shared Object extension
107
+ ifneq ($(_WIN32 ) ,1)
108
+ DSO_EXT := .so
109
+ else
110
+ DSO_EXT := .dll
111
+ endif
112
+
113
+ # Windows Sockets 2 (Winsock) for network-capable apps
114
+ ifeq ($(_WIN32 ) ,1)
115
+ LWINSOCK2 := -lws2_32
116
+ endif
117
+
93
118
ifdef LLAMA_GPROF
94
119
CFLAGS += -pg
95
120
CXXFLAGS += -pg
@@ -102,7 +127,7 @@ endif
102
127
# Architecture specific
103
128
# TODO: probably these flags need to be tweaked on some architectures
104
129
# feel free to update the Makefile for your architecture and send a pull request or issue
105
- ifeq ($(UNAME_M ) ,$(filter $(UNAME_M ) ,x86_64 i686) )
130
+ ifeq ($(UNAME_M ) ,$(filter $(UNAME_M ) ,x86_64 i686 amd64 ) )
106
131
# Use all CPU extensions that are available:
107
132
CFLAGS += -march=native -mtune=native
108
133
CXXFLAGS += -march=native -mtune=native
@@ -168,8 +193,12 @@ ifdef LLAMA_CUBLAS
168
193
CXXFLAGS += -DGGML_USE_CUBLAS -I/usr/local/cuda/include -I/opt/cuda/include -I$(CUDA_PATH)/targets/x86_64-linux/include
169
194
LDFLAGS += -lcublas -lculibos -lcudart -lcublasLt -lpthread -ldl -lrt -L/usr/local/cuda/lib64 -L/opt/cuda/lib64 -L$(CUDA_PATH)/targets/x86_64-linux/lib
170
195
OBJS += ggml-cuda.o
171
- NVCC = nvcc
172
196
NVCCFLAGS = --forward-unknown-to-host-compiler
197
+ ifdef LLAMA_CUDA_NVCC
198
+ NVCC = $(LLAMA_CUDA_NVCC)
199
+ else
200
+ NVCC = nvcc
201
+ endif # LLAMA_CUDA_NVCC
173
202
ifdef CUDA_DOCKER_ARCH
174
203
NVCCFLAGS += -Wno-deprecated-gpu-targets -arch=$(CUDA_DOCKER_ARCH)
175
204
else
@@ -198,19 +227,23 @@ ifdef LLAMA_CUDA_KQUANTS_ITER
198
227
else
199
228
NVCCFLAGS += -DK_QUANTS_PER_ITERATION=2
200
229
endif
201
-
230
+ ifdef LLAMA_CUDA_CCBIN
231
+ NVCCFLAGS += -ccbin $(LLAMA_CUDA_CCBIN)
232
+ endif
202
233
ggml-cuda.o : ggml-cuda.cu ggml-cuda.h
203
234
$(NVCC ) $(NVCCFLAGS ) $(CXXFLAGS ) -Wno-pedantic -c $< -o $@
204
235
endif # LLAMA_CUBLAS
205
236
206
237
ifdef LLAMA_CLBLAST
207
- CFLAGS += -DGGML_USE_CLBLAST
208
- CXXFLAGS += -DGGML_USE_CLBLAST
238
+
239
+ CFLAGS += -DGGML_USE_CLBLAST $(shell pkg-config --cflags clblast OpenCL)
240
+ CXXFLAGS += -DGGML_USE_CLBLAST $(shell pkg-config --cflags clblast OpenCL)
241
+
209
242
# Mac provides OpenCL as a framework
210
243
ifeq ($(UNAME_S),Darwin)
211
244
LDFLAGS += -lclblast -framework OpenCL
212
245
else
213
- LDFLAGS += -lclblast -lOpenCL
246
+ LDFLAGS += $(shell pkg-config --libs clblast OpenCL)
214
247
endif
215
248
OBJS += ggml-opencl.o
216
249
@@ -311,17 +344,20 @@ llama.o: llama.cpp ggml.h ggml-cuda.h ggml-metal.h llama.h llama-util.h
311
344
common.o : examples/common.cpp examples/common.h
312
345
$(CXX ) $(CXXFLAGS ) -c $< -o $@
313
346
347
+ grammar-parser.o : examples/grammar-parser.cpp examples/grammar-parser.h
348
+ $(CXX ) $(CXXFLAGS ) -c $< -o $@
349
+
314
350
libllama.so : llama.o ggml.o $(OBJS )
315
351
$(CXX ) $(CXXFLAGS ) -shared -fPIC -o $@ $^ $(LDFLAGS )
316
352
317
353
clean :
318
- rm -vf * .o * .so main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state server simple vdot train-text-from-scratch embd-input-test build-info.h
354
+ rm -vf * .o * .so * .dll main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state server simple vdot train-text-from-scratch embd-input-test build-info.h $( TEST_TARGETS )
319
355
320
356
#
321
357
# Examples
322
358
#
323
359
324
- main : examples/main/main.cpp build-info.h ggml.o llama.o common.o $(OBJS )
360
+ main : examples/main/main.cpp build-info.h ggml.o llama.o common.o grammar-parser.o $(OBJS )
325
361
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
326
362
@echo
327
363
@echo ' ==== Run ./main -h for help. ===='
@@ -346,14 +382,14 @@ save-load-state: examples/save-load-state/save-load-state.cpp build-info.h ggml.
346
382
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
347
383
348
384
server : examples/server/server.cpp examples/server/httplib.h examples/server/json.hpp build-info.h ggml.o llama.o common.o $(OBJS )
349
- $(CXX ) $(CXXFLAGS ) -Iexamples/server $(filter-out % .h,$(filter-out % .hpp,$^ ) ) -o $@ $(LDFLAGS )
385
+ $(CXX ) $(CXXFLAGS ) -Iexamples/server $(filter-out % .h,$(filter-out % .hpp,$^ ) ) -o $@ $(LDFLAGS ) $( LWINSOCK2 )
350
386
351
- libembdinput.so : examples/embd-input/embd-input.h examples/embd-input/embd-input-lib.cpp build-info.h ggml.o llama.o common.o $(OBJS )
387
+ $( LIB_PRE ) embdinput $( DSO_EXT ) : examples/embd-input/embd-input.h examples/embd-input/embd-input-lib.cpp build-info.h ggml.o llama.o common.o $(OBJS )
352
388
$(CXX ) --shared $(CXXFLAGS ) $(filter-out % .h,$(filter-out % .hpp,$^ ) ) -o $@ $(LDFLAGS )
353
389
354
390
355
- embd-input-test : libembdinput.so examples/embd-input/embd-input-test.cpp build-info.h ggml.o llama.o common.o $(OBJS )
356
- $(CXX ) $(CXXFLAGS ) $(filter-out % .so ,$(filter-out % .h,$(filter-out % .hpp,$^ ) ) ) -o $@ $(LDFLAGS ) -L. -lembdinput
391
+ embd-input-test : $( LIB_PRE ) embdinput $( DSO_EXT ) examples/embd-input/embd-input-test.cpp build-info.h ggml.o llama.o common.o $(OBJS )
392
+ $(CXX ) $(CXXFLAGS ) $(filter-out % $( DSO_EXT ) ,$(filter-out % .h,$(filter-out % .hpp,$^ ) ) ) -o $@ $(LDFLAGS ) -L. -lembdinput
357
393
358
394
train-text-from-scratch : examples/train-text-from-scratch/train-text-from-scratch.cpp build-info.h ggml.o llama.o $(OBJS )
359
395
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
@@ -370,13 +406,32 @@ build-info.h: $(wildcard .git/index) scripts/build-info.sh
370
406
# Tests
371
407
#
372
408
409
+ tests : $(TEST_TARGETS )
410
+
373
411
benchmark-matmult : examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o $(OBJS )
374
412
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
375
413
./$@
376
414
377
415
vdot : pocs/vdot/vdot.cpp ggml.o $(OBJS )
378
416
$(CXX ) $(CXXFLAGS ) $^ -o $@ $(LDFLAGS )
379
417
380
- .PHONY : tests clean
381
- tests :
382
- bash ./tests/run-tests.sh
418
+ tests/test-double-float : tests/test-double-float.c build-info.h ggml.o llama.o common.o $(OBJS )
419
+ $(CXX ) $(CXXFLAGS ) $(filter-out % .txt,$^ ) -o $@ $(LDFLAGS )
420
+
421
+ tests/test-grad0 : tests/test-grad0.c build-info.h ggml.o llama.o common.o $(OBJS )
422
+ $(CXX ) $(CXXFLAGS ) $(filter-out % .txt,$^ ) -o $@ $(LDFLAGS )
423
+
424
+ tests/test-opt : tests/test-opt.c build-info.h ggml.o llama.o common.o $(OBJS )
425
+ $(CXX ) $(CXXFLAGS ) $(filter-out % .txt,$^ ) -o $@ $(LDFLAGS )
426
+
427
+ tests/test-quantize-fns : tests/test-quantize-fns.cpp build-info.h ggml.o llama.o common.o $(OBJS )
428
+ $(CXX ) $(CXXFLAGS ) $(filter-out % .txt,$^ ) -o $@ $(LDFLAGS )
429
+
430
+ tests/test-quantize-perf : tests/test-quantize-perf.cpp build-info.h ggml.o llama.o common.o $(OBJS )
431
+ $(CXX ) $(CXXFLAGS ) $(filter-out % .txt,$^ ) -o $@ $(LDFLAGS )
432
+
433
+ tests/test-sampling : tests/test-sampling.cpp build-info.h ggml.o llama.o common.o $(OBJS )
434
+ $(CXX ) $(CXXFLAGS ) $(filter-out % .txt,$^ ) -o $@ $(LDFLAGS )
435
+
436
+ tests/test-tokenizer-0 : tests/test-tokenizer-0.cpp build-info.h ggml.o llama.o common.o $(OBJS )
437
+ $(CXX ) $(CXXFLAGS ) $(filter-out % .txt,$^ ) -o $@ $(LDFLAGS )
0 commit comments