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
@@ -1,4 +1,3 @@
1
- #include "ggml-backend-impl.h"
2
1
  #include "ggml-decoder.h"
3
2
  #include "ggml-impl.h"
4
3
 
@@ -45,6 +44,7 @@ struct graph_key_hash {
45
44
 
46
45
  struct decoder_runtime_ctx {
47
46
  decoder_runtime_ctx(std::shared_ptr<std::mutex> mutex) : mutex(std::move(mutex)) {}
47
+
48
48
  std::shared_ptr<std::mutex> mutex;
49
49
  std::shared_ptr<GgmlOvDecoder> ptr;
50
50
  };
@@ -64,11 +64,7 @@ struct ov_runtime_context {
64
64
  std::map<std::string, std::string> kv_state_input_name_map;
65
65
  std::atomic<int> backend_count;
66
66
 
67
- ov_runtime_context() :
68
- device("CPU"),
69
- stateful(false),
70
- stateful_kv_size(0),
71
- backend_count(0) {}
67
+ ov_runtime_context() : device("CPU"), stateful(false), stateful_kv_size(0), backend_count(0) {}
72
68
 
73
69
  void clear_caches() {
74
70
  std::lock_guard<std::mutex> lock(ctx_mutex);
@@ -87,6 +83,8 @@ enum ggml_status ov_graph_compute_static(struct ggml_cgraph * cgraph, std::share
87
83
 
88
84
  size_t checksum(const void * data, size_t size);
89
85
 
86
+ bool save_ggml_tensor_data_to_txt(const ggml_tensor * tensor, const std::string & file_path);
87
+
90
88
  void print_input_tensor_info(const std::string & name, const ov::Tensor & tensor);
91
89
 
92
90
  void print_output_tensor_info(const std::string & name, const ov::Tensor & tensor, const void * output_dst);
@@ -117,8 +115,6 @@ std::vector<T> pad_input(const ggml_tensor * tensor, size_t padded_rows, size_t
117
115
  padded_rows, padded_cols, pad_value);
118
116
  }
119
117
 
120
- void set_zero_diagonal(std::vector<float> & matrix, size_t rows, size_t cols);
121
-
122
118
  const ggml_tensor * get_inp_pos_tensor(struct ggml_cgraph * cgraph);
123
119
 
124
120
  bool get_is_prefill(const ggml_tensor * inp_pos);
@@ -137,6 +133,13 @@ ov::Tensor create_ov_output_tensor(std::shared_ptr<GgmlOvDecoder> ggml_decoder,
137
133
 
138
134
  bool is_naive(struct ggml_cgraph * cgraph);
139
135
 
136
+ /**
137
+ * @brief Heuristically checks whether the given computation graph is a split-model fragment.
138
+ * @param cgraph Pointer to the GGML computation graph to analyze.
139
+ * @return true if the graph is identified as split; otherwise false.
140
+ */
141
+ bool is_model_splitted(struct ggml_cgraph * cgraph);
142
+
140
143
  enum ggml_status naive_compute(struct ggml_cgraph * cgraph,
141
144
  ov::Core & core,
142
145
  const std::string & device,
@@ -71,6 +71,44 @@ void quantize_row_q1_0_ref(const float * GGML_RESTRICT x, block_q1_0 * GGML_REST
71
71
  }
72
72
  }
73
73
 
74
+ void quantize_row_q2_0_ref(const float * GGML_RESTRICT x, block_q2_0 * GGML_RESTRICT y, int64_t k) {
75
+ static const int qk = QK2_0;
76
+
77
+ assert(k % qk == 0);
78
+
79
+ const int nb = k / qk;
80
+
81
+ for (int i = 0; i < nb; i++) {
82
+ // Compute scale as max absolute value in the block
83
+ float amax = 0.0f;
84
+ for (int j = 0; j < qk; j++) {
85
+ const float a = fabsf(x[i*qk + j]);
86
+ if (a > amax) amax = a;
87
+ }
88
+ const float d = amax;
89
+ const float id = d > 0.0f ? 1.0f / d : 0.0f;
90
+
91
+ y[i].d = GGML_FP32_TO_FP16(d);
92
+
93
+ // Clear quant bytes
94
+ for (int j = 0; j < qk / 4; ++j) {
95
+ y[i].qs[j] = 0;
96
+ }
97
+
98
+ // Encode 2-bit values: round(w/d) clamped to [-1, 2], then add 1
99
+ // 00 (-1) = -scale, 01 (0) = 0, 10 (+1) = +scale, 11 (+2) = 2*scale
100
+ for (int j = 0; j < qk; ++j) {
101
+ const float w = x[i*qk + j];
102
+ int q = (int)roundf(w * id) + 1;
103
+ if (q < 0) q = 0;
104
+ if (q > 3) q = 3;
105
+ const int byte_index = j / 4;
106
+ const int bit_offset = (j % 4) * 2;
107
+ y[i].qs[byte_index] |= ((uint8_t)q << bit_offset);
108
+ }
109
+ }
110
+ }
111
+
74
112
  // reference implementation for deterministic creation of model files
75
113
  void quantize_row_q4_0_ref(const float * GGML_RESTRICT x, block_q4_0 * GGML_RESTRICT y, int64_t k) {
76
114
  static const int qk = QK4_0;
@@ -398,6 +436,26 @@ void dequantize_row_q1_0(const block_q1_0 * GGML_RESTRICT x, float * GGML_RESTRI
398
436
  }
399
437
  }
400
438
 
439
+ void dequantize_row_q2_0(const block_q2_0 * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k) {
440
+ static const int qk = QK2_0;
441
+
442
+ assert(k % qk == 0);
443
+
444
+ const int nb = k / qk;
445
+
446
+ for (int i = 0; i < nb; i++) {
447
+ const float d = GGML_FP16_TO_FP32(x[i].d);
448
+
449
+ for (int j = 0; j < qk; ++j) {
450
+ const int byte_index = j / 4;
451
+ const int bit_offset = (j % 4) * 2;
452
+ const uint8_t q = (x[i].qs[byte_index] >> bit_offset) & 0x03;
453
+ // 00=-1, 01=0, 10=+1, 11=+2
454
+ y[i*qk + j] = ((int)q - 1) * d;
455
+ }
456
+ }
457
+ }
458
+
401
459
  void dequantize_row_q4_0(const block_q4_0 * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k) {
402
460
  static const int qk = QK4_0;
403
461
 
@@ -2052,6 +2110,20 @@ size_t quantize_q1_0(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst,
2052
2110
  return nrow * row_size;
2053
2111
  }
2054
2112
 
2113
+ size_t quantize_q2_0(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrow, int64_t n_per_row, const float * quant_weights) {
2114
+ if (!quant_weights) {
2115
+ quantize_row_q2_0_ref(src, dst, (int64_t)nrow*n_per_row);
2116
+ return nrow * ggml_row_size(GGML_TYPE_Q2_0, n_per_row);
2117
+ }
2118
+ size_t row_size = ggml_row_size(GGML_TYPE_Q2_0, n_per_row);
2119
+ char * qrow = (char *)dst;
2120
+ for (int64_t row = 0; row < nrow; ++row) {
2121
+ quantize_row_q2_0_ref(src, (block_q2_0*)qrow, n_per_row);
2122
+ src += n_per_row;
2123
+ qrow += row_size;
2124
+ }
2125
+ return nrow * row_size;
2126
+ }
2055
2127
 
2056
2128
  size_t quantize_q4_0(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrow, int64_t n_per_row, const float * quant_weights) {
2057
2129
  if (!quant_weights) {
@@ -5461,6 +5533,10 @@ bool ggml_validate_row_data(enum ggml_type type, const void * data, size_t nbyte
5461
5533
  {
5462
5534
  VALIDATE_ROW_DATA_D_F16_IMPL(block_q1_0, data, nb);
5463
5535
  } break;
5536
+ case GGML_TYPE_Q2_0:
5537
+ {
5538
+ VALIDATE_ROW_DATA_D_F16_IMPL(block_q2_0, data, nb);
5539
+ } break;
5464
5540
  case GGML_TYPE_Q4_0:
5465
5541
  {
5466
5542
  VALIDATE_ROW_DATA_D_F16_IMPL(block_q4_0, data, nb);
@@ -15,6 +15,7 @@ extern "C" {
15
15
 
16
16
  // Quantization
17
17
  GGML_API void quantize_row_q1_0_ref(const float * GGML_RESTRICT x, block_q1_0 * GGML_RESTRICT y, int64_t k);
18
+ GGML_API void quantize_row_q2_0_ref(const float * GGML_RESTRICT x, block_q2_0 * GGML_RESTRICT y, int64_t k);
18
19
  GGML_API void quantize_row_q4_0_ref(const float * GGML_RESTRICT x, block_q4_0 * GGML_RESTRICT y, int64_t k);
19
20
  GGML_API void quantize_row_q4_1_ref(const float * GGML_RESTRICT x, block_q4_1 * GGML_RESTRICT y, int64_t k);
20
21
  GGML_API void quantize_row_q5_0_ref(const float * GGML_RESTRICT x, block_q5_0 * GGML_RESTRICT y, int64_t k);
@@ -43,6 +44,7 @@ GGML_API void quantize_row_iq2_s_ref (const float * GGML_RESTRICT x, block_iq2_
43
44
 
44
45
  // Dequantization
45
46
  GGML_API void dequantize_row_q1_0(const block_q1_0 * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
47
+ GGML_API void dequantize_row_q2_0(const block_q2_0 * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
46
48
  GGML_API void dequantize_row_q4_0(const block_q4_0 * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
47
49
  GGML_API void dequantize_row_q4_1(const block_q4_1 * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
48
50
  GGML_API void dequantize_row_q5_0(const block_q5_0 * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
@@ -93,6 +95,7 @@ GGML_API size_t quantize_q4_K(const float * GGML_RESTRICT src, void * GGML_RESTR
93
95
  GGML_API size_t quantize_q5_K(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
94
96
  GGML_API size_t quantize_q6_K(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
95
97
  GGML_API size_t quantize_q1_0(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
98
+ GGML_API size_t quantize_q2_0(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
96
99
  GGML_API size_t quantize_q4_0(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
97
100
  GGML_API size_t quantize_q4_1(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
98
101
  GGML_API size_t quantize_q5_0(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
@@ -39,8 +39,8 @@ if (WIN32)
39
39
  set(CMAKE_CXX_COMPILER "icx")
40
40
  set(CMAKE_CXX_COMPILER_ID "IntelLLVM")
41
41
  endif()
42
- # Level Zero SDK path for Windows (only when GGML_SYCL_SUPPORT_LEVEL_ZERO is enabled)
43
- if(GGML_SYCL_SUPPORT_LEVEL_ZERO)
42
+ # Level Zero SDK path for Windows (only when GGML_SYCL_SUPPORT_LEVEL_ZERO_API is enabled)
43
+ if(GGML_SYCL_SUPPORT_LEVEL_ZERO_API)
44
44
  if(DEFINED ENV{LEVEL_ZERO_V1_SDK_PATH})
45
45
  set(LEVEL_ZERO_V1_SDK_PATH $ENV{LEVEL_ZERO_V1_SDK_PATH})
46
46
  if(EXISTS "${LEVEL_ZERO_V1_SDK_PATH}")
@@ -105,8 +105,8 @@ endif()
105
105
 
106
106
  target_compile_options(ggml-sycl PRIVATE "-Wno-narrowing")
107
107
 
108
- message(STATUS "GGML_SYCL_SUPPORT_LEVEL_ZERO ${GGML_SYCL_SUPPORT_LEVEL_ZERO}")
109
- if (GGML_SYCL_SUPPORT_LEVEL_ZERO)
108
+ message(STATUS "GGML_SYCL_SUPPORT_LEVEL_ZERO_API ${GGML_SYCL_SUPPORT_LEVEL_ZERO_API}")
109
+ if (GGML_SYCL_SUPPORT_LEVEL_ZERO_API)
110
110
  # Link against Level Zero loader for direct device memory allocation.
111
111
  # Avoids sycl::malloc_device triggering DMA-buf/TTM system RAM staging
112
112
  # in the xe kernel driver during multi-GPU inference.
@@ -114,7 +114,7 @@ if (GGML_SYCL_SUPPORT_LEVEL_ZERO)
114
114
  find_library(ZE_LOADER_LIB ze_loader HINTS ${ONEAPI_ROOT}/lib ${LEVEL_ZERO_V1_SDK_LIB_PATH} ENV LD_LIBRARY_PATH)
115
115
  if(ZE_LOADER_LIB AND LEVEL_ZERO_INCLUDE_DIR)
116
116
  target_link_libraries(ggml-sycl PRIVATE ${ZE_LOADER_LIB})
117
- target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_SUPPORT_LEVEL_ZERO)
117
+ target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_SUPPORT_LEVEL_ZERO_API)
118
118
  message(STATUS "Level Zero loader found: ${ZE_LOADER_LIB}")
119
119
  message(STATUS "Level Zero headers found: ${LEVEL_ZERO_INCLUDE_DIR}")
120
120
  else()
@@ -14,9 +14,11 @@
14
14
  #define GGML_SYCL_BACKEND_HPP
15
15
 
16
16
  #include "binbcast.hpp"
17
+ #include "col2im-1d.hpp"
17
18
  #include "common.hpp"
18
19
  #include "concat.hpp"
19
20
  #include "conv.hpp"
21
+ #include "conv3d.hpp"
20
22
  #include "convert.hpp"
21
23
  #include "count-equal.hpp"
22
24
  #include "cpy.hpp"
@@ -287,6 +287,18 @@ inline void ggml_sycl_op_bin_bcast(ggml_backend_sycl_context & ctx, const ggml_t
287
287
  ne10, ne11, ne12, ne13, ne0, ne1, ne2, ne3, nb00, nb01, nb02, nb03, nb10, nb11, nb12, nb13, nb0, nb1, nb2,
288
288
  nb3, ggml_is_contiguous(src0), ggml_is_contiguous(src1), ggml_is_permuted(src0), ggml_is_permuted(src1),
289
289
  main_stream);
290
+ #ifdef GGML_SYCL_HAS_BF16
291
+ } else if (src0->type == GGML_TYPE_BF16 && src1->type == GGML_TYPE_BF16 && dst->type == GGML_TYPE_BF16) {
292
+ op()((const sycl::ext::oneapi::bfloat16 *) src0->data, (const sycl::ext::oneapi::bfloat16 *) src1->data,
293
+ (sycl::ext::oneapi::bfloat16 *) dst->data, ne00, ne01, ne02, ne03, ne10, ne11, ne12, ne13, ne0, ne1, ne2,
294
+ ne3, nb00, nb01, nb02, nb03, nb10, nb11, nb12, nb13, nb0, nb1, nb2, nb3, ggml_is_contiguous(src0),
295
+ ggml_is_contiguous(src1), ggml_is_permuted(src0), ggml_is_permuted(src1), main_stream);
296
+ } else if (src0->type == GGML_TYPE_BF16 && src1->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_BF16) {
297
+ op()((const sycl::ext::oneapi::bfloat16 *) src0->data, (const float *) src1->data,
298
+ (sycl::ext::oneapi::bfloat16 *) dst->data, ne00, ne01, ne02, ne03, ne10, ne11, ne12, ne13, ne0, ne1, ne2,
299
+ ne3, nb00, nb01, nb02, nb03, nb10, nb11, nb12, nb13, nb0, nb1, nb2, nb3, ggml_is_contiguous(src0),
300
+ ggml_is_contiguous(src1), ggml_is_permuted(src0), ggml_is_permuted(src1), main_stream);
301
+ #endif
290
302
  } else {
291
303
  fprintf(stderr, "%s: unsupported types: dst: %s, src0: %s, src1: %s\n", __func__, ggml_type_name(dst->type),
292
304
  ggml_type_name(src0->type), ggml_type_name(src1->type));
@@ -0,0 +1,102 @@
1
+ #include "col2im-1d.hpp"
2
+
3
+ template <typename T>
4
+ static void col2im_1d_sycl(
5
+ const T * col,
6
+ T * dst,
7
+ const int T_in,
8
+ const sycl::uint3 T_out_fd,
9
+ const int K,
10
+ const int K_OC,
11
+ const int32_t s0,
12
+ const int32_t p0,
13
+ const int total,
14
+ dpct::queue_ptr stream) {
15
+
16
+ const uint32_t block_size = SYCL_COL2IM_1D_BLOCK_SIZE;
17
+ const uint32_t num_blocks = (uint32_t) ((total + block_size - 1) / block_size);
18
+
19
+ stream->parallel_for(
20
+ sycl::nd_range<3>(
21
+ sycl::range<3>(1, 1, num_blocks * block_size),
22
+ sycl::range<3>(1, 1, block_size)),
23
+ [=](sycl::nd_item<3> item_ct1) {
24
+ const int idx = (int) item_ct1.get_global_id(2);
25
+ if (idx >= total) {
26
+ return;
27
+ }
28
+
29
+ const sycl::uint2 qr = fast_div_modulo((uint32_t) idx, T_out_fd);
30
+ const int oc = (int) qr.x();
31
+ const int t_out = (int) qr.y();
32
+ const int t_abs = t_out + p0;
33
+
34
+ int t_in_min = (t_abs - K + s0) / s0;
35
+ if (t_in_min < 0) {
36
+ t_in_min = 0;
37
+ }
38
+ int t_in_max = t_abs / s0;
39
+ if (t_in_max >= T_in) {
40
+ t_in_max = T_in - 1;
41
+ }
42
+
43
+ float sum = 0.0f;
44
+ for (int t_in = t_in_min; t_in <= t_in_max; ++t_in) {
45
+ const int k = t_abs - t_in * s0;
46
+ sum += static_cast<float>(col[(oc * K + k) + t_in * K_OC]);
47
+ }
48
+
49
+ dst[idx] = static_cast<T>(sum);
50
+ });
51
+ }
52
+
53
+ void ggml_sycl_op_col2im_1d(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
54
+ const ggml_tensor * src0 = dst->src[0];
55
+
56
+ GGML_ASSERT(src0 != nullptr);
57
+ GGML_ASSERT(ggml_is_contiguous(src0));
58
+ GGML_ASSERT(src0->type == dst->type);
59
+
60
+ const int32_t s0 = ((const int32_t *) dst->op_params)[0];
61
+ const int32_t OC = ((const int32_t *) dst->op_params)[1];
62
+ const int32_t p0 = ((const int32_t *) dst->op_params)[2];
63
+
64
+ const int K_OC = (int) src0->ne[0];
65
+ const int T_in = (int) src0->ne[1];
66
+ const int K = K_OC / OC;
67
+ const int T_out = (int) dst->ne[0];
68
+
69
+ GGML_ASSERT(OC > 0);
70
+ GGML_ASSERT(K_OC % OC == 0);
71
+
72
+ const sycl::uint3 T_out_fd = init_fastdiv_values((uint32_t) T_out);
73
+
74
+ const int total = T_out * OC;
75
+
76
+ dpct::queue_ptr stream = ctx.stream();
77
+
78
+ switch (src0->type) {
79
+ case GGML_TYPE_F32:
80
+ col2im_1d_sycl<float>(
81
+ (const float *) src0->data,
82
+ (float *) dst->data,
83
+ T_in, T_out_fd, K, K_OC, s0, p0, total, stream);
84
+ break;
85
+ case GGML_TYPE_F16:
86
+ col2im_1d_sycl<sycl::half>(
87
+ (const sycl::half *) src0->data,
88
+ (sycl::half *) dst->data,
89
+ T_in, T_out_fd, K, K_OC, s0, p0, total, stream);
90
+ break;
91
+ #ifdef GGML_SYCL_HAS_BF16
92
+ case GGML_TYPE_BF16:
93
+ col2im_1d_sycl<sycl::ext::oneapi::bfloat16>(
94
+ (const sycl::ext::oneapi::bfloat16 *) src0->data,
95
+ (sycl::ext::oneapi::bfloat16 *) dst->data,
96
+ T_in, T_out_fd, K, K_OC, s0, p0, total, stream);
97
+ break;
98
+ #endif
99
+ default:
100
+ GGML_ABORT("col2im_1d: unsupported type %d", src0->type);
101
+ }
102
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef GGML_SYCL_COL2IM_1D_HPP
2
+ #define GGML_SYCL_COL2IM_1D_HPP
3
+
4
+ #include "common.hpp"
5
+
6
+ void ggml_sycl_op_col2im_1d(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
7
+
8
+ #endif // GGML_SYCL_COL2IM_1D_HPP
@@ -12,7 +12,7 @@
12
12
 
13
13
  #include "common.hpp"
14
14
  #include <sycl/backend.hpp>
15
- #ifdef GGML_SYCL_SUPPORT_LEVEL_ZERO
15
+ #ifdef GGML_SYCL_SUPPORT_LEVEL_ZERO_API
16
16
  #include <level_zero/ze_api.h>
17
17
  #endif
18
18
 
@@ -59,7 +59,7 @@ bool gpu_has_xmx(sycl::device &dev) {
59
59
  return dev.has(sycl::aspect::ext_intel_matrix);
60
60
  }
61
61
 
62
- static int ggml_sycl_get_env(const char *env_name, int default_val) {
62
+ int ggml_sycl_get_env(const char *env_name, int default_val) {
63
63
  char *user_device_string = getenv(env_name);
64
64
  int user_number = default_val;
65
65
 
@@ -84,9 +84,9 @@ int64_t downsample_sycl_global_range(int64_t accumulate_block_num, int64_t block
84
84
  return sycl_down_blk_size;
85
85
  }
86
86
 
87
- #ifdef GGML_SYCL_SUPPORT_LEVEL_ZERO
87
+ #ifdef GGML_SYCL_SUPPORT_LEVEL_ZERO_API
88
88
  static bool ggml_sycl_use_level_zero_device_alloc(sycl::queue &q) {
89
- return ggml_sycl_get_env("GGML_SYCL_ENABLE_LEVEL_ZERO", 1) &&
89
+ return g_ggml_sycl_use_level_zero_api &&
90
90
  q.get_device().is_gpu() &&
91
91
  q.get_backend() == sycl::backend::ext_oneapi_level_zero;
92
92
  }
@@ -94,10 +94,8 @@ static bool ggml_sycl_use_level_zero_device_alloc(sycl::queue &q) {
94
94
 
95
95
  // Use Level Zero zeMemAllocDevice to avoid sycl::malloc_device triggering
96
96
  // DMA-buf/TTM system RAM staging in the xe kernel driver during multi-GPU inference.
97
- // The decision is made from the queue and runtime env because large buffers can be
98
- // allocated before ggml_check_sycl() initializes g_ggml_sycl_enable_level_zero.
99
97
  void * ggml_sycl_malloc_device(size_t size, sycl::queue &q) {
100
- #ifdef GGML_SYCL_SUPPORT_LEVEL_ZERO
98
+ #ifdef GGML_SYCL_SUPPORT_LEVEL_ZERO_API
101
99
  if (ggml_sycl_use_level_zero_device_alloc(q)) {
102
100
  void *ptr = nullptr;
103
101
  auto ze_ctx = sycl::get_native<sycl::backend::ext_oneapi_level_zero>(q.get_context());
@@ -129,7 +127,7 @@ void * ggml_sycl_malloc_device(size_t size, sycl::queue &q) {
129
127
 
130
128
  void ggml_sycl_free_device(void *ptr, sycl::queue &q) {
131
129
  if (!ptr) return;
132
- #ifdef GGML_SYCL_SUPPORT_LEVEL_ZERO
130
+ #ifdef GGML_SYCL_SUPPORT_LEVEL_ZERO_API
133
131
  if (ggml_sycl_use_level_zero_device_alloc(q)) {
134
132
  auto ze_ctx = sycl::get_native<sycl::backend::ext_oneapi_level_zero>(q.get_context());
135
133
  zeMemFree(ze_ctx, ptr);
@@ -59,9 +59,10 @@ void ggml_sycl_host_free(void* ptr);
59
59
 
60
60
 
61
61
  extern int g_ggml_sycl_debug;
62
- extern int g_ggml_sycl_disable_optimize;
62
+ extern int g_ggml_sycl_enable_optimize;
63
63
  extern int g_ggml_sycl_prioritize_dmmv;
64
64
  extern int g_ggml_sycl_enable_flash_attention;
65
+ extern int g_ggml_sycl_dev2dev_memcpy;
65
66
 
66
67
 
67
68
  #if defined(__clang__) && __has_builtin(__builtin_expect)
@@ -126,6 +127,11 @@ enum ggml_sycl_backend_gpu_mode {
126
127
  SYCL_MUL_GPU_MODE
127
128
  };
128
129
 
130
+ enum ggml_sycl_dev2dev_memcpy_mode {
131
+ DEV2DEV_MEMCPY_SYCL = 0,
132
+ DEV2DEV_MEMCPY_L0 = 1,
133
+ };
134
+
129
135
  static_assert(sizeof(sycl::half) == sizeof(ggml_fp16_t), "wrong fp16 size");
130
136
 
131
137
  static void crash() {
@@ -225,10 +231,12 @@ struct sycl_device_info {
225
231
  int max_wg_per_cu; // max work groups per compute unit - refer to
226
232
  // cudaOccupancyMaxActiveBlocksPerMultiprocessor
227
233
  bool vmm; // virtual memory support
234
+ bool l0_discrete_gpu; // Level Zero backend and not an integrated GPU
228
235
  size_t vmm_granularity; // granularity of virtual memory
229
236
  size_t total_vram;
230
237
  sycl_hw_info hw_info;
231
238
  optimize_feature opt_feature;
239
+ bool usm_system_support; // support for USM system allocations
232
240
  };
233
241
 
234
242
 
@@ -316,12 +324,17 @@ struct ggml_tensor_extra_gpu {
316
324
  optimize_feature optimized_feature;
317
325
  };
318
326
 
319
- extern int g_ggml_sycl_enable_level_zero;
327
+ extern int g_ggml_sycl_use_level_zero_api;
320
328
  void * ggml_sycl_malloc_device(size_t size, sycl::queue &q);
321
329
  void ggml_sycl_free_device(void *ptr, sycl::queue &q);
322
330
 
323
331
  void release_extra_gpu(ggml_tensor_extra_gpu * extra, std::vector<queue_ptr> streams={});
324
332
 
333
+ struct mmid_row_mapping {
334
+ int32_t i1;
335
+ int32_t i2;
336
+ };
337
+
325
338
  namespace sycl_ex = sycl::ext::oneapi::experimental;
326
339
  struct ggml_backend_sycl_context {
327
340
  int device;
@@ -419,6 +432,8 @@ struct ggml_backend_sycl_context {
419
432
 
420
433
  std::unique_ptr<ggml_sycl_pool> host_pools[GGML_SYCL_MAX_DEVICES];
421
434
 
435
+ std::vector<mmid_row_mapping> mmid_row_mapping_host;
436
+
422
437
  static std::unique_ptr<ggml_sycl_pool> new_pool_for_device(queue_ptr qptr, int device);
423
438
 
424
439
  static std::unique_ptr<ggml_sycl_pool> new_pool_for_host(queue_ptr qptr, int device);
@@ -644,6 +659,8 @@ constexpr size_t ceil_div(const size_t m, const size_t n) {
644
659
 
645
660
  bool gpu_has_xmx(sycl::device &dev);
646
661
 
662
+ int ggml_sycl_get_env(const char *env_name, int default_val);
663
+
647
664
  template <int N, class T> std::string debug_get_array_str(const std::string & prefix, const T array[N]) {
648
665
  if (LIKELY(!g_ggml_sycl_debug)) {
649
666
  return "";
@@ -10,6 +10,8 @@
10
10
  // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
11
  //
12
12
 
13
+ #include "ggml.h"
14
+
13
15
  #include "concat.hpp"
14
16
 
15
17
  static inline size_t elem_size(ggml_type t) {
@@ -192,11 +194,29 @@ void ggml_sycl_op_concat(ggml_backend_sycl_context & ctx, ggml_tensor *dst) {
192
194
  case GGML_TYPE_F32:
193
195
  concat_impl_sycl<float>(ctx, dst);
194
196
  break;
197
+ case GGML_TYPE_F16:
198
+ concat_impl_sycl<sycl::half>(ctx, dst);
199
+ break;
200
+ #ifdef GGML_SYCL_HAS_BF16
201
+ case GGML_TYPE_BF16:
202
+ concat_impl_sycl<sycl::ext::oneapi::bfloat16>(ctx, dst);
203
+ break;
204
+ #endif
195
205
  case GGML_TYPE_I32:
196
206
  concat_impl_sycl<int32_t>(ctx, dst);
197
207
  break;
208
+ case GGML_TYPE_I16:
209
+ concat_impl_sycl<int16_t>(ctx, dst);
210
+ break;
211
+ case GGML_TYPE_I64:
212
+ concat_impl_sycl<int64_t>(ctx, dst);
213
+ break;
214
+ case GGML_TYPE_I8:
215
+ concat_impl_sycl<int8_t>(ctx, dst);
216
+ break;
198
217
  default:
199
- GGML_ASSERT(false && "ggml_sycl_op_concat: unsupported type");
218
+ fprintf(stderr, "%s: unsupported types: dst: %s\n", __func__, ggml_type_name(dst->type));
219
+ GGML_ASSERT(false);
200
220
  break;
201
221
  }
202
222
  }
@@ -0,0 +1,158 @@
1
+ #include "conv2d-dw.hpp"
2
+
3
+ struct conv2d_dw_params {
4
+ int in_w, in_h;
5
+ int out_w, out_h;
6
+ int kernel_w, kernel_h;
7
+ int stride_x, stride_y;
8
+ int padding_x, padding_y;
9
+ int dilation_x, dilation_y;
10
+ int channels, batches;
11
+ };
12
+
13
+ struct conv2d_dw_kernel_bounds {
14
+ int y_min, y_max;
15
+ int x_min, x_max;
16
+ };
17
+
18
+ static inline conv2d_dw_kernel_bounds dw_calculate_kernel_bounds(int out_x, int out_y,
19
+ const conv2d_dw_params & p) {
20
+ conv2d_dw_kernel_bounds bounds;
21
+ bounds.y_min = sycl::max(0, (p.padding_y - out_y * p.stride_y + p.dilation_y - 1) / p.dilation_y);
22
+ bounds.y_max = sycl::min(p.kernel_h,
23
+ (p.in_h + p.padding_y - out_y * p.stride_y + p.dilation_y - 1) / p.dilation_y);
24
+ bounds.x_min = sycl::max(0, (p.padding_x - out_x * p.stride_x + p.dilation_x - 1) / p.dilation_x);
25
+ bounds.x_max = sycl::min(p.kernel_w,
26
+ (p.in_w + p.padding_x - out_x * p.stride_x + p.dilation_x - 1) / p.dilation_x);
27
+ return bounds;
28
+ }
29
+
30
+ static inline int dw_calculate_input_coord(int out_coord, int kern_coord, int stride, int dilation, int padding) {
31
+ return out_coord * stride + kern_coord * dilation - padding;
32
+ }
33
+
34
+ // whcn layout: input/output stored as [N, C, H, W]
35
+ struct dw_whcn_layout {
36
+ static int input_index(int n, int c, int y, int x, const conv2d_dw_params & p) {
37
+ return n * (p.channels * p.in_w * p.in_h) + c * p.in_w * p.in_h + y * p.in_w + x;
38
+ }
39
+ static int kernel_index(int c, int ky, int kx, const conv2d_dw_params & p) {
40
+ return c * p.kernel_h * p.kernel_w + ky * p.kernel_w + kx;
41
+ }
42
+ static int output_index(int n, int c, int y, int x, const conv2d_dw_params & p) {
43
+ return n * (p.channels * p.out_w * p.out_h) + c * p.out_w * p.out_h + y * p.out_w + x;
44
+ }
45
+ static void unpack_indices(int global_idx, const conv2d_dw_params & p,
46
+ int & n, int & c, int & out_y, int & out_x) {
47
+ out_x = global_idx % p.out_w;
48
+ out_y = (global_idx / p.out_w) % p.out_h;
49
+ c = (global_idx / (p.out_w * p.out_h)) % p.channels;
50
+ n = global_idx / (p.out_w * p.out_h * p.channels);
51
+ }
52
+ };
53
+
54
+ // cwhn layout: input/output stored as [N, H, W, C]
55
+ struct dw_cwhn_layout {
56
+ static int input_index(int n, int c, int y, int x, const conv2d_dw_params & p) {
57
+ return n * (p.channels * p.in_w * p.in_h) + (y * p.in_w + x) * p.channels + c;
58
+ }
59
+ static int kernel_index(int c, int ky, int kx, const conv2d_dw_params & p) {
60
+ return (ky * p.kernel_w + kx) * p.channels + c;
61
+ }
62
+ static int output_index(int n, int c, int y, int x, const conv2d_dw_params & p) {
63
+ return n * (p.channels * p.out_w * p.out_h) + y * (p.out_w * p.channels) + x * p.channels + c;
64
+ }
65
+ static void unpack_indices(int global_idx, const conv2d_dw_params & p,
66
+ int & n, int & c, int & out_y, int & out_x) {
67
+ c = global_idx % p.channels;
68
+ out_x = (global_idx / p.channels) % p.out_w;
69
+ out_y = (global_idx / (p.channels * p.out_w)) % p.out_h;
70
+ n = global_idx / (p.channels * p.out_w * p.out_h);
71
+ }
72
+ };
73
+
74
+ template <typename Layout>
75
+ static void conv2d_dw_kernel(const float * input, const float * kernel, float * output,
76
+ const conv2d_dw_params p, const sycl::nd_item<3> & item_ct1) {
77
+ const int global_idx = item_ct1.get_local_id(2) +
78
+ item_ct1.get_group(2) * item_ct1.get_local_range(2);
79
+ const int total_elements = p.batches * p.channels * p.out_h * p.out_w;
80
+
81
+ if (global_idx >= total_elements) {
82
+ return;
83
+ }
84
+
85
+ int n, c, out_y, out_x;
86
+ Layout::unpack_indices(global_idx, p, n, c, out_y, out_x);
87
+
88
+ float acc = 0.0f;
89
+ const conv2d_dw_kernel_bounds bounds = dw_calculate_kernel_bounds(out_x, out_y, p);
90
+
91
+ for (int ky = bounds.y_min; ky < bounds.y_max; ++ky) {
92
+ const int in_y = dw_calculate_input_coord(out_y, ky, p.stride_y, p.dilation_y, p.padding_y);
93
+ for (int kx = bounds.x_min; kx < bounds.x_max; ++kx) {
94
+ const int in_x = dw_calculate_input_coord(out_x, kx, p.stride_x, p.dilation_x, p.padding_x);
95
+ acc += input[Layout::input_index(n, c, in_y, in_x, p)] *
96
+ kernel[Layout::kernel_index(c, ky, kx, p)];
97
+ }
98
+ }
99
+
100
+ output[Layout::output_index(n, c, out_y, out_x, p)] = acc;
101
+ }
102
+
103
+ template <typename Layout>
104
+ static void conv2d_dw_sycl(const float * x_d, const float * w_d, float * y_d,
105
+ const conv2d_dw_params p, const queue_ptr & stream) {
106
+ const int total = p.batches * p.channels * p.out_h * p.out_w;
107
+ const int num_blocks = (total + SYCL_CONV2D_DW_BLOCK_SIZE - 1) / SYCL_CONV2D_DW_BLOCK_SIZE;
108
+ const sycl::range<3> block_dims(1, 1, SYCL_CONV2D_DW_BLOCK_SIZE);
109
+ const sycl::range<3> block_nums(1, 1, num_blocks);
110
+ stream->parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims),
111
+ [=](sycl::nd_item<3> item_ct1) {
112
+ conv2d_dw_kernel<Layout>(x_d, w_d, y_d, p, item_ct1);
113
+ });
114
+ }
115
+
116
+ void ggml_sycl_op_conv2d_dw(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
117
+ scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/2);
118
+
119
+ const ggml_tensor * kernel = dst->src[0];
120
+ const ggml_tensor * input = dst->src[1];
121
+
122
+ GGML_ASSERT(kernel->type == GGML_TYPE_F32 && input->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_F32);
123
+
124
+ const float * w_d = (const float *) kernel->data;
125
+ const float * x_d = (const float *) input->data;
126
+ float * y_d = (float *) dst->data;
127
+
128
+ const int32_t * p = (const int32_t *) dst->op_params;
129
+ const int stride_x = p[0];
130
+ const int stride_y = p[1];
131
+ const int padding_x = p[2];
132
+ const int padding_y = p[3];
133
+ const int dilation_x = p[4];
134
+ const int dilation_y = p[5];
135
+
136
+ const int in_w = input->ne[0];
137
+ const int in_h = input->ne[1];
138
+ const int kernel_w = kernel->ne[0];
139
+ const int kernel_h = kernel->ne[1];
140
+ const int out_w = dst->ne[0];
141
+ const int out_h = dst->ne[1];
142
+ const int channels = dst->ne[2];
143
+ const int batches = dst->ne[3];
144
+
145
+ const conv2d_dw_params params = { in_w, in_h, out_w, out_h, kernel_w, kernel_h,
146
+ stride_x, stride_y, padding_x, padding_y,
147
+ dilation_x, dilation_y, channels, batches };
148
+
149
+ const queue_ptr stream = ctx.stream();
150
+
151
+ if (ggml_is_contiguous(input)) {
152
+ conv2d_dw_sycl<dw_whcn_layout>(x_d, w_d, y_d, params, stream);
153
+ } else if (ggml_is_contiguous_channels(input)) {
154
+ conv2d_dw_sycl<dw_cwhn_layout>(x_d, w_d, y_d, params, stream);
155
+ } else {
156
+ GGML_ABORT("Unsupported memory layout for conv2d_dw");
157
+ }
158
+ }