cactus-react-native 0.0.1 → 0.1.1

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 (189) hide show
  1. package/LICENSE.txt +20 -0
  2. package/README.md +3 -1
  3. package/android/src/main/CMakeLists.txt +58 -23
  4. package/android/src/main/java/com/cactus/Cactus.java +484 -16
  5. package/android/src/main/java/com/cactus/LlamaContext.java +199 -0
  6. package/android/src/main/jni.cpp +325 -10
  7. package/android/src/main/jniLibs/arm64-v8a/libcactus.so +0 -0
  8. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8.so +0 -0
  9. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2.so +0 -0
  10. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod.so +0 -0
  11. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod_i8mm.so +0 -0
  12. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_i8mm.so +0 -0
  13. package/android/src/main/jniLibs/x86_64/libcactus.so +0 -0
  14. package/android/src/main/jniLibs/x86_64/libcactus_x86_64.so +0 -0
  15. package/android/src/newarch/java/com/cactus/CactusModule.java +79 -7
  16. package/android/src/oldarch/java/com/cactus/CactusModule.java +70 -0
  17. package/cactus-react-native.podspec +0 -3
  18. package/ios/CMakeLists.txt +58 -36
  19. package/ios/Cactus.mm +243 -2
  20. package/ios/CactusContext.h +22 -0
  21. package/ios/CactusContext.mm +176 -1
  22. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +92 -5
  23. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +268 -0
  24. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/chat.h +2 -0
  25. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/common.h +42 -51
  26. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend.h +4 -4
  27. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-common.h +12 -6
  28. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpp.h +1 -1
  29. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu.h +5 -0
  30. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-impl.h +52 -18
  31. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal-impl.h +106 -14
  32. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-opt.h +49 -28
  33. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml.h +87 -106
  34. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-arch.h +16 -0
  35. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-batch.h +2 -1
  36. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-chat.h +7 -2
  37. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-context.h +44 -33
  38. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cparams.h +1 -0
  39. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-graph.h +83 -17
  40. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-hparams.h +44 -2
  41. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-kv-cache.h +407 -179
  42. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-memory.h +13 -2
  43. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-loader.h +5 -3
  44. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-saver.h +37 -0
  45. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model.h +24 -2
  46. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-vocab.h +6 -0
  47. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama.h +102 -142
  48. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/chat-template.hpp +23 -11
  49. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/minja.hpp +186 -127
  50. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Info.plist +0 -0
  51. package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
  52. package/ios/cactus.xcframework/ios-arm64/cactus.framework/ggml-llama.metallib +0 -0
  53. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +92 -5
  54. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +268 -0
  55. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +2 -0
  56. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/common.h +42 -51
  57. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +4 -4
  58. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +12 -6
  59. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +1 -1
  60. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +5 -0
  61. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +52 -18
  62. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +106 -14
  63. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +49 -28
  64. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +87 -106
  65. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +16 -0
  66. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +2 -1
  67. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +7 -2
  68. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +44 -33
  69. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +1 -0
  70. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +83 -17
  71. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +44 -2
  72. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +407 -179
  73. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +13 -2
  74. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +5 -3
  75. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-saver.h +37 -0
  76. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +24 -2
  77. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +6 -0
  78. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +102 -142
  79. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +23 -11
  80. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +186 -127
  81. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Info.plist +0 -0
  82. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/_CodeSignature/CodeResources +1 -1
  83. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
  84. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
  85. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus.h +92 -5
  86. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus_ffi.h +268 -0
  87. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/chat.h +2 -0
  88. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/common.h +42 -51
  89. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend.h +4 -4
  90. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-common.h +12 -6
  91. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpp.h +1 -1
  92. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu.h +5 -0
  93. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-impl.h +52 -18
  94. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal-impl.h +106 -14
  95. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-opt.h +49 -28
  96. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml.h +87 -106
  97. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-arch.h +16 -0
  98. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-batch.h +2 -1
  99. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-chat.h +7 -2
  100. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-context.h +44 -33
  101. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cparams.h +1 -0
  102. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-graph.h +83 -17
  103. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-hparams.h +44 -2
  104. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-kv-cache.h +407 -179
  105. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-memory.h +13 -2
  106. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-loader.h +5 -3
  107. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-saver.h +37 -0
  108. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model.h +24 -2
  109. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-vocab.h +6 -0
  110. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama.h +102 -142
  111. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/chat-template.hpp +23 -11
  112. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/minja.hpp +186 -127
  113. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Info.plist +0 -0
  114. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/cactus +0 -0
  115. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/ggml-llama.metallib +0 -0
  116. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +92 -5
  117. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +268 -0
  118. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +2 -0
  119. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/common.h +42 -51
  120. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +4 -4
  121. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +12 -6
  122. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +1 -1
  123. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +5 -0
  124. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +52 -18
  125. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +106 -14
  126. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +49 -28
  127. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +87 -106
  128. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +16 -0
  129. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +2 -1
  130. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +7 -2
  131. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +44 -33
  132. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +1 -0
  133. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +83 -17
  134. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +44 -2
  135. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +407 -179
  136. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +13 -2
  137. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +5 -3
  138. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-saver.h +37 -0
  139. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +24 -2
  140. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +6 -0
  141. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +102 -142
  142. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +23 -11
  143. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +186 -127
  144. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Info.plist +0 -0
  145. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/_CodeSignature/CodeResources +1 -1
  146. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
  147. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
  148. package/lib/commonjs/NativeCactus.js +1 -0
  149. package/lib/commonjs/NativeCactus.js.map +1 -1
  150. package/lib/commonjs/index.js +112 -0
  151. package/lib/commonjs/index.js.map +1 -1
  152. package/lib/commonjs/tools.js +118 -0
  153. package/lib/commonjs/tools.js.map +1 -0
  154. package/lib/module/NativeCactus.js +3 -0
  155. package/lib/module/NativeCactus.js.map +1 -1
  156. package/lib/module/index.js +87 -1
  157. package/lib/module/index.js.map +1 -1
  158. package/lib/module/tools.js +110 -0
  159. package/lib/module/tools.js.map +1 -0
  160. package/lib/typescript/NativeCactus.d.ts +30 -1
  161. package/lib/typescript/NativeCactus.d.ts.map +1 -1
  162. package/lib/typescript/index.d.ts +21 -2
  163. package/lib/typescript/index.d.ts.map +1 -1
  164. package/lib/typescript/tools.d.ts +38 -0
  165. package/lib/typescript/tools.d.ts.map +1 -0
  166. package/package.json +6 -3
  167. package/src/NativeCactus.ts +62 -1
  168. package/src/index.ts +113 -2
  169. package/src/tools.ts +127 -0
  170. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-aarch64.h +0 -8
  171. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-impl.h +0 -531
  172. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-quants.h +0 -63
  173. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-traits.h +0 -38
  174. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/sgemm.h +0 -14
  175. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-aarch64.h +0 -8
  176. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-impl.h +0 -531
  177. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-quants.h +0 -63
  178. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-traits.h +0 -38
  179. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/sgemm.h +0 -14
  180. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-aarch64.h +0 -8
  181. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-impl.h +0 -531
  182. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-quants.h +0 -63
  183. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-traits.h +0 -38
  184. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/sgemm.h +0 -14
  185. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-aarch64.h +0 -8
  186. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-impl.h +0 -531
  187. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-quants.h +0 -63
  188. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-traits.h +0 -38
  189. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/sgemm.h +0 -14
@@ -1,63 +0,0 @@
1
- #pragma once
2
-
3
- #define LM_GGML_COMMON_DECL_C
4
- #include "ggml-common.h"
5
-
6
- #include "ggml.h"
7
-
8
- // GGML CPU internal header
9
-
10
- #ifdef __cplusplus
11
- extern "C" {
12
- #endif
13
-
14
- // Quantization
15
- void quantize_row_q4_0(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
16
- void quantize_row_q4_1(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
17
- void quantize_row_q5_0(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
18
- void quantize_row_q5_1(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
19
- void quantize_row_q8_0(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
20
- void quantize_row_q8_1(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
21
-
22
- void quantize_row_q2_K(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
23
- void quantize_row_q3_K(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
24
- void quantize_row_q4_K(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
25
- void quantize_row_q5_K(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
26
- void quantize_row_q6_K(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
27
- void quantize_row_q8_K(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
28
-
29
- void quantize_row_tq1_0(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
30
- void quantize_row_tq2_0(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
31
-
32
- void quantize_row_iq4_nl (const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
33
- void quantize_row_iq4_xs (const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
34
-
35
- // Dot product
36
- void lm_ggml_vec_dot_q4_0_q8_0(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
37
- void lm_ggml_vec_dot_q4_1_q8_1(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
38
- void lm_ggml_vec_dot_q5_0_q8_0(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
39
- void lm_ggml_vec_dot_q5_1_q8_1(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
40
- void lm_ggml_vec_dot_q8_0_q8_0(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
41
-
42
- void lm_ggml_vec_dot_q2_K_q8_K(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
43
- void lm_ggml_vec_dot_q3_K_q8_K(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
44
- void lm_ggml_vec_dot_q4_K_q8_K(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
45
- void lm_ggml_vec_dot_q5_K_q8_K(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
46
- void lm_ggml_vec_dot_q6_K_q8_K(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
47
-
48
- void lm_ggml_vec_dot_tq1_0_q8_K(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
49
- void lm_ggml_vec_dot_tq2_0_q8_K(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
50
-
51
- void lm_ggml_vec_dot_iq2_xxs_q8_K(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
52
- void lm_ggml_vec_dot_iq2_xs_q8_K (int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
53
- void lm_ggml_vec_dot_iq2_s_q8_K (int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
54
- void lm_ggml_vec_dot_iq3_xxs_q8_K(int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
55
- void lm_ggml_vec_dot_iq1_s_q8_K (int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
56
- void lm_ggml_vec_dot_iq1_m_q8_K (int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
57
- void lm_ggml_vec_dot_iq4_nl_q8_0 (int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
58
- void lm_ggml_vec_dot_iq4_xs_q8_K (int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
59
- void lm_ggml_vec_dot_iq3_s_q8_K (int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT vx, size_t bx, const void * LM_GGML_RESTRICT vy, size_t by, int nrc);
60
-
61
- #ifdef __cplusplus
62
- }
63
- #endif
@@ -1,38 +0,0 @@
1
- #pragma once
2
- #include "ggml-backend-impl.h"
3
- #include "ggml-cpu-impl.h"
4
- #include "ggml.h"
5
-
6
- #ifdef __cplusplus
7
- # include <vector>
8
- extern "C" {
9
- #endif
10
-
11
- // return true if op part of extra "accelerator"
12
- bool lm_ggml_cpu_extra_compute_forward(struct lm_ggml_compute_params * params, struct lm_ggml_tensor * op);
13
- bool lm_ggml_cpu_extra_work_size(int n_threads, const struct lm_ggml_tensor * op, size_t * size);
14
-
15
- #ifdef __cplusplus
16
- }
17
-
18
- namespace ggml::cpu {
19
- // register in tensor->extra
20
- class tensor_traits {
21
- public:
22
- virtual ~tensor_traits();
23
- virtual bool work_size(int n_threads, const struct lm_ggml_tensor * op, size_t & size) = 0;
24
- virtual bool compute_forward(struct lm_ggml_compute_params * params, struct lm_ggml_tensor * op) = 0;
25
- };
26
-
27
- class extra_buffer_type {
28
- public:
29
- virtual ~extra_buffer_type();
30
- virtual bool supports_op(lm_ggml_backend_dev_t dev, const struct lm_ggml_tensor * op) = 0;
31
- virtual tensor_traits * get_tensor_traits(const struct lm_ggml_tensor * op) = 0;
32
- };
33
- } // namespace ggml::cpu
34
-
35
- // implemented in ggml-cpu.cpp.
36
- std::vector<lm_ggml_backend_buffer_type_t> & lm_ggml_backend_cpu_get_extra_buffers_type();
37
-
38
- #endif
@@ -1,14 +0,0 @@
1
- #pragma once
2
- #include <stdint.h>
3
- #include <stdbool.h>
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif
7
-
8
- bool llamafile_sgemm(const struct lm_ggml_compute_params * params, int64_t, int64_t, int64_t,
9
- const void *, int64_t, const void *, int64_t, void *, int64_t,
10
- int, int, int);
11
-
12
- #ifdef __cplusplus
13
- }
14
- #endif
@@ -1,8 +0,0 @@
1
- #pragma once
2
-
3
- #include "ggml-cpu-traits.h"
4
- #include "ggml.h"
5
-
6
- // GGML internal header
7
-
8
- lm_ggml_backend_buffer_type_t lm_ggml_backend_cpu_aarch64_buffer_type(void);
@@ -1,531 +0,0 @@
1
- #pragma once
2
-
3
- // GGML CPU internal header
4
-
5
- #include "ggml.h"
6
- #include "ggml-impl.h"
7
- #include <stdlib.h> // load `stdlib.h` before other headers to work around MinGW bug: https://sourceforge.net/p/mingw-w64/bugs/192/
8
- //#include <stddef.h>
9
- #include <stdbool.h>
10
- #include <string.h> // memcpy
11
- #include <math.h> // fabsf
12
-
13
-
14
- #ifdef __cplusplus
15
- extern "C" {
16
- #endif
17
-
18
- struct lm_ggml_compute_params {
19
- // ith = thread index, nth = number of threads
20
- int ith, nth;
21
-
22
- // work buffer for all threads
23
- size_t wsize;
24
- void * wdata;
25
-
26
- struct lm_ggml_threadpool * threadpool;
27
- };
28
-
29
-
30
- #if defined(_MSC_VER)
31
-
32
- #define m512bh(p) p
33
- #define m512i(p) p
34
-
35
- #else
36
-
37
- #define m512bh(p) (__m512bh)(p)
38
- #define m512i(p) (__m512i)(p)
39
-
40
- #endif
41
-
42
- // __FMA__ and __F16C__ are not defined in MSVC, however they are implied with AVX2/AVX512
43
- #if defined(_MSC_VER) && (defined(__AVX2__) || defined(__AVX512F__))
44
- #ifndef __FMA__
45
- #define __FMA__
46
- #endif
47
- #ifndef __F16C__
48
- #define __F16C__
49
- #endif
50
- #endif
51
-
52
- // __SSE3__ and __SSSE3__ are not defined in MSVC, but SSE3/SSSE3 are present when AVX/AVX2/AVX512 are available
53
- #if defined(_MSC_VER) && (defined(__AVX__) || defined(__AVX2__) || defined(__AVX512F__))
54
- #ifndef __SSE3__
55
- #define __SSE3__
56
- #endif
57
- #ifndef __SSSE3__
58
- #define __SSSE3__
59
- #endif
60
- #endif
61
-
62
- #if defined(__s390x__) && defined(__VEC__)
63
- #ifndef __VXE__
64
- #define __VXE__
65
- #endif
66
- #ifndef __VXE2__
67
- #define __VXE2__
68
- #endif
69
- #endif
70
-
71
- #if defined(__ARM_FEATURE_SVE)
72
- #include <arm_sve.h>
73
- #include <sys/prctl.h>
74
- #endif
75
-
76
- // 16-bit float
77
- // on Arm, we use __fp16
78
- // on x86, we use uint16_t
79
- #if defined(__ARM_NEON)
80
-
81
- // if YCM cannot find <arm_neon.h>, make a symbolic link to it, for example:
82
- //
83
- // $ ln -sfn /Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/arm_neon.h ./src/
84
- //
85
- #include <arm_neon.h>
86
-
87
- #ifdef _MSC_VER
88
-
89
- typedef uint16_t lm_ggml_fp16_internal_t;
90
-
91
- #define lm_ggml_vld1q_u32(w,x,y,z) { ((w) + ((uint64_t)(x) << 32)), ((y) + ((uint64_t)(z) << 32)) }
92
-
93
- #else
94
-
95
- typedef __fp16 lm_ggml_fp16_internal_t;
96
-
97
- #define lm_ggml_vld1q_u32(w,x,y,z) { (w), (x), (y), (z) }
98
-
99
- #endif // _MSC_VER
100
-
101
- #if !defined(__aarch64__)
102
-
103
- // 32-bit ARM compatibility
104
-
105
- // vaddlvq_s16
106
- // vpaddq_s16
107
- // vpaddq_s32
108
- // vaddvq_s32
109
- // vaddvq_f32
110
- // vmaxvq_f32
111
- // vcvtnq_s32_f32
112
- // vzip1_u8
113
- // vzip2_u8
114
-
115
- inline static int32_t vaddlvq_s16(int16x8_t v) {
116
- int32x4_t v0 = vreinterpretq_s32_s64(vpaddlq_s32(vpaddlq_s16(v)));
117
- return vgetq_lane_s32(v0, 0) + vgetq_lane_s32(v0, 2);
118
- }
119
-
120
- inline static int16x8_t vpaddq_s16(int16x8_t a, int16x8_t b) {
121
- int16x4_t a0 = vpadd_s16(vget_low_s16(a), vget_high_s16(a));
122
- int16x4_t b0 = vpadd_s16(vget_low_s16(b), vget_high_s16(b));
123
- return vcombine_s16(a0, b0);
124
- }
125
-
126
- inline static int32x4_t vpaddq_s32(int32x4_t a, int32x4_t b) {
127
- int32x2_t a0 = vpadd_s32(vget_low_s32(a), vget_high_s32(a));
128
- int32x2_t b0 = vpadd_s32(vget_low_s32(b), vget_high_s32(b));
129
- return vcombine_s32(a0, b0);
130
- }
131
-
132
- inline static int32_t vaddvq_s32(int32x4_t v) {
133
- return vgetq_lane_s32(v, 0) + vgetq_lane_s32(v, 1) + vgetq_lane_s32(v, 2) + vgetq_lane_s32(v, 3);
134
- }
135
-
136
- inline static float vaddvq_f32(float32x4_t v) {
137
- return vgetq_lane_f32(v, 0) + vgetq_lane_f32(v, 1) + vgetq_lane_f32(v, 2) + vgetq_lane_f32(v, 3);
138
- }
139
-
140
- inline static float vmaxvq_f32(float32x4_t v) {
141
- return
142
- MAX(MAX(vgetq_lane_f32(v, 0), vgetq_lane_f32(v, 1)),
143
- MAX(vgetq_lane_f32(v, 2), vgetq_lane_f32(v, 3)));
144
- }
145
-
146
- inline static int32x4_t vcvtnq_s32_f32(float32x4_t v) {
147
- int32x4_t res;
148
-
149
- res[0] = roundf(vgetq_lane_f32(v, 0));
150
- res[1] = roundf(vgetq_lane_f32(v, 1));
151
- res[2] = roundf(vgetq_lane_f32(v, 2));
152
- res[3] = roundf(vgetq_lane_f32(v, 3));
153
-
154
- return res;
155
- }
156
-
157
- inline static uint8x8_t vzip1_u8(uint8x8_t a, uint8x8_t b) {
158
- uint8x8_t res;
159
-
160
- res[0] = a[0]; res[1] = b[0];
161
- res[2] = a[1]; res[3] = b[1];
162
- res[4] = a[2]; res[5] = b[2];
163
- res[6] = a[3]; res[7] = b[3];
164
-
165
- return res;
166
- }
167
-
168
- inline static uint8x8_t vzip2_u8(uint8x8_t a, uint8x8_t b) {
169
- uint8x8_t res;
170
-
171
- res[0] = a[4]; res[1] = b[4];
172
- res[2] = a[5]; res[3] = b[5];
173
- res[4] = a[6]; res[5] = b[6];
174
- res[6] = a[7]; res[7] = b[7];
175
-
176
- return res;
177
- }
178
-
179
- // vld1q_s16_x2
180
- // vld1q_u8_x2
181
- // vld1q_u8_x4
182
- // vld1q_s8_x2
183
- // vld1q_s8_x4
184
- // TODO: double-check these work correctly
185
-
186
- typedef struct lm_ggml_int16x8x2_t {
187
- int16x8_t val[2];
188
- } lm_ggml_int16x8x2_t;
189
-
190
- inline static lm_ggml_int16x8x2_t lm_ggml_vld1q_s16_x2(const int16_t * ptr) {
191
- lm_ggml_int16x8x2_t res;
192
-
193
- res.val[0] = vld1q_s16(ptr + 0);
194
- res.val[1] = vld1q_s16(ptr + 8);
195
-
196
- return res;
197
- }
198
-
199
- typedef struct lm_ggml_uint8x16x2_t {
200
- uint8x16_t val[2];
201
- } lm_ggml_uint8x16x2_t;
202
-
203
- inline static lm_ggml_uint8x16x2_t lm_ggml_vld1q_u8_x2(const uint8_t * ptr) {
204
- lm_ggml_uint8x16x2_t res;
205
-
206
- res.val[0] = vld1q_u8(ptr + 0);
207
- res.val[1] = vld1q_u8(ptr + 16);
208
-
209
- return res;
210
- }
211
-
212
- typedef struct lm_ggml_uint8x16x4_t {
213
- uint8x16_t val[4];
214
- } lm_ggml_uint8x16x4_t;
215
-
216
- inline static lm_ggml_uint8x16x4_t lm_ggml_vld1q_u8_x4(const uint8_t * ptr) {
217
- lm_ggml_uint8x16x4_t res;
218
-
219
- res.val[0] = vld1q_u8(ptr + 0);
220
- res.val[1] = vld1q_u8(ptr + 16);
221
- res.val[2] = vld1q_u8(ptr + 32);
222
- res.val[3] = vld1q_u8(ptr + 48);
223
-
224
- return res;
225
- }
226
-
227
- typedef struct lm_ggml_int8x16x2_t {
228
- int8x16_t val[2];
229
- } lm_ggml_int8x16x2_t;
230
-
231
- inline static lm_ggml_int8x16x2_t lm_ggml_vld1q_s8_x2(const int8_t * ptr) {
232
- lm_ggml_int8x16x2_t res;
233
-
234
- res.val[0] = vld1q_s8(ptr + 0);
235
- res.val[1] = vld1q_s8(ptr + 16);
236
-
237
- return res;
238
- }
239
-
240
- typedef struct lm_ggml_int8x16x4_t {
241
- int8x16_t val[4];
242
- } lm_ggml_int8x16x4_t;
243
-
244
- inline static lm_ggml_int8x16x4_t lm_ggml_vld1q_s8_x4(const int8_t * ptr) {
245
- lm_ggml_int8x16x4_t res;
246
-
247
- res.val[0] = vld1q_s8(ptr + 0);
248
- res.val[1] = vld1q_s8(ptr + 16);
249
- res.val[2] = vld1q_s8(ptr + 32);
250
- res.val[3] = vld1q_s8(ptr + 48);
251
-
252
- return res;
253
- }
254
-
255
- // NOTE: not tested
256
- inline static int8x16_t lm_ggml_vqtbl1q_s8(int8x16_t a, uint8x16_t b) {
257
- int8x16_t res;
258
-
259
- res[ 0] = a[b[ 0]];
260
- res[ 1] = a[b[ 1]];
261
- res[ 2] = a[b[ 2]];
262
- res[ 3] = a[b[ 3]];
263
- res[ 4] = a[b[ 4]];
264
- res[ 5] = a[b[ 5]];
265
- res[ 6] = a[b[ 6]];
266
- res[ 7] = a[b[ 7]];
267
- res[ 8] = a[b[ 8]];
268
- res[ 9] = a[b[ 9]];
269
- res[10] = a[b[10]];
270
- res[11] = a[b[11]];
271
- res[12] = a[b[12]];
272
- res[13] = a[b[13]];
273
- res[14] = a[b[14]];
274
- res[15] = a[b[15]];
275
-
276
- return res;
277
- }
278
-
279
- // NOTE: not tested
280
- inline static uint8x16_t lm_ggml_vqtbl1q_u8(uint8x16_t a, uint8x16_t b) {
281
- uint8x16_t res;
282
-
283
- res[ 0] = a[b[ 0]];
284
- res[ 1] = a[b[ 1]];
285
- res[ 2] = a[b[ 2]];
286
- res[ 3] = a[b[ 3]];
287
- res[ 4] = a[b[ 4]];
288
- res[ 5] = a[b[ 5]];
289
- res[ 6] = a[b[ 6]];
290
- res[ 7] = a[b[ 7]];
291
- res[ 8] = a[b[ 8]];
292
- res[ 9] = a[b[ 9]];
293
- res[10] = a[b[10]];
294
- res[11] = a[b[11]];
295
- res[12] = a[b[12]];
296
- res[13] = a[b[13]];
297
- res[14] = a[b[14]];
298
- res[15] = a[b[15]];
299
-
300
- return res;
301
- }
302
-
303
- #else
304
-
305
- #define lm_ggml_int16x8x2_t int16x8x2_t
306
- #define lm_ggml_uint8x16x2_t uint8x16x2_t
307
- #define lm_ggml_uint8x16x4_t uint8x16x4_t
308
- #define lm_ggml_int8x16x2_t int8x16x2_t
309
- #define lm_ggml_int8x16x4_t int8x16x4_t
310
-
311
- #define lm_ggml_vld1q_s16_x2 vld1q_s16_x2
312
- #define lm_ggml_vld1q_u8_x2 vld1q_u8_x2
313
- #define lm_ggml_vld1q_u8_x4 vld1q_u8_x4
314
- #define lm_ggml_vld1q_s8_x2 vld1q_s8_x2
315
- #define lm_ggml_vld1q_s8_x4 vld1q_s8_x4
316
- #define lm_ggml_vqtbl1q_s8 vqtbl1q_s8
317
- #define lm_ggml_vqtbl1q_u8 vqtbl1q_u8
318
-
319
- #endif // !defined(__aarch64__)
320
-
321
- #if !defined(__ARM_FEATURE_DOTPROD)
322
-
323
- inline static int32x4_t lm_ggml_vdotq_s32(int32x4_t acc, int8x16_t a, int8x16_t b) {
324
- const int16x8_t p0 = vmull_s8(vget_low_s8 (a), vget_low_s8 (b));
325
- const int16x8_t p1 = vmull_s8(vget_high_s8(a), vget_high_s8(b));
326
-
327
- return vaddq_s32(acc, vaddq_s32(vpaddlq_s16(p0), vpaddlq_s16(p1)));
328
- }
329
-
330
- #else
331
-
332
- #define lm_ggml_vdotq_s32(a, b, c) vdotq_s32(a, b, c)
333
-
334
- #endif // !defined(__ARM_FEATURE_DOTPROD)
335
-
336
- #endif // defined(__ARM_NEON)
337
-
338
- #ifdef __wasm_simd128__
339
- #include <wasm_simd128.h>
340
- #else
341
- #ifdef __POWER9_VECTOR__
342
- #include <altivec.h>
343
- #undef bool
344
- #define bool _Bool
345
- #else
346
- #if defined(_MSC_VER) || defined(__MINGW32__)
347
- #include <intrin.h>
348
- #else
349
- #if defined(__AVX__) || defined(__AVX2__) || defined(__AVX512F__) || defined(__SSSE3__) || defined(__SSE3__) || defined(__SSE__)
350
- #if !defined(__riscv)
351
- #include <immintrin.h>
352
- #endif
353
- #endif
354
- #endif
355
- #endif
356
- #endif
357
-
358
- #ifdef __riscv_v_intrinsic
359
- #include <riscv_vector.h>
360
- #endif
361
-
362
- #if defined(__loongarch64)
363
- #if defined(__loongarch_asx)
364
- #include <lasxintrin.h>
365
- #endif
366
- #if defined(__loongarch_sx)
367
- #include <lsxintrin.h>
368
- #endif
369
- #endif
370
-
371
- #if defined(__VXE__) || defined(__VXE2__)
372
- #include <vecintrin.h>
373
-
374
- #define vec_neg(a) (-(a)) // Vector Negate
375
- #define vec_add(a, b) ((a) + (b)) // Vector Add
376
- #define vec_sub(a, b) ((a) - (b)) // Vector Subtract
377
- #define vec_mul(a, b) ((a) * (b)) // Vector Multiply
378
- #define vec_div(a, b) ((a) / (b)) // Vector Divide
379
- #define vec_sl(a, b) ((a) << (b)) // Vector Shift Left
380
- #define vec_sra(a, b) ((a) >> (b)) // Vector Shift Right
381
- #define vec_sr(a, b) ((a) >> (b)) // Vector Shift Right Algebraic
382
- #define vec_slo(a, b) vec_slb(a, (b) << 64) // Vector Shift Left by Octet
383
- #define vec_sro(a, b) vec_srb(a, (b) << 64) // Vector Shift Right by Octet
384
-
385
- #ifndef vec_and
386
- #define vec_and(a, b) ((a) & (b)) // Vector AND
387
- #endif
388
-
389
- #ifndef vec_or
390
- #define vec_or(a, b) ((a) | (b)) // Vector OR
391
- #endif
392
-
393
- #ifndef vec_xor
394
- #define vec_xor(a, b) ((a) ^ (b)) // Vector XOR
395
- #endif
396
-
397
- typedef signed char char8x16_t __attribute__((vector_size(16)));
398
- typedef unsigned char uchar8x16_t __attribute__((vector_size(16)));
399
-
400
- typedef int8_t int8x16_t __attribute__((vector_size(16)));
401
- typedef int16_t int16x8_t __attribute__((vector_size(16)));
402
- typedef int32_t int32x4_t __attribute__((vector_size(16)));
403
-
404
- typedef uint8_t uint8x16_t __attribute__((vector_size(16)));
405
- typedef uint16_t uint16x8_t __attribute__((vector_size(16)));
406
- typedef uint32_t uint32x4_t __attribute__((vector_size(16)));
407
-
408
- typedef float float32x4_t __attribute__((vector_size(16)));
409
- typedef double double64x2_t __attribute((vector_size(16)));
410
-
411
- typedef signed long long long64x2_t __attribute((vector_size(16)));
412
- typedef unsigned long long ulong64x2_t __attribute__((vector_size(16)));
413
-
414
- typedef struct lm_ggml_uint8x16x2_t {
415
- uint8x16_t val[2];
416
- } lm_ggml_uint8x16x2_t;
417
-
418
- inline static lm_ggml_uint8x16x2_t lm_ggml_vec_xl_u8x2(const uint8_t * ptr) {
419
- lm_ggml_uint8x16x2_t res;
420
-
421
- res.val[0] = vec_xl( 0, ptr);
422
- res.val[1] = vec_xl(16, ptr);
423
-
424
- return res;
425
- }
426
-
427
- typedef struct lm_ggml_uint8x16x4_t {
428
- uint8x16_t val[4];
429
- } lm_ggml_uint8x16x4_t;
430
-
431
- inline static lm_ggml_uint8x16x4_t lm_ggml_vec_xl_u8x4(const uint8_t * ptr) {
432
- lm_ggml_uint8x16x4_t res;
433
-
434
- res.val[0] = vec_xl( 0, ptr);
435
- res.val[1] = vec_xl(16, ptr);
436
- res.val[2] = vec_xl(32, ptr);
437
- res.val[3] = vec_xl(48, ptr);
438
-
439
- return res;
440
- }
441
-
442
- typedef struct lm_ggml_int8x16x4_t {
443
- int8x16_t val[4];
444
- } lm_ggml_int8x16x4_t;
445
-
446
- inline static lm_ggml_int8x16x4_t lm_ggml_vec_xl_s8x4(const int8_t * ptr) {
447
- lm_ggml_int8x16x4_t res;
448
-
449
- res.val[0] = vec_xl( 0, ptr);
450
- res.val[1] = vec_xl(16, ptr);
451
- res.val[2] = vec_xl(32, ptr);
452
- res.val[3] = vec_xl(48, ptr);
453
-
454
- return res;
455
- }
456
-
457
- typedef struct lm_ggml_int16x8x2_t {
458
- int16x8_t val[2];
459
- } lm_ggml_int16x8x2_t;
460
-
461
- inline static lm_ggml_int16x8x2_t lm_ggml_vec_xl_s16x2(const int16_t * ptr) {
462
- lm_ggml_int16x8x2_t res;
463
-
464
- res.val[0] = vec_xl( 0, ptr);
465
- res.val[1] = vec_xl(16, ptr);
466
-
467
- return res;
468
- }
469
-
470
- /*
471
- ! WARNING: Very slow. Use vec_perm if possible. Refer to iq4_xs
472
- ! or iq4_nl for example implementation.
473
- */
474
- inline static int8x16_t lm_ggml_vec_tbl(int8x16_t a, uint8x16_t b) {
475
- int8x16_t res;
476
-
477
- res[ 0] = a[b[ 0]];
478
- res[ 1] = a[b[ 1]];
479
- res[ 2] = a[b[ 2]];
480
- res[ 3] = a[b[ 3]];
481
- res[ 4] = a[b[ 4]];
482
- res[ 5] = a[b[ 5]];
483
- res[ 6] = a[b[ 6]];
484
- res[ 7] = a[b[ 7]];
485
- res[ 8] = a[b[ 8]];
486
- res[ 9] = a[b[ 9]];
487
- res[10] = a[b[10]];
488
- res[11] = a[b[11]];
489
- res[12] = a[b[12]];
490
- res[13] = a[b[13]];
491
- res[14] = a[b[14]];
492
- res[15] = a[b[15]];
493
-
494
- return res;
495
- }
496
-
497
- inline static int16x8_t vec_padd_s16(int16x8_t a, int16x8_t b) {
498
- const uchar8x16_t v_maske = { 0, 1, 4, 5, 8, 9, 12, 13,
499
- 16, 17, 20, 21, 24, 25, 28, 29 };
500
-
501
- const int16x8_t v_abo = vec_pack((int32x4_t)a, (int32x4_t)b);
502
- const int16x8_t v_abe = vec_perm(a, b, v_maske);
503
- return v_abo + v_abe;
504
- }
505
-
506
- inline static int32x4_t lm_ggml_vec_dot(int32x4_t acc, int8x16_t a, int8x16_t b) {
507
- const int16x8_t p = vec_mule(a, b) + vec_mulo(a, b);
508
- return acc + (vec_unpackh(p) + vec_unpackl(p));
509
- }
510
-
511
- #endif
512
-
513
- #if defined(__loongarch_asx)
514
- /* float type data load instructions */
515
- static __m128 __lsx_vreplfr2vr_s(const float val) {
516
- v4f32 res = {val, val, val, val};
517
- return (__m128)res;
518
- }
519
-
520
- static __m256 __lasx_xvreplfr2vr_s(const float val) {
521
- v8f32 res = {val, val, val, val, val, val, val, val};
522
- return (__m256)res;
523
- }
524
- #endif
525
-
526
- // TODO: move to ggml-threading
527
- void lm_ggml_barrier(struct lm_ggml_threadpool * tp);
528
-
529
- #ifdef __cplusplus
530
- }
531
- #endif