Makefile 42 KB

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