Makefile 42 KB

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