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,650 @@
|
|
|
1
|
+
#ifndef HTP_MATMUL_OPS_H
|
|
2
|
+
#define HTP_MATMUL_OPS_H
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
#include "htp-ops.h"
|
|
7
|
+
#include "hex-fastdiv.h"
|
|
8
|
+
#include "hex-common.h"
|
|
9
|
+
#include "htp-vtcm.h"
|
|
10
|
+
|
|
11
|
+
#ifdef __cplusplus
|
|
12
|
+
extern "C" {
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
// --- HMX Tile Constraints ---
|
|
16
|
+
#define HTP_MM_HMX_TILE_N_COLS 32
|
|
17
|
+
#define HTP_MM_HMX_TILE_N_ROWS 32
|
|
18
|
+
#define HTP_MM_HMX_TILE_SIZE (32 * 32 * sizeof(__fp16)) // 2048 bytes
|
|
19
|
+
#define HTP_MM_HMX_TILE_N_ELMS 1024
|
|
20
|
+
#define HTP_MM_HMX_MIN_NROWS 4
|
|
21
|
+
|
|
22
|
+
// --- Weight Repacked Tile Sizes ---
|
|
23
|
+
#define HTP_MM_WEIGHT_TILE_SIZE_Q4_0 576
|
|
24
|
+
#define HTP_MM_WEIGHT_TILE_SIZE_Q4_1 640
|
|
25
|
+
#define HTP_MM_WEIGHT_TILE_SIZE_Q8_0 1088
|
|
26
|
+
#define HTP_MM_WEIGHT_TILE_SIZE_IQ4_NL 576
|
|
27
|
+
#define HTP_MM_WEIGHT_TILE_SIZE_MXFP4 544
|
|
28
|
+
|
|
29
|
+
// --- Weight Repacked Aligned Tile Sizes ---
|
|
30
|
+
#define HTP_MM_WEIGHT_ALIGNED_TILE_SIZE_Q4_0 640
|
|
31
|
+
#define HTP_MM_WEIGHT_ALIGNED_TILE_SIZE_Q4_1 640
|
|
32
|
+
#define HTP_MM_WEIGHT_ALIGNED_TILE_SIZE_Q8_0 1152
|
|
33
|
+
#define HTP_MM_WEIGHT_ALIGNED_TILE_SIZE_IQ4_NL 640
|
|
34
|
+
#define HTP_MM_WEIGHT_ALIGNED_TILE_SIZE_MXFP4 640
|
|
35
|
+
|
|
36
|
+
// --- Activation Tiled Block Sizes (including padding) ---
|
|
37
|
+
#define HTP_MM_ACT_TILE_SIZE_Q8_0 1152
|
|
38
|
+
#define HTP_MM_ACT_TILE_SIZE_Q8_1 1280
|
|
39
|
+
|
|
40
|
+
#define HTP_MM_MAX_PREFETCH 16
|
|
41
|
+
|
|
42
|
+
// --- Solver Cost Model Penalty Weights (HMX-specific) ---
|
|
43
|
+
#define HTP_MM_HMX_COST_W_DEQUANT 3 // cost penalty for quantized weight loading/dequantization
|
|
44
|
+
#define HTP_MM_HMX_COST_A_CONVERT 2 // cost penalty for activation loading/conversion
|
|
45
|
+
|
|
46
|
+
// --- DMA Activation Transfer Configuration ---
|
|
47
|
+
#define HTP_MM_DMA_ACT_ROWS_PER_STEP 2
|
|
48
|
+
#define HTP_MM_DMA_ACT_MULTIPLIER (2 * HTP_MM_DMA_ACT_ROWS_PER_STEP)
|
|
49
|
+
|
|
50
|
+
enum htp_mm_kernel_type {
|
|
51
|
+
HTP_MM_KERNEL_UNSUPPORTED = 0,
|
|
52
|
+
|
|
53
|
+
// HMX paths
|
|
54
|
+
HTP_MM_KERNEL_HMX_2D,
|
|
55
|
+
HTP_MM_KERNEL_HMX_F16_BATCHED,
|
|
56
|
+
|
|
57
|
+
// HVX floating-point paths
|
|
58
|
+
HTP_MM_KERNEL_HVX_F16_F16_VTCM,
|
|
59
|
+
HTP_MM_KERNEL_HVX_F16_F16_DDR,
|
|
60
|
+
HTP_MM_KERNEL_HVX_F16_F32_DDR,
|
|
61
|
+
|
|
62
|
+
HTP_MM_KERNEL_HVX_F32_F32_VTCM,
|
|
63
|
+
HTP_MM_KERNEL_HVX_F32_F32_DDR,
|
|
64
|
+
HTP_MM_KERNEL_HVX_F32_F16_DDR,
|
|
65
|
+
|
|
66
|
+
// HVX quantized paths
|
|
67
|
+
HTP_MM_KERNEL_HVX_QUANT_ROW, // standard row-wise parallel quantization
|
|
68
|
+
HTP_MM_KERNEL_HVX_QUANT_BLOCK, // parallel block-wise quantization
|
|
69
|
+
HTP_MM_KERNEL_HVX_QUANT_ROW_FLAT, // row-wise fallback flat quantization
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Op-specific struct for precomputed matmul params
|
|
73
|
+
struct htp_mm_kernel_params {
|
|
74
|
+
int32_t kernel_type; // enum htp_mm_kernel_type
|
|
75
|
+
int32_t pipeline; // 1 = pipelined execution, 0 = standard
|
|
76
|
+
int32_t m_chunk; // Row chunk size (M chunk)
|
|
77
|
+
int32_t n_chunk; // Col chunk size (N chunk)
|
|
78
|
+
int32_t n_threads; // Number of threads to spawn
|
|
79
|
+
int32_t n_act_threads; // Number of threads for activation preparation
|
|
80
|
+
int32_t n_hmx; // 1 = use HMX, 0 = use HVX
|
|
81
|
+
int32_t n_prefetch; // Prefetch lookahead buffers/rows in VTCM
|
|
82
|
+
int32_t tile_size; // Weight tile size
|
|
83
|
+
int32_t aligned_tile_size; // Aligned weight tile size (padded to 128)
|
|
84
|
+
int32_t src1_row_size; // Row size for quantized activation
|
|
85
|
+
int32_t vtcm_size; // Total required scratchpad size in VTCM
|
|
86
|
+
int32_t vtcm_src0_size; // src0 scratchpad size in VTCM
|
|
87
|
+
int32_t vtcm_src1_size; // src1 scratchpad size in VTCM
|
|
88
|
+
int32_t vtcm_src2_size; // src2 scratchpad size in VTCM (fused only)
|
|
89
|
+
int32_t vtcm_src3_size; // src3 scratchpad size in VTCM (fused only)
|
|
90
|
+
int32_t vtcm_dst_size; // dst scratchpad size in VTCM
|
|
91
|
+
|
|
92
|
+
// Precomputed division values
|
|
93
|
+
struct fastdiv_values div_ne12_ne1;
|
|
94
|
+
struct fastdiv_values div_ne1;
|
|
95
|
+
struct fastdiv_values div_r2;
|
|
96
|
+
struct fastdiv_values div_r3;
|
|
97
|
+
struct fastdiv_values div_ne11;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
#if defined(__cplusplus)
|
|
101
|
+
static_assert(sizeof(struct htp_mm_kernel_params) <= 128, "htp_matmul_kernel_params is too large for kernel_params blob");
|
|
102
|
+
#else
|
|
103
|
+
_Static_assert(sizeof(struct htp_mm_kernel_params) <= 128, "htp_matmul_kernel_params is too large for kernel_params blob");
|
|
104
|
+
#endif
|
|
105
|
+
|
|
106
|
+
struct mmid_row_mapping {
|
|
107
|
+
uint32_t i1;
|
|
108
|
+
uint32_t i2;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Search for optimal (mc, nc) chunk sizes within VTCM budget.
|
|
112
|
+
static inline int htp_mm_hmx_compute_chunks(size_t vtcm_total,
|
|
113
|
+
size_t overhead,
|
|
114
|
+
size_t per_n_cost,
|
|
115
|
+
size_t per_m_cost,
|
|
116
|
+
size_t per_mn_cost,
|
|
117
|
+
size_t m,
|
|
118
|
+
size_t n,
|
|
119
|
+
size_t m_block_cost,
|
|
120
|
+
size_t n_block_cost,
|
|
121
|
+
size_t * m_chunk_out,
|
|
122
|
+
size_t * n_chunk_out,
|
|
123
|
+
size_t * total_out) {
|
|
124
|
+
if (m == 0 || n == 0) return -1;
|
|
125
|
+
if (vtcm_total <= overhead) return -1;
|
|
126
|
+
if (per_n_cost == 0 || per_m_cost == 0 || per_mn_cost == 0) return -1;
|
|
127
|
+
|
|
128
|
+
const size_t usable = vtcm_total - overhead;
|
|
129
|
+
|
|
130
|
+
size_t best_cost = SIZE_MAX;
|
|
131
|
+
size_t best_mn = 0;
|
|
132
|
+
size_t best_m = 0, best_n = 0;
|
|
133
|
+
|
|
134
|
+
const size_t n_max = hex_align_down((size_t)n, HTP_MM_HMX_TILE_N_COLS);
|
|
135
|
+
for (size_t nc = n_max; nc >= HTP_MM_HMX_TILE_N_COLS; nc -= HTP_MM_HMX_TILE_N_COLS) {
|
|
136
|
+
size_t n_fixed = 0, ncmn = 0, mc_denom = 0;
|
|
137
|
+
if (hex_mul_overflow(nc, per_n_cost, &n_fixed)) continue;
|
|
138
|
+
if (n_fixed >= usable) goto next_nc;
|
|
139
|
+
|
|
140
|
+
if (hex_mul_overflow(nc, per_mn_cost, &ncmn)) goto next_nc;
|
|
141
|
+
if (hex_add_overflow(per_m_cost, ncmn, &mc_denom) || mc_denom == 0) goto next_nc;
|
|
142
|
+
|
|
143
|
+
{
|
|
144
|
+
size_t remain = usable - n_fixed;
|
|
145
|
+
size_t mc = remain / mc_denom;
|
|
146
|
+
mc = hex_align_down(mc, HTP_MM_HMX_TILE_N_ROWS);
|
|
147
|
+
mc = hex_smin(mc, m);
|
|
148
|
+
|
|
149
|
+
if (mc == 0) {
|
|
150
|
+
goto next_nc;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
size_t mblocks = ((size_t) m + mc - 1) / mc;
|
|
154
|
+
size_t nblocks = ((size_t) n + nc - 1) / nc;
|
|
155
|
+
size_t cost = mblocks * m_block_cost + nblocks * n_block_cost;
|
|
156
|
+
size_t mn = mc * nc;
|
|
157
|
+
if (cost < best_cost || (cost == best_cost && mn > best_mn)) {
|
|
158
|
+
best_cost = cost;
|
|
159
|
+
best_mn = mn;
|
|
160
|
+
best_m = mc;
|
|
161
|
+
best_n = nc;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
next_nc:
|
|
166
|
+
if (nc == HTP_MM_HMX_TILE_N_COLS) break; // avoid size_t underflow
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (best_m == 0 || best_n == 0) return -1;
|
|
170
|
+
|
|
171
|
+
// Compute exact total (with overflow checks)
|
|
172
|
+
size_t t0 = 0, t1 = 0, t2 = 0, mn = 0, total = 0;
|
|
173
|
+
if (hex_mul_overflow(best_n, per_n_cost, &t0)) return -1;
|
|
174
|
+
if (hex_mul_overflow(best_m, per_m_cost, &t1)) return -1;
|
|
175
|
+
if (hex_mul_overflow(best_m, best_n, &mn)) return -1;
|
|
176
|
+
if (hex_mul_overflow(mn, per_mn_cost, &t2)) return -1;
|
|
177
|
+
if (hex_add_overflow(t0, t1, &total)) return -1;
|
|
178
|
+
if (hex_add_overflow(total, t2, &total)) return -1;
|
|
179
|
+
if (hex_add_overflow(total, overhead, &total)) return -1;
|
|
180
|
+
|
|
181
|
+
*m_chunk_out = best_m;
|
|
182
|
+
*n_chunk_out = best_n;
|
|
183
|
+
*total_out = total;
|
|
184
|
+
return 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// --- Tile Size Helpers ---
|
|
188
|
+
static inline uint32_t htp_mm_get_weight_tile_size(int weight_type) {
|
|
189
|
+
switch (weight_type) {
|
|
190
|
+
case HTP_TYPE_Q4_0:
|
|
191
|
+
case HTP_TYPE_IQ4_NL:
|
|
192
|
+
return HTP_MM_WEIGHT_TILE_SIZE_Q4_0;
|
|
193
|
+
case HTP_TYPE_Q4_1:
|
|
194
|
+
return HTP_MM_WEIGHT_TILE_SIZE_Q4_1;
|
|
195
|
+
case HTP_TYPE_Q8_0:
|
|
196
|
+
return HTP_MM_WEIGHT_TILE_SIZE_Q8_0;
|
|
197
|
+
case HTP_TYPE_MXFP4:
|
|
198
|
+
return HTP_MM_WEIGHT_TILE_SIZE_MXFP4;
|
|
199
|
+
default:
|
|
200
|
+
return 0;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
static inline uint32_t htp_mm_get_weight_aligned_tile_size(int weight_type) {
|
|
205
|
+
switch (weight_type) {
|
|
206
|
+
case HTP_TYPE_Q4_0:
|
|
207
|
+
case HTP_TYPE_IQ4_NL:
|
|
208
|
+
return HTP_MM_WEIGHT_ALIGNED_TILE_SIZE_Q4_0;
|
|
209
|
+
case HTP_TYPE_Q4_1:
|
|
210
|
+
return HTP_MM_WEIGHT_ALIGNED_TILE_SIZE_Q4_1;
|
|
211
|
+
case HTP_TYPE_Q8_0:
|
|
212
|
+
return HTP_MM_WEIGHT_ALIGNED_TILE_SIZE_Q8_0;
|
|
213
|
+
case HTP_TYPE_MXFP4:
|
|
214
|
+
return HTP_MM_WEIGHT_ALIGNED_TILE_SIZE_MXFP4;
|
|
215
|
+
default:
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// --- Activation/Row Size Helpers ---
|
|
221
|
+
static inline size_t htp_mm_q8_0_tiled_row_size(uint32_t ne) {
|
|
222
|
+
const uint32_t ne_padded = ((ne + 127) / 128) * 128;
|
|
223
|
+
const uint32_t nb_32 = ne_padded / 32;
|
|
224
|
+
return nb_32 * HTP_MM_ACT_TILE_SIZE_Q8_0;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
static inline size_t htp_mm_q8_1_tiled_row_size(uint32_t ne) {
|
|
228
|
+
const uint32_t ne_padded = ((ne + 127) / 128) * 128;
|
|
229
|
+
const uint32_t nb_32 = ne_padded / 32;
|
|
230
|
+
return nb_32 * HTP_MM_ACT_TILE_SIZE_Q8_1;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
static inline size_t htp_mm_q8_0_flat_row_size(uint32_t ne) {
|
|
234
|
+
const uint32_t quants_size = hex_align_up(ne, 128);
|
|
235
|
+
const uint32_t num_scales = (ne + 31) / 32;
|
|
236
|
+
const uint32_t scales_size = hex_align_up(num_scales * 2, 128);
|
|
237
|
+
return quants_size + scales_size;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
static inline size_t htp_mm_q8_1_flat_row_size(uint32_t ne) {
|
|
241
|
+
const uint32_t quants_size = hex_align_up(ne, 128);
|
|
242
|
+
const uint32_t num_scales = (ne + 31) / 32;
|
|
243
|
+
const uint32_t scales_size = hex_align_up(num_scales * 4, 128);
|
|
244
|
+
return quants_size + scales_size;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
static inline size_t htp_mm_get_tiled_row_stride(int weight_type, uint32_t k) {
|
|
248
|
+
uint32_t nb = (k + QK_Q4_0_TILED - 1) / QK_Q4_0_TILED;
|
|
249
|
+
switch (weight_type) {
|
|
250
|
+
case HTP_TYPE_Q4_0:
|
|
251
|
+
case HTP_TYPE_IQ4_NL:
|
|
252
|
+
case HTP_TYPE_Q4_1:
|
|
253
|
+
case HTP_TYPE_Q8_0:
|
|
254
|
+
case HTP_TYPE_MXFP4:
|
|
255
|
+
return (size_t) nb * htp_mm_get_weight_tile_size(weight_type);
|
|
256
|
+
case HTP_TYPE_F16:
|
|
257
|
+
return (size_t) k * sizeof(__fp16);
|
|
258
|
+
case HTP_TYPE_F32:
|
|
259
|
+
return (size_t) k * sizeof(float);
|
|
260
|
+
default:
|
|
261
|
+
return 0;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
static inline size_t htp_mm_round_up(size_t n, size_t m) {
|
|
266
|
+
return ((n + m - 1) / m) * m;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
static inline bool htp_mm_hmx_pipeline(uint32_t m) {
|
|
270
|
+
return m > 32;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
static inline void htp_mm_hmx_get_2d_chunk_costs(
|
|
274
|
+
int wtype, uint32_t k, bool pipeline, uint32_t aligned_tile_size,
|
|
275
|
+
size_t * size_per_n_out, size_t * size_per_m_out, size_t * size_per_mn_out
|
|
276
|
+
) {
|
|
277
|
+
const bool is_quant = (wtype != HTP_TYPE_F16 && wtype != HTP_TYPE_F32);
|
|
278
|
+
const size_t row_stride = htp_mm_get_tiled_row_stride(wtype, k);
|
|
279
|
+
const size_t vec_dot_size = k * sizeof(uint16_t);
|
|
280
|
+
const uint32_t n_k_tiles = k / HTP_MM_HMX_TILE_N_COLS;
|
|
281
|
+
const size_t qweight_row_stride = is_quant ? (size_t)(n_k_tiles * aligned_tile_size) / 32 : 0;
|
|
282
|
+
|
|
283
|
+
*size_per_n_out = (pipeline ? 2 : 1) * (is_quant ? qweight_row_stride : row_stride) +
|
|
284
|
+
(pipeline ? 2 * vec_dot_size : vec_dot_size);
|
|
285
|
+
*size_per_m_out = vec_dot_size;
|
|
286
|
+
*size_per_mn_out = (pipeline ? 2 : 1) * sizeof(uint16_t);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
static inline void htp_mm_hmx_get_batched_chunk_costs(
|
|
290
|
+
uint32_t k, uint32_t group_size,
|
|
291
|
+
size_t * size_per_n_out, size_t * size_per_m_out, size_t * size_per_mn_out
|
|
292
|
+
) {
|
|
293
|
+
const size_t vec_dot_size = k * sizeof(uint16_t);
|
|
294
|
+
*size_per_n_out = 3 * vec_dot_size;
|
|
295
|
+
*size_per_m_out = group_size * vec_dot_size;
|
|
296
|
+
*size_per_mn_out = sizeof(uint16_t);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
struct htp_mm_hmx_vtcm_layout {
|
|
300
|
+
// Byte offsets from vtcm_base for each region
|
|
301
|
+
size_t off_weight[2]; // [1] is only used when pipelined
|
|
302
|
+
size_t off_act;
|
|
303
|
+
size_t off_act_f32; // fp32 activation conversion scratch
|
|
304
|
+
size_t off_dst[2]; // [1] is only used when pipelined
|
|
305
|
+
size_t off_scratch[2]; // dequantization scratch pads
|
|
306
|
+
size_t off_scales; // HMX scales (256 bytes)
|
|
307
|
+
|
|
308
|
+
// Cached sizes of regions for HMX kernel use
|
|
309
|
+
size_t weight_area_bytes;
|
|
310
|
+
size_t act_area_bytes;
|
|
311
|
+
size_t act_f32_bytes;
|
|
312
|
+
size_t output_area_bytes;
|
|
313
|
+
size_t scratch_bytes[2];
|
|
314
|
+
size_t act_head_stride;
|
|
315
|
+
|
|
316
|
+
size_t total_bytes;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
struct htp_mm_hvx_vtcm_layout {
|
|
320
|
+
// Byte offsets from vtcm_base for each region
|
|
321
|
+
size_t off_src1; // vtcm_src1 (activation)
|
|
322
|
+
size_t off_src0; // vtcm_src0 (weight/Wk)
|
|
323
|
+
size_t off_src2; // vtcm_src2 (Wq / fused only)
|
|
324
|
+
size_t off_src3; // vtcm_src3 (Wv / fused only)
|
|
325
|
+
size_t off_dst; // vtcm_dst (output scratch)
|
|
326
|
+
|
|
327
|
+
// Cached sizes
|
|
328
|
+
size_t src0_bytes;
|
|
329
|
+
size_t src1_bytes;
|
|
330
|
+
size_t src2_bytes;
|
|
331
|
+
size_t src3_bytes;
|
|
332
|
+
size_t dst_bytes;
|
|
333
|
+
|
|
334
|
+
size_t total_bytes;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
static inline void htp_mm_hmx_vtcm_layout_build(
|
|
338
|
+
struct htp_mm_hmx_vtcm_layout * L,
|
|
339
|
+
int kernel_type,
|
|
340
|
+
int wtype,
|
|
341
|
+
uint32_t k,
|
|
342
|
+
size_t mc,
|
|
343
|
+
size_t nc,
|
|
344
|
+
uint32_t group_size,
|
|
345
|
+
bool use_dma_activation,
|
|
346
|
+
bool pipeline,
|
|
347
|
+
uint32_t act_threads,
|
|
348
|
+
uint32_t aligned_tile_size
|
|
349
|
+
) {
|
|
350
|
+
size_t off = 0;
|
|
351
|
+
|
|
352
|
+
if (kernel_type == HTP_MM_KERNEL_HMX_F16_BATCHED) {
|
|
353
|
+
const size_t vec_dot_size = k * sizeof(uint16_t);
|
|
354
|
+
const size_t act_head_stride = mc * k;
|
|
355
|
+
const size_t weight_area_size = hex_align_up(nc * vec_dot_size, HTP_MM_HMX_TILE_SIZE);
|
|
356
|
+
const size_t activation_area_size = hex_align_up(group_size * act_head_stride * sizeof(uint16_t), HTP_MM_HMX_TILE_SIZE);
|
|
357
|
+
const size_t output_area_size = hex_align_up(group_size * mc * nc * sizeof(uint16_t), HTP_MM_HMX_TILE_SIZE);
|
|
358
|
+
const size_t scratch_area_size = hex_align_up(nc * vec_dot_size, HTP_MM_HMX_TILE_SIZE);
|
|
359
|
+
const size_t min_f32_size = use_dma_activation
|
|
360
|
+
? hex_align_up(act_threads * HTP_MM_DMA_ACT_MULTIPLIER * k * sizeof(float), 128) : 0;
|
|
361
|
+
|
|
362
|
+
// Group A: Permanent activation tiles and scales
|
|
363
|
+
size_t off_group_a = 0;
|
|
364
|
+
VTCM_LAYOUT_ALLOC(off_group_a, off_act, activation_area_size);
|
|
365
|
+
VTCM_LAYOUT_ALLOC(off_group_a, off_scales, HTP_MM_HMX_TILE_SIZE); // Padded to 2K for alignment and future persistent data
|
|
366
|
+
|
|
367
|
+
// Group B: Compute-only buffers (starts at off_group_a)
|
|
368
|
+
size_t off_group_b = off_group_a;
|
|
369
|
+
VTCM_LAYOUT_ALLOC(off_group_b, off_weight[0], weight_area_size);
|
|
370
|
+
VTCM_LAYOUT_ALLOC_OPTIONAL(off_group_b, off_weight[1], weight_area_size, false);
|
|
371
|
+
VTCM_LAYOUT_ALLOC(off_group_b, off_dst[0], output_area_size);
|
|
372
|
+
VTCM_LAYOUT_ALLOC_OPTIONAL(off_group_b, off_dst[1], output_area_size, false);
|
|
373
|
+
VTCM_LAYOUT_ALLOC(off_group_b, off_scratch[0], scratch_area_size);
|
|
374
|
+
VTCM_LAYOUT_ALLOC(off_group_b, off_scratch[1], scratch_area_size);
|
|
375
|
+
|
|
376
|
+
const size_t group_b_size = off_group_b - off_group_a;
|
|
377
|
+
|
|
378
|
+
// Group C: Activation prep temporary buffer (overlaps Group B, starting at off_group_a)
|
|
379
|
+
const size_t max_f32_size = act_threads * 64 * k * sizeof(float);
|
|
380
|
+
const size_t act_f32_size = use_dma_activation
|
|
381
|
+
? hex_align_up(hex_smin(max_f32_size, hex_smax(min_f32_size, group_b_size)), 128) : 0;
|
|
382
|
+
size_t off_group_c = off_group_a;
|
|
383
|
+
VTCM_LAYOUT_ALLOC_OPTIONAL(off_group_c, off_act_f32, act_f32_size, use_dma_activation);
|
|
384
|
+
|
|
385
|
+
const size_t group_c_size = off_group_c - off_group_a;
|
|
386
|
+
|
|
387
|
+
L->weight_area_bytes = weight_area_size;
|
|
388
|
+
L->act_area_bytes = activation_area_size;
|
|
389
|
+
L->act_f32_bytes = act_f32_size;
|
|
390
|
+
L->output_area_bytes = output_area_size;
|
|
391
|
+
L->scratch_bytes[0] = scratch_area_size;
|
|
392
|
+
L->scratch_bytes[1] = scratch_area_size;
|
|
393
|
+
L->act_head_stride = act_head_stride;
|
|
394
|
+
|
|
395
|
+
off = off_group_a + hex_smax(group_b_size, group_c_size);
|
|
396
|
+
} else {
|
|
397
|
+
// HTP_MM_KERNEL_HMX_2D
|
|
398
|
+
const bool is_quant = (wtype != HTP_TYPE_F16 && wtype != HTP_TYPE_F32);
|
|
399
|
+
const size_t row_stride = htp_mm_get_tiled_row_stride(wtype, k);
|
|
400
|
+
const size_t vec_dot_size = k * sizeof(uint16_t);
|
|
401
|
+
const uint32_t n_k_tiles = k / HTP_MM_HMX_TILE_N_COLS;
|
|
402
|
+
|
|
403
|
+
const size_t min_f32_size = hex_align_up(act_threads * HTP_MM_DMA_ACT_MULTIPLIER * k * sizeof(float), 128);
|
|
404
|
+
const size_t weight_area_size = is_quant
|
|
405
|
+
? hex_align_up((nc / 32) * n_k_tiles * aligned_tile_size, HTP_MM_HMX_TILE_SIZE)
|
|
406
|
+
: hex_align_up(nc * row_stride, HTP_MM_HMX_TILE_SIZE);
|
|
407
|
+
const size_t act_area_size = hex_align_up(mc * vec_dot_size, HTP_MM_HMX_TILE_SIZE);
|
|
408
|
+
const size_t output_area_size = hex_align_up(mc * nc * sizeof(__fp16), HTP_MM_HMX_TILE_SIZE);
|
|
409
|
+
|
|
410
|
+
const size_t scratch0_size = hex_align_up(nc * vec_dot_size, HTP_MM_HMX_TILE_SIZE);
|
|
411
|
+
const size_t scratch1_size = pipeline ? scratch0_size : 0;
|
|
412
|
+
|
|
413
|
+
// Group A: Scales and activation tiles (must not overlap with Group B or C)
|
|
414
|
+
size_t off_group_a = 0;
|
|
415
|
+
VTCM_LAYOUT_ALLOC(off_group_a, off_scales, HTP_MM_HMX_TILE_SIZE); // Padded to 2K for alignment and future persistent data
|
|
416
|
+
VTCM_LAYOUT_ALLOC(off_group_a, off_act, act_area_size);
|
|
417
|
+
|
|
418
|
+
// Group B: Compute-only buffers (starts at off_group_a)
|
|
419
|
+
size_t off_group_b = off_group_a;
|
|
420
|
+
VTCM_LAYOUT_ALLOC(off_group_b, off_weight[0], weight_area_size);
|
|
421
|
+
VTCM_LAYOUT_ALLOC_OPTIONAL(off_group_b, off_weight[1], weight_area_size, pipeline);
|
|
422
|
+
VTCM_LAYOUT_ALLOC(off_group_b, off_dst[0], output_area_size);
|
|
423
|
+
VTCM_LAYOUT_ALLOC(off_group_b, off_scratch[0], scratch0_size);
|
|
424
|
+
VTCM_LAYOUT_ALLOC_OPTIONAL(off_group_b, off_scratch[1], scratch0_size, pipeline);
|
|
425
|
+
VTCM_LAYOUT_ALLOC_OPTIONAL(off_group_b, off_dst[1], output_area_size, pipeline);
|
|
426
|
+
|
|
427
|
+
const size_t group_b_size = off_group_b - off_group_a;
|
|
428
|
+
|
|
429
|
+
// Group C: Activation prep temporary buffer (overlaps Group B, starting at off_group_a)
|
|
430
|
+
const size_t max_f32_size = act_threads * 64 * k * sizeof(float);
|
|
431
|
+
const size_t act_f32_size = hex_align_up(hex_smin(max_f32_size, hex_smax(min_f32_size, group_b_size)), 128);
|
|
432
|
+
size_t off_group_c = off_group_a;
|
|
433
|
+
VTCM_LAYOUT_ALLOC(off_group_c, off_act_f32, act_f32_size);
|
|
434
|
+
|
|
435
|
+
const size_t group_c_size = off_group_c - off_group_a;
|
|
436
|
+
|
|
437
|
+
L->weight_area_bytes = weight_area_size;
|
|
438
|
+
L->act_area_bytes = act_area_size;
|
|
439
|
+
L->act_f32_bytes = act_f32_size;
|
|
440
|
+
L->output_area_bytes = output_area_size;
|
|
441
|
+
L->scratch_bytes[0] = scratch0_size;
|
|
442
|
+
L->scratch_bytes[1] = scratch1_size;
|
|
443
|
+
L->act_head_stride = 0;
|
|
444
|
+
|
|
445
|
+
off = off_group_a + hex_smax(group_b_size, group_c_size);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
L->total_bytes = off;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
static inline void htp_mm_hvx_vtcm_layout_build(
|
|
452
|
+
struct htp_mm_hvx_vtcm_layout * L,
|
|
453
|
+
int kernel_type,
|
|
454
|
+
int wtype,
|
|
455
|
+
uint32_t ne10, // k
|
|
456
|
+
uint32_t src1_nrows, // m_total
|
|
457
|
+
uint32_t n_threads,
|
|
458
|
+
size_t dst_row_size,
|
|
459
|
+
size_t src0_row_size,
|
|
460
|
+
size_t src1_row_size,
|
|
461
|
+
uint32_t n_prefetch,
|
|
462
|
+
bool is_matmul_id,
|
|
463
|
+
bool is_fused_qkv,
|
|
464
|
+
bool is_fused_ffn
|
|
465
|
+
) {
|
|
466
|
+
size_t src0_sz = 0;
|
|
467
|
+
size_t src1_sz = 0;
|
|
468
|
+
size_t src2_sz = 0;
|
|
469
|
+
size_t src3_sz = 0;
|
|
470
|
+
size_t dst_sz = 0;
|
|
471
|
+
|
|
472
|
+
const bool is_repack = (wtype == HTP_TYPE_Q4_0 || wtype == HTP_TYPE_Q4_1 ||
|
|
473
|
+
wtype == HTP_TYPE_Q8_0 || wtype == HTP_TYPE_IQ4_NL ||
|
|
474
|
+
wtype == HTP_TYPE_MXFP4);
|
|
475
|
+
|
|
476
|
+
if (is_fused_qkv || is_fused_ffn) {
|
|
477
|
+
const size_t src0_row_size_padded = hex_round_up(src0_row_size, 128);
|
|
478
|
+
const size_t quant_scratch_size = hex_round_up(ne10 * sizeof(float), QK_Q8_0_TILED * sizeof(float)) * n_threads;
|
|
479
|
+
|
|
480
|
+
size_t src0_sz_per_thread = 0;
|
|
481
|
+
size_t src2_sz_per_thread = 0;
|
|
482
|
+
size_t src3_sz_per_thread = 0;
|
|
483
|
+
|
|
484
|
+
if (is_repack) {
|
|
485
|
+
uint32_t aligned_tile_size = htp_mm_get_weight_aligned_tile_size(wtype);
|
|
486
|
+
uint32_t n_k_tiles = hex_round_up(ne10, 32) / 32;
|
|
487
|
+
uint32_t tile_row_size = n_k_tiles * aligned_tile_size;
|
|
488
|
+
|
|
489
|
+
src0_sz_per_thread = hex_round_up(n_prefetch * tile_row_size, 128);
|
|
490
|
+
src2_sz_per_thread = hex_round_up(n_prefetch * tile_row_size, 128);
|
|
491
|
+
if (is_fused_qkv) {
|
|
492
|
+
src3_sz_per_thread = hex_round_up(n_prefetch * tile_row_size, 128);
|
|
493
|
+
}
|
|
494
|
+
} else {
|
|
495
|
+
src0_sz_per_thread = hex_round_up(n_prefetch * src0_row_size_padded, 128);
|
|
496
|
+
src2_sz_per_thread = hex_round_up(n_prefetch * src0_row_size_padded, 128);
|
|
497
|
+
if (is_fused_qkv) {
|
|
498
|
+
src3_sz_per_thread = hex_round_up(n_prefetch * src0_row_size_padded, 128);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
size_t flat_src1_row_size = (wtype == HTP_TYPE_Q4_1) ? htp_mm_q8_1_flat_row_size(ne10) : htp_mm_q8_0_flat_row_size(ne10);
|
|
503
|
+
size_t tiled_src1_row_size = (wtype == HTP_TYPE_Q4_1) ? htp_mm_q8_1_tiled_row_size(ne10) : htp_mm_q8_0_tiled_row_size(ne10);
|
|
504
|
+
|
|
505
|
+
if (kernel_type == HTP_MM_KERNEL_HVX_QUANT_ROW_FLAT) {
|
|
506
|
+
src1_sz = hex_round_up(flat_src1_row_size * src1_nrows, 128);
|
|
507
|
+
} else {
|
|
508
|
+
src1_sz = hex_round_up(tiled_src1_row_size * src1_nrows, 128);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
src0_sz = src0_sz_per_thread * n_threads;
|
|
512
|
+
src2_sz = src2_sz_per_thread * n_threads;
|
|
513
|
+
src3_sz = src3_sz_per_thread * n_threads;
|
|
514
|
+
dst_sz = quant_scratch_size;
|
|
515
|
+
} else if (is_matmul_id) {
|
|
516
|
+
const size_t src0_row_size_padded = htp_mm_round_up(src0_row_size, 128);
|
|
517
|
+
const size_t src1_row_size_tiled = (wtype == HTP_TYPE_Q4_1) ? htp_mm_q8_1_tiled_row_size(ne10)
|
|
518
|
+
: htp_mm_q8_0_tiled_row_size(ne10);
|
|
519
|
+
|
|
520
|
+
size_t src0_sz_per_thread = htp_mm_round_up(n_prefetch * src0_row_size_padded, 256);
|
|
521
|
+
src1_sz = htp_mm_round_up(src1_row_size_tiled * src1_nrows, 256);
|
|
522
|
+
|
|
523
|
+
if (is_repack) {
|
|
524
|
+
const uint32_t aligned_tile_size = htp_mm_get_weight_aligned_tile_size(wtype);
|
|
525
|
+
const uint32_t n_k_tiles = ne10 / 32;
|
|
526
|
+
const uint32_t tile_row_size = n_k_tiles * aligned_tile_size;
|
|
527
|
+
size_t repacked_vtcm_size = htp_mm_round_up(n_prefetch * tile_row_size, 256);
|
|
528
|
+
src0_sz_per_thread = repacked_vtcm_size;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
src0_sz = src0_sz_per_thread * n_threads;
|
|
532
|
+
dst_sz = htp_mm_round_up(ne10 * sizeof(float), QK_Q8_0_TILED * sizeof(float)) * n_threads;
|
|
533
|
+
} else {
|
|
534
|
+
const size_t src0_row_size_padded = htp_mm_round_up(src0_row_size, 128);
|
|
535
|
+
const size_t dst_nrows = (src1_nrows > 1) ? 0 : 1;
|
|
536
|
+
|
|
537
|
+
switch (kernel_type) {
|
|
538
|
+
case HTP_MM_KERNEL_HVX_F16_F16_VTCM: {
|
|
539
|
+
size_t f16_src1_row_size = htp_mm_round_up(ne10 * 2, 128);
|
|
540
|
+
src1_sz = htp_mm_round_up(f16_src1_row_size * src1_nrows, 256);
|
|
541
|
+
src0_sz = htp_mm_round_up(n_prefetch * src0_row_size_padded, 256) * n_threads;
|
|
542
|
+
dst_sz = dst_nrows > 0 ? htp_mm_round_up(dst_row_size, 128) * n_threads : 0;
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
case HTP_MM_KERNEL_HVX_F16_F32_DDR:
|
|
546
|
+
case HTP_MM_KERNEL_HVX_F16_F16_DDR:
|
|
547
|
+
case HTP_MM_KERNEL_HVX_F32_F32_DDR:
|
|
548
|
+
case HTP_MM_KERNEL_HVX_F32_F16_DDR: {
|
|
549
|
+
src0_sz = htp_mm_round_up(n_prefetch * src0_row_size, 256) * n_threads;
|
|
550
|
+
src1_sz = htp_mm_round_up(n_prefetch * src1_row_size, 256) * n_threads;
|
|
551
|
+
dst_sz = dst_nrows > 0 ? htp_mm_round_up(dst_row_size, 128) * n_threads : 0;
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
case HTP_MM_KERNEL_HVX_F32_F32_VTCM: {
|
|
555
|
+
size_t f32_src1_row_size = htp_mm_round_up(ne10 * 4, 128);
|
|
556
|
+
src1_sz = htp_mm_round_up(f32_src1_row_size * src1_nrows, 256);
|
|
557
|
+
src0_sz = htp_mm_round_up(n_prefetch * src0_row_size_padded, 256) * n_threads;
|
|
558
|
+
dst_sz = dst_nrows > 0 ? htp_mm_round_up(dst_row_size, 128) * n_threads : 0;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
case HTP_MM_KERNEL_HVX_QUANT_BLOCK:
|
|
562
|
+
case HTP_MM_KERNEL_HVX_QUANT_ROW: {
|
|
563
|
+
size_t q_src1_row_size = (wtype == HTP_TYPE_Q4_1) ? htp_mm_q8_1_tiled_row_size(ne10) : htp_mm_q8_0_tiled_row_size(ne10);
|
|
564
|
+
|
|
565
|
+
src0_sz = htp_mm_round_up(n_prefetch * src0_row_size_padded, 256);
|
|
566
|
+
src1_sz = htp_mm_round_up(q_src1_row_size * src1_nrows, 256);
|
|
567
|
+
|
|
568
|
+
src0_sz = src0_sz * n_threads;
|
|
569
|
+
|
|
570
|
+
if (is_repack) {
|
|
571
|
+
uint32_t aligned_tile_size = htp_mm_get_weight_aligned_tile_size(wtype);
|
|
572
|
+
uint32_t n_k_tiles = ne10 / 32;
|
|
573
|
+
uint32_t tile_row_size = n_k_tiles * aligned_tile_size;
|
|
574
|
+
size_t repacked_vtcm_size = htp_mm_round_up(n_prefetch * tile_row_size, 256);
|
|
575
|
+
src0_sz = repacked_vtcm_size * n_threads;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
size_t quant_scratch_size_per_thread = htp_mm_round_up(ne10 * sizeof(float), QK_Q8_0_TILED * sizeof(float));
|
|
579
|
+
size_t dst_size_per_thread = dst_nrows > 0 ? htp_mm_round_up(dst_row_size, 128) : 0;
|
|
580
|
+
if (dst_size_per_thread < quant_scratch_size_per_thread) {
|
|
581
|
+
dst_size_per_thread = quant_scratch_size_per_thread;
|
|
582
|
+
}
|
|
583
|
+
dst_sz = dst_size_per_thread * n_threads;
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
case HTP_MM_KERNEL_HVX_QUANT_ROW_FLAT: {
|
|
587
|
+
size_t q_src1_row_size = (wtype == HTP_TYPE_Q4_1) ? htp_mm_q8_1_flat_row_size(ne10) : htp_mm_q8_0_flat_row_size(ne10);
|
|
588
|
+
|
|
589
|
+
src0_sz = htp_mm_round_up(n_prefetch * src0_row_size_padded, 256);
|
|
590
|
+
src1_sz = htp_mm_round_up(q_src1_row_size * src1_nrows, 256);
|
|
591
|
+
|
|
592
|
+
src0_sz = src0_sz * n_threads;
|
|
593
|
+
|
|
594
|
+
if (is_repack) {
|
|
595
|
+
uint32_t aligned_tile_size = htp_mm_get_weight_aligned_tile_size(wtype);
|
|
596
|
+
uint32_t n_k_tiles = ne10 / 32;
|
|
597
|
+
uint32_t tile_row_size = n_k_tiles * aligned_tile_size;
|
|
598
|
+
size_t repacked_vtcm_size = htp_mm_round_up(n_prefetch * tile_row_size, 256);
|
|
599
|
+
src0_sz = repacked_vtcm_size * n_threads;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
size_t quant_scratch_size_per_thread = htp_mm_round_up(ne10 * sizeof(float), QK_Q8_0_TILED * sizeof(float));
|
|
603
|
+
size_t dst_size_per_thread = dst_nrows > 0 ? htp_mm_round_up(dst_row_size, 128) : 0;
|
|
604
|
+
if (dst_size_per_thread < quant_scratch_size_per_thread) {
|
|
605
|
+
dst_size_per_thread = quant_scratch_size_per_thread;
|
|
606
|
+
}
|
|
607
|
+
dst_sz = dst_size_per_thread * n_threads;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
default:
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
size_t off = 0;
|
|
616
|
+
VTCM_LAYOUT_ALLOC(off, off_src1, src1_sz);
|
|
617
|
+
VTCM_LAYOUT_ALLOC(off, off_src0, src0_sz);
|
|
618
|
+
VTCM_LAYOUT_ALLOC(off, off_src2, src2_sz);
|
|
619
|
+
VTCM_LAYOUT_ALLOC(off, off_src3, src3_sz);
|
|
620
|
+
VTCM_LAYOUT_ALLOC(off, off_dst, dst_sz);
|
|
621
|
+
|
|
622
|
+
L->src0_bytes = src0_sz;
|
|
623
|
+
L->src1_bytes = src1_sz;
|
|
624
|
+
L->src2_bytes = src2_sz;
|
|
625
|
+
L->src3_bytes = src3_sz;
|
|
626
|
+
L->dst_bytes = dst_sz;
|
|
627
|
+
L->total_bytes = off;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
static inline size_t htp_mm_hmx_get_2d_vtcm_size(
|
|
631
|
+
int wtype, uint32_t k, size_t mc, size_t nc, bool pipeline, uint32_t act_threads, uint32_t aligned_tile_size
|
|
632
|
+
) {
|
|
633
|
+
struct htp_mm_hmx_vtcm_layout L;
|
|
634
|
+
htp_mm_hmx_vtcm_layout_build(&L, HTP_MM_KERNEL_HMX_2D, wtype, k, mc, nc, 1, false, pipeline, act_threads, aligned_tile_size);
|
|
635
|
+
return L.total_bytes;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
static inline size_t htp_mm_hmx_get_batched_vtcm_size(
|
|
639
|
+
int wtype, uint32_t k, size_t mc, size_t nc, uint32_t group_size, bool use_dma_activation, bool pipeline, uint32_t act_threads) {
|
|
640
|
+
(void)pipeline;
|
|
641
|
+
struct htp_mm_hmx_vtcm_layout L;
|
|
642
|
+
htp_mm_hmx_vtcm_layout_build(&L, HTP_MM_KERNEL_HMX_F16_BATCHED, wtype, k, mc, nc, group_size, use_dma_activation, false, act_threads, 0);
|
|
643
|
+
return L.total_bytes;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
#ifdef __cplusplus
|
|
647
|
+
}
|
|
648
|
+
#endif
|
|
649
|
+
|
|
650
|
+
#endif // HTP_MATMUL_OPS_H
|