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.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/ext/options.rb +1 -1
- data/ext/ruby_whisper.c +0 -1
- data/ext/ruby_whisper.h +7 -1
- data/ext/ruby_whisper_context.c +50 -1
- data/ext/ruby_whisper_log_settable.h +1 -2
- data/ext/ruby_whisper_params.c +9 -8
- data/ext/ruby_whisper_transcribe.cpp +0 -19
- data/ext/ruby_whisper_vad_context.c +30 -10
- data/ext/ruby_whisper_vad_context_detect.cpp +8 -9
- data/ext/ruby_whisper_vad_params.c +4 -4
- data/ext/ruby_whisper_vad_segment.c +2 -2
- data/ext/sources/CMakeLists.txt +2 -1
- data/ext/sources/cmake/parakeet.pc.in +2 -2
- data/ext/sources/cmake/whisper.pc.in +2 -2
- data/ext/sources/examples/cli/cli.cpp +9 -1
- data/ext/sources/examples/common-ggml.cpp +2 -0
- data/ext/sources/examples/vad-speech-segments/speech.cpp +3 -2
- data/ext/sources/ggml/CMakeLists.txt +3 -4
- data/ext/sources/ggml/include/ggml-cuda.h +0 -3
- data/ext/sources/ggml/include/ggml-sycl.h +8 -0
- data/ext/sources/ggml/include/ggml.h +3 -1
- data/ext/sources/ggml/src/CMakeLists.txt +8 -1
- data/ext/sources/ggml/src/ggml-backend-meta.cpp +7 -4
- data/ext/sources/ggml/src/ggml-common.h +13 -2
- data/ext/sources/ggml/src/ggml-cpu/CMakeLists.txt +1 -1
- data/ext/sources/ggml/src/ggml-cpu/amx/mmq.cpp +5 -6
- data/ext/sources/ggml/src/ggml-cpu/arch/arm/quants.c +78 -4
- data/ext/sources/ggml/src/ggml-cpu/arch/x86/quants.c +142 -4
- data/ext/sources/ggml/src/ggml-cpu/arch-fallback.h +7 -2
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.c +14 -0
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm.cpp +26 -19
- data/ext/sources/ggml/src/ggml-cpu/ops.cpp +129 -46
- data/ext/sources/ggml/src/ggml-cpu/quants.c +51 -0
- data/ext/sources/ggml/src/ggml-cpu/quants.h +3 -0
- data/ext/sources/ggml/src/ggml-cpu/simd-gemm.h +1 -1
- data/ext/sources/ggml/src/ggml-cpu/simd-mappings.h +11 -0
- data/ext/sources/ggml/src/ggml-cpu/vec.cpp +2 -2
- data/ext/sources/ggml/src/ggml-cuda/binbcast.cu +90 -46
- data/ext/sources/ggml/src/ggml-cuda/col2im-1d.cu +81 -0
- data/ext/sources/ggml/src/ggml-cuda/col2im-1d.cuh +3 -0
- data/ext/sources/ggml/src/ggml-cuda/common.cuh +4 -0
- data/ext/sources/ggml/src/ggml-cuda/concat.cu +33 -21
- data/ext/sources/ggml/src/ggml-cuda/conv-transpose-1d.cu +14 -12
- data/ext/sources/ggml/src/ggml-cuda/convert.cu +86 -34
- data/ext/sources/ggml/src/ggml-cuda/cpy.cu +80 -29
- data/ext/sources/ggml/src/ggml-cuda/fattn-common.cuh +9 -5
- data/ext/sources/ggml/src/ggml-cuda/fattn-mma-f16.cuh +4 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile.cuh +9 -5
- data/ext/sources/ggml/src/ggml-cuda/fattn.cu +27 -21
- data/ext/sources/ggml/src/ggml-cuda/gated_delta_net.cu +40 -25
- data/ext/sources/ggml/src/ggml-cuda/gated_delta_net.cuh +10 -0
- data/ext/sources/ggml/src/ggml-cuda/getrows.cu +15 -12
- data/ext/sources/ggml/src/ggml-cuda/ggml-cuda.cu +718 -1248
- data/ext/sources/ggml/src/ggml-cuda/mmq.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/mmvq.cu +77 -40
- data/ext/sources/ggml/src/ggml-cuda/out-prod.cu +55 -12
- data/ext/sources/ggml/src/ggml-cuda/set-rows.cu +64 -4
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/topk-moe.cu +7 -1
- data/ext/sources/ggml/src/ggml-cuda/vendors/hip.h +1 -0
- data/ext/sources/ggml/src/ggml-cuda/vendors/musa.h +1 -0
- data/ext/sources/ggml/src/ggml-hexagon/CMakeLists.txt +0 -5
- data/ext/sources/ggml/src/ggml-hexagon/ggml-hexagon.cpp +1634 -1293
- data/ext/sources/ggml/src/ggml-hexagon/htp/CMakeLists.txt +11 -40
- data/ext/sources/ggml/src/ggml-hexagon/htp/cmake-toolchain.cmake +13 -15
- data/ext/sources/ggml/src/ggml-hexagon/htp/concat-ops.c +1 -1
- data/ext/sources/ggml/src/ggml-hexagon/htp/flash-attn-ops.c +1749 -399
- data/ext/sources/ggml/src/ggml-hexagon/htp/flash-attn-ops.h +303 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-common.h +80 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-dma.h +26 -23
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-profile.h +64 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-utils.h +1 -83
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-fa-kernels.h +555 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-mm-kernels-tiled.h +1303 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-queue.c +9 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-queue.h +27 -4
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-utils.h +59 -37
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ctx.h +11 -3
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ops.h +52 -12
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-vtcm.h +19 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp_iface.idl +2 -1
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-base.h +14 -30
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-exp.h +39 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-fa-kernels.h +232 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-mm-kernels-flat.h +1511 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-mm-kernels-tiled.h +1200 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-sigmoid.h +39 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/main.c +127 -32
- data/ext/sources/ggml/src/ggml-hexagon/htp/matmul-ops.c +3023 -4425
- data/ext/sources/ggml/src/ggml-hexagon/htp/matmul-ops.h +650 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/rope-ops.c +48 -13
- data/ext/sources/ggml/src/ggml-hexagon/htp/ssm-conv.c +10 -9
- data/ext/sources/ggml/src/ggml-hexagon/htp/worker-pool.c +15 -3
- data/ext/sources/ggml/src/ggml-hexagon/htp/worker-pool.h +8 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp-opnode.h +168 -50
- data/ext/sources/ggml/src/ggml-hexagon/libggml-htp.inf +0 -4
- data/ext/sources/ggml/src/ggml-hip/CMakeLists.txt +5 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.cpp +69 -5
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.h +4 -1
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.m +27 -6
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-impl.h +38 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.cpp +132 -2
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.h +2 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.metal +345 -87
- data/ext/sources/ggml/src/ggml-opencl/CMakeLists.txt +13 -0
- data/ext/sources/ggml/src/ggml-opencl/fa_tune.h +92 -0
- data/ext/sources/ggml/src/ggml-opencl/ggml-opencl.cpp +4060 -357
- data/ext/sources/ggml/src/ggml-opencl/kernels/cvt.cl +198 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f16.cl +81 -41
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32.cl +88 -39
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32_f16.cl +1995 -96
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32_q4_0.cl +1615 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32_q8_0.cl +1486 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_pre_f16.cl +156 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_mxfp4_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_0_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_1_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_k_f32_ns.cl +71 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_0_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_1_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_k_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q6_k_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q1_0_f32.cl +94 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q1_0_f32.cl +121 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q8_0_f32.cl +1 -1
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q1_0_f32_l4_lm.cl +156 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_l4.cl +1149 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q1_0_f32.cl +141 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q1_0_f32_flat.cl +190 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/norm.cl +5 -2
- data/ext/sources/ggml/src/ggml-opencl/kernels/set_rows.cl +500 -0
- data/ext/sources/ggml/src/ggml-opencl/libdl.h +79 -0
- data/ext/sources/ggml/src/ggml-openvino/.clang-format +0 -5
- data/ext/sources/ggml/src/ggml-openvino/CMakeLists.txt +2 -4
- data/ext/sources/ggml/src/ggml-openvino/ggml-decoder.cpp +733 -130
- data/ext/sources/ggml/src/ggml-openvino/ggml-decoder.h +76 -23
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino-extra.cpp +57 -3
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino-extra.h +29 -8
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino.cpp +307 -59
- data/ext/sources/ggml/src/ggml-openvino/ggml-quants.cpp +66 -0
- data/ext/sources/ggml/src/ggml-openvino/ggml-quants.h +10 -4
- data/ext/sources/ggml/src/ggml-openvino/openvino/decoder.h +56 -16
- data/ext/sources/ggml/src/ggml-openvino/openvino/frontend.h +1 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/input_model.h +4 -4
- data/ext/sources/ggml/src/ggml-openvino/openvino/node_context.h +94 -37
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/add_id.cpp +76 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/argsort.cpp +47 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/clamp.cpp +33 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/concat.cpp +48 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/cont.cpp +8 -16
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/cpy.cpp +14 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/div.cpp +146 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/flash_attn_ext.cpp +108 -21
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/gated_delta_net.cpp +282 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/gated_delta_net.hpp +65 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/get_rows.cpp +2 -9
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/glu_geglu.cpp +21 -7
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/glu_swiglu.cpp +41 -8
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/im2col.cpp +120 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/l2_norm.cpp +44 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/mul_mat_id.cpp +226 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/mulmat.cpp +19 -9
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/norm.cpp +58 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/pad.cpp +95 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/permute.cpp +58 -13
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/repeat.cpp +74 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/reshape.cpp +13 -6
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/rms_norm.cpp +1 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/rope.cpp +134 -38
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/set_rows.cpp +3 -3
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/softmax.cpp +126 -49
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/ssm_conv.cpp +59 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/sum_rows.cpp +27 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/transpose.cpp +32 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/unary_silu.cpp +1 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/unary_softplus.cpp +38 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/view.cpp +90 -25
- data/ext/sources/ggml/src/ggml-openvino/openvino/op_table.cpp +41 -23
- data/ext/sources/ggml/src/ggml-openvino/openvino/op_table.h +18 -5
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/mark_decompression_convert_constant_folding.h +1 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/translate_session.cpp +43 -40
- data/ext/sources/ggml/src/ggml-openvino/openvino/translate_session.h +5 -4
- data/ext/sources/ggml/src/ggml-openvino/openvino/utils.cpp +548 -3
- data/ext/sources/ggml/src/ggml-openvino/openvino/utils.h +28 -26
- data/ext/sources/ggml/src/ggml-openvino/utils.cpp +383 -94
- data/ext/sources/ggml/src/ggml-openvino/utils.h +11 -8
- data/ext/sources/ggml/src/ggml-quants.c +76 -0
- data/ext/sources/ggml/src/ggml-quants.h +3 -0
- data/ext/sources/ggml/src/ggml-sycl/CMakeLists.txt +5 -5
- data/ext/sources/ggml/src/ggml-sycl/backend.hpp +2 -0
- data/ext/sources/ggml/src/ggml-sycl/binbcast.cpp +12 -0
- data/ext/sources/ggml/src/ggml-sycl/col2im-1d.cpp +102 -0
- data/ext/sources/ggml/src/ggml-sycl/col2im-1d.hpp +8 -0
- data/ext/sources/ggml/src/ggml-sycl/common.cpp +6 -8
- data/ext/sources/ggml/src/ggml-sycl/common.hpp +19 -2
- data/ext/sources/ggml/src/ggml-sycl/concat.cpp +21 -1
- data/ext/sources/ggml/src/ggml-sycl/conv2d-dw.cpp +158 -0
- data/ext/sources/ggml/src/ggml-sycl/conv2d-dw.hpp +10 -0
- data/ext/sources/ggml/src/ggml-sycl/conv2d-transpose.cpp +125 -0
- data/ext/sources/ggml/src/ggml-sycl/conv2d-transpose.hpp +10 -0
- data/ext/sources/ggml/src/ggml-sycl/conv2d.cpp +150 -0
- data/ext/sources/ggml/src/ggml-sycl/conv2d.hpp +10 -0
- data/ext/sources/ggml/src/ggml-sycl/conv3d.cpp +224 -0
- data/ext/sources/ggml/src/ggml-sycl/conv3d.hpp +8 -0
- data/ext/sources/ggml/src/ggml-sycl/convert.cpp +6 -0
- data/ext/sources/ggml/src/ggml-sycl/cpy.cpp +706 -0
- data/ext/sources/ggml/src/ggml-sycl/cpy.hpp +281 -0
- data/ext/sources/ggml/src/ggml-sycl/cross_entropy_loss.cpp +255 -0
- data/ext/sources/ggml/src/ggml-sycl/cross_entropy_loss.hpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/dequantize.hpp +15 -0
- data/ext/sources/ggml/src/ggml-sycl/dmmv.cpp +492 -319
- data/ext/sources/ggml/src/ggml-sycl/dpct/helper.hpp +15 -7
- data/ext/sources/ggml/src/ggml-sycl/element_wise.cpp +215 -115
- data/ext/sources/ggml/src/ggml-sycl/element_wise.hpp +2 -0
- data/ext/sources/ggml/src/ggml-sycl/ggml-sycl.cpp +1006 -336
- data/ext/sources/ggml/src/ggml-sycl/mmvq.cpp +252 -67
- data/ext/sources/ggml/src/ggml-sycl/mmvq.hpp +17 -0
- data/ext/sources/ggml/src/ggml-sycl/norm.cpp +103 -49
- data/ext/sources/ggml/src/ggml-sycl/outprod.cpp +45 -9
- data/ext/sources/ggml/src/ggml-sycl/pool.cpp +185 -0
- data/ext/sources/ggml/src/ggml-sycl/pool.hpp +22 -0
- data/ext/sources/ggml/src/ggml-sycl/presets.hpp +3 -1
- data/ext/sources/ggml/src/ggml-sycl/set_rows.cpp +10 -2
- data/ext/sources/ggml/src/ggml-sycl/softmax.cpp +9 -10
- data/ext/sources/ggml/src/ggml-sycl/vecdotq.hpp +35 -0
- data/ext/sources/ggml/src/ggml-vulkan/CMakeLists.txt +5 -0
- data/ext/sources/ggml/src/ggml-vulkan/ggml-vulkan.cpp +833 -215
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/col2im_1d.comp +61 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_mm.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv3d_mm.comp +431 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +1 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +1 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/generic_unary_head.glsl +21 -19
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/get_rows_back.comp +25 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/glu_head.glsl +23 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/glu_main.glsl +14 -18
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +4 -7
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq.comp +21 -24
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +31 -23
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +6 -5
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_funcs.glsl +84 -67
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/norm.comp +10 -10
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/repeat_back.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/roll.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/unary.comp +168 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +121 -74
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp +26 -19
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu.cpp +31 -36
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/common_decls.tmpl +16 -2
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_split.wgsl +7 -7
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/get_rows.wgsl +21 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_decls.tmpl +439 -320
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id_vec.wgsl +2 -2
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec.wgsl +45 -39
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec_acc.tmpl +586 -465
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec_q_acc.tmpl +63 -69
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/quantize_q8.wgsl +14 -9
- data/ext/sources/ggml/src/ggml.c +36 -14
- data/ext/sources/include/whisper.h +21 -0
- data/ext/sources/src/whisper.cpp +164 -14
- data/lib/whisper/log_settable.rb +5 -8
- data/lib/whisper/model/uri.rb +0 -7
- data/sig/whisper.rbs +6 -0
- data/test/test_vad.rb +9 -0
- data/test/test_vad_context.rb +2 -2
- data/whispercpp.gemspec +1 -1
- metadata +62 -37
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-flash-attn-ops.c +0 -1878
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-matmul-ops.c +0 -2066
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-ops.c +0 -6
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-ops.h +0 -88
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-profile.h +0 -34
- data/ext/sources/ggml/src/ggml-hexagon/htp/vtcm-utils.h +0 -16
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/unary_gelu.cpp +0 -25
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/abs.comp +0 -21
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/ceil.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp +0 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/cos.comp +0 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/elu.comp +0 -27
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/exp.comp +0 -20
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/floor.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu.comp +0 -25
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu_erf.comp +0 -39
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu_quick.comp +0 -23
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/hardsigmoid.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/hardswish.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/leaky_relu.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/neg.comp +0 -20
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/relu.comp +0 -21
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/round.comp +0 -29
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sgn.comp +0 -21
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sigmoid.comp +0 -20
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/silu.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sin.comp +0 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/softplus.comp +0 -23
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sqrt.comp +0 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/square.comp +0 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/step.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/tanh.comp +0 -20
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/trunc.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/xielu.comp +0 -35
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
#ifndef HTP_FLASH_ATTN_OPS_H
|
|
2
|
+
#define HTP_FLASH_ATTN_OPS_H
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
#include <stdbool.h>
|
|
7
|
+
|
|
8
|
+
#include "hex-fastdiv.h"
|
|
9
|
+
#include "hex-common.h"
|
|
10
|
+
#include "htp-vtcm.h"
|
|
11
|
+
|
|
12
|
+
#ifdef __cplusplus
|
|
13
|
+
extern "C" {
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Tile constants (mirrored from hmx-utils.h for use on host side if needed)
|
|
17
|
+
#define HTP_FA_HMX_TILE_SIZE 2048
|
|
18
|
+
#define HMX_FP16_TILE_SIZE 2048
|
|
19
|
+
#define HMX_FP16_TILE_N_ROWS 32
|
|
20
|
+
#define HMX_FP16_TILE_N_COLS 32
|
|
21
|
+
#define HMX_FP16_TILE_N_ELMS 1024
|
|
22
|
+
|
|
23
|
+
#define HVX_FA_DMA_CACHE_SIZE 128
|
|
24
|
+
#define HMX_FA_DMA_CACHE_SIZE 4
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
#define HTP_FA_M_INITIAL_VAL -10000.0f
|
|
28
|
+
|
|
29
|
+
enum htp_fa_kernel_type {
|
|
30
|
+
HTP_FA_KERNEL_UNSUPPORTED = 0,
|
|
31
|
+
HTP_FA_KERNEL_HVX,
|
|
32
|
+
HTP_FA_KERNEL_HMX
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
struct htp_fa_kernel_params {
|
|
36
|
+
uint8_t kernel_type; // enum htp_fa_kernel_type
|
|
37
|
+
uint8_t is_q_fp32; // 1 = Q type is F32, 0 = F16
|
|
38
|
+
uint8_t is_dst_fp32; // 1 = dst type is F32, 0 = F16
|
|
39
|
+
uint8_t n_threads; // Number of threads to run
|
|
40
|
+
|
|
41
|
+
// Common parameters
|
|
42
|
+
uint16_t Br;
|
|
43
|
+
uint16_t Bc;
|
|
44
|
+
uint16_t n_kv_blocks; // also HVX's n_blocks
|
|
45
|
+
uint16_t G; // GQA factor (n_heads / n_kv_heads)
|
|
46
|
+
|
|
47
|
+
float scale;
|
|
48
|
+
float max_bias;
|
|
49
|
+
float logit_softcap;
|
|
50
|
+
uint32_t vtcm_size;
|
|
51
|
+
|
|
52
|
+
uint32_t qrows;
|
|
53
|
+
uint32_t qrows_per_thread;
|
|
54
|
+
float m0;
|
|
55
|
+
float m1;
|
|
56
|
+
uint32_t n_head_log2;
|
|
57
|
+
|
|
58
|
+
struct fastdiv_values src3_div2;
|
|
59
|
+
struct fastdiv_values src3_div3;
|
|
60
|
+
|
|
61
|
+
struct fastdiv_values broadcast_rk2;
|
|
62
|
+
struct fastdiv_values broadcast_rk3;
|
|
63
|
+
struct fastdiv_values broadcast_rv2;
|
|
64
|
+
struct fastdiv_values broadcast_rv3;
|
|
65
|
+
|
|
66
|
+
union {
|
|
67
|
+
struct {
|
|
68
|
+
uint32_t g_br;
|
|
69
|
+
uint32_t row_buf_stride;
|
|
70
|
+
uint32_t mask_buf_row_stride;
|
|
71
|
+
int32_t mask_broadcast;
|
|
72
|
+
int32_t pipeline;
|
|
73
|
+
struct fastdiv_values div_G;
|
|
74
|
+
} hmx;
|
|
75
|
+
struct {
|
|
76
|
+
uint32_t size_q_row_padded;
|
|
77
|
+
uint32_t size_k_row_padded;
|
|
78
|
+
uint32_t size_v_row_padded;
|
|
79
|
+
struct fastdiv_values src0_div21;
|
|
80
|
+
struct fastdiv_values src0_div1;
|
|
81
|
+
} hvx;
|
|
82
|
+
} u;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
#if defined(__cplusplus)
|
|
86
|
+
static_assert(sizeof(struct htp_fa_kernel_params) <= 128, "htp_fa_kernel_params is too large for kernel_params blob");
|
|
87
|
+
#endif
|
|
88
|
+
|
|
89
|
+
// VTCM region layout for the HMX flash-attention kernel.
|
|
90
|
+
//
|
|
91
|
+
// Single source of truth for both the host (which needs the total size to pick a
|
|
92
|
+
// (Br, Bc) tiling that fits the VTCM budget) and the device (which needs the actual
|
|
93
|
+
// byte offsets to place each scratch buffer). Building the layout once and reading
|
|
94
|
+
// offsets/total from it makes host estimate and device allocation impossible to
|
|
95
|
+
// desync -- previously they were duplicated formulas in two files and drifted.
|
|
96
|
+
//
|
|
97
|
+
// All fields are byte offsets / byte sizes -- no HVX_Vector type is named here so the
|
|
98
|
+
// header stays host-includable. The device casts (base + off_*) to the proper type.
|
|
99
|
+
// An offset of 0 marks a region that is not allocated for this configuration (only
|
|
100
|
+
// off_v_tiles[1], which exists only when pipelining); the device sets such pointers NULL.
|
|
101
|
+
struct hmx_fa_vtcm_layout {
|
|
102
|
+
// Byte offsets from vtcm_base for each region.
|
|
103
|
+
size_t off_q_tiles;
|
|
104
|
+
size_t off_o_tiles[2];
|
|
105
|
+
size_t off_k_fp16[2];
|
|
106
|
+
size_t off_v_fp16[2];
|
|
107
|
+
size_t off_k_tiles;
|
|
108
|
+
size_t off_v_tiles[2]; // [1] allocated only when pipeline, else 0
|
|
109
|
+
size_t off_s_tiles;
|
|
110
|
+
size_t off_p_tiles;
|
|
111
|
+
size_t off_d_tiles;
|
|
112
|
+
size_t off_m_vec;
|
|
113
|
+
size_t off_l_vec;
|
|
114
|
+
size_t off_s_rowmax;
|
|
115
|
+
size_t off_p_rowsum;
|
|
116
|
+
size_t off_row_bufs;
|
|
117
|
+
size_t off_hmx_scales_id;
|
|
118
|
+
size_t off_hmx_scales_qk;
|
|
119
|
+
size_t off_mask_buf;
|
|
120
|
+
size_t off_slopes;
|
|
121
|
+
|
|
122
|
+
// Region byte sizes reused by the device at runtime (not just for allocation).
|
|
123
|
+
size_t q_tile_bytes;
|
|
124
|
+
size_t o_tile_bytes;
|
|
125
|
+
size_t s_tile_bytes; // S and P tiles (same size)
|
|
126
|
+
size_t d_tile_bytes;
|
|
127
|
+
size_t m_line_bytes; // one mask row
|
|
128
|
+
size_t m_buf_slot_bytes; // one dma_cache slot = align_up(Br * m_line_bytes, 4096)
|
|
129
|
+
size_t col_vec_bytes;
|
|
130
|
+
|
|
131
|
+
// Derived strides.
|
|
132
|
+
size_t row_buf_stride; // HVX vectors (128B) per row buffer
|
|
133
|
+
size_t mask_buf_row_stride; // __fp16 elements per row in the mask buffer
|
|
134
|
+
|
|
135
|
+
bool pipeline;
|
|
136
|
+
size_t total_bytes;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Build the VTCM layout.
|
|
140
|
+
|
|
141
|
+
static inline void hmx_fa_vtcm_layout_build(struct hmx_fa_vtcm_layout * L,
|
|
142
|
+
size_t gqa_factor, size_t DK, size_t DV,
|
|
143
|
+
size_t Br, size_t Bc, size_t n_threads, bool pipeline) {
|
|
144
|
+
const size_t g_br = hex_align_up(gqa_factor * Br, HMX_FP16_TILE_N_ROWS);
|
|
145
|
+
const size_t q_tile_size = hex_align_up(g_br * DK * sizeof(__fp16), HTP_FA_HMX_TILE_SIZE);
|
|
146
|
+
const size_t o_tile_size = hex_align_up(g_br * DV * sizeof(__fp16), HTP_FA_HMX_TILE_SIZE);
|
|
147
|
+
const size_t k_tile_size = hex_align_up(Bc * DK * sizeof(__fp16), HTP_FA_HMX_TILE_SIZE);
|
|
148
|
+
const size_t v_tile_size = hex_align_up(Bc * DV * sizeof(__fp16), HTP_FA_HMX_TILE_SIZE);
|
|
149
|
+
const size_t s_tile_size = hex_align_up(g_br * Bc * sizeof(__fp16), HTP_FA_HMX_TILE_SIZE);
|
|
150
|
+
const size_t d_tile_size = hex_align_up(g_br * g_br * sizeof(__fp16), HTP_FA_HMX_TILE_SIZE);
|
|
151
|
+
|
|
152
|
+
const size_t k_dma_size = hex_align_up(Bc * hex_round_up(DK * sizeof(__fp16), 128), 128);
|
|
153
|
+
const size_t v_dma_size = hex_align_up(Bc * hex_round_up(DV * sizeof(__fp16), 128), 128);
|
|
154
|
+
const size_t col_vec_size = hex_align_up(g_br * sizeof(float), 256);
|
|
155
|
+
const size_t row_vec_size = hex_align_up(Bc * sizeof(__fp16), 256);
|
|
156
|
+
const size_t m_line_size = hex_align_up(Bc * sizeof(__fp16), 128);
|
|
157
|
+
const size_t m_buf_slot = hex_align_up(Br * m_line_size, 256);
|
|
158
|
+
const size_t m_buf_size = m_buf_slot * HMX_FA_DMA_CACHE_SIZE;
|
|
159
|
+
const size_t slopes_size = hex_align_up(g_br * sizeof(__fp16), 128);
|
|
160
|
+
|
|
161
|
+
size_t off = 0;
|
|
162
|
+
|
|
163
|
+
// Section 1: HMX Tiled Buffers (FA_HMX_TILE_SIZE = 2KB Aligned)
|
|
164
|
+
VTCM_LAYOUT_ALLOC(off, off_q_tiles, q_tile_size);
|
|
165
|
+
VTCM_LAYOUT_ALLOC(off, off_o_tiles[0], o_tile_size);
|
|
166
|
+
VTCM_LAYOUT_ALLOC(off, off_o_tiles[1], o_tile_size);
|
|
167
|
+
VTCM_LAYOUT_ALLOC(off, off_k_tiles, k_tile_size);
|
|
168
|
+
VTCM_LAYOUT_ALLOC(off, off_v_tiles[0], v_tile_size);
|
|
169
|
+
VTCM_LAYOUT_ALLOC_OPTIONAL(off, off_v_tiles[1], v_tile_size, pipeline);
|
|
170
|
+
VTCM_LAYOUT_ALLOC(off, off_s_tiles, s_tile_size);
|
|
171
|
+
VTCM_LAYOUT_ALLOC(off, off_p_tiles, s_tile_size);
|
|
172
|
+
VTCM_LAYOUT_ALLOC(off, off_d_tiles, d_tile_size);
|
|
173
|
+
|
|
174
|
+
// Section 2: HVX/DMA flat and vector buffers (128B / 256B Aligned)
|
|
175
|
+
VTCM_LAYOUT_ALLOC(off, off_k_fp16[0], k_dma_size);
|
|
176
|
+
VTCM_LAYOUT_ALLOC(off, off_k_fp16[1], k_dma_size);
|
|
177
|
+
VTCM_LAYOUT_ALLOC(off, off_v_fp16[0], v_dma_size);
|
|
178
|
+
VTCM_LAYOUT_ALLOC(off, off_v_fp16[1], v_dma_size);
|
|
179
|
+
VTCM_LAYOUT_ALLOC(off, off_m_vec, col_vec_size);
|
|
180
|
+
VTCM_LAYOUT_ALLOC(off, off_l_vec, col_vec_size);
|
|
181
|
+
VTCM_LAYOUT_ALLOC(off, off_s_rowmax, col_vec_size);
|
|
182
|
+
VTCM_LAYOUT_ALLOC(off, off_p_rowsum, col_vec_size);
|
|
183
|
+
VTCM_LAYOUT_ALLOC(off, off_row_bufs, row_vec_size * 2 * n_threads);
|
|
184
|
+
VTCM_LAYOUT_ALLOC(off, off_hmx_scales_id, 256);
|
|
185
|
+
VTCM_LAYOUT_ALLOC(off, off_hmx_scales_qk, 256);
|
|
186
|
+
VTCM_LAYOUT_ALLOC(off, off_mask_buf, m_buf_size);
|
|
187
|
+
VTCM_LAYOUT_ALLOC(off, off_slopes, slopes_size);
|
|
188
|
+
|
|
189
|
+
L->q_tile_bytes = q_tile_size;
|
|
190
|
+
L->o_tile_bytes = o_tile_size;
|
|
191
|
+
L->col_vec_bytes = col_vec_size;
|
|
192
|
+
L->s_tile_bytes = s_tile_size;
|
|
193
|
+
L->d_tile_bytes = d_tile_size;
|
|
194
|
+
L->m_line_bytes = m_line_size;
|
|
195
|
+
L->m_buf_slot_bytes = m_buf_slot;
|
|
196
|
+
L->row_buf_stride = row_vec_size / 128;
|
|
197
|
+
L->mask_buf_row_stride = m_line_size / sizeof(__fp16);
|
|
198
|
+
L->pipeline = pipeline;
|
|
199
|
+
L->total_bytes = off;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Exact VTCM usage for a given (gqa_factor, DK, DV, Br, Bc) configuration.
|
|
203
|
+
static inline size_t hmx_fa_compute_vtcm_usage(size_t gqa_factor, size_t DK, size_t DV, size_t Br, size_t Bc, size_t n_threads, bool pipeline) {
|
|
204
|
+
struct hmx_fa_vtcm_layout L;
|
|
205
|
+
hmx_fa_vtcm_layout_build(&L, gqa_factor, DK, DV, Br, Bc, n_threads, pipeline);
|
|
206
|
+
return L.total_bytes;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
#define FA_HVX_BLOCK_SIZE 64
|
|
210
|
+
|
|
211
|
+
static inline size_t hvx_fa_compute_vtcm_usage(size_t DK, size_t DV, bool is_q_fp32, bool has_mask, size_t n_threads) {
|
|
212
|
+
const size_t size_q_row_padded = hex_round_up(DK * (is_q_fp32 ? 4 : 2), 128);
|
|
213
|
+
const size_t size_k_row_padded = hex_round_up(DK * sizeof(__fp16), 128);
|
|
214
|
+
const size_t size_v_row_padded = hex_round_up(DV * sizeof(__fp16), 128);
|
|
215
|
+
|
|
216
|
+
const size_t size_q_block = size_q_row_padded * 1;
|
|
217
|
+
const size_t size_k_block = size_k_row_padded * FA_HVX_BLOCK_SIZE;
|
|
218
|
+
const size_t size_v_block = size_v_row_padded * FA_HVX_BLOCK_SIZE;
|
|
219
|
+
const size_t size_m_block = hex_round_up(FA_HVX_BLOCK_SIZE * sizeof(__fp16), 128);
|
|
220
|
+
const size_t size_vkq_acc = hex_round_up(DV * sizeof(float), 128);
|
|
221
|
+
|
|
222
|
+
const size_t size_per_thread = size_q_block * 1
|
|
223
|
+
+ size_k_block * 2
|
|
224
|
+
+ size_v_block * 2
|
|
225
|
+
+ (has_mask ? size_m_block * HVX_FA_DMA_CACHE_SIZE : 0)
|
|
226
|
+
+ size_vkq_acc;
|
|
227
|
+
|
|
228
|
+
return size_per_thread * n_threads;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
#define FA_MIN_KV_BLOCKS 3
|
|
232
|
+
|
|
233
|
+
// Cost-based (Br, Bc) search for flash attention with pipeline constraint.
|
|
234
|
+
static inline int hmx_fa_find_chunk_size(size_t * Br_out,
|
|
235
|
+
size_t * Bc_out,
|
|
236
|
+
size_t gqa_factor,
|
|
237
|
+
size_t DK,
|
|
238
|
+
size_t DV,
|
|
239
|
+
size_t qo_len,
|
|
240
|
+
size_t kv_len,
|
|
241
|
+
size_t vtcm_budget,
|
|
242
|
+
size_t n_threads) {
|
|
243
|
+
const size_t T = HMX_FP16_TILE_N_ROWS; // 32
|
|
244
|
+
const size_t br_unit = hmx_ceil_div(T, gqa_factor);
|
|
245
|
+
const size_t bc_unit = HMX_FP16_TILE_N_COLS * 2; // 64
|
|
246
|
+
const bool can_pipeline = (kv_len >= FA_MIN_KV_BLOCKS * bc_unit && n_threads >= 2);
|
|
247
|
+
|
|
248
|
+
// Br_max: largest Br aligned to br_unit that does not exceed qo_len.
|
|
249
|
+
const size_t Br_max = qo_len >= br_unit ? hex_align_down(qo_len, br_unit) : br_unit;
|
|
250
|
+
|
|
251
|
+
// Pipeline constraint: cap Bc so n_kv_blocks >= FA_MIN_KV_BLOCKS.
|
|
252
|
+
// Only relax when kv_len is too short to form enough blocks.
|
|
253
|
+
const size_t Bc_limit = can_pipeline ? hex_align_down(kv_len / FA_MIN_KV_BLOCKS, bc_unit) :
|
|
254
|
+
(kv_len >= bc_unit ? hex_align_down(kv_len, bc_unit) : bc_unit);
|
|
255
|
+
// Cost coefficients calibrated from profiling
|
|
256
|
+
const size_t c_q_fixed = 1400; // per-Q-block: q_load + epilogue o_update + o_norm + o_store
|
|
257
|
+
const size_t c_iter_fixed = 200; // per-KV-iter: HMX queue push/pop + DMA pop + barriers
|
|
258
|
+
|
|
259
|
+
size_t best_cost = SIZE_MAX, best_mn = 0;
|
|
260
|
+
size_t best_Br = 0, best_Bc = 0;
|
|
261
|
+
|
|
262
|
+
for (size_t Br = Br_max; Br >= br_unit; Br -= br_unit) {
|
|
263
|
+
// Try all Bc candidates from Bc_limit down to bc_unit
|
|
264
|
+
for (size_t Bc = Bc_limit; Bc >= bc_unit; Bc -= bc_unit) {
|
|
265
|
+
size_t vtcm_needed = hmx_fa_compute_vtcm_usage(gqa_factor, DK, DV, Br, Bc, n_threads, can_pipeline);
|
|
266
|
+
if (vtcm_needed <= vtcm_budget) {
|
|
267
|
+
// This Bc fits for this Br!
|
|
268
|
+
const size_t q_blocks = (qo_len + Br - 1) / Br;
|
|
269
|
+
const size_t kv_blocks = (kv_len + Bc - 1) / Bc;
|
|
270
|
+
const size_t cost = q_blocks * (c_q_fixed + kv_blocks * c_iter_fixed);
|
|
271
|
+
const size_t mn = Br * Bc;
|
|
272
|
+
|
|
273
|
+
if (cost < best_cost || (cost == best_cost && mn > best_mn)) {
|
|
274
|
+
best_cost = cost;
|
|
275
|
+
best_mn = mn;
|
|
276
|
+
best_Br = Br;
|
|
277
|
+
best_Bc = Bc;
|
|
278
|
+
}
|
|
279
|
+
// Since we iterate Bc from largest to smallest, this is the largest Bc that fits
|
|
280
|
+
// for this Br. We can break to the next Br.
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (Br == br_unit) {
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (best_Br == 0 || best_Bc == 0) {
|
|
291
|
+
return -1;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
*Br_out = best_Br;
|
|
295
|
+
*Bc_out = best_Bc;
|
|
296
|
+
return 0;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
#ifdef __cplusplus
|
|
300
|
+
}
|
|
301
|
+
#endif
|
|
302
|
+
|
|
303
|
+
#endif /* HTP_FLASH_ATTN_OPS_H */
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#ifndef HEX_COMMON_H
|
|
2
|
+
#define HEX_COMMON_H
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
#include <stdbool.h>
|
|
7
|
+
|
|
8
|
+
#ifndef SIZE_MAX
|
|
9
|
+
#define SIZE_MAX ((size_t)-1)
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#ifndef MAX
|
|
13
|
+
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#ifndef MIN
|
|
17
|
+
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
static inline uint32_t hex_ceil_pow2(uint32_t x) {
|
|
21
|
+
if (x <= 1) { return 1; }
|
|
22
|
+
int p = 2;
|
|
23
|
+
x--;
|
|
24
|
+
while (x >>= 1) { p <<= 1; }
|
|
25
|
+
return p;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static inline size_t hmx_ceil_div(size_t num, size_t den) {
|
|
29
|
+
return (num + den - 1) / den;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static inline int32_t hex_is_aligned(const void * addr, uint32_t align) {
|
|
33
|
+
return ((size_t) addr & (align - 1)) == 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static inline size_t hex_align_up(size_t v, size_t align) {
|
|
37
|
+
return hmx_ceil_div(v, align) * align;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static inline size_t hex_align_down(size_t v, size_t align) {
|
|
41
|
+
return (v / align) * align;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static inline int32_t hex_is_one_chunk(void * addr, uint32_t n, uint32_t chunk_size) {
|
|
45
|
+
uint32_t left_off = (size_t) addr & (chunk_size - 1);
|
|
46
|
+
uint32_t right_off = left_off + n;
|
|
47
|
+
return right_off <= chunk_size;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static inline uint32_t hex_round_up(uint32_t n, uint32_t m) {
|
|
51
|
+
return m * ((n + m - 1) / m);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static inline size_t hex_smin(size_t a, size_t b) {
|
|
55
|
+
return a < b ? a : b;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static inline size_t hex_smax(size_t a, size_t b) {
|
|
59
|
+
return a > b ? a : b;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static inline void hex_swap_ptr(void ** p1, void ** p2) {
|
|
63
|
+
void * t = *p1;
|
|
64
|
+
*p1 = *p2;
|
|
65
|
+
*p2 = t;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static inline bool hex_mul_overflow(size_t a, size_t b, size_t *out) {
|
|
69
|
+
if (a != 0 && b > SIZE_MAX / a) return true;
|
|
70
|
+
*out = a * b;
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static inline bool hex_add_overflow(size_t a, size_t b, size_t *out) {
|
|
75
|
+
if (a > SIZE_MAX - b) return true;
|
|
76
|
+
*out = a + b;
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#endif // HEX_COMMON_H
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
#include <hexagon_types.h>
|
|
6
6
|
#include <stdbool.h>
|
|
7
7
|
#include <stdint.h>
|
|
8
|
+
#include "hex-utils.h"
|
|
9
|
+
|
|
10
|
+
#include "hex-profile.h"
|
|
8
11
|
|
|
9
12
|
#ifdef __cplusplus
|
|
10
13
|
extern "C" {
|
|
@@ -88,6 +91,7 @@ typedef struct {
|
|
|
88
91
|
uint32_t pop_idx;
|
|
89
92
|
uint32_t capacity;
|
|
90
93
|
uint32_t idx_mask;
|
|
94
|
+
struct htp_thread_trace * trace;
|
|
91
95
|
} dma_queue;
|
|
92
96
|
|
|
93
97
|
dma_queue * dma_queue_create(size_t capacity);
|
|
@@ -124,13 +128,8 @@ static inline dma_ptr dma_make_ptr(void *dst, const void *src)
|
|
|
124
128
|
return p;
|
|
125
129
|
}
|
|
126
130
|
|
|
127
|
-
#if __HVX_ARCH__ < 73
|
|
128
|
-
static const uint32_t dma_src_l2_bypass_on = 1;
|
|
129
|
-
static const uint32_t dma_dst_l2_bypass_on = 0;
|
|
130
|
-
#else
|
|
131
131
|
static const uint32_t dma_src_l2_bypass_on = 1;
|
|
132
132
|
static const uint32_t dma_dst_l2_bypass_on = 1;
|
|
133
|
-
#endif
|
|
134
133
|
|
|
135
134
|
static inline bool dma_queue_push_single_1d(dma_queue * q, dma_ptr dptr, size_t size) {
|
|
136
135
|
if (((q->push_idx + 1) & q->idx_mask) == q->pop_idx) {
|
|
@@ -139,26 +138,28 @@ static inline bool dma_queue_push_single_1d(dma_queue * q, dma_ptr dptr, size_t
|
|
|
139
138
|
}
|
|
140
139
|
|
|
141
140
|
dma_descriptor_1d * desc = (dma_descriptor_1d *) &q->desc[q->push_idx];
|
|
142
|
-
desc->
|
|
143
|
-
desc->
|
|
144
|
-
desc->
|
|
145
|
-
desc->dst_bypass = dma_dst_l2_bypass_on;
|
|
146
|
-
desc->order = 0;
|
|
147
|
-
desc->done = 0;
|
|
148
|
-
desc->src = (void *) dptr.src;
|
|
149
|
-
desc->dst = (void *) dptr.dst;
|
|
150
|
-
desc->size = size;
|
|
141
|
+
desc->src = (void *) dptr.src;
|
|
142
|
+
desc->dst = (void *) dptr.dst;
|
|
143
|
+
desc->size = size;
|
|
151
144
|
|
|
152
145
|
q->dptr[q->push_idx] = dptr;
|
|
153
146
|
|
|
154
147
|
if (size) {
|
|
148
|
+
desc->next = NULL;
|
|
149
|
+
desc->desc_size = 0; // 1D mode
|
|
150
|
+
desc->src_bypass = dma_src_l2_bypass_on;
|
|
151
|
+
desc->dst_bypass = dma_dst_l2_bypass_on;
|
|
152
|
+
desc->order = 0;
|
|
153
|
+
desc->done = 0;
|
|
154
|
+
|
|
155
|
+
htp_trace_event_start(q->trace, HTP_TRACE_EVT_DMA, q->push_idx);
|
|
155
156
|
dmlink(q->tail, desc);
|
|
156
157
|
q->tail = (dma_descriptor_2d *) desc;
|
|
157
158
|
} else {
|
|
158
|
-
desc->
|
|
159
|
+
desc->desc_size = 0;
|
|
160
|
+
desc->done = 1;
|
|
159
161
|
}
|
|
160
162
|
|
|
161
|
-
// FARF(ERROR, "dma-push: i %u row-size %u nrows %d dst %p src %p\n", q->push_idx, row_size, nrows, dptr.dst, dptr.src);
|
|
162
163
|
q->push_idx = (q->push_idx + 1) & q->idx_mask;
|
|
163
164
|
return true;
|
|
164
165
|
}
|
|
@@ -202,6 +203,7 @@ static inline bool dma_queue_push_single_2d(dma_queue * q, dma_ptr dptr, size_t
|
|
|
202
203
|
q->dptr[q->push_idx] = dptr;
|
|
203
204
|
|
|
204
205
|
if (nrows) {
|
|
206
|
+
htp_trace_event_start(q->trace, HTP_TRACE_EVT_DMA, q->push_idx);
|
|
205
207
|
dmlink(q->tail, desc);
|
|
206
208
|
q->tail = desc;
|
|
207
209
|
} else {
|
|
@@ -223,10 +225,12 @@ static inline dma_ptr dma_queue_pop(dma_queue * q) {
|
|
|
223
225
|
dma_descriptor_2d * desc = &q->desc[q->pop_idx];
|
|
224
226
|
|
|
225
227
|
// Wait for desc to complete
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
228
|
+
if (!desc->done) {
|
|
229
|
+
while (!desc->done) {
|
|
230
|
+
dmpoll();
|
|
231
|
+
}
|
|
229
232
|
}
|
|
233
|
+
htp_trace_event_stop(q->trace, HTP_TRACE_EVT_DMA, q->pop_idx);
|
|
230
234
|
|
|
231
235
|
dptr = q->dptr[q->pop_idx];
|
|
232
236
|
|
|
@@ -317,7 +321,7 @@ static inline bool dma_queue_push_vtcm_to_ddr(dma_queue * q, dma_ptr dptr, size_
|
|
|
317
321
|
return dma_queue_push(q, dptr, dst_row_size, src_row_size, dst_row_size, nrows);
|
|
318
322
|
}
|
|
319
323
|
|
|
320
|
-
#define DMA_CACHE_MAX_SIZE
|
|
324
|
+
#define DMA_CACHE_MAX_SIZE 256U
|
|
321
325
|
|
|
322
326
|
typedef struct {
|
|
323
327
|
uint8_t *base;
|
|
@@ -349,20 +353,19 @@ static inline bool dma_cache_push(dma_queue *q, dma_cache *c, const uint8_t * sr
|
|
|
349
353
|
if (c->src[i] == (uint32_t) src) {
|
|
350
354
|
c->age[i] = 0;
|
|
351
355
|
dst = c->base + (i * c->line_size); nrows = 0; // dummy dma
|
|
352
|
-
// FARF(ERROR, "dma-cache: found %p", src);
|
|
353
356
|
} else {
|
|
354
357
|
c->age[i]++;
|
|
355
358
|
if (c->age[i] > o_age) { o_age = c->age[i]; o_idx = i; }
|
|
356
359
|
}
|
|
357
360
|
}
|
|
358
361
|
if (!dst) {
|
|
359
|
-
// FARF(ERROR, "dma-cache: replacing #%u : age %u %p -> %p", o_idx, c->age[o_idx], (void *) c->src[o_idx], src);
|
|
360
362
|
c->age[o_idx] = 0;
|
|
361
363
|
c->src[o_idx] = (uint32_t) src;
|
|
362
364
|
dst = c->base + o_idx * c->line_size; // normal nrows dma
|
|
365
|
+
return dma_queue_push(q, dma_make_ptr(dst, src), dst_stride, src_stride, row_size, nrows);
|
|
363
366
|
}
|
|
364
367
|
|
|
365
|
-
return
|
|
368
|
+
return dma_queue_push_single_1d(q, dma_make_ptr(dst, src), 0);
|
|
366
369
|
}
|
|
367
370
|
|
|
368
371
|
#ifdef __cplusplus
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#ifndef HEX_PROFILE_H
|
|
2
|
+
#define HEX_PROFILE_H
|
|
3
|
+
|
|
4
|
+
#include <stdbool.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
#include <qurt.h>
|
|
7
|
+
|
|
8
|
+
#include "hex-utils.h"
|
|
9
|
+
#include "htp-ops.h"
|
|
10
|
+
|
|
11
|
+
#define HTP_TRACE_EVT_START 0
|
|
12
|
+
#define HTP_TRACE_EVT_STOP 1
|
|
13
|
+
|
|
14
|
+
#ifndef HEX_NUM_PMU_COUNTERS
|
|
15
|
+
#define HEX_NUM_PMU_COUNTERS 8
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
static inline void hex_get_pmu(uint32_t counters[]) {
|
|
19
|
+
#if __HVX_ARCH__ >= 79
|
|
20
|
+
asm volatile("%0 = upmucnt0" : "=r"(counters[0]));
|
|
21
|
+
asm volatile("%0 = upmucnt1" : "=r"(counters[1]));
|
|
22
|
+
asm volatile("%0 = upmucnt2" : "=r"(counters[2]));
|
|
23
|
+
asm volatile("%0 = upmucnt3" : "=r"(counters[3]));
|
|
24
|
+
asm volatile("%0 = upmucnt4" : "=r"(counters[4]));
|
|
25
|
+
asm volatile("%0 = upmucnt5" : "=r"(counters[5]));
|
|
26
|
+
asm volatile("%0 = upmucnt6" : "=r"(counters[6]));
|
|
27
|
+
asm volatile("%0 = upmucnt7" : "=r"(counters[7]));
|
|
28
|
+
#else
|
|
29
|
+
counters[0] = qurt_pmu_get(QURT_PMUCNT0);
|
|
30
|
+
counters[1] = qurt_pmu_get(QURT_PMUCNT1);
|
|
31
|
+
counters[2] = qurt_pmu_get(QURT_PMUCNT2);
|
|
32
|
+
counters[3] = qurt_pmu_get(QURT_PMUCNT3);
|
|
33
|
+
counters[4] = qurt_pmu_get(QURT_PMUCNT4);
|
|
34
|
+
counters[5] = qurt_pmu_get(QURT_PMUCNT5);
|
|
35
|
+
counters[6] = qurt_pmu_get(QURT_PMUCNT6);
|
|
36
|
+
counters[7] = qurt_pmu_get(QURT_PMUCNT7);
|
|
37
|
+
#endif
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
struct htp_thread_trace {
|
|
41
|
+
uint32_t count;
|
|
42
|
+
uint32_t max_events;
|
|
43
|
+
struct htp_trace_desc * events;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
static inline void htp_trace_event(struct htp_thread_trace * tr, uint16_t id, uint16_t info, uint32_t type) {
|
|
47
|
+
if (tr && tr->events && tr->count < tr->max_events) {
|
|
48
|
+
uint32_t idx = tr->count;
|
|
49
|
+
tr->events[idx].id = id;
|
|
50
|
+
tr->events[idx].info = info | (type == HTP_TRACE_EVT_STOP ? 0x8000 : 0);
|
|
51
|
+
tr->events[idx].cycles = (uint32_t) hex_get_cycles();
|
|
52
|
+
tr->count++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static inline void htp_trace_event_start(struct htp_thread_trace * tr, uint16_t id, uint16_t info) {
|
|
57
|
+
htp_trace_event(tr, id, info, HTP_TRACE_EVT_START);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static inline void htp_trace_event_stop(struct htp_thread_trace * tr, uint16_t id, uint16_t info) {
|
|
61
|
+
htp_trace_event(tr, id, info, HTP_TRACE_EVT_STOP);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#endif /* HEX_PROFILE_H */
|
|
@@ -11,14 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
#include "hex-fastdiv.h"
|
|
13
13
|
#include "hex-dump.h"
|
|
14
|
-
|
|
15
|
-
#ifndef MAX
|
|
16
|
-
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
17
|
-
#endif
|
|
18
|
-
|
|
19
|
-
#ifndef MIN
|
|
20
|
-
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
21
|
-
#endif
|
|
14
|
+
#include "hex-common.h"
|
|
22
15
|
|
|
23
16
|
static inline uint64_t hex_get_cycles() {
|
|
24
17
|
uint64_t cycles = 0;
|
|
@@ -32,54 +25,6 @@ static inline uint64_t hex_get_pktcnt() {
|
|
|
32
25
|
return pktcnt;
|
|
33
26
|
}
|
|
34
27
|
|
|
35
|
-
static inline uint32_t hex_ceil_pow2(uint32_t x) {
|
|
36
|
-
if (x <= 1) { return 1; }
|
|
37
|
-
int p = 2;
|
|
38
|
-
x--;
|
|
39
|
-
while (x >>= 1) { p <<= 1; }
|
|
40
|
-
return p;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static inline size_t hmx_ceil_div(size_t num, size_t den) {
|
|
44
|
-
return (num + den - 1) / den;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static inline int32_t hex_is_aligned(const void * addr, uint32_t align) {
|
|
48
|
-
return ((size_t) addr & (align - 1)) == 0;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static inline size_t hex_align_up(size_t v, size_t align) {
|
|
52
|
-
return hmx_ceil_div(v, align) * align;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static inline size_t hex_align_down(size_t v, size_t align) {
|
|
56
|
-
return (v / align) * align;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
static inline int32_t hex_is_one_chunk(void * addr, uint32_t n, uint32_t chunk_size) {
|
|
60
|
-
uint32_t left_off = (size_t) addr & (chunk_size - 1);
|
|
61
|
-
uint32_t right_off = left_off + n;
|
|
62
|
-
return right_off <= chunk_size;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static inline uint32_t hex_round_up(uint32_t n, uint32_t m) {
|
|
66
|
-
return m * ((n + m - 1) / m);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
static inline size_t hex_smin(size_t a, size_t b) {
|
|
70
|
-
return a < b ? a : b;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
static inline size_t hex_smax(size_t a, size_t b) {
|
|
74
|
-
return a > b ? a : b;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
static inline void hex_swap_ptr(void ** p1, void ** p2) {
|
|
78
|
-
void * t = *p1;
|
|
79
|
-
*p1 = *p2;
|
|
80
|
-
*p2 = t;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
28
|
static inline void hex_l2fetch(const void * p, uint32_t width, uint32_t stride, uint32_t height) {
|
|
84
29
|
const uint64_t control = Q6_P_combine_RR(stride, Q6_R_combine_RlRl(width, height));
|
|
85
30
|
Q6_l2fetch_AP((void *) p, control);
|
|
@@ -107,31 +52,4 @@ static inline void hex_pause() {
|
|
|
107
52
|
asm volatile(" pause(#255)\n");
|
|
108
53
|
}
|
|
109
54
|
|
|
110
|
-
#ifndef HEX_NUM_PMU_COUNTERS
|
|
111
|
-
#define HEX_NUM_PMU_COUNTERS 8
|
|
112
|
-
#endif
|
|
113
|
-
|
|
114
|
-
static inline void hex_get_pmu(uint32_t counters[]) {
|
|
115
|
-
#if __HVX_ARCH__ >= 79
|
|
116
|
-
asm volatile("%0 = upmucnt0" : "=r"(counters[0]));
|
|
117
|
-
asm volatile("%0 = upmucnt1" : "=r"(counters[1]));
|
|
118
|
-
asm volatile("%0 = upmucnt2" : "=r"(counters[2]));
|
|
119
|
-
asm volatile("%0 = upmucnt3" : "=r"(counters[3]));
|
|
120
|
-
asm volatile("%0 = upmucnt4" : "=r"(counters[4]));
|
|
121
|
-
asm volatile("%0 = upmucnt5" : "=r"(counters[5]));
|
|
122
|
-
asm volatile("%0 = upmucnt6" : "=r"(counters[6]));
|
|
123
|
-
asm volatile("%0 = upmucnt7" : "=r"(counters[7]));
|
|
124
|
-
#else
|
|
125
|
-
counters[0] = qurt_pmu_get(QURT_PMUCNT0);
|
|
126
|
-
counters[1] = qurt_pmu_get(QURT_PMUCNT1);
|
|
127
|
-
counters[2] = qurt_pmu_get(QURT_PMUCNT2);
|
|
128
|
-
counters[3] = qurt_pmu_get(QURT_PMUCNT3);
|
|
129
|
-
counters[4] = qurt_pmu_get(QURT_PMUCNT4);
|
|
130
|
-
counters[5] = qurt_pmu_get(QURT_PMUCNT5);
|
|
131
|
-
counters[6] = qurt_pmu_get(QURT_PMUCNT6);
|
|
132
|
-
counters[7] = qurt_pmu_get(QURT_PMUCNT7);
|
|
133
|
-
// qurt_pmu_get_pmucnt(counters);
|
|
134
|
-
#endif
|
|
135
|
-
}
|
|
136
|
-
|
|
137
55
|
#endif /* HEX_UTILS_H */
|