Makefile 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. # Define the default target now so that it is always the first target
  2. BUILD_TARGETS = \
  3. main quantize quantize-stats perplexity imatrix embedding vdot q8dot train-text-from-scratch convert-llama2c-to-ggml \
  4. simple batched batched-bench save-load-state server gguf llama-bench libllava.a llava-cli baby-llama beam-search \
  5. speculative infill tokenize benchmark-matmult parallel finetune export-lora lookahead lookup passkey tests/test-c.o
  6. # Binaries only useful for tests
  7. TEST_TARGETS = \
  8. tests/test-llama-grammar tests/test-grammar-parser tests/test-double-float tests/test-grad0 tests/test-opt \
  9. tests/test-quantize-fns tests/test-quantize-perf tests/test-sampling tests/test-tokenizer-0-llama \
  10. tests/test-tokenizer-0-falcon tests/test-tokenizer-1-llama tests/test-tokenizer-1-bpe tests/test-rope \
  11. tests/test-backend-ops tests/test-model-load-cancel tests/test-autorelease
  12. # Code coverage output files
  13. COV_TARGETS = *.gcno tests/*.gcno *.gcda tests/*.gcda *.gcov tests/*.gcov lcov-report gcovr-report
  14. ifndef UNAME_S
  15. UNAME_S := $(shell uname -s)
  16. endif
  17. ifndef UNAME_P
  18. UNAME_P := $(shell uname -p)
  19. endif
  20. ifndef UNAME_M
  21. UNAME_M := $(shell uname -m)
  22. endif
  23. # Mac OS + Arm can report x86_64
  24. # ref: https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment-1282546789
  25. ifeq ($(UNAME_S),Darwin)
  26. ifndef LLAMA_NO_METAL
  27. LLAMA_METAL := 1
  28. endif
  29. ifneq ($(UNAME_P),arm)
  30. SYSCTL_M := $(shell sysctl -n hw.optional.arm64 2>/dev/null)
  31. ifeq ($(SYSCTL_M),1)
  32. # UNAME_P := arm
  33. # UNAME_M := arm64
  34. 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)
  35. endif
  36. endif
  37. endif
  38. default: $(BUILD_TARGETS)
  39. test: $(TEST_TARGETS)
  40. @failures=0; \
  41. for test_target in $(TEST_TARGETS); do \
  42. if [ "$$test_target" = "tests/test-tokenizer-0-llama" ]; then \
  43. ./$$test_target $(CURDIR)/models/ggml-vocab-llama.gguf; \
  44. elif [ "$$test_target" = "tests/test-tokenizer-0-falcon" ]; then \
  45. ./$$test_target $(CURDIR)/models/ggml-vocab-falcon.gguf; \
  46. elif [ "$$test_target" = "tests/test-tokenizer-1-llama" ]; then \
  47. continue; \
  48. elif [ "$$test_target" = "tests/test-tokenizer-1-bpe" ]; then \
  49. continue; \
  50. else \
  51. echo "Running test $$test_target..."; \
  52. ./$$test_target; \
  53. fi; \
  54. if [ $$? -ne 0 ]; then \
  55. printf 'Test %s FAILED!\n\n' $$test_target; \
  56. failures=$$(( failures + 1 )); \
  57. else \
  58. printf 'Test %s passed.\n\n' $$test_target; \
  59. fi; \
  60. done; \
  61. if [ $$failures -gt 0 ]; then \
  62. printf '\n%s tests failed.\n' $$failures; \
  63. exit 1; \
  64. fi
  65. @echo 'All tests passed.'
  66. all: $(BUILD_TARGETS) $(TEST_TARGETS)
  67. coverage: ## Run code coverage
  68. gcov -pb tests/*.cpp
  69. lcov-report: coverage ## Generate lcov report
  70. mkdir -p lcov-report
  71. lcov --capture --directory . --output-file lcov-report/coverage.info
  72. genhtml lcov-report/coverage.info --output-directory lcov-report
  73. gcovr-report: coverage ## Generate gcovr report
  74. mkdir -p gcovr-report
  75. gcovr --root . --html --html-details --output gcovr-report/coverage.html
  76. ifdef RISCV_CROSS_COMPILE
  77. CC := riscv64-unknown-linux-gnu-gcc
  78. CXX := riscv64-unknown-linux-gnu-g++
  79. endif
  80. #
  81. # Compile flags
  82. #
  83. # keep standard at C11 and C++11
  84. MK_CPPFLAGS = -I. -Icommon
  85. MK_CFLAGS = -std=c11 -fPIC
  86. MK_CXXFLAGS = -std=c++11 -fPIC
  87. MK_NVCCFLAGS = -std=c++11
  88. # -Ofast tends to produce faster code, but may not be available for some compilers.
  89. ifdef LLAMA_FAST
  90. MK_CFLAGS += -Ofast
  91. HOST_CXXFLAGS += -Ofast
  92. MK_NVCCFLAGS += -O3
  93. else
  94. MK_CFLAGS += -O3
  95. MK_CXXFLAGS += -O3
  96. MK_NVCCFLAGS += -O3
  97. endif
  98. ifndef LLAMA_NO_CCACHE
  99. CCACHE := $(shell which ccache)
  100. ifdef CCACHE
  101. export CCACHE_SLOPPINESS = time_macros
  102. $(info I ccache found, compilation results will be cached. Disable with LLAMA_NO_CCACHE.)
  103. CC := $(CCACHE) $(CC)
  104. CXX := $(CCACHE) $(CXX)
  105. else
  106. $(info I ccache not found. Consider installing it for faster compilation.)
  107. endif # CCACHE
  108. endif # LLAMA_NO_CCACHE
  109. # clock_gettime came in POSIX.1b (1993)
  110. # CLOCK_MONOTONIC came in POSIX.1-2001 / SUSv3 as optional
  111. # posix_memalign came in POSIX.1-2001 / SUSv3
  112. # M_PI is an XSI extension since POSIX.1-2001 / SUSv3, came in XPG1 (1985)
  113. MK_CPPFLAGS += -D_XOPEN_SOURCE=600
  114. # Somehow in OpenBSD whenever POSIX conformance is specified
  115. # some string functions rely on locale_t availability,
  116. # which was introduced in POSIX.1-2008, forcing us to go higher
  117. ifeq ($(UNAME_S),OpenBSD)
  118. MK_CPPFLAGS += -U_XOPEN_SOURCE -D_XOPEN_SOURCE=700
  119. endif
  120. # Data types, macros and functions related to controlling CPU affinity and
  121. # some memory allocation are available on Linux through GNU extensions in libc
  122. ifeq ($(UNAME_S),Linux)
  123. MK_CPPFLAGS += -D_GNU_SOURCE
  124. endif
  125. # RLIMIT_MEMLOCK came in BSD, is not specified in POSIX.1,
  126. # and on macOS its availability depends on enabling Darwin extensions
  127. # similarly on DragonFly, enabling BSD extensions is necessary
  128. ifeq ($(UNAME_S),Darwin)
  129. MK_CPPFLAGS += -D_DARWIN_C_SOURCE
  130. endif
  131. ifeq ($(UNAME_S),DragonFly)
  132. MK_CPPFLAGS += -D__BSD_VISIBLE
  133. endif
  134. # alloca is a non-standard interface that is not visible on BSDs when
  135. # POSIX conformance is specified, but not all of them provide a clean way
  136. # to enable it in such cases
  137. ifeq ($(UNAME_S),FreeBSD)
  138. MK_CPPFLAGS += -D__BSD_VISIBLE
  139. endif
  140. ifeq ($(UNAME_S),NetBSD)
  141. MK_CPPFLAGS += -D_NETBSD_SOURCE
  142. endif
  143. ifeq ($(UNAME_S),OpenBSD)
  144. MK_CPPFLAGS += -D_BSD_SOURCE
  145. endif
  146. ifdef LLAMA_DEBUG
  147. MK_CFLAGS += -O0 -g
  148. MK_CXXFLAGS += -O0 -g
  149. MK_LDFLAGS += -g
  150. ifeq ($(UNAME_S),Linux)
  151. MK_CPPFLAGS += -D_GLIBCXX_ASSERTIONS
  152. endif
  153. else
  154. MK_CPPFLAGS += -DNDEBUG
  155. endif
  156. ifdef LLAMA_SANITIZE_THREAD
  157. MK_CFLAGS += -fsanitize=thread -g
  158. MK_CXXFLAGS += -fsanitize=thread -g
  159. MK_LDFLAGS += -fsanitize=thread -g
  160. endif
  161. ifdef LLAMA_SANITIZE_ADDRESS
  162. MK_CFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
  163. MK_CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
  164. MK_LDFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
  165. endif
  166. ifdef LLAMA_SANITIZE_UNDEFINED
  167. MK_CFLAGS += -fsanitize=undefined -g
  168. MK_CXXFLAGS += -fsanitize=undefined -g
  169. MK_LDFLAGS += -fsanitize=undefined -g
  170. endif
  171. ifdef LLAMA_SERVER_VERBOSE
  172. MK_CPPFLAGS += -DSERVER_VERBOSE=$(LLAMA_SERVER_VERBOSE)
  173. endif
  174. ifdef LLAMA_CODE_COVERAGE
  175. MK_CXXFLAGS += -fprofile-arcs -ftest-coverage -dumpbase ''
  176. endif
  177. ifdef LLAMA_DISABLE_LOGS
  178. MK_CPPFLAGS += -DLOG_DISABLE_LOGS
  179. endif # LLAMA_DISABLE_LOGS
  180. # warnings
  181. WARN_FLAGS = -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function
  182. MK_CFLAGS += $(WARN_FLAGS) -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Werror=implicit-int \
  183. -Werror=implicit-function-declaration
  184. MK_CXXFLAGS += $(WARN_FLAGS) -Wmissing-declarations -Wmissing-noreturn
  185. ifeq ($(LLAMA_FATAL_WARNINGS),1)
  186. MK_CFLAGS += -Werror
  187. MK_CXXFLAGS += -Werror
  188. endif
  189. # this version of Apple ld64 is buggy
  190. ifneq '' '$(findstring dyld-1015.7,$(shell $(CC) $(LDFLAGS) -Wl,-v 2>&1))'
  191. MK_CPPFLAGS += -DHAVE_BUGGY_APPLE_LINKER
  192. endif
  193. # OS specific
  194. # TODO: support Windows
  195. ifneq '' '$(filter $(UNAME_S),Linux Darwin FreeBSD NetBSD OpenBSD Haiku)'
  196. MK_CFLAGS += -pthread
  197. MK_CXXFLAGS += -pthread
  198. endif
  199. # detect Windows
  200. ifneq ($(findstring _NT,$(UNAME_S)),)
  201. _WIN32 := 1
  202. endif
  203. # library name prefix
  204. ifneq ($(_WIN32),1)
  205. LIB_PRE := lib
  206. endif
  207. # Dynamic Shared Object extension
  208. ifneq ($(_WIN32),1)
  209. DSO_EXT := .so
  210. else
  211. DSO_EXT := .dll
  212. endif
  213. # Windows Sockets 2 (Winsock) for network-capable apps
  214. ifeq ($(_WIN32),1)
  215. LWINSOCK2 := -lws2_32
  216. endif
  217. ifdef LLAMA_GPROF
  218. MK_CFLAGS += -pg
  219. MK_CXXFLAGS += -pg
  220. endif
  221. ifdef LLAMA_PERF
  222. MK_CPPFLAGS += -DGGML_PERF
  223. endif
  224. # Architecture specific
  225. # TODO: probably these flags need to be tweaked on some architectures
  226. # feel free to update the Makefile for your architecture and send a pull request or issue
  227. ifndef RISCV
  228. ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686 amd64))
  229. # Use all CPU extensions that are available:
  230. MK_CFLAGS += -march=native -mtune=native
  231. HOST_CXXFLAGS += -march=native -mtune=native
  232. # Usage AVX-only
  233. #MK_CFLAGS += -mfma -mf16c -mavx
  234. #MK_CXXFLAGS += -mfma -mf16c -mavx
  235. # Usage SSSE3-only (Not is SSE3!)
  236. #MK_CFLAGS += -mssse3
  237. #MK_CXXFLAGS += -mssse3
  238. endif
  239. ifneq '' '$(findstring mingw,$(shell $(CC) -dumpmachine))'
  240. # The stack is only 16-byte aligned on Windows, so don't let gcc emit aligned moves.
  241. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54412
  242. # https://github.com/ggerganov/llama.cpp/issues/2922
  243. MK_CFLAGS += -Xassembler -muse-unaligned-vector-move
  244. MK_CXXFLAGS += -Xassembler -muse-unaligned-vector-move
  245. # Target Windows 8 for PrefetchVirtualMemory
  246. MK_CPPFLAGS += -D_WIN32_WINNT=0x602
  247. endif
  248. ifneq ($(filter aarch64%,$(UNAME_M)),)
  249. # Apple M1, M2, etc.
  250. # Raspberry Pi 3, 4, Zero 2 (64-bit)
  251. # Nvidia Jetson
  252. MK_CFLAGS += -mcpu=native
  253. MK_CXXFLAGS += -mcpu=native
  254. JETSON_RELEASE_INFO = $(shell jetson_release)
  255. ifdef JETSON_RELEASE_INFO
  256. ifneq ($(filter TX2%,$(JETSON_RELEASE_INFO)),)
  257. JETSON_EOL_MODULE_DETECT = 1
  258. CC = aarch64-unknown-linux-gnu-gcc
  259. cxx = aarch64-unknown-linux-gnu-g++
  260. endif
  261. endif
  262. endif
  263. ifneq ($(filter armv6%,$(UNAME_M)),)
  264. # Raspberry Pi 1, Zero
  265. MK_CFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access
  266. MK_CXXFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access
  267. endif
  268. ifneq ($(filter armv7%,$(UNAME_M)),)
  269. # Raspberry Pi 2
  270. MK_CFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access -funsafe-math-optimizations
  271. MK_CXXFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access -funsafe-math-optimizations
  272. endif
  273. ifneq ($(filter armv8%,$(UNAME_M)),)
  274. # Raspberry Pi 3, 4, Zero 2 (32-bit)
  275. MK_CFLAGS += -mfp16-format=ieee -mno-unaligned-access
  276. MK_CXXFLAGS += -mfp16-format=ieee -mno-unaligned-access
  277. endif
  278. ifneq ($(filter ppc64%,$(UNAME_M)),)
  279. POWER9_M := $(shell grep "POWER9" /proc/cpuinfo)
  280. ifneq (,$(findstring POWER9,$(POWER9_M)))
  281. MK_CFLAGS += -mcpu=power9
  282. MK_CXXFLAGS += -mcpu=power9
  283. endif
  284. endif
  285. ifneq ($(filter ppc64le%,$(UNAME_M)),)
  286. MK_CFLAGS += -mcpu=powerpc64le
  287. MK_CXXFLAGS += -mcpu=powerpc64le
  288. CUDA_POWER_ARCH = 1
  289. endif
  290. else
  291. MK_CFLAGS += -march=rv64gcv -mabi=lp64d
  292. MK_CXXFLAGS += -march=rv64gcv -mabi=lp64d
  293. endif
  294. ifdef LLAMA_QKK_64
  295. MK_CPPFLAGS += -DGGML_QKK_64
  296. endif
  297. ifndef LLAMA_NO_ACCELERATE
  298. # Mac OS - include Accelerate framework.
  299. # `-framework Accelerate` works both with Apple Silicon and Mac Intel
  300. ifeq ($(UNAME_S),Darwin)
  301. MK_CPPFLAGS += -DGGML_USE_ACCELERATE
  302. MK_CPPFLAGS += -DACCELERATE_NEW_LAPACK
  303. MK_CPPFLAGS += -DACCELERATE_LAPACK_ILP64
  304. MK_LDFLAGS += -framework Accelerate
  305. endif
  306. endif # LLAMA_NO_ACCELERATE
  307. ifdef LLAMA_MPI
  308. MK_CPPFLAGS += -DGGML_USE_MPI
  309. MK_CFLAGS += -Wno-cast-qual
  310. MK_CXXFLAGS += -Wno-cast-qual
  311. OBJS += ggml-mpi.o
  312. endif # LLAMA_MPI
  313. ifdef LLAMA_OPENBLAS
  314. MK_CPPFLAGS += -DGGML_USE_OPENBLAS $(shell pkg-config --cflags-only-I openblas)
  315. MK_CFLAGS += $(shell pkg-config --cflags-only-other openblas)
  316. MK_LDFLAGS += $(shell pkg-config --libs openblas)
  317. endif # LLAMA_OPENBLAS
  318. ifdef LLAMA_BLIS
  319. MK_CPPFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/blis -I/usr/include/blis
  320. MK_LDFLAGS += -lblis -L/usr/local/lib
  321. endif # LLAMA_BLIS
  322. ifdef LLAMA_CUBLAS
  323. MK_CPPFLAGS += -DGGML_USE_CUBLAS -I/usr/local/cuda/include -I/opt/cuda/include -I$(CUDA_PATH)/targets/x86_64-linux/include -I/usr/local/cuda/targets/aarch64-linux/include
  324. MK_LDFLAGS += -lcuda -lcublas -lculibos -lcudart -lcublasLt -lpthread -ldl -lrt -L/usr/local/cuda/lib64 -L/opt/cuda/lib64 -L$(CUDA_PATH)/targets/x86_64-linux/lib -L/usr/local/cuda/targets/aarch64-linux/lib -L/usr/lib/wsl/lib
  325. OBJS += ggml-cuda.o
  326. MK_NVCCFLAGS += -use_fast_math
  327. ifdef LLAMA_FATAL_WARNINGS
  328. MK_NVCCFLAGS += -Werror all-warnings
  329. endif # LLAMA_FATAL_WARNINGS
  330. ifndef JETSON_EOL_MODULE_DETECT
  331. MK_NVCCFLAGS += --forward-unknown-to-host-compiler
  332. endif # JETSON_EOL_MODULE_DETECT
  333. ifdef LLAMA_DEBUG
  334. MK_NVCCFLAGS += -lineinfo
  335. endif # LLAMA_DEBUG
  336. ifdef LLAMA_CUDA_NVCC
  337. NVCC = $(CCACHE) $(LLAMA_CUDA_NVCC)
  338. else
  339. NVCC = $(CCACHE) nvcc
  340. endif #LLAMA_CUDA_NVCC
  341. ifdef CUDA_DOCKER_ARCH
  342. MK_NVCCFLAGS += -Wno-deprecated-gpu-targets -arch=$(CUDA_DOCKER_ARCH)
  343. else ifndef CUDA_POWER_ARCH
  344. MK_NVCCFLAGS += -arch=native
  345. endif # CUDA_DOCKER_ARCH
  346. ifdef LLAMA_CUDA_FORCE_DMMV
  347. MK_NVCCFLAGS += -DGGML_CUDA_FORCE_DMMV
  348. endif # LLAMA_CUDA_FORCE_DMMV
  349. ifdef LLAMA_CUDA_FORCE_MMQ
  350. MK_NVCCFLAGS += -DGGML_CUDA_FORCE_MMQ
  351. endif # LLAMA_CUDA_FORCE_MMQ
  352. ifdef LLAMA_CUDA_DMMV_X
  353. MK_NVCCFLAGS += -DGGML_CUDA_DMMV_X=$(LLAMA_CUDA_DMMV_X)
  354. else
  355. MK_NVCCFLAGS += -DGGML_CUDA_DMMV_X=32
  356. endif # LLAMA_CUDA_DMMV_X
  357. ifdef LLAMA_CUDA_MMV_Y
  358. MK_NVCCFLAGS += -DGGML_CUDA_MMV_Y=$(LLAMA_CUDA_MMV_Y)
  359. else ifdef LLAMA_CUDA_DMMV_Y
  360. MK_NVCCFLAGS += -DGGML_CUDA_MMV_Y=$(LLAMA_CUDA_DMMV_Y) # for backwards compatibility
  361. else
  362. MK_NVCCFLAGS += -DGGML_CUDA_MMV_Y=1
  363. endif # LLAMA_CUDA_MMV_Y
  364. ifdef LLAMA_CUDA_F16
  365. MK_NVCCFLAGS += -DGGML_CUDA_F16
  366. endif # LLAMA_CUDA_F16
  367. ifdef LLAMA_CUDA_DMMV_F16
  368. MK_NVCCFLAGS += -DGGML_CUDA_F16
  369. endif # LLAMA_CUDA_DMMV_F16
  370. ifdef LLAMA_CUDA_KQUANTS_ITER
  371. MK_NVCCFLAGS += -DK_QUANTS_PER_ITERATION=$(LLAMA_CUDA_KQUANTS_ITER)
  372. else
  373. MK_NVCCFLAGS += -DK_QUANTS_PER_ITERATION=2
  374. endif
  375. ifdef LLAMA_CUDA_PEER_MAX_BATCH_SIZE
  376. MK_NVCCFLAGS += -DGGML_CUDA_PEER_MAX_BATCH_SIZE=$(LLAMA_CUDA_PEER_MAX_BATCH_SIZE)
  377. else
  378. MK_NVCCFLAGS += -DGGML_CUDA_PEER_MAX_BATCH_SIZE=128
  379. endif # LLAMA_CUDA_PEER_MAX_BATCH_SIZE
  380. #ifdef LLAMA_CUDA_CUBLAS
  381. # MK_NVCCFLAGS += -DGGML_CUDA_CUBLAS
  382. #endif # LLAMA_CUDA_CUBLAS
  383. ifdef LLAMA_CUDA_CCBIN
  384. MK_NVCCFLAGS += -ccbin $(LLAMA_CUDA_CCBIN)
  385. endif
  386. ggml-cuda.o: ggml-cuda.cu ggml-cuda.h
  387. ifdef JETSON_EOL_MODULE_DETECT
  388. $(NVCC) -I. -Icommon -D_XOPEN_SOURCE=600 -D_GNU_SOURCE -DNDEBUG -DGGML_USE_CUBLAS -I/usr/local/cuda/include -I/opt/cuda/include -I/usr/local/cuda/targets/aarch64-linux/include -std=c++11 -O3 $(NVCCFLAGS) $(CPPFLAGS) -Xcompiler "$(CUDA_CXXFLAGS)" -c $< -o $@
  389. else
  390. $(NVCC) $(NVCCFLAGS) $(CPPFLAGS) -Xcompiler "$(CUDA_CXXFLAGS)" -c $< -o $@
  391. endif # JETSON_EOL_MODULE_DETECT
  392. endif # LLAMA_CUBLAS
  393. ifdef LLAMA_CLBLAST
  394. MK_CPPFLAGS += -DGGML_USE_CLBLAST $(shell pkg-config --cflags-only-I clblast OpenCL)
  395. MK_CFLAGS += $(shell pkg-config --cflags-only-other clblast OpenCL)
  396. MK_CXXFLAGS += $(shell pkg-config --cflags-only-other clblast OpenCL)
  397. # Mac provides OpenCL as a framework
  398. ifeq ($(UNAME_S),Darwin)
  399. MK_LDFLAGS += -lclblast -framework OpenCL
  400. else
  401. MK_LDFLAGS += $(shell pkg-config --libs clblast OpenCL)
  402. endif
  403. OBJS += ggml-opencl.o
  404. ggml-opencl.o: ggml-opencl.cpp ggml-opencl.h
  405. $(CXX) $(CXXFLAGS) -c $< -o $@
  406. endif # LLAMA_CLBLAST
  407. ifdef LLAMA_VULKAN
  408. MK_CPPFLAGS += -DGGML_USE_VULKAN
  409. MK_LDFLAGS += -lvulkan
  410. OBJS += ggml-vulkan.o
  411. ifdef LLAMA_VULKAN_CHECK_RESULTS
  412. MK_CPPFLAGS += -DGGML_VULKAN_CHECK_RESULTS
  413. endif
  414. ifdef LLAMA_VULKAN_DEBUG
  415. MK_CPPFLAGS += -DGGML_VULKAN_DEBUG
  416. endif
  417. ifdef LLAMA_VULKAN_VALIDATE
  418. MK_CPPFLAGS += -DGGML_VULKAN_VALIDATE
  419. endif
  420. ifdef LLAMA_VULKAN_RUN_TESTS
  421. MK_CPPFLAGS += -DGGML_VULKAN_RUN_TESTS
  422. endif
  423. ggml-vulkan.o: ggml-vulkan.cpp ggml-vulkan.h
  424. $(CXX) $(CXXFLAGS) -c $< -o $@
  425. endif # LLAMA_VULKAN
  426. ifdef LLAMA_HIPBLAS
  427. ifeq ($(wildcard /opt/rocm),)
  428. ROCM_PATH ?= /usr
  429. GPU_TARGETS ?= $(shell $(shell which amdgpu-arch))
  430. else
  431. ROCM_PATH ?= /opt/rocm
  432. GPU_TARGETS ?= $(shell $(ROCM_PATH)/llvm/bin/amdgpu-arch)
  433. endif
  434. HIPCC ?= $(CCACHE) $(ROCM_PATH)/bin/hipcc
  435. LLAMA_CUDA_DMMV_X ?= 32
  436. LLAMA_CUDA_MMV_Y ?= 1
  437. LLAMA_CUDA_KQUANTS_ITER ?= 2
  438. MK_CPPFLAGS += -DGGML_USE_HIPBLAS -DGGML_USE_CUBLAS
  439. ifdef LLAMA_HIP_UMA
  440. MK_CPPFLAGS += -DGGML_HIP_UMA
  441. endif # LLAMA_HIP_UMA
  442. MK_LDFLAGS += -L$(ROCM_PATH)/lib -Wl,-rpath=$(ROCM_PATH)/lib
  443. MK_LDFLAGS += -lhipblas -lamdhip64 -lrocblas
  444. HIPFLAGS += $(addprefix --offload-arch=,$(GPU_TARGETS))
  445. HIPFLAGS += -DGGML_CUDA_DMMV_X=$(LLAMA_CUDA_DMMV_X)
  446. HIPFLAGS += -DGGML_CUDA_MMV_Y=$(LLAMA_CUDA_MMV_Y)
  447. HIPFLAGS += -DK_QUANTS_PER_ITERATION=$(LLAMA_CUDA_KQUANTS_ITER)
  448. ifdef LLAMA_CUDA_FORCE_DMMV
  449. HIPFLAGS += -DGGML_CUDA_FORCE_DMMV
  450. endif # LLAMA_CUDA_FORCE_DMMV
  451. OBJS += ggml-cuda.o
  452. ggml-cuda.o: ggml-cuda.cu ggml-cuda.h
  453. $(HIPCC) $(CXXFLAGS) $(HIPFLAGS) -x hip -c -o $@ $<
  454. endif # LLAMA_HIPBLAS
  455. ifdef LLAMA_METAL
  456. MK_CPPFLAGS += -DGGML_USE_METAL
  457. MK_LDFLAGS += -framework Foundation -framework Metal -framework MetalKit
  458. OBJS += ggml-metal.o
  459. ifdef LLAMA_METAL_NDEBUG
  460. MK_CPPFLAGS += -DGGML_METAL_NDEBUG
  461. endif
  462. ifdef LLAMA_METAL_EMBED_LIBRARY
  463. MK_CPPFLAGS += -DGGML_METAL_EMBED_LIBRARY
  464. OBJS += ggml-metal-embed.o
  465. endif
  466. endif # LLAMA_METAL
  467. ifdef LLAMA_METAL
  468. ggml-metal.o: ggml-metal.m ggml-metal.h
  469. $(CC) $(CFLAGS) -c $< -o $@
  470. ifdef LLAMA_METAL_EMBED_LIBRARY
  471. ggml-metal-embed.o: ggml-metal.metal
  472. @echo "Embedding Metal library"
  473. $(eval TEMP_ASSEMBLY=$(shell mktemp))
  474. @echo ".section __DATA, __ggml_metallib" > $(TEMP_ASSEMBLY)
  475. @echo ".globl _ggml_metallib_start" >> $(TEMP_ASSEMBLY)
  476. @echo "_ggml_metallib_start:" >> $(TEMP_ASSEMBLY)
  477. @echo ".incbin \"$<\"" >> $(TEMP_ASSEMBLY)
  478. @echo ".globl _ggml_metallib_end" >> $(TEMP_ASSEMBLY)
  479. @echo "_ggml_metallib_end:" >> $(TEMP_ASSEMBLY)
  480. @$(AS) $(TEMP_ASSEMBLY) -o $@
  481. @rm -f ${TEMP_ASSEMBLY}
  482. endif
  483. endif # LLAMA_METAL
  484. ifdef LLAMA_MPI
  485. ggml-mpi.o: ggml-mpi.c ggml-mpi.h
  486. $(CC) $(CFLAGS) -c $< -o $@
  487. endif # LLAMA_MPI
  488. GF_CC := $(CC)
  489. include scripts/get-flags.mk
  490. # combine build flags with cmdline overrides
  491. override CPPFLAGS := $(MK_CPPFLAGS) $(CPPFLAGS)
  492. override CFLAGS := $(CPPFLAGS) $(MK_CFLAGS) $(GF_CFLAGS) $(CFLAGS)
  493. BASE_CXXFLAGS := $(MK_CXXFLAGS) $(CXXFLAGS)
  494. override CXXFLAGS := $(BASE_CXXFLAGS) $(HOST_CXXFLAGS) $(GF_CXXFLAGS) $(CPPFLAGS)
  495. override NVCCFLAGS := $(MK_NVCCFLAGS) $(NVCCFLAGS)
  496. override LDFLAGS := $(MK_LDFLAGS) $(LDFLAGS)
  497. # identify CUDA host compiler
  498. ifdef LLAMA_CUBLAS
  499. GF_CC := $(NVCC) $(NVCCFLAGS) 2>/dev/null .c -Xcompiler
  500. include scripts/get-flags.mk
  501. CUDA_CXXFLAGS := $(BASE_CXXFLAGS) $(GF_CXXFLAGS) -Wno-pedantic
  502. endif
  503. #
  504. # Print build information
  505. #
  506. $(info I llama.cpp build info: )
  507. $(info I UNAME_S: $(UNAME_S))
  508. $(info I UNAME_P: $(UNAME_P))
  509. $(info I UNAME_M: $(UNAME_M))
  510. $(info I CFLAGS: $(CFLAGS))
  511. $(info I CXXFLAGS: $(CXXFLAGS))
  512. $(info I NVCCFLAGS: $(NVCCFLAGS))
  513. $(info I LDFLAGS: $(LDFLAGS))
  514. $(info I CC: $(shell $(CC) --version | head -n 1))
  515. $(info I CXX: $(shell $(CXX) --version | head -n 1))
  516. ifdef LLAMA_CUBLAS
  517. $(info I NVCC: $(shell $(NVCC) --version | tail -n 1))
  518. CUDA_VERSION := $(shell $(NVCC) --version | grep -oP 'release (\K[0-9]+\.[0-9])')
  519. ifeq ($(shell awk -v "v=$(CUDA_VERSION)" 'BEGIN { print (v < 11.7) }'),1)
  520. ifndef CUDA_DOCKER_ARCH
  521. ifndef CUDA_POWER_ARCH
  522. $(error I ERROR: For CUDA versions < 11.7 a target CUDA architecture must be explicitly provided via CUDA_DOCKER_ARCH)
  523. endif # CUDA_POWER_ARCH
  524. endif # CUDA_DOCKER_ARCH
  525. endif # eq ($(shell echo "$(CUDA_VERSION) < 11.7" | bc),1)
  526. endif # LLAMA_CUBLAS
  527. $(info )
  528. #
  529. # Build library
  530. #
  531. ggml.o: ggml.c ggml.h ggml-cuda.h
  532. $(CC) $(CFLAGS) -c $< -o $@
  533. ggml-alloc.o: ggml-alloc.c ggml.h ggml-alloc.h
  534. $(CC) $(CFLAGS) -c $< -o $@
  535. ggml-backend.o: ggml-backend.c ggml.h ggml-backend.h
  536. $(CC) $(CFLAGS) -c $< -o $@
  537. ggml-quants.o: ggml-quants.c ggml.h ggml-quants.h
  538. $(CC) $(CFLAGS) -c $< -o $@
  539. OBJS += ggml-alloc.o ggml-backend.o ggml-quants.o
  540. llama.o: llama.cpp ggml.h ggml-alloc.h ggml-backend.h ggml-cuda.h ggml-metal.h llama.h
  541. $(CXX) $(CXXFLAGS) -c $< -o $@
  542. COMMON_H_DEPS = common/common.h common/sampling.h common/log.h
  543. COMMON_DEPS = common.o sampling.o grammar-parser.o build-info.o
  544. common.o: common/common.cpp $(COMMON_H_DEPS)
  545. $(CXX) $(CXXFLAGS) -c $< -o $@
  546. sampling.o: common/sampling.cpp $(COMMON_H_DEPS)
  547. $(CXX) $(CXXFLAGS) -c $< -o $@
  548. console.o: common/console.cpp common/console.h
  549. $(CXX) $(CXXFLAGS) -c $< -o $@
  550. grammar-parser.o: common/grammar-parser.cpp common/grammar-parser.h
  551. $(CXX) $(CXXFLAGS) -c $< -o $@
  552. train.o: common/train.cpp common/train.h
  553. $(CXX) $(CXXFLAGS) -c $< -o $@
  554. libllama.so: llama.o ggml.o $(OBJS)
  555. $(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
  556. libllama.a: llama.o ggml.o $(OBJS) $(COMMON_DEPS)
  557. ar rcs libllama.a llama.o ggml.o $(OBJS) $(COMMON_DEPS)
  558. clean:
  559. rm -vrf *.o tests/*.o *.so *.a *.dll benchmark-matmult common/build-info.cpp *.dot $(COV_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS)
  560. find examples pocs -type f -name "*.o" -delete
  561. #
  562. # Examples
  563. #
  564. # $< is the first prerequisite, i.e. the source file.
  565. # Explicitly compile this to an object file so that it can be cached with ccache.
  566. # The source file is then filtered out from $^ (the list of all prerequisites) and the object file is added instead.
  567. # Helper function that replaces .c, .cpp, and .cu file endings with .o:
  568. GET_OBJ_FILE = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(patsubst %.cu,%.o,$(1))))
  569. main: examples/main/main.cpp ggml.o llama.o $(COMMON_DEPS) console.o grammar-parser.o $(OBJS)
  570. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  571. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  572. @echo
  573. @echo '==== Run ./main -h for help. ===='
  574. @echo
  575. infill: examples/infill/infill.cpp ggml.o llama.o $(COMMON_DEPS) console.o grammar-parser.o $(OBJS)
  576. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  577. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  578. simple: examples/simple/simple.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  579. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  580. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  581. tokenize: examples/tokenize/tokenize.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  582. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  583. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  584. batched: examples/batched/batched.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  585. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  586. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  587. batched-bench: examples/batched-bench/batched-bench.cpp build-info.o ggml.o llama.o common.o $(OBJS)
  588. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  589. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  590. quantize: examples/quantize/quantize.cpp build-info.o ggml.o llama.o $(OBJS)
  591. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  592. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  593. quantize-stats: examples/quantize-stats/quantize-stats.cpp build-info.o ggml.o llama.o $(OBJS)
  594. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  595. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  596. perplexity: examples/perplexity/perplexity.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  597. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  598. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  599. imatrix: examples/imatrix/imatrix.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  600. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  601. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  602. embedding: examples/embedding/embedding.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  603. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  604. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  605. save-load-state: examples/save-load-state/save-load-state.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  606. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  607. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  608. server: examples/server/server.cpp examples/server/oai.hpp examples/server/utils.hpp examples/server/httplib.h examples/server/json.hpp examples/server/index.html.hpp examples/server/index.js.hpp examples/server/completion.js.hpp examples/llava/clip.cpp examples/llava/clip.h examples/llava/llava.h examples/llava/llava.cpp common/stb_image.h ggml.o llama.o $(COMMON_DEPS) grammar-parser.o $(OBJS)
  609. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  610. $(CXX) $(CXXFLAGS) -c examples/llava/clip.cpp -o $(call GET_OBJ_FILE, examples/llava/clip.cpp) -Wno-cast-qual
  611. $(CXX) $(CXXFLAGS) -Iexamples/server $(filter-out %.h %.hpp $< examples/llava/clip.cpp,$^) $(call GET_OBJ_FILE, $<) $(call GET_OBJ_FILE, examples/llava/clip.cpp) -o $@ $(LDFLAGS) $(LWINSOCK2)
  612. gguf: examples/gguf/gguf.cpp ggml.o $(OBJS)
  613. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  614. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  615. train-text-from-scratch: examples/train-text-from-scratch/train-text-from-scratch.cpp ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS)
  616. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  617. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  618. convert-llama2c-to-ggml: examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp ggml.o llama.o $(OBJS)
  619. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  620. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  621. llama-bench: examples/llama-bench/llama-bench.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  622. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  623. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  624. libllava.a: examples/llava/llava.cpp examples/llava/llava.h examples/llava/clip.cpp examples/llava/clip.h common/stb_image.h common/base64.hpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  625. $(CXX) $(CXXFLAGS) -static -fPIC -c $< -o $@ -Wno-cast-qual
  626. llava-cli: examples/llava/llava-cli.cpp examples/llava/clip.h examples/llava/clip.cpp examples/llava/llava.h examples/llava/llava.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  627. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  628. $(CXX) $(CXXFLAGS) -c examples/llava/clip.cpp -o $(call GET_OBJ_FILE, examples/llava/clip.cpp) -Wno-cast-qual
  629. $(CXX) $(CXXFLAGS) -c examples/llava/llava.cpp -o $(call GET_OBJ_FILE, examples/llava/llava.cpp)
  630. $(CXX) $(CXXFLAGS) $(filter-out %.h $< examples/llava/clip.cpp examples/llava/llava.cpp,$^) $(call GET_OBJ_FILE, $<) $(call GET_OBJ_FILE, examples/llava/clip.cpp) $(call GET_OBJ_FILE, examples/llava/llava.cpp) -o $@ $(LDFLAGS)
  631. baby-llama: examples/baby-llama/baby-llama.cpp ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS)
  632. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  633. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  634. beam-search: examples/beam-search/beam-search.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  635. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  636. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  637. finetune: examples/finetune/finetune.cpp ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS)
  638. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  639. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  640. export-lora: examples/export-lora/export-lora.cpp ggml.o common/common.h $(OBJS)
  641. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  642. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  643. speculative: examples/speculative/speculative.cpp ggml.o llama.o $(COMMON_DEPS) grammar-parser.o $(OBJS)
  644. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  645. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  646. parallel: examples/parallel/parallel.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  647. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  648. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  649. lookahead: examples/lookahead/lookahead.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  650. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  651. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  652. lookup: examples/lookup/lookup.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  653. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  654. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  655. passkey: examples/passkey/passkey.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  656. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  657. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  658. ifeq ($(UNAME_S),Darwin)
  659. swift: examples/batched.swift
  660. (cd examples/batched.swift; make build)
  661. endif
  662. common/build-info.cpp: $(wildcard .git/index) scripts/build-info.sh
  663. @sh scripts/build-info.sh "$(CC)" > $@.tmp
  664. @if ! cmp -s $@.tmp $@; then \
  665. mv $@.tmp $@; \
  666. else \
  667. rm $@.tmp; \
  668. fi
  669. build-info.o: common/build-info.cpp
  670. $(CXX) $(CXXFLAGS) -c $(filter-out %.h,$^) -o $@
  671. #
  672. # Tests
  673. #
  674. tests: $(TEST_TARGETS)
  675. benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.o ggml.o $(OBJS)
  676. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  677. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  678. run-benchmark-matmult: benchmark-matmult
  679. ./$@
  680. .PHONY: run-benchmark-matmult swift
  681. vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS)
  682. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  683. $(CXX) $(CXXFLAGS) $(filter-out $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  684. q8dot: pocs/vdot/q8dot.cpp ggml.o $(OBJS)
  685. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  686. $(CXX) $(CXXFLAGS) $(filter-out $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  687. tests/test-llama-grammar: tests/test-llama-grammar.cpp ggml.o grammar-parser.o $(OBJS)
  688. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  689. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  690. tests/test-grammar-parser: tests/test-grammar-parser.cpp ggml.o llama.o grammar-parser.o $(OBJS)
  691. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  692. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  693. tests/test-double-float: tests/test-double-float.cpp ggml.o $(OBJS)
  694. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  695. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  696. tests/test-grad0: tests/test-grad0.cpp ggml.o $(OBJS)
  697. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  698. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  699. tests/test-opt: tests/test-opt.cpp ggml.o $(OBJS)
  700. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  701. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  702. tests/test-quantize-fns: tests/test-quantize-fns.cpp ggml.o $(OBJS)
  703. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  704. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  705. tests/test-quantize-perf: tests/test-quantize-perf.cpp ggml.o $(OBJS)
  706. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  707. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  708. tests/test-sampling: tests/test-sampling.cpp ggml.o llama.o $(OBJS)
  709. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  710. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  711. tests/test-tokenizer-0-falcon: tests/test-tokenizer-0-falcon.cpp ggml.o llama.o $(COMMON_DEPS) console.o $(OBJS)
  712. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  713. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  714. tests/test-tokenizer-0-llama: tests/test-tokenizer-0-llama.cpp ggml.o llama.o $(COMMON_DEPS) console.o $(OBJS)
  715. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  716. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  717. tests/test-tokenizer-1-bpe: tests/test-tokenizer-1-bpe.cpp ggml.o llama.o $(COMMON_DEPS) console.o $(OBJS)
  718. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  719. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  720. tests/test-tokenizer-1-llama: tests/test-tokenizer-1-llama.cpp ggml.o llama.o $(COMMON_DEPS) console.o $(OBJS)
  721. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  722. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  723. tests/test-rope: tests/test-rope.cpp ggml.o $(OBJS)
  724. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  725. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  726. tests/test-c.o: tests/test-c.c llama.h
  727. $(CC) $(CFLAGS) -c $(filter-out %.h,$^) -o $@
  728. tests/test-backend-ops: tests/test-backend-ops.cpp ggml.o $(OBJS)
  729. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  730. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  731. tests/test-model-load-cancel: tests/test-model-load-cancel.cpp ggml.o llama.o tests/get-model.cpp $(COMMON_DEPS) $(OBJS)
  732. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  733. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  734. tests/test-autorelease: tests/test-autorelease.cpp ggml.o llama.o tests/get-model.cpp $(COMMON_DEPS) $(OBJS)
  735. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  736. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  737. tests/test-chat-template: tests/test-chat-template.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
  738. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  739. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)