Makefile 31 KB

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