Makefile 18 KB

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