whispercpp 1.3.7 → 1.3.8

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 (308) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -4
  3. data/ext/options.rb +1 -1
  4. data/ext/ruby_whisper.c +0 -1
  5. data/ext/ruby_whisper.h +7 -1
  6. data/ext/ruby_whisper_context.c +50 -1
  7. data/ext/ruby_whisper_log_settable.h +1 -2
  8. data/ext/ruby_whisper_params.c +9 -8
  9. data/ext/ruby_whisper_transcribe.cpp +0 -19
  10. data/ext/ruby_whisper_vad_context.c +30 -10
  11. data/ext/ruby_whisper_vad_context_detect.cpp +8 -9
  12. data/ext/ruby_whisper_vad_params.c +4 -4
  13. data/ext/ruby_whisper_vad_segment.c +2 -2
  14. data/ext/sources/CMakeLists.txt +2 -1
  15. data/ext/sources/cmake/parakeet.pc.in +2 -2
  16. data/ext/sources/cmake/whisper.pc.in +2 -2
  17. data/ext/sources/examples/cli/cli.cpp +9 -1
  18. data/ext/sources/examples/common-ggml.cpp +2 -0
  19. data/ext/sources/examples/vad-speech-segments/speech.cpp +3 -2
  20. data/ext/sources/ggml/CMakeLists.txt +3 -4
  21. data/ext/sources/ggml/include/ggml-cuda.h +0 -3
  22. data/ext/sources/ggml/include/ggml-sycl.h +8 -0
  23. data/ext/sources/ggml/include/ggml.h +3 -1
  24. data/ext/sources/ggml/src/CMakeLists.txt +8 -1
  25. data/ext/sources/ggml/src/ggml-backend-meta.cpp +7 -4
  26. data/ext/sources/ggml/src/ggml-common.h +13 -2
  27. data/ext/sources/ggml/src/ggml-cpu/CMakeLists.txt +1 -1
  28. data/ext/sources/ggml/src/ggml-cpu/amx/mmq.cpp +5 -6
  29. data/ext/sources/ggml/src/ggml-cpu/arch/arm/quants.c +78 -4
  30. data/ext/sources/ggml/src/ggml-cpu/arch/x86/quants.c +142 -4
  31. data/ext/sources/ggml/src/ggml-cpu/arch-fallback.h +7 -2
  32. data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.c +14 -0
  33. data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm.cpp +26 -19
  34. data/ext/sources/ggml/src/ggml-cpu/ops.cpp +129 -46
  35. data/ext/sources/ggml/src/ggml-cpu/quants.c +51 -0
  36. data/ext/sources/ggml/src/ggml-cpu/quants.h +3 -0
  37. data/ext/sources/ggml/src/ggml-cpu/simd-gemm.h +1 -1
  38. data/ext/sources/ggml/src/ggml-cpu/simd-mappings.h +11 -0
  39. data/ext/sources/ggml/src/ggml-cpu/vec.cpp +2 -2
  40. data/ext/sources/ggml/src/ggml-cuda/binbcast.cu +90 -46
  41. data/ext/sources/ggml/src/ggml-cuda/col2im-1d.cu +81 -0
  42. data/ext/sources/ggml/src/ggml-cuda/col2im-1d.cuh +3 -0
  43. data/ext/sources/ggml/src/ggml-cuda/common.cuh +4 -0
  44. data/ext/sources/ggml/src/ggml-cuda/concat.cu +33 -21
  45. data/ext/sources/ggml/src/ggml-cuda/conv-transpose-1d.cu +14 -12
  46. data/ext/sources/ggml/src/ggml-cuda/convert.cu +86 -34
  47. data/ext/sources/ggml/src/ggml-cuda/cpy.cu +80 -29
  48. data/ext/sources/ggml/src/ggml-cuda/fattn-common.cuh +9 -5
  49. data/ext/sources/ggml/src/ggml-cuda/fattn-mma-f16.cuh +4 -0
  50. data/ext/sources/ggml/src/ggml-cuda/fattn-tile.cuh +9 -5
  51. data/ext/sources/ggml/src/ggml-cuda/fattn.cu +27 -21
  52. data/ext/sources/ggml/src/ggml-cuda/gated_delta_net.cu +40 -25
  53. data/ext/sources/ggml/src/ggml-cuda/gated_delta_net.cuh +10 -0
  54. data/ext/sources/ggml/src/ggml-cuda/getrows.cu +15 -12
  55. data/ext/sources/ggml/src/ggml-cuda/ggml-cuda.cu +718 -1248
  56. data/ext/sources/ggml/src/ggml-cuda/mmq.cu +7 -0
  57. data/ext/sources/ggml/src/ggml-cuda/mmvq.cu +77 -40
  58. data/ext/sources/ggml/src/ggml-cuda/out-prod.cu +55 -12
  59. data/ext/sources/ggml/src/ggml-cuda/set-rows.cu +64 -4
  60. data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +1 -0
  61. data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +1 -0
  62. data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +1 -0
  63. data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +1 -0
  64. data/ext/sources/ggml/src/ggml-cuda/topk-moe.cu +7 -1
  65. data/ext/sources/ggml/src/ggml-cuda/vendors/hip.h +1 -0
  66. data/ext/sources/ggml/src/ggml-cuda/vendors/musa.h +1 -0
  67. data/ext/sources/ggml/src/ggml-hexagon/CMakeLists.txt +0 -5
  68. data/ext/sources/ggml/src/ggml-hexagon/ggml-hexagon.cpp +1634 -1293
  69. data/ext/sources/ggml/src/ggml-hexagon/htp/CMakeLists.txt +11 -40
  70. data/ext/sources/ggml/src/ggml-hexagon/htp/cmake-toolchain.cmake +13 -15
  71. data/ext/sources/ggml/src/ggml-hexagon/htp/concat-ops.c +1 -1
  72. data/ext/sources/ggml/src/ggml-hexagon/htp/flash-attn-ops.c +1749 -399
  73. data/ext/sources/ggml/src/ggml-hexagon/htp/flash-attn-ops.h +303 -0
  74. data/ext/sources/ggml/src/ggml-hexagon/htp/hex-common.h +80 -0
  75. data/ext/sources/ggml/src/ggml-hexagon/htp/hex-dma.h +26 -23
  76. data/ext/sources/ggml/src/ggml-hexagon/htp/hex-profile.h +64 -0
  77. data/ext/sources/ggml/src/ggml-hexagon/htp/hex-utils.h +1 -83
  78. data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-fa-kernels.h +555 -0
  79. data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-mm-kernels-tiled.h +1303 -0
  80. data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-queue.c +9 -0
  81. data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-queue.h +27 -4
  82. data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-utils.h +59 -37
  83. data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ctx.h +11 -3
  84. data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ops.h +52 -12
  85. data/ext/sources/ggml/src/ggml-hexagon/htp/htp-vtcm.h +19 -0
  86. data/ext/sources/ggml/src/ggml-hexagon/htp/htp_iface.idl +2 -1
  87. data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-base.h +14 -30
  88. data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-exp.h +39 -0
  89. data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-fa-kernels.h +232 -0
  90. data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-mm-kernels-flat.h +1511 -0
  91. data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-mm-kernels-tiled.h +1200 -0
  92. data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-sigmoid.h +39 -0
  93. data/ext/sources/ggml/src/ggml-hexagon/htp/main.c +127 -32
  94. data/ext/sources/ggml/src/ggml-hexagon/htp/matmul-ops.c +3023 -4425
  95. data/ext/sources/ggml/src/ggml-hexagon/htp/matmul-ops.h +650 -0
  96. data/ext/sources/ggml/src/ggml-hexagon/htp/rope-ops.c +48 -13
  97. data/ext/sources/ggml/src/ggml-hexagon/htp/ssm-conv.c +10 -9
  98. data/ext/sources/ggml/src/ggml-hexagon/htp/worker-pool.c +15 -3
  99. data/ext/sources/ggml/src/ggml-hexagon/htp/worker-pool.h +8 -0
  100. data/ext/sources/ggml/src/ggml-hexagon/htp-opnode.h +168 -50
  101. data/ext/sources/ggml/src/ggml-hexagon/libggml-htp.inf +0 -4
  102. data/ext/sources/ggml/src/ggml-hip/CMakeLists.txt +5 -0
  103. data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.cpp +69 -5
  104. data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.h +4 -1
  105. data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.m +27 -6
  106. data/ext/sources/ggml/src/ggml-metal/ggml-metal-impl.h +38 -0
  107. data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.cpp +132 -2
  108. data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.h +2 -0
  109. data/ext/sources/ggml/src/ggml-metal/ggml-metal.metal +345 -87
  110. data/ext/sources/ggml/src/ggml-opencl/CMakeLists.txt +13 -0
  111. data/ext/sources/ggml/src/ggml-opencl/fa_tune.h +92 -0
  112. data/ext/sources/ggml/src/ggml-opencl/ggml-opencl.cpp +4060 -357
  113. data/ext/sources/ggml/src/ggml-opencl/kernels/cvt.cl +198 -0
  114. data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f16.cl +81 -41
  115. data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32.cl +88 -39
  116. data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32_f16.cl +1995 -96
  117. data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32_q4_0.cl +1615 -0
  118. data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32_q8_0.cl +1486 -0
  119. data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_pre_f16.cl +156 -0
  120. data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_mxfp4_f32_ns.cl +74 -6
  121. data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_0_f32_ns.cl +74 -6
  122. data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_1_f32_ns.cl +74 -6
  123. data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_k_f32_ns.cl +71 -6
  124. data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_0_f32_ns.cl +74 -6
  125. data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_1_f32_ns.cl +74 -6
  126. data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_k_f32_ns.cl +74 -6
  127. data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q6_k_f32_ns.cl +74 -6
  128. data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q1_0_f32.cl +94 -0
  129. data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q1_0_f32.cl +121 -0
  130. data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q8_0_f32.cl +1 -1
  131. data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q1_0_f32_l4_lm.cl +156 -0
  132. data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_l4.cl +1149 -0
  133. data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q1_0_f32.cl +141 -0
  134. data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q1_0_f32_flat.cl +190 -0
  135. data/ext/sources/ggml/src/ggml-opencl/kernels/norm.cl +5 -2
  136. data/ext/sources/ggml/src/ggml-opencl/kernels/set_rows.cl +500 -0
  137. data/ext/sources/ggml/src/ggml-opencl/libdl.h +79 -0
  138. data/ext/sources/ggml/src/ggml-openvino/.clang-format +0 -5
  139. data/ext/sources/ggml/src/ggml-openvino/CMakeLists.txt +2 -4
  140. data/ext/sources/ggml/src/ggml-openvino/ggml-decoder.cpp +733 -130
  141. data/ext/sources/ggml/src/ggml-openvino/ggml-decoder.h +76 -23
  142. data/ext/sources/ggml/src/ggml-openvino/ggml-openvino-extra.cpp +57 -3
  143. data/ext/sources/ggml/src/ggml-openvino/ggml-openvino-extra.h +29 -8
  144. data/ext/sources/ggml/src/ggml-openvino/ggml-openvino.cpp +307 -59
  145. data/ext/sources/ggml/src/ggml-openvino/ggml-quants.cpp +66 -0
  146. data/ext/sources/ggml/src/ggml-openvino/ggml-quants.h +10 -4
  147. data/ext/sources/ggml/src/ggml-openvino/openvino/decoder.h +56 -16
  148. data/ext/sources/ggml/src/ggml-openvino/openvino/frontend.h +1 -1
  149. data/ext/sources/ggml/src/ggml-openvino/openvino/input_model.h +4 -4
  150. data/ext/sources/ggml/src/ggml-openvino/openvino/node_context.h +94 -37
  151. data/ext/sources/ggml/src/ggml-openvino/openvino/op/add_id.cpp +76 -0
  152. data/ext/sources/ggml/src/ggml-openvino/openvino/op/argsort.cpp +47 -0
  153. data/ext/sources/ggml/src/ggml-openvino/openvino/op/clamp.cpp +33 -0
  154. data/ext/sources/ggml/src/ggml-openvino/openvino/op/concat.cpp +48 -0
  155. data/ext/sources/ggml/src/ggml-openvino/openvino/op/cont.cpp +8 -16
  156. data/ext/sources/ggml/src/ggml-openvino/openvino/op/cpy.cpp +14 -1
  157. data/ext/sources/ggml/src/ggml-openvino/openvino/op/div.cpp +146 -0
  158. data/ext/sources/ggml/src/ggml-openvino/openvino/op/flash_attn_ext.cpp +108 -21
  159. data/ext/sources/ggml/src/ggml-openvino/openvino/op/gated_delta_net.cpp +282 -0
  160. data/ext/sources/ggml/src/ggml-openvino/openvino/op/gated_delta_net.hpp +65 -0
  161. data/ext/sources/ggml/src/ggml-openvino/openvino/op/get_rows.cpp +2 -9
  162. data/ext/sources/ggml/src/ggml-openvino/openvino/op/glu_geglu.cpp +21 -7
  163. data/ext/sources/ggml/src/ggml-openvino/openvino/op/glu_swiglu.cpp +41 -8
  164. data/ext/sources/ggml/src/ggml-openvino/openvino/op/im2col.cpp +120 -0
  165. data/ext/sources/ggml/src/ggml-openvino/openvino/op/l2_norm.cpp +44 -0
  166. data/ext/sources/ggml/src/ggml-openvino/openvino/op/mul_mat_id.cpp +226 -0
  167. data/ext/sources/ggml/src/ggml-openvino/openvino/op/mulmat.cpp +19 -9
  168. data/ext/sources/ggml/src/ggml-openvino/openvino/op/norm.cpp +58 -0
  169. data/ext/sources/ggml/src/ggml-openvino/openvino/op/pad.cpp +95 -0
  170. data/ext/sources/ggml/src/ggml-openvino/openvino/op/permute.cpp +58 -13
  171. data/ext/sources/ggml/src/ggml-openvino/openvino/op/repeat.cpp +74 -0
  172. data/ext/sources/ggml/src/ggml-openvino/openvino/op/reshape.cpp +13 -6
  173. data/ext/sources/ggml/src/ggml-openvino/openvino/op/rms_norm.cpp +1 -1
  174. data/ext/sources/ggml/src/ggml-openvino/openvino/op/rope.cpp +134 -38
  175. data/ext/sources/ggml/src/ggml-openvino/openvino/op/set_rows.cpp +3 -3
  176. data/ext/sources/ggml/src/ggml-openvino/openvino/op/softmax.cpp +126 -49
  177. data/ext/sources/ggml/src/ggml-openvino/openvino/op/ssm_conv.cpp +59 -0
  178. data/ext/sources/ggml/src/ggml-openvino/openvino/op/sum_rows.cpp +27 -0
  179. data/ext/sources/ggml/src/ggml-openvino/openvino/op/transpose.cpp +32 -1
  180. data/ext/sources/ggml/src/ggml-openvino/openvino/op/unary_silu.cpp +1 -1
  181. data/ext/sources/ggml/src/ggml-openvino/openvino/op/unary_softplus.cpp +38 -0
  182. data/ext/sources/ggml/src/ggml-openvino/openvino/op/view.cpp +90 -25
  183. data/ext/sources/ggml/src/ggml-openvino/openvino/op_table.cpp +41 -23
  184. data/ext/sources/ggml/src/ggml-openvino/openvino/op_table.h +18 -5
  185. data/ext/sources/ggml/src/ggml-openvino/openvino/pass/mark_decompression_convert_constant_folding.h +1 -1
  186. data/ext/sources/ggml/src/ggml-openvino/openvino/translate_session.cpp +43 -40
  187. data/ext/sources/ggml/src/ggml-openvino/openvino/translate_session.h +5 -4
  188. data/ext/sources/ggml/src/ggml-openvino/openvino/utils.cpp +548 -3
  189. data/ext/sources/ggml/src/ggml-openvino/openvino/utils.h +28 -26
  190. data/ext/sources/ggml/src/ggml-openvino/utils.cpp +383 -94
  191. data/ext/sources/ggml/src/ggml-openvino/utils.h +11 -8
  192. data/ext/sources/ggml/src/ggml-quants.c +76 -0
  193. data/ext/sources/ggml/src/ggml-quants.h +3 -0
  194. data/ext/sources/ggml/src/ggml-sycl/CMakeLists.txt +5 -5
  195. data/ext/sources/ggml/src/ggml-sycl/backend.hpp +2 -0
  196. data/ext/sources/ggml/src/ggml-sycl/binbcast.cpp +12 -0
  197. data/ext/sources/ggml/src/ggml-sycl/col2im-1d.cpp +102 -0
  198. data/ext/sources/ggml/src/ggml-sycl/col2im-1d.hpp +8 -0
  199. data/ext/sources/ggml/src/ggml-sycl/common.cpp +6 -8
  200. data/ext/sources/ggml/src/ggml-sycl/common.hpp +19 -2
  201. data/ext/sources/ggml/src/ggml-sycl/concat.cpp +21 -1
  202. data/ext/sources/ggml/src/ggml-sycl/conv2d-dw.cpp +158 -0
  203. data/ext/sources/ggml/src/ggml-sycl/conv2d-dw.hpp +10 -0
  204. data/ext/sources/ggml/src/ggml-sycl/conv2d-transpose.cpp +125 -0
  205. data/ext/sources/ggml/src/ggml-sycl/conv2d-transpose.hpp +10 -0
  206. data/ext/sources/ggml/src/ggml-sycl/conv2d.cpp +150 -0
  207. data/ext/sources/ggml/src/ggml-sycl/conv2d.hpp +10 -0
  208. data/ext/sources/ggml/src/ggml-sycl/conv3d.cpp +224 -0
  209. data/ext/sources/ggml/src/ggml-sycl/conv3d.hpp +8 -0
  210. data/ext/sources/ggml/src/ggml-sycl/convert.cpp +6 -0
  211. data/ext/sources/ggml/src/ggml-sycl/cpy.cpp +706 -0
  212. data/ext/sources/ggml/src/ggml-sycl/cpy.hpp +281 -0
  213. data/ext/sources/ggml/src/ggml-sycl/cross_entropy_loss.cpp +255 -0
  214. data/ext/sources/ggml/src/ggml-sycl/cross_entropy_loss.hpp +7 -0
  215. data/ext/sources/ggml/src/ggml-sycl/dequantize.hpp +15 -0
  216. data/ext/sources/ggml/src/ggml-sycl/dmmv.cpp +492 -319
  217. data/ext/sources/ggml/src/ggml-sycl/dpct/helper.hpp +15 -7
  218. data/ext/sources/ggml/src/ggml-sycl/element_wise.cpp +215 -115
  219. data/ext/sources/ggml/src/ggml-sycl/element_wise.hpp +2 -0
  220. data/ext/sources/ggml/src/ggml-sycl/ggml-sycl.cpp +1006 -336
  221. data/ext/sources/ggml/src/ggml-sycl/mmvq.cpp +252 -67
  222. data/ext/sources/ggml/src/ggml-sycl/mmvq.hpp +17 -0
  223. data/ext/sources/ggml/src/ggml-sycl/norm.cpp +103 -49
  224. data/ext/sources/ggml/src/ggml-sycl/outprod.cpp +45 -9
  225. data/ext/sources/ggml/src/ggml-sycl/pool.cpp +185 -0
  226. data/ext/sources/ggml/src/ggml-sycl/pool.hpp +22 -0
  227. data/ext/sources/ggml/src/ggml-sycl/presets.hpp +3 -1
  228. data/ext/sources/ggml/src/ggml-sycl/set_rows.cpp +10 -2
  229. data/ext/sources/ggml/src/ggml-sycl/softmax.cpp +9 -10
  230. data/ext/sources/ggml/src/ggml-sycl/vecdotq.hpp +35 -0
  231. data/ext/sources/ggml/src/ggml-vulkan/CMakeLists.txt +5 -0
  232. data/ext/sources/ggml/src/ggml-vulkan/ggml-vulkan.cpp +833 -215
  233. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/col2im_1d.comp +61 -0
  234. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_mm.comp +1 -1
  235. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv3d_mm.comp +431 -0
  236. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp +3 -3
  237. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +1 -0
  238. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +1 -0
  239. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/generic_unary_head.glsl +21 -19
  240. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/get_rows_back.comp +25 -0
  241. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/glu_head.glsl +23 -4
  242. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/glu_main.glsl +14 -18
  243. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +4 -7
  244. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq.comp +21 -24
  245. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +31 -23
  246. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +6 -5
  247. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_funcs.glsl +84 -67
  248. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/norm.comp +10 -10
  249. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/repeat_back.comp +3 -3
  250. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/roll.comp +3 -3
  251. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp +3 -3
  252. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/unary.comp +168 -0
  253. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +121 -74
  254. data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp +26 -19
  255. data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu.cpp +31 -36
  256. data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/common_decls.tmpl +16 -2
  257. data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_split.wgsl +7 -7
  258. data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/get_rows.wgsl +21 -0
  259. data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_decls.tmpl +439 -320
  260. data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id_vec.wgsl +2 -2
  261. data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec.wgsl +45 -39
  262. data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec_acc.tmpl +586 -465
  263. data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec_q_acc.tmpl +63 -69
  264. data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/quantize_q8.wgsl +14 -9
  265. data/ext/sources/ggml/src/ggml.c +36 -14
  266. data/ext/sources/include/whisper.h +21 -0
  267. data/ext/sources/src/whisper.cpp +164 -14
  268. data/lib/whisper/log_settable.rb +5 -8
  269. data/lib/whisper/model/uri.rb +0 -7
  270. data/sig/whisper.rbs +6 -0
  271. data/test/test_vad.rb +9 -0
  272. data/test/test_vad_context.rb +2 -2
  273. data/whispercpp.gemspec +1 -1
  274. metadata +62 -37
  275. data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-flash-attn-ops.c +0 -1878
  276. data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-matmul-ops.c +0 -2066
  277. data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-ops.c +0 -6
  278. data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-ops.h +0 -88
  279. data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-profile.h +0 -34
  280. data/ext/sources/ggml/src/ggml-hexagon/htp/vtcm-utils.h +0 -16
  281. data/ext/sources/ggml/src/ggml-openvino/openvino/op/unary_gelu.cpp +0 -25
  282. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/abs.comp +0 -21
  283. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/ceil.comp +0 -22
  284. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp +0 -17
  285. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/cos.comp +0 -17
  286. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/elu.comp +0 -27
  287. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/exp.comp +0 -20
  288. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/floor.comp +0 -22
  289. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu.comp +0 -25
  290. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu_erf.comp +0 -39
  291. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu_quick.comp +0 -23
  292. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/hardsigmoid.comp +0 -22
  293. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/hardswish.comp +0 -22
  294. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/leaky_relu.comp +0 -22
  295. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/neg.comp +0 -20
  296. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/relu.comp +0 -21
  297. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/round.comp +0 -29
  298. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sgn.comp +0 -21
  299. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sigmoid.comp +0 -20
  300. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/silu.comp +0 -22
  301. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sin.comp +0 -17
  302. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/softplus.comp +0 -23
  303. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sqrt.comp +0 -17
  304. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/square.comp +0 -17
  305. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/step.comp +0 -22
  306. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/tanh.comp +0 -20
  307. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/trunc.comp +0 -22
  308. data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/xielu.comp +0 -35
@@ -23,6 +23,7 @@
23
23
  #define HTP_ROPE_TYPE_NORMAL 0
24
24
  #define HTP_ROPE_TYPE_NEOX 2
25
25
  #define HTP_ROPE_TYPE_MROPE 8
26
+ #define HTP_ROPE_TYPE_VISION 24
26
27
  #define HTP_ROPE_TYPE_IMROPE 40
27
28
 
28
29
  #define HTP_ROPE_SPAD_NROWS 16
@@ -70,7 +71,9 @@ struct htp_rope_context {
70
71
  struct htp_ops_context * octx;
71
72
 
72
73
  size_t src0_row_size;
74
+ size_t src0_row_stride;
73
75
  size_t dst_row_size;
76
+ size_t dst_row_stride;
74
77
  size_t src0_row_size_aligned;
75
78
  size_t dst_row_size_aligned;
76
79
  size_t theta_cache_offset;
@@ -210,6 +213,7 @@ static __attribute__((noinline)) void mrope_cache_init(const float pos_t,
210
213
  const float pos_e,
211
214
  const int32_t sections[4],
212
215
  const bool is_imrope,
216
+ const bool indep_sects,
213
217
  const float freq_scale,
214
218
  const float * freq_factors,
215
219
  float * corr_dims,
@@ -231,6 +235,14 @@ static __attribute__((noinline)) void mrope_cache_init(const float pos_t,
231
235
  const float ff = freq_factors ? freq_factors[i0 / 2] : 1.0f;
232
236
  const int sector = (i0 / 2) % sect_dims;
233
237
 
238
+ if (indep_sects) {
239
+ // Reset theta when crossing into a new section.
240
+ if (sector == 0) { theta_t = pos_t; }
241
+ else if (sector == sections[0]) { theta_h = pos_h; }
242
+ else if (sector == sec_w) { theta_w = pos_w; }
243
+ else if (sector == sec_e) { theta_e = pos_e; }
244
+ }
245
+
234
246
  float theta;
235
247
  if (is_imrope) {
236
248
  // Interleaved: sector mod 3 selects component
@@ -422,6 +434,17 @@ static void inline rope_neox_f32(struct htp_rope_context * rctx, uint8_t * restr
422
434
  }
423
435
  }
424
436
 
437
+ static void inline rope_vision_f32(struct htp_rope_context * rctx, uint8_t * restrict dst, uint8_t * restrict src,
438
+ uint32_t nr, uint32_t ne0, const float * restrict theta_cache) {
439
+ #pragma unroll(4)
440
+ for (uint32_t i = 0; i < nr; i++) {
441
+ float * d = (float *) (dst + i * rctx->dst_row_size_aligned);
442
+ float * s = (float *) (src + i * rctx->src0_row_size_aligned);
443
+
444
+ hvx_rope_neox_f32_aa(d, s, ne0, theta_cache);
445
+ }
446
+ }
447
+
425
448
  static void rope_job_f32(unsigned int nth, unsigned int ith, void * data) {
426
449
  struct htp_rope_context * rctx = (struct htp_rope_context *) data;
427
450
  struct htp_ops_context * octx = rctx->octx;
@@ -447,8 +470,9 @@ static void rope_job_f32(unsigned int nth, unsigned int ith, void * data) {
447
470
  uint64_t tt = HAP_perf_get_qtimer_count();
448
471
 
449
472
  const int32_t mode = rctx->mode;
450
- // MROPE and IMROPE use NEOX-style pairing for the rotation
473
+ // MROPE, IMROPE and VISION use NEOX-style pairing for the rotation
451
474
  const bool is_neox = (mode & HTP_ROPE_TYPE_NEOX) || (mode & HTP_ROPE_TYPE_MROPE);
475
+ const bool is_vision = (mode == HTP_ROPE_TYPE_VISION);
452
476
 
453
477
  // VTCM setup
454
478
  uint8_t * src0_spad_base = octx->src0_spad.data + (ith * octx->src0_spad.size_per_thread);
@@ -496,8 +520,10 @@ static void rope_job_f32(unsigned int nth, unsigned int ith, void * data) {
496
520
 
497
521
  const uint8_t * src_addr = (const uint8_t *) src0->data + i3 * nb03 + i2 * nb02 + pi1 * nb01;
498
522
  uint8_t * src_spad = src0_spad_base + pr * rctx->src0_row_size_aligned;
499
- dma_queue_push_ddr_to_vtcm(dma_queue, dma_make_ptr(src_spad, src_addr),
500
- rctx->src0_row_size_aligned, rctx->src0_row_size, pnr);
523
+
524
+ // Copy only the row payload while striding the DDR source
525
+ dma_queue_push(dma_queue, dma_make_ptr(src_spad, src_addr),
526
+ rctx->src0_row_size_aligned, rctx->src0_row_stride, rctx->src0_row_size, pnr);
501
527
 
502
528
  // FARF(HIGH, "rope-prefetch %u: pr %u i1 %u i2 %u i3 %u src-spad %p src-addr %p pnr %u", ith, pir, pi1, i2, i3, src_spad, src_addr, pnr);
503
529
  }
@@ -516,7 +542,7 @@ static void rope_job_f32(unsigned int nth, unsigned int ith, void * data) {
516
542
  (float) pos[i2 + ne2],
517
543
  (float) pos[i2 + ne2 * 2],
518
544
  (float) pos[i2 + ne2 * 3],
519
- rctx->sections, is_imrope,
545
+ rctx->sections, is_imrope, is_vision,
520
546
  rctx->freq_scale, freq_factors, rctx->corr_dims,
521
547
  ne0, rctx->ext_factor, rctx->attn_factor,
522
548
  theta_cache, rctx->theta_scale);
@@ -542,14 +568,19 @@ static void rope_job_f32(unsigned int nth, unsigned int ith, void * data) {
542
568
  // FARF(HIGH, "rope-compute %u: ir %u i1 %u i2 %u i3 %u src-spad %p cnr %u : usec %u", ith, ir, i1, i2, i3, src_spad, cnr,
543
569
  // (unsigned) HAP_perf_qtimer_count_to_us(HAP_perf_get_qtimer_count() - rctx->t_start));
544
570
 
545
- if (is_neox) {
571
+ if (is_vision) {
572
+ rope_vision_f32(rctx, dst_spad, src_spad, cnr, ne0, theta_cache);
573
+ } else if (is_neox) {
546
574
  rope_neox_f32(rctx, dst_spad, src_spad, cnr, ne0, theta_cache);
547
575
  } else {
548
576
  rope_basic_f32(rctx, dst_spad, src_spad, cnr, ne0, theta_cache);
549
577
  }
550
578
 
551
579
  uint8_t * dst_addr = (uint8_t *) dst->data + i3 * nb3 + i2 * nb2 + i1 * nb1;
552
- dma_queue_push_vtcm_to_ddr(dma_queue, dma_make_ptr(dst_addr, dst_spad), rctx->dst_row_size, rctx->dst_row_size_aligned, cnr);
580
+
581
+ // Write only the row payload while striding the DDR dst
582
+ dma_queue_push(dma_queue, dma_make_ptr(dst_addr, dst_spad),
583
+ rctx->dst_row_stride, rctx->dst_row_size_aligned, rctx->dst_row_size, cnr);
553
584
 
554
585
  // Prefetch more rows (if any)
555
586
  if ((cr + HTP_ROPE_SPAD_NROWS) < nrows) {
@@ -558,8 +589,8 @@ static void rope_job_f32(unsigned int nth, unsigned int ith, void * data) {
558
589
  uint32_t pir = ir + HTP_ROPE_SPAD_NROWS;
559
590
 
560
591
  const uint8_t * src_addr = (const uint8_t *) src0->data + i3 * nb03 + i2 * nb02 + pi1 * nb01;
561
- dma_queue_push_ddr_to_vtcm(dma_queue, dma_make_ptr(src_spad, src_addr),
562
- rctx->src0_row_size_aligned, rctx->src0_row_size, pnr);
592
+ dma_queue_push(dma_queue, dma_make_ptr(src_spad, src_addr),
593
+ rctx->src0_row_size_aligned, rctx->src0_row_stride, rctx->src0_row_size, pnr);
563
594
 
564
595
  // FARF(HIGH, "rope-prefetch %u: pr %u i1 %u i2 %u i3 %u src-spad %p src-addr %p pnr %u", ith, pir, pi1, i2, i3, src_spad, src_addr, pnr);
565
596
  }
@@ -598,12 +629,14 @@ static int execute_op_rope_f32(struct htp_ops_context * octx) {
598
629
  const uint32_t src0_nrows = src0->ne[1] * src0->ne[2] * src0->ne[3];
599
630
  const uint32_t n_threads = MIN(octx->n_threads, src0_nrows);
600
631
 
601
- const size_t src0_row_size = src0->nb[1];
602
- const size_t dst_row_size = dst->nb[1];
632
+ const size_t src0_row_size = src0->ne[0] * sizeof(float);
633
+ const size_t src0_row_stride = src0->nb[1];
634
+ const size_t dst_row_size = dst->ne[0] * sizeof(float);
635
+ const size_t dst_row_stride = dst->nb[1];
603
636
 
604
637
  // Aligned row sizes for VTCM
605
638
  const size_t src0_row_size_aligned = hex_round_up(src0_row_size, VLEN);
606
- const size_t dst_row_size_aligned = hex_round_up(dst_row_size, VLEN);
639
+ const size_t dst_row_size_aligned = hex_round_up(dst_row_stride, VLEN);
607
640
  const size_t theta_cache_size_aligned = hex_round_up(src0->ne[0] * sizeof(float), 256);
608
641
 
609
642
  // Calculate spad sizes per thread
@@ -652,8 +685,10 @@ static int execute_op_rope_f32(struct htp_ops_context * octx) {
652
685
 
653
686
  rope_corr_dims(rctx.n_dims, rctx.n_ctx_orig, rctx.freq_base, rctx.beta_fast, rctx.beta_slow, rctx.corr_dims);
654
687
 
655
- rctx.src0_row_size = src0_row_size;
656
- rctx.dst_row_size = dst_row_size;
688
+ rctx.src0_row_size = src0_row_size;
689
+ rctx.src0_row_stride = src0_row_stride;
690
+ rctx.dst_row_size = dst_row_size;
691
+ rctx.dst_row_stride = dst_row_stride;
657
692
  rctx.src0_row_size_aligned = src0_row_size_aligned;
658
693
  rctx.dst_row_size_aligned = dst_row_size_aligned;
659
694
  rctx.theta_cache_offset = theta_cache_size_aligned;
@@ -183,24 +183,25 @@ static inline void hvx_transpose_32x32_f32(HVX_Vector m[32]) {
183
183
  // transposed into VTCM.
184
184
  //
185
185
  // VTCM layouts (per thread):
186
- // src1_T : {d_inner_per_thread, d_conv} staged once per launch (small).
187
- // src0_T : {d_inner_tile, ncs} staged per d_inner-tile.
186
+ // src1_T : {d_inner_stride, d_conv} - staged once per launch (small).
187
+ // src0_T : {d_inner_tile, ncs} - staged per d_inner-tile.
188
188
  //
189
189
  // d_inner_tile is chosen so that per-thread VTCM stays under the budget.
190
190
  // Each thread iterates ceil(d_inner_per_thread d_inner_tile) tiles serially.
191
191
  #define HTP_SSM_CONV_VTCM_BUDGET (1u << 20) // 1 MiB per thread
192
192
 
193
- // Scalar transpose: src1 {d_conv, d_inner} (DDR) -> {d_inner_per_thread, d_conv} (VTCM)
193
+ // Scalar transpose: src1 {d_conv, d_inner} (DDR) -> {d_inner_stride, d_conv} (VTCM)
194
194
  static inline void transpose_src1(const float * src1_data,
195
195
  uint32_t src1_stride_inner,
196
196
  uint32_t i1_off,
197
197
  uint32_t d_inner_per_thread,
198
+ uint32_t d_inner_stride,
198
199
  uint32_t d_conv,
199
200
  float * src1_T) {
200
201
  for (uint32_t i = 0; i < d_inner_per_thread; ++i) {
201
202
  const float * src_row = src1_data + (i1_off + i) * src1_stride_inner;
202
203
  for (uint32_t j = 0; j < d_conv; ++j) {
203
- src1_T[j * d_inner_per_thread + i] = src_row[j];
204
+ src1_T[j * d_inner_stride + i] = src_row[j];
204
205
  }
205
206
  }
206
207
  }
@@ -280,6 +281,7 @@ static void ssm_conv_thread_f32_f32_hvx(unsigned int nth, unsigned int ith, void
280
281
  }
281
282
 
282
283
  const uint32_t d_inner_per_thread = ir1 - ir0;
284
+ const uint32_t d_inner_stride = scctx->nrows_per_thread;
283
285
  const uint32_t d_inner_tile = scctx->d_inner_tile;
284
286
 
285
287
  const float * src0_data = (const float *) src0->data;
@@ -290,8 +292,8 @@ static void ssm_conv_thread_f32_f32_hvx(unsigned int nth, unsigned int ith, void
290
292
  float * src0_T = (float *)(octx->src0_spad.data + ith * octx->src0_spad.size_per_thread);
291
293
  float * src1_T = (float *)(octx->src1_spad.data + ith * octx->src1_spad.size_per_thread);
292
294
 
293
- // Stage src1 weights once into VTCM in {d_inner_per_thread, d_conv} layout.
294
- transpose_src1(src1_data, src1_stride_inner, ir0, d_inner_per_thread, d_conv, src1_T);
295
+ // Stage src1 weights once into VTCM in {d_inner_stride, d_conv} layout.
296
+ transpose_src1(src1_data, src1_stride_inner, ir0, d_inner_per_thread, d_inner_stride, d_conv, src1_T);
295
297
 
296
298
  const uint32_t C_TILE = VLEN_FP32;
297
299
 
@@ -314,7 +316,7 @@ static void ssm_conv_thread_f32_f32_hvx(unsigned int nth, unsigned int ith, void
314
316
  HVX_Vector acc = hvx_vec_splat_f32(0.0f);
315
317
  for (uint32_t j = 0; j < d_conv; ++j) {
316
318
  HVX_Vector x = *(const HVX_Vector *) (src0_T + (t + j) * d_inner_tile + cb);
317
- HVX_Vector w = *(const HVX_Vector *) (src1_T + j * d_inner_per_thread + tile_off + cb);
319
+ HVX_Vector w = *(const HVX_Vector *) (src1_T + j * d_inner_stride + tile_off + cb);
318
320
  acc = Q6_Vqf32_vadd_Vqf32Vqf32(acc, Q6_Vqf32_vmpy_VsfVsf(x, w));
319
321
  }
320
322
  HVX_Vector res = Q6_Vsf_equals_Vqf32(acc);
@@ -362,8 +364,7 @@ int op_ssm_conv_f32(struct htp_ops_context * octx) {
362
364
  use_hvx = 1;
363
365
  }
364
366
 
365
- scctx.nrows_per_thread = (d_inner + n_threads - 1) / n_threads;
366
- scctx.nrows_per_thread += (scctx.nrows_per_thread & 1);
367
+ scctx.nrows_per_thread = hex_round_up((d_inner + n_threads - 1) / n_threads, VLEN_FP32);
367
368
 
368
369
  const uint32_t d_inner_per_thread = scctx.nrows_per_thread;
369
370
  const uint32_t ncs = src0->ne[0];
@@ -1,6 +1,9 @@
1
1
  #include "worker-pool.h"
2
+ #include "hex-utils.h"
2
3
 
3
4
  #include <qurt.h>
5
+ #include <qurt_hvx.h>
6
+
4
7
  #include <stdatomic.h>
5
8
  #include <stdint.h>
6
9
  #include <stdio.h>
@@ -9,7 +12,6 @@
9
12
 
10
13
  #include "HAP_farf.h"
11
14
 
12
- #define WORKER_THREAD_STACK_SZ (2 * 16384)
13
15
  #define LOWEST_USABLE_QURT_PRIO (254)
14
16
 
15
17
  struct worker_pool_s;
@@ -42,17 +44,27 @@ static void worker_pool_main(void * context) {
42
44
  FARF(HIGH, "worker-pool: thread %u started", me->id);
43
45
 
44
46
  unsigned int prev_seqn = 0;
47
+ unsigned int poll_cnt = WORKER_POOL_POLL_COUNT;
45
48
  while (!atomic_load(&pool->killed)) {
46
49
  unsigned int seqn = atomic_load(&pool->seqn);
47
50
  if (seqn == prev_seqn) {
48
- // Nothing to do
51
+ // drop HVX context while spinning
52
+ if (poll_cnt > 1 && poll_cnt == WORKER_POOL_POLL_COUNT) {
53
+ qurt_hvx_unlock();
54
+ }
55
+ if (--poll_cnt) {
56
+ hex_pause();
57
+ continue;
58
+ }
49
59
  qurt_futex_wait(&pool->seqn, prev_seqn);
60
+ poll_cnt = WORKER_POOL_POLL_COUNT;
50
61
  continue;
51
62
  }
52
63
 
53
- // New job
54
64
  prev_seqn = seqn;
65
+ poll_cnt = WORKER_POOL_POLL_COUNT;
55
66
 
67
+ // New job
56
68
  unsigned int n = atomic_load(&pool->n_jobs);
57
69
  unsigned int i = atomic_fetch_add(&pool->next_job, 1);
58
70
  if (i >= n) {
@@ -24,9 +24,17 @@ typedef struct {
24
24
  void * data;
25
25
  } worker_pool_job_t;
26
26
 
27
+ #define WORKER_THREAD_STACK_SZ (2 * 16384)
28
+
27
29
  /// Maximum supported number of worker threads.
28
30
  #define MAX_NUM_WORKERS 10
29
31
 
32
+ #if __HVX_ARCH__ > 79
33
+ #define WORKER_POOL_POLL_COUNT 2000
34
+ #else
35
+ #define WORKER_POOL_POLL_COUNT 1
36
+ #endif
37
+
30
38
  // Initialize worker pool.
31
39
  WORKERPOOL_API AEEResult worker_pool_init(worker_pool_context_t * context, uint32_t n_threads);
32
40
 
@@ -5,10 +5,13 @@
5
5
  #include "ggml-backend-impl.h"
6
6
  #include "ggml-common.h"
7
7
 
8
+ #include <algorithm>
8
9
  #include <string>
9
10
  #include <vector>
10
11
  #include <stdio.h>
11
12
  #include "htp-ops.h"
13
+ #include "htp/matmul-ops.h"
14
+ #include "htp/flash-attn-ops.h"
12
15
 
13
16
  struct htp_opnode {
14
17
  ggml_tensor * node = nullptr;
@@ -17,6 +20,13 @@ struct htp_opnode {
17
20
 
18
21
  htp_op_code opcode = HTP_OP_INVALID;
19
22
 
23
+ std::vector<ggml_tensor *> extra_dsts;
24
+
25
+ int32_t kernel_params[HTP_OP_MAX_KERN_PARAMS] = {0};
26
+
27
+ htp_opnode(ggml_tensor * node = nullptr, std::vector<ggml_tensor *> fused = {}, htp_op_code opcode = HTP_OP_INVALID, std::vector<ggml_tensor *> extra_dsts = {})
28
+ : node(node), fused(std::move(fused)), opcode(opcode), extra_dsts(std::move(extra_dsts)) {}
29
+
20
30
  ggml_op op() const {
21
31
  return node->op;
22
32
  }
@@ -25,6 +35,26 @@ struct htp_opnode {
25
35
  return fused.empty() ? node : fused.back();
26
36
  }
27
37
 
38
+ void add_fused(ggml_tensor * t, bool extra_dst = false) {
39
+ fused.push_back(t);
40
+ if (extra_dst) {
41
+ extra_dsts.push_back(t);
42
+ }
43
+ }
44
+
45
+ std::vector<const ggml_tensor *> get_outputs() const {
46
+ std::vector<const ggml_tensor *> res;
47
+ if (extra_dsts.empty()) {
48
+ res.push_back(dst());
49
+ } else {
50
+ res.push_back(node);
51
+ for (const auto * x : extra_dsts) {
52
+ res.push_back(x);
53
+ }
54
+ }
55
+ return res;
56
+ }
57
+
28
58
  const ggml_tensor * src0() const {
29
59
  return node->src[0];
30
60
  }
@@ -37,10 +67,6 @@ struct htp_opnode {
37
67
  return ggml_op_is_empty(node->op);
38
68
  }
39
69
 
40
- void add_fused(ggml_tensor * t) {
41
- fused.push_back(t);
42
- }
43
-
44
70
  bool stackable() const {
45
71
  switch (this->op()) {
46
72
  case GGML_OP_MUL_MAT:
@@ -131,87 +157,117 @@ struct htp_opformat {
131
157
  char types[16 * GGML_MAX_SRC];
132
158
  char buffs[64 * GGML_MAX_SRC];
133
159
  char names[64 * GGML_MAX_SRC];
160
+ char kparams[128];
134
161
 
135
- int format_tensor_dims(char * str, const struct ggml_tensor * t) {
162
+ int format_tensor_dims(char * str, size_t max_size, const struct ggml_tensor * t) {
136
163
  if (!t) {
137
- return sprintf(str, "NONE");
164
+ return snprintf(str, max_size, "NONE");
138
165
  }
139
166
  if (t->ne[2] == 1 && t->ne[3] == 1) {
140
- return sprintf(str, "%d:%d", (int) t->ne[0], (int) t->ne[1]);
167
+ return snprintf(str, max_size, "%d:%d", (int) t->ne[0], (int) t->ne[1]);
141
168
  } else {
142
- return sprintf(str, "%d:%d:%d:%d", (int) t->ne[0], (int) t->ne[1], (int) t->ne[2], (int) t->ne[3]);
169
+ return snprintf(str, max_size, "%d:%d:%d:%d", (int) t->ne[0], (int) t->ne[1], (int) t->ne[2], (int) t->ne[3]);
143
170
  }
144
171
  }
145
172
 
146
- void format_op_dims(char * str, const htp_opnode & node) {
173
+ void format_op_dims(char * str, size_t max_size, const htp_opnode & node) {
147
174
  char * p = str;
175
+ char * p_end = str + max_size;
148
176
  auto inputs = node.get_inputs();
149
177
 
150
178
  if (!inputs.empty()) {
151
- p += format_tensor_dims(p, inputs[0]);
179
+ p += std::min((size_t)format_tensor_dims(p, p_end - p, inputs[0]), (size_t)(p_end - p));
152
180
 
153
181
  for (size_t i = 1; i < inputs.size(); i++) {
154
- p += sprintf(p, " x ");
155
- p += format_tensor_dims(p, inputs[i]);
182
+ if (p < p_end) {
183
+ p += std::min((size_t)snprintf(p, p_end - p, " x "), (size_t)(p_end - p));
184
+ }
185
+ if (p < p_end) {
186
+ p += std::min((size_t)format_tensor_dims(p, p_end - p, inputs[i]), (size_t)(p_end - p));
187
+ }
156
188
  }
157
189
 
158
- p += sprintf(p, " -> ");
190
+ if (p < p_end) {
191
+ p += std::min((size_t)snprintf(p, p_end - p, " -> "), (size_t)(p_end - p));
192
+ }
159
193
  }
160
194
 
161
195
  char self[64];
162
- format_tensor_dims(self, node.dst());
163
- p += sprintf(p, "%s", self);
196
+ format_tensor_dims(self, sizeof(self), node.dst());
197
+ if (p < p_end) {
198
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", self), (size_t)(p_end - p));
199
+ }
164
200
  }
165
201
 
166
- int format_tensor_strides(char * str, const struct ggml_tensor * t) {
202
+ int format_tensor_strides(char * str, size_t max_size, const struct ggml_tensor * t) {
167
203
  if (!t) {
168
- return sprintf(str, "NONE");
204
+ return snprintf(str, max_size, "NONE");
169
205
  }
170
206
  const char * c = ggml_is_contiguous(t) ? "" : "!";
171
207
 
172
208
  if (t->ne[2] == 1 && t->ne[3] == 1) {
173
- return sprintf(str, "%zu:%zu%s", (size_t) t->nb[0], (size_t) t->nb[1], c);
209
+ return snprintf(str, max_size, "%zu:%zu%s", (size_t) t->nb[0], (size_t) t->nb[1], c);
174
210
  } else {
175
- return sprintf(str, "%zu:%zu:%zu:%zu%s", (size_t) t->nb[0], (size_t) t->nb[1], (size_t) t->nb[2], (size_t) t->nb[3], c);
211
+ return snprintf(str, max_size, "%zu:%zu:%zu:%zu%s", (size_t) t->nb[0], (size_t) t->nb[1], (size_t) t->nb[2], (size_t) t->nb[3], c);
176
212
  }
177
213
  }
178
214
 
179
- void format_op_strides(char * str, const htp_opnode & node) {
215
+ void format_op_strides(char * str, size_t max_size, const htp_opnode & node) {
180
216
  char * p = str;
217
+ char * p_end = str + max_size;
181
218
  auto inputs = node.get_inputs();
182
219
 
183
220
  if (!inputs.empty()) {
184
- p += format_tensor_strides(p, inputs[0]);
221
+ p += std::min((size_t)format_tensor_strides(p, p_end - p, inputs[0]), (size_t)(p_end - p));
185
222
 
186
223
  for (size_t i = 1; i < inputs.size(); i++) {
187
- p += sprintf(p, " x ");
188
- p += format_tensor_strides(p, inputs[i]);
224
+ if (p < p_end) {
225
+ p += std::min((size_t)snprintf(p, p_end - p, " x "), (size_t)(p_end - p));
226
+ }
227
+ if (p < p_end) {
228
+ p += std::min((size_t)format_tensor_strides(p, p_end - p, inputs[i]), (size_t)(p_end - p));
229
+ }
189
230
  }
190
231
 
191
- p += sprintf(p, " -> ");
232
+ if (p < p_end) {
233
+ p += std::min((size_t)snprintf(p, p_end - p, " -> "), (size_t)(p_end - p));
234
+ }
192
235
  }
193
236
 
194
237
  char self[64];
195
- format_tensor_strides(self, node.dst());
196
- p += sprintf(p, "%s", self);
238
+ format_tensor_strides(self, sizeof(self), node.dst());
239
+ if (p < p_end) {
240
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", self), (size_t)(p_end - p));
241
+ }
197
242
  }
198
243
 
199
- void format_op_types(char * str, const htp_opnode & node) {
244
+ void format_op_types(char * str, size_t max_size, const htp_opnode & node) {
200
245
  char * p = str;
246
+ char * p_end = str + max_size;
201
247
  auto inputs = node.get_inputs();
202
248
 
203
249
  if (!inputs.empty()) {
204
- p += sprintf(p, "%s", inputs[0] ? ggml_type_name(inputs[0]->type) : "NONE");
250
+ if (p < p_end) {
251
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", inputs[0] ? ggml_type_name(inputs[0]->type) : "NONE"), (size_t)(p_end - p));
252
+ }
205
253
 
206
254
  for (size_t i = 1; i < inputs.size(); i++) {
207
- p += sprintf(p, " x ");
208
- p += sprintf(p, "%s", inputs[i] ? ggml_type_name(inputs[i]->type) : "NONE");
255
+ if (p < p_end) {
256
+ p += std::min((size_t)snprintf(p, p_end - p, " x "), (size_t)(p_end - p));
257
+ }
258
+ if (p < p_end) {
259
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", inputs[i] ? ggml_type_name(inputs[i]->type) : "NONE"), (size_t)(p_end - p));
260
+ }
209
261
  }
210
262
 
211
- p += sprintf(p, " -> ");
263
+ if (p < p_end) {
264
+ p += std::min((size_t)snprintf(p, p_end - p, " -> "), (size_t)(p_end - p));
265
+ }
212
266
  }
213
267
 
214
- p += sprintf(p, "%s", ggml_type_name(node.dst()->type));
268
+ if (p < p_end) {
269
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", ggml_type_name(node.dst()->type)), (size_t)(p_end - p));
270
+ }
215
271
  }
216
272
 
217
273
  const char * tensor_buff_name(const struct ggml_tensor * t) {
@@ -221,51 +277,113 @@ struct htp_opformat {
221
277
  return "NONE";
222
278
  }
223
279
 
224
- void format_op_buffs(char * str, const htp_opnode & node) {
280
+ void format_op_buffs(char * str, size_t max_size, const htp_opnode & node) {
225
281
  char * p = str;
282
+ char * p_end = str + max_size;
226
283
  auto inputs = node.get_inputs();
227
284
 
228
285
  if (!inputs.empty()) {
229
- p += sprintf(p, "%s", tensor_buff_name(inputs[0]));
286
+ if (p < p_end) {
287
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", tensor_buff_name(inputs[0])), (size_t)(p_end - p));
288
+ }
230
289
 
231
290
  for (size_t i = 1; i < inputs.size(); i++) {
232
- p += sprintf(p, " x ");
233
- p += sprintf(p, "%s", tensor_buff_name(inputs[i]));
291
+ if (p < p_end) {
292
+ p += std::min((size_t)snprintf(p, p_end - p, " x "), (size_t)(p_end - p));
293
+ }
294
+ if (p < p_end) {
295
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", tensor_buff_name(inputs[i])), (size_t)(p_end - p));
296
+ }
234
297
  }
235
298
 
236
- p += sprintf(p, " -> ");
299
+ if (p < p_end) {
300
+ p += std::min((size_t)snprintf(p, p_end - p, " -> "), (size_t)(p_end - p));
301
+ }
237
302
  }
238
303
 
239
- p += sprintf(p, "%s", tensor_buff_name(node.dst()));
304
+ if (p < p_end) {
305
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", tensor_buff_name(node.dst())), (size_t)(p_end - p));
306
+ }
240
307
  }
241
308
 
242
- void format_op_names(char * str, const htp_opnode & node) {
309
+ void format_op_names(char * str, size_t max_size, const htp_opnode & node) {
243
310
  char * p = str;
311
+ char * p_end = str + max_size;
244
312
  auto inputs = node.get_inputs();
245
313
 
246
314
  if (!inputs.empty()) {
247
- p += sprintf(p, "%s", inputs[0] ? inputs[0]->name : "NONE");
315
+ if (p < p_end) {
316
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", inputs[0] ? inputs[0]->name : "NONE"), (size_t)(p_end - p));
317
+ }
248
318
 
249
319
  for (size_t i = 1; i < inputs.size(); i++) {
250
- p += sprintf(p, " x ");
251
- p += sprintf(p, "%s", inputs[i] ? inputs[i]->name : "NONE");
320
+ if (p < p_end) {
321
+ p += std::min((size_t)snprintf(p, p_end - p, " x "), (size_t)(p_end - p));
322
+ }
323
+ if (p < p_end) {
324
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", inputs[i] ? inputs[i]->name : "NONE"), (size_t)(p_end - p));
325
+ }
252
326
  }
253
327
 
254
- p += sprintf(p, " -> ");
328
+ if (p < p_end) {
329
+ p += std::min((size_t)snprintf(p, p_end - p, " -> "), (size_t)(p_end - p));
330
+ }
255
331
  }
256
332
 
257
- p += sprintf(p, "%s", node.dst()->name);
333
+ if (p < p_end) {
334
+ p += std::min((size_t)snprintf(p, p_end - p, "%s", node.dst()->name), (size_t)(p_end - p));
335
+ }
336
+ }
337
+ void format_kernel_params(char * str, size_t max_size, const htp_opnode & node) {
338
+ if (node.opcode == HTP_OP_MUL_MAT || node.opcode == HTP_OP_MUL_MAT_ID ||
339
+ node.opcode == HTP_OP_MUL_MAT_QKV || node.opcode == HTP_OP_MUL_MAT_FFN ||
340
+ node.opcode == HTP_OP_MUL_MAT_ADD) {
341
+ const auto * kparams = (const struct htp_mm_kernel_params *) node.kernel_params;
342
+ const char * path = "unknown";
343
+ int32_t type = kparams->kernel_type;
344
+ if (type == HTP_MM_KERNEL_HMX_2D || type == HTP_MM_KERNEL_HMX_F16_BATCHED) {
345
+ path = "hmx-tiled";
346
+ } else if (type == HTP_MM_KERNEL_HVX_F16_F16_VTCM || type == HTP_MM_KERNEL_HVX_F32_F32_VTCM ||
347
+ type == HTP_MM_KERNEL_HVX_QUANT_ROW || type == HTP_MM_KERNEL_HVX_QUANT_BLOCK) {
348
+ path = "hvx-tiled";
349
+ } else if (type == HTP_MM_KERNEL_HVX_F16_F16_DDR || type == HTP_MM_KERNEL_HVX_F16_F32_DDR ||
350
+ type == HTP_MM_KERNEL_HVX_F32_F32_DDR || type == HTP_MM_KERNEL_HVX_F32_F16_DDR ||
351
+ type == HTP_MM_KERNEL_HVX_QUANT_ROW_FLAT) {
352
+ path = "hvx-flat";
353
+ }
354
+ snprintf(str, max_size, "%s vtcm %d", path, (int) kparams->vtcm_size);
355
+ } else if (node.opcode == HTP_OP_FLASH_ATTN_EXT) {
356
+ const auto * kparams = (const struct htp_fa_kernel_params *) node.kernel_params;
357
+ const char * path = "unknown";
358
+ int32_t type = kparams->kernel_type;
359
+ if (type == HTP_FA_KERNEL_HMX) {
360
+ path = kparams->u.hmx.pipeline ? "hmx-pipe" : "hmx-seq";
361
+ } else if (type == HTP_FA_KERNEL_HVX) {
362
+ path = "hvx";
363
+ }
364
+ snprintf(str, max_size, "%s vtcm %d", path, (int) kparams->vtcm_size);
365
+ } else {
366
+ snprintf(str, max_size, "----");
367
+ }
258
368
  }
259
369
 
260
370
  void format(const htp_opnode & node) {
261
- format_op_dims(dims, node);
262
- format_op_strides(strides, node);
263
- format_op_types(types, node);
264
- format_op_buffs(buffs, node);
265
- format_op_names(names, node);
371
+ format_op_dims(dims, sizeof(dims), node);
372
+ format_op_strides(strides, sizeof(strides), node);
373
+ format_op_types(types, sizeof(types), node);
374
+ format_op_buffs(buffs, sizeof(buffs), node);
375
+ format_op_names(names, sizeof(names), node);
376
+ format_kernel_params(kparams, sizeof(kparams), node);
266
377
  }
267
378
 
268
- htp_opformat() {}
379
+ htp_opformat() {
380
+ strides[0] = '\0';
381
+ dims[0] = '\0';
382
+ types[0] = '\0';
383
+ buffs[0] = '\0';
384
+ names[0] = '\0';
385
+ kparams[0] = '\0';
386
+ }
269
387
  htp_opformat(const htp_opnode & node) { format(node); }
270
388
  };
271
389
 
@@ -14,8 +14,6 @@ Drivers_Dir = 13
14
14
  1 = %DiskId%
15
15
 
16
16
  [SourceDisksFiles]
17
- libggml-htp-v68.so = 1
18
- libggml-htp-v69.so = 1
19
17
  libggml-htp-v73.so = 1
20
18
  libggml-htp-v75.so = 1
21
19
  libggml-htp-v79.so = 1
@@ -28,8 +26,6 @@ ExcludeFromSelect = *
28
26
  CopyFiles=Drivers_Dir
29
27
 
30
28
  [Drivers_Dir]
31
- libggml-htp-v68.so,,,0x10 ;COPYFLG_NO_OVERWRITE
32
- libggml-htp-v69.so,,,0x10 ;COPYFLG_NO_OVERWRITE
33
29
  libggml-htp-v73.so,,,0x10 ;COPYFLG_NO_OVERWRITE
34
30
  libggml-htp-v75.so,,,0x10 ;COPYFLG_NO_OVERWRITE
35
31
  libggml-htp-v79.so,,,0x10 ;COPYFLG_NO_OVERWRITE
@@ -130,6 +130,9 @@ if (GGML_HIP_EXPORT_METRICS)
130
130
  set(CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS} -Rpass-analysis=kernel-resource-usage --save-temps")
131
131
  endif()
132
132
 
133
+ # Fast math for HIP, like CUDA's -use_fast_math. Not -ffast-math: that implies -ffinite-math-only, which breaks ggml's INFINITY masking and produces NaNs.
134
+ set(CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS} -funsafe-math-optimizations")
135
+
133
136
  if (NOT GGML_CUDA_FA)
134
137
  add_compile_definitions(GGML_CUDA_NO_FA)
135
138
  endif()
@@ -155,3 +158,5 @@ if (GGML_HIP_RCCL)
155
158
  endif()
156
159
 
157
160
  target_link_libraries(ggml-hip PRIVATE ggml-base hip::host roc::rocblas roc::hipblas)
161
+
162
+ target_compile_options(ggml-hip PRIVATE "$<$<COMPILE_LANGUAGE:HIP>:-ffast-math;-fno-finite-math-only>")