Makefile 43 KB

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