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
@@ -665,6 +665,7 @@ void ggml_compute_forward_add(
665
665
  ggml_compute_forward_add_non_quantized(params, dst);
666
666
  } break;
667
667
  case GGML_TYPE_Q1_0:
668
+ case GGML_TYPE_Q2_0:
668
669
  case GGML_TYPE_Q4_0:
669
670
  case GGML_TYPE_Q4_1:
670
671
  case GGML_TYPE_Q5_0:
@@ -1115,6 +1116,7 @@ void ggml_compute_forward_add1(
1115
1116
  }
1116
1117
  } break;
1117
1118
  case GGML_TYPE_Q1_0:
1119
+ case GGML_TYPE_Q2_0:
1118
1120
  case GGML_TYPE_Q4_0:
1119
1121
  case GGML_TYPE_Q4_1:
1120
1122
  case GGML_TYPE_Q5_0:
@@ -1245,6 +1247,7 @@ void ggml_compute_forward_acc(
1245
1247
  case GGML_TYPE_F16:
1246
1248
  case GGML_TYPE_BF16:
1247
1249
  case GGML_TYPE_Q1_0:
1250
+ case GGML_TYPE_Q2_0:
1248
1251
  case GGML_TYPE_Q4_0:
1249
1252
  case GGML_TYPE_Q4_1:
1250
1253
  case GGML_TYPE_Q5_0:
@@ -1913,7 +1916,11 @@ static void ggml_compute_forward_concat_any(
1913
1916
  GGML_ASSERT(dim >= 0 && dim < 4);
1914
1917
 
1915
1918
  int64_t o[4] = {0, 0, 0, 0};
1916
- o[dim] = src0->ne[dim];
1919
+ if (dim == 0) {
1920
+ o[dim] = src0->ne[dim]/ggml_blck_size(src0->type);
1921
+ } else {
1922
+ o[dim] = src0->ne[dim];
1923
+ }
1917
1924
 
1918
1925
  const char * x;
1919
1926
 
@@ -1921,8 +1928,8 @@ static void ggml_compute_forward_concat_any(
1921
1928
  for (int i3 = 0; i3 < ne3; i3++) {
1922
1929
  for (int i2 = ith; i2 < ne2; i2 += nth) {
1923
1930
  for (int i1 = 0; i1 < ne1; i1++) {
1924
- for (int i0 = 0; i0 < ne0; i0++) {
1925
- if (i0 < ne00 && i1 < ne01 && i2 < ne02 && i3 < ne03) {
1931
+ for (int i0 = 0; i0 < ne0/ggml_blck_size(dst->type); i0++) {
1932
+ if (i0 < ne00/ggml_blck_size(src0->type) && i1 < ne01 && i2 < ne02 && i3 < ne03) {
1926
1933
  x = (const char *)src0->data + (i0 )*nb00 + (i1 )*nb01 + (i2 )*nb02 + (i3 )*nb03;
1927
1934
  } else {
1928
1935
  x = (const char *)src1->data + (i0 - o[0])*nb10 + (i1 - o[1])*nb11 + (i2 - o[2])*nb12 + (i3 - o[3])*nb13;
@@ -2071,6 +2078,14 @@ void ggml_compute_forward_concat(
2071
2078
  ggml_tensor * dst) {
2072
2079
 
2073
2080
  const ggml_tensor * src0 = dst->src[0];
2081
+ const ggml_tensor * src1 = dst->src[1];
2082
+
2083
+ if (ggml_is_quantized(src0->type)) {
2084
+ GGML_ASSERT(ggml_is_contiguous(src0));
2085
+ GGML_ASSERT(ggml_is_contiguous(src1));
2086
+ GGML_ASSERT(src0->ne[0] % ggml_blck_size(src0->type) == 0);
2087
+ GGML_ASSERT(src1->ne[0] % ggml_blck_size(src1->type) == 0);
2088
+ }
2074
2089
 
2075
2090
  switch (src0->type) {
2076
2091
  case GGML_TYPE_F16:
@@ -3688,8 +3703,6 @@ static void ggml_compute_forward_norm_f32(
3688
3703
 
3689
3704
  GGML_ASSERT(ggml_are_same_shape(src0, dst));
3690
3705
 
3691
- GGML_ASSERT(src0->nb[0] == sizeof(float));
3692
-
3693
3706
  const int ith = params->ith;
3694
3707
  const int nth = params->nth;
3695
3708
 
@@ -3703,25 +3716,49 @@ static void ggml_compute_forward_norm_f32(
3703
3716
  for (int64_t i03 = 0; i03 < ne03; i03++) {
3704
3717
  for (int64_t i02 = 0; i02 < ne02; i02++) {
3705
3718
  for (int64_t i01 = ith; i01 < ne01; i01 += nth) {
3706
- const float * x = (float *) ((char *) src0->data + i01*nb01 + i02*nb02 + i03*nb03);
3719
+ const char * x = (const char *) src0->data + i01*nb01 + i02*nb02 + i03*nb03;
3720
+ char * y = (char *) dst->data + i01*nb1 + i02*nb2 + i03*nb3;
3707
3721
 
3708
- float sum = 0.0;
3709
- ggml_vec_sum_f32(ne00, &sum, x);
3710
- float mean = sum/ne00;
3722
+ if (nb00 == sizeof(float) && nb0 == sizeof(float)) {
3723
+ const float * xf = (const float *) x;
3711
3724
 
3712
- float * y = (float *) ((char *) dst->data + i01*nb1 + i02*nb2 + i03*nb3);
3713
- float variance = 0;
3725
+ float sum = 0.0;
3726
+ ggml_vec_sum_f32(ne00, &sum, xf);
3727
+ float mean = sum/ne00;
3728
+
3729
+ float * yf = (float *) y;
3730
+ float variance = 0;
3714
3731
 
3715
3732
  #ifdef GGML_USE_ACCELERATE
3716
- mean = -mean;
3717
- vDSP_vsadd(x, 1, &mean, y, 1, ne00);
3718
- vDSP_measqv(y, 1, &variance, ne00);
3733
+ mean = -mean;
3734
+ vDSP_vsadd(xf, 1, &mean, yf, 1, ne00);
3735
+ vDSP_measqv(yf, 1, &variance, ne00);
3719
3736
  #else
3720
- variance = ggml_vec_cvar_f32(ne00, y, x, mean);
3737
+ variance = ggml_vec_cvar_f32(ne00, yf, xf, mean);
3721
3738
  #endif //GGML_USE_ACCELERATE
3722
3739
 
3723
- const float scale = 1.0f/sqrtf(variance + eps);
3724
- ggml_vec_scale_f32(ne00, y, scale);
3740
+ const float scale = 1.0f/sqrtf(variance + eps);
3741
+ ggml_vec_scale_f32(ne00, yf, scale);
3742
+ } else {
3743
+ float sum = 0.0;
3744
+ for (int64_t i00 = 0; i00 < ne00; i00++) {
3745
+ sum += *(const float *) (x + i00*nb00);
3746
+ }
3747
+ const float mean = sum/ne00;
3748
+
3749
+ float variance = 0.0f;
3750
+ for (int64_t i00 = 0; i00 < ne00; i00++) {
3751
+ const float v = *(const float *) (x + i00*nb00) - mean;
3752
+ *(float *) (y + i00*nb0) = v;
3753
+ variance += v * v;
3754
+ }
3755
+ variance /= ne00;
3756
+
3757
+ const float scale = 1.0f/sqrtf(variance + eps);
3758
+ for (int64_t i00 = 0; i00 < ne00; i00++) {
3759
+ *(float *) (y + i00*nb0) *= scale;
3760
+ }
3761
+ }
3725
3762
  }
3726
3763
  }
3727
3764
  }
@@ -4142,8 +4179,6 @@ static void ggml_compute_forward_l2_norm_f32(
4142
4179
 
4143
4180
  GGML_ASSERT(ggml_are_same_shape(src0, dst));
4144
4181
 
4145
- GGML_ASSERT(src0->nb[0] == sizeof(float));
4146
-
4147
4182
  const int ith = params->ith;
4148
4183
  const int nth = params->nth;
4149
4184
 
@@ -4158,20 +4193,27 @@ static void ggml_compute_forward_l2_norm_f32(
4158
4193
  for (int64_t i03 = 0; i03 < ne03; i03++) {
4159
4194
  for (int64_t i02 = 0; i02 < ne02; i02++) {
4160
4195
  for (int64_t i01 = ith; i01 < ne01; i01 += nth) {
4161
- const float * x = (float *) ((char *) src0->data + i01*nb01 + i02*nb02 + i03*nb03);
4196
+ const char * x = (const char *) src0->data + i01*nb01 + i02*nb02 + i03*nb03;
4162
4197
 
4163
4198
  ggml_float sum = 0.0;
4164
4199
  for (int64_t i00 = 0; i00 < ne00; i00++) {
4165
- sum += (ggml_float)(x[i00] * x[i00]);
4200
+ const float xi = *(const float *) (x + i00*nb00);
4201
+ sum += (ggml_float)(xi * xi);
4166
4202
  }
4167
4203
 
4168
- float * y = (float *) ((char *) dst->data + i01*nb1 + i02*nb2 + i03*nb3);
4169
-
4170
- memcpy(y, x, ne00 * sizeof(float));
4171
-
4172
4204
  const float scale = 1.0f/fmaxf(sqrtf(sum), eps);
4173
4205
 
4174
- ggml_vec_scale_f32(ne00, y, scale);
4206
+ char * y = (char *) dst->data + i01*nb1 + i02*nb2 + i03*nb3;
4207
+
4208
+ if (nb00 == sizeof(float) && nb0 == sizeof(float)) {
4209
+ memcpy(y, x, ne00 * sizeof(float));
4210
+ ggml_vec_scale_f32(ne00, (float *) y, scale);
4211
+ } else {
4212
+ for (int64_t i00 = 0; i00 < ne00; i00++) {
4213
+ const float xi = *(const float *) (x + i00*nb00);
4214
+ *(float *) (y + i00*nb0) = xi * scale;
4215
+ }
4216
+ }
4175
4217
  }
4176
4218
  }
4177
4219
  }
@@ -4415,6 +4457,7 @@ void ggml_compute_forward_out_prod(
4415
4457
 
4416
4458
  switch (src0->type) {
4417
4459
  case GGML_TYPE_Q1_0:
4460
+ case GGML_TYPE_Q2_0:
4418
4461
  case GGML_TYPE_Q4_0:
4419
4462
  case GGML_TYPE_Q4_1:
4420
4463
  case GGML_TYPE_Q5_0:
@@ -4691,6 +4734,7 @@ void ggml_compute_forward_set(
4691
4734
  case GGML_TYPE_F16:
4692
4735
  case GGML_TYPE_BF16:
4693
4736
  case GGML_TYPE_Q1_0:
4737
+ case GGML_TYPE_Q2_0:
4694
4738
  case GGML_TYPE_Q4_0:
4695
4739
  case GGML_TYPE_Q4_1:
4696
4740
  case GGML_TYPE_Q5_0:
@@ -4915,6 +4959,7 @@ void ggml_compute_forward_get_rows(
4915
4959
 
4916
4960
  switch (src0->type) {
4917
4961
  case GGML_TYPE_Q1_0:
4962
+ case GGML_TYPE_Q2_0:
4918
4963
  case GGML_TYPE_Q4_0:
4919
4964
  case GGML_TYPE_Q4_1:
4920
4965
  case GGML_TYPE_Q5_0:
@@ -4980,8 +5025,8 @@ void ggml_compute_forward_get_rows(
4980
5025
  //}
4981
5026
  }
4982
5027
 
4983
- template<typename idx_t>
4984
- static void ggml_compute_forward_set_rows_f32(
5028
+ template<typename src_t, typename idx_t>
5029
+ static void ggml_compute_forward_set_rows_impl(
4985
5030
  const ggml_compute_params * params,
4986
5031
  ggml_tensor * dst) {
4987
5032
 
@@ -4996,7 +5041,7 @@ static void ggml_compute_forward_set_rows_f32(
4996
5041
  assert(ne0 == nc);
4997
5042
  assert(ne2 == ne02);
4998
5043
  assert(ne3 == ne03);
4999
- assert(src0->type == GGML_TYPE_F32);
5044
+ GGML_ASSERT(src0->type == GGML_TYPE_F32 || (src0->type == GGML_TYPE_F16 && dst->type == GGML_TYPE_F16));
5000
5045
  assert(ne02 % ne11 == 0);
5001
5046
  assert(ne03 % ne12 == 0);
5002
5047
 
@@ -5010,6 +5055,8 @@ static void ggml_compute_forward_set_rows_f32(
5010
5055
  const int64_t ir0 = dr*ith;
5011
5056
  const int64_t ir1 = std::min(ir0 + dr, nr);
5012
5057
 
5058
+ const size_t rs = ggml_row_size(src0->type, nc);
5059
+
5013
5060
  ggml_from_float_t const from_float = ggml_get_type_traits_cpu(dst->type)->from_float;
5014
5061
 
5015
5062
  for (int64_t i03 = 0; i03 < ne03; ++i03) {
@@ -5023,9 +5070,18 @@ static void ggml_compute_forward_set_rows_f32(
5023
5070
 
5024
5071
  GGML_ASSERT(i1 >= 0 && i1 < ne1);
5025
5072
 
5026
- from_float(
5027
- (const float *) ((char *) src0->data + i*nb01 + i02*nb02 + i03*nb03),
5028
- ((char *) dst->data + i1*nb1 + i02*nb2 + i03*nb3), nc);
5073
+ if constexpr (std::is_same_v<src_t, float>) {
5074
+ from_float(
5075
+ (const float *) ((char *) src0->data + i*nb01 + i02*nb02 + i03*nb03),
5076
+ ((char *) dst->data + i1*nb1 + i02*nb2 + i03*nb3), nc);
5077
+ } else if constexpr (std::is_same_v<src_t, ggml_fp16_t>) {
5078
+ memcpy(
5079
+ ((char *) dst->data + i1*nb1 + i02*nb2 + i03*nb3),
5080
+ ((char *) src0->data + i*nb01 + i02*nb02 + i03*nb03),
5081
+ rs);
5082
+ } else {
5083
+ GGML_ABORT("src0->type = %d (%s) not supported", src0->type, ggml_type_name(src0->type));
5084
+ }
5029
5085
  }
5030
5086
  }
5031
5087
  }
@@ -5042,13 +5098,27 @@ void ggml_compute_forward_set_rows(
5042
5098
  case GGML_TYPE_F32:
5043
5099
  {
5044
5100
  if (src1->type == GGML_TYPE_I64) {
5045
- ggml_compute_forward_set_rows_f32<int64_t>(params, dst);
5101
+ ggml_compute_forward_set_rows_impl<float, int64_t>(params, dst);
5046
5102
  } else if (src1->type == GGML_TYPE_I32) {
5047
- ggml_compute_forward_set_rows_f32<int32_t>(params, dst);
5103
+ ggml_compute_forward_set_rows_impl<float, int32_t>(params, dst);
5048
5104
  } else {
5049
5105
  GGML_ABORT("src1->type = %d (%s) not supported", src1->type, ggml_type_name(src1->type));
5050
5106
  }
5051
5107
  } break;
5108
+ case GGML_TYPE_F16:
5109
+ {
5110
+ if (dst->type == GGML_TYPE_F16) {
5111
+ if (src1->type == GGML_TYPE_I64) {
5112
+ ggml_compute_forward_set_rows_impl<ggml_fp16_t, int64_t>(params, dst);
5113
+ } else if (src1->type == GGML_TYPE_I32) {
5114
+ ggml_compute_forward_set_rows_impl<ggml_fp16_t, int32_t>(params, dst);
5115
+ } else {
5116
+ GGML_ABORT("src1->type = %d (%s) not supported", src1->type, ggml_type_name(src1->type));
5117
+ }
5118
+ } else {
5119
+ GGML_ABORT("dst->type = %d (%s) not supported with src0->type = %d (%s)", dst->type, ggml_type_name(dst->type), src0->type, ggml_type_name(src0->type));
5120
+ }
5121
+ } break;
5052
5122
  default:
5053
5123
  {
5054
5124
  GGML_ABORT("src0->type = %d (%s) not supported", src0->type, ggml_type_name(src0->type));
@@ -5641,6 +5711,7 @@ void ggml_compute_forward_clamp(
5641
5711
  } break;
5642
5712
  case GGML_TYPE_BF16:
5643
5713
  case GGML_TYPE_Q1_0:
5714
+ case GGML_TYPE_Q2_0:
5644
5715
  case GGML_TYPE_Q4_0:
5645
5716
  case GGML_TYPE_Q4_1:
5646
5717
  case GGML_TYPE_Q5_0:
@@ -7228,6 +7299,13 @@ struct ggml_conv_2d_dw_params {
7228
7299
  int dilation_y;
7229
7300
  };
7230
7301
 
7302
+ static inline float ggml_conv_2d_dw_knl_f32(const char * data, int64_t i, ggml_type type) {
7303
+ if (type == GGML_TYPE_F16) {
7304
+ return GGML_FP16_TO_FP32(((const ggml_fp16_t *)data)[i]);
7305
+ }
7306
+ return ((const float *)data)[i];
7307
+ }
7308
+
7231
7309
  static void ggml_compute_forward_conv_2d_dw_cwhn(
7232
7310
  const ggml_compute_params * params,
7233
7311
  const ggml_tensor * src,
@@ -7236,7 +7314,8 @@ static void ggml_compute_forward_conv_2d_dw_cwhn(
7236
7314
  const ggml_conv_2d_dw_params & p) {
7237
7315
 
7238
7316
  const int64_t c = p.channels;
7239
- const float * knl_data = (const float *)kernel->data;
7317
+ const char * knl_data = (const char *)kernel->data;
7318
+ const ggml_type knl_type = kernel->type;
7240
7319
 
7241
7320
  const int64_t rows_total = p.dst_h * p.batch;
7242
7321
  const int64_t rows_per_thread = (rows_total + params->nth - 1) / params->nth;
@@ -7244,13 +7323,16 @@ static void ggml_compute_forward_conv_2d_dw_cwhn(
7244
7323
  const int64_t row_end = MIN(row_start + rows_per_thread, rows_total);
7245
7324
 
7246
7325
  #ifdef GGML_SIMD
7326
+ int64_t c_pkg_end = 0;
7327
+ int64_t pkg_size = GGML_F32_EPR;
7328
+ if (knl_type == GGML_TYPE_F32) {
7247
7329
  #if defined(__ARM_FEATURE_SVE)
7248
- const int64_t pkg_size = svcntw();
7330
+ pkg_size = svcntw();
7249
7331
  #else
7250
- const int64_t pkg_size = GGML_F32_EPR;
7332
+ pkg_size = GGML_F32_EPR;
7251
7333
  #endif
7252
- const int64_t pkg_count = c / pkg_size;
7253
- const int64_t c_pkg_end = pkg_count * pkg_size;
7334
+ c_pkg_end = (c / pkg_size) * pkg_size;
7335
+ }
7254
7336
  #else
7255
7337
  const int64_t c_pkg_end = 0;
7256
7338
  #endif
@@ -7264,7 +7346,6 @@ static void ggml_compute_forward_conv_2d_dw_cwhn(
7264
7346
  const int64_t src_x_base = dst_x * p.stride_x - p.pad_x;
7265
7347
 
7266
7348
  #ifdef GGML_SIMD
7267
- // Vectorized loop
7268
7349
  for (int64_t c_i = 0; c_i < c_pkg_end; c_i += pkg_size) {
7269
7350
  GGML_F32_VEC sum = GGML_F32_VEC_ZERO;
7270
7351
  for (int64_t knl_y = 0; knl_y < p.knl_h; ++knl_y) {
@@ -7277,7 +7358,8 @@ static void ggml_compute_forward_conv_2d_dw_cwhn(
7277
7358
  if (src_x < 0 || src_x >= p.src_w) {
7278
7359
  continue;
7279
7360
  }
7280
- GGML_F32_VEC k = GGML_F32_VEC_LOAD(knl_data + (knl_y * p.knl_w + knl_x) * c + c_i);
7361
+ const float * kp = (const float *)knl_data + (knl_y * p.knl_w + knl_x) * c + c_i;
7362
+ GGML_F32_VEC k = GGML_F32_VEC_LOAD(kp);
7281
7363
  GGML_F32_VEC s = GGML_F32_VEC_LOAD(src_data + (src_y * p.src_w + src_x) * c + c_i);
7282
7364
  sum = GGML_F32_VEC_FMA(sum, k, s);
7283
7365
  }
@@ -7285,7 +7367,6 @@ static void ggml_compute_forward_conv_2d_dw_cwhn(
7285
7367
  GGML_F32_VEC_STORE(dst_data + c_i, sum);
7286
7368
  }
7287
7369
  #endif
7288
- // Scalar loop
7289
7370
  for (int64_t c_i = c_pkg_end; c_i < c; ++c_i) {
7290
7371
  float sum = 0.0f;
7291
7372
  for (int64_t knl_y = 0; knl_y < p.knl_h; ++knl_y) {
@@ -7298,7 +7379,7 @@ static void ggml_compute_forward_conv_2d_dw_cwhn(
7298
7379
  if (src_x < 0 || src_x >= p.src_w) {
7299
7380
  continue;
7300
7381
  }
7301
- sum += knl_data[(knl_y * p.knl_w + knl_x) * c + c_i]
7382
+ sum += ggml_conv_2d_dw_knl_f32(knl_data, (knl_y * p.knl_w + knl_x) * c + c_i, knl_type)
7302
7383
  * src_data[(src_y * p.src_w + src_x) * c + c_i];
7303
7384
  }
7304
7385
  }
@@ -7319,9 +7400,11 @@ static void ggml_compute_forward_conv_2d_dw_whcn(
7319
7400
  const int64_t per_thread = (n + params->nth - 1) / params->nth;
7320
7401
  const int64_t start = params->ith * per_thread;
7321
7402
  const int64_t end = MIN(start + per_thread, n);
7403
+ const char * knl_base = (const char *)kernel->data;
7404
+ const ggml_type knl_type = kernel->type;
7322
7405
 
7323
7406
  for (int64_t i = start; i < end; ++i) {
7324
- const float * knl_data = (const float *)kernel->data + (i % p.channels) * p.knl_w * p.knl_h;
7407
+ const int64_t knl_offset = (i % p.channels) * p.knl_w * p.knl_h;
7325
7408
  const float * src_data = (const float *)src->data + i * p.src_w * p.src_h;
7326
7409
  float * dst_data = (float *)dst->data + i * p.dst_w * p.dst_h;
7327
7410
 
@@ -7339,7 +7422,7 @@ static void ggml_compute_forward_conv_2d_dw_whcn(
7339
7422
  if (src_x < 0 || src_x >= p.src_w) {
7340
7423
  continue;
7341
7424
  }
7342
- sum += knl_data[knl_y * p.knl_w + knl_x]
7425
+ sum += ggml_conv_2d_dw_knl_f32(knl_base, knl_offset + knl_y * p.knl_w + knl_x, knl_type)
7343
7426
  * src_data[src_y * p.src_w + src_x];
7344
7427
  }
7345
7428
  }
@@ -7371,13 +7454,13 @@ void ggml_compute_forward_conv_2d_dw(
7371
7454
  p.dilation_x = dst->op_params[4];
7372
7455
  p.dilation_y = dst->op_params[5];
7373
7456
 
7457
+ GGML_ASSERT(kernel->type == GGML_TYPE_F32 || kernel->type == GGML_TYPE_F16);
7374
7458
  GGML_ASSERT(kernel->ne[3] == p.channels);
7375
7459
  GGML_ASSERT(dst->ne[3] == p.batch);
7376
7460
 
7377
7461
  if (ggml_is_contiguous(src)) {
7378
7462
  ggml_compute_forward_conv_2d_dw_whcn(params, src, kernel, dst, p);
7379
7463
  } else if (ggml_is_contiguous_channels(src)) {
7380
- // kernel should also have channels most contiguous in memory
7381
7464
  GGML_ASSERT(kernel->nb[0] >= kernel->nb[2] && kernel->nb[1] >= kernel->nb[0]);
7382
7465
  ggml_compute_forward_conv_2d_dw_cwhn(params, src, kernel, dst, p);
7383
7466
  } else {
@@ -26,6 +26,10 @@ void quantize_row_q1_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, in
26
26
  quantize_row_q1_0_ref(x, y, k);
27
27
  }
28
28
 
29
+ void quantize_row_q2_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k) {
30
+ quantize_row_q2_0_ref(x, y, k);
31
+ }
32
+
29
33
  void quantize_row_q4_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k) {
30
34
  quantize_row_q4_0_ref(x, y, k);
31
35
  }
@@ -170,6 +174,53 @@ void ggml_vec_dot_q1_0_q8_0_generic(int n, float * GGML_RESTRICT s, size_t bs, c
170
174
  *s = sumf;
171
175
  }
172
176
 
177
+ void ggml_vec_dot_q2_0_q8_0_generic(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc) {
178
+ const int qk = QK2_0;
179
+ const int nb = n / qk;
180
+
181
+ assert(n % qk == 0);
182
+ assert(nrc == 1);
183
+ UNUSED(nrc);
184
+ UNUSED(bx);
185
+ UNUSED(by);
186
+ UNUSED(bs);
187
+
188
+ const block_q2_0 * GGML_RESTRICT x = vx;
189
+ const block_q8_0 * GGML_RESTRICT y = vy;
190
+
191
+ float sumf = 0.0f;
192
+
193
+ for (int i = 0; i < nb; i++) {
194
+ const float d0 = GGML_CPU_FP16_TO_FP32(x[i].d);
195
+
196
+ float sumi = 0.0f;
197
+
198
+ // group 64: one Q2_0 block (64 weights) maps to two Q8_0 blocks (2 * 32 = 64)
199
+ for (int k = 0; k < 2; k++) {
200
+ const block_q8_0 * GGML_RESTRICT yb = &y[i * 2 + k];
201
+ const float d1 = GGML_CPU_FP16_TO_FP32(yb->d);
202
+ int sumi_block = 0;
203
+
204
+ const uint8_t * GGML_RESTRICT qs = &x[i].qs[k * 8];
205
+ const int8_t * GGML_RESTRICT qy = yb->qs;
206
+
207
+ for (int b = 0; b < 8; ++b) {
208
+ const uint8_t byte = qs[b];
209
+ // Extract 4 two-bit values, map {0,1,2,3} -> {-1,0,1,2}
210
+ sumi_block += ((int)((byte >> 0) & 3) - 1) * qy[b*4 + 0];
211
+ sumi_block += ((int)((byte >> 2) & 3) - 1) * qy[b*4 + 1];
212
+ sumi_block += ((int)((byte >> 4) & 3) - 1) * qy[b*4 + 2];
213
+ sumi_block += ((int)((byte >> 6) & 3) - 1) * qy[b*4 + 3];
214
+ }
215
+
216
+ sumi += d1 * sumi_block;
217
+ }
218
+
219
+ sumf += d0 * sumi;
220
+ }
221
+
222
+ *s = sumf;
223
+ }
173
224
 
174
225
  void ggml_vec_dot_q4_0_q8_0_generic(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc) {
175
226
  const int qk = QK8_0;
@@ -13,6 +13,7 @@ extern "C" {
13
13
 
14
14
  // Quantization
15
15
  void quantize_row_q1_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
16
+ void quantize_row_q2_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
16
17
  void quantize_row_q4_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
17
18
  void quantize_row_q4_1(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
18
19
  void quantize_row_q5_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
@@ -38,6 +39,7 @@ void quantize_row_iq4_xs (const float * GGML_RESTRICT x, void * GGML_RESTRICT y,
38
39
 
39
40
  // Dot product
40
41
  void ggml_vec_dot_q1_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
42
+ void ggml_vec_dot_q2_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
41
43
  void ggml_vec_dot_q4_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
42
44
  void ggml_vec_dot_q4_1_q8_1(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
43
45
  void ggml_vec_dot_q5_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
@@ -71,6 +73,7 @@ void quantize_row_q8_0_generic(const float * GGML_RESTRICT x, void * GGML_RESTRI
71
73
  void quantize_row_q8_1_generic(const float * GGML_RESTRICT x, void * GGML_RESTRICT vy, int64_t k);
72
74
  void quantize_row_q8_K_generic(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
73
75
  void ggml_vec_dot_q1_0_q8_0_generic(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
76
+ void ggml_vec_dot_q2_0_q8_0_generic(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
74
77
  void ggml_vec_dot_q4_0_q8_0_generic(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
75
78
  void ggml_vec_dot_q4_1_q8_1_generic(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
76
79
  void ggml_vec_dot_q5_0_q8_0_generic(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
@@ -78,7 +78,7 @@ static void simd_gemm(
78
78
  for (int64_t i = 0; i < GEMM_RM; i++) {
79
79
  float a = C[i * N + jj];
80
80
  for (int64_t kk = 0; kk < K; kk++) {
81
- a += A[i + kk] * B[kk * N + jj];
81
+ a += A[i * K + kk] * B[kk * N + jj];
82
82
  }
83
83
  C[i * N + jj] = a;
84
84
  }
@@ -120,6 +120,10 @@ extern float ggml_table_f32_f16[1 << 16];
120
120
  // defined in ggml-cpu.c, initialized in ggml_cpu_init()
121
121
  extern float ggml_table_f32_e8m0_half[1 << 8];
122
122
 
123
+ // precomputed f32 table for ue4m3 (1 KB)
124
+ // defined in ggml-cpu.c, initialized in ggml_cpu_init()
125
+ extern float ggml_table_f32_ue4m3[1 << 8];
126
+
123
127
  // Use lookup table for E8M0 on x86 (faster than bit manipulation)
124
128
  #if defined(__AVX__) || defined(__AVX2__) || defined(__AVX512F__)
125
129
  #define GGML_CPU_E8M0_TO_FP32_HALF(x) ggml_table_f32_e8m0_half[(uint8_t)(x)]
@@ -127,6 +131,13 @@ extern float ggml_table_f32_e8m0_half[1 << 8];
127
131
  #define GGML_CPU_E8M0_TO_FP32_HALF(x) GGML_E8M0_TO_FP32_HALF(x)
128
132
  #endif
129
133
 
134
+ // Use lookup table for UE4M3 on x86 and ARM (faster than bit manipulation)
135
+ #if defined(__AVX__) || defined(__AVX2__) || defined(__AVX512F__) || defined(__ARM_NEON)
136
+ #define GGML_CPU_UE4M3_TO_FP32(x) ggml_table_f32_ue4m3[(uint8_t)(x)]
137
+ #else
138
+ #define GGML_CPU_UE4M3_TO_FP32(x) ggml_ue4m3_to_fp32(x)
139
+ #endif
140
+
130
141
  // On ARM NEON, it's quicker to directly convert x -> x instead of calling into ggml_lookup_fp16_to_fp32,
131
142
  // so we define GGML_CPU_FP16_TO_FP32 and GGML_CPU_FP32_TO_FP16 elsewhere for NEON.
132
143
  // This is also true for POWER9.
@@ -75,12 +75,12 @@ void ggml_vec_dot_f32(int n, float * GGML_RESTRICT s, size_t bs, const float * G
75
75
  ay1 = GGML_F32_VEC_LOAD(y + i);
76
76
  sum1 = GGML_F32_VEC_FMA(sum1, ax1, ay1);
77
77
  }
78
- // maximum number of leftover elements will be less that ggml_f32_epr. Apply predicated svmad on available elements only
78
+ // maximum number of leftover elements will be less that ggml_f32_epr. Apply predicated svmla on available elements only
79
79
  if (np2 < n) {
80
80
  svbool_t pg = svwhilelt_b32(np2, n);
81
81
  ax1 = svld1_f32(pg, x + np2);
82
82
  ay1 = svld1_f32(pg, y + np2);
83
- sum1 = svmad_f32_m(pg, ax1, ay1, sum1);
83
+ sum1 = svmla_f32_m(pg, sum1, ax1, ay1);
84
84
  }
85
85
  // reduce sum1,sum2 to sum1
86
86
  GGML_F32_VEC_REDUCE(sumf, sum1, sum2, sum3, sum4, sum5, sum6, sum7, sum8);