Makefile 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  1. # Define the default target now so that it is always the first target
  2. BUILD_TARGETS = \
  3. libllava.a \
  4. llama-baby-llama \
  5. llama-batched \
  6. llama-batched-bench \
  7. llama-bench \
  8. llama-benchmark-matmult \
  9. llama-cli \
  10. llama-convert-llama2c-to-ggml \
  11. llama-embedding \
  12. llama-eval-callback \
  13. llama-export-lora \
  14. llama-finetune \
  15. llama-gbnf-validator \
  16. llama-gguf \
  17. llama-gguf-split \
  18. llama-gritlm \
  19. llama-imatrix \
  20. llama-infill \
  21. llama-llava-cli \
  22. llama-lookahead \
  23. llama-lookup \
  24. llama-lookup-create \
  25. llama-lookup-merge \
  26. llama-lookup-stats \
  27. llama-parallel \
  28. llama-passkey \
  29. llama-perplexity \
  30. llama-q8dot \
  31. llama-quantize \
  32. llama-quantize-stats \
  33. llama-retrieval \
  34. llama-save-load-state \
  35. llama-server \
  36. llama-simple \
  37. llama-speculative \
  38. llama-tokenize \
  39. llama-train-text-from-scratch \
  40. llama-vdot \
  41. llama-cvector-generator \
  42. tests/test-c.o
  43. # Binaries only useful for tests
  44. TEST_TARGETS = \
  45. tests/test-autorelease \
  46. tests/test-backend-ops \
  47. tests/test-double-float \
  48. tests/test-grad0 \
  49. tests/test-grammar-integration \
  50. tests/test-grammar-parser \
  51. tests/test-json-schema-to-grammar \
  52. tests/test-llama-grammar \
  53. tests/test-model-load-cancel \
  54. tests/test-opt \
  55. tests/test-quantize-fns \
  56. tests/test-quantize-perf \
  57. tests/test-rope \
  58. tests/test-sampling \
  59. tests/test-tokenizer-0 \
  60. tests/test-tokenizer-1-bpe \
  61. tests/test-tokenizer-1-spm
  62. # Deprecation aliases
  63. ifdef LLAMA_CUBLAS
  64. $(error LLAMA_CUBLAS is removed. Use GGML_CUDA instead.)
  65. endif
  66. ifdef LLAMA_CUDA
  67. GGML_CUDA := 1
  68. DEPRECATE_WARNING := 1
  69. endif
  70. ifdef LLAMA_KOMPUTE
  71. GGML_KOMPUTE := 1
  72. DEPRECATE_WARNING := 1
  73. endif
  74. ifdef LLAMA_METAL
  75. GGML_METAL := 1
  76. DEPRECATE_WARNING := 1
  77. endif
  78. ifdef LLAMA_OPENMP
  79. GGML_OPENMP := 1
  80. DEPRECATE_WARNING := 1
  81. endif
  82. ifdef LLAMA_RPC
  83. GGML_RPC := 1
  84. DEPRECATE_WARNING := 1
  85. endif
  86. ifdef LLAMA_SYCL
  87. GGML_SYCL := 1
  88. DEPRECATE_WARNING := 1
  89. endif
  90. ifdef LLAMA_SYCL_F16
  91. GGML_SYCL_F16 := 1
  92. DEPRECATE_WARNING := 1
  93. endif
  94. ifdef LLAMA_OPENBLAS
  95. GGML_OPENBLAS := 1
  96. DEPRECATE_WARNING := 1
  97. endif
  98. ifdef LLAMA_OPENBLAS64
  99. GGML_OPENBLAS64 := 1
  100. DEPRECATE_WARNING := 1
  101. endif
  102. ifdef LLAMA_BLIS
  103. GGML_BLIS := 1
  104. DEPRECATE_WARNING := 1
  105. endif
  106. ifdef LLAMA_NO_LLAMAFILE
  107. GGML_NO_LLAMAFILE := 1
  108. DEPRECATE_WARNING := 1
  109. endif
  110. ifdef LLAMA_NO_ACCELERATE
  111. GGML_NO_ACCELERATE := 1
  112. DEPRECATE_WARNING := 1
  113. endif
  114. ifdef LLAMA_NO_OPENMP
  115. GGML_NO_OPENMP := 1
  116. DEPRECATE_WARNING := 1
  117. endif
  118. ifdef LLAMA_NO_METAL
  119. GGML_NO_METAL := 1
  120. DEPRECATE_WARNING := 1
  121. endif
  122. ifndef UNAME_S
  123. UNAME_S := $(shell uname -s)
  124. endif
  125. ifndef UNAME_P
  126. UNAME_P := $(shell uname -p)
  127. endif
  128. ifndef UNAME_M
  129. UNAME_M := $(shell uname -m)
  130. endif
  131. MK_CFLAGS += -O3
  132. MK_CXXFLAGS += -O3
  133. ifndef LLAMA_DEBUG
  134. MK_NVCCFLAGS += -O3
  135. endif # LLAMA_DEBUG
  136. # In GNU make default CXX is g++ instead of c++. Let's fix that so that users
  137. # of non-gcc compilers don't have to provide g++ alias or wrapper.
  138. DEFCC := cc
  139. DEFCXX := c++
  140. ifeq ($(origin CC),default)
  141. CC := $(DEFCC)
  142. endif
  143. ifeq ($(origin CXX),default)
  144. CXX := $(DEFCXX)
  145. endif
  146. # Mac OS + Arm can report x86_64
  147. # ref: https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment-1282546789
  148. ifeq ($(UNAME_S),Darwin)
  149. ifndef GGML_NO_METAL
  150. GGML_METAL := 1
  151. endif
  152. GGML_NO_OPENMP := 1
  153. ifneq ($(UNAME_P),arm)
  154. SYSCTL_M := $(shell sysctl -n hw.optional.arm64 2>/dev/null)
  155. ifeq ($(SYSCTL_M),1)
  156. # UNAME_P := arm
  157. # UNAME_M := arm64
  158. 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)
  159. endif
  160. endif
  161. endif
  162. ifdef GGML_METAL
  163. GGML_METAL_EMBED_LIBRARY := 1
  164. endif
  165. ifdef GGML_RPC
  166. BUILD_TARGETS += rpc-server
  167. endif
  168. default: $(BUILD_TARGETS)
  169. test: $(TEST_TARGETS)
  170. @failures=0; \
  171. for test_target in $(TEST_TARGETS); do \
  172. if [ "$$test_target" = "tests/test-tokenizer-0" ]; then \
  173. ./$$test_target $(CURDIR)/models/ggml-vocab-llama-spm.gguf; \
  174. ./$$test_target $(CURDIR)/models/ggml-vocab-llama-bpe.gguf; \
  175. ./$$test_target $(CURDIR)/models/ggml-vocab-phi-3.gguf; \
  176. ./$$test_target $(CURDIR)/models/ggml-vocab-falcon.gguf; \
  177. ./$$test_target $(CURDIR)/models/ggml-vocab-bert-bge.gguf; \
  178. ./$$test_target $(CURDIR)/models/ggml-vocab-starcoder.gguf; \
  179. ./$$test_target $(CURDIR)/models/ggml-vocab-gpt-2.gguf; \
  180. ./$$test_target $(CURDIR)/models/ggml-vocab-refact.gguf; \
  181. elif [ "$$test_target" = "tests/test-tokenizer-1-spm" ]; then \
  182. continue; \
  183. elif [ "$$test_target" = "tests/test-tokenizer-1-bpe" ]; then \
  184. continue; \
  185. else \
  186. echo "Running test $$test_target..."; \
  187. ./$$test_target; \
  188. fi; \
  189. if [ $$? -ne 0 ]; then \
  190. printf 'Test %s FAILED!\n\n' $$test_target; \
  191. failures=$$(( failures + 1 )); \
  192. else \
  193. printf 'Test %s passed.\n\n' $$test_target; \
  194. fi; \
  195. done; \
  196. if [ $$failures -gt 0 ]; then \
  197. printf '\n%s tests failed.\n' $$failures; \
  198. exit 1; \
  199. fi
  200. @echo 'All tests passed.'
  201. all: $(BUILD_TARGETS) $(TEST_TARGETS)
  202. ifdef RISCV_CROSS_COMPILE
  203. CC := riscv64-unknown-linux-gnu-gcc
  204. CXX := riscv64-unknown-linux-gnu-g++
  205. endif
  206. #
  207. # Compile flags
  208. #
  209. # keep standard at C11 and C++11
  210. MK_CPPFLAGS = -Iggml/include -Iggml/src -Iinclude -Isrc -Icommon
  211. MK_CFLAGS = -std=c11 -fPIC
  212. MK_CXXFLAGS = -std=c++11 -fPIC
  213. MK_NVCCFLAGS = -std=c++11
  214. ifndef LLAMA_NO_CCACHE
  215. CCACHE := $(shell which ccache)
  216. ifdef CCACHE
  217. export CCACHE_SLOPPINESS = time_macros
  218. $(info I ccache found, compilation results will be cached. Disable with LLAMA_NO_CCACHE.)
  219. CC := $(CCACHE) $(CC)
  220. CXX := $(CCACHE) $(CXX)
  221. else
  222. $(info I ccache not found. Consider installing it for faster compilation.)
  223. endif # CCACHE
  224. endif # LLAMA_NO_CCACHE
  225. # clock_gettime came in POSIX.1b (1993)
  226. # CLOCK_MONOTONIC came in POSIX.1-2001 / SUSv3 as optional
  227. # posix_memalign came in POSIX.1-2001 / SUSv3
  228. # M_PI is an XSI extension since POSIX.1-2001 / SUSv3, came in XPG1 (1985)
  229. MK_CPPFLAGS += -D_XOPEN_SOURCE=600
  230. # Somehow in OpenBSD whenever POSIX conformance is specified
  231. # some string functions rely on locale_t availability,
  232. # which was introduced in POSIX.1-2008, forcing us to go higher
  233. ifeq ($(UNAME_S),OpenBSD)
  234. MK_CPPFLAGS += -U_XOPEN_SOURCE -D_XOPEN_SOURCE=700
  235. endif
  236. # Data types, macros and functions related to controlling CPU affinity and
  237. # some memory allocation are available on Linux through GNU extensions in libc
  238. ifeq ($(UNAME_S),Linux)
  239. MK_CPPFLAGS += -D_GNU_SOURCE
  240. endif
  241. # RLIMIT_MEMLOCK came in BSD, is not specified in POSIX.1,
  242. # and on macOS its availability depends on enabling Darwin extensions
  243. # similarly on DragonFly, enabling BSD extensions is necessary
  244. ifeq ($(UNAME_S),Darwin)
  245. MK_CPPFLAGS += -D_DARWIN_C_SOURCE
  246. endif
  247. ifeq ($(UNAME_S),DragonFly)
  248. MK_CPPFLAGS += -D__BSD_VISIBLE
  249. endif
  250. # alloca is a non-standard interface that is not visible on BSDs when
  251. # POSIX conformance is specified, but not all of them provide a clean way
  252. # to enable it in such cases
  253. ifeq ($(UNAME_S),FreeBSD)
  254. MK_CPPFLAGS += -D__BSD_VISIBLE
  255. endif
  256. ifeq ($(UNAME_S),NetBSD)
  257. MK_CPPFLAGS += -D_NETBSD_SOURCE
  258. endif
  259. ifeq ($(UNAME_S),OpenBSD)
  260. MK_CPPFLAGS += -D_BSD_SOURCE
  261. endif
  262. ifdef GGML_SCHED_MAX_COPIES
  263. MK_CPPFLAGS += -DGGML_SCHED_MAX_COPIES=$(GGML_SCHED_MAX_COPIES)
  264. endif
  265. ifdef LLAMA_DEBUG
  266. MK_CFLAGS += -O0 -g
  267. MK_CXXFLAGS += -O0 -g
  268. MK_LDFLAGS += -g
  269. MK_NVCCFLAGS += -O0 -g
  270. ifeq ($(UNAME_S),Linux)
  271. MK_CPPFLAGS += -D_GLIBCXX_ASSERTIONS
  272. endif
  273. else
  274. MK_CPPFLAGS += -DNDEBUG
  275. endif
  276. ifdef LLAMA_SANITIZE_THREAD
  277. MK_CFLAGS += -fsanitize=thread -g
  278. MK_CXXFLAGS += -fsanitize=thread -g
  279. MK_LDFLAGS += -fsanitize=thread -g
  280. endif
  281. ifdef LLAMA_SANITIZE_ADDRESS
  282. MK_CFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
  283. MK_CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
  284. MK_LDFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
  285. endif
  286. ifdef LLAMA_SANITIZE_UNDEFINED
  287. MK_CFLAGS += -fsanitize=undefined -g
  288. MK_CXXFLAGS += -fsanitize=undefined -g
  289. MK_LDFLAGS += -fsanitize=undefined -g
  290. endif
  291. ifdef LLAMA_SERVER_VERBOSE
  292. MK_CPPFLAGS += -DSERVER_VERBOSE=$(LLAMA_SERVER_VERBOSE)
  293. endif
  294. ifdef LLAMA_SERVER_SSL
  295. MK_CPPFLAGS += -DCPPHTTPLIB_OPENSSL_SUPPORT
  296. MK_LDFLAGS += -lssl -lcrypto
  297. endif
  298. ifdef LLAMA_DISABLE_LOGS
  299. MK_CPPFLAGS += -DLOG_DISABLE_LOGS
  300. endif # LLAMA_DISABLE_LOGS
  301. # warnings
  302. WARN_FLAGS = \
  303. -Wall \
  304. -Wextra \
  305. -Wpedantic \
  306. -Wcast-qual \
  307. -Wno-unused-function
  308. MK_CFLAGS += \
  309. $(WARN_FLAGS) \
  310. -Wshadow \
  311. -Wstrict-prototypes \
  312. -Wpointer-arith \
  313. -Wmissing-prototypes \
  314. -Werror=implicit-int \
  315. -Werror=implicit-function-declaration
  316. MK_CXXFLAGS += \
  317. $(WARN_FLAGS) \
  318. -Wmissing-declarations \
  319. -Wmissing-noreturn
  320. ifeq ($(LLAMA_FATAL_WARNINGS),1)
  321. MK_CFLAGS += -Werror
  322. MK_CXXFLAGS += -Werror
  323. endif
  324. # this version of Apple ld64 is buggy
  325. ifneq '' '$(findstring dyld-1015.7,$(shell $(CC) $(LDFLAGS) -Wl,-v 2>&1))'
  326. MK_CPPFLAGS += -DHAVE_BUGGY_APPLE_LINKER
  327. endif
  328. # OS specific
  329. # TODO: support Windows
  330. ifneq '' '$(filter $(UNAME_S),Linux Darwin FreeBSD NetBSD OpenBSD Haiku)'
  331. MK_CFLAGS += -pthread
  332. MK_CXXFLAGS += -pthread
  333. endif
  334. # detect Windows
  335. ifneq ($(findstring _NT,$(UNAME_S)),)
  336. _WIN32 := 1
  337. endif
  338. # library name prefix
  339. ifneq ($(_WIN32),1)
  340. LIB_PRE := lib
  341. endif
  342. # Dynamic Shared Object extension
  343. ifneq ($(_WIN32),1)
  344. DSO_EXT := .so
  345. else
  346. DSO_EXT := .dll
  347. endif
  348. # Windows Sockets 2 (Winsock) for network-capable apps
  349. ifeq ($(_WIN32),1)
  350. LWINSOCK2 := -lws2_32
  351. endif
  352. ifdef LLAMA_GPROF
  353. MK_CFLAGS += -pg
  354. MK_CXXFLAGS += -pg
  355. endif
  356. # Architecture specific
  357. # TODO: probably these flags need to be tweaked on some architectures
  358. # feel free to update the Makefile for your architecture and send a pull request or issue
  359. ifndef RISCV
  360. ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686 amd64))
  361. # Use all CPU extensions that are available:
  362. MK_CFLAGS += -march=native -mtune=native
  363. HOST_CXXFLAGS += -march=native -mtune=native
  364. # Usage AVX-only
  365. #MK_CFLAGS += -mfma -mf16c -mavx
  366. #MK_CXXFLAGS += -mfma -mf16c -mavx
  367. # Usage SSSE3-only (Not is SSE3!)
  368. #MK_CFLAGS += -mssse3
  369. #MK_CXXFLAGS += -mssse3
  370. endif
  371. ifneq '' '$(findstring mingw,$(shell $(CC) -dumpmachine))'
  372. # The stack is only 16-byte aligned on Windows, so don't let gcc emit aligned moves.
  373. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54412
  374. # https://github.com/ggerganov/llama.cpp/issues/2922
  375. MK_CFLAGS += -Xassembler -muse-unaligned-vector-move
  376. MK_CXXFLAGS += -Xassembler -muse-unaligned-vector-move
  377. # Target Windows 8 for PrefetchVirtualMemory
  378. MK_CPPFLAGS += -D_WIN32_WINNT=0x602
  379. endif
  380. ifneq ($(filter aarch64%,$(UNAME_M)),)
  381. # Apple M1, M2, etc.
  382. # Raspberry Pi 3, 4, Zero 2 (64-bit)
  383. # Nvidia Jetson
  384. MK_CFLAGS += -mcpu=native
  385. MK_CXXFLAGS += -mcpu=native
  386. JETSON_RELEASE_INFO = $(shell jetson_release)
  387. ifdef JETSON_RELEASE_INFO
  388. ifneq ($(filter TX2%,$(JETSON_RELEASE_INFO)),)
  389. JETSON_EOL_MODULE_DETECT = 1
  390. CC = aarch64-unknown-linux-gnu-gcc
  391. cxx = aarch64-unknown-linux-gnu-g++
  392. endif
  393. endif
  394. endif
  395. ifneq ($(filter armv6%,$(UNAME_M)),)
  396. # Raspberry Pi 1, Zero
  397. MK_CFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access
  398. MK_CXXFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access
  399. endif
  400. ifneq ($(filter armv7%,$(UNAME_M)),)
  401. # Raspberry Pi 2
  402. MK_CFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access -funsafe-math-optimizations
  403. MK_CXXFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access -funsafe-math-optimizations
  404. endif
  405. ifneq ($(filter armv8%,$(UNAME_M)),)
  406. # Raspberry Pi 3, 4, Zero 2 (32-bit)
  407. MK_CFLAGS += -mfp16-format=ieee -mno-unaligned-access
  408. MK_CXXFLAGS += -mfp16-format=ieee -mno-unaligned-access
  409. endif
  410. ifneq ($(filter ppc64%,$(UNAME_M)),)
  411. POWER9_M := $(shell grep "POWER9" /proc/cpuinfo)
  412. ifneq (,$(findstring POWER9,$(POWER9_M)))
  413. MK_CFLAGS += -mcpu=power9
  414. MK_CXXFLAGS += -mcpu=power9
  415. endif
  416. endif
  417. ifneq ($(filter ppc64le%,$(UNAME_M)),)
  418. MK_CFLAGS += -mcpu=powerpc64le
  419. MK_CXXFLAGS += -mcpu=powerpc64le
  420. CUDA_POWER_ARCH = 1
  421. endif
  422. ifneq ($(filter loongarch64%,$(UNAME_M)),)
  423. MK_CFLAGS += -mlasx
  424. MK_CXXFLAGS += -mlasx
  425. endif
  426. else
  427. MK_CFLAGS += -march=rv64gcv -mabi=lp64d
  428. MK_CXXFLAGS += -march=rv64gcv -mabi=lp64d
  429. endif
  430. ifndef GGML_NO_ACCELERATE
  431. # Mac OS - include Accelerate framework.
  432. # `-framework Accelerate` works both with Apple Silicon and Mac Intel
  433. ifeq ($(UNAME_S),Darwin)
  434. MK_CPPFLAGS += -DGGML_USE_ACCELERATE -DGGML_USE_BLAS
  435. MK_CPPFLAGS += -DACCELERATE_NEW_LAPACK
  436. MK_CPPFLAGS += -DACCELERATE_LAPACK_ILP64
  437. MK_LDFLAGS += -framework Accelerate
  438. OBJ_GGML += ggml/src/ggml-blas.o
  439. endif
  440. endif # GGML_NO_ACCELERATE
  441. ifndef GGML_NO_OPENMP
  442. MK_CPPFLAGS += -DGGML_USE_OPENMP
  443. MK_CFLAGS += -fopenmp
  444. MK_CXXFLAGS += -fopenmp
  445. endif # GGML_NO_OPENMP
  446. ifdef GGML_OPENBLAS
  447. MK_CPPFLAGS += -DGGML_USE_BLAS $(shell pkg-config --cflags-only-I openblas)
  448. MK_CFLAGS += $(shell pkg-config --cflags-only-other openblas)
  449. MK_LDFLAGS += $(shell pkg-config --libs openblas)
  450. OBJ_GGML += ggml/src/ggml-blas.o
  451. endif # GGML_OPENBLAS
  452. ifdef GGML_OPENBLAS64
  453. MK_CPPFLAGS += -DGGML_USE_BLAS $(shell pkg-config --cflags-only-I openblas64)
  454. MK_CFLAGS += $(shell pkg-config --cflags-only-other openblas64)
  455. MK_LDFLAGS += $(shell pkg-config --libs openblas64)
  456. OBJ_GGML += ggml/src/ggml-blas.o
  457. endif # GGML_OPENBLAS64
  458. ifdef GGML_BLIS
  459. MK_CPPFLAGS += -DGGML_USE_BLAS -I/usr/local/include/blis -I/usr/include/blis
  460. MK_LDFLAGS += -lblis -L/usr/local/lib
  461. OBJ_GGML += ggml/src/ggml-blas.o
  462. endif # GGML_BLIS
  463. ifndef GGML_NO_LLAMAFILE
  464. MK_CPPFLAGS += -DGGML_USE_LLAMAFILE
  465. OBJ_GGML += ggml/src/sgemm.o
  466. endif
  467. ifdef GGML_RPC
  468. MK_CPPFLAGS += -DGGML_USE_RPC
  469. OBJ_GGML += ggml/src/ggml-rpc.o
  470. endif # GGML_RPC
  471. OBJ_CUDA_TMPL = $(patsubst %.cu,%.o,$(wildcard ggml/src/ggml-cuda/template-instances/fattn-wmma*.cu))
  472. OBJ_CUDA_TMPL += $(patsubst %.cu,%.o,$(wildcard ggml/src/ggml-cuda/template-instances/mmq*.cu))
  473. ifdef GGML_CUDA_FA_ALL_QUANTS
  474. OBJ_CUDA_TMPL += $(patsubst %.cu,%.o,$(wildcard ggml/src/ggml-cuda/template-instances/fattn-vec*.cu))
  475. else
  476. OBJ_CUDA_TMPL += $(patsubst %.cu,%.o,$(wildcard ggml/src/ggml-cuda/template-instances/fattn-vec*q4_0-q4_0.cu))
  477. OBJ_CUDA_TMPL += $(patsubst %.cu,%.o,$(wildcard ggml/src/ggml-cuda/template-instances/fattn-vec*q8_0-q8_0.cu))
  478. OBJ_CUDA_TMPL += $(patsubst %.cu,%.o,$(wildcard ggml/src/ggml-cuda/template-instances/fattn-vec*f16-f16.cu))
  479. endif # GGML_CUDA_FA_ALL_QUANTS
  480. ifdef GGML_CUDA
  481. ifneq ('', '$(wildcard /opt/cuda)')
  482. CUDA_PATH ?= /opt/cuda
  483. else
  484. CUDA_PATH ?= /usr/local/cuda
  485. endif
  486. MK_CPPFLAGS += -DGGML_USE_CUDA -I$(CUDA_PATH)/include -I$(CUDA_PATH)/targets/$(UNAME_M)-linux/include -DGGML_CUDA_USE_GRAPHS
  487. MK_LDFLAGS += -lcuda -lcublas -lculibos -lcudart -lcublasLt -lpthread -ldl -lrt -L$(CUDA_PATH)/lib64 -L/usr/lib64 -L$(CUDA_PATH)/targets/$(UNAME_M)-linux/lib -L$(CUDA_PATH)/lib64/stubs -L/usr/lib/wsl/lib
  488. MK_NVCCFLAGS += -use_fast_math
  489. OBJ_GGML += ggml/src/ggml-cuda.o
  490. OBJ_GGML += $(patsubst %.cu,%.o,$(wildcard ggml/src/ggml-cuda/*.cu))
  491. OBJ_GGML += $(OBJ_CUDA_TMPL)
  492. ifdef LLAMA_FATAL_WARNINGS
  493. MK_NVCCFLAGS += -Werror all-warnings
  494. endif # LLAMA_FATAL_WARNINGS
  495. ifndef JETSON_EOL_MODULE_DETECT
  496. MK_NVCCFLAGS += --forward-unknown-to-host-compiler
  497. endif # JETSON_EOL_MODULE_DETECT
  498. ifdef LLAMA_DEBUG
  499. MK_NVCCFLAGS += -lineinfo
  500. endif # LLAMA_DEBUG
  501. ifdef GGML_CUDA_DEBUG
  502. MK_NVCCFLAGS += --device-debug
  503. endif # GGML_CUDA_DEBUG
  504. ifdef GGML_CUDA_NVCC
  505. NVCC = $(CCACHE) $(GGML_CUDA_NVCC)
  506. else
  507. NVCC = $(CCACHE) nvcc
  508. endif #GGML_CUDA_NVCC
  509. ifdef CUDA_DOCKER_ARCH
  510. MK_NVCCFLAGS += -Wno-deprecated-gpu-targets -arch=$(CUDA_DOCKER_ARCH)
  511. else ifndef CUDA_POWER_ARCH
  512. MK_NVCCFLAGS += -arch=native
  513. endif # CUDA_DOCKER_ARCH
  514. ifdef GGML_CUDA_FORCE_DMMV
  515. MK_NVCCFLAGS += -DGGML_CUDA_FORCE_DMMV
  516. endif # GGML_CUDA_FORCE_DMMV
  517. ifdef GGML_CUDA_FORCE_MMQ
  518. MK_NVCCFLAGS += -DGGML_CUDA_FORCE_MMQ
  519. endif # GGML_CUDA_FORCE_MMQ
  520. ifdef GGML_CUDA_FORCE_CUBLAS
  521. MK_NVCCFLAGS += -DGGML_CUDA_FORCE_CUBLAS
  522. endif # GGML_CUDA_FORCE_CUBLAS
  523. ifdef GGML_CUDA_DMMV_X
  524. MK_NVCCFLAGS += -DGGML_CUDA_DMMV_X=$(GGML_CUDA_DMMV_X)
  525. else
  526. MK_NVCCFLAGS += -DGGML_CUDA_DMMV_X=32
  527. endif # GGML_CUDA_DMMV_X
  528. ifdef GGML_CUDA_MMV_Y
  529. MK_NVCCFLAGS += -DGGML_CUDA_MMV_Y=$(GGML_CUDA_MMV_Y)
  530. else ifdef GGML_CUDA_DMMV_Y
  531. MK_NVCCFLAGS += -DGGML_CUDA_MMV_Y=$(GGML_CUDA_DMMV_Y) # for backwards compatibility
  532. else
  533. MK_NVCCFLAGS += -DGGML_CUDA_MMV_Y=1
  534. endif # GGML_CUDA_MMV_Y
  535. ifdef GGML_CUDA_F16
  536. MK_NVCCFLAGS += -DGGML_CUDA_F16
  537. endif # GGML_CUDA_F16
  538. ifdef GGML_CUDA_DMMV_F16
  539. MK_NVCCFLAGS += -DGGML_CUDA_F16
  540. endif # GGML_CUDA_DMMV_F16
  541. ifdef GGML_CUDA_KQUANTS_ITER
  542. MK_NVCCFLAGS += -DK_QUANTS_PER_ITERATION=$(GGML_CUDA_KQUANTS_ITER)
  543. else
  544. MK_NVCCFLAGS += -DK_QUANTS_PER_ITERATION=2
  545. endif
  546. ifdef GGML_CUDA_PEER_MAX_BATCH_SIZE
  547. MK_NVCCFLAGS += -DGGML_CUDA_PEER_MAX_BATCH_SIZE=$(GGML_CUDA_PEER_MAX_BATCH_SIZE)
  548. else
  549. MK_NVCCFLAGS += -DGGML_CUDA_PEER_MAX_BATCH_SIZE=128
  550. endif # GGML_CUDA_PEER_MAX_BATCH_SIZE
  551. ifdef GGML_CUDA_NO_PEER_COPY
  552. MK_NVCCFLAGS += -DGGML_CUDA_NO_PEER_COPY
  553. endif # GGML_CUDA_NO_PEER_COPY
  554. ifdef GGML_CUDA_CCBIN
  555. MK_NVCCFLAGS += -ccbin $(GGML_CUDA_CCBIN)
  556. endif # GGML_CUDA_CCBIN
  557. ifdef GGML_CUDA_FA_ALL_QUANTS
  558. MK_NVCCFLAGS += -DGGML_CUDA_FA_ALL_QUANTS
  559. endif # GGML_CUDA_FA_ALL_QUANTS
  560. ifdef JETSON_EOL_MODULE_DETECT
  561. define NVCC_COMPILE
  562. $(NVCC) -I. -Icommon -D_XOPEN_SOURCE=600 -D_GNU_SOURCE -DNDEBUG -DGGML_USE_CUDA -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 $@
  563. endef # NVCC_COMPILE
  564. else
  565. define NVCC_COMPILE
  566. $(NVCC) $(NVCCFLAGS) $(CPPFLAGS) -Xcompiler "$(CUDA_CXXFLAGS)" -c $< -o $@
  567. endef # NVCC_COMPILE
  568. endif # JETSON_EOL_MODULE_DETECT
  569. ggml/src/ggml-cuda/%.o: \
  570. ggml/src/ggml-cuda/%.cu \
  571. ggml/include/ggml.h \
  572. ggml/src/ggml-common.h \
  573. ggml/src/ggml-cuda/common.cuh
  574. $(NVCC_COMPILE)
  575. ggml/src/ggml-cuda.o: \
  576. ggml/src/ggml-cuda.cu \
  577. ggml/include/ggml-cuda.h \
  578. ggml/include/ggml.h \
  579. ggml/include/ggml-backend.h \
  580. ggml/src/ggml-backend-impl.h \
  581. ggml/src/ggml-common.h \
  582. $(wildcard ggml/src/ggml-cuda/*.cuh)
  583. $(NVCC_COMPILE)
  584. endif # GGML_CUDA
  585. ifdef GGML_VULKAN
  586. MK_CPPFLAGS += -DGGML_USE_VULKAN
  587. MK_LDFLAGS += -lvulkan
  588. OBJ_GGML += ggml/src/ggml-vulkan.o
  589. ifdef GGML_VULKAN_CHECK_RESULTS
  590. MK_CPPFLAGS += -DGGML_VULKAN_CHECK_RESULTS
  591. endif
  592. ifdef GGML_VULKAN_DEBUG
  593. MK_CPPFLAGS += -DGGML_VULKAN_DEBUG
  594. endif
  595. ifdef GGML_VULKAN_MEMORY_DEBUG
  596. MK_CPPFLAGS += -DGGML_VULKAN_MEMORY_DEBUG
  597. endif
  598. ifdef GGML_VULKAN_VALIDATE
  599. MK_CPPFLAGS += -DGGML_VULKAN_VALIDATE
  600. endif
  601. ifdef GGML_VULKAN_RUN_TESTS
  602. MK_CPPFLAGS += -DGGML_VULKAN_RUN_TESTS
  603. endif
  604. ggml/src/ggml-vulkan.o: \
  605. ggml/src/ggml-vulkan.cpp \
  606. ggml/include/ggml-vulkan.h
  607. $(CXX) $(CXXFLAGS) -c $< -o $@
  608. endif # GGML_VULKAN
  609. ifdef GGML_HIPBLAS
  610. ifeq ($(wildcard /opt/rocm),)
  611. ROCM_PATH ?= /usr
  612. AMDGPU_TARGETS ?= $(shell $(shell which amdgpu-arch))
  613. else
  614. ROCM_PATH ?= /opt/rocm
  615. AMDGPU_TARGETS ?= $(shell $(ROCM_PATH)/llvm/bin/amdgpu-arch)
  616. endif
  617. GGML_CUDA_DMMV_X ?= 32
  618. GGML_CUDA_MMV_Y ?= 1
  619. GGML_CUDA_KQUANTS_ITER ?= 2
  620. MK_CPPFLAGS += -DGGML_USE_HIPBLAS -DGGML_USE_CUDA
  621. ifdef GGML_HIP_UMA
  622. MK_CPPFLAGS += -DGGML_HIP_UMA
  623. endif # GGML_HIP_UMA
  624. MK_LDFLAGS += -L$(ROCM_PATH)/lib -Wl,-rpath=$(ROCM_PATH)/lib
  625. MK_LDFLAGS += -L$(ROCM_PATH)/lib64 -Wl,-rpath=$(ROCM_PATH)/lib64
  626. MK_LDFLAGS += -lhipblas -lamdhip64 -lrocblas
  627. HIPCC ?= $(CCACHE) $(ROCM_PATH)/bin/hipcc
  628. HIPFLAGS += $(addprefix --offload-arch=,$(AMDGPU_TARGETS))
  629. HIPFLAGS += -DGGML_CUDA_DMMV_X=$(GGML_CUDA_DMMV_X)
  630. HIPFLAGS += -DGGML_CUDA_MMV_Y=$(GGML_CUDA_MMV_Y)
  631. HIPFLAGS += -DK_QUANTS_PER_ITERATION=$(GGML_CUDA_KQUANTS_ITER)
  632. ifdef GGML_CUDA_FORCE_DMMV
  633. HIPFLAGS += -DGGML_CUDA_FORCE_DMMV
  634. endif # GGML_CUDA_FORCE_DMMV
  635. ifdef GGML_CUDA_NO_PEER_COPY
  636. HIPFLAGS += -DGGML_CUDA_NO_PEER_COPY
  637. endif # GGML_CUDA_NO_PEER_COPY
  638. OBJ_GGML += ggml/src/ggml-cuda.o
  639. OBJ_GGML += $(patsubst %.cu,%.o,$(wildcard ggml/src/ggml-cuda/*.cu))
  640. OBJ_GGML += $(OBJ_CUDA_TMPL)
  641. ggml/src/ggml-cuda.o: \
  642. ggml/src/ggml-cuda.cu \
  643. ggml/include/ggml-cuda.h \
  644. ggml/include/ggml.h \
  645. ggml/include/ggml-backend.h \
  646. ggml/src/ggml-backend-impl.h \
  647. ggml/src/ggml-common.h \
  648. $(wildcard ggml/src/ggml-cuda/*.cuh)
  649. $(HIPCC) $(CXXFLAGS) $(HIPFLAGS) -x hip -c -o $@ $<
  650. ggml/src/ggml-cuda/%.o: \
  651. ggml/src/ggml-cuda/%.cu \
  652. ggml/include/ggml.h \
  653. ggml/src/ggml-common.h \
  654. ggml/src/ggml-cuda/common.cuh
  655. $(HIPCC) $(CXXFLAGS) $(HIPFLAGS) -x hip -c -o $@ $<
  656. endif # GGML_HIPBLAS
  657. ifdef GGML_METAL
  658. MK_CPPFLAGS += -DGGML_USE_METAL
  659. MK_LDFLAGS += -framework Foundation -framework Metal -framework MetalKit
  660. OBJ_GGML += ggml/src/ggml-metal.o
  661. ifdef GGML_METAL_NDEBUG
  662. MK_CPPFLAGS += -DGGML_METAL_NDEBUG
  663. endif
  664. ifdef GGML_METAL_EMBED_LIBRARY
  665. MK_CPPFLAGS += -DGGML_METAL_EMBED_LIBRARY
  666. OBJ_GGML += ggml/src/ggml-metal-embed.o
  667. endif
  668. endif # GGML_METAL
  669. ifdef GGML_METAL
  670. ggml/src/ggml-metal.o: \
  671. ggml/src/ggml-metal.m \
  672. ggml/include/ggml-metal.h \
  673. ggml/include/ggml.h
  674. $(CC) $(CFLAGS) -c $< -o $@
  675. ifdef GGML_METAL_EMBED_LIBRARY
  676. ggml/src/ggml-metal-embed.o: \
  677. ggml/src/ggml-metal.metal \
  678. ggml/src/ggml-common.h
  679. @echo "Embedding Metal library"
  680. @sed -e '/#include "ggml-common.h"/r ggml/src/ggml-common.h' -e '/#include "ggml-common.h"/d' < ggml/src/ggml-metal.metal > ggml/src/ggml-metal-embed.metal
  681. $(eval TEMP_ASSEMBLY=$(shell mktemp))
  682. @echo ".section __DATA, __ggml_metallib" > $(TEMP_ASSEMBLY)
  683. @echo ".globl _ggml_metallib_start" >> $(TEMP_ASSEMBLY)
  684. @echo "_ggml_metallib_start:" >> $(TEMP_ASSEMBLY)
  685. @echo ".incbin \"ggml/src/ggml-metal-embed.metal\"" >> $(TEMP_ASSEMBLY)
  686. @echo ".globl _ggml_metallib_end" >> $(TEMP_ASSEMBLY)
  687. @echo "_ggml_metallib_end:" >> $(TEMP_ASSEMBLY)
  688. @$(AS) $(TEMP_ASSEMBLY) -o $@
  689. @rm -f ${TEMP_ASSEMBLY}
  690. endif
  691. endif # GGML_METAL
  692. OBJ_GGML += \
  693. ggml/src/ggml.o \
  694. ggml/src/ggml-alloc.o \
  695. ggml/src/ggml-backend.o \
  696. ggml/src/ggml-quants.o
  697. OBJ_LLAMA = \
  698. src/llama.o \
  699. src/unicode.o \
  700. src/unicode-data.o
  701. OBJ_COMMON = \
  702. common/common.o \
  703. common/console.o \
  704. common/ngram-cache.o \
  705. common/sampling.o \
  706. common/train.o \
  707. common/grammar-parser.o \
  708. common/build-info.o \
  709. common/json-schema-to-grammar.o
  710. OBJ_ALL = $(OBJ_GGML) $(OBJ_LLAMA) $(OBJ_COMMON)
  711. LIB_GGML = $(LIB_PRE)ggml$(DSO_EXT)
  712. LIB_GGML_S = $(LIB_PRE)ggml.a
  713. LIB_LLAMA = $(LIB_PRE)llama$(DSO_EXT)
  714. LIB_LLAMA_S = $(LIB_PRE)llama.a
  715. LIB_COMMON = $(LIB_PRE)common$(DSO_EXT)
  716. LIB_COMMON_S = $(LIB_PRE)common.a
  717. LIB_ALL = $(LIB_GGML) $(LIB_LLAMA) $(LIB_COMMON)
  718. LIB_ALL_S = $(LIB_GGML_S) $(LIB_LLAMA_S) $(LIB_COMMON_S)
  719. GF_CC := $(CC)
  720. include scripts/get-flags.mk
  721. # combine build flags with cmdline overrides
  722. override CPPFLAGS := $(MK_CPPFLAGS) $(CPPFLAGS)
  723. override CFLAGS := $(CPPFLAGS) $(MK_CFLAGS) $(GF_CFLAGS) $(CFLAGS)
  724. BASE_CXXFLAGS := $(MK_CXXFLAGS) $(CXXFLAGS)
  725. override CXXFLAGS := $(BASE_CXXFLAGS) $(HOST_CXXFLAGS) $(GF_CXXFLAGS) $(CPPFLAGS)
  726. override NVCCFLAGS := $(MK_NVCCFLAGS) $(NVCCFLAGS)
  727. override LDFLAGS := $(MK_LDFLAGS) $(LDFLAGS)
  728. # identify CUDA host compiler
  729. ifdef GGML_CUDA
  730. GF_CC := $(NVCC) $(NVCCFLAGS) 2>/dev/null .c -Xcompiler
  731. include scripts/get-flags.mk
  732. CUDA_CXXFLAGS := $(BASE_CXXFLAGS) $(GF_CXXFLAGS) -Wno-pedantic
  733. endif
  734. ifdef LLAMA_CURL
  735. override CXXFLAGS := $(CXXFLAGS) -DLLAMA_USE_CURL
  736. override LDFLAGS := $(LDFLAGS) -lcurl
  737. endif
  738. #
  739. # Print build information
  740. #
  741. $(info I llama.cpp build info: )
  742. $(info I UNAME_S: $(UNAME_S))
  743. $(info I UNAME_P: $(UNAME_P))
  744. $(info I UNAME_M: $(UNAME_M))
  745. $(info I CFLAGS: $(CFLAGS))
  746. $(info I CXXFLAGS: $(CXXFLAGS))
  747. $(info I NVCCFLAGS: $(NVCCFLAGS))
  748. $(info I LDFLAGS: $(LDFLAGS))
  749. $(info I CC: $(shell $(CC) --version | head -n 1))
  750. $(info I CXX: $(shell $(CXX) --version | head -n 1))
  751. ifdef GGML_CUDA
  752. $(info I NVCC: $(shell $(NVCC) --version | tail -n 1))
  753. CUDA_VERSION := $(shell $(NVCC) --version | grep -oP 'release (\K[0-9]+\.[0-9])')
  754. ifeq ($(shell awk -v "v=$(CUDA_VERSION)" 'BEGIN { print (v < 11.7) }'),1)
  755. ifndef CUDA_DOCKER_ARCH
  756. ifndef CUDA_POWER_ARCH
  757. $(error I ERROR: For CUDA versions < 11.7 a target CUDA architecture must be explicitly provided via environment variable CUDA_DOCKER_ARCH, e.g. by running "export CUDA_DOCKER_ARCH=compute_XX" on Unix-like systems, where XX is the minimum compute capability that the code needs to run on. A list with compute capabilities can be found here: https://developer.nvidia.com/cuda-gpus )
  758. endif # CUDA_POWER_ARCH
  759. endif # CUDA_DOCKER_ARCH
  760. endif # eq ($(shell echo "$(CUDA_VERSION) < 11.7" | bc),1)
  761. endif # GGML_CUDA
  762. $(info )
  763. ifdef DEPRECATE_WARNING
  764. $(info !!! DEPRECATION WARNING !!!)
  765. $(info The following LLAMA_ options are deprecated and will be removed in the future. Use the GGML_ prefix instead)
  766. $(info - LLAMA_CUDA)
  767. $(info - LLAMA_METAL)
  768. $(info - LLAMA_METAL_EMBED_LIBRARY)
  769. $(info - LLAMA_OPENMP)
  770. $(info - LLAMA_RPC)
  771. $(info - LLAMA_SYCL)
  772. $(info - LLAMA_SYCL_F16)
  773. $(info - LLAMA_OPENBLAS)
  774. $(info - LLAMA_OPENBLAS64)
  775. $(info - LLAMA_BLIS)
  776. $(info - LLAMA_NO_LLAMAFILE)
  777. $(info - LLAMA_NO_ACCELERATE)
  778. $(info - LLAMA_NO_OPENMP)
  779. $(info - LLAMA_NO_METAL)
  780. $(info )
  781. endif
  782. #
  783. # Build libraries
  784. #
  785. # ggml
  786. ggml/src/ggml.o: \
  787. ggml/src/ggml.c \
  788. ggml/include/ggml.h
  789. $(CC) $(CFLAGS) -c $< -o $@
  790. ggml/src/ggml-alloc.o: \
  791. ggml/src/ggml-alloc.c \
  792. ggml/include/ggml.h \
  793. ggml/include/ggml-alloc.h
  794. $(CC) $(CFLAGS) -c $< -o $@
  795. ggml/src/ggml-backend.o: \
  796. ggml/src/ggml-backend.c \
  797. ggml/include/ggml.h \
  798. ggml/include/ggml-backend.h
  799. $(CC) $(CFLAGS) -c $< -o $@
  800. ggml/src/ggml-quants.o: \
  801. ggml/src/ggml-quants.c \
  802. ggml/include/ggml.h \
  803. ggml/src/ggml-quants.h \
  804. ggml/src/ggml-common.h
  805. $(CC) $(CFLAGS) -c $< -o $@
  806. ggml/src/ggml-blas.o: \
  807. ggml/src/ggml-blas.cpp \
  808. ggml/include/ggml-blas.h
  809. $(CXX) $(CXXFLAGS) -c $< -o $@
  810. ifndef GGML_NO_LLAMAFILE
  811. ggml/src/sgemm.o: \
  812. ggml/src/sgemm.cpp \
  813. ggml/src/sgemm.h \
  814. ggml/include/ggml.h
  815. $(CXX) $(CXXFLAGS) -c $< -o $@
  816. endif # GGML_NO_LLAMAFILE
  817. ifdef GGML_RPC
  818. ggml/src/ggml-rpc.o: \
  819. ggml/src/ggml-rpc.cpp \
  820. ggml/include/ggml-rpc.h
  821. $(CXX) $(CXXFLAGS) -c $< -o $@
  822. endif # GGML_RPC
  823. $(LIB_GGML): \
  824. $(OBJ_GGML)
  825. $(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
  826. $(LIB_GGML_S): \
  827. $(OBJ_GGML)
  828. ar rcs $(LIB_GGML_S) $^
  829. # llama
  830. src/unicode.o: \
  831. src/unicode.cpp \
  832. src/unicode.h
  833. $(CXX) $(CXXFLAGS) -c $< -o $@
  834. src/unicode-data.o: \
  835. src/unicode-data.cpp \
  836. src/unicode-data.h
  837. $(CXX) $(CXXFLAGS) -c $< -o $@
  838. src/llama.o: \
  839. src/llama.cpp \
  840. src/unicode.h \
  841. include/llama.h \
  842. ggml/include/ggml-cuda.h \
  843. ggml/include/ggml-metal.h \
  844. ggml/include/ggml.h \
  845. ggml/include/ggml-alloc.h \
  846. ggml/include/ggml-backend.h
  847. $(CXX) $(CXXFLAGS) -c $< -o $@
  848. $(LIB_LLAMA): \
  849. $(OBJ_LLAMA) \
  850. $(LIB_GGML)
  851. $(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
  852. $(LIB_LLAMA_S): \
  853. $(OBJ_LLAMA)
  854. ar rcs $(LIB_LLAMA_S) $^
  855. # common
  856. common/common.o: \
  857. common/common.cpp \
  858. common/common.h \
  859. common/console.h \
  860. common/sampling.h \
  861. common/json.hpp \
  862. common/json-schema-to-grammar.h \
  863. include/llama.h
  864. $(CXX) $(CXXFLAGS) -c $< -o $@
  865. common/sampling.o: \
  866. common/sampling.cpp \
  867. common/sampling.h \
  868. include/llama.h
  869. $(CXX) $(CXXFLAGS) -c $< -o $@
  870. common/console.o: \
  871. common/console.cpp \
  872. common/console.h
  873. $(CXX) $(CXXFLAGS) -c $< -o $@
  874. common/grammar-parser.o: \
  875. common/grammar-parser.cpp \
  876. common/grammar-parser.h
  877. $(CXX) $(CXXFLAGS) -c $< -o $@
  878. common/json-schema-to-grammar.o: \
  879. common/json-schema-to-grammar.cpp \
  880. common/json-schema-to-grammar.h
  881. $(CXX) $(CXXFLAGS) -c $< -o $@
  882. common/train.o: \
  883. common/train.cpp \
  884. common/train.h
  885. $(CXX) $(CXXFLAGS) -c $< -o $@
  886. common/ngram-cache.o: \
  887. common/ngram-cache.cpp \
  888. common/ngram-cache.h
  889. $(CXX) $(CXXFLAGS) -c $< -o $@
  890. $(LIB_COMMON): \
  891. $(OBJ_COMMON) \
  892. $(LIB_LLAMA) \
  893. $(LIB_GGML)
  894. $(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
  895. $(LIB_COMMON_S): \
  896. $(OBJ_COMMON)
  897. ar rcs $(LIB_COMMON_S) $^
  898. clean:
  899. rm -vrf *.dot $(BUILD_TARGETS) $(TEST_TARGETS)
  900. rm -rvf src/*.o
  901. rm -rvf tests/*.o
  902. rm -rvf examples/*.o
  903. rm -rvf *.a
  904. rm -rvf *.dll
  905. rm -rvf *.so
  906. rm -rvf *.dot
  907. rm -rvf ggml/*.a
  908. rm -rvf ggml/*.dll
  909. rm -rvf ggml/*.so
  910. rm -vrf ggml/src/*.o
  911. rm -rvf common/build-info.cpp
  912. rm -vrf ggml/src/ggml-metal-embed.metal
  913. rm -vrf ggml/src/ggml-cuda/*.o
  914. rm -vrf ggml/src/ggml-cuda/template-instances/*.o
  915. rm -rvf $(BUILD_TARGETS)
  916. rm -rvf $(TEST_TARGETS)
  917. find examples pocs -type f -name "*.o" -delete
  918. #
  919. # Examples
  920. #
  921. # $< is the first prerequisite, i.e. the source file.
  922. # Explicitly compile this to an object file so that it can be cached with ccache.
  923. # The source file is then filtered out from $^ (the list of all prerequisites) and the object file is added instead.
  924. # Helper function that replaces .c, .cpp, and .cu file endings with .o:
  925. GET_OBJ_FILE = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(patsubst %.cu,%.o,$(1))))
  926. llama-cli: examples/main/main.cpp \
  927. $(OBJ_ALL)
  928. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  929. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  930. @echo
  931. @echo '==== Run ./llama-cli -h for help. ===='
  932. @echo
  933. llama-infill: examples/infill/infill.cpp \
  934. $(OBJ_ALL)
  935. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  936. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  937. llama-simple: examples/simple/simple.cpp \
  938. $(OBJ_ALL)
  939. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  940. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  941. llama-tokenize: examples/tokenize/tokenize.cpp \
  942. $(OBJ_ALL)
  943. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  944. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  945. llama-batched: examples/batched/batched.cpp \
  946. $(OBJ_ALL)
  947. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  948. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  949. llama-batched-bench: examples/batched-bench/batched-bench.cpp \
  950. $(OBJ_ALL)
  951. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  952. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  953. llama-quantize: examples/quantize/quantize.cpp \
  954. $(OBJ_ALL)
  955. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  956. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  957. llama-quantize-stats: examples/quantize-stats/quantize-stats.cpp \
  958. $(OBJ_ALL)
  959. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  960. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  961. llama-perplexity: examples/perplexity/perplexity.cpp \
  962. $(OBJ_ALL)
  963. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  964. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  965. llama-imatrix: examples/imatrix/imatrix.cpp \
  966. $(OBJ_ALL)
  967. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  968. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  969. llama-embedding: examples/embedding/embedding.cpp \
  970. $(OBJ_ALL)
  971. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  972. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  973. llama-gritlm: examples/gritlm/gritlm.cpp \
  974. $(OBJ_ALL)
  975. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  976. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  977. llama-save-load-state: examples/save-load-state/save-load-state.cpp \
  978. $(OBJ_ALL)
  979. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  980. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  981. llama-gguf: examples/gguf/gguf.cpp \
  982. $(OBJ_GGML)
  983. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  984. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  985. llama-gguf-split: examples/gguf-split/gguf-split.cpp \
  986. $(OBJ_ALL)
  987. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  988. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  989. llama-eval-callback: examples/eval-callback/eval-callback.cpp \
  990. $(OBJ_ALL)
  991. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  992. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  993. llama-cvector-generator: examples/cvector-generator/cvector-generator.cpp \
  994. $(OBJ_ALL)
  995. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  996. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  997. llama-train-text-from-scratch: examples/train-text-from-scratch/train-text-from-scratch.cpp \
  998. $(OBJ_ALL)
  999. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1000. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1001. llama-convert-llama2c-to-ggml: examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp \
  1002. $(OBJ_GGML) $(OBJ_LLAMA)
  1003. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1004. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1005. llama-bench: examples/llama-bench/llama-bench.cpp \
  1006. $(OBJ_ALL)
  1007. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1008. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1009. llama-baby-llama: examples/baby-llama/baby-llama.cpp \
  1010. $(OBJ_ALL)
  1011. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1012. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1013. llama-finetune: examples/finetune/finetune.cpp \
  1014. $(OBJ_ALL)
  1015. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1016. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1017. llama-export-lora: examples/export-lora/export-lora.cpp \
  1018. $(OBJ_GGML) common/log.h
  1019. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1020. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1021. llama-retrieval: examples/retrieval/retrieval.cpp \
  1022. $(OBJ_ALL)
  1023. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1024. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1025. llama-speculative: examples/speculative/speculative.cpp \
  1026. $(OBJ_ALL)
  1027. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1028. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1029. llama-parallel: examples/parallel/parallel.cpp \
  1030. $(OBJ_ALL)
  1031. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1032. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1033. llama-lookahead: examples/lookahead/lookahead.cpp \
  1034. $(OBJ_ALL)
  1035. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1036. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1037. llama-lookup: examples/lookup/lookup.cpp \
  1038. $(OBJ_ALL)
  1039. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1040. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1041. llama-lookup-create: examples/lookup/lookup-create.cpp \
  1042. $(OBJ_ALL)
  1043. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1044. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1045. llama-lookup-merge: examples/lookup/lookup-merge.cpp \
  1046. $(OBJ_ALL)
  1047. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1048. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1049. llama-lookup-stats: examples/lookup/lookup-stats.cpp \
  1050. $(OBJ_ALL)
  1051. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1052. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1053. llama-passkey: examples/passkey/passkey.cpp \
  1054. $(OBJ_ALL)
  1055. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1056. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1057. llama-gbnf-validator: examples/gbnf-validator/gbnf-validator.cpp \
  1058. $(OBJ_ALL)
  1059. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1060. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1061. ifdef GGML_RPC
  1062. rpc-server: examples/rpc/rpc-server.cpp \
  1063. $(OBJ_GGML)
  1064. $(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
  1065. endif # GGML_RPC
  1066. llama-server: \
  1067. examples/server/server.cpp \
  1068. examples/server/utils.hpp \
  1069. examples/server/httplib.h \
  1070. examples/server/colorthemes.css.hpp \
  1071. examples/server/style.css.hpp \
  1072. examples/server/theme-beeninorder.css.hpp \
  1073. examples/server/theme-ketivah.css.hpp \
  1074. examples/server/theme-mangotango.css.hpp \
  1075. examples/server/theme-playground.css.hpp \
  1076. examples/server/theme-polarnight.css.hpp \
  1077. examples/server/theme-snowstorm.css.hpp \
  1078. examples/server/index.html.hpp \
  1079. examples/server/index-new.html.hpp \
  1080. examples/server/index.js.hpp \
  1081. examples/server/completion.js.hpp \
  1082. examples/server/system-prompts.js.hpp \
  1083. examples/server/prompt-formats.js.hpp \
  1084. examples/server/json-schema-to-grammar.mjs.hpp \
  1085. common/json.hpp \
  1086. common/stb_image.h \
  1087. $(OBJ_ALL)
  1088. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1089. $(CXX) $(CXXFLAGS) $(filter-out %.h %.hpp $<,$^) -Iexamples/server $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) $(LWINSOCK2)
  1090. # Portable equivalent of `cd examples/server/public && xxd -i $(notdir $<) ../$(notdir $<).hpp`:
  1091. examples/server/%.hpp: examples/server/public/% Makefile
  1092. @( export NAME=$(subst .,_,$(subst -,_,$(notdir $<))) && \
  1093. echo "unsigned char $${NAME}[] = {" && \
  1094. cat $< | od -v -t x1 -An | sed -E 's/([0-9a-fA-F]+)/0x\1, /g' && \
  1095. echo "};" && \
  1096. echo "unsigned int $${NAME}_len = $(shell cat $< | wc -c );" \
  1097. ) > $@
  1098. libllava.a: examples/llava/llava.cpp \
  1099. examples/llava/llava.h \
  1100. examples/llava/clip.cpp \
  1101. examples/llava/clip.h \
  1102. common/stb_image.h \
  1103. common/base64.hpp \
  1104. $(OBJ_ALL)
  1105. $(CXX) $(CXXFLAGS) -static -fPIC -c $< -o $@ -Wno-cast-qual
  1106. llama-llava-cli: examples/llava/llava-cli.cpp \
  1107. examples/llava/clip.h \
  1108. examples/llava/clip.cpp \
  1109. examples/llava/llava.h \
  1110. examples/llava/llava.cpp \
  1111. $(OBJ_ALL)
  1112. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1113. $(CXX) $(CXXFLAGS) -c examples/llava/clip.cpp -o $(call GET_OBJ_FILE, examples/llava/clip.cpp) -Wno-cast-qual
  1114. $(CXX) $(CXXFLAGS) -c examples/llava/llava.cpp -o $(call GET_OBJ_FILE, examples/llava/llava.cpp)
  1115. $(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)
  1116. ifeq ($(UNAME_S),Darwin)
  1117. swift: examples/batched.swift
  1118. (cd examples/batched.swift; make build)
  1119. endif
  1120. common/build-info.cpp: $(wildcard .git/index) scripts/build-info.sh
  1121. @sh scripts/build-info.sh "$(CC)" > $@.tmp
  1122. @if ! cmp -s $@.tmp $@; then \
  1123. mv $@.tmp $@; \
  1124. else \
  1125. rm $@.tmp; \
  1126. fi
  1127. common/build-info.o: common/build-info.cpp
  1128. $(CXX) $(CXXFLAGS) -c $(filter-out %.h,$^) -o $@
  1129. #
  1130. # Tests
  1131. #
  1132. tests: $(TEST_TARGETS)
  1133. llama-benchmark-matmult: examples/benchmark/benchmark-matmult.cpp \
  1134. $(OBJ_GGML) common/build-info.o
  1135. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1136. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1137. run-benchmark-matmult: llama-benchmark-matmult
  1138. ./$@
  1139. .PHONY: run-benchmark-matmult swift
  1140. tests/test-llama-grammar: tests/test-llama-grammar.cpp \
  1141. $(OBJ_GGML) $(OBJ_COMMON) src/unicode.o src/unicode-data.o
  1142. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1143. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1144. tests/test-grammar-parser: tests/test-grammar-parser.cpp \
  1145. $(OBJ_ALL)
  1146. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1147. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1148. tests/test-grammar-integration: tests/test-grammar-integration.cpp \
  1149. $(OBJ_ALL)
  1150. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1151. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1152. tests/test-double-float: tests/test-double-float.cpp
  1153. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1154. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1155. tests/test-json-schema-to-grammar: tests/test-json-schema-to-grammar.cpp \
  1156. $(OBJ_ALL)
  1157. $(CXX) $(CXXFLAGS) -Iexamples/server -c $< -o $(call GET_OBJ_FILE, $<)
  1158. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1159. tests/test-grad0: tests/test-grad0.cpp \
  1160. $(OBJ_GGML)
  1161. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1162. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1163. tests/test-opt: tests/test-opt.cpp \
  1164. $(OBJ_GGML)
  1165. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1166. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1167. tests/test-quantize-fns: tests/test-quantize-fns.cpp \
  1168. $(OBJ_GGML)
  1169. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1170. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1171. tests/test-quantize-perf: tests/test-quantize-perf.cpp \
  1172. $(OBJ_GGML)
  1173. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1174. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1175. tests/test-sampling: tests/test-sampling.cpp \
  1176. $(OBJ_ALL)
  1177. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1178. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1179. tests/test-tokenizer-0: tests/test-tokenizer-0.cpp \
  1180. $(OBJ_ALL)
  1181. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1182. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1183. tests/test-tokenizer-1-bpe: tests/test-tokenizer-1-bpe.cpp \
  1184. $(OBJ_ALL)
  1185. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1186. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1187. tests/test-tokenizer-1-spm: tests/test-tokenizer-1-spm.cpp \
  1188. $(OBJ_ALL)
  1189. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1190. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1191. tests/test-rope: tests/test-rope.cpp ggml/src/ggml.o \
  1192. $(OBJ_GGML)
  1193. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1194. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1195. tests/test-c.o: tests/test-c.c include/llama.h
  1196. $(CC) $(CFLAGS) -c $(filter-out %.h,$^) -o $@
  1197. tests/test-backend-ops: tests/test-backend-ops.cpp \
  1198. $(OBJ_GGML)
  1199. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1200. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1201. tests/test-model-load-cancel: tests/test-model-load-cancel.cpp tests/get-model.cpp \
  1202. $(OBJ_ALL)
  1203. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1204. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1205. tests/test-autorelease: tests/test-autorelease.cpp tests/get-model.cpp \
  1206. $(OBJ_ALL)
  1207. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1208. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1209. tests/test-chat-template: tests/test-chat-template.cpp \
  1210. $(OBJ_ALL)
  1211. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1212. $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1213. #
  1214. # PoCs
  1215. #
  1216. llama-vdot: pocs/vdot/vdot.cpp ggml/src/ggml.o \
  1217. $(OBJ_GGML)
  1218. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1219. $(CXX) $(CXXFLAGS) $(filter-out $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
  1220. llama-q8dot: pocs/vdot/q8dot.cpp ggml/src/ggml.o \
  1221. $(OBJ_GGML)
  1222. $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
  1223. $(CXX) $(CXXFLAGS) $(filter-out $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)