Makefile 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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 convert-llama2c-to-ggml simple save-load-state server embd-input-test gguf llama-bench baby-llama beam-search tests/test-c.o
  3. # Binaries only useful for tests
  4. TEST_TARGETS = tests/test-llama-grammar tests/test-grammar-parser 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-llama tests/test-tokenizer-0-falcon tests/test-tokenizer-1
  5. default: $(BUILD_TARGETS)
  6. test:
  7. @echo "Running tests..."
  8. @for test_target in $(TEST_TARGETS); do \
  9. if [ "$$test_target" = "tests/test-tokenizer-0-llama" ]; then \
  10. ./$$test_target $(CURDIR)/models/ggml-vocab-llama.gguf; \
  11. elif [ "$$test_target" = "tests/test-tokenizer-0-falcon" ]; then \
  12. continue; \
  13. elif [ "$$test_target" = "tests/test-tokenizer-1" ]; then \
  14. continue; \
  15. else \
  16. ./$$test_target; \
  17. fi; \
  18. done
  19. @echo "All tests have been run."
  20. all: $(BUILD_TARGETS) $(TEST_TARGETS)
  21. ifndef UNAME_S
  22. UNAME_S := $(shell uname -s)
  23. endif
  24. ifndef UNAME_P
  25. UNAME_P := $(shell uname -p)
  26. endif
  27. ifndef UNAME_M
  28. UNAME_M := $(shell uname -m)
  29. endif
  30. CCV := $(shell $(CC) --version | head -n 1)
  31. CXXV := $(shell $(CXX) --version | head -n 1)
  32. # Mac OS + Arm can report x86_64
  33. # ref: https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment-1282546789
  34. ifeq ($(UNAME_S),Darwin)
  35. ifneq ($(UNAME_P),arm)
  36. SYSCTL_M := $(shell sysctl -n hw.optional.arm64 2>/dev/null)
  37. ifeq ($(SYSCTL_M),1)
  38. # UNAME_P := arm
  39. # UNAME_M := arm64
  40. warn := $(warning Your arch is announced as x86_64, but it seems to actually be ARM64. Not fixing that can lead to bad performance. For more info see: https://github.com/ggerganov/whisper.cpp/issues/66\#issuecomment-1282546789)
  41. endif
  42. endif
  43. endif
  44. #
  45. # Compile flags
  46. #
  47. # keep standard at C11 and C++11
  48. # -Ofast tends to produce faster code, but may not be available for some compilers.
  49. ifdef LLAMA_FAST
  50. OPT = -Ofast
  51. else
  52. OPT = -O3
  53. endif
  54. CFLAGS = -I. $(OPT) -std=c11 -fPIC
  55. CXXFLAGS = -I. -I./common $(OPT) -std=c++11 -fPIC
  56. LDFLAGS =
  57. ifdef LLAMA_DEBUG
  58. CFLAGS += -O0 -g
  59. CXXFLAGS += -O0 -g
  60. LDFLAGS += -g
  61. else
  62. CFLAGS += -DNDEBUG
  63. CXXFLAGS += -DNDEBUG
  64. endif
  65. ifdef LLAMA_SERVER_VERBOSE
  66. CXXFLAGS += -DSERVER_VERBOSE=$(LLAMA_SERVER_VERBOSE)
  67. endif
  68. # warnings
  69. CFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith \
  70. -Wmissing-prototypes -Werror=implicit-int
  71. CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wno-multichar
  72. # OS specific
  73. # TODO: support Windows
  74. ifeq ($(UNAME_S),Linux)
  75. CFLAGS += -pthread
  76. CXXFLAGS += -pthread
  77. endif
  78. ifeq ($(UNAME_S),Darwin)
  79. CFLAGS += -pthread
  80. CXXFLAGS += -pthread
  81. endif
  82. ifeq ($(UNAME_S),FreeBSD)
  83. CFLAGS += -pthread
  84. CXXFLAGS += -pthread
  85. endif
  86. ifeq ($(UNAME_S),NetBSD)
  87. CFLAGS += -pthread
  88. CXXFLAGS += -pthread
  89. endif
  90. ifeq ($(UNAME_S),OpenBSD)
  91. CFLAGS += -pthread
  92. CXXFLAGS += -pthread
  93. endif
  94. ifeq ($(UNAME_S),Haiku)
  95. CFLAGS += -pthread
  96. CXXFLAGS += -pthread
  97. endif
  98. # detect Windows
  99. ifneq ($(findstring _NT,$(UNAME_S)),)
  100. _WIN32 := 1
  101. endif
  102. # library name prefix
  103. ifneq ($(_WIN32),1)
  104. LIB_PRE := lib
  105. endif
  106. # Dynamic Shared Object extension
  107. ifneq ($(_WIN32),1)
  108. DSO_EXT := .so
  109. else
  110. DSO_EXT := .dll
  111. endif
  112. # Windows Sockets 2 (Winsock) for network-capable apps
  113. ifeq ($(_WIN32),1)
  114. LWINSOCK2 := -lws2_32
  115. endif
  116. ifdef LLAMA_GPROF
  117. CFLAGS += -pg
  118. CXXFLAGS += -pg
  119. endif
  120. ifdef LLAMA_PERF
  121. CFLAGS += -DGGML_PERF
  122. CXXFLAGS += -DGGML_PERF
  123. endif
  124. # Architecture specific
  125. # TODO: probably these flags need to be tweaked on some architectures
  126. # feel free to update the Makefile for your architecture and send a pull request or issue
  127. ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686 amd64))
  128. # Use all CPU extensions that are available:
  129. CFLAGS += -march=native -mtune=native
  130. CXXFLAGS += -march=native -mtune=native
  131. # Usage AVX-only
  132. #CFLAGS += -mfma -mf16c -mavx
  133. #CXXFLAGS += -mfma -mf16c -mavx
  134. # Usage SSSE3-only (Not is SSE3!)
  135. #CFLAGS += -mssse3
  136. #CXXFLAGS += -mssse3
  137. endif
  138. ifneq ($(filter aarch64%,$(UNAME_M)),)
  139. # Apple M1, M2, etc.
  140. # Raspberry Pi 3, 4, Zero 2 (64-bit)
  141. CFLAGS += -mcpu=native
  142. CXXFLAGS += -mcpu=native
  143. endif
  144. ifneq ($(filter armv6%,$(UNAME_M)),)
  145. # Raspberry Pi 1, Zero
  146. CFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access
  147. endif
  148. ifneq ($(filter armv7%,$(UNAME_M)),)
  149. # Raspberry Pi 2
  150. CFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access -funsafe-math-optimizations
  151. endif
  152. ifneq ($(filter armv8%,$(UNAME_M)),)
  153. # Raspberry Pi 3, 4, Zero 2 (32-bit)
  154. CFLAGS += -mfp16-format=ieee -mno-unaligned-access
  155. endif
  156. ifneq ($(filter ppc64%,$(UNAME_M)),)
  157. POWER9_M := $(shell grep "POWER9" /proc/cpuinfo)
  158. ifneq (,$(findstring POWER9,$(POWER9_M)))
  159. CFLAGS += -mcpu=power9
  160. CXXFLAGS += -mcpu=power9
  161. endif
  162. # Require c++23's std::byteswap for big-endian support.
  163. ifeq ($(UNAME_M),ppc64)
  164. CXXFLAGS += -std=c++23 -DGGML_BIG_ENDIAN
  165. endif
  166. endif
  167. ifndef LLAMA_NO_K_QUANTS
  168. CFLAGS += -DGGML_USE_K_QUANTS
  169. CXXFLAGS += -DGGML_USE_K_QUANTS
  170. OBJS += k_quants.o
  171. ifdef LLAMA_QKK_64
  172. CFLAGS += -DGGML_QKK_64
  173. CXXFLAGS += -DGGML_QKK_64
  174. endif
  175. endif
  176. ifndef LLAMA_NO_ACCELERATE
  177. # Mac M1 - include Accelerate framework.
  178. # `-framework Accelerate` works on Mac Intel as well, with negliable performance boost (as of the predict time).
  179. ifeq ($(UNAME_S),Darwin)
  180. CFLAGS += -DGGML_USE_ACCELERATE
  181. LDFLAGS += -framework Accelerate
  182. endif
  183. endif # LLAMA_NO_ACCELERATE
  184. ifdef LLAMA_MPI
  185. CFLAGS += -DGGML_USE_MPI -Wno-cast-qual
  186. CXXFLAGS += -DGGML_USE_MPI -Wno-cast-qual
  187. OBJS += ggml-mpi.o
  188. endif # LLAMA_MPI
  189. ifdef LLAMA_OPENBLAS
  190. CFLAGS += -DGGML_USE_OPENBLAS $(shell pkg-config --cflags openblas)
  191. LDFLAGS += $(shell pkg-config --libs openblas)
  192. endif # LLAMA_OPENBLAS
  193. ifdef LLAMA_BLIS
  194. CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/blis -I/usr/include/blis
  195. LDFLAGS += -lblis -L/usr/local/lib
  196. endif # LLAMA_BLIS
  197. ifdef LLAMA_CUBLAS
  198. CFLAGS += -DGGML_USE_CUBLAS -I/usr/local/cuda/include -I/opt/cuda/include -I$(CUDA_PATH)/targets/x86_64-linux/include
  199. CXXFLAGS += -DGGML_USE_CUBLAS -I/usr/local/cuda/include -I/opt/cuda/include -I$(CUDA_PATH)/targets/x86_64-linux/include
  200. 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
  201. OBJS += ggml-cuda.o
  202. NVCCFLAGS = --forward-unknown-to-host-compiler -use_fast_math
  203. ifdef LLAMA_CUDA_NVCC
  204. NVCC = $(LLAMA_CUDA_NVCC)
  205. else
  206. NVCC = nvcc
  207. endif #LLAMA_CUDA_NVCC
  208. ifdef CUDA_DOCKER_ARCH
  209. NVCCFLAGS += -Wno-deprecated-gpu-targets -arch=$(CUDA_DOCKER_ARCH)
  210. else
  211. NVCCFLAGS += -arch=native
  212. endif # CUDA_DOCKER_ARCH
  213. ifdef LLAMA_CUDA_FORCE_DMMV
  214. NVCCFLAGS += -DGGML_CUDA_FORCE_DMMV
  215. endif # LLAMA_CUDA_FORCE_DMMV
  216. ifdef LLAMA_CUDA_DMMV_X
  217. NVCCFLAGS += -DGGML_CUDA_DMMV_X=$(LLAMA_CUDA_DMMV_X)
  218. else
  219. NVCCFLAGS += -DGGML_CUDA_DMMV_X=32
  220. endif # LLAMA_CUDA_DMMV_X
  221. ifdef LLAMA_CUDA_MMV_Y
  222. NVCCFLAGS += -DGGML_CUDA_MMV_Y=$(LLAMA_CUDA_MMV_Y)
  223. else ifdef LLAMA_CUDA_DMMV_Y
  224. NVCCFLAGS += -DGGML_CUDA_MMV_Y=$(LLAMA_CUDA_DMMV_Y) # for backwards compatibility
  225. else
  226. NVCCFLAGS += -DGGML_CUDA_MMV_Y=1
  227. endif # LLAMA_CUDA_MMV_Y
  228. ifdef LLAMA_CUDA_F16
  229. NVCCFLAGS += -DGGML_CUDA_F16
  230. endif # LLAMA_CUDA_F16
  231. ifdef LLAMA_CUDA_DMMV_F16
  232. NVCCFLAGS += -DGGML_CUDA_F16
  233. endif # LLAMA_CUDA_DMMV_F16
  234. ifdef LLAMA_CUDA_KQUANTS_ITER
  235. NVCCFLAGS += -DK_QUANTS_PER_ITERATION=$(LLAMA_CUDA_KQUANTS_ITER)
  236. else
  237. NVCCFLAGS += -DK_QUANTS_PER_ITERATION=2
  238. endif
  239. #ifdef LLAMA_CUDA_CUBLAS
  240. # NVCCFLAGS += -DGGML_CUDA_CUBLAS
  241. #endif # LLAMA_CUDA_CUBLAS
  242. ifdef LLAMA_CUDA_CCBIN
  243. NVCCFLAGS += -ccbin $(LLAMA_CUDA_CCBIN)
  244. endif
  245. ggml-cuda.o: ggml-cuda.cu ggml-cuda.h
  246. $(NVCC) $(NVCCFLAGS) $(subst -Ofast,-O3,$(CXXFLAGS)) -Wno-pedantic -c $< -o $@
  247. endif # LLAMA_CUBLAS
  248. ifdef LLAMA_CLBLAST
  249. CFLAGS += -DGGML_USE_CLBLAST $(shell pkg-config --cflags clblast OpenCL)
  250. CXXFLAGS += -DGGML_USE_CLBLAST $(shell pkg-config --cflags clblast OpenCL)
  251. # Mac provides OpenCL as a framework
  252. ifeq ($(UNAME_S),Darwin)
  253. LDFLAGS += -lclblast -framework OpenCL
  254. else
  255. LDFLAGS += $(shell pkg-config --libs clblast OpenCL)
  256. endif
  257. OBJS += ggml-opencl.o
  258. ggml-opencl.o: ggml-opencl.cpp ggml-opencl.h
  259. $(CXX) $(CXXFLAGS) -c $< -o $@
  260. endif # LLAMA_CLBLAST
  261. ifdef LLAMA_HIPBLAS
  262. ROCM_PATH ?= /opt/rocm
  263. HIPCC ?= $(ROCM_PATH)/bin/hipcc
  264. GPU_TARGETS ?= $(shell $(ROCM_PATH)/llvm/bin/amdgpu-arch)
  265. LLAMA_CUDA_DMMV_X ?= 32
  266. LLAMA_CUDA_MMV_Y ?= 1
  267. LLAMA_CUDA_KQUANTS_ITER ?= 2
  268. CFLAGS += -DGGML_USE_HIPBLAS -DGGML_USE_CUBLAS
  269. CXXFLAGS += -DGGML_USE_HIPBLAS -DGGML_USE_CUBLAS
  270. LDFLAGS += -L$(ROCM_PATH)/lib -Wl,-rpath=$(ROCM_PATH)/lib
  271. LDFLAGS += -lhipblas -lamdhip64 -lrocblas
  272. HIPFLAGS += $(addprefix --offload-arch=,$(GPU_TARGETS))
  273. HIPFLAGS += -DGGML_CUDA_DMMV_X=$(LLAMA_CUDA_DMMV_X)
  274. HIPFLAGS += -DGGML_CUDA_MMV_Y=$(LLAMA_CUDA_MMV_Y)
  275. HIPFLAGS += -DK_QUANTS_PER_ITERATION=$(LLAMA_CUDA_KQUANTS_ITER)
  276. HIPFLAGS += -DCC_TURING=1000000000
  277. ifdef LLAMA_CUDA_FORCE_DMMV
  278. HIPFLAGS += -DGGML_CUDA_FORCE_DMMV
  279. endif # LLAMA_CUDA_FORCE_DMMV
  280. OBJS += ggml-cuda.o
  281. ggml-cuda.o: ggml-cuda.cu ggml-cuda.h
  282. $(HIPCC) $(CXXFLAGS) $(HIPFLAGS) -x hip -c -o $@ $<
  283. endif # LLAMA_HIPBLAS
  284. ifdef LLAMA_METAL
  285. CFLAGS += -DGGML_USE_METAL #-DGGML_METAL_NDEBUG
  286. CXXFLAGS += -DGGML_USE_METAL
  287. LDFLAGS += -framework Foundation -framework Metal -framework MetalKit
  288. OBJS += ggml-metal.o
  289. endif # LLAMA_METAL
  290. ifdef LLAMA_METAL
  291. ggml-metal.o: ggml-metal.m ggml-metal.h
  292. $(CC) $(CFLAGS) -c $< -o $@
  293. endif # LLAMA_METAL
  294. ifdef LLAMA_MPI
  295. ggml-mpi.o: ggml-mpi.c ggml-mpi.h
  296. $(CC) $(CFLAGS) -c $< -o $@
  297. endif # LLAMA_MPI
  298. ifdef LLAMA_NO_K_QUANTS
  299. k_quants.o: k_quants.c k_quants.h
  300. $(CC) $(CFLAGS) -c $< -o $@
  301. endif # LLAMA_NO_K_QUANTS
  302. ifdef LLAMA_DISABLE_LOGS
  303. CFLAGS += -DLOG_DISABLE_LOGS
  304. CXXFLAGS += -DLOG_DISABLE_LOGS
  305. endif # LLAMA_DISABLE_LOGS
  306. #
  307. # Print build information
  308. #
  309. $(info I llama.cpp build info: )
  310. $(info I UNAME_S: $(UNAME_S))
  311. $(info I UNAME_P: $(UNAME_P))
  312. $(info I UNAME_M: $(UNAME_M))
  313. $(info I CFLAGS: $(CFLAGS))
  314. $(info I CXXFLAGS: $(CXXFLAGS))
  315. $(info I LDFLAGS: $(LDFLAGS))
  316. $(info I CC: $(CCV))
  317. $(info I CXX: $(CXXV))
  318. $(info )
  319. #
  320. # Build library
  321. #
  322. ggml.o: ggml.c ggml.h ggml-cuda.h
  323. $(CC) $(CFLAGS) -c $< -o $@
  324. ggml-alloc.o: ggml-alloc.c ggml.h ggml-alloc.h
  325. $(CC) $(CFLAGS) -c $< -o $@
  326. OBJS += ggml-alloc.o
  327. llama.o: llama.cpp ggml.h ggml-alloc.h ggml-cuda.h ggml-metal.h llama.h
  328. $(CXX) $(CXXFLAGS) -c $< -o $@
  329. common.o: common/common.cpp common/common.h build-info.h common/log.h
  330. $(CXX) $(CXXFLAGS) -c $< -o $@
  331. console.o: common/console.cpp common/console.h
  332. $(CXX) $(CXXFLAGS) -c $< -o $@
  333. grammar-parser.o: common/grammar-parser.cpp common/grammar-parser.h
  334. $(CXX) $(CXXFLAGS) -c $< -o $@
  335. libllama.so: llama.o ggml.o $(OBJS)
  336. $(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
  337. clean:
  338. rm -vf *.o tests/*.o *.so *.dll benchmark-matmult build-info.h $(BUILD_TARGETS) $(TEST_TARGETS)
  339. #
  340. # Examples
  341. #
  342. main: examples/main/main.cpp build-info.h ggml.o llama.o common.o console.o grammar-parser.o $(OBJS)
  343. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  344. @echo
  345. @echo '==== Run ./main -h for help. ===='
  346. @echo
  347. simple: examples/simple/simple.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  348. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  349. quantize: examples/quantize/quantize.cpp build-info.h ggml.o llama.o $(OBJS)
  350. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  351. quantize-stats: examples/quantize-stats/quantize-stats.cpp build-info.h ggml.o llama.o $(OBJS)
  352. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  353. perplexity: examples/perplexity/perplexity.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  354. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  355. embedding: examples/embedding/embedding.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  356. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  357. save-load-state: examples/save-load-state/save-load-state.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  358. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  359. server: examples/server/server.cpp examples/server/httplib.h examples/server/json.hpp examples/server/index.html.hpp examples/server/index.js.hpp examples/server/completion.js.hpp build-info.h ggml.o llama.o common.o grammar-parser.o $(OBJS)
  360. $(CXX) $(CXXFLAGS) -Iexamples/server $(filter-out %.h,$(filter-out %.hpp,$^)) -o $@ $(LDFLAGS) $(LWINSOCK2)
  361. $(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)
  362. $(CXX) --shared $(CXXFLAGS) $(filter-out %.h,$(filter-out %.hpp,$^)) -o $@ $(LDFLAGS)
  363. 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)
  364. $(CXX) $(CXXFLAGS) $(filter-out %$(DSO_EXT),$(filter-out %.h,$(filter-out %.hpp,$^))) -o $@ $(LDFLAGS) -L. -lembdinput
  365. gguf: examples/gguf/gguf.cpp ggml.o llama.o $(OBJS)
  366. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  367. train-text-from-scratch: examples/train-text-from-scratch/train-text-from-scratch.cpp ggml.o llama.o common.o $(OBJS)
  368. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  369. convert-llama2c-to-ggml: examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp ggml.o llama.o $(OBJS)
  370. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  371. llama-bench: examples/llama-bench/llama-bench.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  372. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  373. baby-llama: examples/baby-llama/baby-llama.cpp ggml.o llama.o common.o $(OBJS)
  374. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  375. beam-search: examples/beam-search/beam-search.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  376. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  377. ifneq '' '$(or $(filter clean,$(MAKECMDGOALS)),$(LLAMA_METAL))'
  378. BUILD_TARGETS += metal
  379. endif
  380. ifdef LLAMA_METAL
  381. metal: examples/metal/metal.cpp ggml.o $(OBJS)
  382. $(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
  383. endif
  384. build-info.h: $(wildcard .git/index) scripts/build-info.sh
  385. @sh scripts/build-info.sh > $@.tmp
  386. @if ! cmp -s $@.tmp $@; then \
  387. mv $@.tmp $@; \
  388. else \
  389. rm $@.tmp; \
  390. fi
  391. #
  392. # Tests
  393. #
  394. tests: $(TEST_TARGETS)
  395. benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o $(OBJS)
  396. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  397. ./$@
  398. vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS)
  399. $(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
  400. tests/test-llama-grammar: tests/test-llama-grammar.cpp build-info.h ggml.o common.o grammar-parser.o $(OBJS)
  401. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  402. tests/test-grammar-parser: tests/test-grammar-parser.cpp build-info.h ggml.o llama.o common.o grammar-parser.o $(OBJS)
  403. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  404. tests/test-double-float: tests/test-double-float.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  405. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  406. tests/test-grad0: tests/test-grad0.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  407. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  408. tests/test-opt: tests/test-opt.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  409. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  410. tests/test-quantize-fns: tests/test-quantize-fns.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  411. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  412. tests/test-quantize-perf: tests/test-quantize-perf.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  413. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  414. tests/test-sampling: tests/test-sampling.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  415. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  416. tests/test-tokenizer-0-falcon: tests/test-tokenizer-0-falcon.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  417. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  418. tests/test-tokenizer-0-llama: tests/test-tokenizer-0-llama.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  419. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  420. tests/test-tokenizer-1: tests/test-tokenizer-1.cpp build-info.h ggml.o llama.o common.o $(OBJS)
  421. $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
  422. tests/test-c.o: tests/test-c.c llama.h
  423. $(CC) $(CFLAGS) -c $(filter-out %.h,$^) -o $@