@fugood/llama.node 0.3.16 → 0.4.0

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 (281) hide show
  1. package/CMakeLists.txt +6 -1
  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-cuda/arm64/llama-node.node +0 -0
  7. package/bin/linux-cuda/x64/llama-node.node +0 -0
  8. package/bin/linux-vulkan/arm64/llama-node.node +0 -0
  9. package/bin/linux-vulkan/x64/llama-node.node +0 -0
  10. package/bin/win32/arm64/llama-node.node +0 -0
  11. package/bin/win32/arm64/node.lib +0 -0
  12. package/bin/win32/x64/llama-node.node +0 -0
  13. package/bin/win32/x64/node.lib +0 -0
  14. package/bin/win32-vulkan/arm64/llama-node.node +0 -0
  15. package/bin/win32-vulkan/arm64/node.lib +0 -0
  16. package/bin/win32-vulkan/x64/llama-node.node +0 -0
  17. package/bin/win32-vulkan/x64/node.lib +0 -0
  18. package/lib/binding.ts +44 -2
  19. package/lib/index.js +132 -1
  20. package/lib/index.ts +203 -3
  21. package/package.json +2 -1
  22. package/src/EmbeddingWorker.cpp +1 -1
  23. package/src/LlamaCompletionWorker.cpp +374 -19
  24. package/src/LlamaCompletionWorker.h +31 -10
  25. package/src/LlamaContext.cpp +216 -7
  26. package/src/LlamaContext.h +12 -0
  27. package/src/common.hpp +15 -0
  28. package/src/llama.cpp/.github/workflows/build-linux-cross.yml +233 -0
  29. package/src/llama.cpp/.github/workflows/build.yml +89 -767
  30. package/src/llama.cpp/.github/workflows/docker.yml +9 -6
  31. package/src/llama.cpp/.github/workflows/release.yml +716 -0
  32. package/src/llama.cpp/.github/workflows/server.yml +19 -23
  33. package/src/llama.cpp/CMakeLists.txt +11 -1
  34. package/src/llama.cpp/cmake/build-info.cmake +8 -2
  35. package/src/llama.cpp/cmake/x64-windows-llvm.cmake +0 -6
  36. package/src/llama.cpp/common/CMakeLists.txt +35 -4
  37. package/src/llama.cpp/common/arg.cpp +844 -121
  38. package/src/llama.cpp/common/arg.h +9 -0
  39. package/src/llama.cpp/common/chat.cpp +129 -107
  40. package/src/llama.cpp/common/chat.h +2 -0
  41. package/src/llama.cpp/common/common.cpp +64 -518
  42. package/src/llama.cpp/common/common.h +35 -45
  43. package/src/llama.cpp/common/json-schema-to-grammar.cpp +3 -0
  44. package/src/llama.cpp/common/llguidance.cpp +31 -47
  45. package/src/llama.cpp/common/minja/chat-template.hpp +23 -11
  46. package/src/llama.cpp/common/minja/minja.hpp +186 -127
  47. package/src/llama.cpp/common/regex-partial.cpp +204 -0
  48. package/src/llama.cpp/common/regex-partial.h +56 -0
  49. package/src/llama.cpp/common/sampling.cpp +60 -50
  50. package/src/llama.cpp/docs/build.md +122 -7
  51. package/src/llama.cpp/examples/CMakeLists.txt +2 -32
  52. package/src/llama.cpp/examples/batched/batched.cpp +1 -1
  53. package/src/llama.cpp/examples/embedding/embedding.cpp +9 -12
  54. package/src/llama.cpp/examples/gritlm/gritlm.cpp +1 -1
  55. package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +1 -0
  56. package/src/llama.cpp/examples/parallel/parallel.cpp +89 -15
  57. package/src/llama.cpp/examples/passkey/passkey.cpp +1 -1
  58. package/src/llama.cpp/examples/speculative/speculative.cpp +1 -1
  59. package/src/llama.cpp/examples/speculative-simple/speculative-simple.cpp +1 -1
  60. package/src/llama.cpp/examples/sycl/build.sh +2 -2
  61. package/src/llama.cpp/examples/sycl/win-build-sycl.bat +2 -2
  62. package/src/llama.cpp/examples/training/CMakeLists.txt +5 -0
  63. package/src/llama.cpp/examples/training/finetune.cpp +96 -0
  64. package/src/llama.cpp/ggml/CMakeLists.txt +35 -2
  65. package/src/llama.cpp/ggml/cmake/GitVars.cmake +22 -0
  66. package/src/llama.cpp/ggml/include/ggml-backend.h +4 -4
  67. package/src/llama.cpp/ggml/include/ggml-cpp.h +1 -1
  68. package/src/llama.cpp/ggml/include/ggml-cpu.h +5 -0
  69. package/src/llama.cpp/ggml/include/ggml-opt.h +47 -28
  70. package/src/llama.cpp/ggml/include/ggml-rpc.h +6 -1
  71. package/src/llama.cpp/ggml/include/ggml.h +76 -106
  72. package/src/llama.cpp/ggml/src/CMakeLists.txt +11 -8
  73. package/src/llama.cpp/ggml/src/ggml-alloc.c +4 -1
  74. package/src/llama.cpp/ggml/src/ggml-backend.cpp +9 -5
  75. package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +0 -2
  76. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +8 -4
  77. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +5 -5
  78. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +692 -1534
  79. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +613 -122
  80. package/src/llama.cpp/ggml/src/ggml-cann/common.h +135 -1
  81. package/src/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +507 -137
  82. package/src/llama.cpp/ggml/src/ggml-common.h +12 -6
  83. package/src/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +66 -33
  84. package/src/llama.cpp/ggml/src/ggml-cpu/binary-ops.cpp +158 -0
  85. package/src/llama.cpp/ggml/src/ggml-cpu/binary-ops.h +16 -0
  86. package/src/llama.cpp/ggml/src/ggml-cpu/common.h +72 -0
  87. package/src/llama.cpp/ggml/src/ggml-cpu/cpu-feats-x86.cpp +1 -1
  88. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.cpp +896 -194
  89. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-impl.h +2 -21
  90. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.c +1060 -410
  91. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +1008 -13533
  92. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +31 -16
  93. package/src/llama.cpp/ggml/src/ggml-cpu/kleidiai/kernels.cpp +90 -12
  94. package/src/llama.cpp/ggml/src/ggml-cpu/kleidiai/kernels.h +47 -13
  95. package/src/llama.cpp/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +266 -72
  96. package/src/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp +1034 -88
  97. package/src/llama.cpp/ggml/src/ggml-cpu/ops.cpp +8796 -0
  98. package/src/llama.cpp/ggml/src/ggml-cpu/ops.h +110 -0
  99. package/src/llama.cpp/ggml/src/ggml-cpu/simd-mappings.h +892 -0
  100. package/src/llama.cpp/ggml/src/ggml-cpu/unary-ops.cpp +186 -0
  101. package/src/llama.cpp/ggml/src/ggml-cpu/unary-ops.h +28 -0
  102. package/src/llama.cpp/ggml/src/ggml-cpu/vec.cpp +252 -0
  103. package/src/llama.cpp/ggml/src/ggml-cpu/vec.h +802 -0
  104. package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +23 -4
  105. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +7 -0
  106. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +1 -0
  107. package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +0 -4
  108. package/src/llama.cpp/ggml/src/ggml-impl.h +52 -18
  109. package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +106 -14
  110. package/src/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +67 -119
  111. package/src/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +1023 -262
  112. package/src/llama.cpp/ggml/src/ggml-opt.cpp +368 -190
  113. package/src/llama.cpp/ggml/src/ggml-quants.c +0 -6
  114. package/src/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +307 -40
  115. package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +125 -45
  116. package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +10 -8
  117. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +239 -0
  118. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.hpp +39 -0
  119. package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +0 -35
  120. package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +9 -307
  121. package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +72 -25
  122. package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +14 -7
  123. package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +59 -21
  124. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +7 -1
  125. package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +79 -90
  126. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +944 -438
  127. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +22 -23
  128. package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +37 -8
  129. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +24 -20
  130. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.hpp +1 -4
  131. package/src/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +507 -411
  132. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +84 -74
  133. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +1 -3
  134. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +185 -89
  135. package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +37 -49
  136. package/src/llama.cpp/ggml/src/ggml-sycl/norm.hpp +7 -22
  137. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +4 -14
  138. package/src/llama.cpp/ggml/src/ggml-sycl/quants.hpp +83 -0
  139. package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +204 -118
  140. package/src/llama.cpp/ggml/src/ggml-sycl/rope.hpp +1 -3
  141. package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +128 -53
  142. package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +83 -49
  143. package/src/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +1278 -282
  144. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +32 -0
  145. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +133 -30
  146. package/src/llama.cpp/ggml/src/ggml.c +170 -265
  147. package/src/llama.cpp/ggml/src/gguf.cpp +34 -33
  148. package/src/llama.cpp/include/llama.h +82 -22
  149. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.inp +112 -0
  150. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.out +46 -0
  151. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.inp +112 -0
  152. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.out +46 -0
  153. package/src/llama.cpp/requirements/requirements-all.txt +5 -3
  154. package/src/llama.cpp/requirements/requirements-gguf_editor_gui.txt +3 -0
  155. package/src/llama.cpp/scripts/xxd.cmake +1 -1
  156. package/src/llama.cpp/src/CMakeLists.txt +4 -2
  157. package/src/llama.cpp/src/llama-adapter.cpp +43 -1
  158. package/src/llama.cpp/src/llama-arch.cpp +163 -17
  159. package/src/llama.cpp/src/llama-arch.h +16 -0
  160. package/src/llama.cpp/src/llama-batch.cpp +5 -1
  161. package/src/llama.cpp/src/llama-batch.h +2 -1
  162. package/src/llama.cpp/src/llama-chat.cpp +91 -16
  163. package/src/llama.cpp/src/llama-chat.h +7 -2
  164. package/src/llama.cpp/src/llama-context.cpp +479 -575
  165. package/src/llama.cpp/src/llama-context.h +44 -33
  166. package/src/llama.cpp/src/llama-cparams.h +1 -0
  167. package/src/llama.cpp/src/llama-graph.cpp +209 -157
  168. package/src/llama.cpp/src/llama-graph.h +38 -14
  169. package/src/llama.cpp/src/llama-hparams.h +13 -0
  170. package/src/llama.cpp/src/llama-kv-cache.cpp +1604 -543
  171. package/src/llama.cpp/src/llama-kv-cache.h +283 -171
  172. package/src/llama.cpp/src/llama-memory.h +12 -2
  173. package/src/llama.cpp/src/llama-mmap.cpp +1 -1
  174. package/src/llama.cpp/src/llama-model-loader.cpp +34 -20
  175. package/src/llama.cpp/src/llama-model-loader.h +5 -3
  176. package/src/llama.cpp/src/llama-model-saver.cpp +281 -0
  177. package/src/llama.cpp/src/llama-model-saver.h +37 -0
  178. package/src/llama.cpp/src/llama-model.cpp +1803 -330
  179. package/src/llama.cpp/src/llama-model.h +21 -2
  180. package/src/llama.cpp/src/llama-quant.cpp +33 -10
  181. package/src/llama.cpp/src/llama-sampling.cpp +25 -7
  182. package/src/llama.cpp/src/llama-vocab.cpp +86 -10
  183. package/src/llama.cpp/src/llama-vocab.h +6 -0
  184. package/src/llama.cpp/src/llama.cpp +15 -1
  185. package/src/llama.cpp/tests/CMakeLists.txt +52 -31
  186. package/src/llama.cpp/tests/test-arg-parser.cpp +51 -4
  187. package/src/llama.cpp/tests/test-backend-ops.cpp +189 -90
  188. package/src/llama.cpp/tests/test-chat-template.cpp +26 -6
  189. package/src/llama.cpp/tests/test-chat.cpp +15 -3
  190. package/src/llama.cpp/{examples/gbnf-validator/gbnf-validator.cpp → tests/test-gbnf-validator.cpp} +2 -2
  191. package/src/llama.cpp/tests/test-grammar-integration.cpp +3 -2
  192. package/src/llama.cpp/tests/test-grammar-llguidance.cpp +63 -2
  193. package/src/llama.cpp/tests/test-grammar-parser.cpp +3 -1
  194. package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +17 -1
  195. package/src/llama.cpp/tests/test-llama-grammar.cpp +2 -1
  196. package/src/llama.cpp/tests/test-mtmd-c-api.c +63 -0
  197. package/src/llama.cpp/tests/test-opt.cpp +33 -21
  198. package/src/llama.cpp/{examples/quantize-stats/quantize-stats.cpp → tests/test-quantize-stats.cpp} +3 -1
  199. package/src/llama.cpp/tests/test-regex-partial.cpp +288 -0
  200. package/src/llama.cpp/tests/test-sampling.cpp +1 -1
  201. package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +2 -1
  202. package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +2 -1
  203. package/src/llama.cpp/tools/CMakeLists.txt +39 -0
  204. package/src/llama.cpp/{examples → tools}/batched-bench/batched-bench.cpp +3 -3
  205. package/src/llama.cpp/{examples → tools}/export-lora/export-lora.cpp +1 -1
  206. package/src/llama.cpp/{examples → tools}/gguf-split/gguf-split.cpp +15 -16
  207. package/src/llama.cpp/{examples → tools}/imatrix/imatrix.cpp +11 -9
  208. package/src/llama.cpp/{examples → tools}/llama-bench/llama-bench.cpp +623 -274
  209. package/src/llama.cpp/{examples → tools}/main/main.cpp +22 -14
  210. package/src/llama.cpp/tools/mtmd/CMakeLists.txt +47 -0
  211. package/src/llama.cpp/tools/mtmd/clip-impl.h +365 -0
  212. package/src/llama.cpp/tools/mtmd/clip.cpp +3646 -0
  213. package/src/llama.cpp/tools/mtmd/clip.h +99 -0
  214. package/src/llama.cpp/tools/mtmd/deprecation-warning.cpp +22 -0
  215. package/src/llama.cpp/tools/mtmd/mtmd-cli.cpp +370 -0
  216. package/src/llama.cpp/tools/mtmd/mtmd-helper.cpp +310 -0
  217. package/src/llama.cpp/tools/mtmd/mtmd.cpp +678 -0
  218. package/src/llama.cpp/tools/mtmd/mtmd.h +331 -0
  219. package/src/llama.cpp/{examples → tools}/perplexity/perplexity.cpp +21 -5
  220. package/src/llama.cpp/{examples → tools}/quantize/quantize.cpp +53 -3
  221. package/src/llama.cpp/tools/rpc/CMakeLists.txt +4 -0
  222. package/src/llama.cpp/tools/rpc/rpc-server.cpp +322 -0
  223. package/src/llama.cpp/tools/run/CMakeLists.txt +16 -0
  224. package/src/llama.cpp/{examples → tools}/run/run.cpp +30 -30
  225. package/src/llama.cpp/{examples → tools}/server/CMakeLists.txt +2 -1
  226. package/src/llama.cpp/{examples → tools}/server/httplib.h +313 -247
  227. package/src/llama.cpp/{examples → tools}/server/server.cpp +529 -215
  228. package/src/llama.cpp/{examples → tools}/server/utils.hpp +427 -6
  229. package/src/llama.cpp/{examples → tools}/tts/tts.cpp +6 -9
  230. package/src/llama.cpp/cmake/arm64-windows-msvc.cmake +0 -6
  231. package/src/llama.cpp/examples/gbnf-validator/CMakeLists.txt +0 -5
  232. package/src/llama.cpp/examples/infill/CMakeLists.txt +0 -5
  233. package/src/llama.cpp/examples/infill/infill.cpp +0 -590
  234. package/src/llama.cpp/examples/llava/CMakeLists.txt +0 -66
  235. package/src/llama.cpp/examples/llava/android/build_64.sh +0 -8
  236. package/src/llama.cpp/examples/llava/clip-quantize-cli.cpp +0 -59
  237. package/src/llama.cpp/examples/llava/clip.cpp +0 -3206
  238. package/src/llama.cpp/examples/llava/clip.h +0 -118
  239. package/src/llama.cpp/examples/llava/gemma3-cli.cpp +0 -341
  240. package/src/llama.cpp/examples/llava/llava-cli.cpp +0 -332
  241. package/src/llama.cpp/examples/llava/llava.cpp +0 -574
  242. package/src/llama.cpp/examples/llava/llava.h +0 -49
  243. package/src/llama.cpp/examples/llava/minicpmv-cli.cpp +0 -354
  244. package/src/llama.cpp/examples/llava/qwen2vl-cli.cpp +0 -584
  245. package/src/llama.cpp/examples/quantize-stats/CMakeLists.txt +0 -6
  246. package/src/llama.cpp/examples/rpc/CMakeLists.txt +0 -2
  247. package/src/llama.cpp/examples/rpc/rpc-server.cpp +0 -171
  248. package/src/llama.cpp/examples/run/CMakeLists.txt +0 -5
  249. package/src/llama.cpp/ggml/src/ggml-cann/kernels/CMakeLists.txt +0 -30
  250. package/src/llama.cpp/ggml/src/ggml-cann/kernels/ascendc_kernels.h +0 -19
  251. package/src/llama.cpp/ggml/src/ggml-cann/kernels/dup.cpp +0 -234
  252. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_f16.cpp +0 -197
  253. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_f32.cpp +0 -190
  254. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp +0 -204
  255. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_q8_0.cpp +0 -191
  256. package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp +0 -218
  257. package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp +0 -216
  258. package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp +0 -295
  259. /package/src/llama.cpp/{examples → tools}/batched-bench/CMakeLists.txt +0 -0
  260. /package/src/llama.cpp/{examples → tools}/cvector-generator/CMakeLists.txt +0 -0
  261. /package/src/llama.cpp/{examples → tools}/cvector-generator/completions.txt +0 -0
  262. /package/src/llama.cpp/{examples → tools}/cvector-generator/cvector-generator.cpp +0 -0
  263. /package/src/llama.cpp/{examples → tools}/cvector-generator/mean.hpp +0 -0
  264. /package/src/llama.cpp/{examples → tools}/cvector-generator/negative.txt +0 -0
  265. /package/src/llama.cpp/{examples → tools}/cvector-generator/pca.hpp +0 -0
  266. /package/src/llama.cpp/{examples → tools}/cvector-generator/positive.txt +0 -0
  267. /package/src/llama.cpp/{examples → tools}/export-lora/CMakeLists.txt +0 -0
  268. /package/src/llama.cpp/{examples → tools}/gguf-split/CMakeLists.txt +0 -0
  269. /package/src/llama.cpp/{examples → tools}/imatrix/CMakeLists.txt +0 -0
  270. /package/src/llama.cpp/{examples → tools}/llama-bench/CMakeLists.txt +0 -0
  271. /package/src/llama.cpp/{examples → tools}/main/CMakeLists.txt +0 -0
  272. /package/src/llama.cpp/{examples/llava → tools/mtmd}/requirements.txt +0 -0
  273. /package/src/llama.cpp/{examples → tools}/perplexity/CMakeLists.txt +0 -0
  274. /package/src/llama.cpp/{examples → tools}/quantize/CMakeLists.txt +0 -0
  275. /package/src/llama.cpp/{examples → tools}/run/linenoise.cpp/linenoise.cpp +0 -0
  276. /package/src/llama.cpp/{examples → tools}/run/linenoise.cpp/linenoise.h +0 -0
  277. /package/src/llama.cpp/{examples → tools}/server/bench/requirements.txt +0 -0
  278. /package/src/llama.cpp/{examples → tools}/server/tests/requirements.txt +0 -0
  279. /package/src/llama.cpp/{examples → tools}/tokenize/CMakeLists.txt +0 -0
  280. /package/src/llama.cpp/{examples → tools}/tokenize/tokenize.cpp +0 -0
  281. /package/src/llama.cpp/{examples → tools}/tts/CMakeLists.txt +0 -0
@@ -23,35 +23,64 @@ ggml_add_backend_library(ggml-sycl
23
23
  ../../include/ggml-sycl.h
24
24
  )
25
25
 
26
- find_package(DNNL)
26
+ file(GLOB GGML_HEADERS_SYCL "*.hpp")
27
+ file(GLOB GGML_SOURCES_SYCL "*.cpp")
28
+ target_sources(ggml-sycl PRIVATE ${GGML_HEADERS_SYCL} ${GGML_SOURCES_SYCL})
29
+
30
+ if (WIN32)
31
+ # To generate a Visual Studio solution, using Intel C++ Compiler for ggml-sycl is mandatory
32
+ if( ${CMAKE_GENERATOR} MATCHES "Visual Studio" AND NOT (${CMAKE_GENERATOR_TOOLSET} MATCHES "Intel C"))
33
+ set_target_properties(ggml-sycl PROPERTIES VS_PLATFORM_TOOLSET "Intel C++ Compiler 2025")
34
+ set(CMAKE_CXX_COMPILER "icx")
35
+ set(CMAKE_CXX_COMPILER_ID "IntelLLVM")
36
+ endif()
37
+ endif()
38
+
39
+ find_package(IntelSYCL)
40
+ if (IntelSYCL_FOUND)
41
+ # Use oneAPI CMake when possible
42
+ target_link_libraries(ggml-sycl PRIVATE IntelSYCL::SYCL_CXX)
43
+ else()
44
+ # Fallback to the simplest way of enabling SYCL when using intel/llvm nightly for instance
45
+ target_compile_options(ggml-sycl PRIVATE "-fsycl")
46
+ target_link_options(ggml-sycl PRIVATE "-fsycl")
47
+ endif()
48
+
49
+ target_compile_options(ggml-sycl PRIVATE "-Wno-narrowing")
50
+
51
+ # Link against oneDNN
27
52
  set(GGML_SYCL_DNNL 0)
28
- if(DNNL_FOUND)
29
- if (DEFINED ENV{ONEAPI_ROOT} AND NOT DEFINED DNNL_GPU_VENDOR)
30
- # Assuming oneDNN packaged with oneapi release is used which
31
- # supports only intel target
32
- set(DNNL_GPU_VENDOR "INTEL")
33
- if(NOT "${GGML_SYCL_TARGET}" STREQUAL "INTEL")
34
- message(WARNING "oneDNN builds bundled with oneapi release only support INTEL target")
53
+ if(GGML_SYCL_DNN)
54
+ find_package(DNNL)
55
+ if(DNNL_FOUND)
56
+ if (NOT DEFINED DNNL_GPU_VENDOR)
57
+ # default to intel target
58
+ set(DNNL_GPU_VENDOR "INTEL")
59
+ if(NOT "${GGML_SYCL_TARGET}" STREQUAL "INTEL")
60
+ message(WARNING "oneDNN builds bundled with oneapi release only support INTEL target")
61
+ endif()
35
62
  endif()
36
- endif()
37
63
 
38
- # Verify oneDNN was compiled for the same target as llama
39
- if("${GGML_SYCL_TARGET}" STREQUAL "${DNNL_GPU_VENDOR}")
40
- target_link_libraries(ggml-sycl PRIVATE DNNL::dnnl)
41
- set(GGML_SYCL_DNNL 1)
42
- get_target_property(CONFIGS DNNL::dnnl IMPORTED_CONFIGURATIONS)
43
- foreach(CONFIG ${CONFIGS})
44
- get_target_property(DNNL_LIB DNNL::dnnl IMPORTED_LOCATION_${CONFIG})
45
- message(STATUS "Found oneDNN: ${DNNL_LIB}")
46
- endforeach()
64
+ # Verify oneDNN was compiled for the same target as llama
65
+ if("${GGML_SYCL_TARGET}" STREQUAL "${DNNL_GPU_VENDOR}")
66
+ target_link_libraries(ggml-sycl PRIVATE DNNL::dnnl)
67
+ set(GGML_SYCL_DNNL 1)
68
+ get_target_property(CONFIGS DNNL::dnnl IMPORTED_CONFIGURATIONS)
69
+ foreach(CONFIG ${CONFIGS})
70
+ get_target_property(DNNL_LIB DNNL::dnnl IMPORTED_LOCATION_${CONFIG})
71
+ message(STATUS "Found oneDNN: ${DNNL_LIB}")
72
+ endforeach()
73
+ else()
74
+ message(WARNING
75
+ "oneDNN must be compiled for the same target as llama.cpp.
76
+ llama.cpp: ${GGML_SYCL_TARGET}, oneDNN: ${DNNL_GPU_VENDOR}.
77
+ Disabling oneDNN support.")
78
+ endif()
47
79
  else()
48
- message(WARNING
49
- "oneDNN must be compiled for the same target as llama.cpp.
50
- llama.cpp: ${GGML_SYCL_TARGET}, oneDNN: ${DNNL_GPU_VENDOR}.
51
- Disabling oneDNN support.")
80
+ message(STATUS "oneDNN not found, disabling oneDNN support")
52
81
  endif()
53
82
  else()
54
- message(STATUS "oneDNN not found, disabling oneDNN support")
83
+ message(STATUS "oneDNN support disabled by the user")
55
84
  endif()
56
85
  target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_DNNL=${GGML_SYCL_DNNL})
57
86
 
@@ -62,8 +91,6 @@ if (GGML_SYCL_F16)
62
91
  add_compile_definitions(GGML_SYCL_F16)
63
92
  endif()
64
93
 
65
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing -fsycl")
66
-
67
94
  if (GGML_SYCL_TARGET STREQUAL "NVIDIA")
68
95
  add_compile_definitions(GGML_SYCL_WARP_SIZE=32)
69
96
  elseif (GGML_SYCL_TARGET STREQUAL "AMD")
@@ -76,34 +103,87 @@ else()
76
103
  add_compile_definitions(GGML_SYCL_WARP_SIZE=16)
77
104
  endif()
78
105
 
79
- file(GLOB GGML_HEADERS_SYCL "*.hpp")
80
- file(GLOB GGML_SOURCES_SYCL "*.cpp")
81
- target_sources(ggml-sycl PRIVATE ${GGML_HEADERS_SYCL} ${GGML_SOURCES_SYCL})
82
-
106
+ if (GGML_SYCL_GRAPH)
107
+ target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_GRAPH)
108
+ endif()
83
109
 
84
- if (WIN32)
85
- find_package(IntelSYCL REQUIRED)
110
+ # Link against Intel oneMKL or oneMath
111
+ if (GGML_SYCL_TARGET STREQUAL "INTEL")
112
+ # Intel devices use Intel oneMKL directly instead of oneMath to avoid the limitation of linking Intel oneMKL statically
113
+ # See https://github.com/uxlfoundation/oneMath/issues/654
114
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
115
+ set(SYCL_COMPILER ON)
116
+ endif()
86
117
  find_package(MKL REQUIRED)
87
- target_link_libraries(ggml-sycl PRIVATE IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL)
118
+ target_link_libraries(ggml-sycl PRIVATE MKL::MKL_SYCL::BLAS)
119
+ target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_USE_INTEL_ONEMKL)
88
120
  else()
89
- if (GGML_SYCL_GRAPH)
90
- add_compile_definitions(GGML_SYCL_GRAPH)
121
+ find_package(oneMath QUIET)
122
+ if (NOT oneMath_FOUND)
123
+ message(STATUS "oneMath not found: oneMath will be automatically downloaded")
124
+ # Use FetchContent to automatically pull and build oneMath
125
+ include(FetchContent)
126
+ set(BUILD_FUNCTIONAL_TESTS False)
127
+ set(BUILD_EXAMPLES False)
128
+ set(TARGET_DOMAINS blas)
129
+ if (GGML_SYCL_TARGET STREQUAL "NVIDIA")
130
+ set(ENABLE_MKLCPU_BACKEND False)
131
+ set(ENABLE_MKLGPU_BACKEND False)
132
+ set(ENABLE_CUBLAS_BACKEND True)
133
+ elseif (GGML_SYCL_TARGET STREQUAL "AMD")
134
+ set(ENABLE_MKLCPU_BACKEND False)
135
+ set(ENABLE_MKLGPU_BACKEND False)
136
+ set(ENABLE_ROCBLAS_BACKEND True)
137
+ # Ensure setting a string variable here is not overriden by oneMath CACHE variables
138
+ cmake_policy(SET CMP0126 NEW)
139
+ # Setting the device architecture is only needed and useful for AMD devices in oneMath
140
+ set(HIP_TARGETS ${GGML_SYCL_DEVICE_ARCH} CACHE STRING "oneMath HIP target" FORCE)
141
+ endif()
142
+ FetchContent_Declare(
143
+ ONEMATH
144
+ GIT_REPOSITORY https://github.com/uxlfoundation/oneMath.git
145
+ GIT_TAG c255b1b4c41e2ee3059455c1f96a965d6a62568a
146
+ )
147
+ FetchContent_MakeAvailable(ONEMATH)
148
+ # Create alias to match with find_package targets name
149
+ function(onemath_alias target)
150
+ if (TARGET ${target}_obj)
151
+ # Silence verbose warnings from external libraries
152
+ target_compile_options(${target}_obj PRIVATE -w)
153
+ endif()
154
+ if (TARGET ${target})
155
+ add_library(ONEMATH::${target} ALIAS ${target})
156
+ endif()
157
+ endfunction()
158
+ onemath_alias(onemath)
159
+ onemath_alias(onemath_blas_mklcpu)
160
+ onemath_alias(onemath_blas_mklgpu)
161
+ onemath_alias(onemath_blas_cublas)
162
+ onemath_alias(onemath_blas_rocblas)
91
163
  endif()
92
- if (GGML_SYCL_TARGET STREQUAL "INTEL")
93
- target_link_libraries(ggml-sycl PRIVATE sycl OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread)
94
- elseif (GGML_SYCL_TARGET STREQUAL "NVIDIA")
95
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=nvptx64-nvidia-cuda")
96
- add_compile_definitions(GGML_SYCL_NVIDIA)
97
- target_link_libraries(ggml-sycl PRIVATE sycl pthread m dl onemkl_blas_cublas)
164
+
165
+ # Below oneMath compile-time dispatching is used for better performance
166
+ if (GGML_SYCL_TARGET STREQUAL "NVIDIA")
167
+ target_link_libraries(ggml-sycl PRIVATE ONEMATH::onemath_blas_cublas)
168
+ target_compile_options(ggml-sycl PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda")
169
+ target_link_options(ggml-sycl PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda")
170
+ target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_NVIDIA)
98
171
  elseif (GGML_SYCL_TARGET STREQUAL "AMD")
99
172
  if (NOT GGML_SYCL_DEVICE_ARCH)
100
173
  message(ERROR "Can't enable SYCL hip backend, GGML_SYCL_DEVICE_ARCH has not been set.")
101
174
  endif()
102
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=amdgcn-amd-amdhsa")
103
- target_link_libraries(ggml-sycl PRIVATE sycl pthread m dl onemkl)
175
+ target_link_libraries(ggml-sycl PRIVATE ONEMATH::onemath_blas_rocblas)
176
+ target_compile_options(ggml-sycl PRIVATE "-fsycl-targets=amdgcn-amd-amdhsa")
177
+ target_link_options(ggml-sycl PRIVATE "-fsycl-targets=amdgcn-amd-amdhsa")
178
+ target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_AMD)
179
+ else()
180
+ # Fallback to oneMath runtime dispatcher
181
+ target_link_libraries(ggml-sycl PRIVATE ONEMATH::onemath)
182
+ target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_GENERIC)
104
183
  endif()
184
+ endif()
105
185
 
106
- if (GGML_SYCL_DEVICE_ARCH)
107
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xsycl-target-backend --offload-arch=${GGML_SYCL_DEVICE_ARCH}")
108
- endif()
186
+ if (GGML_SYCL_DEVICE_ARCH)
187
+ target_compile_options(ggml-sycl PRIVATE -Xsycl-target-backend --offload-arch=${GGML_SYCL_DEVICE_ARCH})
188
+ target_link_options(ggml-sycl PRIVATE -Xsycl-target-backend --offload-arch=${GGML_SYCL_DEVICE_ARCH})
109
189
  endif()
@@ -13,23 +13,25 @@
13
13
  #ifndef GGML_SYCL_BACKEND_HPP
14
14
  #define GGML_SYCL_BACKEND_HPP
15
15
 
16
- #include "concat.hpp"
16
+ #include "binbcast.hpp"
17
17
  #include "common.hpp"
18
+ #include "concat.hpp"
18
19
  #include "conv.hpp"
19
20
  #include "convert.hpp"
21
+ #include "cpy.hpp"
20
22
  #include "dequantize.hpp"
21
23
  #include "dmmv.hpp"
24
+ #include "element_wise.hpp"
25
+ #include "gla.hpp"
26
+ #include "im2col.hpp"
22
27
  #include "mmq.hpp"
23
28
  #include "mmvq.hpp"
24
- #include "rope.hpp"
25
29
  #include "norm.hpp"
30
+ #include "outprod.hpp"
31
+ #include "quants.hpp"
32
+ #include "rope.hpp"
26
33
  #include "softmax.hpp"
27
34
  #include "tsembd.hpp"
28
- #include "im2col.hpp"
29
35
  #include "wkv.hpp"
30
- #include "outprod.hpp"
31
- #include "element_wise.hpp"
32
- #include "cpy.hpp"
33
- #include "gla.hpp"
34
36
 
35
- #endif // GGML_SYCL_BACKEND_HPP
37
+ #endif // GGML_SYCL_BACKEND_HPP
@@ -0,0 +1,239 @@
1
+ #include "binbcast.hpp"
2
+
3
+ #include <array>
4
+ #include <cstddef>
5
+ #include <cstdint>
6
+ #include <sycl/sycl.hpp>
7
+
8
+ #include "dpct/helper.hpp"
9
+ #include "ggml.h"
10
+
11
+ template <float (*bin_op)(const float, const float), typename src0_t, typename src1_t, typename dst_t>
12
+ static __dpct_inline__ void k_bin_bcast_contiguous(const src0_t * __restrict__ src0, const src1_t * __restrict__ src1,
13
+ dst_t * dst, std::size_t num_elements, const sycl::nd_item<1> & it) {
14
+ auto element_id = it.get_global_id(0);
15
+ auto global_range = it.get_global_range(0);
16
+ for (; element_id < num_elements; element_id += global_range) {
17
+ auto src0_float_val = sycl::vec(src0[element_id]).template convert<float, sycl::rounding_mode::rte>();
18
+ auto src1_float_val = sycl::vec(src1[element_id]).template convert<float, sycl::rounding_mode::rte>();
19
+ float dst_val = bin_op(src0_float_val[0], src1_float_val[0]);
20
+ auto val_to_store = sycl::vec(dst_val).template convert<dst_t, sycl::rounding_mode::rte>();
21
+ dst[element_id] = val_to_store;
22
+ }
23
+ }
24
+
25
+ template <float (*bin_op)(const float, const float), typename src0_t, typename src1_t, typename dst_t>
26
+ static __dpct_inline__ void k_bin_bcast(const src0_t * __restrict__ src0, const src1_t * __restrict__ src1, dst_t * dst,
27
+ int ne0, int ne1, int ne2, int ne3, int ne10, int ne11, int ne12, int ne13,
28
+ int s0, int s1, int s2, int s3, int s00, int s01, int s02, int s03, int s10,
29
+ int s11, int s12, int s13, std::size_t num_dst_elements,
30
+ const sycl::nd_item<1> & item_ct1) {
31
+ auto calculate_logical_index =
32
+ [](const std::array<int, 4> & dims, std::size_t element_id) __attribute__((always_inline))->std::array<int, 4> {
33
+ std::array<int, 4> logical_index;
34
+ #pragma unroll(4)
35
+ for (int i = 3; i >= 0; i--) {
36
+ logical_index[i] = element_id % dims[i];
37
+ element_id /= dims[i];
38
+ }
39
+ return logical_index;
40
+ };
41
+
42
+ auto calculate_index = [](const std::array<int, 4> & dims, const std::array<int, 4> & strides,
43
+ const std::array<int, 4> & indices) __attribute__((always_inline))
44
+ ->std::size_t {
45
+ std::size_t index = 0;
46
+ #pragma unroll(4)
47
+ for (int i = 0; i < 4; i++) {
48
+ auto index_i = indices[i];
49
+ if (indices[i] >= dims[i]) {
50
+ index_i = indices[i] % dims[i];
51
+ }
52
+ index += strides[i] * index_i;
53
+ }
54
+ return index;
55
+ };
56
+
57
+ auto element_id = item_ct1.get_global_id(0);
58
+ for (; element_id < num_dst_elements; element_id += item_ct1.get_global_range(0)) {
59
+ auto logical_index = calculate_logical_index({ ne3, ne2, ne1, ne0 }, element_id);
60
+ auto src_0_index = calculate_index({ ne3, ne2, ne1, ne0 }, { s03, s02, s01, s00 }, logical_index);
61
+ auto src_1_index = calculate_index({ ne13, ne12, ne11, ne10 }, { s13, s12, s11, s10 }, logical_index);
62
+ auto dst_index = calculate_index({ ne3, ne2, ne1, ne0 }, { s3, s2, s1, s0 }, logical_index);
63
+ auto src0_float_val = sycl::vec(src0[src_0_index]).template convert<float, sycl::rounding_mode::rte>();
64
+ auto src1_float_val = sycl::vec(src1[src_1_index]).template convert<float, sycl::rounding_mode::rte>();
65
+ float dst_val = bin_op(src0_float_val[0], src1_float_val[0]);
66
+ auto val_to_store = sycl::vec(dst_val).template convert<dst_t, sycl::rounding_mode::rte>();
67
+ dst[dst_index] = val_to_store;
68
+ }
69
+ }
70
+
71
+ template <float (*bin_op)(const float, const float)> struct bin_bcast_sycl {
72
+ template <typename src0_t, typename src1_t, typename dst_t>
73
+ void operator()(const src0_t * src0_dd, const src1_t * src1_dd, dst_t * dst_dd, const int64_t ne00,
74
+ const int64_t ne01, const int64_t ne02, const int64_t ne03, const int64_t ne10, const int64_t ne11,
75
+ const int64_t ne12, const int64_t ne13, const int64_t ne0, const int64_t ne1, const int64_t ne2,
76
+ const int64_t ne3, const size_t nb00, const size_t nb01, const size_t nb02, const size_t nb03,
77
+ const size_t nb10, const size_t nb11, const size_t nb12, const size_t nb13, const size_t nb0,
78
+ const size_t nb1, const size_t nb2, const size_t nb3, const bool src0_is_contiguous,
79
+ const bool src1_is_contiguous, const bool dst_is_contiguous, queue_ptr stream) {
80
+ auto check_bcast_required = [](const std::array<int64_t, 4> & src_dims,
81
+ const std::array<int64_t, 4> & dst_dims) -> bool {
82
+ for (int i = 0; i < 4; i++) {
83
+ if (dst_dims[i] > src_dims[i]) {
84
+ return true;
85
+ }
86
+ }
87
+ return false;
88
+ };
89
+
90
+ dpct::has_capability_or_fail(stream->get_device(), { sycl::aspect::fp16 });
91
+
92
+ GGML_ASSERT(nb0 % sizeof(dst_t) == 0);
93
+ GGML_ASSERT(nb1 % sizeof(dst_t) == 0);
94
+ GGML_ASSERT(nb2 % sizeof(dst_t) == 0);
95
+ GGML_ASSERT(nb3 % sizeof(dst_t) == 0);
96
+
97
+ GGML_ASSERT(nb00 % sizeof(src0_t) == 0);
98
+ GGML_ASSERT(nb01 % sizeof(src0_t) == 0);
99
+ GGML_ASSERT(nb02 % sizeof(src0_t) == 0);
100
+ GGML_ASSERT(nb03 % sizeof(src0_t) == 0);
101
+
102
+ GGML_ASSERT(nb10 % sizeof(src1_t) == 0);
103
+ GGML_ASSERT(nb11 % sizeof(src1_t) == 0);
104
+ GGML_ASSERT(nb12 % sizeof(src1_t) == 0);
105
+ GGML_ASSERT(nb13 % sizeof(src1_t) == 0);
106
+
107
+ // dst strides in number of elements
108
+ size_t s0 = nb0 / sizeof(dst_t);
109
+ size_t s1 = nb1 / sizeof(dst_t);
110
+ size_t s2 = nb2 / sizeof(dst_t);
111
+ size_t s3 = nb3 / sizeof(dst_t);
112
+
113
+ // src1 strides in number of elements
114
+ size_t s10 = nb10 / sizeof(src0_t);
115
+ size_t s11 = nb11 / sizeof(src1_t);
116
+ size_t s12 = nb12 / sizeof(src1_t);
117
+ size_t s13 = nb13 / sizeof(src1_t);
118
+
119
+ // src0 strides in number of elements
120
+ size_t s00 = nb00 / sizeof(src0_t);
121
+ size_t s01 = nb01 / sizeof(src0_t);
122
+ size_t s02 = nb02 / sizeof(src0_t);
123
+ size_t s03 = nb03 / sizeof(src0_t);
124
+
125
+ std::size_t num_dst_elements = static_cast<std::size_t>(ne0) * static_cast<std::size_t>(ne1) *
126
+ static_cast<std::size_t>(ne2) * static_cast<std::size_t>(ne3);
127
+ std::size_t local_range = 256;
128
+ std::size_t global_range = ceil_div(num_dst_elements, local_range) * local_range;
129
+
130
+ bool needs_broadcasting = check_bcast_required({ ne00, ne01, ne02, ne03 }, { ne0, ne1, ne2, ne3 }) ||
131
+ check_bcast_required({ ne10, ne11, ne12, ne13 }, { ne0, ne1, ne2, ne3 });
132
+ bool all_contiguous = src0_is_contiguous && src1_is_contiguous && dst_is_contiguous;
133
+
134
+ if (! needs_broadcasting && all_contiguous) {
135
+ stream->submit([&](sycl::handler & cgh) {
136
+ cgh.parallel_for(sycl::nd_range<1>({ global_range }, { local_range }), [=](sycl::nd_item<1> it) {
137
+ k_bin_bcast_contiguous<bin_op>(src0_dd, src1_dd, dst_dd, num_dst_elements, it);
138
+ });
139
+ });
140
+ } else {
141
+ stream->submit([&](sycl::handler & cgh) {
142
+ cgh.parallel_for(sycl::nd_range<1>({ global_range }, { local_range }), [=](sycl::nd_item<1> it) {
143
+ k_bin_bcast<bin_op>(src0_dd, src1_dd, dst_dd, ne0, ne1, ne2, ne3, ne10, ne11, ne12, ne13, s0, s1,
144
+ s2, s3, s00, s01, s02, s03, s10, s11, s12, s13, num_dst_elements, it);
145
+ });
146
+ });
147
+ }
148
+ }
149
+ };
150
+
151
+ template <class op>
152
+ inline void ggml_sycl_op_bin_bcast(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1,
153
+ ggml_tensor * dst) {
154
+ dpct::queue_ptr main_stream = ctx.stream();
155
+ GGML_TENSOR_BINARY_OP_LOCALS
156
+
157
+ if (src0->type == GGML_TYPE_F32 && src1->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_F32) {
158
+ op()((const float *) src0->data, (const float *) src1->data, (float *) dst->data, ne00, ne01, ne02, ne03, ne10,
159
+ ne11, ne12, ne13, ne0, ne1, ne2, ne3, nb00, nb01, nb02, nb03, nb10, nb11, nb12, nb13, nb0, nb1, nb2, nb3,
160
+ ggml_is_contiguous(src0), ggml_is_contiguous(src1), ggml_is_contiguous(dst), main_stream);
161
+ } else if (src0->type == GGML_TYPE_F16 && src1->type == GGML_TYPE_F16 && dst->type == GGML_TYPE_F16) {
162
+ op()((const sycl::half *) src0->data, (const sycl::half *) src1->data, (sycl::half *) dst->data, ne00, ne01,
163
+ ne02, ne03, ne10, ne11, ne12, ne13, ne0, ne1, ne2, ne3, nb00, nb01, nb02, nb03, nb10, nb11, nb12, nb13,
164
+ nb0, nb1, nb2, nb3, ggml_is_contiguous(src0), ggml_is_contiguous(src1), ggml_is_contiguous(dst),
165
+ main_stream);
166
+ } else if (src0->type == GGML_TYPE_F16 && src1->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_F16) {
167
+ op()((const sycl::half *) src0->data, (const float *) src1->data, (sycl::half *) dst->data, ne00, ne01, ne02,
168
+ ne03, ne10, ne11, ne12, ne13, ne0, ne1, ne2, ne3, nb00, nb01, nb02, nb03, nb10, nb11, nb12, nb13, nb0, nb1,
169
+ nb2, nb3, ggml_is_contiguous(src0), ggml_is_contiguous(src1), ggml_is_contiguous(dst), main_stream);
170
+ } else if (src0->type == GGML_TYPE_I32 && src1->type == GGML_TYPE_I32 && dst->type == GGML_TYPE_I32) {
171
+ op()((const int32_t *) src0->data, (const int32_t *) src1->data, (int32_t *) dst->data, ne00, ne01, ne02, ne03,
172
+ ne10, ne11, ne12, ne13, ne0, ne1, ne2, ne3, nb00, nb01, nb02, nb03, nb10, nb11, nb12, nb13, nb0, nb1, nb2,
173
+ nb3, ggml_is_contiguous(src0), ggml_is_contiguous(src1), ggml_is_contiguous(dst), main_stream);
174
+ } else if (src0->type == GGML_TYPE_I16 && src1->type == GGML_TYPE_I16 && dst->type == GGML_TYPE_I16) {
175
+ op()((const int16_t *) src0->data, (const int16_t *) src1->data, (int16_t *) dst->data, ne00, ne01, ne02, ne03,
176
+ ne10, ne11, ne12, ne13, ne0, ne1, ne2, ne3, nb00, nb01, nb02, nb03, nb10, nb11, nb12, nb13, nb0, nb1, nb2,
177
+ nb3, ggml_is_contiguous(src0), ggml_is_contiguous(src1), ggml_is_contiguous(dst), main_stream);
178
+ } else {
179
+ fprintf(stderr, "%s: unsupported types: dst: %s, src0: %s, src1: %s\n", __func__, ggml_type_name(dst->type),
180
+ ggml_type_name(src0->type), ggml_type_name(src1->type));
181
+ GGML_ABORT("fatal error");
182
+ }
183
+ }
184
+
185
+ inline void ggml_sycl_op_add(ggml_backend_sycl_context & ctx, ggml_tensor *dst) {
186
+
187
+ ggml_sycl_op_bin_bcast<bin_bcast_sycl<op_add>>(ctx, dst->src[0], dst->src[1], dst);
188
+ }
189
+
190
+ inline void ggml_sycl_op_sub(ggml_backend_sycl_context & ctx, ggml_tensor *dst) {
191
+
192
+ ggml_sycl_op_bin_bcast<bin_bcast_sycl<op_sub>>(ctx, dst->src[0], dst->src[1], dst);
193
+ }
194
+
195
+ inline void ggml_sycl_op_mul(ggml_backend_sycl_context & ctx, ggml_tensor *dst) {
196
+
197
+ ggml_sycl_op_bin_bcast<bin_bcast_sycl<op_mul>>(ctx, dst->src[0], dst->src[1], dst);
198
+ }
199
+
200
+ inline void ggml_sycl_op_div(ggml_backend_sycl_context & ctx, ggml_tensor *dst) {
201
+
202
+ ggml_sycl_op_bin_bcast<bin_bcast_sycl<op_div>>(ctx, dst->src[0], dst->src[1], dst);
203
+ }
204
+
205
+ inline void ggml_sycl_op_repeat(ggml_backend_sycl_context & ctx, ggml_tensor *dst) {
206
+ ggml_sycl_op_bin_bcast<bin_bcast_sycl<op_repeat>>(ctx, dst, dst->src[0], dst);
207
+ }
208
+
209
+
210
+ void ggml_sycl_add(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
211
+ GGML_SYCL_DEBUG("call %s\n", __func__);
212
+ ggml_sycl_op_add(ctx, dst);
213
+ GGML_SYCL_DEBUG("call %s done\n", __func__);
214
+ }
215
+
216
+ void ggml_sycl_sub(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
217
+ GGML_SYCL_DEBUG("call %s\n", __func__);
218
+ ggml_sycl_op_sub(ctx, dst);
219
+ GGML_SYCL_DEBUG("call %s done\n", __func__);
220
+ }
221
+
222
+ void ggml_sycl_mul(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
223
+ GGML_SYCL_DEBUG("call %s\n", __func__);
224
+ ggml_sycl_op_mul(ctx, dst);
225
+ GGML_SYCL_DEBUG("call %s done\n", __func__);
226
+ }
227
+
228
+ void ggml_sycl_div(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
229
+ GGML_SYCL_DEBUG("call %s\n", __func__);
230
+ ggml_sycl_op_div(ctx, dst);
231
+ GGML_SYCL_DEBUG("call %s done\n", __func__);
232
+ }
233
+
234
+ void ggml_sycl_repeat(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
235
+ GGML_SYCL_DEBUG("call %s\n", __func__);
236
+ ggml_sycl_op_repeat(ctx, dst);
237
+ GGML_SYCL_DEBUG("call %s done\n", __func__);
238
+ }
239
+
@@ -0,0 +1,39 @@
1
+ #ifndef GGML_SYCL_BINBCAST_HPP
2
+ #define GGML_SYCL_BINBCAST_HPP
3
+ #include "common.hpp"
4
+
5
+
6
+ static __dpct_inline__ float op_repeat(const float a, const float b) {
7
+ return b;
8
+ GGML_UNUSED(a);
9
+ }
10
+
11
+ static __dpct_inline__ float op_add(const float a, const float b) {
12
+ return a + b;
13
+ }
14
+
15
+ static __dpct_inline__ float op_sub(const float a, const float b) {
16
+ return a - b;
17
+ }
18
+
19
+ static __dpct_inline__ float op_mul(const float a, const float b) {
20
+ return a * b;
21
+ }
22
+
23
+ static __dpct_inline__ float op_div(const float a, const float b) {
24
+ return a / b;
25
+ }
26
+
27
+ void ggml_sycl_add(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
28
+
29
+ void ggml_sycl_sub(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
30
+
31
+ void ggml_sycl_mul(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
32
+
33
+ void ggml_sycl_div(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
34
+
35
+ void ggml_sycl_repeat(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
36
+
37
+
38
+ #endif //GGML_SYCL_BINBCAST_HPP
39
+
@@ -66,41 +66,6 @@ int64_t downsample_sycl_global_range(int64_t accumulate_block_num, int64_t block
66
66
  return sycl_down_blk_size;
67
67
  }
68
68
 
69
- void ggml_sycl_op_flatten(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
70
- const ggml_tensor *src1, ggml_tensor *dst,
71
- const ggml_sycl_op_flatten_t op) try {
72
-
73
- const bool use_src1 = src1 != nullptr;
74
- if(use_src1)
75
- GGML_ASSERT(strcmp(src1->buffer->buft->iface.get_name(src1->buffer->buft), GGML_SYCL_NAME "_Split") != 0);
76
- GGML_ASSERT(strcmp(dst->buffer->buft->iface.get_name(dst->buffer->buft), GGML_SYCL_NAME "_Split") != 0);
77
-
78
- // dd = data device
79
- float * src0_ddf = (float *) src0->data;
80
- float * src1_ddf = use_src1 ? (float *) src1->data : nullptr;
81
- float * dst_ddf = (float *) dst->data;
82
-
83
- ggml_sycl_pool_alloc<float> src0_f(ctx.pool());
84
- ggml_sycl_pool_alloc<float> src1_f(ctx.pool());
85
- ggml_sycl_pool_alloc<float> dst_f(ctx.pool());
86
-
87
- ggml_sycl_set_device(ctx.device);
88
- queue_ptr main_stream = ctx.stream();
89
- // GGML_SYCL_DEBUG("ctx.device=%d, main_stream=%p src0_on_device=%d, src1_on_device=%d, dst_on_device=%d\n",
90
- // ctx.device, main_stream, src0_on_device, src1_on_device, dst_on_device);
91
-
92
- // do the computation
93
- op(ctx, src0, src1, dst, src0_ddf, src1_ddf, dst_ddf, main_stream);
94
- // print_ggml_tensor("tensor", dst);
95
- }
96
- catch (sycl::exception const &exc) {
97
-
98
- std::cerr << exc.what() << "Exception caught at file:" << __FILE__
99
- << ", line:" << __LINE__ << std::endl;
100
- std::exit(1);
101
- }
102
-
103
-
104
69
  void release_extra_gpu(ggml_tensor_extra_gpu * extra, std::vector<queue_ptr> streams) {
105
70
  for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
106
71
  for (int64_t is = 0; is < GGML_SYCL_MAX_STREAMS; ++is) {