@fugood/llama.node 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/CMakeLists.txt +7 -0
  2. package/bin/darwin/arm64/llama-node.node +0 -0
  3. package/bin/darwin/x64/llama-node.node +0 -0
  4. package/bin/linux/arm64/llama-node.node +0 -0
  5. package/bin/linux/x64/llama-node.node +0 -0
  6. package/bin/linux-vulkan/arm64/llama-node.node +0 -0
  7. package/bin/linux-vulkan/x64/llama-node.node +0 -0
  8. package/bin/win32/arm64/llama-node.node +0 -0
  9. package/bin/win32/arm64/node.lib +0 -0
  10. package/bin/win32/x64/llama-node.node +0 -0
  11. package/bin/win32/x64/node.lib +0 -0
  12. package/bin/win32-vulkan/arm64/llama-node.node +0 -0
  13. package/bin/win32-vulkan/arm64/node.lib +0 -0
  14. package/bin/win32-vulkan/x64/llama-node.node +0 -0
  15. package/bin/win32-vulkan/x64/node.lib +0 -0
  16. package/lib/binding.ts +18 -1
  17. package/package.json +1 -1
  18. package/src/DetokenizeWorker.cpp +1 -1
  19. package/src/EmbeddingWorker.cpp +17 -7
  20. package/src/EmbeddingWorker.h +2 -1
  21. package/src/LlamaCompletionWorker.cpp +8 -8
  22. package/src/LlamaCompletionWorker.h +2 -2
  23. package/src/LlamaContext.cpp +89 -27
  24. package/src/LlamaContext.h +2 -0
  25. package/src/TokenizeWorker.cpp +1 -1
  26. package/src/common.hpp +4 -4
  27. package/src/llama.cpp/.github/workflows/build.yml +240 -168
  28. package/src/llama.cpp/.github/workflows/docker.yml +8 -8
  29. package/src/llama.cpp/.github/workflows/python-lint.yml +8 -1
  30. package/src/llama.cpp/.github/workflows/server.yml +21 -14
  31. package/src/llama.cpp/CMakeLists.txt +14 -6
  32. package/src/llama.cpp/Sources/llama/llama.h +4 -0
  33. package/src/llama.cpp/cmake/arm64-apple-clang.cmake +16 -0
  34. package/src/llama.cpp/cmake/common.cmake +33 -0
  35. package/src/llama.cpp/cmake/x64-windows-llvm.cmake +11 -0
  36. package/src/llama.cpp/common/CMakeLists.txt +6 -4
  37. package/src/llama.cpp/common/arg.cpp +986 -770
  38. package/src/llama.cpp/common/arg.h +22 -22
  39. package/src/llama.cpp/common/common.cpp +212 -351
  40. package/src/llama.cpp/common/common.h +204 -117
  41. package/src/llama.cpp/common/json-schema-to-grammar.cpp +1 -1
  42. package/src/llama.cpp/common/log.cpp +50 -50
  43. package/src/llama.cpp/common/log.h +18 -18
  44. package/src/llama.cpp/common/ngram-cache.cpp +36 -36
  45. package/src/llama.cpp/common/ngram-cache.h +19 -19
  46. package/src/llama.cpp/common/sampling.cpp +163 -121
  47. package/src/llama.cpp/common/sampling.h +41 -20
  48. package/src/llama.cpp/common/speculative.cpp +274 -0
  49. package/src/llama.cpp/common/speculative.h +28 -0
  50. package/src/llama.cpp/docs/build.md +134 -161
  51. package/src/llama.cpp/examples/CMakeLists.txt +33 -14
  52. package/src/llama.cpp/examples/batched/CMakeLists.txt +1 -1
  53. package/src/llama.cpp/examples/batched/batched.cpp +19 -18
  54. package/src/llama.cpp/examples/batched-bench/CMakeLists.txt +1 -1
  55. package/src/llama.cpp/examples/batched-bench/batched-bench.cpp +10 -11
  56. package/src/llama.cpp/examples/convert-llama2c-to-ggml/CMakeLists.txt +1 -1
  57. package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +1 -1
  58. package/src/llama.cpp/examples/cvector-generator/CMakeLists.txt +1 -1
  59. package/src/llama.cpp/examples/cvector-generator/cvector-generator.cpp +9 -9
  60. package/src/llama.cpp/examples/deprecation-warning/deprecation-warning.cpp +1 -1
  61. package/src/llama.cpp/examples/embedding/CMakeLists.txt +1 -1
  62. package/src/llama.cpp/examples/embedding/embedding.cpp +12 -12
  63. package/src/llama.cpp/examples/eval-callback/CMakeLists.txt +3 -2
  64. package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +8 -8
  65. package/src/llama.cpp/examples/export-lora/CMakeLists.txt +1 -1
  66. package/src/llama.cpp/examples/export-lora/export-lora.cpp +5 -5
  67. package/src/llama.cpp/examples/gbnf-validator/CMakeLists.txt +1 -1
  68. package/src/llama.cpp/examples/gbnf-validator/gbnf-validator.cpp +4 -7
  69. package/src/llama.cpp/examples/gen-docs/CMakeLists.txt +1 -1
  70. package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +7 -7
  71. package/src/llama.cpp/examples/gguf/CMakeLists.txt +1 -1
  72. package/src/llama.cpp/examples/gguf-hash/CMakeLists.txt +8 -1
  73. package/src/llama.cpp/examples/gguf-split/CMakeLists.txt +1 -1
  74. package/src/llama.cpp/examples/gguf-split/gguf-split.cpp +2 -2
  75. package/src/llama.cpp/examples/gritlm/CMakeLists.txt +1 -1
  76. package/src/llama.cpp/examples/gritlm/gritlm.cpp +18 -18
  77. package/src/llama.cpp/examples/imatrix/CMakeLists.txt +1 -1
  78. package/src/llama.cpp/examples/imatrix/imatrix.cpp +31 -13
  79. package/src/llama.cpp/examples/infill/CMakeLists.txt +1 -1
  80. package/src/llama.cpp/examples/infill/infill.cpp +41 -87
  81. package/src/llama.cpp/examples/llama-bench/CMakeLists.txt +1 -1
  82. package/src/llama.cpp/examples/llama-bench/llama-bench.cpp +439 -459
  83. package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +2 -0
  84. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +11 -14
  85. package/src/llama.cpp/examples/llava/CMakeLists.txt +10 -3
  86. package/src/llama.cpp/examples/llava/clip.cpp +263 -66
  87. package/src/llama.cpp/examples/llava/clip.h +8 -2
  88. package/src/llama.cpp/examples/llava/llava-cli.cpp +23 -23
  89. package/src/llama.cpp/examples/llava/llava.cpp +83 -22
  90. package/src/llama.cpp/examples/llava/minicpmv-cli.cpp +21 -21
  91. package/src/llama.cpp/examples/llava/qwen2vl-cli.cpp +581 -0
  92. package/src/llama.cpp/examples/lookahead/CMakeLists.txt +1 -1
  93. package/src/llama.cpp/examples/lookahead/lookahead.cpp +26 -26
  94. package/src/llama.cpp/examples/lookup/CMakeLists.txt +4 -4
  95. package/src/llama.cpp/examples/lookup/lookup-create.cpp +7 -7
  96. package/src/llama.cpp/examples/lookup/lookup-merge.cpp +4 -4
  97. package/src/llama.cpp/examples/lookup/lookup-stats.cpp +16 -15
  98. package/src/llama.cpp/examples/lookup/lookup.cpp +30 -30
  99. package/src/llama.cpp/examples/main/CMakeLists.txt +1 -1
  100. package/src/llama.cpp/examples/main/main.cpp +73 -114
  101. package/src/llama.cpp/examples/main-cmake-pkg/CMakeLists.txt +1 -1
  102. package/src/llama.cpp/examples/parallel/CMakeLists.txt +1 -1
  103. package/src/llama.cpp/examples/parallel/parallel.cpp +18 -19
  104. package/src/llama.cpp/examples/passkey/CMakeLists.txt +1 -1
  105. package/src/llama.cpp/examples/passkey/passkey.cpp +14 -14
  106. package/src/llama.cpp/examples/perplexity/CMakeLists.txt +1 -1
  107. package/src/llama.cpp/examples/perplexity/perplexity.cpp +99 -120
  108. package/src/llama.cpp/examples/quantize/CMakeLists.txt +1 -1
  109. package/src/llama.cpp/examples/quantize/quantize.cpp +0 -3
  110. package/src/llama.cpp/examples/quantize-stats/CMakeLists.txt +1 -1
  111. package/src/llama.cpp/examples/quantize-stats/quantize-stats.cpp +10 -9
  112. package/src/llama.cpp/examples/retrieval/CMakeLists.txt +1 -1
  113. package/src/llama.cpp/examples/retrieval/retrieval.cpp +16 -16
  114. package/src/llama.cpp/examples/rpc/rpc-server.cpp +3 -1
  115. package/src/llama.cpp/examples/run/CMakeLists.txt +5 -0
  116. package/src/llama.cpp/examples/run/run.cpp +911 -0
  117. package/src/llama.cpp/examples/save-load-state/CMakeLists.txt +1 -1
  118. package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +38 -21
  119. package/src/llama.cpp/examples/server/CMakeLists.txt +3 -16
  120. package/src/llama.cpp/examples/server/server.cpp +2073 -1339
  121. package/src/llama.cpp/examples/server/tests/requirements.txt +2 -2
  122. package/src/llama.cpp/examples/server/utils.hpp +354 -277
  123. package/src/llama.cpp/examples/simple/CMakeLists.txt +2 -2
  124. package/src/llama.cpp/examples/simple/simple.cpp +130 -94
  125. package/src/llama.cpp/examples/simple-chat/CMakeLists.txt +5 -0
  126. package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +200 -0
  127. package/src/llama.cpp/examples/speculative/CMakeLists.txt +1 -1
  128. package/src/llama.cpp/examples/speculative/speculative.cpp +68 -64
  129. package/src/llama.cpp/examples/speculative-simple/CMakeLists.txt +5 -0
  130. package/src/llama.cpp/examples/speculative-simple/speculative-simple.cpp +265 -0
  131. package/src/llama.cpp/examples/tokenize/CMakeLists.txt +1 -1
  132. package/src/llama.cpp/examples/tokenize/tokenize.cpp +3 -3
  133. package/src/llama.cpp/examples/tts/CMakeLists.txt +5 -0
  134. package/src/llama.cpp/examples/tts/tts.cpp +932 -0
  135. package/src/llama.cpp/ggml/CMakeLists.txt +54 -36
  136. package/src/llama.cpp/ggml/include/ggml-backend.h +63 -34
  137. package/src/llama.cpp/ggml/include/ggml-blas.h +5 -3
  138. package/src/llama.cpp/ggml/include/ggml-cann.h +9 -7
  139. package/src/llama.cpp/ggml/include/ggml-cpp.h +38 -0
  140. package/src/llama.cpp/ggml/include/ggml-cpu.h +135 -0
  141. package/src/llama.cpp/ggml/include/ggml-cuda.h +12 -12
  142. package/src/llama.cpp/ggml/include/ggml-kompute.h +7 -3
  143. package/src/llama.cpp/ggml/include/ggml-metal.h +11 -7
  144. package/src/llama.cpp/ggml/include/ggml-opencl.h +26 -0
  145. package/src/llama.cpp/ggml/include/ggml-opt.h +216 -0
  146. package/src/llama.cpp/ggml/include/ggml-rpc.h +9 -5
  147. package/src/llama.cpp/ggml/include/ggml-sycl.h +18 -11
  148. package/src/llama.cpp/ggml/include/ggml-vulkan.h +10 -8
  149. package/src/llama.cpp/ggml/include/ggml.h +159 -417
  150. package/src/llama.cpp/ggml/src/CMakeLists.txt +121 -1155
  151. package/src/llama.cpp/ggml/src/ggml-alloc.c +23 -28
  152. package/src/llama.cpp/ggml/src/ggml-backend-impl.h +57 -36
  153. package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +552 -0
  154. package/src/llama.cpp/ggml/src/ggml-backend.cpp +306 -867
  155. package/src/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +87 -0
  156. package/src/llama.cpp/ggml/src/{ggml-blas.cpp → ggml-blas/ggml-blas.cpp} +216 -65
  157. package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +76 -0
  158. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +456 -111
  159. package/src/llama.cpp/ggml/src/ggml-cann/common.h +6 -3
  160. package/src/llama.cpp/ggml/src/{ggml-cann.cpp → ggml-cann/ggml-cann.cpp} +343 -177
  161. package/src/llama.cpp/ggml/src/ggml-cann/kernels/CMakeLists.txt +2 -5
  162. package/src/llama.cpp/ggml/src/ggml-cann/kernels/dup.cpp +22 -9
  163. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_f16.cpp +24 -13
  164. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_f32.cpp +23 -13
  165. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp +11 -0
  166. package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp +10 -0
  167. package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp +10 -0
  168. package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp +17 -0
  169. package/src/llama.cpp/ggml/src/ggml-common.h +42 -42
  170. package/src/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +336 -0
  171. package/src/llama.cpp/ggml/src/ggml-cpu/amx/amx.cpp +220 -0
  172. package/src/llama.cpp/ggml/src/ggml-cpu/amx/amx.h +8 -0
  173. package/src/llama.cpp/ggml/src/ggml-cpu/amx/common.h +91 -0
  174. package/src/llama.cpp/ggml/src/ggml-cpu/amx/mmq.cpp +2511 -0
  175. package/src/llama.cpp/ggml/src/ggml-cpu/amx/mmq.h +10 -0
  176. package/src/llama.cpp/ggml/src/ggml-cpu/cpu-feats-x86.cpp +323 -0
  177. package/src/llama.cpp/ggml/src/{ggml-aarch64.c → ggml-cpu/ggml-cpu-aarch64.cpp} +1299 -246
  178. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +8 -0
  179. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-hbm.cpp +55 -0
  180. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-hbm.h +8 -0
  181. package/src/llama.cpp/ggml/src/{ggml-cpu-impl.h → ggml-cpu/ggml-cpu-impl.h} +14 -242
  182. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.c +10835 -0
  183. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.h +63 -0
  184. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-traits.cpp +36 -0
  185. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-traits.h +38 -0
  186. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +14123 -0
  187. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +628 -0
  188. package/src/llama.cpp/ggml/src/{llamafile → ggml-cpu/llamafile}/sgemm.cpp +666 -0
  189. package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +152 -0
  190. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +8 -0
  191. package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +104 -0
  192. package/src/llama.cpp/ggml/src/ggml-impl.h +393 -22
  193. package/src/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +166 -0
  194. package/src/llama.cpp/ggml/src/{ggml-kompute.cpp → ggml-kompute/ggml-kompute.cpp} +360 -127
  195. package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +105 -0
  196. package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +288 -0
  197. package/src/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +107 -0
  198. package/src/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +147 -0
  199. package/src/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +4004 -0
  200. package/src/llama.cpp/ggml/src/ggml-opt.cpp +854 -0
  201. package/src/llama.cpp/ggml/src/ggml-quants.c +188 -10702
  202. package/src/llama.cpp/ggml/src/ggml-quants.h +78 -125
  203. package/src/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +9 -0
  204. package/src/llama.cpp/ggml/src/{ggml-rpc.cpp → ggml-rpc/ggml-rpc.cpp} +478 -300
  205. package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +84 -0
  206. package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +3 -0
  207. package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +36 -5
  208. package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +259 -0
  209. package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +3 -2
  210. package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +1 -1
  211. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +5 -5
  212. package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +34 -35
  213. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +1030 -0
  214. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +76 -0
  215. package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +4 -4
  216. package/src/llama.cpp/ggml/src/{ggml-sycl.cpp → ggml-sycl/ggml-sycl.cpp} +3638 -4151
  217. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +3 -2
  218. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +6 -6
  219. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +75 -87
  220. package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +7 -6
  221. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +56 -0
  222. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +11 -0
  223. package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +6 -0
  224. package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +4 -3
  225. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +7 -7
  226. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +1 -0
  227. package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +4 -4
  228. package/src/llama.cpp/ggml/src/ggml-sycl/wkv6.cpp +141 -0
  229. package/src/llama.cpp/ggml/src/ggml-sycl/wkv6.hpp +10 -0
  230. package/src/llama.cpp/ggml/src/ggml-threading.cpp +12 -0
  231. package/src/llama.cpp/ggml/src/ggml-threading.h +14 -0
  232. package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +92 -0
  233. package/src/llama.cpp/ggml/src/{ggml-vulkan.cpp → ggml-vulkan/ggml-vulkan.cpp} +2138 -887
  234. package/src/llama.cpp/ggml/src/{vulkan-shaders → ggml-vulkan/vulkan-shaders}/CMakeLists.txt +3 -1
  235. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +593 -0
  236. package/src/llama.cpp/ggml/src/ggml.c +4427 -20125
  237. package/src/llama.cpp/include/llama-cpp.h +25 -0
  238. package/src/llama.cpp/include/llama.h +93 -52
  239. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +112 -0
  240. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +46 -0
  241. package/src/llama.cpp/pocs/CMakeLists.txt +3 -1
  242. package/src/llama.cpp/pocs/vdot/CMakeLists.txt +2 -2
  243. package/src/llama.cpp/pocs/vdot/q8dot.cpp +4 -3
  244. package/src/llama.cpp/pocs/vdot/vdot.cpp +8 -7
  245. package/src/llama.cpp/src/CMakeLists.txt +4 -8
  246. package/src/llama.cpp/src/llama-grammar.cpp +15 -15
  247. package/src/llama.cpp/src/llama-grammar.h +2 -5
  248. package/src/llama.cpp/src/llama-sampling.cpp +779 -194
  249. package/src/llama.cpp/src/llama-sampling.h +21 -2
  250. package/src/llama.cpp/src/llama-vocab.cpp +55 -10
  251. package/src/llama.cpp/src/llama-vocab.h +35 -11
  252. package/src/llama.cpp/src/llama.cpp +4317 -2979
  253. package/src/llama.cpp/src/unicode-data.cpp +2 -2
  254. package/src/llama.cpp/src/unicode.cpp +62 -51
  255. package/src/llama.cpp/src/unicode.h +9 -10
  256. package/src/llama.cpp/tests/CMakeLists.txt +48 -38
  257. package/src/llama.cpp/tests/test-arg-parser.cpp +15 -15
  258. package/src/llama.cpp/tests/test-backend-ops.cpp +324 -80
  259. package/src/llama.cpp/tests/test-barrier.cpp +1 -0
  260. package/src/llama.cpp/tests/test-chat-template.cpp +59 -9
  261. package/src/llama.cpp/tests/test-gguf.cpp +1303 -0
  262. package/src/llama.cpp/tests/test-grammar-integration.cpp +3 -6
  263. package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +17 -4
  264. package/src/llama.cpp/tests/test-llama-grammar.cpp +2 -4
  265. package/src/llama.cpp/tests/test-log.cpp +2 -2
  266. package/src/llama.cpp/tests/test-opt.cpp +853 -142
  267. package/src/llama.cpp/tests/test-quantize-fns.cpp +24 -21
  268. package/src/llama.cpp/tests/test-quantize-perf.cpp +16 -14
  269. package/src/llama.cpp/tests/test-rope.cpp +62 -20
  270. package/src/llama.cpp/tests/test-sampling.cpp +163 -138
  271. package/src/llama.cpp/tests/test-tokenizer-0.cpp +7 -7
  272. package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +5 -5
  273. package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +5 -5
  274. package/src/llama.cpp/.github/workflows/nix-ci-aarch64.yml +0 -72
  275. package/src/llama.cpp/.github/workflows/nix-ci.yml +0 -79
  276. package/src/llama.cpp/.github/workflows/nix-flake-update.yml +0 -22
  277. package/src/llama.cpp/.github/workflows/nix-publish-flake.yml +0 -36
  278. package/src/llama.cpp/common/train.cpp +0 -1515
  279. package/src/llama.cpp/common/train.h +0 -233
  280. package/src/llama.cpp/examples/baby-llama/CMakeLists.txt +0 -5
  281. package/src/llama.cpp/examples/baby-llama/baby-llama.cpp +0 -1639
  282. package/src/llama.cpp/ggml/src/ggml-aarch64.h +0 -39
  283. package/src/llama.cpp/ggml/src/vulkan-shaders/vulkan-shaders-gen.cpp +0 -600
  284. package/src/llama.cpp/tests/test-grad0.cpp +0 -1683
  285. /package/src/llama.cpp/ggml/{cmake → src/ggml-cpu/cmake}/FindSIMD.cmake +0 -0
  286. /package/src/llama.cpp/ggml/src/{llamafile → ggml-cpu/llamafile}/sgemm.h +0 -0
@@ -0,0 +1,105 @@
1
+ find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
2
+ find_library(METAL_FRAMEWORK Metal REQUIRED)
3
+ find_library(METALKIT_FRAMEWORK MetalKit REQUIRED)
4
+
5
+ message(STATUS "Metal framework found")
6
+
7
+ ggml_add_backend_library(ggml-metal
8
+ ggml-metal.m
9
+ )
10
+
11
+ target_link_libraries(ggml-metal PRIVATE
12
+ ${FOUNDATION_LIBRARY}
13
+ ${METAL_FRAMEWORK}
14
+ ${METALKIT_FRAMEWORK}
15
+ )
16
+
17
+ if (GGML_METAL_NDEBUG)
18
+ add_compile_definitions(GGML_METAL_NDEBUG)
19
+ endif()
20
+
21
+ if (GGML_METAL_USE_BF16)
22
+ add_compile_definitions(GGML_METAL_USE_BF16)
23
+ endif()
24
+
25
+ # copy metal files to bin directory
26
+ configure_file(../ggml-common.h ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h COPYONLY)
27
+ configure_file(ggml-metal.metal ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal COPYONLY)
28
+ configure_file(ggml-metal-impl.h ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal-impl.h COPYONLY)
29
+
30
+ if (GGML_METAL_EMBED_LIBRARY)
31
+ enable_language(ASM)
32
+
33
+ add_compile_definitions(GGML_METAL_EMBED_LIBRARY)
34
+
35
+ set(METALLIB_COMMON "${CMAKE_CURRENT_SOURCE_DIR}/../ggml-common.h")
36
+ set(METALLIB_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal.metal")
37
+ set(METALLIB_IMPL "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal-impl.h")
38
+
39
+ file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/autogenerated")
40
+
41
+ # merge ggml-common.h and ggml-metal.metal into a single file
42
+ set(METALLIB_EMBED_ASM "${CMAKE_BINARY_DIR}/autogenerated/ggml-metal-embed.s")
43
+ set(METALLIB_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-metal-embed.metal")
44
+ set(METALLIB_SOURCE_EMBED_TMP "${CMAKE_BINARY_DIR}/autogenerated/ggml-metal-embed.metal.tmp")
45
+
46
+ add_custom_command(
47
+ OUTPUT ${METALLIB_EMBED_ASM}
48
+ COMMAND echo "Embedding Metal library"
49
+ COMMAND sed -e '/__embed_ggml-common.h__/r ${METALLIB_COMMON}' -e '/__embed_ggml-common.h__/d' < ${METALLIB_SOURCE} > ${METALLIB_SOURCE_EMBED_TMP}
50
+ COMMAND sed -e '/\#include \"ggml-metal-impl.h\"/r ${METALLIB_IMPL}' -e '/\#include \"ggml-metal-impl.h\"/d' < ${METALLIB_SOURCE_EMBED_TMP} > ${METALLIB_SOURCE_EMBED}
51
+ COMMAND echo ".section __DATA,__ggml_metallib" > ${METALLIB_EMBED_ASM}
52
+ COMMAND echo ".globl _ggml_metallib_start" >> ${METALLIB_EMBED_ASM}
53
+ COMMAND echo "_ggml_metallib_start:" >> ${METALLIB_EMBED_ASM}
54
+ COMMAND echo ".incbin \\\"${METALLIB_SOURCE_EMBED}\\\"" >> ${METALLIB_EMBED_ASM}
55
+ COMMAND echo ".globl _ggml_metallib_end" >> ${METALLIB_EMBED_ASM}
56
+ COMMAND echo "_ggml_metallib_end:" >> ${METALLIB_EMBED_ASM}
57
+ DEPENDS ../ggml-common.h ggml-metal.metal ggml-metal-impl.h
58
+ COMMENT "Generate assembly for embedded Metal library"
59
+ )
60
+
61
+ target_sources(ggml-metal PRIVATE ${METALLIB_EMBED_ASM})
62
+ else()
63
+ if (GGML_METAL_SHADER_DEBUG)
64
+ # custom command to do the following:
65
+ # xcrun -sdk macosx metal -fno-fast-math -c ggml-metal.metal -o ggml-metal.air
66
+ # xcrun -sdk macosx metallib ggml-metal.air -o default.metallib
67
+ #
68
+ # note: this is the only way I found to disable fast-math in Metal. it's ugly, but at least it works
69
+ # disabling fast math is needed in order to pass tests/test-backend-ops
70
+ # note: adding -fno-inline fixes the tests when using MTL_SHADER_VALIDATION=1
71
+ # note: unfortunately, we have to call it default.metallib instead of ggml.metallib
72
+ # ref: https://github.com/ggerganov/whisper.cpp/issues/1720
73
+ set(XC_FLAGS -fno-fast-math -fno-inline -g)
74
+ else()
75
+ set(XC_FLAGS -O3)
76
+ endif()
77
+
78
+ # Append macOS metal versioning flags
79
+ if (GGML_METAL_MACOSX_VERSION_MIN)
80
+ message(STATUS "Adding -mmacosx-version-min=${GGML_METAL_MACOSX_VERSION_MIN} flag to metal compilation")
81
+ list (APPEND XC_FLAGS -mmacosx-version-min=${GGML_METAL_MACOSX_VERSION_MIN})
82
+ endif()
83
+
84
+ if (GGML_METAL_STD)
85
+ message(STATUS "Adding -std=${GGML_METAL_STD} flag to metal compilation")
86
+ list (APPEND XC_FLAGS -std=${GGML_METAL_STD})
87
+ endif()
88
+
89
+ add_custom_command(
90
+ OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
91
+ COMMAND xcrun -sdk macosx metal ${XC_FLAGS} -c ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air
92
+ COMMAND xcrun -sdk macosx metallib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
93
+ COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air
94
+ COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h
95
+ COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal
96
+ DEPENDS ggml-metal.metal ggml-common.h
97
+ COMMENT "Compiling Metal kernels"
98
+ )
99
+
100
+ # FIXME: only add to the ggml-metal target?
101
+ add_custom_target(
102
+ ggml-metal-lib ALL
103
+ DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
104
+ )
105
+ endif() # GGML_METAL_EMBED_LIBRARY
@@ -0,0 +1,288 @@
1
+ #ifndef GGML_METAL_IMPL
2
+ #define GGML_METAL_IMPL
3
+
4
+ // kernel argument structs
5
+ //
6
+ // - element counters (e.g. ne00) typically use int32_t to reduce register usage
7
+ // however, be careful from int overflows when using those in the kernel implementation
8
+ //
9
+ // - strides (e.g. nb00) use uint64_t
10
+
11
+ typedef struct {
12
+ int32_t ne00;
13
+ int32_t ne01;
14
+ int32_t ne02;
15
+ int32_t ne03;
16
+ uint64_t nb00;
17
+ uint64_t nb01;
18
+ uint64_t nb02;
19
+ uint64_t nb03;
20
+ int32_t ne10;
21
+ int32_t ne11;
22
+ int32_t ne12;
23
+ int32_t ne13;
24
+ uint64_t nb10;
25
+ uint64_t nb11;
26
+ uint64_t nb12;
27
+ uint64_t nb13;
28
+ int32_t ne0;
29
+ int32_t ne1;
30
+ int32_t ne2;
31
+ int32_t ne3;
32
+ uint64_t nb0;
33
+ uint64_t nb1;
34
+ uint64_t nb2;
35
+ uint64_t nb3;
36
+ int32_t dim;
37
+ } ggml_metal_kargs_concat;
38
+
39
+ typedef struct {
40
+ int32_t ne00;
41
+ int32_t ne01;
42
+ int32_t ne02;
43
+ int32_t ne03;
44
+ uint64_t nb00;
45
+ uint64_t nb01;
46
+ uint64_t nb02;
47
+ uint64_t nb03;
48
+ int32_t ne10;
49
+ int32_t ne11;
50
+ int32_t ne12;
51
+ int32_t ne13;
52
+ uint64_t nb10;
53
+ uint64_t nb11;
54
+ uint64_t nb12;
55
+ uint64_t nb13;
56
+ int32_t ne0;
57
+ int32_t ne1;
58
+ int32_t ne2;
59
+ int32_t ne3;
60
+ uint64_t nb0;
61
+ uint64_t nb1;
62
+ uint64_t nb2;
63
+ uint64_t nb3;
64
+ uint64_t offs;
65
+ } ggml_metal_kargs_bin;
66
+
67
+ typedef struct {
68
+ int32_t ne00;
69
+ int32_t ne01;
70
+ int32_t ne02;
71
+ int32_t ne03;
72
+ uint64_t nb00;
73
+ uint64_t nb01;
74
+ uint64_t nb02;
75
+ uint64_t nb03;
76
+ int32_t ne0;
77
+ int32_t ne1;
78
+ int32_t ne2;
79
+ int32_t ne3;
80
+ uint64_t nb0;
81
+ uint64_t nb1;
82
+ uint64_t nb2;
83
+ uint64_t nb3;
84
+ } ggml_metal_kargs_repeat;
85
+
86
+ typedef struct {
87
+ int64_t ne00;
88
+ int64_t ne01;
89
+ int64_t ne02;
90
+ int64_t ne03;
91
+ uint64_t nb00;
92
+ uint64_t nb01;
93
+ uint64_t nb02;
94
+ uint64_t nb03;
95
+ int64_t ne0;
96
+ int64_t ne1;
97
+ int64_t ne2;
98
+ int64_t ne3;
99
+ uint64_t nb0;
100
+ uint64_t nb1;
101
+ uint64_t nb2;
102
+ uint64_t nb3;
103
+ } ggml_metal_kargs_cpy;
104
+
105
+ typedef struct {
106
+ int64_t ne10;
107
+ int64_t ne11;
108
+ int64_t ne12;
109
+ uint64_t nb10;
110
+ uint64_t nb11;
111
+ uint64_t nb12;
112
+ uint64_t nb13;
113
+ uint64_t nb1;
114
+ uint64_t nb2;
115
+ uint64_t nb3;
116
+ uint64_t offs;
117
+ bool inplace;
118
+ } ggml_metal_kargs_set;
119
+
120
+ typedef struct {
121
+ int32_t ne00;
122
+ int32_t ne01;
123
+ int32_t ne02;
124
+ int32_t ne03;
125
+ uint64_t nb00;
126
+ uint64_t nb01;
127
+ uint64_t nb02;
128
+ uint64_t nb03;
129
+ int32_t ne0;
130
+ int32_t ne1;
131
+ int32_t ne2;
132
+ int32_t ne3;
133
+ uint64_t nb0;
134
+ uint64_t nb1;
135
+ uint64_t nb2;
136
+ uint64_t nb3;
137
+ int32_t n_past;
138
+ int32_t n_dims;
139
+ int32_t n_ctx_orig;
140
+ float freq_base;
141
+ float freq_scale;
142
+ float ext_factor;
143
+ float attn_factor;
144
+ float beta_fast;
145
+ float beta_slow;
146
+ } ggml_metal_kargs_rope;
147
+
148
+ typedef struct {
149
+ int32_t ne01;
150
+ int32_t ne02;
151
+ int32_t ne03;
152
+ uint64_t nb01;
153
+ uint64_t nb02;
154
+ uint64_t nb03;
155
+ int32_t ne11;
156
+ int32_t ne_12_2; // assume K and V are same shape
157
+ int32_t ne_12_3;
158
+ uint64_t nb_12_1;
159
+ uint64_t nb_12_2;
160
+ uint64_t nb_12_3;
161
+ uint64_t nb31;
162
+ int32_t ne1;
163
+ int32_t ne2;
164
+ float scale;
165
+ float max_bias;
166
+ float m0;
167
+ float m1;
168
+ uint16_t n_head_log2;
169
+ float logit_softcap;
170
+ } ggml_metal_kargs_flash_attn_ext;
171
+
172
+ typedef struct {
173
+ int32_t ne00;
174
+ int32_t ne02;
175
+ uint64_t nb01;
176
+ uint64_t nb02;
177
+ uint64_t nb03;
178
+ int32_t ne12;
179
+ uint64_t nb10;
180
+ uint64_t nb11;
181
+ uint64_t nb12;
182
+ uint64_t nb13;
183
+ int32_t ne0;
184
+ int32_t ne1;
185
+ int16_t r2;
186
+ int16_t r3;
187
+ } ggml_metal_kargs_mul_mm;
188
+
189
+ typedef struct {
190
+ int32_t ne00;
191
+ int32_t ne01;
192
+ int32_t ne02;
193
+ uint64_t nb00;
194
+ uint64_t nb01;
195
+ uint64_t nb02;
196
+ uint64_t nb03;
197
+ int32_t ne10;
198
+ int32_t ne11;
199
+ int32_t ne12;
200
+ uint64_t nb10;
201
+ uint64_t nb11;
202
+ uint64_t nb12;
203
+ uint64_t nb13;
204
+ int32_t ne0;
205
+ int32_t ne1;
206
+ int16_t r2;
207
+ int16_t r3;
208
+ } ggml_metal_kargs_mul_mv;
209
+
210
+ typedef struct {
211
+ int32_t ne00;
212
+ int32_t ne01;
213
+ int32_t ne02;
214
+ uint64_t nb00;
215
+ uint64_t nb01;
216
+ uint64_t nb02;
217
+ uint64_t nb03;
218
+ int32_t ne10;
219
+ int32_t ne11;
220
+ int32_t ne12;
221
+ uint64_t nb10;
222
+ uint64_t nb11;
223
+ uint64_t nb12;
224
+ uint64_t nb13;
225
+ int32_t ne0;
226
+ int32_t ne1;
227
+ int16_t r2;
228
+ int16_t r3;
229
+ int16_t nsg;
230
+ int16_t nxpsg;
231
+ int16_t r1ptg;
232
+ } ggml_metal_kargs_mul_mv_ext;
233
+
234
+ typedef struct {
235
+ int32_t nei0;
236
+ int32_t nei1;
237
+ uint64_t nbi1;
238
+ int32_t ne00;
239
+ int32_t ne02;
240
+ uint64_t nb01;
241
+ uint64_t nb02;
242
+ int32_t ne11;
243
+ int32_t ne12;
244
+ int32_t ne13;
245
+ uint64_t nb10;
246
+ uint64_t nb11;
247
+ uint64_t nb12;
248
+ int32_t ne0;
249
+ int32_t ne1;
250
+ } ggml_metal_kargs_mul_mm_id;
251
+
252
+ typedef struct {
253
+ int32_t nei0;
254
+ int32_t nei1;
255
+ uint64_t nbi1;
256
+ int32_t ne00;
257
+ int32_t ne01;
258
+ int32_t ne02;
259
+ uint64_t nb00;
260
+ uint64_t nb01;
261
+ uint64_t nb02;
262
+ int32_t ne10;
263
+ int32_t ne11;
264
+ int32_t ne12;
265
+ int32_t ne13;
266
+ uint64_t nb10;
267
+ uint64_t nb11;
268
+ uint64_t nb12;
269
+ int32_t ne0;
270
+ int32_t ne1;
271
+ uint64_t nb1;
272
+ } ggml_metal_kargs_mul_mv_id;
273
+
274
+ typedef struct {
275
+ int32_t ne00;
276
+ int32_t ne00_4;
277
+ uint64_t nb01;
278
+ float eps;
279
+ } ggml_metal_kargs_norm;
280
+
281
+ typedef struct {
282
+ int32_t ne00;
283
+ int32_t ne00_4;
284
+ uint64_t nb01;
285
+ float eps;
286
+ } ggml_metal_kargs_rms_norm;
287
+
288
+ #endif // GGML_METAL_IMPL
@@ -0,0 +1,107 @@
1
+ if (NOT EXISTS $ENV{MUSA_PATH})
2
+ if (NOT EXISTS /opt/musa)
3
+ set(MUSA_PATH /usr/local/musa)
4
+ else()
5
+ set(MUSA_PATH /opt/musa)
6
+ endif()
7
+ else()
8
+ set(MUSA_PATH $ENV{MUSA_PATH})
9
+ endif()
10
+
11
+ set(CMAKE_C_COMPILER "${MUSA_PATH}/bin/clang")
12
+ set(CMAKE_C_EXTENSIONS OFF)
13
+ set(CMAKE_CXX_COMPILER "${MUSA_PATH}/bin/clang++")
14
+ set(CMAKE_CXX_EXTENSIONS OFF)
15
+
16
+ list(APPEND CMAKE_MODULE_PATH "${MUSA_PATH}/cmake")
17
+
18
+ find_package(MUSAToolkit)
19
+
20
+ if (MUSAToolkit_FOUND)
21
+ message(STATUS "MUSA Toolkit found")
22
+
23
+ if (NOT DEFINED MUSA_ARCHITECTURES)
24
+ set(MUSA_ARCHITECTURES "21;22")
25
+ endif()
26
+ message(STATUS "Using MUSA architectures: ${MUSA_ARCHITECTURES}")
27
+
28
+ file(GLOB GGML_HEADERS_MUSA "../ggml-cuda/*.cuh")
29
+ list(APPEND GGML_HEADERS_MUSA "../../include/ggml-cuda.h")
30
+
31
+ file(GLOB GGML_SOURCES_MUSA "../ggml-cuda/*.cu")
32
+ file(GLOB SRCS "../ggml-cuda/template-instances/fattn-wmma*.cu")
33
+ list(APPEND GGML_SOURCES_MUSA ${SRCS})
34
+ file(GLOB SRCS "../ggml-cuda/template-instances/mmq*.cu")
35
+ list(APPEND GGML_SOURCES_MUSA ${SRCS})
36
+
37
+ if (GGML_CUDA_FA_ALL_QUANTS)
38
+ file(GLOB SRCS "../ggml-cuda/template-instances/fattn-vec*.cu")
39
+ list(APPEND GGML_SOURCES_MUSA ${SRCS})
40
+ add_compile_definitions(GGML_CUDA_FA_ALL_QUANTS)
41
+ else()
42
+ file(GLOB SRCS "../ggml-cuda/template-instances/fattn-vec*q4_0-q4_0.cu")
43
+ list(APPEND GGML_SOURCES_MUSA ${SRCS})
44
+ file(GLOB SRCS "../ggml-cuda/template-instances/fattn-vec*q8_0-q8_0.cu")
45
+ list(APPEND GGML_SOURCES_MUSA ${SRCS})
46
+ file(GLOB SRCS "../ggml-cuda/template-instances/fattn-vec*f16-f16.cu")
47
+ list(APPEND GGML_SOURCES_MUSA ${SRCS})
48
+ endif()
49
+
50
+ set_source_files_properties(${GGML_SOURCES_MUSA} PROPERTIES LANGUAGE CXX)
51
+ foreach(SOURCE ${GGML_SOURCES_MUSA})
52
+ set(COMPILE_FLAGS "-x musa -mtgpu")
53
+ foreach(ARCH ${MUSA_ARCHITECTURES})
54
+ set(COMPILE_FLAGS "${COMPILE_FLAGS} --cuda-gpu-arch=mp_${ARCH}")
55
+ endforeach()
56
+ set_property(SOURCE ${SOURCE} PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS})
57
+ endforeach()
58
+
59
+ ggml_add_backend_library(ggml-musa
60
+ ${GGML_HEADERS_MUSA}
61
+ ${GGML_SOURCES_MUSA}
62
+ )
63
+
64
+ # TODO: do not use CUDA definitions for MUSA
65
+ target_compile_definitions(ggml PUBLIC GGML_USE_CUDA)
66
+
67
+ add_compile_definitions(GGML_USE_MUSA)
68
+ add_compile_definitions(GGML_CUDA_PEER_MAX_BATCH_SIZE=${GGML_CUDA_PEER_MAX_BATCH_SIZE})
69
+
70
+ if (GGML_CUDA_GRAPHS)
71
+ add_compile_definitions(GGML_CUDA_USE_GRAPHS)
72
+ endif()
73
+
74
+ if (GGML_CUDA_FORCE_MMQ)
75
+ add_compile_definitions(GGML_CUDA_FORCE_MMQ)
76
+ endif()
77
+
78
+ if (GGML_CUDA_FORCE_CUBLAS)
79
+ add_compile_definitions(GGML_CUDA_FORCE_CUBLAS)
80
+ endif()
81
+
82
+ if (GGML_CUDA_NO_VMM)
83
+ add_compile_definitions(GGML_CUDA_NO_VMM)
84
+ endif()
85
+
86
+ if (GGML_CUDA_F16 OR GGML_CUDA_DMMV_F16)
87
+ add_compile_definitions(GGML_CUDA_F16)
88
+ endif()
89
+
90
+ if (GGML_CUDA_NO_PEER_COPY)
91
+ add_compile_definitions(GGML_CUDA_NO_PEER_COPY)
92
+ endif()
93
+
94
+ if (GGML_STATIC)
95
+ target_link_libraries(ggml-musa PRIVATE MUSA::musart_static MUSA::mublas_static)
96
+ else()
97
+ target_link_libraries(ggml-musa PRIVATE MUSA::musart MUSA::mublas)
98
+ endif()
99
+
100
+ if (GGML_CUDA_NO_VMM)
101
+ # No VMM requested, no need to link directly with the musa driver lib (libmusa.so)
102
+ else()
103
+ target_link_libraries(ggml-musa PRIVATE MUSA::musa_driver)
104
+ endif()
105
+ else()
106
+ message(FATAL_ERROR "MUSA Toolkit not found")
107
+ endif()
@@ -0,0 +1,147 @@
1
+ find_package(OpenCL REQUIRED)
2
+ find_package(Python3 REQUIRED)
3
+
4
+ set(TARGET_NAME ggml-opencl)
5
+
6
+ ggml_add_backend_library(${TARGET_NAME}
7
+ ggml-opencl.cpp
8
+ ../../include/ggml-opencl.h)
9
+ target_link_libraries(${TARGET_NAME} PRIVATE ${OpenCL_LIBRARIES})
10
+ target_include_directories(${TARGET_NAME} PRIVATE ${OpenCL_INCLUDE_DIRS})
11
+
12
+ if (GGML_OPENCL_PROFILING)
13
+ message(STATUS "OpenCL profiling enabled (increases CPU overhead)")
14
+ add_compile_definitions(GGML_OPENCL_PROFILING)
15
+ endif ()
16
+
17
+ add_compile_definitions(GGML_OPENCL_SOA_Q)
18
+
19
+ if (GGML_OPENCL_USE_ADRENO_KERNELS)
20
+ message(STATUS "OpenCL will use matmul kernels optimized for Adreno")
21
+ add_compile_definitions(GGML_OPENCL_USE_ADRENO_KERNELS)
22
+ endif ()
23
+
24
+ if (GGML_OPENCL_EMBED_KERNELS)
25
+ add_compile_definitions(GGML_OPENCL_EMBED_KERNELS)
26
+
27
+ set(OPENCL_CL_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-opencl.cl.h")
28
+ set(OPENCL_MM_CL_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-opencl_mm.cl.h")
29
+ set(OPENCL_CVT_CL_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-opencl_cvt.cl.h")
30
+
31
+ set(OPENCL_GEMV_NOSHUFFLE_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-opencl_gemv_noshuffle.cl.h")
32
+ set(OPENCL_GEMV_NOSHUFFLE_GENERAL_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-opencl_gemv_noshuffle_general.cl.h")
33
+ set(OPENCL_MUL_MAT_Ab_Bi_8x4_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-opencl_mul_mat_Ab_Bi_8x4.cl.h")
34
+ set(OPENCL_TRANSPOSE_16_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-opencl_transpose_16.cl.h")
35
+ set(OPENCL_TRANSPOSE_32_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-opencl_transpose_32.cl.h")
36
+ set(OPENCL_TRANSPOSE_32_16_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-opencl_transpose_32_16.cl.h")
37
+
38
+ set(EMBED_KERNEL_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/kernels/embed_kernel.py")
39
+ file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/autogenerated")
40
+
41
+ include_directories("${CMAKE_BINARY_DIR}/autogenerated")
42
+
43
+ # Python must be accessible from command line
44
+ add_custom_command(
45
+ OUTPUT ${OPENCL_CL_SOURCE_EMBED}
46
+ COMMAND ${Python3_EXECUTABLE} ${EMBED_KERNEL_SCRIPT}
47
+ ${CMAKE_CURRENT_SOURCE_DIR}/kernels/ggml-opencl.cl
48
+ ${OPENCL_CL_SOURCE_EMBED}
49
+ DEPENDS kernels/ggml-opencl.cl ${EMBED_KERNEL_SCRIPT}
50
+ COMMENT "Generate ggml-opencl.cl.h"
51
+ )
52
+
53
+ add_custom_command(
54
+ OUTPUT ${OPENCL_MM_CL_SOURCE_EMBED}
55
+ COMMAND ${Python3_EXECUTABLE} ${EMBED_KERNEL_SCRIPT}
56
+ ${CMAKE_CURRENT_SOURCE_DIR}/kernels/ggml-opencl_mm.cl
57
+ ${OPENCL_MM_CL_SOURCE_EMBED}
58
+ DEPENDS kernels/ggml-opencl_mm.cl ${EMBED_KERNEL_SCRIPT}
59
+ COMMENT "Generate ggml-opencl_mm.cl.h"
60
+ )
61
+
62
+ add_custom_command(
63
+ OUTPUT ${OPENCL_CVT_CL_SOURCE_EMBED}
64
+ COMMAND ${Python3_EXECUTABLE} ${EMBED_KERNEL_SCRIPT}
65
+ ${CMAKE_CURRENT_SOURCE_DIR}/kernels/ggml-opencl_cvt.cl
66
+ ${OPENCL_CVT_CL_SOURCE_EMBED}
67
+ DEPENDS kernels/ggml-opencl_cvt.cl ${EMBED_KERNEL_SCRIPT}
68
+ COMMENT "Generate ggml-opencl_cvt.cl.h"
69
+ )
70
+
71
+ add_custom_command(
72
+ OUTPUT ${OPENCL_GEMV_NOSHUFFLE_SOURCE_EMBED}
73
+ COMMAND ${Python3_EXECUTABLE} ${EMBED_KERNEL_SCRIPT}
74
+ ${CMAKE_CURRENT_SOURCE_DIR}/kernels/ggml-opencl_gemv_noshuffle.cl
75
+ ${OPENCL_GEMV_NOSHUFFLE_SOURCE_EMBED}
76
+ DEPENDS kernels/ggml-opencl_gemv_noshuffle.cl ${EMBED_KERNEL_SCRIPT}
77
+ COMMENT "Generate ggml-opencl_gemv_noshuffle.cl.h"
78
+ )
79
+
80
+ add_custom_command(
81
+ OUTPUT ${OPENCL_GEMV_NOSHUFFLE_GENERAL_SOURCE_EMBED}
82
+ COMMAND ${Python3_EXECUTABLE} ${EMBED_KERNEL_SCRIPT}
83
+ ${CMAKE_CURRENT_SOURCE_DIR}/kernels/ggml-opencl_gemv_noshuffle_general.cl
84
+ ${OPENCL_GEMV_NOSHUFFLE_GENERAL_SOURCE_EMBED}
85
+ DEPENDS kernels/ggml-opencl_gemv_noshuffle_general.cl ${EMBED_KERNEL_SCRIPT}
86
+ COMMENT "Generate ggml-opencl_gemv_noshuffle_general.cl.h"
87
+ )
88
+
89
+ add_custom_command(
90
+ OUTPUT ${OPENCL_MUL_MAT_Ab_Bi_8x4_SOURCE_EMBED}
91
+ COMMAND ${Python3_EXECUTABLE} ${EMBED_KERNEL_SCRIPT}
92
+ ${CMAKE_CURRENT_SOURCE_DIR}/kernels/ggml-opencl_mul_mat_Ab_Bi_8x4.cl
93
+ ${OPENCL_MUL_MAT_Ab_Bi_8x4_SOURCE_EMBED}
94
+ DEPENDS kernels/ggml-opencl_mul_mat_Ab_Bi_8x4.cl ${EMBED_KERNEL_SCRIPT}
95
+ COMMENT "Generate ggml-opencl_mul_mat_Ab_Bi_8x4.cl.cl.h"
96
+ )
97
+
98
+ add_custom_command(
99
+ OUTPUT ${OPENCL_TRANSPOSE_16_SOURCE_EMBED}
100
+ COMMAND ${Python3_EXECUTABLE} ${EMBED_KERNEL_SCRIPT}
101
+ ${CMAKE_CURRENT_SOURCE_DIR}/kernels/ggml-opencl_transpose_16.cl
102
+ ${OPENCL_TRANSPOSE_16_SOURCE_EMBED}
103
+ DEPENDS kernels/ggml-opencl_transpose_16.cl ${EMBED_KERNEL_SCRIPT}
104
+ COMMENT "Generate ggml-opencl_transpose_16.cl.h"
105
+ )
106
+
107
+ add_custom_command(
108
+ OUTPUT ${OPENCL_TRANSPOSE_32_SOURCE_EMBED}
109
+ COMMAND ${Python3_EXECUTABLE} ${EMBED_KERNEL_SCRIPT}
110
+ ${CMAKE_CURRENT_SOURCE_DIR}/kernels/ggml-opencl_transpose_32.cl
111
+ ${OPENCL_TRANSPOSE_32_SOURCE_EMBED}
112
+ DEPENDS kernels/ggml-opencl_transpose_32.cl ${EMBED_KERNEL_SCRIPT}
113
+ COMMENT "Generate ggml-opencl_transpose_32.cl.h"
114
+ )
115
+
116
+ add_custom_command(
117
+ OUTPUT ${OPENCL_TRANSPOSE_32_16_SOURCE_EMBED}
118
+ COMMAND ${Python3_EXECUTABLE} ${EMBED_KERNEL_SCRIPT}
119
+ ${CMAKE_CURRENT_SOURCE_DIR}/kernels/ggml-opencl_transpose_32_16.cl
120
+ ${OPENCL_TRANSPOSE_32_16_SOURCE_EMBED}
121
+ DEPENDS kernels/ggml-opencl_transpose_32_16.cl ${EMBED_KERNEL_SCRIPT}
122
+ COMMENT "Generate ggml-opencl_transpose_32_16.cl.h"
123
+ )
124
+
125
+ target_sources(${TARGET_NAME} PRIVATE
126
+ ${OPENCL_CL_SOURCE_EMBED}
127
+ ${OPENCL_MM_CL_SOURCE_EMBED}
128
+ ${OPENCL_CVT_CL_SOURCE_EMBED}
129
+ ${OPENCL_GEMV_NOSHUFFLE_SOURCE_EMBED}
130
+ ${OPENCL_GEMV_NOSHUFFLE_GENERAL_SOURCE_EMBED}
131
+ ${OPENCL_MUL_MAT_Ab_Bi_8x4_SOURCE_EMBED}
132
+ ${OPENCL_TRANSPOSE_16_SOURCE_EMBED}
133
+ ${OPENCL_TRANSPOSE_32_SOURCE_EMBED}
134
+ ${OPENCL_TRANSPOSE_32_16_SOURCE_EMBED})
135
+ else ()
136
+ # copy ggml-opencl.cl to bin directory
137
+ configure_file(kernels/ggml-opencl.cl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-opencl.cl COPYONLY)
138
+ configure_file(kernels/ggml-opencl_mm.cl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-opencl_mm.cl COPYONLY)
139
+ configure_file(kernels/ggml-opencl_cvt.cl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-opencl_cvt.cl COPYONLY)
140
+
141
+ configure_file(kernels/ggml-opencl_gemv_noshuffle.cl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-opencl_gemv_noshuffle.cl COPYONLY)
142
+ configure_file(kernels/ggml-opencl_gemv_noshuffle_general.cl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-opencl_gemv_noshuffle_general.cl COPYONLY)
143
+ configure_file(kernels/ggml-opencl_mul_mat_Ab_Bi_8x4.cl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-opencl_mul_mat_Ab_Bi_8x4.cl COPYONLY)
144
+ configure_file(kernels/ggml-opencl_transpose_16.cl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-opencl_transpose_16.cl COPYONLY)
145
+ configure_file(kernels/ggml-opencl_transpose_32.cl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-opencl_transpose_32.cl COPYONLY)
146
+ configure_file(kernels/ggml-opencl_transpose_32_16.cl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-opencl_transpose_32_16.cl COPYONLY)
147
+ endif ()