Makefile 17 KB

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