@fugood/llama.node 0.6.3 → 1.0.0-beta.2

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 (377) hide show
  1. package/CMakeLists.txt +40 -30
  2. package/README.md +4 -1
  3. package/lib/binding.js +41 -29
  4. package/lib/binding.ts +26 -25
  5. package/package.json +40 -7
  6. package/scripts/build.js +47 -0
  7. package/scripts/llama.cpp.patch +109 -0
  8. package/src/anyascii.c +22223 -0
  9. package/src/anyascii.h +42 -0
  10. package/src/tts_utils.cpp +20 -7
  11. package/src/tts_utils.h +2 -0
  12. package/bin/darwin/arm64/llama-node.node +0 -0
  13. package/bin/darwin/x64/llama-node.node +0 -0
  14. package/bin/linux/arm64/llama-node.node +0 -0
  15. package/bin/linux/x64/llama-node.node +0 -0
  16. package/bin/linux-cuda/arm64/llama-node.node +0 -0
  17. package/bin/linux-cuda/x64/llama-node.node +0 -0
  18. package/bin/linux-vulkan/arm64/llama-node.node +0 -0
  19. package/bin/linux-vulkan/x64/llama-node.node +0 -0
  20. package/bin/win32/x64/llama-node.node +0 -0
  21. package/bin/win32/x64/node.lib +0 -0
  22. package/bin/win32-vulkan/arm64/llama-node.node +0 -0
  23. package/bin/win32-vulkan/arm64/node.lib +0 -0
  24. package/bin/win32-vulkan/x64/llama-node.node +0 -0
  25. package/bin/win32-vulkan/x64/node.lib +0 -0
  26. package/src/llama.cpp/.github/workflows/build-linux-cross.yml +0 -233
  27. package/src/llama.cpp/.github/workflows/build.yml +0 -1078
  28. package/src/llama.cpp/.github/workflows/close-issue.yml +0 -28
  29. package/src/llama.cpp/.github/workflows/docker.yml +0 -178
  30. package/src/llama.cpp/.github/workflows/editorconfig.yml +0 -29
  31. package/src/llama.cpp/.github/workflows/gguf-publish.yml +0 -44
  32. package/src/llama.cpp/.github/workflows/labeler.yml +0 -17
  33. package/src/llama.cpp/.github/workflows/python-check-requirements.yml +0 -33
  34. package/src/llama.cpp/.github/workflows/python-lint.yml +0 -30
  35. package/src/llama.cpp/.github/workflows/python-type-check.yml +0 -40
  36. package/src/llama.cpp/.github/workflows/release.yml +0 -739
  37. package/src/llama.cpp/.github/workflows/server.yml +0 -237
  38. package/src/llama.cpp/.github/workflows/winget.yml +0 -42
  39. package/src/llama.cpp/cmake/arm64-apple-clang.cmake +0 -16
  40. package/src/llama.cpp/cmake/arm64-windows-llvm.cmake +0 -16
  41. package/src/llama.cpp/cmake/build-info.cmake +0 -64
  42. package/src/llama.cpp/cmake/common.cmake +0 -35
  43. package/src/llama.cpp/cmake/git-vars.cmake +0 -22
  44. package/src/llama.cpp/cmake/x64-windows-llvm.cmake +0 -5
  45. package/src/llama.cpp/common/build-info.cpp.in +0 -4
  46. package/src/llama.cpp/docs/build.md +0 -561
  47. package/src/llama.cpp/examples/CMakeLists.txt +0 -43
  48. package/src/llama.cpp/examples/batched/CMakeLists.txt +0 -5
  49. package/src/llama.cpp/examples/batched/batched.cpp +0 -246
  50. package/src/llama.cpp/examples/chat-13B.bat +0 -57
  51. package/src/llama.cpp/examples/convert-llama2c-to-ggml/CMakeLists.txt +0 -5
  52. package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +0 -941
  53. package/src/llama.cpp/examples/deprecation-warning/deprecation-warning.cpp +0 -35
  54. package/src/llama.cpp/examples/embedding/CMakeLists.txt +0 -5
  55. package/src/llama.cpp/examples/embedding/embedding.cpp +0 -323
  56. package/src/llama.cpp/examples/eval-callback/CMakeLists.txt +0 -10
  57. package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +0 -194
  58. package/src/llama.cpp/examples/gen-docs/CMakeLists.txt +0 -5
  59. package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +0 -83
  60. package/src/llama.cpp/examples/gguf/CMakeLists.txt +0 -5
  61. package/src/llama.cpp/examples/gguf/gguf.cpp +0 -265
  62. package/src/llama.cpp/examples/gguf-hash/CMakeLists.txt +0 -22
  63. package/src/llama.cpp/examples/gguf-hash/deps/rotate-bits/rotate-bits.h +0 -46
  64. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.c +0 -295
  65. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.h +0 -52
  66. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.c +0 -221
  67. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.h +0 -24
  68. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.c +0 -42
  69. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.h +0 -7093
  70. package/src/llama.cpp/examples/gguf-hash/gguf-hash.cpp +0 -694
  71. package/src/llama.cpp/examples/gritlm/CMakeLists.txt +0 -5
  72. package/src/llama.cpp/examples/gritlm/gritlm.cpp +0 -229
  73. package/src/llama.cpp/examples/jeopardy/questions.txt +0 -100
  74. package/src/llama.cpp/examples/llama.android/app/build.gradle.kts +0 -65
  75. package/src/llama.cpp/examples/llama.android/build.gradle.kts +0 -6
  76. package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +0 -71
  77. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/CMakeLists.txt +0 -53
  78. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +0 -452
  79. package/src/llama.cpp/examples/llama.android/settings.gradle.kts +0 -18
  80. package/src/llama.cpp/examples/lookahead/CMakeLists.txt +0 -5
  81. package/src/llama.cpp/examples/lookahead/lookahead.cpp +0 -472
  82. package/src/llama.cpp/examples/lookup/CMakeLists.txt +0 -23
  83. package/src/llama.cpp/examples/lookup/lookup-create.cpp +0 -40
  84. package/src/llama.cpp/examples/lookup/lookup-merge.cpp +0 -47
  85. package/src/llama.cpp/examples/lookup/lookup-stats.cpp +0 -157
  86. package/src/llama.cpp/examples/lookup/lookup.cpp +0 -242
  87. package/src/llama.cpp/examples/parallel/CMakeLists.txt +0 -5
  88. package/src/llama.cpp/examples/parallel/parallel.cpp +0 -492
  89. package/src/llama.cpp/examples/passkey/CMakeLists.txt +0 -5
  90. package/src/llama.cpp/examples/passkey/passkey.cpp +0 -277
  91. package/src/llama.cpp/examples/retrieval/CMakeLists.txt +0 -5
  92. package/src/llama.cpp/examples/retrieval/retrieval.cpp +0 -304
  93. package/src/llama.cpp/examples/save-load-state/CMakeLists.txt +0 -5
  94. package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +0 -246
  95. package/src/llama.cpp/examples/simple/CMakeLists.txt +0 -5
  96. package/src/llama.cpp/examples/simple/simple.cpp +0 -206
  97. package/src/llama.cpp/examples/simple-chat/CMakeLists.txt +0 -5
  98. package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +0 -206
  99. package/src/llama.cpp/examples/simple-cmake-pkg/CMakeLists.txt +0 -11
  100. package/src/llama.cpp/examples/speculative/CMakeLists.txt +0 -5
  101. package/src/llama.cpp/examples/speculative/speculative.cpp +0 -644
  102. package/src/llama.cpp/examples/speculative-simple/CMakeLists.txt +0 -5
  103. package/src/llama.cpp/examples/speculative-simple/speculative-simple.cpp +0 -261
  104. package/src/llama.cpp/examples/sycl/CMakeLists.txt +0 -9
  105. package/src/llama.cpp/examples/sycl/build.sh +0 -23
  106. package/src/llama.cpp/examples/sycl/ls-sycl-device.cpp +0 -13
  107. package/src/llama.cpp/examples/sycl/run-llama2.sh +0 -27
  108. package/src/llama.cpp/examples/sycl/run-llama3.sh +0 -28
  109. package/src/llama.cpp/examples/sycl/win-build-sycl.bat +0 -33
  110. package/src/llama.cpp/examples/sycl/win-run-llama2.bat +0 -9
  111. package/src/llama.cpp/examples/sycl/win-run-llama3.bat +0 -9
  112. package/src/llama.cpp/examples/training/CMakeLists.txt +0 -5
  113. package/src/llama.cpp/examples/training/finetune.cpp +0 -96
  114. package/src/llama.cpp/ggml/cmake/GitVars.cmake +0 -22
  115. package/src/llama.cpp/ggml/cmake/common.cmake +0 -26
  116. package/src/llama.cpp/ggml/src/ggml-alloc.c +0 -1042
  117. package/src/llama.cpp/ggml/src/ggml-backend-impl.h +0 -255
  118. package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +0 -586
  119. package/src/llama.cpp/ggml/src/ggml-backend.cpp +0 -2008
  120. package/src/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +0 -87
  121. package/src/llama.cpp/ggml/src/ggml-blas/ggml-blas.cpp +0 -517
  122. package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +0 -74
  123. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +0 -179
  124. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +0 -258
  125. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +0 -2863
  126. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +0 -1110
  127. package/src/llama.cpp/ggml/src/ggml-cann/common.h +0 -420
  128. package/src/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +0 -2570
  129. package/src/llama.cpp/ggml/src/ggml-common.h +0 -1857
  130. package/src/llama.cpp/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +0 -100
  131. package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +0 -184
  132. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +0 -15
  133. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +0 -243
  134. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +0 -140
  135. package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +0 -131
  136. package/src/llama.cpp/ggml/src/ggml-impl.h +0 -601
  137. package/src/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +0 -166
  138. package/src/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +0 -2251
  139. package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +0 -120
  140. package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +0 -622
  141. package/src/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +0 -113
  142. package/src/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +0 -96
  143. package/src/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +0 -5124
  144. package/src/llama.cpp/ggml/src/ggml-opt.cpp +0 -1037
  145. package/src/llama.cpp/ggml/src/ggml-quants.c +0 -5232
  146. package/src/llama.cpp/ggml/src/ggml-quants.h +0 -100
  147. package/src/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +0 -9
  148. package/src/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +0 -1813
  149. package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +0 -189
  150. package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +0 -37
  151. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +0 -239
  152. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.hpp +0 -39
  153. package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +0 -83
  154. package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +0 -493
  155. package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +0 -197
  156. package/src/llama.cpp/ggml/src/ggml-sycl/concat.hpp +0 -20
  157. package/src/llama.cpp/ggml/src/ggml-sycl/conv.cpp +0 -100
  158. package/src/llama.cpp/ggml/src/ggml-sycl/conv.hpp +0 -20
  159. package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +0 -623
  160. package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +0 -34
  161. package/src/llama.cpp/ggml/src/ggml-sycl/cpy.cpp +0 -701
  162. package/src/llama.cpp/ggml/src/ggml-sycl/cpy.hpp +0 -11
  163. package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +0 -791
  164. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +0 -1160
  165. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +0 -27
  166. package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +0 -2957
  167. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +0 -1536
  168. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +0 -75
  169. package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +0 -99
  170. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +0 -311
  171. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.hpp +0 -20
  172. package/src/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +0 -4443
  173. package/src/llama.cpp/ggml/src/ggml-sycl/gla.cpp +0 -105
  174. package/src/llama.cpp/ggml/src/ggml-sycl/gla.hpp +0 -8
  175. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +0 -136
  176. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +0 -21
  177. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +0 -3030
  178. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +0 -33
  179. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +0 -1108
  180. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +0 -27
  181. package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +0 -474
  182. package/src/llama.cpp/ggml/src/ggml-sycl/norm.hpp +0 -26
  183. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +0 -46
  184. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +0 -10
  185. package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +0 -74
  186. package/src/llama.cpp/ggml/src/ggml-sycl/quants.hpp +0 -83
  187. package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +0 -362
  188. package/src/llama.cpp/ggml/src/ggml-sycl/rope.hpp +0 -20
  189. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +0 -264
  190. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +0 -20
  191. package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.cpp +0 -13
  192. package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.hpp +0 -23
  193. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +0 -73
  194. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +0 -20
  195. package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +0 -1215
  196. package/src/llama.cpp/ggml/src/ggml-sycl/wkv.cpp +0 -305
  197. package/src/llama.cpp/ggml/src/ggml-sycl/wkv.hpp +0 -10
  198. package/src/llama.cpp/ggml/src/ggml-threading.cpp +0 -12
  199. package/src/llama.cpp/ggml/src/ggml-threading.h +0 -14
  200. package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +0 -196
  201. package/src/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +0 -10699
  202. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +0 -39
  203. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +0 -751
  204. package/src/llama.cpp/ggml/src/ggml.c +0 -6550
  205. package/src/llama.cpp/ggml/src/gguf.cpp +0 -1330
  206. package/src/llama.cpp/models/.editorconfig +0 -1
  207. package/src/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
  208. package/src/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
  209. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
  210. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +0 -112
  211. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +0 -46
  212. package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +0 -112
  213. package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.out +0 -46
  214. package/src/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
  215. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.inp +0 -112
  216. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.out +0 -46
  217. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
  218. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +0 -112
  219. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +0 -46
  220. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
  221. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +0 -112
  222. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +0 -46
  223. package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.inp +0 -112
  224. package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.out +0 -46
  225. package/src/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
  226. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.inp +0 -112
  227. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.out +0 -46
  228. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
  229. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +0 -112
  230. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +0 -46
  231. package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.inp +0 -112
  232. package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.out +0 -46
  233. package/src/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
  234. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
  235. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +0 -112
  236. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +0 -46
  237. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
  238. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +0 -112
  239. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +0 -46
  240. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.inp +0 -112
  241. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.out +0 -46
  242. package/src/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
  243. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.inp +0 -112
  244. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.out +0 -46
  245. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf +0 -0
  246. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.inp +0 -112
  247. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.out +0 -46
  248. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.inp +0 -112
  249. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.out +0 -46
  250. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
  251. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +0 -112
  252. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.out +0 -46
  253. package/src/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
  254. package/src/llama.cpp/models/ggml-vocab-refact.gguf.inp +0 -112
  255. package/src/llama.cpp/models/ggml-vocab-refact.gguf.out +0 -46
  256. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +0 -112
  257. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +0 -46
  258. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
  259. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +0 -112
  260. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.out +0 -46
  261. package/src/llama.cpp/pocs/CMakeLists.txt +0 -14
  262. package/src/llama.cpp/pocs/vdot/CMakeLists.txt +0 -9
  263. package/src/llama.cpp/pocs/vdot/q8dot.cpp +0 -173
  264. package/src/llama.cpp/pocs/vdot/vdot.cpp +0 -311
  265. package/src/llama.cpp/prompts/LLM-questions.txt +0 -49
  266. package/src/llama.cpp/prompts/alpaca.txt +0 -1
  267. package/src/llama.cpp/prompts/assistant.txt +0 -31
  268. package/src/llama.cpp/prompts/chat-with-baichuan.txt +0 -4
  269. package/src/llama.cpp/prompts/chat-with-bob.txt +0 -7
  270. package/src/llama.cpp/prompts/chat-with-qwen.txt +0 -1
  271. package/src/llama.cpp/prompts/chat-with-vicuna-v0.txt +0 -7
  272. package/src/llama.cpp/prompts/chat-with-vicuna-v1.txt +0 -7
  273. package/src/llama.cpp/prompts/chat.txt +0 -28
  274. package/src/llama.cpp/prompts/dan-modified.txt +0 -1
  275. package/src/llama.cpp/prompts/dan.txt +0 -1
  276. package/src/llama.cpp/prompts/mnemonics.txt +0 -93
  277. package/src/llama.cpp/prompts/parallel-questions.txt +0 -43
  278. package/src/llama.cpp/prompts/reason-act.txt +0 -18
  279. package/src/llama.cpp/requirements/requirements-all.txt +0 -15
  280. package/src/llama.cpp/requirements/requirements-compare-llama-bench.txt +0 -2
  281. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +0 -7
  282. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +0 -7
  283. package/src/llama.cpp/requirements/requirements-convert_legacy_llama.txt +0 -5
  284. package/src/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +0 -1
  285. package/src/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +0 -4
  286. package/src/llama.cpp/requirements/requirements-gguf_editor_gui.txt +0 -3
  287. package/src/llama.cpp/requirements/requirements-pydantic.txt +0 -3
  288. package/src/llama.cpp/requirements/requirements-test-tokenizer-random.txt +0 -1
  289. package/src/llama.cpp/requirements/requirements-tool_bench.txt +0 -12
  290. package/src/llama.cpp/requirements.txt +0 -13
  291. package/src/llama.cpp/scripts/build-info.sh +0 -30
  292. package/src/llama.cpp/scripts/install-oneapi.bat +0 -19
  293. package/src/llama.cpp/scripts/xxd.cmake +0 -16
  294. package/src/llama.cpp/tests/CMakeLists.txt +0 -177
  295. package/src/llama.cpp/tests/get-model.cpp +0 -21
  296. package/src/llama.cpp/tests/get-model.h +0 -2
  297. package/src/llama.cpp/tests/test-arg-parser.cpp +0 -178
  298. package/src/llama.cpp/tests/test-autorelease.cpp +0 -24
  299. package/src/llama.cpp/tests/test-backend-ops.cpp +0 -4793
  300. package/src/llama.cpp/tests/test-barrier.cpp +0 -94
  301. package/src/llama.cpp/tests/test-c.c +0 -7
  302. package/src/llama.cpp/tests/test-chat-template.cpp +0 -417
  303. package/src/llama.cpp/tests/test-chat.cpp +0 -985
  304. package/src/llama.cpp/tests/test-double-float.cpp +0 -57
  305. package/src/llama.cpp/tests/test-gbnf-validator.cpp +0 -109
  306. package/src/llama.cpp/tests/test-gguf.cpp +0 -1338
  307. package/src/llama.cpp/tests/test-grammar-integration.cpp +0 -1308
  308. package/src/llama.cpp/tests/test-grammar-llguidance.cpp +0 -1201
  309. package/src/llama.cpp/tests/test-grammar-parser.cpp +0 -519
  310. package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +0 -1304
  311. package/src/llama.cpp/tests/test-llama-grammar.cpp +0 -408
  312. package/src/llama.cpp/tests/test-log.cpp +0 -39
  313. package/src/llama.cpp/tests/test-model-load-cancel.cpp +0 -27
  314. package/src/llama.cpp/tests/test-mtmd-c-api.c +0 -63
  315. package/src/llama.cpp/tests/test-opt.cpp +0 -904
  316. package/src/llama.cpp/tests/test-quantize-fns.cpp +0 -186
  317. package/src/llama.cpp/tests/test-quantize-perf.cpp +0 -365
  318. package/src/llama.cpp/tests/test-quantize-stats.cpp +0 -424
  319. package/src/llama.cpp/tests/test-regex-partial.cpp +0 -288
  320. package/src/llama.cpp/tests/test-rope.cpp +0 -262
  321. package/src/llama.cpp/tests/test-sampling.cpp +0 -399
  322. package/src/llama.cpp/tests/test-tokenizer-0.cpp +0 -312
  323. package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +0 -155
  324. package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +0 -125
  325. package/src/llama.cpp/tools/CMakeLists.txt +0 -39
  326. package/src/llama.cpp/tools/batched-bench/CMakeLists.txt +0 -5
  327. package/src/llama.cpp/tools/batched-bench/batched-bench.cpp +0 -204
  328. package/src/llama.cpp/tools/cvector-generator/CMakeLists.txt +0 -5
  329. package/src/llama.cpp/tools/cvector-generator/completions.txt +0 -582
  330. package/src/llama.cpp/tools/cvector-generator/cvector-generator.cpp +0 -508
  331. package/src/llama.cpp/tools/cvector-generator/mean.hpp +0 -48
  332. package/src/llama.cpp/tools/cvector-generator/negative.txt +0 -4
  333. package/src/llama.cpp/tools/cvector-generator/pca.hpp +0 -315
  334. package/src/llama.cpp/tools/cvector-generator/positive.txt +0 -4
  335. package/src/llama.cpp/tools/export-lora/CMakeLists.txt +0 -5
  336. package/src/llama.cpp/tools/export-lora/export-lora.cpp +0 -434
  337. package/src/llama.cpp/tools/gguf-split/CMakeLists.txt +0 -5
  338. package/src/llama.cpp/tools/gguf-split/gguf-split.cpp +0 -583
  339. package/src/llama.cpp/tools/imatrix/CMakeLists.txt +0 -5
  340. package/src/llama.cpp/tools/imatrix/imatrix.cpp +0 -667
  341. package/src/llama.cpp/tools/llama-bench/CMakeLists.txt +0 -5
  342. package/src/llama.cpp/tools/llama-bench/llama-bench.cpp +0 -2024
  343. package/src/llama.cpp/tools/main/CMakeLists.txt +0 -5
  344. package/src/llama.cpp/tools/main/main.cpp +0 -977
  345. package/src/llama.cpp/tools/mtmd/CMakeLists.txt +0 -58
  346. package/src/llama.cpp/tools/mtmd/clip-impl.h +0 -462
  347. package/src/llama.cpp/tools/mtmd/clip.cpp +0 -4024
  348. package/src/llama.cpp/tools/mtmd/clip.h +0 -101
  349. package/src/llama.cpp/tools/mtmd/deprecation-warning.cpp +0 -22
  350. package/src/llama.cpp/tools/mtmd/miniaudio.h +0 -93468
  351. package/src/llama.cpp/tools/mtmd/mtmd-audio.cpp +0 -855
  352. package/src/llama.cpp/tools/mtmd/mtmd-audio.h +0 -62
  353. package/src/llama.cpp/tools/mtmd/mtmd-cli.cpp +0 -377
  354. package/src/llama.cpp/tools/mtmd/mtmd-helper.cpp +0 -297
  355. package/src/llama.cpp/tools/mtmd/mtmd.cpp +0 -942
  356. package/src/llama.cpp/tools/mtmd/mtmd.h +0 -362
  357. package/src/llama.cpp/tools/mtmd/requirements.txt +0 -5
  358. package/src/llama.cpp/tools/perplexity/CMakeLists.txt +0 -5
  359. package/src/llama.cpp/tools/perplexity/perplexity.cpp +0 -2063
  360. package/src/llama.cpp/tools/quantize/CMakeLists.txt +0 -6
  361. package/src/llama.cpp/tools/quantize/quantize.cpp +0 -519
  362. package/src/llama.cpp/tools/rpc/CMakeLists.txt +0 -4
  363. package/src/llama.cpp/tools/rpc/rpc-server.cpp +0 -322
  364. package/src/llama.cpp/tools/run/CMakeLists.txt +0 -16
  365. package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.cpp +0 -1995
  366. package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.h +0 -137
  367. package/src/llama.cpp/tools/run/run.cpp +0 -1261
  368. package/src/llama.cpp/tools/server/CMakeLists.txt +0 -51
  369. package/src/llama.cpp/tools/server/bench/requirements.txt +0 -2
  370. package/src/llama.cpp/tools/server/httplib.h +0 -10506
  371. package/src/llama.cpp/tools/server/server.cpp +0 -4966
  372. package/src/llama.cpp/tools/server/tests/requirements.txt +0 -8
  373. package/src/llama.cpp/tools/server/utils.hpp +0 -1337
  374. package/src/llama.cpp/tools/tokenize/CMakeLists.txt +0 -5
  375. package/src/llama.cpp/tools/tokenize/tokenize.cpp +0 -416
  376. package/src/llama.cpp/tools/tts/CMakeLists.txt +0 -5
  377. package/src/llama.cpp/tools/tts/tts.cpp +0 -1092
@@ -1,586 +0,0 @@
1
- #include "ggml-backend-impl.h"
2
- #include "ggml-backend.h"
3
- #include "ggml-impl.h"
4
- #include <algorithm>
5
- #include <cstring>
6
- #include <filesystem>
7
- #include <memory>
8
- #include <string>
9
- #include <type_traits>
10
- #include <vector>
11
- #include <cctype>
12
-
13
- #ifdef _WIN32
14
- # define WIN32_LEAN_AND_MEAN
15
- # ifndef NOMINMAX
16
- # define NOMINMAX
17
- # endif
18
- # include <windows.h>
19
- #elif defined(__APPLE__)
20
- # include <mach-o/dyld.h>
21
- # include <dlfcn.h>
22
- #else
23
- # include <dlfcn.h>
24
- # include <unistd.h>
25
- #endif
26
-
27
- // Backend registry
28
- #ifdef GGML_USE_CPU
29
- #include "ggml-cpu.h"
30
- #endif
31
-
32
- #ifdef GGML_USE_CUDA
33
- #include "ggml-cuda.h"
34
- #endif
35
-
36
- #ifdef GGML_USE_METAL
37
- #include "ggml-metal.h"
38
- #endif
39
-
40
- #ifdef GGML_USE_SYCL
41
- #include "ggml-sycl.h"
42
- #endif
43
-
44
- #ifdef GGML_USE_VULKAN
45
- #include "ggml-vulkan.h"
46
- #endif
47
-
48
- #ifdef GGML_USE_OPENCL
49
- #include "ggml-opencl.h"
50
- #endif
51
-
52
- #ifdef GGML_USE_BLAS
53
- #include "ggml-blas.h"
54
- #endif
55
-
56
- #ifdef GGML_USE_RPC
57
- #include "ggml-rpc.h"
58
- #endif
59
-
60
- #ifdef GGML_USE_CANN
61
- #include "ggml-cann.h"
62
- #endif
63
-
64
- #ifdef GGML_USE_KOMPUTE
65
- #include "ggml-kompute.h"
66
- #endif
67
-
68
- // disable C++17 deprecation warning for std::codecvt_utf8
69
- #if defined(__clang__)
70
- # pragma clang diagnostic push
71
- # pragma clang diagnostic ignored "-Wdeprecated-declarations"
72
- #endif
73
-
74
- namespace fs = std::filesystem;
75
-
76
- static std::string path_str(const fs::path & path) {
77
- std::string u8path;
78
- try {
79
- #if defined(__cpp_lib_char8_t)
80
- // C++20 and later: u8string() returns std::u8string
81
- std::u8string u8str = path.u8string();
82
- u8path = std::string(reinterpret_cast<const char*>(u8str.c_str()));
83
- #else
84
- // C++17: u8string() returns std::string
85
- u8path = path.u8string();
86
- #endif
87
- } catch (...) {
88
- }
89
- return u8path;
90
- }
91
-
92
- #if defined(__clang__)
93
- # pragma clang diagnostic pop
94
- #endif
95
-
96
- #ifdef _WIN32
97
-
98
- using dl_handle = std::remove_pointer_t<HMODULE>;
99
-
100
- struct dl_handle_deleter {
101
- void operator()(HMODULE handle) {
102
- FreeLibrary(handle);
103
- }
104
- };
105
-
106
- static dl_handle * dl_load_library(const fs::path & path) {
107
- // suppress error dialogs for missing DLLs
108
- DWORD old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
109
- SetErrorMode(old_mode | SEM_FAILCRITICALERRORS);
110
-
111
- HMODULE handle = LoadLibraryW(path.wstring().c_str());
112
-
113
- SetErrorMode(old_mode);
114
-
115
- return handle;
116
- }
117
-
118
- static void * dl_get_sym(dl_handle * handle, const char * name) {
119
- DWORD old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
120
- SetErrorMode(old_mode | SEM_FAILCRITICALERRORS);
121
-
122
- void * p = (void *) GetProcAddress(handle, name);
123
-
124
- SetErrorMode(old_mode);
125
-
126
- return p;
127
- }
128
-
129
- #else
130
-
131
- using dl_handle = void;
132
-
133
- struct dl_handle_deleter {
134
- void operator()(void * handle) {
135
- dlclose(handle);
136
- }
137
- };
138
-
139
- static void * dl_load_library(const fs::path & path) {
140
- dl_handle * handle = dlopen(path.string().c_str(), RTLD_NOW | RTLD_LOCAL);
141
-
142
- return handle;
143
- }
144
-
145
- static void * dl_get_sym(dl_handle * handle, const char * name) {
146
- return dlsym(handle, name);
147
- }
148
-
149
- #endif
150
-
151
- using dl_handle_ptr = std::unique_ptr<dl_handle, dl_handle_deleter>;
152
-
153
- struct ggml_backend_reg_entry {
154
- ggml_backend_reg_t reg;
155
- dl_handle_ptr handle;
156
- };
157
-
158
- struct ggml_backend_registry {
159
- std::vector<ggml_backend_reg_entry> backends;
160
- std::vector<ggml_backend_dev_t> devices;
161
-
162
- ggml_backend_registry() {
163
- #ifdef GGML_USE_CUDA
164
- register_backend(ggml_backend_cuda_reg());
165
- #endif
166
- #ifdef GGML_USE_METAL
167
- register_backend(ggml_backend_metal_reg());
168
- #endif
169
- #ifdef GGML_USE_SYCL
170
- register_backend(ggml_backend_sycl_reg());
171
- #endif
172
- #ifdef GGML_USE_VULKAN
173
- register_backend(ggml_backend_vk_reg());
174
- #endif
175
- #ifdef GGML_USE_OPENCL
176
- register_backend(ggml_backend_opencl_reg());
177
- #endif
178
- #ifdef GGML_USE_CANN
179
- register_backend(ggml_backend_cann_reg());
180
- #endif
181
- #ifdef GGML_USE_BLAS
182
- register_backend(ggml_backend_blas_reg());
183
- #endif
184
- #ifdef GGML_USE_RPC
185
- register_backend(ggml_backend_rpc_reg());
186
- #endif
187
- #ifdef GGML_USE_KOMPUTE
188
- register_backend(ggml_backend_kompute_reg());
189
- #endif
190
- #ifdef GGML_USE_CPU
191
- register_backend(ggml_backend_cpu_reg());
192
- #endif
193
- }
194
-
195
- ~ggml_backend_registry() {
196
- // FIXME: backends cannot be safely unloaded without a function to destroy all the backend resources,
197
- // since backend threads may still be running and accessing resources from the dynamic library
198
- for (auto & entry : backends) {
199
- if (entry.handle) {
200
- entry.handle.release(); // NOLINT
201
- }
202
- }
203
- }
204
-
205
- void register_backend(ggml_backend_reg_t reg, dl_handle_ptr handle = nullptr) {
206
- if (!reg) {
207
- return;
208
- }
209
-
210
- #ifndef NDEBUG
211
- GGML_LOG_DEBUG("%s: registered backend %s (%zu devices)\n",
212
- __func__, ggml_backend_reg_name(reg), ggml_backend_reg_dev_count(reg));
213
- #endif
214
- backends.push_back({ reg, std::move(handle) });
215
- for (size_t i = 0; i < ggml_backend_reg_dev_count(reg); i++) {
216
- register_device(ggml_backend_reg_dev_get(reg, i));
217
- }
218
- }
219
-
220
- void register_device(ggml_backend_dev_t device) {
221
- #ifndef NDEBUG
222
- GGML_LOG_DEBUG("%s: registered device %s (%s)\n", __func__, ggml_backend_dev_name(device), ggml_backend_dev_description(device));
223
- #endif
224
- devices.push_back(device);
225
- }
226
-
227
- ggml_backend_reg_t load_backend(const fs::path & path, bool silent) {
228
- dl_handle_ptr handle { dl_load_library(path) };
229
- if (!handle) {
230
- if (!silent) {
231
- GGML_LOG_ERROR("%s: failed to load %s\n", __func__, path_str(path).c_str());
232
- }
233
- return nullptr;
234
- }
235
-
236
- auto score_fn = (ggml_backend_score_t) dl_get_sym(handle.get(), "ggml_backend_score");
237
- if (score_fn && score_fn() == 0) {
238
- if (!silent) {
239
- GGML_LOG_INFO("%s: backend %s is not supported on this system\n", __func__, path_str(path).c_str());
240
- }
241
- return nullptr;
242
- }
243
-
244
- auto backend_init_fn = (ggml_backend_init_t) dl_get_sym(handle.get(), "ggml_backend_init");
245
- if (!backend_init_fn) {
246
- if (!silent) {
247
- GGML_LOG_ERROR("%s: failed to find ggml_backend_init in %s\n", __func__, path_str(path).c_str());
248
- }
249
- return nullptr;
250
- }
251
-
252
- ggml_backend_reg_t reg = backend_init_fn();
253
- if (!reg || reg->api_version != GGML_BACKEND_API_VERSION) {
254
- if (!silent) {
255
- if (!reg) {
256
- GGML_LOG_ERROR("%s: failed to initialize backend from %s: ggml_backend_init returned NULL\n",
257
- __func__, path_str(path).c_str());
258
- } else {
259
- GGML_LOG_ERROR("%s: failed to initialize backend from %s: incompatible API version (backend: %d, current: %d)\n",
260
- __func__, path_str(path).c_str(), reg->api_version, GGML_BACKEND_API_VERSION);
261
- }
262
- }
263
- return nullptr;
264
- }
265
-
266
- GGML_LOG_INFO("%s: loaded %s backend from %s\n", __func__, ggml_backend_reg_name(reg), path_str(path).c_str());
267
-
268
- register_backend(reg, std::move(handle));
269
-
270
- return reg;
271
- }
272
-
273
- void unload_backend(ggml_backend_reg_t reg, bool silent) {
274
- auto it = std::find_if(backends.begin(), backends.end(),
275
- [reg](const ggml_backend_reg_entry & entry) { return entry.reg == reg; });
276
-
277
- if (it == backends.end()) {
278
- if (!silent) {
279
- GGML_LOG_ERROR("%s: backend not found\n", __func__);
280
- }
281
- return;
282
- }
283
-
284
- if (!silent) {
285
- GGML_LOG_DEBUG("%s: unloading %s backend\n", __func__, ggml_backend_reg_name(reg));
286
- }
287
-
288
- // remove devices
289
- devices.erase(
290
- std::remove_if(devices.begin(), devices.end(),
291
- [reg](ggml_backend_dev_t dev) { return ggml_backend_dev_backend_reg(dev) == reg; }),
292
- devices.end());
293
-
294
- // remove backend
295
- backends.erase(it);
296
- }
297
- };
298
-
299
- static ggml_backend_registry & get_reg() {
300
- static ggml_backend_registry reg;
301
- return reg;
302
- }
303
-
304
- // Internal API
305
- void ggml_backend_register(ggml_backend_reg_t reg) {
306
- get_reg().register_backend(reg);
307
- }
308
-
309
- void ggml_backend_device_register(ggml_backend_dev_t device) {
310
- get_reg().register_device(device);
311
- }
312
-
313
- // Backend (reg) enumeration
314
- static bool striequals(const char * a, const char * b) {
315
- for (; *a && *b; a++, b++) {
316
- if (std::tolower(*a) != std::tolower(*b)) {
317
- return false;
318
- }
319
- }
320
- return *a == *b;
321
- }
322
-
323
- size_t ggml_backend_reg_count() {
324
- return get_reg().backends.size();
325
- }
326
-
327
- ggml_backend_reg_t ggml_backend_reg_get(size_t index) {
328
- GGML_ASSERT(index < ggml_backend_reg_count());
329
- return get_reg().backends[index].reg;
330
- }
331
-
332
- ggml_backend_reg_t ggml_backend_reg_by_name(const char * name) {
333
- for (size_t i = 0; i < ggml_backend_reg_count(); i++) {
334
- ggml_backend_reg_t reg = ggml_backend_reg_get(i);
335
- if (striequals(ggml_backend_reg_name(reg), name)) {
336
- return reg;
337
- }
338
- }
339
- return nullptr;
340
- }
341
-
342
- // Device enumeration
343
- size_t ggml_backend_dev_count() {
344
- return get_reg().devices.size();
345
- }
346
-
347
- ggml_backend_dev_t ggml_backend_dev_get(size_t index) {
348
- GGML_ASSERT(index < ggml_backend_dev_count());
349
- return get_reg().devices[index];
350
- }
351
-
352
- ggml_backend_dev_t ggml_backend_dev_by_name(const char * name) {
353
- for (size_t i = 0; i < ggml_backend_dev_count(); i++) {
354
- ggml_backend_dev_t dev = ggml_backend_dev_get(i);
355
- if (striequals(ggml_backend_dev_name(dev), name)) {
356
- return dev;
357
- }
358
- }
359
- return nullptr;
360
- }
361
-
362
- ggml_backend_dev_t ggml_backend_dev_by_type(enum ggml_backend_dev_type type) {
363
- for (size_t i = 0; i < ggml_backend_dev_count(); i++) {
364
- ggml_backend_dev_t dev = ggml_backend_dev_get(i);
365
- if (ggml_backend_dev_type(dev) == type) {
366
- return dev;
367
- }
368
- }
369
- return nullptr;
370
- }
371
-
372
- // Convenience functions
373
- ggml_backend_t ggml_backend_init_by_name(const char * name, const char * params) {
374
- ggml_backend_dev_t dev = ggml_backend_dev_by_name(name);
375
- if (!dev) {
376
- return nullptr;
377
- }
378
- return ggml_backend_dev_init(dev, params);
379
- }
380
-
381
- ggml_backend_t ggml_backend_init_by_type(enum ggml_backend_dev_type type, const char * params) {
382
- ggml_backend_dev_t dev = ggml_backend_dev_by_type(type);
383
- if (!dev) {
384
- return nullptr;
385
- }
386
- return ggml_backend_dev_init(dev, params);
387
- }
388
-
389
- ggml_backend_t ggml_backend_init_best(void) {
390
- ggml_backend_dev_t dev = ggml_backend_dev_by_type(GGML_BACKEND_DEVICE_TYPE_GPU);
391
- if (!dev) {
392
- dev = ggml_backend_dev_by_type(GGML_BACKEND_DEVICE_TYPE_CPU);
393
- }
394
- if (!dev) {
395
- return nullptr;
396
- }
397
- return ggml_backend_dev_init(dev, nullptr);
398
- }
399
-
400
- // Dynamic loading
401
- ggml_backend_reg_t ggml_backend_load(const char * path) {
402
- return get_reg().load_backend(path, false);
403
- }
404
-
405
- void ggml_backend_unload(ggml_backend_reg_t reg) {
406
- get_reg().unload_backend(reg, true);
407
- }
408
-
409
- static fs::path get_executable_path() {
410
- #if defined(__APPLE__)
411
- // get executable path
412
- std::vector<char> path;
413
- uint32_t size;
414
- while (true) {
415
- size = path.size();
416
- if (_NSGetExecutablePath(path.data(), &size) == 0) {
417
- break;
418
- }
419
- path.resize(size);
420
- }
421
- std::string base_path(path.data(), size);
422
- // remove executable name
423
- auto last_slash = base_path.find_last_of('/');
424
- if (last_slash != std::string::npos) {
425
- base_path = base_path.substr(0, last_slash);
426
- }
427
- return base_path + "/";
428
- #elif defined(__linux__) || defined(__FreeBSD__)
429
- std::string base_path = ".";
430
- std::vector<char> path(1024);
431
- while (true) {
432
- // get executable path
433
- # if defined(__linux__)
434
- ssize_t len = readlink("/proc/self/exe", path.data(), path.size());
435
- # elif defined(__FreeBSD__)
436
- ssize_t len = readlink("/proc/curproc/file", path.data(), path.size());
437
- # endif
438
- if (len == -1) {
439
- break;
440
- }
441
- if (len < (ssize_t) path.size()) {
442
- base_path = std::string(path.data(), len);
443
- // remove executable name
444
- auto last_slash = base_path.find_last_of('/');
445
- if (last_slash != std::string::npos) {
446
- base_path = base_path.substr(0, last_slash);
447
- }
448
- break;
449
- }
450
- path.resize(path.size() * 2);
451
- }
452
-
453
- return base_path + "/";
454
- #elif defined(_WIN32)
455
- std::vector<wchar_t> path(MAX_PATH);
456
- DWORD len = GetModuleFileNameW(NULL, path.data(), path.size());
457
- if (len == 0) {
458
- return {};
459
- }
460
- std::wstring base_path(path.data(), len);
461
- // remove executable name
462
- auto last_slash = base_path.find_last_of('\\');
463
- if (last_slash != std::string::npos) {
464
- base_path = base_path.substr(0, last_slash);
465
- }
466
- return base_path + L"\\";
467
- #else
468
- return {};
469
- #endif
470
- }
471
-
472
- static fs::path backend_filename_prefix() {
473
- #ifdef _WIN32
474
- return fs::u8path("ggml-");
475
- #else
476
- return fs::u8path("libggml-");
477
- #endif
478
- }
479
-
480
- static fs::path backend_filename_extension() {
481
- #ifdef _WIN32
482
- return fs::u8path(".dll");
483
- #else
484
- return fs::u8path(".so");
485
- #endif
486
- }
487
-
488
- static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent, const char * user_search_path) {
489
- // enumerate all the files that match [lib]ggml-name-*.[so|dll] in the search paths
490
- const fs::path name_path = fs::u8path(name);
491
- const fs::path file_prefix = backend_filename_prefix().native() + name_path.native() + fs::u8path("-").native();
492
- const fs::path file_extension = backend_filename_extension();
493
-
494
- std::vector<fs::path> search_paths;
495
- if (user_search_path == nullptr) {
496
- // default search paths: executable directory, current directory
497
- search_paths.push_back(get_executable_path());
498
- search_paths.push_back(fs::current_path());
499
- } else {
500
- search_paths.push_back(fs::u8path(user_search_path));
501
- }
502
-
503
- int best_score = 0;
504
- fs::path best_path;
505
-
506
- for (const auto & search_path : search_paths) {
507
- if (!fs::exists(search_path)) {
508
- GGML_LOG_DEBUG("%s: search path %s does not exist\n", __func__, path_str(search_path).c_str());
509
- continue;
510
- }
511
- fs::directory_iterator dir_it(search_path, fs::directory_options::skip_permission_denied);
512
- for (const auto & entry : dir_it) {
513
- if (entry.is_regular_file()) {
514
- auto filename = entry.path().filename();
515
- auto ext = entry.path().extension();
516
- if (filename.native().find(file_prefix) == 0 && ext == file_extension) {
517
- dl_handle_ptr handle { dl_load_library(entry) };
518
- if (!handle && !silent) {
519
- GGML_LOG_ERROR("%s: failed to load %s\n", __func__, path_str(entry.path()).c_str());
520
- }
521
- if (handle) {
522
- auto score_fn = (ggml_backend_score_t) dl_get_sym(handle.get(), "ggml_backend_score");
523
- if (score_fn) {
524
- int s = score_fn();
525
- #ifndef NDEBUG
526
- GGML_LOG_DEBUG("%s: %s score: %d\n", __func__, path_str(entry.path()).c_str(), s);
527
- #endif
528
- if (s > best_score) {
529
- best_score = s;
530
- best_path = entry.path();
531
- }
532
- } else {
533
- if (!silent) {
534
- GGML_LOG_INFO("%s: failed to find ggml_backend_score in %s\n", __func__, path_str(entry.path()).c_str());
535
- }
536
- }
537
- }
538
- }
539
- }
540
- }
541
- }
542
-
543
- if (best_score == 0) {
544
- // try to load the base backend
545
- for (const auto & search_path : search_paths) {
546
- fs::path filename = backend_filename_prefix().native() + name_path.native() + backend_filename_extension().native();
547
- fs::path path = search_path / filename;
548
- if (fs::exists(path)) {
549
- return get_reg().load_backend(path, silent);
550
- }
551
- }
552
- return nullptr;
553
- }
554
-
555
- return get_reg().load_backend(best_path, silent);
556
- }
557
-
558
- void ggml_backend_load_all() {
559
- ggml_backend_load_all_from_path(nullptr);
560
- }
561
-
562
- void ggml_backend_load_all_from_path(const char * dir_path) {
563
- #ifdef NDEBUG
564
- bool silent = true;
565
- #else
566
- bool silent = false;
567
- #endif
568
-
569
- ggml_backend_load_best("blas", silent, dir_path);
570
- ggml_backend_load_best("cann", silent, dir_path);
571
- ggml_backend_load_best("cuda", silent, dir_path);
572
- ggml_backend_load_best("hip", silent, dir_path);
573
- ggml_backend_load_best("kompute", silent, dir_path);
574
- ggml_backend_load_best("metal", silent, dir_path);
575
- ggml_backend_load_best("rpc", silent, dir_path);
576
- ggml_backend_load_best("sycl", silent, dir_path);
577
- ggml_backend_load_best("vulkan", silent, dir_path);
578
- ggml_backend_load_best("opencl", silent, dir_path);
579
- ggml_backend_load_best("musa", silent, dir_path);
580
- ggml_backend_load_best("cpu", silent, dir_path);
581
- // check the environment variable GGML_BACKEND_PATH to load an out-of-tree backend
582
- const char * backend_path = std::getenv("GGML_BACKEND_PATH");
583
- if (backend_path) {
584
- ggml_backend_load(backend_path);
585
- }
586
- }