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
@@ -48,6 +48,287 @@ inline void cpy_blck_f32_q8_0(const char * cxi, char * cdsti) {
48
48
  }
49
49
  }
50
50
 
51
+ inline void cpy_blck_f32_q1_0(const char * cxi, char * cdsti) {
52
+ const float * xi = (const float *) cxi;
53
+ block_q1_0 * dsti = (block_q1_0 *) cdsti;
54
+
55
+ float sum_abs = 0.0f;
56
+ for (int j = 0; j < QK1_0; ++j) {
57
+ sum_abs += sycl::fabs((float) xi[j]);
58
+ }
59
+
60
+ dsti->d = sum_abs / QK1_0;
61
+
62
+ for (int j = 0; j < QK1_0 / 8; ++j) {
63
+ dsti->qs[j] = 0;
64
+ }
65
+
66
+ for (int j = 0; j < QK1_0; ++j) {
67
+ if (xi[j] >= 0.0f) {
68
+ dsti->qs[j / 8] |= (1u << (j % 8));
69
+ }
70
+ }
71
+ }
72
+
73
+ inline int best_index_mxfp4(const float x, const float e) {
74
+ int best_index = 0;
75
+ float best_err = sycl::fabs((float) (kvalues_mxfp4[0] * e - x));
76
+ for (int i = 1; i < 16; ++i) {
77
+ const float err = sycl::fabs((float) (kvalues_mxfp4[i] * e - x));
78
+ if (err < best_err) {
79
+ best_index = i;
80
+ best_err = err;
81
+ }
82
+ }
83
+ return best_index;
84
+ }
85
+
86
+ inline int nearest_int_sycl(float x) {
87
+ const float val = x + 12582912.0f;
88
+ int i;
89
+ memcpy(&i, &val, sizeof(int));
90
+ return (i & 0x007fffff) - 0x00400000;
91
+ }
92
+
93
+ inline int nearest_int_ggml_sycl(float x) {
94
+ return (int) sycl::round((float) x);
95
+ }
96
+
97
+ inline uint8_t clamp_u8(const int x, const int lo, const int hi) {
98
+ return (uint8_t) dpct::max(lo, dpct::min(hi, x));
99
+ }
100
+
101
+ inline int8_t clamp_i8(const int x, const int lo, const int hi) {
102
+ return (int8_t) dpct::max(lo, dpct::min(hi, x));
103
+ }
104
+
105
+ constexpr float GROUP_MAX_EPS_SYCL = 1e-15f;
106
+
107
+ inline float make_qx_quants_sycl(int n, int nmax, const float * x, int8_t * L, int rmse_type, const float * qw) {
108
+ float max = 0.0f;
109
+ float amax = 0.0f;
110
+ for (int i = 0; i < n; ++i) {
111
+ const float ax = sycl::fabs(x[i]);
112
+ if (ax > amax) {
113
+ amax = ax;
114
+ max = x[i];
115
+ }
116
+ }
117
+ if (amax < GROUP_MAX_EPS_SYCL) {
118
+ for (int i = 0; i < n; ++i) {
119
+ L[i] = 0;
120
+ }
121
+ return 0.0f;
122
+ }
123
+
124
+ float iscale = -nmax / max;
125
+ if (rmse_type == 0) {
126
+ for (int i = 0; i < n; ++i) {
127
+ int l = nearest_int_ggml_sycl(iscale * x[i]);
128
+ L[i] = (int8_t) (nmax + dpct::max(-nmax, dpct::min(nmax - 1, l)));
129
+ }
130
+ return 1.0f / iscale;
131
+ }
132
+
133
+ bool return_early = false;
134
+ if (rmse_type < 0) {
135
+ rmse_type = -rmse_type;
136
+ return_early = true;
137
+ }
138
+
139
+ float sumlx = 0.0f;
140
+ float suml2 = 0.0f;
141
+ for (int i = 0; i < n; ++i) {
142
+ int l = nearest_int_ggml_sycl(iscale * x[i]);
143
+ l = dpct::max(-nmax, dpct::min(nmax - 1, l));
144
+ L[i] = (int8_t) (l + nmax);
145
+
146
+ const float w = qw ? qw[i] : (rmse_type == 1 ? x[i] * x[i] :
147
+ rmse_type == 2 ? 1.0f : rmse_type == 3 ? sycl::fabs(x[i]) : sycl::sqrt(sycl::fabs(x[i])));
148
+
149
+ sumlx += w * x[i] * l;
150
+ suml2 += w * l * l;
151
+ }
152
+
153
+ float scale = suml2 ? sumlx / suml2 : 0.0f;
154
+ if (return_early) {
155
+ return suml2 > 0.0f ? 0.5f * (scale + 1.0f / iscale) : 1.0f / iscale;
156
+ }
157
+
158
+ float best = scale * sumlx;
159
+ for (int is = -9; is <= 9; ++is) {
160
+ if (is == 0) {
161
+ continue;
162
+ }
163
+ iscale = -(nmax + 0.1f * is) / max;
164
+ sumlx = 0.0f;
165
+ suml2 = 0.0f;
166
+ for (int i = 0; i < n; ++i) {
167
+ int l = nearest_int_ggml_sycl(iscale * x[i]);
168
+ l = dpct::max(-nmax, dpct::min(nmax - 1, l));
169
+ const float w = qw ? qw[i] : (rmse_type == 1 ? x[i] * x[i] :
170
+ rmse_type == 2 ? 1.0f : rmse_type == 3 ? sycl::fabs(x[i]) : sycl::sqrt(sycl::fabs(x[i])));
171
+ sumlx += w * x[i] * l;
172
+ suml2 += w * l * l;
173
+ }
174
+
175
+ if (suml2 > 0.0f && sumlx * sumlx > best * suml2) {
176
+ for (int i = 0; i < n; ++i) {
177
+ int l = nearest_int_ggml_sycl(iscale * x[i]);
178
+ L[i] = (int8_t) (nmax + dpct::max(-nmax, dpct::min(nmax - 1, l)));
179
+ }
180
+ scale = sumlx / suml2;
181
+ best = scale * sumlx;
182
+ }
183
+ }
184
+
185
+ return scale;
186
+ }
187
+
188
+ inline float make_q3_quants_sycl(int n, int nmax, const float * x, int8_t * L, bool do_rmse) {
189
+ float max = 0.0f;
190
+ float amax = 0.0f;
191
+ for (int i = 0; i < n; ++i) {
192
+ const float ax = sycl::fabs(x[i]);
193
+ if (ax > amax) {
194
+ amax = ax;
195
+ max = x[i];
196
+ }
197
+ }
198
+
199
+ if (amax < GROUP_MAX_EPS_SYCL) {
200
+ for (int i = 0; i < n; ++i) {
201
+ L[i] = 0;
202
+ }
203
+ return 0.0f;
204
+ }
205
+
206
+ const float iscale = -nmax / max;
207
+ if (do_rmse) {
208
+ float sumlx = 0.0f;
209
+ float suml2 = 0.0f;
210
+ for (int i = 0; i < n; ++i) {
211
+ int l = nearest_int_ggml_sycl(iscale * x[i]);
212
+ l = dpct::max(-nmax, dpct::min(nmax - 1, l));
213
+ L[i] = (int8_t) l;
214
+ const float w = x[i] * x[i];
215
+ sumlx += w * x[i] * l;
216
+ suml2 += w * l * l;
217
+ }
218
+
219
+ for (int itry = 0; itry < 5; ++itry) {
220
+ int n_changed = 0;
221
+ for (int i = 0; i < n; ++i) {
222
+ const float w = x[i] * x[i];
223
+ float slx = sumlx - w * x[i] * L[i];
224
+ if (slx > 0.0f) {
225
+ float sl2 = suml2 - w * L[i] * L[i];
226
+ int new_l = nearest_int_ggml_sycl(x[i] * sl2 / slx);
227
+ new_l = dpct::max(-nmax, dpct::min(nmax - 1, new_l));
228
+ if (new_l != L[i]) {
229
+ slx += w * x[i] * new_l;
230
+ sl2 += w * new_l * new_l;
231
+ if (sl2 > 0.0f && slx * slx * suml2 > sumlx * sumlx * sl2) {
232
+ L[i] = (int8_t) new_l;
233
+ sumlx = slx;
234
+ suml2 = sl2;
235
+ ++n_changed;
236
+ }
237
+ }
238
+ }
239
+ }
240
+ if (!n_changed) {
241
+ break;
242
+ }
243
+ }
244
+
245
+ for (int i = 0; i < n; ++i) {
246
+ L[i] += nmax;
247
+ }
248
+ return suml2 > 0.0f ? sumlx / suml2 : 0.0f;
249
+ }
250
+
251
+ for (int i = 0; i < n; ++i) {
252
+ int l = nearest_int_ggml_sycl(iscale * x[i]);
253
+ l = dpct::max(-nmax, dpct::min(nmax - 1, l));
254
+ L[i] = (int8_t) (l + nmax);
255
+ }
256
+
257
+ return 1.0f / iscale;
258
+ }
259
+
260
+ inline void set_scale_min_k4(int j, uint8_t * q, uint8_t d, uint8_t m) {
261
+ if (j < 4) {
262
+ q[j] = (q[j] & 0xC0) | (d & 0x3F);
263
+ q[j + 4] = (q[j + 4] & 0xC0) | (m & 0x3F);
264
+ } else {
265
+ q[j + 4] = (d & 0x0F) | ((m & 0x0F) << 4);
266
+ q[j - 4] = (q[j - 4] & 0x3F) | ((d >> 4) << 6);
267
+ q[j - 0] = (q[j - 0] & 0x3F) | ((m >> 4) << 6);
268
+ }
269
+ }
270
+
271
+ inline void get_scale_min_k4_local(int j, const uint8_t * q, uint8_t & d, uint8_t & m) {
272
+ if (j < 4) {
273
+ d = q[j] & 63;
274
+ m = q[j + 4] & 63;
275
+ } else {
276
+ d = (q[j + 4] & 0xF) | ((q[j - 4] >> 6) << 4);
277
+ m = (q[j + 4] >> 4) | ((q[j - 0] >> 6) << 4);
278
+ }
279
+ }
280
+
281
+ inline void cpy_blck_f32_mxfp4(const char * cxi, char * cdsti) {
282
+ const float * xi = (const float *) cxi;
283
+ block_mxfp4 * dsti = (block_mxfp4 *) cdsti;
284
+
285
+ float amax = 0.0f;
286
+ for (int j = 0; j < QK_MXFP4; ++j) {
287
+ amax = sycl::fmax(amax, sycl::fabs((float) xi[j]));
288
+ }
289
+
290
+ const uint8_t e = amax > 0.0f ? (uint8_t) (sycl::floor(sycl::log2(amax)) - 2 + 127) : 0;
291
+ const float d = GGML_E8M0_TO_FP32_HALF(e);
292
+
293
+ dsti->e = e;
294
+
295
+ for (int j = 0; j < QK_MXFP4 / 2; ++j) {
296
+ const uint8_t x0 = best_index_mxfp4(xi[0 + j], d);
297
+ const uint8_t x1 = best_index_mxfp4(xi[QK_MXFP4 / 2 + j], d);
298
+
299
+ dsti->qs[j] = x0;
300
+ dsti->qs[j] |= x1 << 4;
301
+ }
302
+ }
303
+
304
+ inline void cpy_blck_f32_nvfp4(const char * cxi, char * cdsti) {
305
+ const float * xi = (const float *) cxi;
306
+ block_nvfp4 * dsti = (block_nvfp4 *) cdsti;
307
+
308
+ constexpr int n_sub = QK_NVFP4 / QK_NVFP4_SUB;
309
+
310
+ for (int s = 0; s < n_sub; ++s) {
311
+ const float * xb = xi + s * QK_NVFP4_SUB;
312
+
313
+ float amax = 0.0f;
314
+ for (int j = 0; j < QK_NVFP4_SUB; ++j) {
315
+ amax = sycl::fmax(amax, sycl::fabs((float) xb[j]));
316
+ }
317
+
318
+ const uint8_t ue = ggml_fp32_to_ue4m3(amax / 6.0f);
319
+ dsti->d[s] = ue;
320
+ const float d = ggml_sycl_ue4m3_to_fp32(ue);
321
+
322
+ for (int j = 0; j < QK_NVFP4_SUB / 2; ++j) {
323
+ const uint8_t x0 = best_index_mxfp4(xb[0 + j], d);
324
+ const uint8_t x1 = best_index_mxfp4(xb[QK_NVFP4_SUB / 2 + j], d);
325
+
326
+ dsti->qs[s * (QK_NVFP4_SUB / 2) + j] = x0 | (x1 << 4);
327
+ }
328
+ }
329
+ }
330
+
331
+
51
332
  inline void cpy_blck_f32_q4_0(const char * cxi, char * cdsti) {
52
333
  const float * xi = (const float *) cxi;
53
334
  block_q4_0 * dsti = (block_q4_0 *) cdsti;
@@ -0,0 +1,255 @@
1
+ #include "cross_entropy_loss.hpp"
2
+
3
+ #include <cstdint>
4
+ #include <cmath>
5
+
6
+ template <bool has_shared>
7
+ static __dpct_inline__ void cross_entropy_loss_f32_kernel(
8
+ const float * __restrict__ logits,
9
+ const float * __restrict__ labels,
10
+ float * __restrict__ row_loss,
11
+ const int nclasses,
12
+ const int nrows,
13
+ float * __restrict__ smem,
14
+ const sycl::nd_item<3> & item) {
15
+
16
+ const int row = item.get_group(2);
17
+ const int tid = item.get_local_id(2);
18
+
19
+ logits += (int64_t) row * nclasses;
20
+ labels += (int64_t) row * nclasses;
21
+
22
+ float max_logit = -INFINITY;
23
+ for (int i = tid; i < nclasses; i += WARP_SIZE) {
24
+ const float v = logits[i];
25
+ max_logit = sycl::fmax(max_logit, v);
26
+ if (has_shared) {
27
+ smem[i] = v;
28
+ }
29
+ }
30
+ max_logit = warp_reduce_max<WARP_SIZE>(max_logit);
31
+
32
+ float sum_exp = 0.0f;
33
+ for (int i = tid; i < nclasses; i += WARP_SIZE) {
34
+ const float v = has_shared ? smem[i] : logits[i];
35
+ sum_exp += sycl::exp(v - max_logit);
36
+ }
37
+ sum_exp = warp_reduce_sum<WARP_SIZE>(sum_exp);
38
+ const float log_sum = sycl::log(sum_exp);
39
+
40
+ float loss = 0.0f;
41
+ for (int i = tid; i < nclasses; i += WARP_SIZE) {
42
+ const float v = has_shared ? smem[i] : logits[i];
43
+ loss += (v - max_logit - log_sum) * labels[i];
44
+ }
45
+ loss = -warp_reduce_sum<WARP_SIZE>(loss) / (float) nrows;
46
+
47
+ if (tid == 0) {
48
+ row_loss[row] = loss;
49
+ }
50
+ }
51
+
52
+ template <bool has_shared>
53
+ static __dpct_inline__ void cross_entropy_loss_back_f32_kernel(
54
+ const float * __restrict__ grad,
55
+ const float * __restrict__ logits,
56
+ const float * __restrict__ labels,
57
+ float * __restrict__ dst,
58
+ const int nclasses,
59
+ const int nrows,
60
+ float * __restrict__ smem,
61
+ const sycl::nd_item<3> & item) {
62
+
63
+ const int row = item.get_group(2);
64
+ const int tid = item.get_local_id(2);
65
+
66
+ logits += (int64_t) row * nclasses;
67
+ labels += (int64_t) row * nclasses;
68
+ dst += (int64_t) row * nclasses;
69
+
70
+ float max_logit = -INFINITY;
71
+ for (int i = tid; i < nclasses; i += WARP_SIZE) {
72
+ const float v = logits[i];
73
+ max_logit = sycl::fmax(max_logit, v);
74
+ if (has_shared) {
75
+ smem[i] = v;
76
+ }
77
+ }
78
+ max_logit = warp_reduce_max<WARP_SIZE>(max_logit);
79
+
80
+ float sum_exp = 0.0f;
81
+ for (int i = tid; i < nclasses; i += WARP_SIZE) {
82
+ const float v = sycl::exp((has_shared ? smem[i] : logits[i]) - max_logit);
83
+ sum_exp += v;
84
+ if (has_shared) {
85
+ smem[i] = v;
86
+ } else {
87
+ dst[i] = v;
88
+ }
89
+ }
90
+ sum_exp = warp_reduce_sum<WARP_SIZE>(sum_exp);
91
+ const float inv_sum = 1.0f / sum_exp;
92
+
93
+ const float d_by_nrows = grad[0] / (float) nrows;
94
+ for (int i = tid; i < nclasses; i += WARP_SIZE) {
95
+ const float sm_num = has_shared ? smem[i] : dst[i];
96
+ dst[i] = (sm_num * inv_sum - labels[i]) * d_by_nrows;
97
+ }
98
+ }
99
+
100
+ static void cross_entropy_reduce_rows(
101
+ ggml_backend_sycl_context & ctx,
102
+ const float * row_loss,
103
+ float * dst,
104
+ const int64_t nrows) {
105
+ if (nrows == 1) {
106
+ SYCL_CHECK(CHECK_TRY_ERROR(
107
+ ctx.stream()->memcpy(dst, row_loss, sizeof(float))));
108
+ return;
109
+ }
110
+
111
+ ggml_sycl_pool_alloc<float> tmp_alloc(ctx.pool(), nrows);
112
+ float * tmp = tmp_alloc.get();
113
+ SYCL_CHECK(CHECK_TRY_ERROR(
114
+ ctx.stream()->memcpy(tmp, row_loss, nrows * sizeof(float))));
115
+
116
+ int64_t cur = nrows;
117
+ while (cur > 1) {
118
+ const int64_t out = (cur + WARP_SIZE - 1) / WARP_SIZE;
119
+ const sycl::range<3> block(1, 1, WARP_SIZE);
120
+ const sycl::range<3> grid(1, 1, out);
121
+ ctx.stream()->parallel_for(
122
+ sycl::nd_range<3>(grid * block, block),
123
+ [=](sycl::nd_item<3> item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] {
124
+ const int row = item.get_group(2);
125
+ const int tid = item.get_local_id(2);
126
+ const int64_t i = (int64_t) row * WARP_SIZE + tid;
127
+ float v = i < cur ? tmp[i] : 0.0f;
128
+ v = warp_reduce_sum<WARP_SIZE>(v);
129
+ if (tid == 0) {
130
+ tmp[row] = v;
131
+ }
132
+ });
133
+ cur = out;
134
+ }
135
+
136
+ SYCL_CHECK(CHECK_TRY_ERROR(
137
+ ctx.stream()->memcpy(dst, tmp, sizeof(float))));
138
+ }
139
+
140
+ void ggml_sycl_cross_entropy_loss(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
141
+ scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/2);
142
+
143
+ const ggml_tensor * src0 = dst->src[0];
144
+ const ggml_tensor * src1 = dst->src[1];
145
+
146
+ GGML_ASSERT(src0->type == GGML_TYPE_F32);
147
+ GGML_ASSERT(src1->type == GGML_TYPE_F32);
148
+ GGML_ASSERT(dst->type == GGML_TYPE_F32);
149
+ GGML_ASSERT(ggml_is_contiguous(src0));
150
+ GGML_ASSERT(ggml_is_contiguous(src1));
151
+ GGML_ASSERT(ggml_is_contiguous(dst));
152
+ GGML_ASSERT(ggml_are_same_shape(src0, src1));
153
+ GGML_ASSERT(ggml_is_scalar(dst));
154
+
155
+ SYCL_CHECK(ggml_sycl_set_device(ctx.device));
156
+
157
+ const int64_t nclasses = src0->ne[0];
158
+ const int64_t nrows = ggml_nrows(src0);
159
+
160
+ const float * logits_d = (const float *) src0->data;
161
+ const float * labels_d = (const float *) src1->data;
162
+ float * dst_d = (float *) dst->data;
163
+
164
+ ggml_sycl_pool_alloc<float> row_loss_alloc(ctx.pool(), nrows);
165
+ float * row_loss = row_loss_alloc.get();
166
+
167
+ const sycl::range<3> block(1, 1, WARP_SIZE);
168
+ const sycl::range<3> grid(1, 1, nrows);
169
+ const size_t nbytes_shared = (size_t) nclasses * sizeof(float);
170
+ const size_t smpbo = ggml_sycl_info().devices[ctx.device].smpbo;
171
+
172
+ if (nbytes_shared <= smpbo) {
173
+ ctx.stream()->submit([&](sycl::handler & cgh) {
174
+ sycl::local_accessor<float, 1> smem(sycl::range<1>(nclasses), cgh);
175
+ cgh.parallel_for(
176
+ sycl::nd_range<3>(grid * block, block),
177
+ [=](sycl::nd_item<3> item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] {
178
+ cross_entropy_loss_f32_kernel<true>(
179
+ logits_d, labels_d, row_loss,
180
+ (int) nclasses, (int) nrows,
181
+ get_pointer(smem), item);
182
+ });
183
+ });
184
+ } else {
185
+ ctx.stream()->parallel_for(
186
+ sycl::nd_range<3>(grid * block, block),
187
+ [=](sycl::nd_item<3> item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] {
188
+ cross_entropy_loss_f32_kernel<false>(
189
+ logits_d, labels_d, row_loss,
190
+ (int) nclasses, (int) nrows,
191
+ nullptr, item);
192
+ });
193
+ }
194
+
195
+ cross_entropy_reduce_rows(ctx, row_loss, dst_d, nrows);
196
+ }
197
+
198
+ void ggml_sycl_cross_entropy_loss_back(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
199
+ scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/3);
200
+
201
+ const ggml_tensor * grad = dst->src[0];
202
+ const ggml_tensor * src0f = dst->src[1];
203
+ const ggml_tensor * src1f = dst->src[2];
204
+
205
+ GGML_ASSERT(grad->type == GGML_TYPE_F32);
206
+ GGML_ASSERT(src0f->type == GGML_TYPE_F32);
207
+ GGML_ASSERT(src1f->type == GGML_TYPE_F32);
208
+ GGML_ASSERT(dst->type == GGML_TYPE_F32);
209
+
210
+ GGML_ASSERT(ggml_is_scalar(grad));
211
+ GGML_ASSERT(ggml_is_contiguous(grad));
212
+ GGML_ASSERT(ggml_is_contiguous(src0f));
213
+ GGML_ASSERT(ggml_is_contiguous(src1f));
214
+ GGML_ASSERT(ggml_is_contiguous(dst));
215
+ GGML_ASSERT(ggml_are_same_shape(src0f, src1f));
216
+ GGML_ASSERT(ggml_are_same_shape(src0f, dst));
217
+
218
+ SYCL_CHECK(ggml_sycl_set_device(ctx.device));
219
+
220
+ const int64_t nclasses = src0f->ne[0];
221
+ const int64_t nrows = ggml_nrows(src0f);
222
+
223
+ const float * grad_d = (const float *) grad->data;
224
+ const float * logits_d = (const float *) src0f->data;
225
+ const float * labels_d = (const float *) src1f->data;
226
+ float * dst_d = (float *) dst->data;
227
+
228
+ const sycl::range<3> block(1, 1, WARP_SIZE);
229
+ const sycl::range<3> grid(1, 1, nrows);
230
+ const size_t nbytes_shared = (size_t) nclasses * sizeof(float);
231
+ const size_t smpbo = ggml_sycl_info().devices[ctx.device].smpbo;
232
+
233
+ if (nbytes_shared <= smpbo) {
234
+ ctx.stream()->submit([&](sycl::handler & cgh) {
235
+ sycl::local_accessor<float, 1> smem(sycl::range<1>(nclasses), cgh);
236
+ cgh.parallel_for(
237
+ sycl::nd_range<3>(grid * block, block),
238
+ [=](sycl::nd_item<3> item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] {
239
+ cross_entropy_loss_back_f32_kernel<true>(
240
+ grad_d, logits_d, labels_d, dst_d,
241
+ (int) nclasses, (int) nrows,
242
+ get_pointer(smem), item);
243
+ });
244
+ });
245
+ } else {
246
+ ctx.stream()->parallel_for(
247
+ sycl::nd_range<3>(grid * block, block),
248
+ [=](sycl::nd_item<3> item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] {
249
+ cross_entropy_loss_back_f32_kernel<false>(
250
+ grad_d, logits_d, labels_d, dst_d,
251
+ (int) nclasses, (int) nrows,
252
+ nullptr, item);
253
+ });
254
+ }
255
+ }
@@ -0,0 +1,7 @@
1
+ #pragma once
2
+
3
+ #include "common.hpp"
4
+
5
+ void ggml_sycl_cross_entropy_loss(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
6
+
7
+ void ggml_sycl_cross_entropy_loss_back(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
@@ -70,6 +70,21 @@ static __dpct_inline__ void dequantize_q4_0_reorder(const void *d_ptr, const int
70
70
  #endif // GGML_SYCL_F16
71
71
  }
72
72
 
73
+ static __dpct_inline__ void dequantize_q1_0_reorder(const void *d_ptr, const int64_t ib, const void *qs,
74
+ const int iqs, dfloat2 &v) {
75
+ // Q1_0 reorder layout: scale values followed by quantized bits
76
+ const dfloat d = (const dfloat)*((const sycl::half*)d_ptr+ib);
77
+
78
+ const int bit_index_0 = iqs + 0;
79
+ const int bit_index_1 = iqs + 1;
80
+
81
+ const int bit_0 = (*((const uint8_t *)qs + bit_index_0 / 8) >> (bit_index_0 % 8)) & 1;
82
+ const int bit_1 = (*((const uint8_t *)qs + bit_index_1 / 8) >> (bit_index_1 % 8)) & 1;
83
+
84
+ v.x() = (2 * bit_0 - 1) * d;
85
+ v.y() = (2 * bit_1 - 1) * d;
86
+ }
87
+
73
88
  static __dpct_inline__ void dequantize_q4_1(const void *vx, const int64_t ib,
74
89
  const int iqs, dfloat2 &v) {
75
90
  const block_q4_1 * x = (const block_q4_1 *) vx;