Makefile 47 KB

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