Makefile 17 KB

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