Makefile 17 KB

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