whispercpp 1.3.6 → 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/.document +3 -0
- data/.rdoc_options +2 -0
- data/README.md +43 -9
- data/Rakefile +18 -3
- data/ext/dependencies.rb +10 -4
- data/ext/dependencies_for_windows.rb +17 -0
- data/ext/extconf.rb +20 -8
- data/ext/options.rb +54 -14
- data/ext/options_for_windows.rb +51 -0
- data/ext/ruby_whisper.c +35 -42
- data/ext/ruby_whisper.h +141 -0
- data/ext/ruby_whisper_context.c +157 -29
- data/ext/ruby_whisper_log_queue.c +180 -0
- data/ext/ruby_whisper_log_settable.h +46 -0
- data/ext/ruby_whisper_parakeet.c +49 -0
- data/ext/ruby_whisper_parakeet_context.c +304 -0
- data/ext/ruby_whisper_parakeet_context_params.c +117 -0
- data/ext/ruby_whisper_parakeet_model.c +84 -0
- data/ext/ruby_whisper_parakeet_params.c +548 -0
- data/ext/ruby_whisper_parakeet_segment.c +157 -0
- data/ext/ruby_whisper_parakeet_token.c +188 -0
- data/ext/ruby_whisper_parakeet_transcribe.cpp +58 -0
- data/ext/ruby_whisper_params.c +265 -73
- data/ext/ruby_whisper_segment.c +6 -6
- data/ext/ruby_whisper_transcribe.cpp +23 -15
- 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 +42 -3
- data/ext/sources/CMakePresets.json +95 -0
- data/ext/sources/cmake/parakeet-config.cmake.in +30 -0
- data/ext/sources/cmake/parakeet.pc.in +10 -0
- data/ext/sources/cmake/whisper.pc.in +2 -2
- data/ext/sources/examples/CMakeLists.txt +4 -2
- data/ext/sources/examples/bench/bench.cpp +1 -1
- data/ext/sources/examples/cli/cli.cpp +52 -10
- data/ext/sources/examples/common-ggml.cpp +4 -0
- data/ext/sources/examples/common-whisper.cpp +139 -67
- data/ext/sources/examples/common-whisper.h +11 -0
- data/ext/sources/examples/ffmpeg-transcode.cpp +211 -341
- data/ext/sources/examples/parakeet-cli/CMakeLists.txt +8 -0
- data/ext/sources/examples/parakeet-cli/parakeet-cli.cpp +243 -0
- data/ext/sources/examples/parakeet-quantize/CMakeLists.txt +7 -0
- data/ext/sources/examples/parakeet-quantize/parakeet-quantize.cpp +230 -0
- data/ext/sources/examples/server/server.cpp +199 -163
- data/ext/sources/examples/vad-speech-segments/speech.cpp +3 -2
- data/ext/sources/ggml/CMakeLists.txt +21 -14
- data/ext/sources/ggml/cmake/FindNCCL.cmake +36 -0
- data/ext/sources/ggml/cmake/ggml-config.cmake.in +12 -2
- data/ext/sources/ggml/include/ggml-alloc.h +1 -0
- data/ext/sources/ggml/include/ggml-backend.h +72 -10
- data/ext/sources/ggml/include/ggml-cuda.h +2 -2
- data/ext/sources/ggml/include/ggml-rpc.h +3 -3
- data/ext/sources/ggml/include/ggml-sycl.h +8 -0
- data/ext/sources/ggml/include/ggml.h +103 -9
- data/ext/sources/ggml/include/gguf.h +10 -2
- data/ext/sources/ggml/src/CMakeLists.txt +30 -6
- data/ext/sources/ggml/src/ggml-alloc.c +5 -1
- data/ext/sources/ggml/src/ggml-backend-impl.h +22 -2
- data/ext/sources/ggml/src/ggml-backend-meta.cpp +2266 -0
- data/ext/sources/ggml/src/ggml-backend-reg.cpp +12 -0
- data/ext/sources/ggml/src/ggml-backend.cpp +110 -9
- data/ext/sources/ggml/src/ggml-blas/ggml-blas.cpp +4 -0
- data/ext/sources/ggml/src/ggml-cann/aclnn_ops.cpp +672 -257
- data/ext/sources/ggml/src/ggml-cann/aclnn_ops.h +71 -0
- data/ext/sources/ggml/src/ggml-cann/common.h +20 -10
- data/ext/sources/ggml/src/ggml-cann/ggml-cann.cpp +211 -30
- data/ext/sources/ggml/src/ggml-common.h +24 -2
- data/ext/sources/ggml/src/ggml-cpu/CMakeLists.txt +59 -30
- data/ext/sources/ggml/src/ggml-cpu/amx/amx.cpp +2 -0
- data/ext/sources/ggml/src/ggml-cpu/amx/mmq.cpp +21 -22
- data/ext/sources/ggml/src/ggml-cpu/arch/arm/quants.c +194 -11
- data/ext/sources/ggml/src/ggml-cpu/arch/arm/repack.cpp +65 -0
- data/ext/sources/ggml/src/ggml-cpu/arch/loongarch/quants.c +151 -1
- data/ext/sources/ggml/src/ggml-cpu/arch/powerpc/quants.c +0 -1
- data/ext/sources/ggml/src/ggml-cpu/arch/riscv/quants.c +4279 -1292
- data/ext/sources/ggml/src/ggml-cpu/arch/riscv/repack.cpp +5 -35
- data/ext/sources/ggml/src/ggml-cpu/arch/s390/quants.c +0 -1
- data/ext/sources/ggml/src/ggml-cpu/arch/wasm/quants.c +72 -1
- data/ext/sources/ggml/src/ggml-cpu/arch/x86/quants.c +319 -31
- data/ext/sources/ggml/src/ggml-cpu/arch/x86/repack.cpp +1 -1
- data/ext/sources/ggml/src/ggml-cpu/arch-fallback.h +12 -2
- data/ext/sources/ggml/src/ggml-cpu/cmake/FindSMTIME.cmake +32 -0
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu-impl.h +10 -0
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.c +109 -5
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.cpp +2 -0
- data/ext/sources/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +146 -134
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm.cpp +107 -82
- data/ext/sources/ggml/src/ggml-cpu/ops.cpp +501 -119
- data/ext/sources/ggml/src/ggml-cpu/ops.h +3 -0
- data/ext/sources/ggml/src/ggml-cpu/quants.c +106 -0
- data/ext/sources/ggml/src/ggml-cpu/quants.h +6 -0
- data/ext/sources/ggml/src/ggml-cpu/repack.cpp +3 -0
- data/ext/sources/ggml/src/ggml-cpu/simd-gemm.h +91 -1
- data/ext/sources/ggml/src/ggml-cpu/simd-mappings.h +14 -16
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime.cpp +1402 -687
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime.h +8 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime1_kernels.cpp +597 -2766
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime2_kernels.cpp +5768 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime_env.cpp +320 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime_env.h +55 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime_kernels.h +182 -19
- data/ext/sources/ggml/src/ggml-cpu/spacemit/repack.cpp +1795 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/repack.h +14 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/rvv_kernels.cpp +3178 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/rvv_kernels.h +95 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/spine_barrier.h +34 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/spine_mem_pool.cpp +760 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/spine_mem_pool.h +32 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/spine_tcm.h +409 -0
- data/ext/sources/ggml/src/ggml-cpu/vec.cpp +39 -55
- data/ext/sources/ggml/src/ggml-cpu/vec.h +225 -240
- data/ext/sources/ggml/src/ggml-cuda/CMakeLists.txt +17 -7
- data/ext/sources/ggml/src/ggml-cuda/allreduce.cu +971 -0
- data/ext/sources/ggml/src/ggml-cuda/allreduce.cuh +29 -0
- data/ext/sources/ggml/src/ggml-cuda/argsort.cu +62 -26
- data/ext/sources/ggml/src/ggml-cuda/binbcast.cu +134 -64
- data/ext/sources/ggml/src/ggml-cuda/binbcast.cuh +1 -0
- 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 +246 -28
- data/ext/sources/ggml/src/ggml-cuda/concat.cu +134 -116
- data/ext/sources/ggml/src/ggml-cuda/conv-transpose-1d.cu +14 -12
- data/ext/sources/ggml/src/ggml-cuda/conv2d-transpose.cu +45 -21
- data/ext/sources/ggml/src/ggml-cuda/conv2d-transpose.cuh +1 -0
- data/ext/sources/ggml/src/ggml-cuda/convert.cu +139 -34
- data/ext/sources/ggml/src/ggml-cuda/convert.cuh +10 -0
- data/ext/sources/ggml/src/ggml-cuda/cpy.cu +88 -29
- data/ext/sources/ggml/src/ggml-cuda/dequantize.cuh +22 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn-common.cuh +287 -49
- data/ext/sources/ggml/src/ggml-cuda/fattn-mma-f16.cuh +335 -130
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile.cu +12 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile.cuh +127 -24
- data/ext/sources/ggml/src/ggml-cuda/fattn-vec.cuh +40 -15
- data/ext/sources/ggml/src/ggml-cuda/fattn-wmma-f16.cu +18 -9
- data/ext/sources/ggml/src/ggml-cuda/fattn.cu +169 -60
- data/ext/sources/ggml/src/ggml-cuda/fattn.cuh +2 -0
- data/ext/sources/ggml/src/ggml-cuda/fwht.cu +101 -0
- data/ext/sources/ggml/src/ggml-cuda/fwht.cuh +4 -0
- data/ext/sources/ggml/src/ggml-cuda/gated_delta_net.cu +109 -45
- data/ext/sources/ggml/src/ggml-cuda/gated_delta_net.cuh +10 -0
- data/ext/sources/ggml/src/ggml-cuda/getrows.cu +48 -23
- data/ext/sources/ggml/src/ggml-cuda/ggml-cuda.cu +2034 -2104
- data/ext/sources/ggml/src/ggml-cuda/im2col.cu +32 -29
- data/ext/sources/ggml/src/ggml-cuda/mean.cu +4 -2
- data/ext/sources/ggml/src/ggml-cuda/mma.cuh +242 -195
- data/ext/sources/ggml/src/ggml-cuda/mmf.cuh +3 -3
- data/ext/sources/ggml/src/ggml-cuda/mmq.cu +25 -12
- data/ext/sources/ggml/src/ggml-cuda/mmq.cuh +502 -423
- data/ext/sources/ggml/src/ggml-cuda/mmvf.cu +19 -12
- data/ext/sources/ggml/src/ggml-cuda/mmvq.cu +562 -97
- data/ext/sources/ggml/src/ggml-cuda/mmvq.cuh +6 -1
- data/ext/sources/ggml/src/ggml-cuda/norm.cu +36 -10
- data/ext/sources/ggml/src/ggml-cuda/out-prod.cu +66 -7
- data/ext/sources/ggml/src/ggml-cuda/quantize.cu +133 -26
- data/ext/sources/ggml/src/ggml-cuda/quantize.cuh +1 -1
- data/ext/sources/ggml/src/ggml-cuda/reduce_rows.cuh +5 -1
- data/ext/sources/ggml/src/ggml-cuda/rope.cu +11 -4
- data/ext/sources/ggml/src/ggml-cuda/scale.cu +4 -1
- data/ext/sources/ggml/src/ggml-cuda/set-rows.cu +78 -10
- data/ext/sources/ggml/src/ggml-cuda/snake.cu +72 -0
- data/ext/sources/ggml/src/ggml-cuda/snake.cuh +8 -0
- data/ext/sources/ggml/src/ggml-cuda/softcap.cu +4 -1
- data/ext/sources/ggml/src/ggml-cuda/ssm-conv.cu +45 -13
- data/ext/sources/ggml/src/ggml-cuda/ssm-conv.cuh +1 -1
- data/ext/sources/ggml/src/ggml-cuda/ssm-scan.cu +40 -18
- data/ext/sources/ggml/src/ggml-cuda/sumrows.cu +8 -4
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_32.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +2 -0
- 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_16-ncols2_4.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_32.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +2 -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_16.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_4-ncols2_4.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +2 -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/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +2 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq192-dv128.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq320-dv256.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq512-dv512.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-bf16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-f16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q8_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-bf16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-bf16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-bf16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-bf16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-bf16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-bf16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmq-instance-nvfp4.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmq-instance-q1_0.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/top-k.cu +5 -4
- data/ext/sources/ggml/src/ggml-cuda/topk-moe.cu +33 -24
- data/ext/sources/ggml/src/ggml-cuda/unary.cu +31 -2
- data/ext/sources/ggml/src/ggml-cuda/unary.cuh +2 -0
- data/ext/sources/ggml/src/ggml-cuda/vecdotq.cuh +80 -0
- data/ext/sources/ggml/src/ggml-cuda/vendors/cuda.h +7 -2
- data/ext/sources/ggml/src/ggml-cuda/vendors/hip.h +23 -4
- data/ext/sources/ggml/src/ggml-cuda/vendors/musa.h +4 -0
- data/ext/sources/ggml/src/ggml-hexagon/CMakeLists.txt +1 -5
- data/ext/sources/ggml/src/ggml-hexagon/ggml-hexagon.cpp +2788 -1762
- data/ext/sources/ggml/src/ggml-hexagon/htp/CMakeLists.txt +13 -4
- data/ext/sources/ggml/src/ggml-hexagon/htp/act-ops.c +53 -84
- data/ext/sources/ggml/src/ggml-hexagon/htp/argsort-ops.c +25 -12
- data/ext/sources/ggml/src/ggml-hexagon/htp/binary-ops.c +165 -184
- data/ext/sources/ggml/src/ggml-hexagon/htp/cmake-toolchain.cmake +17 -19
- data/ext/sources/ggml/src/ggml-hexagon/htp/concat-ops.c +277 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/cpy-ops.c +170 -127
- data/ext/sources/ggml/src/ggml-hexagon/htp/cumsum-ops.c +270 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/diag-ops.c +216 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/fill-ops.c +123 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/flash-attn-ops.c +1774 -396
- data/ext/sources/ggml/src/ggml-hexagon/htp/flash-attn-ops.h +303 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/gated-delta-net-ops.c +1148 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/get-rows-ops.c +148 -42
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-common.h +80 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-dma.c +2 -2
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-dma.h +255 -62
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-dump.h +9 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-profile.h +64 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-utils.h +25 -21
- 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 +167 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-queue.h +157 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-utils.h +222 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ctx.h +104 -13
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ops.h +222 -57
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-vtcm.h +19 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp_iface.idl +10 -3
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-base.h +78 -26
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-copy.h +27 -10
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-div.h +63 -23
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-exp.h +48 -8
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-fa-kernels.h +232 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-flash-attn.h +47 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-log.h +65 -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-pow.h +42 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-repl.h +74 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-sigmoid.h +40 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-sin-cos.h +90 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-utils.h +5 -8
- data/ext/sources/ggml/src/ggml-hexagon/htp/main.c +625 -816
- data/ext/sources/ggml/src/ggml-hexagon/htp/matmul-ops.c +3052 -2166
- data/ext/sources/ggml/src/ggml-hexagon/htp/matmul-ops.h +650 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/pad-ops.c +547 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/repeat-ops.c +148 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/rope-ops.c +337 -106
- data/ext/sources/ggml/src/ggml-hexagon/htp/set-rows-ops.c +59 -37
- data/ext/sources/ggml/src/ggml-hexagon/htp/softmax-ops.c +121 -133
- data/ext/sources/ggml/src/ggml-hexagon/htp/solve-tri-ops.c +267 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/ssm-conv.c +245 -151
- data/ext/sources/ggml/src/ggml-hexagon/htp/sum-rows-ops.c +6 -6
- data/ext/sources/ggml/src/ggml-hexagon/htp/unary-ops.c +719 -45
- 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 +390 -0
- data/ext/sources/ggml/src/ggml-hexagon/libggml-htp.inf +3 -5
- data/ext/sources/ggml/src/ggml-hip/CMakeLists.txt +27 -9
- data/ext/sources/ggml/src/ggml-impl.h +6 -1
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.cpp +207 -18
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.h +36 -2
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.m +186 -29
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-impl.h +118 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.cpp +322 -21
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.h +4 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.cpp +39 -26
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.metal +1226 -467
- data/ext/sources/ggml/src/ggml-musa/CMakeLists.txt +5 -6
- data/ext/sources/ggml/src/ggml-opencl/CMakeLists.txt +67 -5
- data/ext/sources/ggml/src/ggml-opencl/fa_tune.h +92 -0
- data/ext/sources/ggml/src/ggml-opencl/ggml-opencl.cpp +16290 -6246
- data/ext/sources/ggml/src/ggml-opencl/kernels/concat.cl +67 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/cpy.cl +59 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/cvt.cl +1997 -92
- 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/gated_delta_net.cl +249 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_mxfp4_f32_ns.cl +374 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_0_f32_ns.cl +324 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_1_f32_ns.cl +326 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_k_f32_ns.cl +348 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_0_f32_ns.cl +328 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_1_f32_ns.cl +330 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_k_f32_ns.cl +356 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q6_k_f32_ns.cl +335 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_iq4_nl_f32.cl +150 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q1_0_f32.cl +94 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/{mul_mat_Ab_Bi_8x4.cl → gemm_noshuffle_q4_0_f32.cl} +1 -1
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q4_k_f32.cl +172 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q5_0_f32.cl +131 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q5_1_f32.cl +134 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q5_k_f32.cl +176 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q6_k_f32.cl +140 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/{mul_mm_q8_0_f32_8x4.cl → gemm_noshuffle_q8_0_f32.cl} +1 -1
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_xmem_f16_f32_os8.cl +233 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_moe_mxfp4_f32_ns.cl +165 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_moe_q4_0_f32_ns.cl +120 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_moe_q4_1_f32_ns.cl +123 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_moe_q4_k_f32_ns.cl +155 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_moe_q5_0_f32_ns.cl +123 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_moe_q5_1_f32_ns.cl +125 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_moe_q5_k_f32_ns.cl +160 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_moe_q6_k_f32_ns.cl +141 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_iq4_nl_f32.cl +302 -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_general.cl → gemv_noshuffle_q4_0_f32.cl} +5 -5
- data/ext/sources/ggml/src/ggml-opencl/kernels/{gemv_noshuffle.cl → gemv_noshuffle_q4_0_f32_spec.cl} +5 -5
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q4_k_f32.cl +318 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q5_0_f32.cl +291 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q5_1_f32.cl +294 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q5_k_f32.cl +326 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q6_k_f32.cl +293 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/{gemv_noshuffle_general_q8_0_f32.cl → gemv_noshuffle_q8_0_f32.cl} +1 -1
- data/ext/sources/ggml/src/ggml-opencl/kernels/get_rows.cl +15 -9
- data/ext/sources/ggml/src/ggml-opencl/kernels/moe_reorder_b.cl +30 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/moe_sort_by_expert.cl +82 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_iq4_nl_f32_l4_lm.cl +171 -0
- 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_mm_q4_k_f32_l4_lm.cl +179 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q5_0_f32_l4_lm.cl +173 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q5_1_f32_l4_lm.cl +175 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q5_k_f32_l4_lm.cl +192 -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_iq4_nl_f32.cl +164 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_iq4_nl_f32_flat.cl +202 -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/mul_mv_q4_k_f32_flat.cl +196 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q5_0_f32.cl +241 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q5_0_f32_flat.cl +243 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q5_1_f32.cl +243 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q5_1_f32_flat.cl +247 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q5_k_f32.cl +187 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q5_k_f32_flat.cl +203 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q6_k_f32_flat.cl +48 -64
- 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 +740 -127
- data/ext/sources/ggml/src/ggml-openvino/ggml-decoder.h +76 -23
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino-extra.cpp +75 -14
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino-extra.h +29 -8
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino.cpp +339 -69
- data/ext/sources/ggml/src/ggml-openvino/ggml-quants.cpp +330 -192
- 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 +161 -39
- 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 -22
- data/ext/sources/ggml/src/ggml-openvino/openvino/op_table.h +18 -4
- 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/rt_info/weightless_caching_attributes.hpp +41 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/translate_session.cpp +70 -43
- data/ext/sources/ggml/src/ggml-openvino/openvino/translate_session.h +5 -4
- data/ext/sources/ggml/src/ggml-openvino/openvino/utils.cpp +612 -36
- data/ext/sources/ggml/src/ggml-openvino/openvino/utils.h +29 -26
- data/ext/sources/ggml/src/ggml-openvino/utils.cpp +460 -114
- data/ext/sources/ggml/src/ggml-openvino/utils.h +32 -9
- data/ext/sources/ggml/src/ggml-opt.cpp +1 -0
- data/ext/sources/ggml/src/ggml-quants.c +365 -114
- data/ext/sources/ggml/src/ggml-quants.h +6 -0
- data/ext/sources/ggml/src/ggml-rpc/CMakeLists.txt +24 -0
- data/ext/sources/ggml/src/ggml-rpc/ggml-rpc.cpp +167 -311
- data/ext/sources/ggml/src/ggml-rpc/transport.cpp +683 -0
- data/ext/sources/ggml/src/ggml-rpc/transport.h +34 -0
- data/ext/sources/ggml/src/ggml-sycl/CMakeLists.txt +50 -4
- data/ext/sources/ggml/src/ggml-sycl/add-id.cpp +1 -1
- data/ext/sources/ggml/src/ggml-sycl/backend.hpp +5 -1
- 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 +72 -2
- data/ext/sources/ggml/src/ggml-sycl/common.hpp +59 -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 +121 -13
- data/ext/sources/ggml/src/ggml-sycl/convert.hpp +9 -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/cumsum.cpp +148 -0
- data/ext/sources/ggml/src/ggml-sycl/cumsum.hpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/dequantize.hpp +678 -0
- data/ext/sources/ggml/src/ggml-sycl/diag.cpp +67 -0
- data/ext/sources/ggml/src/ggml-sycl/diag.hpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/dmmv.cpp +997 -244
- data/ext/sources/ggml/src/ggml-sycl/dpct/helper.hpp +15 -7
- data/ext/sources/ggml/src/ggml-sycl/element_wise.cpp +215 -204
- data/ext/sources/ggml/src/ggml-sycl/element_wise.hpp +2 -2
- data/ext/sources/ggml/src/ggml-sycl/fattn-buffers.cpp +56 -0
- data/ext/sources/ggml/src/ggml-sycl/fattn-buffers.hpp +63 -0
- data/ext/sources/ggml/src/ggml-sycl/fattn-common.hpp +7 -5
- data/ext/sources/ggml/src/ggml-sycl/fattn-tile.cpp +4 -0
- data/ext/sources/ggml/src/ggml-sycl/fattn-tile.hpp +76 -168
- data/ext/sources/ggml/src/ggml-sycl/fattn-vec.hpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/fattn.cpp +3 -1
- data/ext/sources/ggml/src/ggml-sycl/fill.cpp +55 -0
- data/ext/sources/ggml/src/ggml-sycl/fill.hpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/gated_delta_net.cpp +69 -31
- data/ext/sources/ggml/src/ggml-sycl/gated_delta_net.hpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/gemm.hpp +3 -0
- data/ext/sources/ggml/src/ggml-sycl/getrows.cpp +79 -3
- data/ext/sources/ggml/src/ggml-sycl/ggml-sycl.cpp +1758 -455
- data/ext/sources/ggml/src/ggml-sycl/im2col.cpp +353 -89
- data/ext/sources/ggml/src/ggml-sycl/im2col.hpp +5 -3
- data/ext/sources/ggml/src/ggml-sycl/mmvq.cpp +1542 -39
- data/ext/sources/ggml/src/ggml-sycl/mmvq.hpp +33 -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/pad.cpp +27 -27
- 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/quants.hpp +71 -0
- data/ext/sources/ggml/src/ggml-sycl/set_rows.cpp +17 -3
- data/ext/sources/ggml/src/ggml-sycl/softmax.cpp +9 -10
- data/ext/sources/ggml/src/ggml-sycl/solve_tri.cpp +172 -0
- data/ext/sources/ggml/src/ggml-sycl/solve_tri.hpp +8 -0
- data/ext/sources/ggml/src/ggml-sycl/ssm_conv.cpp +6 -1
- data/ext/sources/ggml/src/ggml-sycl/ssm_scan.cpp +156 -0
- data/ext/sources/ggml/src/ggml-sycl/ssm_scan.hpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/sycl_hw.cpp +62 -10
- data/ext/sources/ggml/src/ggml-sycl/sycl_hw.hpp +18 -6
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq512-dv512.cpp +6 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-f16.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q4_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q4_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q5_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q5_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q8_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-f16.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q4_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q4_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q5_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q5_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q8_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-f16.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q4_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q4_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q5_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q5_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q8_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-f16.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q4_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q4_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q5_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q5_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q8_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-f16.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q4_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q4_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q5_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q5_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q8_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-f16.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q4_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q4_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q5_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q5_1.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q8_0.cpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/type.hpp +112 -0
- data/ext/sources/ggml/src/ggml-sycl/upscale.cpp +410 -0
- data/ext/sources/ggml/src/ggml-sycl/upscale.hpp +9 -0
- data/ext/sources/ggml/src/ggml-sycl/vecdotq.hpp +242 -45
- data/ext/sources/ggml/src/ggml-virtgpu/ggml-backend-buffer.cpp +4 -0
- data/ext/sources/ggml/src/ggml-virtgpu/ggml-backend-device.cpp +2 -0
- data/ext/sources/ggml/src/ggml-virtgpu/ggml-backend.cpp +2 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-shm.cpp +1 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu.cpp +1 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu.h +0 -2
- data/ext/sources/ggml/src/ggml-vulkan/CMakeLists.txt +16 -0
- data/ext/sources/ggml/src/ggml-vulkan/ggml-vulkan.cpp +2843 -700
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +4 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/col2im_1d.comp +61 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/contig_copy.comp +6 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_mm.comp +146 -13
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv3d_mm.comp +431 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/copy.comp +3 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/copy_from_quant.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp +25 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs.glsl +88 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs_cm2.glsl +643 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_nvfp4.comp +32 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q1_0.comp +29 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp +3 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dot_product_funcs.glsl +27 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/feature-tests/coopmat2_decode_vector.comp +7 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +198 -48
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_base.glsl +60 -59
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +116 -113
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +122 -31
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_dequant.glsl +131 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_mmq_funcs.glsl +203 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/fwht.comp +115 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gated_delta_net.comp +125 -64
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/generic_binary_head.glsl +0 -1
- 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 +29 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/glu_main.glsl +17 -11
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/im2col.comp +76 -54
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/im2col_3d.comp +0 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +4 -7
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/log.comp +0 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec.comp +122 -27
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iface.glsl +6 -6
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q2_k.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q4_k.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q5_k.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq.comp +22 -24
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq_funcs.glsl +88 -55
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +42 -40
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +49 -15
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_funcs.glsl +222 -171
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.glsl +8 -8
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_shmem_types.glsl +24 -9
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/multi_add.comp +0 -1
- 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/rope_funcs.glsl +5 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_head.glsl +0 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_params.glsl +3 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/snake.comp +49 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/ssm_conv.comp +11 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp +3 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/types.glsl +79 -2
- 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 +282 -211
- data/ext/sources/ggml/src/ggml-webgpu/CMakeLists.txt +5 -2
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp +2209 -283
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu.cpp +2618 -1416
- data/ext/sources/ggml/src/ggml-webgpu/pre_wgsl.hpp +37 -7
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/add_id.wgsl +64 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/binary.wgsl +8 -7
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/common_decls.tmpl +90 -95
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/concat.wgsl +19 -1
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/conv2d.wgsl +165 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/{cpy.tmpl.wgsl → cpy.wgsl} +25 -50
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn.wgsl +107 -184
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_quant_staging.tmpl +124 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_tile.wgsl +397 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_blk.wgsl +101 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_reduce.wgsl +84 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_split.wgsl +619 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/gated_delta_net.wgsl +149 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/get_rows.wgsl +204 -78
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/glu.wgsl +155 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/im2col.wgsl +101 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_decls.tmpl +805 -526
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id.wgsl +195 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id_gather.wgsl +52 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id_vec.wgsl +154 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_reg_tile.wgsl +8 -6
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_subgroup_matrix.wgsl +5 -1
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec.wgsl +90 -413
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec_acc.tmpl +1553 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec_q_acc.tmpl +297 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/quant_inner_loops.tmpl +21 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/quantize_q8.wgsl +178 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/rms_norm_mul.wgsl +152 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/{rope.tmpl.wgsl → rope.wgsl} +71 -142
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/row_norm.wgsl +153 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/scale.wgsl +6 -4
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/set.wgsl +109 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/set_rows.wgsl +2 -3
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/set_rows_quant.wgsl +224 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/{soft_max.tmpl.wgsl → soft_max.wgsl} +106 -206
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/solve_tri.wgsl +121 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/ssm_conv.wgsl +65 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/ssm_scan.wgsl +193 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/unary.wgsl +68 -48
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/upscale.wgsl +240 -0
- data/ext/sources/ggml/src/ggml-zdnn/ggml-zdnn.cpp +18 -14
- data/ext/sources/ggml/src/ggml-zendnn/CMakeLists.txt +1 -1
- data/ext/sources/ggml/src/ggml-zendnn/ggml-zendnn.cpp +244 -10
- data/ext/sources/ggml/src/ggml.c +146 -42
- data/ext/sources/ggml/src/gguf.cpp +173 -28
- data/ext/sources/include/parakeet.h +342 -0
- data/ext/sources/include/whisper.h +31 -0
- data/ext/sources/media/matmul.png +0 -0
- data/ext/sources/src/CMakeLists.txt +23 -0
- data/ext/sources/src/parakeet-arch.h +188 -0
- data/ext/sources/src/parakeet.cpp +3838 -0
- data/ext/sources/src/whisper.cpp +220 -26
- data/extsources.rb +26 -10
- data/lib/whisper/log_settable.rb +33 -0
- data/lib/whisper/model/uri.rb +13 -8
- data/lib/whisper/output.rb +74 -0
- data/sig/whisper.rbs +417 -62
- data/test/helper.rb +2 -0
- data/test/jfk_reader/jfk_reader.c +50 -7
- data/test/test_callback.rb +1 -0
- data/test/test_package.rb +6 -5
- data/test/test_parakeet.rb +28 -0
- data/test/test_parakeet_callback.rb +107 -0
- data/test/test_parakeet_context.rb +116 -0
- data/test/test_parakeet_context_params.rb +24 -0
- data/test/test_parakeet_model.rb +21 -0
- data/test/test_parakeet_params.rb +78 -0
- data/test/test_parakeet_segment.rb +42 -0
- data/test/test_parakeet_token.rb +73 -0
- data/test/test_params.rb +2 -0
- data/test/test_vad.rb +9 -0
- data/test/test_vad_context.rb +2 -2
- data/test/test_vad_segment.rb +1 -1
- data/test/test_whisper.rb +24 -6
- data/whispercpp.gemspec +2 -2
- metadata +263 -304
- data/ext/sources/bindings/javascript/CMakeLists.txt +0 -41
- data/ext/sources/bindings/javascript/emscripten.cpp +0 -93
- data/ext/sources/bindings/javascript/libwhisper.worker.js +0 -1
- data/ext/sources/bindings/javascript/package.json +0 -26
- data/ext/sources/bindings/javascript/whisper.js +0 -19
- data/ext/sources/examples/addon.node/CMakeLists.txt +0 -31
- data/ext/sources/examples/addon.node/__test__/whisper.spec.js +0 -133
- data/ext/sources/examples/addon.node/addon.cpp +0 -557
- data/ext/sources/examples/addon.node/index.js +0 -59
- data/ext/sources/examples/addon.node/package.json +0 -16
- data/ext/sources/examples/addon.node/vad-example.js +0 -132
- data/ext/sources/examples/bench.wasm/CMakeLists.txt +0 -49
- data/ext/sources/examples/bench.wasm/emscripten.cpp +0 -87
- data/ext/sources/examples/bench.wasm/index-tmpl.html +0 -285
- data/ext/sources/examples/coi-serviceworker.js +0 -146
- data/ext/sources/examples/command/CMakeLists.txt +0 -10
- data/ext/sources/examples/command/command.cpp +0 -802
- data/ext/sources/examples/command/commands.txt +0 -9
- data/ext/sources/examples/command.wasm/CMakeLists.txt +0 -50
- data/ext/sources/examples/command.wasm/emscripten.cpp +0 -327
- data/ext/sources/examples/command.wasm/index-tmpl.html +0 -415
- data/ext/sources/examples/generate-karaoke.sh +0 -57
- data/ext/sources/examples/helpers.js +0 -191
- data/ext/sources/examples/livestream.sh +0 -112
- data/ext/sources/examples/lsp/CMakeLists.txt +0 -10
- data/ext/sources/examples/lsp/lsp.cpp +0 -471
- data/ext/sources/examples/lsp/whisper.vim +0 -362
- data/ext/sources/examples/python/test_whisper_processor.py +0 -7
- data/ext/sources/examples/python/whisper_processor.py +0 -54
- data/ext/sources/examples/server/bench.js +0 -29
- data/ext/sources/examples/server.py +0 -120
- data/ext/sources/examples/stream/CMakeLists.txt +0 -10
- data/ext/sources/examples/stream/stream.cpp +0 -437
- data/ext/sources/examples/stream.wasm/CMakeLists.txt +0 -49
- data/ext/sources/examples/stream.wasm/emscripten.cpp +0 -216
- data/ext/sources/examples/stream.wasm/index-tmpl.html +0 -491
- data/ext/sources/examples/sycl/CMakeLists.txt +0 -9
- data/ext/sources/examples/sycl/build.sh +0 -22
- data/ext/sources/examples/sycl/ls-sycl-device.cpp +0 -11
- data/ext/sources/examples/sycl/run-whisper.sh +0 -17
- data/ext/sources/examples/talk-llama/CMakeLists.txt +0 -48
- data/ext/sources/examples/talk-llama/eleven-labs.py +0 -80
- data/ext/sources/examples/talk-llama/llama-adapter.cpp +0 -488
- data/ext/sources/examples/talk-llama/llama-adapter.h +0 -89
- data/ext/sources/examples/talk-llama/llama-arch.cpp +0 -2877
- data/ext/sources/examples/talk-llama/llama-arch.h +0 -628
- data/ext/sources/examples/talk-llama/llama-batch.cpp +0 -919
- data/ext/sources/examples/talk-llama/llama-batch.h +0 -173
- data/ext/sources/examples/talk-llama/llama-chat.cpp +0 -896
- data/ext/sources/examples/talk-llama/llama-chat.h +0 -71
- data/ext/sources/examples/talk-llama/llama-context.cpp +0 -3633
- data/ext/sources/examples/talk-llama/llama-context.h +0 -359
- data/ext/sources/examples/talk-llama/llama-cparams.cpp +0 -5
- data/ext/sources/examples/talk-llama/llama-cparams.h +0 -47
- data/ext/sources/examples/talk-llama/llama-ext.h +0 -12
- data/ext/sources/examples/talk-llama/llama-grammar.cpp +0 -1464
- data/ext/sources/examples/talk-llama/llama-grammar.h +0 -194
- data/ext/sources/examples/talk-llama/llama-graph.cpp +0 -2735
- data/ext/sources/examples/talk-llama/llama-graph.h +0 -1031
- data/ext/sources/examples/talk-llama/llama-hparams.cpp +0 -258
- data/ext/sources/examples/talk-llama/llama-hparams.h +0 -353
- data/ext/sources/examples/talk-llama/llama-impl.cpp +0 -171
- data/ext/sources/examples/talk-llama/llama-impl.h +0 -75
- data/ext/sources/examples/talk-llama/llama-io.cpp +0 -15
- data/ext/sources/examples/talk-llama/llama-io.h +0 -35
- data/ext/sources/examples/talk-llama/llama-kv-cache-iswa.cpp +0 -330
- data/ext/sources/examples/talk-llama/llama-kv-cache-iswa.h +0 -137
- data/ext/sources/examples/talk-llama/llama-kv-cache.cpp +0 -2285
- data/ext/sources/examples/talk-llama/llama-kv-cache.h +0 -389
- data/ext/sources/examples/talk-llama/llama-kv-cells.h +0 -533
- data/ext/sources/examples/talk-llama/llama-memory-hybrid-iswa.cpp +0 -275
- data/ext/sources/examples/talk-llama/llama-memory-hybrid-iswa.h +0 -140
- data/ext/sources/examples/talk-llama/llama-memory-hybrid.cpp +0 -268
- data/ext/sources/examples/talk-llama/llama-memory-hybrid.h +0 -139
- data/ext/sources/examples/talk-llama/llama-memory-recurrent.cpp +0 -1165
- data/ext/sources/examples/talk-llama/llama-memory-recurrent.h +0 -182
- data/ext/sources/examples/talk-llama/llama-memory.cpp +0 -59
- data/ext/sources/examples/talk-llama/llama-memory.h +0 -122
- data/ext/sources/examples/talk-llama/llama-mmap.cpp +0 -752
- data/ext/sources/examples/talk-llama/llama-mmap.h +0 -73
- data/ext/sources/examples/talk-llama/llama-model-loader.cpp +0 -1655
- data/ext/sources/examples/talk-llama/llama-model-loader.h +0 -206
- data/ext/sources/examples/talk-llama/llama-model-saver.cpp +0 -299
- data/ext/sources/examples/talk-llama/llama-model-saver.h +0 -40
- data/ext/sources/examples/talk-llama/llama-model.cpp +0 -9056
- data/ext/sources/examples/talk-llama/llama-model.h +0 -597
- data/ext/sources/examples/talk-llama/llama-quant.cpp +0 -1304
- data/ext/sources/examples/talk-llama/llama-quant.h +0 -1
- data/ext/sources/examples/talk-llama/llama-sampler.cpp +0 -3885
- data/ext/sources/examples/talk-llama/llama-sampler.h +0 -42
- data/ext/sources/examples/talk-llama/llama-vocab.cpp +0 -3970
- data/ext/sources/examples/talk-llama/llama-vocab.h +0 -187
- data/ext/sources/examples/talk-llama/llama.cpp +0 -1194
- data/ext/sources/examples/talk-llama/llama.h +0 -1573
- data/ext/sources/examples/talk-llama/models/afmoe.cpp +0 -190
- data/ext/sources/examples/talk-llama/models/apertus.cpp +0 -125
- data/ext/sources/examples/talk-llama/models/arcee.cpp +0 -135
- data/ext/sources/examples/talk-llama/models/arctic.cpp +0 -137
- data/ext/sources/examples/talk-llama/models/arwkv7.cpp +0 -86
- data/ext/sources/examples/talk-llama/models/baichuan.cpp +0 -123
- data/ext/sources/examples/talk-llama/models/bailingmoe.cpp +0 -143
- data/ext/sources/examples/talk-llama/models/bailingmoe2.cpp +0 -133
- data/ext/sources/examples/talk-llama/models/bert.cpp +0 -184
- data/ext/sources/examples/talk-llama/models/bitnet.cpp +0 -145
- data/ext/sources/examples/talk-llama/models/bloom.cpp +0 -101
- data/ext/sources/examples/talk-llama/models/chameleon.cpp +0 -178
- data/ext/sources/examples/talk-llama/models/chatglm.cpp +0 -132
- data/ext/sources/examples/talk-llama/models/codeshell.cpp +0 -111
- data/ext/sources/examples/talk-llama/models/cogvlm.cpp +0 -102
- data/ext/sources/examples/talk-llama/models/cohere2-iswa.cpp +0 -134
- data/ext/sources/examples/talk-llama/models/command-r.cpp +0 -122
- data/ext/sources/examples/talk-llama/models/dbrx.cpp +0 -122
- data/ext/sources/examples/talk-llama/models/deci.cpp +0 -135
- data/ext/sources/examples/talk-llama/models/deepseek.cpp +0 -142
- data/ext/sources/examples/talk-llama/models/deepseek2.cpp +0 -262
- data/ext/sources/examples/talk-llama/models/delta-net-base.cpp +0 -445
- data/ext/sources/examples/talk-llama/models/dots1.cpp +0 -132
- data/ext/sources/examples/talk-llama/models/dream.cpp +0 -105
- data/ext/sources/examples/talk-llama/models/ernie4-5-moe.cpp +0 -148
- data/ext/sources/examples/talk-llama/models/ernie4-5.cpp +0 -110
- data/ext/sources/examples/talk-llama/models/eurobert.cpp +0 -97
- data/ext/sources/examples/talk-llama/models/exaone-moe.cpp +0 -145
- data/ext/sources/examples/talk-llama/models/exaone.cpp +0 -114
- data/ext/sources/examples/talk-llama/models/exaone4.cpp +0 -123
- data/ext/sources/examples/talk-llama/models/falcon-h1.cpp +0 -111
- data/ext/sources/examples/talk-llama/models/falcon.cpp +0 -120
- data/ext/sources/examples/talk-llama/models/gemma-embedding.cpp +0 -116
- data/ext/sources/examples/talk-llama/models/gemma.cpp +0 -112
- data/ext/sources/examples/talk-llama/models/gemma2-iswa.cpp +0 -128
- data/ext/sources/examples/talk-llama/models/gemma3.cpp +0 -155
- data/ext/sources/examples/talk-llama/models/gemma3n-iswa.cpp +0 -384
- data/ext/sources/examples/talk-llama/models/glm4-moe.cpp +0 -170
- data/ext/sources/examples/talk-llama/models/glm4.cpp +0 -157
- data/ext/sources/examples/talk-llama/models/gpt2.cpp +0 -105
- data/ext/sources/examples/talk-llama/models/gptneox.cpp +0 -144
- data/ext/sources/examples/talk-llama/models/granite-hybrid.cpp +0 -195
- data/ext/sources/examples/talk-llama/models/granite.cpp +0 -210
- data/ext/sources/examples/talk-llama/models/grok.cpp +0 -159
- data/ext/sources/examples/talk-llama/models/grovemoe.cpp +0 -139
- data/ext/sources/examples/talk-llama/models/hunyuan-dense.cpp +0 -132
- data/ext/sources/examples/talk-llama/models/hunyuan-moe.cpp +0 -153
- data/ext/sources/examples/talk-llama/models/internlm2.cpp +0 -120
- data/ext/sources/examples/talk-llama/models/jais.cpp +0 -86
- data/ext/sources/examples/talk-llama/models/jais2.cpp +0 -123
- data/ext/sources/examples/talk-llama/models/jamba.cpp +0 -106
- data/ext/sources/examples/talk-llama/models/kimi-linear.cpp +0 -381
- data/ext/sources/examples/talk-llama/models/lfm2.cpp +0 -196
- data/ext/sources/examples/talk-llama/models/llada-moe.cpp +0 -122
- data/ext/sources/examples/talk-llama/models/llada.cpp +0 -99
- data/ext/sources/examples/talk-llama/models/llama-iswa.cpp +0 -178
- data/ext/sources/examples/talk-llama/models/llama.cpp +0 -175
- data/ext/sources/examples/talk-llama/models/maincoder.cpp +0 -117
- data/ext/sources/examples/talk-llama/models/mamba-base.cpp +0 -289
- data/ext/sources/examples/talk-llama/models/mamba.cpp +0 -54
- data/ext/sources/examples/talk-llama/models/mimo2-iswa.cpp +0 -129
- data/ext/sources/examples/talk-llama/models/minicpm3.cpp +0 -200
- data/ext/sources/examples/talk-llama/models/minimax-m2.cpp +0 -123
- data/ext/sources/examples/talk-llama/models/mistral3.cpp +0 -160
- data/ext/sources/examples/talk-llama/models/models.h +0 -704
- data/ext/sources/examples/talk-llama/models/modern-bert.cpp +0 -109
- data/ext/sources/examples/talk-llama/models/mpt.cpp +0 -126
- data/ext/sources/examples/talk-llama/models/nemotron-h.cpp +0 -162
- data/ext/sources/examples/talk-llama/models/nemotron.cpp +0 -122
- data/ext/sources/examples/talk-llama/models/neo-bert.cpp +0 -104
- data/ext/sources/examples/talk-llama/models/olmo.cpp +0 -121
- data/ext/sources/examples/talk-llama/models/olmo2.cpp +0 -150
- data/ext/sources/examples/talk-llama/models/olmoe.cpp +0 -124
- data/ext/sources/examples/talk-llama/models/openai-moe-iswa.cpp +0 -127
- data/ext/sources/examples/talk-llama/models/openelm.cpp +0 -124
- data/ext/sources/examples/talk-llama/models/orion.cpp +0 -123
- data/ext/sources/examples/talk-llama/models/paddleocr.cpp +0 -122
- data/ext/sources/examples/talk-llama/models/pangu-embedded.cpp +0 -121
- data/ext/sources/examples/talk-llama/models/phi2.cpp +0 -121
- data/ext/sources/examples/talk-llama/models/phi3.cpp +0 -152
- data/ext/sources/examples/talk-llama/models/plamo.cpp +0 -110
- data/ext/sources/examples/talk-llama/models/plamo2.cpp +0 -320
- data/ext/sources/examples/talk-llama/models/plamo3.cpp +0 -128
- data/ext/sources/examples/talk-llama/models/plm.cpp +0 -169
- data/ext/sources/examples/talk-llama/models/qwen.cpp +0 -108
- data/ext/sources/examples/talk-llama/models/qwen2.cpp +0 -126
- data/ext/sources/examples/talk-llama/models/qwen2moe.cpp +0 -151
- data/ext/sources/examples/talk-llama/models/qwen2vl.cpp +0 -117
- data/ext/sources/examples/talk-llama/models/qwen3.cpp +0 -120
- data/ext/sources/examples/talk-llama/models/qwen35.cpp +0 -381
- data/ext/sources/examples/talk-llama/models/qwen35moe.cpp +0 -422
- data/ext/sources/examples/talk-llama/models/qwen3moe.cpp +0 -131
- data/ext/sources/examples/talk-llama/models/qwen3next.cpp +0 -525
- data/ext/sources/examples/talk-llama/models/qwen3vl-moe.cpp +0 -140
- data/ext/sources/examples/talk-llama/models/qwen3vl.cpp +0 -132
- data/ext/sources/examples/talk-llama/models/refact.cpp +0 -94
- data/ext/sources/examples/talk-llama/models/rnd1.cpp +0 -126
- data/ext/sources/examples/talk-llama/models/rwkv6-base.cpp +0 -164
- data/ext/sources/examples/talk-llama/models/rwkv6.cpp +0 -94
- data/ext/sources/examples/talk-llama/models/rwkv6qwen2.cpp +0 -86
- data/ext/sources/examples/talk-llama/models/rwkv7-base.cpp +0 -137
- data/ext/sources/examples/talk-llama/models/rwkv7.cpp +0 -90
- data/ext/sources/examples/talk-llama/models/seed-oss.cpp +0 -124
- data/ext/sources/examples/talk-llama/models/smallthinker.cpp +0 -126
- data/ext/sources/examples/talk-llama/models/smollm3.cpp +0 -128
- data/ext/sources/examples/talk-llama/models/stablelm.cpp +0 -146
- data/ext/sources/examples/talk-llama/models/starcoder.cpp +0 -100
- data/ext/sources/examples/talk-llama/models/starcoder2.cpp +0 -121
- data/ext/sources/examples/talk-llama/models/step35-iswa.cpp +0 -165
- data/ext/sources/examples/talk-llama/models/t5-dec.cpp +0 -166
- data/ext/sources/examples/talk-llama/models/t5-enc.cpp +0 -96
- data/ext/sources/examples/talk-llama/models/wavtokenizer-dec.cpp +0 -149
- data/ext/sources/examples/talk-llama/models/xverse.cpp +0 -108
- data/ext/sources/examples/talk-llama/prompts/talk-alpaca.txt +0 -23
- data/ext/sources/examples/talk-llama/speak +0 -40
- data/ext/sources/examples/talk-llama/speak.bat +0 -1
- data/ext/sources/examples/talk-llama/speak.ps1 +0 -14
- data/ext/sources/examples/talk-llama/talk-llama.cpp +0 -813
- data/ext/sources/examples/talk-llama/unicode-data.cpp +0 -7034
- data/ext/sources/examples/talk-llama/unicode-data.h +0 -20
- data/ext/sources/examples/talk-llama/unicode.cpp +0 -1103
- data/ext/sources/examples/talk-llama/unicode.h +0 -111
- data/ext/sources/examples/wchess/CMakeLists.txt +0 -10
- data/ext/sources/examples/wchess/libwchess/CMakeLists.txt +0 -19
- data/ext/sources/examples/wchess/libwchess/Chessboard.cpp +0 -803
- data/ext/sources/examples/wchess/libwchess/Chessboard.h +0 -33
- data/ext/sources/examples/wchess/libwchess/WChess.cpp +0 -193
- data/ext/sources/examples/wchess/libwchess/WChess.h +0 -63
- data/ext/sources/examples/wchess/libwchess/test-chessboard.cpp +0 -117
- data/ext/sources/examples/wchess/wchess.cmd/CMakeLists.txt +0 -8
- data/ext/sources/examples/wchess/wchess.cmd/wchess.cmd.cpp +0 -253
- data/ext/sources/examples/whisper.wasm/CMakeLists.txt +0 -50
- data/ext/sources/examples/whisper.wasm/emscripten.cpp +0 -118
- data/ext/sources/examples/whisper.wasm/index-tmpl.html +0 -659
- data/ext/sources/ggml/src/ggml-cuda/template-instances/generate_cu_files.py +0 -99
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-msg.h +0 -155
- data/ext/sources/ggml/src/ggml-hexagon/op-desc.h +0 -153
- data/ext/sources/ggml/src/ggml-opencl/kernels/embed_kernel.py +0 -26
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/eliminate_zp.cpp +0 -123
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/eliminate_zp.h +0 -17
- data/ext/sources/ggml/src/ggml-virtgpu/regenerate_remoting.py +0 -333
- 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 -21
- 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/rte.glsl +0 -5
- 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
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/embed_wgsl.py +0 -182
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/glu.tmpl.wgsl +0 -323
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat.wgsl +0 -718
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/rms_norm.wgsl +0 -123
- data/ext/sources/tests/CMakeLists.txt +0 -112
- data/ext/sources/tests/earnings21/eval.mk +0 -58
- data/ext/sources/tests/earnings21/eval.py +0 -68
- data/ext/sources/tests/earnings21/normalizers/__init__.py +0 -2
- data/ext/sources/tests/earnings21/normalizers/basic.py +0 -80
- data/ext/sources/tests/earnings21/normalizers/english.json +0 -1741
- data/ext/sources/tests/earnings21/normalizers/english.py +0 -550
- data/ext/sources/tests/earnings21/requirements.txt +0 -6
- data/ext/sources/tests/en-0-ref.txt +0 -1
- data/ext/sources/tests/en-1-ref.txt +0 -1
- data/ext/sources/tests/en-2-ref.txt +0 -1
- data/ext/sources/tests/es-0-ref.txt +0 -1
- data/ext/sources/tests/librispeech/eval.mk +0 -39
- data/ext/sources/tests/librispeech/eval.py +0 -47
- data/ext/sources/tests/librispeech/normalizers/__init__.py +0 -2
- data/ext/sources/tests/librispeech/normalizers/basic.py +0 -80
- data/ext/sources/tests/librispeech/normalizers/english.json +0 -1741
- data/ext/sources/tests/librispeech/normalizers/english.py +0 -550
- data/ext/sources/tests/librispeech/requirements.txt +0 -6
- data/ext/sources/tests/run-tests.sh +0 -130
- data/ext/sources/tests/test-c.c +0 -3
- data/ext/sources/tests/test-vad-full.cpp +0 -56
- data/ext/sources/tests/test-vad.cpp +0 -83
- data/ext/sources/tests/test-whisper.js +0 -58
- data/lib/whisper/context.rb +0 -15
- data/lib/whisper/segment.rb +0 -58
|
@@ -42,6 +42,8 @@ typedef matrix<bfloat, 4, 4> bfloat4x4;
|
|
|
42
42
|
typedef matrix<bfloat, 2, 4> bfloat2x4;
|
|
43
43
|
#endif
|
|
44
44
|
|
|
45
|
+
#define QK_NL 16
|
|
46
|
+
|
|
45
47
|
constexpr constant static float kvalues_iq4nl_f[16] = {
|
|
46
48
|
-127.f, -104.f, -83.f, -65.f, -49.f, -35.f, -22.f, -10.f, 1.f, 13.f, 25.f, 38.f, 53.f, 69.f, 89.f, 113.f
|
|
47
49
|
};
|
|
@@ -118,6 +120,56 @@ void dequantize_bf16_t4(device const bfloat4 * src, short il, thread type4 & reg
|
|
|
118
120
|
}
|
|
119
121
|
#endif
|
|
120
122
|
|
|
123
|
+
template <typename type4x4>
|
|
124
|
+
void dequantize_q1_0(device const block_q1_0 * xb, short il, thread type4x4 & reg) {
|
|
125
|
+
device const uint8_t * qs = xb->qs;
|
|
126
|
+
const float d = xb->d;
|
|
127
|
+
const float neg_d = -d;
|
|
128
|
+
|
|
129
|
+
const int byte_offset = il * 2; // il*16 bits = il*2 bytes
|
|
130
|
+
const uint8_t b0 = qs[byte_offset];
|
|
131
|
+
const uint8_t b1 = qs[byte_offset + 1];
|
|
132
|
+
|
|
133
|
+
float4x4 reg_f;
|
|
134
|
+
|
|
135
|
+
reg_f[0][0] = select(neg_d, d, bool(b0 & 0x01));
|
|
136
|
+
reg_f[0][1] = select(neg_d, d, bool(b0 & 0x02));
|
|
137
|
+
reg_f[0][2] = select(neg_d, d, bool(b0 & 0x04));
|
|
138
|
+
reg_f[0][3] = select(neg_d, d, bool(b0 & 0x08));
|
|
139
|
+
reg_f[1][0] = select(neg_d, d, bool(b0 & 0x10));
|
|
140
|
+
reg_f[1][1] = select(neg_d, d, bool(b0 & 0x20));
|
|
141
|
+
reg_f[1][2] = select(neg_d, d, bool(b0 & 0x40));
|
|
142
|
+
reg_f[1][3] = select(neg_d, d, bool(b0 & 0x80));
|
|
143
|
+
|
|
144
|
+
reg_f[2][0] = select(neg_d, d, bool(b1 & 0x01));
|
|
145
|
+
reg_f[2][1] = select(neg_d, d, bool(b1 & 0x02));
|
|
146
|
+
reg_f[2][2] = select(neg_d, d, bool(b1 & 0x04));
|
|
147
|
+
reg_f[2][3] = select(neg_d, d, bool(b1 & 0x08));
|
|
148
|
+
reg_f[3][0] = select(neg_d, d, bool(b1 & 0x10));
|
|
149
|
+
reg_f[3][1] = select(neg_d, d, bool(b1 & 0x20));
|
|
150
|
+
reg_f[3][2] = select(neg_d, d, bool(b1 & 0x40));
|
|
151
|
+
reg_f[3][3] = select(neg_d, d, bool(b1 & 0x80));
|
|
152
|
+
|
|
153
|
+
reg = (type4x4) reg_f;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
template <typename type4>
|
|
157
|
+
void dequantize_q1_0_t4(device const block_q1_0 * xb, short il, thread type4 & reg) {
|
|
158
|
+
const float d = xb->d;
|
|
159
|
+
const float neg_d = -d;
|
|
160
|
+
const int base = il * 4;
|
|
161
|
+
const uint8_t byte = xb->qs[base / 8];
|
|
162
|
+
const int s = base % 8;
|
|
163
|
+
|
|
164
|
+
float4 reg_f;
|
|
165
|
+
reg_f[0] = select(neg_d, d, bool((byte >> (s )) & 1));
|
|
166
|
+
reg_f[1] = select(neg_d, d, bool((byte >> (s + 1)) & 1));
|
|
167
|
+
reg_f[2] = select(neg_d, d, bool((byte >> (s + 2)) & 1));
|
|
168
|
+
reg_f[3] = select(neg_d, d, bool((byte >> (s + 3)) & 1));
|
|
169
|
+
|
|
170
|
+
reg = (type4) reg_f;
|
|
171
|
+
}
|
|
172
|
+
|
|
121
173
|
template <typename type4x4>
|
|
122
174
|
void dequantize_q4_0(device const block_q4_0 * xb, short il, thread type4x4 & reg) {
|
|
123
175
|
device const uint16_t * qs = ((device const uint16_t *)xb + 1);
|
|
@@ -152,6 +204,23 @@ void dequantize_q4_0_t4(device const block_q4_0 * xb, short il, thread type4 & r
|
|
|
152
204
|
}
|
|
153
205
|
}
|
|
154
206
|
|
|
207
|
+
void quantize_q1_0(device const float * src, device block_q1_0 & dst) {
|
|
208
|
+
float sum_abs = 0.0f;
|
|
209
|
+
for (int j = 0; j < QK1_0; j++) {
|
|
210
|
+
sum_abs += fabs(src[j]);
|
|
211
|
+
}
|
|
212
|
+
dst.d = sum_abs / QK1_0;
|
|
213
|
+
|
|
214
|
+
for (int j = 0; j < QK1_0 / 8; j++) {
|
|
215
|
+
dst.qs[j] = 0;
|
|
216
|
+
}
|
|
217
|
+
for (int j = 0; j < QK1_0; j++) {
|
|
218
|
+
if (src[j] >= 0.0f) {
|
|
219
|
+
dst.qs[j / 8] |= (1 << (j % 8));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
155
224
|
void quantize_q4_0(device const float * src, device block_q4_0 & dst) {
|
|
156
225
|
#pragma METAL fp math_mode(safe)
|
|
157
226
|
float amax = 0.0f; // absolute max
|
|
@@ -1094,6 +1163,31 @@ kernel void kernel_unary_impl(
|
|
|
1094
1163
|
// TODO: precise implementation
|
|
1095
1164
|
dst_ptr[i0] = (T) (exp(x) - 1);
|
|
1096
1165
|
}
|
|
1166
|
+
|
|
1167
|
+
if (FC_OP == OP_UNARY_NUM_FLOOR) {
|
|
1168
|
+
dst_ptr[i0] = (T) floor(x);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
if (FC_OP == OP_UNARY_NUM_CEIL) {
|
|
1172
|
+
dst_ptr[i0] = (T) ceil(x);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
if (FC_OP == OP_UNARY_NUM_ROUND) {
|
|
1176
|
+
dst_ptr[i0] = (T) round(x);
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
if (FC_OP == OP_UNARY_NUM_TRUNC) {
|
|
1180
|
+
dst_ptr[i0] = (T) trunc(x);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
if (FC_OP == OP_UNARY_NUM_XIELU) {
|
|
1184
|
+
const TC xi = x;
|
|
1185
|
+
const TC gate = TC(xi > TC(0.0f));
|
|
1186
|
+
const TC clamped = fmin(xi, TC(args.val));
|
|
1187
|
+
const TC y_pos = TC(args.scale) * xi * xi + TC(args.bias) * xi;
|
|
1188
|
+
const TC y_neg = (exp(clamped) - TC(1.0f) - xi) * TC(args.slope) + TC(args.bias) * xi;
|
|
1189
|
+
dst_ptr[i0] = (T) (gate * y_pos + (TC(1.0f) - gate) * y_neg);
|
|
1190
|
+
}
|
|
1097
1191
|
}
|
|
1098
1192
|
|
|
1099
1193
|
#undef FC_OP
|
|
@@ -1326,10 +1420,14 @@ typedef decltype(kernel_repeat<float>) kernel_repeat_t;
|
|
|
1326
1420
|
|
|
1327
1421
|
template [[host_name("kernel_repeat_f32")]] kernel kernel_repeat_t kernel_repeat<float>;
|
|
1328
1422
|
template [[host_name("kernel_repeat_f16")]] kernel kernel_repeat_t kernel_repeat<half>;
|
|
1423
|
+
#if defined(GGML_METAL_HAS_BF16)
|
|
1424
|
+
template [[host_name("kernel_repeat_bf16")]] kernel kernel_repeat_t kernel_repeat<bfloat>;
|
|
1425
|
+
#endif
|
|
1329
1426
|
template [[host_name("kernel_repeat_i32")]] kernel kernel_repeat_t kernel_repeat<int>;
|
|
1330
1427
|
template [[host_name("kernel_repeat_i16")]] kernel kernel_repeat_t kernel_repeat<short>;
|
|
1331
1428
|
|
|
1332
|
-
|
|
1429
|
+
template<typename T>
|
|
1430
|
+
kernel void kernel_reglu(
|
|
1333
1431
|
constant ggml_metal_kargs_glu & args,
|
|
1334
1432
|
device const char * src0,
|
|
1335
1433
|
device const char * src1,
|
|
@@ -1337,19 +1435,25 @@ kernel void kernel_reglu_f32(
|
|
|
1337
1435
|
uint tgpig[[threadgroup_position_in_grid]],
|
|
1338
1436
|
uint tpitg[[thread_position_in_threadgroup]],
|
|
1339
1437
|
uint ntg[[threads_per_threadgroup]]) {
|
|
1340
|
-
device const
|
|
1341
|
-
device const
|
|
1342
|
-
device
|
|
1438
|
+
device const T * src0_row = (device const T *) ((device const char *) src0 + tgpig*args.nb01) + args.i00;
|
|
1439
|
+
device const T * src1_row = (device const T *) ((device const char *) src1 + tgpig*args.nb11) + args.i10;
|
|
1440
|
+
device T * dst_row = (device T *) ((device char *) dst + tgpig*args.nb1);
|
|
1343
1441
|
|
|
1344
1442
|
for (int i0 = tpitg; i0 < args.ne0; i0 += ntg) {
|
|
1345
1443
|
const float x0 = src0_row[i0];
|
|
1346
1444
|
const float x1 = src1_row[i0];
|
|
1347
1445
|
|
|
1348
|
-
dst_row[i0] = x0*x1*(x0 > 0.0f);
|
|
1446
|
+
dst_row[i0] = (T)(x0*x1*(x0 > 0.0f));
|
|
1349
1447
|
}
|
|
1350
1448
|
}
|
|
1351
1449
|
|
|
1352
|
-
|
|
1450
|
+
typedef decltype(kernel_reglu<float>) kernel_reglu_t;
|
|
1451
|
+
|
|
1452
|
+
template [[host_name("kernel_reglu_f32")]] kernel kernel_reglu_t kernel_reglu<float>;
|
|
1453
|
+
template [[host_name("kernel_reglu_f16")]] kernel kernel_reglu_t kernel_reglu<half>;
|
|
1454
|
+
|
|
1455
|
+
template<typename T>
|
|
1456
|
+
kernel void kernel_geglu(
|
|
1353
1457
|
constant ggml_metal_kargs_glu & args,
|
|
1354
1458
|
device const char * src0,
|
|
1355
1459
|
device const char * src1,
|
|
@@ -1357,9 +1461,9 @@ kernel void kernel_geglu_f32(
|
|
|
1357
1461
|
uint tgpig[[threadgroup_position_in_grid]],
|
|
1358
1462
|
uint tpitg[[thread_position_in_threadgroup]],
|
|
1359
1463
|
uint ntg[[threads_per_threadgroup]]) {
|
|
1360
|
-
device const
|
|
1361
|
-
device const
|
|
1362
|
-
device
|
|
1464
|
+
device const T * src0_row = (device const T *) ((device const char *) src0 + tgpig*args.nb01) + args.i00;
|
|
1465
|
+
device const T * src1_row = (device const T *) ((device const char *) src1 + tgpig*args.nb11) + args.i10;
|
|
1466
|
+
device T * dst_row = (device T *) ((device char *) dst + tgpig*args.nb1);
|
|
1363
1467
|
|
|
1364
1468
|
for (int i0 = tpitg; i0 < args.ne0; i0 += ntg) {
|
|
1365
1469
|
const float x0 = src0_row[i0];
|
|
@@ -1367,11 +1471,17 @@ kernel void kernel_geglu_f32(
|
|
|
1367
1471
|
|
|
1368
1472
|
const float gelu = 0.5f*x0*(1.0f + precise::tanh(SQRT_2_OVER_PI*x0*(1.0f + GELU_COEF_A*x0*x0)));
|
|
1369
1473
|
|
|
1370
|
-
dst_row[i0] = gelu*x1;
|
|
1474
|
+
dst_row[i0] = (T)(gelu*x1);
|
|
1371
1475
|
}
|
|
1372
1476
|
}
|
|
1373
1477
|
|
|
1374
|
-
|
|
1478
|
+
typedef decltype(kernel_geglu<float>) kernel_geglu_t;
|
|
1479
|
+
|
|
1480
|
+
template [[host_name("kernel_geglu_f32")]] kernel kernel_geglu_t kernel_geglu<float>;
|
|
1481
|
+
template [[host_name("kernel_geglu_f16")]] kernel kernel_geglu_t kernel_geglu<half>;
|
|
1482
|
+
|
|
1483
|
+
template<typename T>
|
|
1484
|
+
kernel void kernel_swiglu(
|
|
1375
1485
|
constant ggml_metal_kargs_glu & args,
|
|
1376
1486
|
device const char * src0,
|
|
1377
1487
|
device const char * src1,
|
|
@@ -1379,9 +1489,9 @@ kernel void kernel_swiglu_f32(
|
|
|
1379
1489
|
uint tgpig[[threadgroup_position_in_grid]],
|
|
1380
1490
|
uint tpitg[[thread_position_in_threadgroup]],
|
|
1381
1491
|
uint ntg[[threads_per_threadgroup]]) {
|
|
1382
|
-
device const
|
|
1383
|
-
device const
|
|
1384
|
-
device
|
|
1492
|
+
device const T * src0_row = (device const T *) ((device const char *) src0 + tgpig*args.nb01) + args.i00;
|
|
1493
|
+
device const T * src1_row = (device const T *) ((device const char *) src1 + tgpig*args.nb11) + args.i10;
|
|
1494
|
+
device T * dst_row = (device T *) ((device char *) dst + tgpig*args.nb1);
|
|
1385
1495
|
|
|
1386
1496
|
for (int i0 = tpitg; i0 < args.ne0; i0 += ntg) {
|
|
1387
1497
|
const float x0 = src0_row[i0];
|
|
@@ -1389,11 +1499,17 @@ kernel void kernel_swiglu_f32(
|
|
|
1389
1499
|
|
|
1390
1500
|
const float silu = x0 / (1.0f + exp(-x0));
|
|
1391
1501
|
|
|
1392
|
-
dst_row[i0] = silu*x1;
|
|
1502
|
+
dst_row[i0] = (T)(silu*x1);
|
|
1393
1503
|
}
|
|
1394
1504
|
}
|
|
1395
1505
|
|
|
1396
|
-
|
|
1506
|
+
typedef decltype(kernel_swiglu<float>) kernel_swiglu_t;
|
|
1507
|
+
|
|
1508
|
+
template [[host_name("kernel_swiglu_f32")]] kernel kernel_swiglu_t kernel_swiglu<float>;
|
|
1509
|
+
template [[host_name("kernel_swiglu_f16")]] kernel kernel_swiglu_t kernel_swiglu<half>;
|
|
1510
|
+
|
|
1511
|
+
template<typename T>
|
|
1512
|
+
kernel void kernel_swiglu_oai(
|
|
1397
1513
|
constant ggml_metal_kargs_glu & args,
|
|
1398
1514
|
device const char * src0,
|
|
1399
1515
|
device const char * src1,
|
|
@@ -1401,9 +1517,9 @@ kernel void kernel_swiglu_oai_f32(
|
|
|
1401
1517
|
uint tgpig[[threadgroup_position_in_grid]],
|
|
1402
1518
|
uint tpitg[[thread_position_in_threadgroup]],
|
|
1403
1519
|
uint ntg[[threads_per_threadgroup]]) {
|
|
1404
|
-
device const
|
|
1405
|
-
device const
|
|
1406
|
-
device
|
|
1520
|
+
device const T * src0_row = (device const T *) ((device const char *) src0 + tgpig*args.nb01) + args.i00;
|
|
1521
|
+
device const T * src1_row = (device const T *) ((device const char *) src1 + tgpig*args.nb11) + args.i10;
|
|
1522
|
+
device T * dst_row = (device T *) ((device char *) dst + tgpig*args.nb1);
|
|
1407
1523
|
|
|
1408
1524
|
for (int i0 = tpitg; i0 < args.ne0; i0 += ntg) {
|
|
1409
1525
|
float x0 = src0_row[i0];
|
|
@@ -1415,11 +1531,17 @@ kernel void kernel_swiglu_oai_f32(
|
|
|
1415
1531
|
float out_glu = x0 / (1.0f + exp(-x0 * args.alpha));
|
|
1416
1532
|
out_glu = out_glu * (1.0f + x1);
|
|
1417
1533
|
|
|
1418
|
-
dst_row[i0] = out_glu;
|
|
1534
|
+
dst_row[i0] = (T)out_glu;
|
|
1419
1535
|
}
|
|
1420
1536
|
}
|
|
1421
1537
|
|
|
1422
|
-
|
|
1538
|
+
typedef decltype(kernel_swiglu_oai<float>) kernel_swiglu_oai_t;
|
|
1539
|
+
|
|
1540
|
+
template [[host_name("kernel_swiglu_oai_f32")]] kernel kernel_swiglu_oai_t kernel_swiglu_oai<float>;
|
|
1541
|
+
template [[host_name("kernel_swiglu_oai_f16")]] kernel kernel_swiglu_oai_t kernel_swiglu_oai<half>;
|
|
1542
|
+
|
|
1543
|
+
template<typename T>
|
|
1544
|
+
kernel void kernel_geglu_erf(
|
|
1423
1545
|
constant ggml_metal_kargs_glu & args,
|
|
1424
1546
|
device const char * src0,
|
|
1425
1547
|
device const char * src1,
|
|
@@ -1427,9 +1549,9 @@ kernel void kernel_geglu_erf_f32(
|
|
|
1427
1549
|
uint tgpig[[threadgroup_position_in_grid]],
|
|
1428
1550
|
uint tpitg[[thread_position_in_threadgroup]],
|
|
1429
1551
|
uint ntg[[threads_per_threadgroup]]) {
|
|
1430
|
-
device const
|
|
1431
|
-
device const
|
|
1432
|
-
device
|
|
1552
|
+
device const T * src0_row = (device const T *) ((device const char *) src0 + tgpig*args.nb01) + args.i00;
|
|
1553
|
+
device const T * src1_row = (device const T *) ((device const char *) src1 + tgpig*args.nb11) + args.i10;
|
|
1554
|
+
device T * dst_row = (device T *) ((device char *) dst + tgpig*args.nb1);
|
|
1433
1555
|
|
|
1434
1556
|
for (int i0 = tpitg; i0 < args.ne0; i0 += ntg) {
|
|
1435
1557
|
const float x0 = src0_row[i0];
|
|
@@ -1437,11 +1559,17 @@ kernel void kernel_geglu_erf_f32(
|
|
|
1437
1559
|
|
|
1438
1560
|
const float gelu_erf = 0.5f*x0*(1.0f+erf_approx<float>(x0*SQRT_2_INV));
|
|
1439
1561
|
|
|
1440
|
-
dst_row[i0] = gelu_erf*x1;
|
|
1562
|
+
dst_row[i0] = (T)(gelu_erf*x1);
|
|
1441
1563
|
}
|
|
1442
1564
|
}
|
|
1443
1565
|
|
|
1444
|
-
|
|
1566
|
+
typedef decltype(kernel_geglu_erf<float>) kernel_geglu_erf_t;
|
|
1567
|
+
|
|
1568
|
+
template [[host_name("kernel_geglu_erf_f32")]] kernel kernel_geglu_erf_t kernel_geglu_erf<float>;
|
|
1569
|
+
template [[host_name("kernel_geglu_erf_f16")]] kernel kernel_geglu_erf_t kernel_geglu_erf<half>;
|
|
1570
|
+
|
|
1571
|
+
template<typename T>
|
|
1572
|
+
kernel void kernel_geglu_quick(
|
|
1445
1573
|
constant ggml_metal_kargs_glu & args,
|
|
1446
1574
|
device const char * src0,
|
|
1447
1575
|
device const char * src1,
|
|
@@ -1449,9 +1577,9 @@ kernel void kernel_geglu_quick_f32(
|
|
|
1449
1577
|
uint tgpig[[threadgroup_position_in_grid]],
|
|
1450
1578
|
uint tpitg[[thread_position_in_threadgroup]],
|
|
1451
1579
|
uint ntg[[threads_per_threadgroup]]) {
|
|
1452
|
-
device const
|
|
1453
|
-
device const
|
|
1454
|
-
device
|
|
1580
|
+
device const T * src0_row = (device const T *) ((device const char *) src0 + tgpig*args.nb01) + args.i00;
|
|
1581
|
+
device const T * src1_row = (device const T *) ((device const char *) src1 + tgpig*args.nb11) + args.i10;
|
|
1582
|
+
device T * dst_row = (device T *) ((device char *) dst + tgpig*args.nb1);
|
|
1455
1583
|
|
|
1456
1584
|
for (int i0 = tpitg; i0 < args.ne0; i0 += ntg) {
|
|
1457
1585
|
const float x0 = src0_row[i0];
|
|
@@ -1459,10 +1587,15 @@ kernel void kernel_geglu_quick_f32(
|
|
|
1459
1587
|
|
|
1460
1588
|
const float gelu_quick = x0*(1.0f/(1.0f+exp(GELU_QUICK_COEF*x0)));
|
|
1461
1589
|
|
|
1462
|
-
dst_row[i0] = gelu_quick*x1;
|
|
1590
|
+
dst_row[i0] = (T)(gelu_quick*x1);
|
|
1463
1591
|
}
|
|
1464
1592
|
}
|
|
1465
1593
|
|
|
1594
|
+
typedef decltype(kernel_geglu_quick<float>) kernel_geglu_quick_t;
|
|
1595
|
+
|
|
1596
|
+
template [[host_name("kernel_geglu_quick_f32")]] kernel kernel_geglu_quick_t kernel_geglu_quick<float>;
|
|
1597
|
+
template [[host_name("kernel_geglu_quick_f16")]] kernel kernel_geglu_quick_t kernel_geglu_quick<half>;
|
|
1598
|
+
|
|
1466
1599
|
kernel void kernel_op_sum_f32(
|
|
1467
1600
|
constant ggml_metal_kargs_sum & args,
|
|
1468
1601
|
device const float * src0,
|
|
@@ -2439,6 +2572,7 @@ kernel void kernel_rwkv_wkv7_f32(
|
|
|
2439
2572
|
|
|
2440
2573
|
constant short FC_gated_delta_net_ne20 [[function_constant(FC_GATED_DELTA_NET + 0)]];
|
|
2441
2574
|
constant short FC_gated_delta_net_ne30 [[function_constant(FC_GATED_DELTA_NET + 1)]];
|
|
2575
|
+
constant short FC_gated_delta_net_K [[function_constant(FC_GATED_DELTA_NET + 2)]];
|
|
2442
2576
|
|
|
2443
2577
|
#if 1
|
|
2444
2578
|
template<short NSG>
|
|
@@ -2456,21 +2590,24 @@ kernel void kernel_gated_delta_net_impl(
|
|
|
2456
2590
|
uint3 ntg[[threads_per_threadgroup]]) {
|
|
2457
2591
|
#define S_v FC_gated_delta_net_ne20
|
|
2458
2592
|
#define G FC_gated_delta_net_ne30
|
|
2593
|
+
#define K FC_gated_delta_net_K
|
|
2459
2594
|
|
|
2460
2595
|
const uint tx = tpitg.x;
|
|
2461
2596
|
const uint ty = tpitg.y;
|
|
2462
2597
|
|
|
2463
|
-
const uint i23 = tgpig.z; // B
|
|
2464
|
-
const uint i21 = tgpig.y; // H
|
|
2465
|
-
const uint i20 = tgpig.x*NSG + ty;
|
|
2598
|
+
const uint i23 = tgpig.z; // B (n_seqs)
|
|
2599
|
+
const uint i21 = tgpig.y; // H (head)
|
|
2600
|
+
const uint i20 = tgpig.x*NSG + ty; // row within S_v
|
|
2466
2601
|
|
|
2467
2602
|
const uint i01 = i21 % args.ne01;
|
|
2468
2603
|
const uint i11 = i21 % args.ne11;
|
|
2469
2604
|
|
|
2470
2605
|
const float scale = 1.0f / sqrt((float)S_v);
|
|
2471
2606
|
|
|
2607
|
+
// input state layout [S_v, S_v, H, n_seqs] (s0 only): per-seq stride is H*D.
|
|
2472
2608
|
// state is stored transposed: M[i20][is] = S[is][i20], so row i20 is contiguous
|
|
2473
|
-
|
|
2609
|
+
const uint state_in_base = (i23*args.ne21 + i21)*S_v*S_v + i20*S_v;
|
|
2610
|
+
device const float * s_ptr = (device const float *) (s) + state_in_base;
|
|
2474
2611
|
|
|
2475
2612
|
float ls[NSG];
|
|
2476
2613
|
|
|
@@ -2488,6 +2625,16 @@ kernel void kernel_gated_delta_net_impl(
|
|
|
2488
2625
|
device const float * b_ptr = (device const float *) (b) + (i23*args.ne22*args.ne21 + i21);
|
|
2489
2626
|
device const float * g_ptr = (device const float *) (g) + (i23*args.ne22*args.ne21 + i21)*G;
|
|
2490
2627
|
|
|
2628
|
+
// snapshot slot mapping: slot 0 = most recent state, slot s = s tokens back.
|
|
2629
|
+
// When n_tokens < K, only slots 0..n_tokens-1 are written; older slots are caller-owned.
|
|
2630
|
+
|
|
2631
|
+
// output state base offset: after attention scores
|
|
2632
|
+
const uint attn_size = args.ne22 * args.ne21 * S_v * args.ne23;
|
|
2633
|
+
// output state per-slot size: S_v * S_v * H * n_seqs
|
|
2634
|
+
const uint state_size_per_snap = S_v * S_v * args.ne21 * args.ne23;
|
|
2635
|
+
// per-(seq,head) offset within a slot
|
|
2636
|
+
const uint state_out_base = (i23*args.ne21 + i21)*S_v*S_v + i20*S_v;
|
|
2637
|
+
|
|
2491
2638
|
for (short t = 0; t < args.ne22; t++) {
|
|
2492
2639
|
float s_k = 0.0f;
|
|
2493
2640
|
|
|
@@ -2535,17 +2682,30 @@ kernel void kernel_gated_delta_net_impl(
|
|
|
2535
2682
|
|
|
2536
2683
|
b_ptr += args.ne21;
|
|
2537
2684
|
g_ptr += args.ne21*G;
|
|
2538
|
-
}
|
|
2539
2685
|
|
|
2540
|
-
|
|
2686
|
+
if (K > 1) {
|
|
2687
|
+
const int target_slot = (int)args.ne22 - 1 - (int)t;
|
|
2688
|
+
if (target_slot >= 0 && target_slot < (int)K) {
|
|
2689
|
+
device float * dst_state = (device float *) (dst) + attn_size + (uint)target_slot * state_size_per_snap + state_out_base;
|
|
2690
|
+
FOR_UNROLL (short j = 0; j < NSG; j++) {
|
|
2691
|
+
const short is = tx*NSG + j;
|
|
2692
|
+
dst_state[is] = ls[j];
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2541
2697
|
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2698
|
+
if (K == 1) {
|
|
2699
|
+
device float * dst_state = (device float *) (dst) + attn_size + state_out_base;
|
|
2700
|
+
FOR_UNROLL (short j = 0; j < NSG; j++) {
|
|
2701
|
+
const short is = tx*NSG + j;
|
|
2702
|
+
dst_state[is] = ls[j];
|
|
2703
|
+
}
|
|
2545
2704
|
}
|
|
2546
2705
|
|
|
2547
2706
|
#undef S_v
|
|
2548
2707
|
#undef G
|
|
2708
|
+
#undef K
|
|
2549
2709
|
}
|
|
2550
2710
|
|
|
2551
2711
|
typedef decltype(kernel_gated_delta_net_impl<4>) kernel_gated_delta_net_t;
|
|
@@ -3100,6 +3260,35 @@ kernel void kernel_group_norm_f32(
|
|
|
3100
3260
|
}
|
|
3101
3261
|
}
|
|
3102
3262
|
|
|
3263
|
+
// Q1_0 dot product: dot = d * (2 * Σ(yl[i] where bit=1) - sumy)
|
|
3264
|
+
inline float block_q_n_dot_y(device const block_q1_0 * qb_curr, float sumy, thread float * yl, int il) {
|
|
3265
|
+
device const uint8_t * qs = qb_curr->qs + il / 8;
|
|
3266
|
+
const uint8_t b0 = qs[0];
|
|
3267
|
+
const uint8_t b1 = qs[1];
|
|
3268
|
+
|
|
3269
|
+
float acc = 0.0f;
|
|
3270
|
+
|
|
3271
|
+
acc += select(0.0f, yl[ 0], bool(b0 & 0x01));
|
|
3272
|
+
acc += select(0.0f, yl[ 1], bool(b0 & 0x02));
|
|
3273
|
+
acc += select(0.0f, yl[ 2], bool(b0 & 0x04));
|
|
3274
|
+
acc += select(0.0f, yl[ 3], bool(b0 & 0x08));
|
|
3275
|
+
acc += select(0.0f, yl[ 4], bool(b0 & 0x10));
|
|
3276
|
+
acc += select(0.0f, yl[ 5], bool(b0 & 0x20));
|
|
3277
|
+
acc += select(0.0f, yl[ 6], bool(b0 & 0x40));
|
|
3278
|
+
acc += select(0.0f, yl[ 7], bool(b0 & 0x80));
|
|
3279
|
+
|
|
3280
|
+
acc += select(0.0f, yl[ 8], bool(b1 & 0x01));
|
|
3281
|
+
acc += select(0.0f, yl[ 9], bool(b1 & 0x02));
|
|
3282
|
+
acc += select(0.0f, yl[10], bool(b1 & 0x04));
|
|
3283
|
+
acc += select(0.0f, yl[11], bool(b1 & 0x08));
|
|
3284
|
+
acc += select(0.0f, yl[12], bool(b1 & 0x10));
|
|
3285
|
+
acc += select(0.0f, yl[13], bool(b1 & 0x20));
|
|
3286
|
+
acc += select(0.0f, yl[14], bool(b1 & 0x40));
|
|
3287
|
+
acc += select(0.0f, yl[15], bool(b1 & 0x80));
|
|
3288
|
+
|
|
3289
|
+
return qb_curr->d * (2.0f * acc - sumy);
|
|
3290
|
+
}
|
|
3291
|
+
|
|
3103
3292
|
// function for calculate inner product between half a q4_0 block and 16 floats (yl), sumy is SUM(yl[i])
|
|
3104
3293
|
// il indicates where the q4 quants begin (0 or QK4_0/4)
|
|
3105
3294
|
// we assume that the yl's have been multiplied with the appropriate scale factor
|
|
@@ -3232,6 +3421,9 @@ static inline void helper_mv_reduce_and_write(
|
|
|
3232
3421
|
|
|
3233
3422
|
constant short FC_mul_mv_nsg [[function_constant(FC_MUL_MV + 0)]];
|
|
3234
3423
|
constant short FC_mul_mv_nxpsg [[function_constant(FC_MUL_MV + 1)]];
|
|
3424
|
+
constant short FC_mul_mv_ne12 [[function_constant(FC_MUL_MV + 2)]];
|
|
3425
|
+
constant short FC_mul_mv_r2 [[function_constant(FC_MUL_MV + 3)]];
|
|
3426
|
+
constant short FC_mul_mv_r3 [[function_constant(FC_MUL_MV + 4)]];
|
|
3235
3427
|
|
|
3236
3428
|
template<typename block_q_type, short NR0, typename args_t>
|
|
3237
3429
|
void mul_vec_q_n_f32_impl(
|
|
@@ -3255,10 +3447,10 @@ void mul_vec_q_n_f32_impl(
|
|
|
3255
3447
|
const int r1 = tgpig.y;
|
|
3256
3448
|
const int im = tgpig.z;
|
|
3257
3449
|
|
|
3258
|
-
const uint i12 = im%
|
|
3259
|
-
const uint i13 = im/
|
|
3450
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
3451
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
3260
3452
|
|
|
3261
|
-
//const uint64_t offset0 = r0*args.nb01 + (i12/
|
|
3453
|
+
//const uint64_t offset0 = r0*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3262
3454
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
3263
3455
|
|
|
3264
3456
|
//device const block_q_type * x = (device const block_q_type *) (src0 + offset0);
|
|
@@ -3267,7 +3459,7 @@ void mul_vec_q_n_f32_impl(
|
|
|
3267
3459
|
// pointers to src0 rows
|
|
3268
3460
|
device const block_q_type * ax[NR0];
|
|
3269
3461
|
FOR_UNROLL (int row = 0; row < NR0; ++row) {
|
|
3270
|
-
const uint64_t offset0 = (r0 + row)*args.nb01 + (i12/
|
|
3462
|
+
const uint64_t offset0 = (r0 + row)*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3271
3463
|
|
|
3272
3464
|
ax[row] = (device const block_q_type *) ((device char *) src0 + offset0);
|
|
3273
3465
|
}
|
|
@@ -3321,6 +3513,85 @@ void mul_vec_q_n_f32_impl(
|
|
|
3321
3513
|
}
|
|
3322
3514
|
}
|
|
3323
3515
|
|
|
3516
|
+
template<int nr0, typename args_t>
|
|
3517
|
+
void kernel_mul_mv_q1_0_f32_impl(
|
|
3518
|
+
args_t args,
|
|
3519
|
+
device const char * src0,
|
|
3520
|
+
device const char * src1,
|
|
3521
|
+
device char * dst,
|
|
3522
|
+
threadgroup char * shmem,
|
|
3523
|
+
uint3 tgpig,
|
|
3524
|
+
ushort tiisg,
|
|
3525
|
+
ushort sgitg) {
|
|
3526
|
+
const short NSG = FC_mul_mv_nsg;
|
|
3527
|
+
|
|
3528
|
+
const int nb = args.ne00/QK1_0;
|
|
3529
|
+
|
|
3530
|
+
const int r0 = tgpig.x;
|
|
3531
|
+
const int r1 = tgpig.y;
|
|
3532
|
+
const int im = tgpig.z;
|
|
3533
|
+
|
|
3534
|
+
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
3535
|
+
|
|
3536
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
3537
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
3538
|
+
|
|
3539
|
+
const uint64_t offset1 = r1*args.nb11 + (i12)*args.nb12 + (i13)*args.nb13;
|
|
3540
|
+
|
|
3541
|
+
device const float * y = (device const float *) (src1 + offset1);
|
|
3542
|
+
|
|
3543
|
+
device const block_q1_0 * ax[nr0];
|
|
3544
|
+
for (int row = 0; row < nr0; ++row) {
|
|
3545
|
+
const uint64_t offset0 = (first_row + row)*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3546
|
+
ax[row] = (device const block_q1_0 *) ((device char *) src0 + offset0);
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
|
+
float yl[16];
|
|
3550
|
+
float sumf[nr0] = {0.f};
|
|
3551
|
+
|
|
3552
|
+
const short ix = (tiisg/8);
|
|
3553
|
+
const short il = (tiisg%8)*16;
|
|
3554
|
+
|
|
3555
|
+
device const float * yb = y + ix*QK1_0 + il;
|
|
3556
|
+
|
|
3557
|
+
for (int ib = ix; ib < nb; ib += N_SIMDWIDTH/8) {
|
|
3558
|
+
float sumy = 0.f;
|
|
3559
|
+
|
|
3560
|
+
FOR_UNROLL (short i = 0; i < 16; i++) {
|
|
3561
|
+
yl[i] = yb[i];
|
|
3562
|
+
sumy += yb[i];
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3565
|
+
FOR_UNROLL (short row = 0; row < nr0; row++) {
|
|
3566
|
+
sumf[row] += block_q_n_dot_y(ax[row] + ib, sumy, yl, il);
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
yb += QK1_0 * (N_SIMDWIDTH/8);
|
|
3570
|
+
}
|
|
3571
|
+
|
|
3572
|
+
device float * dst_f32 = (device float *) dst + (uint64_t)im*args.ne0*args.ne1 + (uint64_t)r1*args.ne0;
|
|
3573
|
+
|
|
3574
|
+
for (int row = 0; row < nr0; ++row) {
|
|
3575
|
+
const float tot = simd_sum(sumf[row]);
|
|
3576
|
+
|
|
3577
|
+
if (tiisg == 0 && first_row + row < args.ne01) {
|
|
3578
|
+
dst_f32[first_row + row] = tot;
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3583
|
+
[[host_name("kernel_mul_mv_q1_0_f32")]]
|
|
3584
|
+
kernel void kernel_mul_mv_q1_0_f32(
|
|
3585
|
+
constant ggml_metal_kargs_mul_mv & args,
|
|
3586
|
+
device const char * src0,
|
|
3587
|
+
device const char * src1,
|
|
3588
|
+
device char * dst,
|
|
3589
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
3590
|
+
ushort tiisg[[thread_index_in_simdgroup]],
|
|
3591
|
+
ushort sgitg[[simdgroup_index_in_threadgroup]]) {
|
|
3592
|
+
kernel_mul_mv_q1_0_f32_impl<N_R0_Q1_0, constant ggml_metal_kargs_mul_mv &>(args, src0, src1, dst, nullptr, tgpig, tiisg, sgitg);
|
|
3593
|
+
}
|
|
3594
|
+
|
|
3324
3595
|
kernel void kernel_mul_mv_q4_0_f32(
|
|
3325
3596
|
constant ggml_metal_kargs_mul_mv & args,
|
|
3326
3597
|
device const char * src0,
|
|
@@ -3390,10 +3661,10 @@ void kernel_mul_mv_q8_0_f32_impl(
|
|
|
3390
3661
|
const int r1 = tgpig.y;
|
|
3391
3662
|
const int im = tgpig.z;
|
|
3392
3663
|
|
|
3393
|
-
const uint i12 = im%
|
|
3394
|
-
const uint i13 = im/
|
|
3664
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
3665
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
3395
3666
|
|
|
3396
|
-
//const uint64_t offset0 = r0*args.nb01 + (i12/
|
|
3667
|
+
//const uint64_t offset0 = r0*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3397
3668
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
3398
3669
|
|
|
3399
3670
|
//device const block_q8_0 * x = (device const block_q8_0 *) (src0 + offset0);
|
|
@@ -3402,7 +3673,7 @@ void kernel_mul_mv_q8_0_f32_impl(
|
|
|
3402
3673
|
// pointers to src0 rows
|
|
3403
3674
|
device const block_q8_0 * ax[NR0];
|
|
3404
3675
|
FOR_UNROLL (short row = 0; row < NR0; ++row) {
|
|
3405
|
-
const uint64_t offset0 = (r0 + row)*args.nb01 + (i12/
|
|
3676
|
+
const uint64_t offset0 = (r0 + row)*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3406
3677
|
|
|
3407
3678
|
ax[row] = (device const block_q8_0 *) ((device char *) src0 + offset0);
|
|
3408
3679
|
}
|
|
@@ -3482,10 +3753,10 @@ void kernel_mul_mv_ext_q4_f32_impl(
|
|
|
3482
3753
|
const int i11 = tgpig.y*r1ptg;
|
|
3483
3754
|
const int i1m = tgpig.z;
|
|
3484
3755
|
|
|
3485
|
-
const int i12 = i1m%
|
|
3486
|
-
const int i13 = i1m/
|
|
3756
|
+
const int i12 = i1m%FC_mul_mv_ne12;
|
|
3757
|
+
const int i13 = i1m/FC_mul_mv_ne12;
|
|
3487
3758
|
|
|
3488
|
-
const uint64_t offset0 = i01*args.nb01 + (i12/
|
|
3759
|
+
const uint64_t offset0 = i01*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3489
3760
|
const uint64_t offset1 = i11*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
3490
3761
|
|
|
3491
3762
|
device const q_t * xq = (i01 < args.ne01) ? (device const q_t *) (src0 + offset0) + tx/chpb : (device const q_t *) src0;
|
|
@@ -3585,10 +3856,10 @@ void kernel_mul_mv_ext_q4x4_f32_impl(
|
|
|
3585
3856
|
const int i11 = tgpig.y*r1ptg;
|
|
3586
3857
|
const int i1m = tgpig.z;
|
|
3587
3858
|
|
|
3588
|
-
const int i12 = i1m%
|
|
3589
|
-
const int i13 = i1m/
|
|
3859
|
+
const int i12 = i1m%FC_mul_mv_ne12;
|
|
3860
|
+
const int i13 = i1m/FC_mul_mv_ne12;
|
|
3590
3861
|
|
|
3591
|
-
const uint64_t offset0 = i01*args.nb01 + (i12/
|
|
3862
|
+
const uint64_t offset0 = i01*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3592
3863
|
const uint64_t offset1 = i11*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
3593
3864
|
|
|
3594
3865
|
device const q_t * xq = (i01 < args.ne01) ? (device const q_t *) (src0 + offset0) + tx/chpb : (device const q_t *) src0;
|
|
@@ -3713,6 +3984,11 @@ template [[host_name("kernel_mul_mv_ext_bf16_f32_r1_4")]] kernel mul_mv_ext_q4
|
|
|
3713
3984
|
template [[host_name("kernel_mul_mv_ext_bf16_f32_r1_5")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<5, bfloat4, 4, dequantize_bf16_t4>;
|
|
3714
3985
|
#endif
|
|
3715
3986
|
|
|
3987
|
+
template [[host_name("kernel_mul_mv_ext_q1_0_f32_r1_2")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<2, block_q1_0, 128, dequantize_q1_0_t4>;
|
|
3988
|
+
template [[host_name("kernel_mul_mv_ext_q1_0_f32_r1_3")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<3, block_q1_0, 128, dequantize_q1_0_t4>;
|
|
3989
|
+
template [[host_name("kernel_mul_mv_ext_q1_0_f32_r1_4")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<4, block_q1_0, 128, dequantize_q1_0_t4>;
|
|
3990
|
+
template [[host_name("kernel_mul_mv_ext_q1_0_f32_r1_5")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<5, block_q1_0, 128, dequantize_q1_0_t4>;
|
|
3991
|
+
|
|
3716
3992
|
template [[host_name("kernel_mul_mv_ext_q4_0_f32_r1_2")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<2, block_q4_0, 32, dequantize_q4_0_t4>;
|
|
3717
3993
|
template [[host_name("kernel_mul_mv_ext_q4_0_f32_r1_3")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<3, block_q4_0, 32, dequantize_q4_0_t4>;
|
|
3718
3994
|
template [[host_name("kernel_mul_mv_ext_q4_0_f32_r1_4")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<4, block_q4_0, 32, dequantize_q4_0_t4>;
|
|
@@ -3795,10 +4071,10 @@ void kernel_mul_mv_t_t_impl(
|
|
|
3795
4071
|
const int r1 = tgpig.y;
|
|
3796
4072
|
const int im = tgpig.z;
|
|
3797
4073
|
|
|
3798
|
-
const uint i12 = im%
|
|
3799
|
-
const uint i13 = im/
|
|
4074
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
4075
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
3800
4076
|
|
|
3801
|
-
//const uint64_t offset0 = r0*args.nb01 + (i12/
|
|
4077
|
+
//const uint64_t offset0 = r0*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3802
4078
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
3803
4079
|
|
|
3804
4080
|
//device const T0 * x = (device const T0 *) (src0 + offset0);
|
|
@@ -3807,7 +4083,7 @@ void kernel_mul_mv_t_t_impl(
|
|
|
3807
4083
|
// pointers to src0 rows
|
|
3808
4084
|
device const T0 * ax [NR0];
|
|
3809
4085
|
FOR_UNROLL (short row = 0; row < NR0; ++row) {
|
|
3810
|
-
const uint64_t offset0 = (r0 + row)*args.nb01 + (i12/
|
|
4086
|
+
const uint64_t offset0 = (r0 + row)*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3811
4087
|
|
|
3812
4088
|
ax[row] = (device const T0 *) ((device char *) src0 + offset0);
|
|
3813
4089
|
}
|
|
@@ -3917,10 +4193,10 @@ void kernel_mul_mv_t_t_4_impl(
|
|
|
3917
4193
|
const int r1 = tgpig.y;
|
|
3918
4194
|
const int im = tgpig.z;
|
|
3919
4195
|
|
|
3920
|
-
const uint i12 = im%
|
|
3921
|
-
const uint i13 = im/
|
|
4196
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
4197
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
3922
4198
|
|
|
3923
|
-
//const uint64_t offset0 = r0*args.nb01 + (i12/
|
|
4199
|
+
//const uint64_t offset0 = r0*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3924
4200
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
3925
4201
|
|
|
3926
4202
|
device const T1 * y = (device const T1 *) (src1 + offset1);
|
|
@@ -3930,7 +4206,7 @@ void kernel_mul_mv_t_t_4_impl(
|
|
|
3930
4206
|
device const T0 * ax [NR0];
|
|
3931
4207
|
device const T04 * ax4[NR0];
|
|
3932
4208
|
FOR_UNROLL (short row = 0; row < NR0; ++row) {
|
|
3933
|
-
const uint64_t offset0 = (r0 + row)*args.nb01 + (i12/
|
|
4209
|
+
const uint64_t offset0 = (r0 + row)*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
3934
4210
|
|
|
3935
4211
|
ax [row] = (device const T0 *) ((device char *) src0 + offset0);
|
|
3936
4212
|
ax4[row] = (device const T04 *) ((device char *) src0 + offset0);
|
|
@@ -4034,10 +4310,10 @@ void kernel_mul_mv_t_t_short_impl(
|
|
|
4034
4310
|
return;
|
|
4035
4311
|
}
|
|
4036
4312
|
|
|
4037
|
-
const uint i12 = im%
|
|
4038
|
-
const uint i13 = im/
|
|
4313
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
4314
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
4039
4315
|
|
|
4040
|
-
const uint64_t offset0 = r0*args.nb01 + (i12/
|
|
4316
|
+
const uint64_t offset0 = r0*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
4041
4317
|
|
|
4042
4318
|
device const T0 * x = (device const T0 *) (src0 + offset0);
|
|
4043
4319
|
|
|
@@ -4084,6 +4360,7 @@ template [[host_name("kernel_mul_mv_bf16_bf16_short")]] kernel mul_mv_t_t_short_
|
|
|
4084
4360
|
#endif
|
|
4085
4361
|
|
|
4086
4362
|
constant bool FC_rope_is_imrope [[function_constant(FC_ROPE + 0)]];
|
|
4363
|
+
constant bool FC_rope_is_back [[function_constant(FC_ROPE + 1)]];
|
|
4087
4364
|
|
|
4088
4365
|
static float rope_yarn_ramp(const float low, const float high, const int i0) {
|
|
4089
4366
|
const float y = (i0 / 2 - low) / max(0.001f, high - low);
|
|
@@ -4107,6 +4384,9 @@ static void rope_yarn(
|
|
|
4107
4384
|
}
|
|
4108
4385
|
*cos_theta = cos(theta) * mscale;
|
|
4109
4386
|
*sin_theta = sin(theta) * mscale;
|
|
4387
|
+
if (FC_rope_is_back) {
|
|
4388
|
+
*sin_theta *= -1.0f;
|
|
4389
|
+
}
|
|
4110
4390
|
}
|
|
4111
4391
|
|
|
4112
4392
|
// Apparently solving `n_rot = 2pi * x * base^((2 * max_pos_emb) / n_dims)` for x, we get
|
|
@@ -4460,59 +4740,59 @@ kernel void kernel_im2col(
|
|
|
4460
4740
|
template [[host_name("kernel_im2col_f32")]] kernel im2col_t kernel_im2col<float>;
|
|
4461
4741
|
template [[host_name("kernel_im2col_f16")]] kernel im2col_t kernel_im2col<half>;
|
|
4462
4742
|
|
|
4463
|
-
// TODO:
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4743
|
+
// TODO: optimize
|
|
4744
|
+
typedef void (im2col_ext_t)(
|
|
4745
|
+
constant ggml_metal_kargs_im2col & args,
|
|
4746
|
+
device const float * x,
|
|
4747
|
+
device char * dst,
|
|
4748
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
4749
|
+
uint3 tgpg[[threadgroups_per_grid]],
|
|
4750
|
+
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
4751
|
+
uint3 ntg[[threads_per_threadgroup]]);
|
|
4752
|
+
|
|
4753
|
+
template <typename T>
|
|
4754
|
+
kernel void kernel_im2col_ext(
|
|
4755
|
+
constant ggml_metal_kargs_im2col & args,
|
|
4756
|
+
device const float * x,
|
|
4757
|
+
device char * dst,
|
|
4758
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
4759
|
+
uint3 tgpg[[threadgroups_per_grid]], // tgpg[0] = D x IC x KH x KW, CHW = IC x KH x KW
|
|
4760
|
+
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
4761
|
+
uint3 ntg[[threads_per_threadgroup]]) { // [M, 1, 1]
|
|
4762
|
+
const int64_t KHW = (int64_t)args.KHW;
|
|
4763
|
+
|
|
4764
|
+
const int64_t d = tgpig[0] / args.CHW;
|
|
4765
|
+
const int64_t chw = tgpig[0] % args.CHW;
|
|
4766
|
+
const int64_t tgpig_0 = chw / KHW; // 0 ~ (IC - 1)
|
|
4767
|
+
const int64_t HW = tgpig[0] % KHW;
|
|
4768
|
+
|
|
4769
|
+
const int64_t tpitg_0 = (d * ntg[0]) + tpitg[0];
|
|
4770
|
+
if (tpitg_0 >= args.N) {
|
|
4771
|
+
return;
|
|
4772
|
+
}
|
|
4773
|
+
|
|
4774
|
+
const int64_t tpitg_1 = HW / args.KW;
|
|
4775
|
+
const int64_t tpitg_2 = HW % args.KW;
|
|
4776
|
+
|
|
4777
|
+
const int64_t iiw = tgpig[2] * args.s0 + tpitg_2 * args.d0 - args.p0;
|
|
4778
|
+
const int64_t iih = tgpig[1] * args.s1 + tpitg_1 * args.d1 - args.p1;
|
|
4779
|
+
|
|
4780
|
+
const int64_t offset_dst =
|
|
4781
|
+
(tpitg_0 * tgpg[1] * tgpg[2] + tgpig[1] * tgpg[2] + tgpig[2]) * args.CHW +
|
|
4782
|
+
(tgpig_0 * KHW + tpitg_1 * args.KW + tpitg_2);
|
|
4783
|
+
|
|
4784
|
+
device T * pdst = (device T *) (dst);
|
|
4785
|
+
|
|
4786
|
+
if (iih < 0 || iih >= args.IH || iiw < 0 || iiw >= args.IW) {
|
|
4787
|
+
pdst[offset_dst] = 0.0f;
|
|
4788
|
+
} else {
|
|
4789
|
+
const int64_t offset_src = tpitg_0 * args.ofs0 + tgpig_0 * args.ofs1;
|
|
4790
|
+
pdst[offset_dst] = x[offset_src + iih * args.IW + iiw];
|
|
4791
|
+
}
|
|
4792
|
+
}
|
|
4793
|
+
|
|
4794
|
+
template [[host_name("kernel_im2col_ext_f32")]] kernel im2col_ext_t kernel_im2col_ext<float>;
|
|
4795
|
+
template [[host_name("kernel_im2col_ext_f16")]] kernel im2col_ext_t kernel_im2col_ext<half>;
|
|
4516
4796
|
|
|
4517
4797
|
template <typename TK>
|
|
4518
4798
|
kernel void kernel_conv_2d(
|
|
@@ -4628,92 +4908,348 @@ kernel void kernel_conv_2d<half>(
|
|
|
4628
4908
|
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
4629
4909
|
uint3 ntg[[threads_per_threadgroup]]);
|
|
4630
4910
|
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
device
|
|
4911
|
+
// grid: x = C tile, y = OH, z = OW * N (for channel-contiguous layouts)
|
|
4912
|
+
template <typename TK>
|
|
4913
|
+
kernel void kernel_conv_2d_dw_tiled(
|
|
4914
|
+
constant ggml_metal_kargs_conv_2d_dw & args,
|
|
4915
|
+
device const char * weights,
|
|
4916
|
+
device const char * src,
|
|
4917
|
+
device char * dst,
|
|
4636
4918
|
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
4637
|
-
uint3
|
|
4919
|
+
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
4920
|
+
uint3 ntg[[threads_per_threadgroup]]) {
|
|
4638
4921
|
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
device const float * src1,
|
|
4644
|
-
device char * dst,
|
|
4645
|
-
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
4646
|
-
uint3 tgpg[[threadgroups_per_grid]]) {
|
|
4922
|
+
const int32_t c = (int32_t)(tgpig.x * ntg.x + tpitg.x);
|
|
4923
|
+
if (c >= args.C) {
|
|
4924
|
+
return;
|
|
4925
|
+
}
|
|
4647
4926
|
|
|
4648
|
-
|
|
4927
|
+
const int32_t oh = tgpig.y;
|
|
4928
|
+
const int32_t own = tgpig.z;
|
|
4929
|
+
const int32_t ow = own % args.OW;
|
|
4930
|
+
const int32_t n = own / args.OW;
|
|
4649
4931
|
|
|
4650
|
-
|
|
4651
|
-
const int32_t kernel_offset = c * tgpg[1] * args.K + args.K * tgpig[1];
|
|
4652
|
-
const int32_t input_offset = c * args.IL;
|
|
4932
|
+
const int32_t base_y = oh*args.s1 - args.p1;
|
|
4653
4933
|
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4934
|
+
int32_t ky_start = 0;
|
|
4935
|
+
if (base_y < 0) {
|
|
4936
|
+
ky_start = (-base_y + args.d1 - 1)/args.d1;
|
|
4937
|
+
}
|
|
4938
|
+
int32_t ky_end = args.KH;
|
|
4939
|
+
const int32_t y_max = args.IH - 1 - base_y;
|
|
4940
|
+
if (y_max < 0) {
|
|
4941
|
+
ky_end = ky_start;
|
|
4942
|
+
} else if (base_y + (args.KH - 1)*args.d1 >= args.IH) {
|
|
4943
|
+
ky_end = min(ky_end, y_max/args.d1 + 1);
|
|
4659
4944
|
}
|
|
4660
4945
|
|
|
4661
|
-
|
|
4946
|
+
const int32_t base_x = ow*args.s0 - args.p0;
|
|
4662
4947
|
|
|
4663
|
-
|
|
4664
|
-
|
|
4948
|
+
int32_t kx_start = 0;
|
|
4949
|
+
if (base_x < 0) {
|
|
4950
|
+
kx_start = (-base_x + args.d0 - 1)/args.d0;
|
|
4951
|
+
}
|
|
4952
|
+
int32_t kx_end = args.KW;
|
|
4953
|
+
const int32_t x_max = args.IW - 1 - base_x;
|
|
4954
|
+
if (x_max < 0) {
|
|
4955
|
+
kx_end = kx_start;
|
|
4956
|
+
} else if (base_x + (args.KW - 1)*args.d0 >= args.IW) {
|
|
4957
|
+
kx_end = min(kx_end, x_max/args.d0 + 1);
|
|
4958
|
+
}
|
|
4665
4959
|
|
|
4666
|
-
|
|
4667
|
-
kernel void kernel_conv_transpose_1d<float>(
|
|
4668
|
-
constant ggml_metal_kargs_conv_transpose_1d & args,
|
|
4669
|
-
device const float * src0,
|
|
4670
|
-
device const float * src1,
|
|
4671
|
-
device char * dst,
|
|
4672
|
-
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
4673
|
-
uint3 tgpg[[threadgroups_per_grid]]);
|
|
4960
|
+
float acc = 0.0f;
|
|
4674
4961
|
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
device const half * src0,
|
|
4679
|
-
device const float * src1,
|
|
4680
|
-
device char * dst,
|
|
4681
|
-
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
4682
|
-
uint3 tgpg[[threadgroups_per_grid]]);
|
|
4962
|
+
if (ky_start < ky_end && kx_start < kx_end) {
|
|
4963
|
+
const uint64_t w_base = (uint64_t) c * args.nb02;
|
|
4964
|
+
const uint64_t src_base = (uint64_t) n * args.nb13 + (uint64_t) c * args.nb12;
|
|
4683
4965
|
|
|
4966
|
+
for (int32_t ky = ky_start; ky < ky_end; ++ky) {
|
|
4967
|
+
const int32_t iy = base_y + ky*args.d1;
|
|
4968
|
+
const uint64_t src_row = src_base + (uint64_t) iy * args.nb11;
|
|
4969
|
+
const uint64_t w_row = w_base + (uint64_t) ky * args.nb01;
|
|
4684
4970
|
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4971
|
+
for (int32_t kx = kx_start; kx < kx_end; ++kx) {
|
|
4972
|
+
const int32_t ix = base_x + kx*args.d0;
|
|
4973
|
+
const float x = *(device const float *)(src + src_row + (uint64_t) ix * args.nb10);
|
|
4974
|
+
const float w = (float)(*(device const TK *)(weights + w_row + (uint64_t) kx * args.nb00));
|
|
4975
|
+
acc += x * w;
|
|
4976
|
+
}
|
|
4977
|
+
}
|
|
4978
|
+
}
|
|
4692
4979
|
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4980
|
+
const uint64_t dst_offs =
|
|
4981
|
+
(uint64_t) n * args.nb3 +
|
|
4982
|
+
(uint64_t) c * args.nb2 +
|
|
4983
|
+
(uint64_t) oh * args.nb1 +
|
|
4984
|
+
(uint64_t) ow * args.nb0;
|
|
4985
|
+
|
|
4986
|
+
*(device float *)(dst + dst_offs) = acc;
|
|
4987
|
+
}
|
|
4988
|
+
|
|
4989
|
+
// grid: x = OW tile, y = OH, z = C * N (for spatially-contiguous layouts)
|
|
4990
|
+
template <typename TK>
|
|
4991
|
+
kernel void kernel_conv_2d_dw(
|
|
4992
|
+
constant ggml_metal_kargs_conv_2d_dw & args,
|
|
4993
|
+
device const char * weights,
|
|
4994
|
+
device const char * src,
|
|
4995
|
+
device char * dst,
|
|
4700
4996
|
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
4701
4997
|
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
4702
4998
|
uint3 ntg[[threads_per_threadgroup]]) {
|
|
4703
4999
|
|
|
4704
|
-
const
|
|
4705
|
-
const
|
|
4706
|
-
const
|
|
4707
|
-
|
|
4708
|
-
const int64_t kw = tpitg[0];
|
|
4709
|
-
const int64_t kh = tpitg[1];
|
|
5000
|
+
const int32_t oh = tgpig.y;
|
|
5001
|
+
const int32_t cn = tgpig.z;
|
|
5002
|
+
const int32_t c = cn % args.C;
|
|
5003
|
+
const int32_t n = cn / args.C;
|
|
4710
5004
|
|
|
4711
|
-
|
|
5005
|
+
const int32_t base_y = oh*args.s1 - args.p1;
|
|
4712
5006
|
|
|
4713
|
-
|
|
4714
|
-
|
|
5007
|
+
int32_t ky_start = 0;
|
|
5008
|
+
if (base_y < 0) {
|
|
5009
|
+
ky_start = (-base_y + args.d1 - 1)/args.d1;
|
|
5010
|
+
}
|
|
5011
|
+
int32_t ky_end = args.KH;
|
|
5012
|
+
const int32_t y_max = args.IH - 1 - base_y;
|
|
5013
|
+
if (y_max < 0) {
|
|
5014
|
+
ky_end = ky_start;
|
|
5015
|
+
} else if (base_y + (args.KH - 1)*args.d1 >= args.IH) {
|
|
5016
|
+
ky_end = min(ky_end, y_max/args.d1 + 1);
|
|
5017
|
+
}
|
|
4715
5018
|
|
|
4716
|
-
|
|
5019
|
+
const uint64_t w_base = (uint64_t) c * args.nb02;
|
|
5020
|
+
const uint64_t src_base = (uint64_t) n * args.nb13 + (uint64_t) c * args.nb12;
|
|
5021
|
+
|
|
5022
|
+
const int32_t ow = (int32_t)(tgpig.x * ntg.x + tpitg.x);
|
|
5023
|
+
if (ow >= args.OW) {
|
|
5024
|
+
return;
|
|
5025
|
+
}
|
|
5026
|
+
|
|
5027
|
+
float acc = 0.0f;
|
|
5028
|
+
|
|
5029
|
+
const int32_t base_x = ow*args.s0 - args.p0;
|
|
5030
|
+
|
|
5031
|
+
int32_t kx_start = 0;
|
|
5032
|
+
if (base_x < 0) {
|
|
5033
|
+
kx_start = (-base_x + args.d0 - 1)/args.d0;
|
|
5034
|
+
}
|
|
5035
|
+
int32_t kx_end = args.KW;
|
|
5036
|
+
const int32_t x_max = args.IW - 1 - base_x;
|
|
5037
|
+
if (x_max < 0) {
|
|
5038
|
+
kx_end = kx_start;
|
|
5039
|
+
} else if (base_x + (args.KW - 1)*args.d0 >= args.IW) {
|
|
5040
|
+
kx_end = min(kx_end, x_max/args.d0 + 1);
|
|
5041
|
+
}
|
|
5042
|
+
|
|
5043
|
+
if (ky_start < ky_end && kx_start < kx_end) {
|
|
5044
|
+
for (int32_t ky = ky_start; ky < ky_end; ++ky) {
|
|
5045
|
+
const int32_t iy = base_y + ky*args.d1;
|
|
5046
|
+
const uint64_t src_row = src_base + (uint64_t) iy * args.nb11;
|
|
5047
|
+
const uint64_t w_row = w_base + (uint64_t) ky * args.nb01;
|
|
5048
|
+
|
|
5049
|
+
for (int32_t kx = kx_start; kx < kx_end; ++kx) {
|
|
5050
|
+
const int32_t ix = base_x + kx*args.d0;
|
|
5051
|
+
const float x = *(device const float *)(src + src_row + (uint64_t) ix * args.nb10);
|
|
5052
|
+
const float w = (float)(*(device const TK *)(weights + w_row + (uint64_t) kx * args.nb00));
|
|
5053
|
+
acc += x * w;
|
|
5054
|
+
}
|
|
5055
|
+
}
|
|
5056
|
+
}
|
|
5057
|
+
|
|
5058
|
+
const uint64_t dst_offs =
|
|
5059
|
+
(uint64_t) n * args.nb3 +
|
|
5060
|
+
(uint64_t) c * args.nb2 +
|
|
5061
|
+
(uint64_t) oh * args.nb1 +
|
|
5062
|
+
(uint64_t) ow * args.nb0;
|
|
5063
|
+
|
|
5064
|
+
*(device float *)(dst + dst_offs) = acc;
|
|
5065
|
+
}
|
|
5066
|
+
|
|
5067
|
+
template [[host_name("kernel_conv_2d_dw_f32_f32")]]
|
|
5068
|
+
kernel void kernel_conv_2d_dw<float>(
|
|
5069
|
+
constant ggml_metal_kargs_conv_2d_dw & args,
|
|
5070
|
+
device const char * weights,
|
|
5071
|
+
device const char * src,
|
|
5072
|
+
device char * dst,
|
|
5073
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5074
|
+
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
5075
|
+
uint3 ntg[[threads_per_threadgroup]]);
|
|
5076
|
+
|
|
5077
|
+
template [[host_name("kernel_conv_2d_dw_f16_f32")]]
|
|
5078
|
+
kernel void kernel_conv_2d_dw<half>(
|
|
5079
|
+
constant ggml_metal_kargs_conv_2d_dw & args,
|
|
5080
|
+
device const char * weights,
|
|
5081
|
+
device const char * src,
|
|
5082
|
+
device char * dst,
|
|
5083
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5084
|
+
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
5085
|
+
uint3 ntg[[threads_per_threadgroup]]);
|
|
5086
|
+
|
|
5087
|
+
template [[host_name("kernel_conv_2d_dw_tiled_f32_f32")]]
|
|
5088
|
+
kernel void kernel_conv_2d_dw_tiled<float>(
|
|
5089
|
+
constant ggml_metal_kargs_conv_2d_dw & args,
|
|
5090
|
+
device const char * weights,
|
|
5091
|
+
device const char * src,
|
|
5092
|
+
device char * dst,
|
|
5093
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5094
|
+
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
5095
|
+
uint3 ntg[[threads_per_threadgroup]]);
|
|
5096
|
+
|
|
5097
|
+
template [[host_name("kernel_conv_2d_dw_tiled_f16_f32")]]
|
|
5098
|
+
kernel void kernel_conv_2d_dw_tiled<half>(
|
|
5099
|
+
constant ggml_metal_kargs_conv_2d_dw & args,
|
|
5100
|
+
device const char * weights,
|
|
5101
|
+
device const char * src,
|
|
5102
|
+
device char * dst,
|
|
5103
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5104
|
+
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
5105
|
+
uint3 ntg[[threads_per_threadgroup]]);
|
|
5106
|
+
|
|
5107
|
+
typedef void (conv_transpose_1d_t)(
|
|
5108
|
+
constant ggml_metal_kargs_conv_transpose_1d & args,
|
|
5109
|
+
device const float * src0,
|
|
5110
|
+
device const float * src1,
|
|
5111
|
+
device char * dst,
|
|
5112
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5113
|
+
uint3 tgpg[[threadgroups_per_grid]]);
|
|
5114
|
+
|
|
5115
|
+
template <typename T>
|
|
5116
|
+
kernel void kernel_conv_transpose_1d(
|
|
5117
|
+
constant ggml_metal_kargs_conv_transpose_1d & args,
|
|
5118
|
+
device const T * src0,
|
|
5119
|
+
device const float * src1,
|
|
5120
|
+
device char * dst,
|
|
5121
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5122
|
+
uint3 tgpg[[threadgroups_per_grid]]) {
|
|
5123
|
+
|
|
5124
|
+
// For output position j on the time axis, only input positions
|
|
5125
|
+
// i such that i*s0 <= j < i*s0 + K
|
|
5126
|
+
// contribute -- i.e. i in [ceil((j - K + 1)/s0), floor(j/s0)]
|
|
5127
|
+
// intersected with [0, IL-1]. That's at most ceil(K/s0) values
|
|
5128
|
+
// (typically 2 for stride==K/2 transposed convs).
|
|
5129
|
+
const int32_t j = tgpig[0];
|
|
5130
|
+
const int32_t s0 = args.s0;
|
|
5131
|
+
const int32_t K = args.K;
|
|
5132
|
+
const int32_t IL = args.IL;
|
|
5133
|
+
|
|
5134
|
+
int32_t i_min;
|
|
5135
|
+
{
|
|
5136
|
+
int32_t a = j - K + 1;
|
|
5137
|
+
i_min = a <= 0 ? 0 : (a + s0 - 1) / s0; // ceil(a/s0) for a>0
|
|
5138
|
+
}
|
|
5139
|
+
int32_t i_max = j / s0;
|
|
5140
|
+
if (i_max > IL - 1) i_max = IL - 1;
|
|
5141
|
+
|
|
5142
|
+
float v = 0.0f;
|
|
5143
|
+
if (i_min <= i_max) {
|
|
5144
|
+
for (int64_t c = 0; c < args.IC; c++) {
|
|
5145
|
+
const int32_t kernel_offset = c * tgpg[1] * K + K * tgpig[1];
|
|
5146
|
+
const int32_t input_offset = c * IL;
|
|
5147
|
+
|
|
5148
|
+
for (int32_t i = i_min; i <= i_max; i++) {
|
|
5149
|
+
v += float(src0[kernel_offset + j - i * s0]) * src1[input_offset + i];
|
|
5150
|
+
}
|
|
5151
|
+
}
|
|
5152
|
+
}
|
|
5153
|
+
|
|
5154
|
+
device float * dst_ptr = (device float *) (dst + tgpig[0] * args.nb0 + tgpig[1] * args.nb1);
|
|
5155
|
+
|
|
5156
|
+
dst_ptr[0] = v;
|
|
5157
|
+
}
|
|
5158
|
+
|
|
5159
|
+
template [[host_name("kernel_conv_transpose_1d_f32_f32")]]
|
|
5160
|
+
kernel void kernel_conv_transpose_1d<float>(
|
|
5161
|
+
constant ggml_metal_kargs_conv_transpose_1d & args,
|
|
5162
|
+
device const float * src0,
|
|
5163
|
+
device const float * src1,
|
|
5164
|
+
device char * dst,
|
|
5165
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5166
|
+
uint3 tgpg[[threadgroups_per_grid]]);
|
|
5167
|
+
|
|
5168
|
+
template [[host_name("kernel_conv_transpose_1d_f16_f32")]]
|
|
5169
|
+
kernel void kernel_conv_transpose_1d<half>(
|
|
5170
|
+
constant ggml_metal_kargs_conv_transpose_1d & args,
|
|
5171
|
+
device const half * src0,
|
|
5172
|
+
device const float * src1,
|
|
5173
|
+
device char * dst,
|
|
5174
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5175
|
+
uint3 tgpg[[threadgroups_per_grid]]);
|
|
5176
|
+
|
|
5177
|
+
|
|
5178
|
+
template <typename T>
|
|
5179
|
+
kernel void kernel_col2im_1d(
|
|
5180
|
+
constant ggml_metal_kargs_col2im_1d & args,
|
|
5181
|
+
device const T * col,
|
|
5182
|
+
device T * dst,
|
|
5183
|
+
uint tgpig [[threadgroup_position_in_grid]],
|
|
5184
|
+
uint tpitg [[thread_position_in_threadgroup]],
|
|
5185
|
+
uint ntg [[threads_per_threadgroup]]) {
|
|
5186
|
+
|
|
5187
|
+
const int idx = tgpig * ntg + tpitg;
|
|
5188
|
+
if (idx >= args.T_out * args.OC) {
|
|
5189
|
+
return;
|
|
5190
|
+
}
|
|
5191
|
+
|
|
5192
|
+
const int t_out = idx % args.T_out;
|
|
5193
|
+
const int oc = idx / args.T_out;
|
|
5194
|
+
const int t_abs = t_out + args.p0; // absolute position in uncropped signal
|
|
5195
|
+
|
|
5196
|
+
int t_in_min = (t_abs - args.K + args.s0) / args.s0; // ceil((t_abs - K + 1) / s0)
|
|
5197
|
+
if (t_in_min < 0) {
|
|
5198
|
+
t_in_min = 0;
|
|
5199
|
+
}
|
|
5200
|
+
int t_in_max = t_abs / args.s0;
|
|
5201
|
+
if (t_in_max >= args.T_in) {
|
|
5202
|
+
t_in_max = args.T_in - 1;
|
|
5203
|
+
}
|
|
5204
|
+
|
|
5205
|
+
float sum = 0.0f;
|
|
5206
|
+
for (int t_in = t_in_min; t_in <= t_in_max; t_in++) {
|
|
5207
|
+
const int k = t_abs - t_in * args.s0;
|
|
5208
|
+
sum += float(col[(oc * args.K + k) + t_in * args.K_OC]);
|
|
5209
|
+
}
|
|
5210
|
+
|
|
5211
|
+
dst[t_out + oc * args.T_out] = T(sum);
|
|
5212
|
+
}
|
|
5213
|
+
|
|
5214
|
+
template [[host_name("kernel_col2im_1d_f32")]] kernel void kernel_col2im_1d<float>(constant ggml_metal_kargs_col2im_1d &, device const float *, device float *, uint, uint, uint);
|
|
5215
|
+
template [[host_name("kernel_col2im_1d_f16")]] kernel void kernel_col2im_1d<half>(constant ggml_metal_kargs_col2im_1d &, device const half *, device half *, uint, uint, uint);
|
|
5216
|
+
#if defined(GGML_METAL_HAS_BF16)
|
|
5217
|
+
template [[host_name("kernel_col2im_1d_bf16")]] kernel void kernel_col2im_1d<bfloat>(constant ggml_metal_kargs_col2im_1d &, device const bfloat *, device bfloat *, uint, uint, uint);
|
|
5218
|
+
#endif
|
|
5219
|
+
|
|
5220
|
+
|
|
5221
|
+
typedef void (conv_transpose_2d_t)(
|
|
5222
|
+
constant ggml_metal_kargs_conv_transpose_2d & args,
|
|
5223
|
+
device const float * src0,
|
|
5224
|
+
device const float * src1,
|
|
5225
|
+
device char * dst,
|
|
5226
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5227
|
+
uint3 tgpg[[threadgroups_per_grid]]);
|
|
5228
|
+
|
|
5229
|
+
template <typename T>
|
|
5230
|
+
kernel void kernel_conv_transpose_2d(
|
|
5231
|
+
constant ggml_metal_kargs_conv_transpose_2d & args,
|
|
5232
|
+
device const T * src0,
|
|
5233
|
+
device const float * src1,
|
|
5234
|
+
device char * dst,
|
|
5235
|
+
threadgroup float * shared_sum [[threadgroup(0)]],
|
|
5236
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5237
|
+
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
5238
|
+
uint3 ntg[[threads_per_threadgroup]]) {
|
|
5239
|
+
|
|
5240
|
+
const int64_t out_x = tgpig[0];
|
|
5241
|
+
const int64_t out_y = tgpig[1];
|
|
5242
|
+
const int64_t out_c = tgpig[2];
|
|
5243
|
+
|
|
5244
|
+
const int64_t kw = tpitg[0];
|
|
5245
|
+
const int64_t kh = tpitg[1];
|
|
5246
|
+
|
|
5247
|
+
float v = 0.0f;
|
|
5248
|
+
|
|
5249
|
+
for (int64_t in_c = 0; in_c < args.IC; in_c++) {
|
|
5250
|
+
int64_t in_y = out_y - kh;
|
|
5251
|
+
|
|
5252
|
+
if (in_y < 0 || in_y % args.s0) continue;
|
|
4717
5253
|
|
|
4718
5254
|
in_y /= args.s0;
|
|
4719
5255
|
|
|
@@ -4851,7 +5387,7 @@ kernel void kernel_upscale_bilinear_f32(
|
|
|
4851
5387
|
for (int64_t sx = x_min; sx < x_max; ++sx) {
|
|
4852
5388
|
const float wx = MAX(0.0f, 1.0f - fabs((float)sx - f00) * invscale0);
|
|
4853
5389
|
const float w = wx * wy;
|
|
4854
|
-
|
|
5390
|
+
device const float * src_ptr = (device const float *)(src0 + sy*args.nb01 + sx*args.nb00);
|
|
4855
5391
|
sum += (*src_ptr) * w;
|
|
4856
5392
|
wsum += w;
|
|
4857
5393
|
}
|
|
@@ -4883,6 +5419,98 @@ kernel void kernel_upscale_bilinear_f32(
|
|
|
4883
5419
|
}
|
|
4884
5420
|
}
|
|
4885
5421
|
|
|
5422
|
+
template <typename T>
|
|
5423
|
+
kernel void kernel_conv_3d(
|
|
5424
|
+
constant ggml_metal_kargs_conv_3d & args,
|
|
5425
|
+
device const char * src0, // Weights [IC * OC, KD, KH, KW]
|
|
5426
|
+
device const char * src1, // Inputs [IC * N, ID, IH, IW]
|
|
5427
|
+
device char * dst, // Outputs [OC * N, OD, OH, OW]
|
|
5428
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5429
|
+
uint3 tpitg[[thread_position_in_threadgroup]]) {
|
|
5430
|
+
|
|
5431
|
+
// 1. Un-flatten the spatial dimension from Grid X
|
|
5432
|
+
int64_t spatial_idx = tgpig.x * 32 + tpitg.x;
|
|
5433
|
+
|
|
5434
|
+
if (spatial_idx >= args.OW * args.OH * args.OD) {
|
|
5435
|
+
return; // Thread falls outside the spatial volume
|
|
5436
|
+
}
|
|
5437
|
+
|
|
5438
|
+
int64_t od = spatial_idx / (args.OW * args.OH);
|
|
5439
|
+
int64_t oh = (spatial_idx / args.OW) % args.OH;
|
|
5440
|
+
int64_t ow = spatial_idx % args.OW;
|
|
5441
|
+
|
|
5442
|
+
// 2. Map Y to Channels, Z to Batch
|
|
5443
|
+
int64_t oc = tgpig.y;
|
|
5444
|
+
int64_t batch_idx = tgpig.z;
|
|
5445
|
+
|
|
5446
|
+
// 3. Calculate anchor coordinates in the Input volume
|
|
5447
|
+
int64_t i_w_base = ow * args.s0 - args.p0;
|
|
5448
|
+
int64_t i_h_base = oh * args.s1 - args.p1;
|
|
5449
|
+
int64_t i_d_base = od * args.s2 - args.p2;
|
|
5450
|
+
|
|
5451
|
+
float sum = 0.0f;
|
|
5452
|
+
|
|
5453
|
+
// 4. Gather Loop (Iterate over Input Channels -> Depth -> Height -> Width)
|
|
5454
|
+
for (int64_t ic = 0; ic < args.IC; ++ic) {
|
|
5455
|
+
|
|
5456
|
+
// ggml packs batch and channel together in the 4th dimension
|
|
5457
|
+
int64_t src_cn_idx = batch_idx * args.IC + ic;
|
|
5458
|
+
int64_t w_cn_idx = oc * args.IC + ic;
|
|
5459
|
+
|
|
5460
|
+
for (int64_t kz = 0; kz < args.KD; ++kz) {
|
|
5461
|
+
int64_t id = i_d_base + kz * args.d2;
|
|
5462
|
+
if (id < 0 || id >= args.ID) continue; // Boundary check (Padding)
|
|
5463
|
+
|
|
5464
|
+
for (int64_t ky = 0; ky < args.KH; ++ky) {
|
|
5465
|
+
int64_t ih = i_h_base + ky * args.d1;
|
|
5466
|
+
if (ih < 0 || ih >= args.IH) continue;
|
|
5467
|
+
|
|
5468
|
+
for (int64_t kx = 0; kx < args.KW; ++kx) {
|
|
5469
|
+
int64_t iw = i_w_base + kx * args.d0;
|
|
5470
|
+
if (iw < 0 || iw >= args.IW) continue;
|
|
5471
|
+
|
|
5472
|
+
// Convert multi-dimensional coordinates to flat byte offsets
|
|
5473
|
+
int64_t w_idx = kx*args.nb00 + ky*args.nb01 + kz*args.nb02 + w_cn_idx*args.nb03;
|
|
5474
|
+
int64_t i_idx = iw*args.nb10 + ih*args.nb11 + id*args.nb12 + src_cn_idx*args.nb13;
|
|
5475
|
+
|
|
5476
|
+
// Dereference memory and cast weights to f32 if they were f16
|
|
5477
|
+
float w_val = (float)*(device const T*)((device const char*)src0 + w_idx);
|
|
5478
|
+
float i_val = *(device const float*)((device const char*)src1 + i_idx);
|
|
5479
|
+
|
|
5480
|
+
sum += w_val * i_val;
|
|
5481
|
+
}
|
|
5482
|
+
}
|
|
5483
|
+
}
|
|
5484
|
+
}
|
|
5485
|
+
|
|
5486
|
+
// 5. Write the accumulated value out to RAM
|
|
5487
|
+
int64_t dst_cn_idx = batch_idx * args.OC + oc;
|
|
5488
|
+
int64_t d_idx = ow*args.nb0 + oh*args.nb1 + od*args.nb2 + dst_cn_idx*args.nb3;
|
|
5489
|
+
|
|
5490
|
+
*(device float*)(dst + d_idx) = sum;
|
|
5491
|
+
}
|
|
5492
|
+
|
|
5493
|
+
// Explicit instantiations so the JIT compiler can find them by name
|
|
5494
|
+
template [[host_name("kernel_conv_3d_f32_f32")]]
|
|
5495
|
+
kernel void kernel_conv_3d<float>(
|
|
5496
|
+
constant ggml_metal_kargs_conv_3d & args,
|
|
5497
|
+
device const char * src0,
|
|
5498
|
+
device const char * src1,
|
|
5499
|
+
device char * dst,
|
|
5500
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5501
|
+
uint3 tpitg[[thread_position_in_threadgroup]]);
|
|
5502
|
+
|
|
5503
|
+
// Explicit instantiation for f16 weights
|
|
5504
|
+
template [[host_name("kernel_conv_3d_f16_f32")]]
|
|
5505
|
+
kernel void kernel_conv_3d<half>(
|
|
5506
|
+
constant ggml_metal_kargs_conv_3d & args,
|
|
5507
|
+
device const char * src0,
|
|
5508
|
+
device const char * src1,
|
|
5509
|
+
device char * dst,
|
|
5510
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5511
|
+
uint3 tpitg[[thread_position_in_threadgroup]]);
|
|
5512
|
+
|
|
5513
|
+
|
|
4886
5514
|
static inline float bicubic_weight1(float x) {
|
|
4887
5515
|
const float a = -0.75f;
|
|
4888
5516
|
return ((a + 2) * x - (a + 3)) * x * x + 1;
|
|
@@ -4941,7 +5569,7 @@ kernel void kernel_upscale_bicubic_f32(
|
|
|
4941
5569
|
const int64_t ix = MAX(0, MIN(args.ne00 - 1, i00 + dx));
|
|
4942
5570
|
const float wx = (dx == -1) ? w_x0 : (dx == 0) ? w_x1 : (dx == 1) ? w_x2 : w_x3;
|
|
4943
5571
|
|
|
4944
|
-
|
|
5572
|
+
device const float * src_ptr = (device const float *)(src_slice + iy * args.nb01 + ix * args.nb00);
|
|
4945
5573
|
sum += (*src_ptr) * wx * wy;
|
|
4946
5574
|
}
|
|
4947
5575
|
}
|
|
@@ -4950,8 +5578,8 @@ kernel void kernel_upscale_bicubic_f32(
|
|
|
4950
5578
|
}
|
|
4951
5579
|
}
|
|
4952
5580
|
|
|
4953
|
-
kernel void
|
|
4954
|
-
constant
|
|
5581
|
+
kernel void kernel_roll_f32(
|
|
5582
|
+
constant ggml_metal_kargs_roll & args,
|
|
4955
5583
|
device const char * src0,
|
|
4956
5584
|
device char * dst,
|
|
4957
5585
|
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
@@ -4962,30 +5590,68 @@ kernel void kernel_pad_f32(
|
|
|
4962
5590
|
const int64_t i2 = tgpig.y;
|
|
4963
5591
|
const int64_t i1 = tgpig.x;
|
|
4964
5592
|
|
|
4965
|
-
const
|
|
4966
|
-
|
|
4967
|
-
const int64_t i01 = i1;
|
|
5593
|
+
device const float * src0_ptr = (device const float *) src0;
|
|
5594
|
+
device float * dst_ptr = (device float *) dst;
|
|
4968
5595
|
|
|
4969
|
-
|
|
4970
|
-
|
|
5596
|
+
for (int i0 = tpitg.x; i0 < args.ne0; i0 += ntg.x) {
|
|
5597
|
+
// apply shifts and wrap around
|
|
5598
|
+
int64_t i00 = i0 - args.s0;
|
|
5599
|
+
int64_t i01 = i1 - args.s1;
|
|
5600
|
+
int64_t i02 = i2 - args.s2;
|
|
5601
|
+
int64_t i03 = i3 - args.s3;
|
|
4971
5602
|
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
} else {
|
|
4977
|
-
dst_ptr[i0] = 0.0f;
|
|
4978
|
-
}
|
|
4979
|
-
}
|
|
5603
|
+
if (i00 < 0) { i00 += args.ne00; } else if (i00 >= args.ne00) { i00 -= args.ne00; }
|
|
5604
|
+
if (i01 < 0) { i01 += args.ne01; } else if (i01 >= args.ne01) { i01 -= args.ne01; }
|
|
5605
|
+
if (i02 < 0) { i02 += args.ne02; } else if (i02 >= args.ne02) { i02 -= args.ne02; }
|
|
5606
|
+
if (i03 < 0) { i03 += args.ne03; } else if (i03 >= args.ne03) { i03 -= args.ne03; }
|
|
4980
5607
|
|
|
4981
|
-
|
|
5608
|
+
int64_t src_idx = i03*args.ne02*args.ne01*args.ne00 + i02*args.ne01*args.ne00 + i01*args.ne00 + i00;
|
|
5609
|
+
int64_t dst_idx = i3 *args.ne2 *args.ne1 *args.ne0 + i2 *args.ne1 *args.ne0 + i1 *args.ne0 + i0;
|
|
5610
|
+
|
|
5611
|
+
dst_ptr[dst_idx] = src0_ptr[src_idx];
|
|
4982
5612
|
}
|
|
5613
|
+
}
|
|
4983
5614
|
|
|
4984
|
-
|
|
4985
|
-
|
|
5615
|
+
template <typename T>
|
|
5616
|
+
kernel void kernel_pad_impl(
|
|
5617
|
+
constant ggml_metal_kargs_pad & args,
|
|
5618
|
+
device const char * src0,
|
|
5619
|
+
device char * dst,
|
|
5620
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
5621
|
+
uint3 tpitg[[thread_position_in_threadgroup]],
|
|
5622
|
+
uint3 ntg[[threads_per_threadgroup]]) {
|
|
5623
|
+
const int32_t i3 = tgpig.z;
|
|
5624
|
+
const int32_t i2 = tgpig.y;
|
|
5625
|
+
const int32_t k0 = tgpig.x/args.ne1;
|
|
5626
|
+
const int32_t i1 = tgpig.x - k0*args.ne1;
|
|
5627
|
+
|
|
5628
|
+
const int32_t i03 = i3;
|
|
5629
|
+
const int32_t i02 = i2;
|
|
5630
|
+
const int32_t i01 = i1;
|
|
5631
|
+
|
|
5632
|
+
device const T * src0_ptr = (device const T *) (src0 + i03*args.nb03 + i02*args.nb02 + i01*args.nb01);
|
|
5633
|
+
device T * dst_ptr = (device T *) (dst + i3*args.nb3 + i2*args.nb2 + i1*args.nb1);
|
|
5634
|
+
|
|
5635
|
+
for (int32_t l0 = 0; l0 < 1024; l0 += ntg.x) {
|
|
5636
|
+
const int32_t i0 = k0*1024 + tpitg.x + l0;
|
|
5637
|
+
if (i0 >= args.ne0) {
|
|
5638
|
+
break;
|
|
5639
|
+
}
|
|
5640
|
+
|
|
5641
|
+
if (i0 < args.ne00 && i1 < args.ne01 && i2 < args.ne02 && i3 < args.ne03) {
|
|
5642
|
+
dst_ptr[i0] = src0_ptr[i0];
|
|
5643
|
+
} else {
|
|
5644
|
+
dst_ptr[i0] = 0.0f;
|
|
5645
|
+
}
|
|
4986
5646
|
}
|
|
4987
5647
|
}
|
|
4988
5648
|
|
|
5649
|
+
typedef decltype(kernel_pad_impl<float>) kernel_pad_t;
|
|
5650
|
+
|
|
5651
|
+
template [[host_name("kernel_pad_f32")]] kernel kernel_pad_t kernel_pad_impl<float>;
|
|
5652
|
+
template [[host_name("kernel_pad_f32_4")]] kernel kernel_pad_t kernel_pad_impl<float4>;
|
|
5653
|
+
|
|
5654
|
+
// TODO: this is slow - optimize
|
|
4989
5655
|
kernel void kernel_pad_reflect_1d_f32(
|
|
4990
5656
|
constant ggml_metal_kargs_pad_reflect_1d & args,
|
|
4991
5657
|
device const char * src0,
|
|
@@ -6177,6 +6843,7 @@ template [[host_name("kernel_flash_attn_ext_f32_dk192_dv192")]] kernel flash_at
|
|
|
6177
6843
|
template [[host_name("kernel_flash_attn_ext_f32_dk192_dv128")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES_F32, float4x4, 1, dequantize_f32, float4x4, 1, dequantize_f32, 192, 128>;
|
|
6178
6844
|
template [[host_name("kernel_flash_attn_ext_f32_dk256_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES_F32, float4x4, 1, dequantize_f32, float4x4, 1, dequantize_f32, 256, 256>;
|
|
6179
6845
|
template [[host_name("kernel_flash_attn_ext_f32_dk320_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES_F32, float4x4, 1, dequantize_f32, float4x4, 1, dequantize_f32, 320, 256>;
|
|
6846
|
+
template [[host_name("kernel_flash_attn_ext_f32_dk512_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES_F32, float4x4, 1, dequantize_f32, float4x4, 1, dequantize_f32, 512, 512>;
|
|
6180
6847
|
template [[host_name("kernel_flash_attn_ext_f32_dk576_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES_F32, float4x4, 1, dequantize_f32, float4x4, 1, dequantize_f32, 576, 512>;
|
|
6181
6848
|
|
|
6182
6849
|
template [[host_name("kernel_flash_attn_ext_f16_dk32_dv32" )]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, half4x4, 1, dequantize_f16, half4x4, 1, dequantize_f16, 32, 32>;
|
|
@@ -6192,6 +6859,7 @@ template [[host_name("kernel_flash_attn_ext_f16_dk192_dv192")]] kernel flash_at
|
|
|
6192
6859
|
template [[host_name("kernel_flash_attn_ext_f16_dk192_dv128")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, half4x4, 1, dequantize_f16, half4x4, 1, dequantize_f16, 192, 128>;
|
|
6193
6860
|
template [[host_name("kernel_flash_attn_ext_f16_dk256_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, half4x4, 1, dequantize_f16, half4x4, 1, dequantize_f16, 256, 256>;
|
|
6194
6861
|
template [[host_name("kernel_flash_attn_ext_f16_dk320_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, half4x4, 1, dequantize_f16, half4x4, 1, dequantize_f16, 320, 256>;
|
|
6862
|
+
template [[host_name("kernel_flash_attn_ext_f16_dk512_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, half4x4, 1, dequantize_f16, half4x4, 1, dequantize_f16, 512, 512>;
|
|
6195
6863
|
template [[host_name("kernel_flash_attn_ext_f16_dk576_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, half4x4, 1, dequantize_f16, half4x4, 1, dequantize_f16, 576, 512>;
|
|
6196
6864
|
|
|
6197
6865
|
#if defined(GGML_METAL_HAS_BF16)
|
|
@@ -6208,6 +6876,7 @@ template [[host_name("kernel_flash_attn_ext_bf16_dk192_dv192")]] kernel flash_at
|
|
|
6208
6876
|
template [[host_name("kernel_flash_attn_ext_bf16_dk192_dv128")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES_BF, bfloat4x4, 1, dequantize_bf16, bfloat4x4, 1, dequantize_bf16, 192, 128>;
|
|
6209
6877
|
template [[host_name("kernel_flash_attn_ext_bf16_dk256_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES_BF, bfloat4x4, 1, dequantize_bf16, bfloat4x4, 1, dequantize_bf16, 256, 256>;
|
|
6210
6878
|
template [[host_name("kernel_flash_attn_ext_bf16_dk320_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES_BF, bfloat4x4, 1, dequantize_bf16, bfloat4x4, 1, dequantize_bf16, 320, 256>;
|
|
6879
|
+
template [[host_name("kernel_flash_attn_ext_bf16_dk512_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES_BF, bfloat4x4, 1, dequantize_bf16, bfloat4x4, 1, dequantize_bf16, 512, 512>;
|
|
6211
6880
|
template [[host_name("kernel_flash_attn_ext_bf16_dk576_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES_BF, bfloat4x4, 1, dequantize_bf16, bfloat4x4, 1, dequantize_bf16, 576, 512>;
|
|
6212
6881
|
#endif
|
|
6213
6882
|
|
|
@@ -6224,6 +6893,7 @@ template [[host_name("kernel_flash_attn_ext_q4_0_dk192_dv192")]] kernel flash_at
|
|
|
6224
6893
|
template [[host_name("kernel_flash_attn_ext_q4_0_dk192_dv128")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_0, 2, dequantize_q4_0, block_q4_0, 2, dequantize_q4_0, 192, 128>;
|
|
6225
6894
|
template [[host_name("kernel_flash_attn_ext_q4_0_dk256_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_0, 2, dequantize_q4_0, block_q4_0, 2, dequantize_q4_0, 256, 256>;
|
|
6226
6895
|
template [[host_name("kernel_flash_attn_ext_q4_0_dk320_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_0, 2, dequantize_q4_0, block_q4_0, 2, dequantize_q4_0, 320, 256>;
|
|
6896
|
+
template [[host_name("kernel_flash_attn_ext_q4_0_dk512_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_0, 2, dequantize_q4_0, block_q4_0, 2, dequantize_q4_0, 512, 512>;
|
|
6227
6897
|
template [[host_name("kernel_flash_attn_ext_q4_0_dk576_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_0, 2, dequantize_q4_0, block_q4_0, 2, dequantize_q4_0, 576, 512>;
|
|
6228
6898
|
|
|
6229
6899
|
template [[host_name("kernel_flash_attn_ext_q4_1_dk32_dv32" )]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_1, 2, dequantize_q4_1, block_q4_1, 2, dequantize_q4_1, 32, 32>;
|
|
@@ -6239,6 +6909,7 @@ template [[host_name("kernel_flash_attn_ext_q4_1_dk192_dv192")]] kernel flash_at
|
|
|
6239
6909
|
template [[host_name("kernel_flash_attn_ext_q4_1_dk192_dv128")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_1, 2, dequantize_q4_1, block_q4_1, 2, dequantize_q4_1, 192, 128>;
|
|
6240
6910
|
template [[host_name("kernel_flash_attn_ext_q4_1_dk256_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_1, 2, dequantize_q4_1, block_q4_1, 2, dequantize_q4_1, 256, 256>;
|
|
6241
6911
|
template [[host_name("kernel_flash_attn_ext_q4_1_dk320_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_1, 2, dequantize_q4_1, block_q4_1, 2, dequantize_q4_1, 320, 256>;
|
|
6912
|
+
template [[host_name("kernel_flash_attn_ext_q4_1_dk512_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_1, 2, dequantize_q4_1, block_q4_1, 2, dequantize_q4_1, 512, 512>;
|
|
6242
6913
|
template [[host_name("kernel_flash_attn_ext_q4_1_dk576_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q4_1, 2, dequantize_q4_1, block_q4_1, 2, dequantize_q4_1, 576, 512>;
|
|
6243
6914
|
|
|
6244
6915
|
template [[host_name("kernel_flash_attn_ext_q5_0_dk32_dv32" )]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_0, 2, dequantize_q5_0, block_q5_0, 2, dequantize_q5_0, 32, 32>;
|
|
@@ -6254,6 +6925,7 @@ template [[host_name("kernel_flash_attn_ext_q5_0_dk192_dv192")]] kernel flash_at
|
|
|
6254
6925
|
template [[host_name("kernel_flash_attn_ext_q5_0_dk192_dv128")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_0, 2, dequantize_q5_0, block_q5_0, 2, dequantize_q5_0, 192, 128>;
|
|
6255
6926
|
template [[host_name("kernel_flash_attn_ext_q5_0_dk256_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_0, 2, dequantize_q5_0, block_q5_0, 2, dequantize_q5_0, 256, 256>;
|
|
6256
6927
|
template [[host_name("kernel_flash_attn_ext_q5_0_dk320_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_0, 2, dequantize_q5_0, block_q5_0, 2, dequantize_q5_0, 320, 256>;
|
|
6928
|
+
template [[host_name("kernel_flash_attn_ext_q5_0_dk512_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_0, 2, dequantize_q5_0, block_q5_0, 2, dequantize_q5_0, 512, 512>;
|
|
6257
6929
|
template [[host_name("kernel_flash_attn_ext_q5_0_dk576_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_0, 2, dequantize_q5_0, block_q5_0, 2, dequantize_q5_0, 576, 512>;
|
|
6258
6930
|
|
|
6259
6931
|
template [[host_name("kernel_flash_attn_ext_q5_1_dk32_dv32" )]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_1, 2, dequantize_q5_1, block_q5_1, 2, dequantize_q5_1, 32, 32>;
|
|
@@ -6269,6 +6941,7 @@ template [[host_name("kernel_flash_attn_ext_q5_1_dk192_dv192")]] kernel flash_at
|
|
|
6269
6941
|
template [[host_name("kernel_flash_attn_ext_q5_1_dk192_dv128")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_1, 2, dequantize_q5_1, block_q5_1, 2, dequantize_q5_1, 192, 128>;
|
|
6270
6942
|
template [[host_name("kernel_flash_attn_ext_q5_1_dk256_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_1, 2, dequantize_q5_1, block_q5_1, 2, dequantize_q5_1, 256, 256>;
|
|
6271
6943
|
template [[host_name("kernel_flash_attn_ext_q5_1_dk320_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_1, 2, dequantize_q5_1, block_q5_1, 2, dequantize_q5_1, 320, 256>;
|
|
6944
|
+
template [[host_name("kernel_flash_attn_ext_q5_1_dk512_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_1, 2, dequantize_q5_1, block_q5_1, 2, dequantize_q5_1, 512, 512>;
|
|
6272
6945
|
template [[host_name("kernel_flash_attn_ext_q5_1_dk576_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q5_1, 2, dequantize_q5_1, block_q5_1, 2, dequantize_q5_1, 576, 512>;
|
|
6273
6946
|
|
|
6274
6947
|
template [[host_name("kernel_flash_attn_ext_q8_0_dk32_dv32" )]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q8_0, 2, dequantize_q8_0, block_q8_0, 2, dequantize_q8_0, 32, 32>;
|
|
@@ -6284,6 +6957,7 @@ template [[host_name("kernel_flash_attn_ext_q8_0_dk192_dv192")]] kernel flash_at
|
|
|
6284
6957
|
template [[host_name("kernel_flash_attn_ext_q8_0_dk192_dv128")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q8_0, 2, dequantize_q8_0, block_q8_0, 2, dequantize_q8_0, 192, 128>;
|
|
6285
6958
|
template [[host_name("kernel_flash_attn_ext_q8_0_dk256_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q8_0, 2, dequantize_q8_0, block_q8_0, 2, dequantize_q8_0, 256, 256>;
|
|
6286
6959
|
template [[host_name("kernel_flash_attn_ext_q8_0_dk320_dv256")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q8_0, 2, dequantize_q8_0, block_q8_0, 2, dequantize_q8_0, 320, 256>;
|
|
6960
|
+
template [[host_name("kernel_flash_attn_ext_q8_0_dk512_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q8_0, 2, dequantize_q8_0, block_q8_0, 2, dequantize_q8_0, 512, 512>;
|
|
6287
6961
|
template [[host_name("kernel_flash_attn_ext_q8_0_dk576_dv512")]] kernel flash_attn_ext_t kernel_flash_attn_ext<FA_TYPES, block_q8_0, 2, dequantize_q8_0, block_q8_0, 2, dequantize_q8_0, 576, 512>;
|
|
6288
6962
|
|
|
6289
6963
|
#undef FA_TYPES
|
|
@@ -6865,6 +7539,17 @@ template [[host_name("kernel_flash_attn_ext_vec_q5_0_dk320_dv256")]] kernel flas
|
|
|
6865
7539
|
template [[host_name("kernel_flash_attn_ext_vec_q5_1_dk320_dv256")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES, block_q5_1, 8, dequantize_q5_1_t4, block_q5_1, 8, dequantize_q5_1_t4, 320, 256, 2>;
|
|
6866
7540
|
template [[host_name("kernel_flash_attn_ext_vec_q8_0_dk320_dv256")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES, block_q8_0, 8, dequantize_q8_0_t4, block_q8_0, 8, dequantize_q8_0_t4, 320, 256, 2>;
|
|
6867
7541
|
|
|
7542
|
+
template [[host_name("kernel_flash_attn_ext_vec_f32_dk512_dv512")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES_F32, float4, 1, dequantize_f32_t4, float4, 1, dequantize_f32_t4, 512, 512, 1>;
|
|
7543
|
+
template [[host_name("kernel_flash_attn_ext_vec_f16_dk512_dv512")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES, half4, 1, dequantize_f16_t4, half4, 1, dequantize_f16_t4, 512, 512, 1>;
|
|
7544
|
+
#if defined(GGML_METAL_HAS_BF16)
|
|
7545
|
+
template [[host_name("kernel_flash_attn_ext_vec_bf16_dk512_dv512")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES, bfloat4, 1, dequantize_bf16_t4, bfloat4, 1, dequantize_bf16_t4, 512, 512, 1>;
|
|
7546
|
+
#endif
|
|
7547
|
+
template [[host_name("kernel_flash_attn_ext_vec_q4_0_dk512_dv512")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES, block_q4_0, 8, dequantize_q4_0_t4, block_q4_0, 8, dequantize_q4_0_t4, 512, 512, 1>;
|
|
7548
|
+
template [[host_name("kernel_flash_attn_ext_vec_q4_1_dk512_dv512")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES, block_q4_1, 8, dequantize_q4_1_t4, block_q4_1, 8, dequantize_q4_1_t4, 512, 512, 1>;
|
|
7549
|
+
template [[host_name("kernel_flash_attn_ext_vec_q5_0_dk512_dv512")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES, block_q5_0, 8, dequantize_q5_0_t4, block_q5_0, 8, dequantize_q5_0_t4, 512, 512, 1>;
|
|
7550
|
+
template [[host_name("kernel_flash_attn_ext_vec_q5_1_dk512_dv512")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES, block_q5_1, 8, dequantize_q5_1_t4, block_q5_1, 8, dequantize_q5_1_t4, 512, 512, 1>;
|
|
7551
|
+
template [[host_name("kernel_flash_attn_ext_vec_q8_0_dk512_dv512")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES, block_q8_0, 8, dequantize_q8_0_t4, block_q8_0, 8, dequantize_q8_0_t4, 512, 512, 1>;
|
|
7552
|
+
|
|
6868
7553
|
template [[host_name("kernel_flash_attn_ext_vec_f32_dk576_dv512")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES_F32, float4, 1, dequantize_f32_t4, float4, 1, dequantize_f32_t4, 576, 512, 2>;
|
|
6869
7554
|
template [[host_name("kernel_flash_attn_ext_vec_f16_dk576_dv512")]] kernel flash_attn_ext_vec_t kernel_flash_attn_ext_vec<FA_TYPES, half4, 1, dequantize_f16_t4, half4, 1, dequantize_f16_t4, 576, 512, 2>;
|
|
6870
7555
|
#if defined(GGML_METAL_HAS_BF16)
|
|
@@ -6930,23 +7615,27 @@ kernel void kernel_cpy_t_t(
|
|
|
6930
7615
|
device const char * src0,
|
|
6931
7616
|
device char * dst,
|
|
6932
7617
|
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
6933
|
-
|
|
7618
|
+
ushort3 tpitg[[thread_position_in_threadgroup]],
|
|
6934
7619
|
ushort3 ntg[[threads_per_threadgroup]]) {
|
|
6935
|
-
const
|
|
6936
|
-
const
|
|
6937
|
-
const
|
|
6938
|
-
const
|
|
7620
|
+
const int32_t i03 = tgpig[2];
|
|
7621
|
+
const int32_t i02 = tgpig[1];
|
|
7622
|
+
const int32_t i01 = ntg[1] == 1 ? tgpig[0]%args.ne01 : tgpig[0]*ntg[1] + tpitg.y;
|
|
7623
|
+
const int32_t iw0 = ntg[1] == 1 ? tgpig[0]/args.ne01 : 0;
|
|
7624
|
+
|
|
7625
|
+
if (i01 >= args.ne01) {
|
|
7626
|
+
return;
|
|
7627
|
+
}
|
|
6939
7628
|
|
|
6940
7629
|
const int64_t n = i03*args.ne02*args.ne01*args.ne00 + i02*args.ne01*args.ne00 + i01*args.ne00;
|
|
6941
7630
|
|
|
6942
|
-
const
|
|
6943
|
-
const
|
|
6944
|
-
const
|
|
6945
|
-
const
|
|
7631
|
+
const int32_t i3 = n/(args.ne2*args.ne1*args.ne0);
|
|
7632
|
+
const int32_t i2 = (n - i3*args.ne2*args.ne1*args.ne0)/(args.ne1*args.ne0);
|
|
7633
|
+
const int32_t i1 = (n - i3*args.ne2*args.ne1*args.ne0 - i2*args.ne1*args.ne0)/args.ne0;
|
|
7634
|
+
const int32_t i0 = (n - i3*args.ne2*args.ne1*args.ne0 - i2*args.ne1*args.ne0 - i1*args.ne0);
|
|
6946
7635
|
|
|
6947
7636
|
device T1 * dst_data = (device T1 *) (dst + i3*args.nb3 + i2*args.nb2 + i1*args.nb1 + i0*args.nb0);
|
|
6948
7637
|
|
|
6949
|
-
for (
|
|
7638
|
+
for (int32_t i00 = iw0*ntg[0] + tpitg.x; i00 < args.ne00;) {
|
|
6950
7639
|
device const T0 * src = (device T0 *)(src0 + i03*args.nb03 + i02*args.nb02 + i01*args.nb01 + i00*args.nb00);
|
|
6951
7640
|
dst_data[i00] = (T1) src[0];
|
|
6952
7641
|
break;
|
|
@@ -6978,23 +7667,27 @@ kernel void kernel_cpy_f32_q(
|
|
|
6978
7667
|
device const char * src0,
|
|
6979
7668
|
device char * dst,
|
|
6980
7669
|
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
6981
|
-
|
|
7670
|
+
ushort3 tpitg[[thread_position_in_threadgroup]],
|
|
6982
7671
|
ushort3 ntg[[threads_per_threadgroup]]) {
|
|
6983
|
-
const
|
|
6984
|
-
const
|
|
6985
|
-
const
|
|
6986
|
-
const
|
|
7672
|
+
const int32_t i03 = tgpig[2];
|
|
7673
|
+
const int32_t i02 = tgpig[1];
|
|
7674
|
+
const int32_t i01 = ntg[1] == 1 ? tgpig[0]%args.ne01 : tgpig[0]*ntg[1] + tpitg.y;
|
|
7675
|
+
const int32_t iw0 = ntg[1] == 1 ? tgpig[0]/args.ne01 : 0;
|
|
7676
|
+
|
|
7677
|
+
if (i01 >= args.ne01) {
|
|
7678
|
+
return;
|
|
7679
|
+
}
|
|
6987
7680
|
|
|
6988
7681
|
const int64_t n = i03*args.ne02*args.ne01*args.ne00 + i02*args.ne01*args.ne00 + i01*args.ne00;
|
|
6989
7682
|
|
|
6990
|
-
const
|
|
6991
|
-
const
|
|
6992
|
-
const
|
|
6993
|
-
const
|
|
7683
|
+
const int32_t i3 = n / (args.ne2*args.ne1*args.ne0);
|
|
7684
|
+
const int32_t i2 = (n - i3*args.ne2*args.ne1*args.ne0) / (args.ne1*args.ne0);
|
|
7685
|
+
const int32_t i1 = (n - i3*args.ne2*args.ne1*args.ne0 - i2*args.ne1*args.ne0) / args.ne0;
|
|
7686
|
+
const int32_t i0 = (n - i3*args.ne2*args.ne1*args.ne0 - i2*args.ne1*args.ne0 - i1*args.ne0)/QK;
|
|
6994
7687
|
|
|
6995
7688
|
device block_q * dst_data = (device block_q *)(dst + i3*args.nb3 + i2*args.nb2 + i1*args.nb1 + i0*args.nb0);
|
|
6996
7689
|
|
|
6997
|
-
for (
|
|
7690
|
+
for (int32_t i00 = iw0*ntg[0] + tpitg.x; i00 < args.nk0;) {
|
|
6998
7691
|
device const float * src = (device const float *)(src0 + i03*args.nb03 + i02*args.nb02 + i01*args.nb01 + (i00*QK)*args.nb00);
|
|
6999
7692
|
|
|
7000
7693
|
quantize_func(src, dst_data[i00]);
|
|
@@ -7006,6 +7699,7 @@ kernel void kernel_cpy_f32_q(
|
|
|
7006
7699
|
typedef decltype(kernel_cpy_f32_q<QK8_0, block_q8_0, quantize_q8_0>) cpy_f_q_t;
|
|
7007
7700
|
|
|
7008
7701
|
template [[host_name("kernel_cpy_f32_q8_0")]] kernel cpy_f_q_t kernel_cpy_f32_q<QK8_0, block_q8_0, quantize_q8_0>;
|
|
7702
|
+
template [[host_name("kernel_cpy_f32_q1_0")]] kernel cpy_f_q_t kernel_cpy_f32_q<QK1_0, block_q1_0, quantize_q1_0>;
|
|
7009
7703
|
template [[host_name("kernel_cpy_f32_q4_0")]] kernel cpy_f_q_t kernel_cpy_f32_q<QK4_0, block_q4_0, quantize_q4_0>;
|
|
7010
7704
|
template [[host_name("kernel_cpy_f32_q4_1")]] kernel cpy_f_q_t kernel_cpy_f32_q<QK4_1, block_q4_1, quantize_q4_1>;
|
|
7011
7705
|
template [[host_name("kernel_cpy_f32_q5_0")]] kernel cpy_f_q_t kernel_cpy_f32_q<QK5_0, block_q5_0, quantize_q5_0>;
|
|
@@ -7018,24 +7712,28 @@ kernel void kernel_cpy_q_f32(
|
|
|
7018
7712
|
device const char * src0,
|
|
7019
7713
|
device char * dst,
|
|
7020
7714
|
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
7021
|
-
|
|
7715
|
+
ushort3 tpitg[[thread_position_in_threadgroup]],
|
|
7022
7716
|
ushort3 ntg[[threads_per_threadgroup]]) {
|
|
7023
|
-
const
|
|
7024
|
-
const
|
|
7025
|
-
const
|
|
7026
|
-
const
|
|
7717
|
+
const int32_t i03 = tgpig[2];
|
|
7718
|
+
const int32_t i02 = tgpig[1];
|
|
7719
|
+
const int32_t i01 = ntg[1] == 1 ? tgpig[0]%args.ne01 : tgpig[0]*ntg[1] + tpitg.y;
|
|
7720
|
+
const int32_t iw0 = ntg[1] == 1 ? tgpig[0]/args.ne01 : 0;
|
|
7721
|
+
|
|
7722
|
+
if (i01 >= args.ne01) {
|
|
7723
|
+
return;
|
|
7724
|
+
}
|
|
7027
7725
|
|
|
7028
7726
|
const int64_t n = i03*args.ne02*args.ne01*args.ne00 + i02*args.ne01*args.ne00 + i01*args.ne00;
|
|
7029
7727
|
|
|
7030
|
-
const
|
|
7031
|
-
const
|
|
7032
|
-
const
|
|
7033
|
-
const
|
|
7728
|
+
const int32_t i3 = n/(args.ne2*args.ne1*args.ne0);
|
|
7729
|
+
const int32_t i2 = (n - i3*args.ne2*args.ne1*args.ne0)/(args.ne1*args.ne0);
|
|
7730
|
+
const int32_t i1 = (n - i3*args.ne2*args.ne1*args.ne0 - i2*args.ne1*args.ne0)/args.ne0;
|
|
7731
|
+
const int32_t i0 = (n - i3*args.ne2*args.ne1*args.ne0 - i2*args.ne1*args.ne0 - i1*args.ne0);
|
|
7034
7732
|
|
|
7035
7733
|
device const block_q * src_data = (device const block_q *)(src0 + i03*args.nb03 + i02*args.nb02 + i01*args.nb01);
|
|
7036
7734
|
device T4x4 * dst_data = (device T4x4 *)(dst + i3*args.nb3 + i2*args.nb2 + i1*args.nb1 + i0*args.nb0);
|
|
7037
7735
|
|
|
7038
|
-
for (
|
|
7736
|
+
for (int32_t i00 = iw0*ntg[0] + tpitg.x; i00 < args.nk0;) {
|
|
7039
7737
|
T4x4 temp;
|
|
7040
7738
|
dequantize_func(src_data + i00/nl, i00%nl, temp);
|
|
7041
7739
|
dst_data[i00] = temp;
|
|
@@ -7046,49 +7744,68 @@ kernel void kernel_cpy_q_f32(
|
|
|
7046
7744
|
|
|
7047
7745
|
typedef decltype(kernel_cpy_q_f32<float4x4, block_q4_0, 2, dequantize_q4_0>) cpy_q_f_t;
|
|
7048
7746
|
|
|
7747
|
+
template [[host_name("kernel_cpy_q1_0_f32")]] kernel cpy_q_f_t kernel_cpy_q_f32<float4x4, block_q1_0, 8, dequantize_q1_0>;
|
|
7049
7748
|
template [[host_name("kernel_cpy_q4_0_f32")]] kernel cpy_q_f_t kernel_cpy_q_f32<float4x4, block_q4_0, 2, dequantize_q4_0>;
|
|
7050
7749
|
template [[host_name("kernel_cpy_q4_1_f32")]] kernel cpy_q_f_t kernel_cpy_q_f32<float4x4, block_q4_1, 2, dequantize_q4_1>;
|
|
7051
7750
|
template [[host_name("kernel_cpy_q5_0_f32")]] kernel cpy_q_f_t kernel_cpy_q_f32<float4x4, block_q5_0, 2, dequantize_q5_0>;
|
|
7052
7751
|
template [[host_name("kernel_cpy_q5_1_f32")]] kernel cpy_q_f_t kernel_cpy_q_f32<float4x4, block_q5_1, 2, dequantize_q5_1>;
|
|
7053
7752
|
template [[host_name("kernel_cpy_q8_0_f32")]] kernel cpy_q_f_t kernel_cpy_q_f32<float4x4, block_q8_0, 2, dequantize_q8_0>;
|
|
7054
7753
|
|
|
7754
|
+
template [[host_name("kernel_cpy_q1_0_f16")]] kernel cpy_q_f_t kernel_cpy_q_f32<half4x4, block_q1_0, 8, dequantize_q1_0>;
|
|
7055
7755
|
template [[host_name("kernel_cpy_q4_0_f16")]] kernel cpy_q_f_t kernel_cpy_q_f32<half4x4, block_q4_0, 2, dequantize_q4_0>;
|
|
7056
7756
|
template [[host_name("kernel_cpy_q4_1_f16")]] kernel cpy_q_f_t kernel_cpy_q_f32<half4x4, block_q4_1, 2, dequantize_q4_1>;
|
|
7057
7757
|
template [[host_name("kernel_cpy_q5_0_f16")]] kernel cpy_q_f_t kernel_cpy_q_f32<half4x4, block_q5_0, 2, dequantize_q5_0>;
|
|
7058
7758
|
template [[host_name("kernel_cpy_q5_1_f16")]] kernel cpy_q_f_t kernel_cpy_q_f32<half4x4, block_q5_1, 2, dequantize_q5_1>;
|
|
7059
7759
|
template [[host_name("kernel_cpy_q8_0_f16")]] kernel cpy_q_f_t kernel_cpy_q_f32<half4x4, block_q8_0, 2, dequantize_q8_0>;
|
|
7060
7760
|
|
|
7761
|
+
template<typename T>
|
|
7061
7762
|
kernel void kernel_concat(
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7763
|
+
constant ggml_metal_kargs_concat & args,
|
|
7764
|
+
device const char * src0,
|
|
7765
|
+
device const char * src1,
|
|
7766
|
+
device char * dst,
|
|
7767
|
+
uint3 tgpig[[threadgroup_position_in_grid]],
|
|
7768
|
+
ushort3 tpitg[[thread_position_in_threadgroup]],
|
|
7769
|
+
ushort3 ntg[[threads_per_threadgroup]]) {
|
|
7069
7770
|
|
|
7070
7771
|
const int i3 = tgpig.z;
|
|
7071
7772
|
const int i2 = tgpig.y;
|
|
7072
|
-
const int i1 = tgpig.x;
|
|
7773
|
+
const int i1 = ntg.y == 1 ? tgpig.x : tgpig.x*ntg.y + tpitg.y;
|
|
7774
|
+
|
|
7775
|
+
if (i1 >= args.ne1) {
|
|
7776
|
+
return;
|
|
7777
|
+
}
|
|
7073
7778
|
|
|
7074
7779
|
int o[4] = {0, 0, 0, 0};
|
|
7075
7780
|
o[args.dim] = args.dim == 0 ? args.ne00 : (args.dim == 1 ? args.ne01 : (args.dim == 2 ? args.ne02 : args.ne03));
|
|
7076
7781
|
|
|
7077
|
-
device const float * x;
|
|
7078
|
-
|
|
7079
7782
|
for (int i0 = tpitg.x; i0 < args.ne0; i0 += ntg.x) {
|
|
7783
|
+
device const T * x;
|
|
7784
|
+
|
|
7080
7785
|
if (i0 < args.ne00 && i1 < args.ne01 && i2 < args.ne02 && i3 < args.ne03) {
|
|
7081
|
-
x = (device const
|
|
7786
|
+
x = (device const T *)(src0 + (i3 )*args.nb03 + (i2 )*args.nb02 + (i1 )*args.nb01 + (i0 )*args.nb00);
|
|
7082
7787
|
} else {
|
|
7083
|
-
x = (device const
|
|
7788
|
+
x = (device const T *)(src1 + (i3 - o[3])*args.nb13 + (i2 - o[2])*args.nb12 + (i1 - o[1])*args.nb11 + (i0 - o[0])*args.nb10);
|
|
7084
7789
|
}
|
|
7085
7790
|
|
|
7086
|
-
device
|
|
7791
|
+
device T * y = (device T *)(dst + i3*args.nb3 + i2*args.nb2 + i1*args.nb1 + i0*args.nb0);
|
|
7087
7792
|
|
|
7088
7793
|
*y = *x;
|
|
7089
7794
|
}
|
|
7090
7795
|
}
|
|
7091
7796
|
|
|
7797
|
+
typedef decltype(kernel_concat<float>) kernel_concat_t;
|
|
7798
|
+
|
|
7799
|
+
template [[host_name("kernel_concat_f32")]] kernel kernel_concat_t kernel_concat<float>;
|
|
7800
|
+
template [[host_name("kernel_concat_f16")]] kernel kernel_concat_t kernel_concat<half>;
|
|
7801
|
+
#if defined(GGML_METAL_HAS_BF16)
|
|
7802
|
+
template [[host_name("kernel_concat_bf16")]] kernel kernel_concat_t kernel_concat<bfloat>;
|
|
7803
|
+
#endif
|
|
7804
|
+
template [[host_name("kernel_concat_i8")]] kernel kernel_concat_t kernel_concat<char>;
|
|
7805
|
+
template [[host_name("kernel_concat_i16")]] kernel kernel_concat_t kernel_concat<short>;
|
|
7806
|
+
template [[host_name("kernel_concat_i32")]] kernel kernel_concat_t kernel_concat<int>;
|
|
7807
|
+
template [[host_name("kernel_concat_i64")]] kernel kernel_concat_t kernel_concat<long>;
|
|
7808
|
+
|
|
7092
7809
|
template<int nr0, typename args_t>
|
|
7093
7810
|
void kernel_mul_mv_q2_K_f32_impl(
|
|
7094
7811
|
args_t args,
|
|
@@ -7109,10 +7826,10 @@ void kernel_mul_mv_q2_K_f32_impl(
|
|
|
7109
7826
|
|
|
7110
7827
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
7111
7828
|
|
|
7112
|
-
const uint i12 = im%
|
|
7113
|
-
const uint i13 = im/
|
|
7829
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
7830
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
7114
7831
|
|
|
7115
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
7832
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
7116
7833
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
7117
7834
|
|
|
7118
7835
|
device const block_q2_K * x = (device const block_q2_K *) (src0 + offset0);
|
|
@@ -7214,10 +7931,10 @@ void kernel_mul_mv_q3_K_f32_impl(
|
|
|
7214
7931
|
|
|
7215
7932
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
7216
7933
|
|
|
7217
|
-
const uint i12 = im%
|
|
7218
|
-
const uint i13 = im/
|
|
7934
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
7935
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
7219
7936
|
|
|
7220
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
7937
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
7221
7938
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
7222
7939
|
|
|
7223
7940
|
device const block_q3_K * x = (device const block_q3_K *) (src0 + offset0);
|
|
@@ -7388,10 +8105,10 @@ void kernel_mul_mv_q4_K_f32_impl(
|
|
|
7388
8105
|
|
|
7389
8106
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
7390
8107
|
|
|
7391
|
-
const uint i12 = im%
|
|
7392
|
-
const uint i13 = im/
|
|
8108
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
8109
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
7393
8110
|
|
|
7394
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
8111
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
7395
8112
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
7396
8113
|
|
|
7397
8114
|
device const block_q4_K * x = (device const block_q4_K *) (src0 + offset0);
|
|
@@ -7500,10 +8217,10 @@ void kernel_mul_mv_q5_K_f32_impl(
|
|
|
7500
8217
|
|
|
7501
8218
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
7502
8219
|
|
|
7503
|
-
const uint i12 = im%
|
|
7504
|
-
const uint i13 = im/
|
|
8220
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
8221
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
7505
8222
|
|
|
7506
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
8223
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
7507
8224
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
7508
8225
|
|
|
7509
8226
|
device const block_q5_K * x = (device const block_q5_K *) (src0 + offset0);
|
|
@@ -7636,10 +8353,10 @@ void kernel_mul_mv_q6_K_f32_impl(
|
|
|
7636
8353
|
|
|
7637
8354
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
7638
8355
|
|
|
7639
|
-
const uint i12 = im%
|
|
7640
|
-
const uint i13 = im/
|
|
8356
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
8357
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
7641
8358
|
|
|
7642
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
8359
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
7643
8360
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
7644
8361
|
|
|
7645
8362
|
device const block_q6_K * x = (device const block_q6_K *) (src0 + offset0);
|
|
@@ -7741,10 +8458,10 @@ void kernel_mul_mv_iq2_xxs_f32_impl(
|
|
|
7741
8458
|
|
|
7742
8459
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
7743
8460
|
|
|
7744
|
-
const uint i12 = im%
|
|
7745
|
-
const uint i13 = im/
|
|
8461
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
8462
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
7746
8463
|
|
|
7747
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
8464
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
7748
8465
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
7749
8466
|
|
|
7750
8467
|
device const block_iq2_xxs * x = (device const block_iq2_xxs *) (src0 + offset0);
|
|
@@ -7849,10 +8566,10 @@ void kernel_mul_mv_iq2_xs_f32_impl(
|
|
|
7849
8566
|
|
|
7850
8567
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
7851
8568
|
|
|
7852
|
-
const uint i12 = im%
|
|
7853
|
-
const uint i13 = im/
|
|
8569
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
8570
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
7854
8571
|
|
|
7855
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
8572
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
7856
8573
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
7857
8574
|
|
|
7858
8575
|
device const block_iq2_xs * x = (device const block_iq2_xs *) (src0 + offset0);
|
|
@@ -7968,10 +8685,10 @@ void kernel_mul_mv_iq3_xxs_f32_impl(
|
|
|
7968
8685
|
|
|
7969
8686
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
7970
8687
|
|
|
7971
|
-
const uint i12 = im%
|
|
7972
|
-
const uint i13 = im/
|
|
8688
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
8689
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
7973
8690
|
|
|
7974
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
8691
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
7975
8692
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
7976
8693
|
|
|
7977
8694
|
device const block_iq3_xxs * x = (device const block_iq3_xxs *) (src0 + offset0);
|
|
@@ -8080,10 +8797,10 @@ void kernel_mul_mv_iq3_s_f32_impl(
|
|
|
8080
8797
|
|
|
8081
8798
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
8082
8799
|
|
|
8083
|
-
const uint i12 = im%
|
|
8084
|
-
const uint i13 = im/
|
|
8800
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
8801
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
8085
8802
|
|
|
8086
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
8803
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
8087
8804
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
8088
8805
|
|
|
8089
8806
|
device const block_iq3_s * x = (device const block_iq3_s *) (src0 + offset0);
|
|
@@ -8192,10 +8909,10 @@ void kernel_mul_mv_iq2_s_f32_impl(
|
|
|
8192
8909
|
|
|
8193
8910
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
8194
8911
|
|
|
8195
|
-
const uint i12 = im%
|
|
8196
|
-
const uint i13 = im/
|
|
8912
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
8913
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
8197
8914
|
|
|
8198
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
8915
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
8199
8916
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
8200
8917
|
|
|
8201
8918
|
device const block_iq2_s * x = (device const block_iq2_s *) (src0 + offset0);
|
|
@@ -8305,10 +9022,10 @@ void kernel_mul_mv_iq1_s_f32_impl(
|
|
|
8305
9022
|
|
|
8306
9023
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
8307
9024
|
|
|
8308
|
-
const uint i12 = im%
|
|
8309
|
-
const uint i13 = im/
|
|
9025
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
9026
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
8310
9027
|
|
|
8311
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
9028
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
8312
9029
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
8313
9030
|
|
|
8314
9031
|
device const block_iq1_s * x = (device const block_iq1_s *) (src0 + offset0);
|
|
@@ -8404,10 +9121,10 @@ void kernel_mul_mv_iq1_m_f32_impl(
|
|
|
8404
9121
|
|
|
8405
9122
|
const int first_row = (r0 * NSG + sgitg) * nr0;
|
|
8406
9123
|
|
|
8407
|
-
const uint i12 = im%
|
|
8408
|
-
const uint i13 = im/
|
|
9124
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
9125
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
8409
9126
|
|
|
8410
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
9127
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
8411
9128
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
8412
9129
|
|
|
8413
9130
|
device const block_iq1_m * x = (device const block_iq1_m *) (src0 + offset0);
|
|
@@ -8513,10 +9230,10 @@ void kernel_mul_mv_iq4_nl_f32_impl(
|
|
|
8513
9230
|
|
|
8514
9231
|
const int first_row = (r0 * NSG + sgitg) * NR0;
|
|
8515
9232
|
|
|
8516
|
-
const uint i12 = im%
|
|
8517
|
-
const uint i13 = im/
|
|
9233
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
9234
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
8518
9235
|
|
|
8519
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
9236
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
8520
9237
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
8521
9238
|
|
|
8522
9239
|
device const block_iq4_nl * x = (device const block_iq4_nl *) (src0 + offset0);
|
|
@@ -8622,10 +9339,10 @@ void kernel_mul_mv_iq4_xs_f32_impl(
|
|
|
8622
9339
|
const int im = tgpig.z;
|
|
8623
9340
|
const int first_row = (r0 * NSG + sgitg) * NR0;
|
|
8624
9341
|
|
|
8625
|
-
const uint i12 = im%
|
|
8626
|
-
const uint i13 = im/
|
|
9342
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
9343
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
8627
9344
|
|
|
8628
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
9345
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
8629
9346
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
8630
9347
|
|
|
8631
9348
|
device const block_iq4_xs * x = (device const block_iq4_xs *) (src0 + offset0);
|
|
@@ -8733,10 +9450,10 @@ void kernel_mul_mv_mxfp4_f32_impl(
|
|
|
8733
9450
|
|
|
8734
9451
|
const int first_row = (r0 * NSG + sgitg) * NR0;
|
|
8735
9452
|
|
|
8736
|
-
const uint i12 = im%
|
|
8737
|
-
const uint i13 = im/
|
|
9453
|
+
const uint i12 = im%FC_mul_mv_ne12;
|
|
9454
|
+
const uint i13 = im/FC_mul_mv_ne12;
|
|
8738
9455
|
|
|
8739
|
-
const uint64_t offset0 = first_row*args.nb01 + (i12/
|
|
9456
|
+
const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
|
8740
9457
|
const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
|
8741
9458
|
|
|
8742
9459
|
device const block_mxfp4 * x = (device const block_mxfp4 *) (src0 + offset0);
|
|
@@ -8867,7 +9584,40 @@ kernel void kernel_get_rows_f(
|
|
|
8867
9584
|
}
|
|
8868
9585
|
}
|
|
8869
9586
|
|
|
8870
|
-
|
|
9587
|
+
typedef decltype(kernel_get_rows_f<float, float>) get_rows_f_t;
|
|
9588
|
+
|
|
9589
|
+
template [[host_name("kernel_get_rows_f32")]] kernel get_rows_f_t kernel_get_rows_f<float, float>;
|
|
9590
|
+
template [[host_name("kernel_get_rows_f16")]] kernel get_rows_f_t kernel_get_rows_f<half, float>;
|
|
9591
|
+
template [[host_name("kernel_get_rows_i32")]] kernel get_rows_f_t kernel_get_rows_f<int32_t, int32_t>;
|
|
9592
|
+
#if defined(GGML_METAL_HAS_BF16)
|
|
9593
|
+
template [[host_name("kernel_get_rows_bf16")]] kernel get_rows_f_t kernel_get_rows_f<bfloat, float>;
|
|
9594
|
+
#endif
|
|
9595
|
+
|
|
9596
|
+
typedef decltype(kernel_get_rows_q<block_q4_0, 2, dequantize_q4_0>) get_rows_q_t;
|
|
9597
|
+
|
|
9598
|
+
template [[host_name("kernel_get_rows_q1_0")]] kernel get_rows_q_t kernel_get_rows_q<block_q1_0, 8, dequantize_q1_0>;
|
|
9599
|
+
template [[host_name("kernel_get_rows_q4_0")]] kernel get_rows_q_t kernel_get_rows_q<block_q4_0, 2, dequantize_q4_0>;
|
|
9600
|
+
template [[host_name("kernel_get_rows_q4_1")]] kernel get_rows_q_t kernel_get_rows_q<block_q4_1, 2, dequantize_q4_1>;
|
|
9601
|
+
template [[host_name("kernel_get_rows_q5_0")]] kernel get_rows_q_t kernel_get_rows_q<block_q5_0, 2, dequantize_q5_0>;
|
|
9602
|
+
template [[host_name("kernel_get_rows_q5_1")]] kernel get_rows_q_t kernel_get_rows_q<block_q5_1, 2, dequantize_q5_1>;
|
|
9603
|
+
template [[host_name("kernel_get_rows_q8_0")]] kernel get_rows_q_t kernel_get_rows_q<block_q8_0, 2, dequantize_q8_0>;
|
|
9604
|
+
template [[host_name("kernel_get_rows_mxfp4")]] kernel get_rows_q_t kernel_get_rows_q<block_mxfp4, 2, dequantize_mxfp4>;
|
|
9605
|
+
template [[host_name("kernel_get_rows_q2_K")]] kernel get_rows_q_t kernel_get_rows_q<block_q2_K, QK_NL, dequantize_q2_K>;
|
|
9606
|
+
template [[host_name("kernel_get_rows_q3_K")]] kernel get_rows_q_t kernel_get_rows_q<block_q3_K, QK_NL, dequantize_q3_K>;
|
|
9607
|
+
template [[host_name("kernel_get_rows_q4_K")]] kernel get_rows_q_t kernel_get_rows_q<block_q4_K, QK_NL, dequantize_q4_K>;
|
|
9608
|
+
template [[host_name("kernel_get_rows_q5_K")]] kernel get_rows_q_t kernel_get_rows_q<block_q5_K, QK_NL, dequantize_q5_K>;
|
|
9609
|
+
template [[host_name("kernel_get_rows_q6_K")]] kernel get_rows_q_t kernel_get_rows_q<block_q6_K, QK_NL, dequantize_q6_K>;
|
|
9610
|
+
template [[host_name("kernel_get_rows_iq2_xxs")]] kernel get_rows_q_t kernel_get_rows_q<block_iq2_xxs, QK_NL, dequantize_iq2_xxs>;
|
|
9611
|
+
template [[host_name("kernel_get_rows_iq2_xs")]] kernel get_rows_q_t kernel_get_rows_q<block_iq2_xs, QK_NL, dequantize_iq2_xs>;
|
|
9612
|
+
template [[host_name("kernel_get_rows_iq3_xxs")]] kernel get_rows_q_t kernel_get_rows_q<block_iq3_xxs, QK_NL, dequantize_iq3_xxs>;
|
|
9613
|
+
template [[host_name("kernel_get_rows_iq3_s")]] kernel get_rows_q_t kernel_get_rows_q<block_iq3_s, QK_NL, dequantize_iq3_s>;
|
|
9614
|
+
template [[host_name("kernel_get_rows_iq2_s")]] kernel get_rows_q_t kernel_get_rows_q<block_iq2_s, QK_NL, dequantize_iq2_s>;
|
|
9615
|
+
template [[host_name("kernel_get_rows_iq1_s")]] kernel get_rows_q_t kernel_get_rows_q<block_iq1_s, QK_NL, dequantize_iq1_s>;
|
|
9616
|
+
template [[host_name("kernel_get_rows_iq1_m")]] kernel get_rows_q_t kernel_get_rows_q<block_iq1_m, QK_NL, dequantize_iq1_m>;
|
|
9617
|
+
template [[host_name("kernel_get_rows_iq4_nl")]] kernel get_rows_q_t kernel_get_rows_q<block_iq4_nl, 2, dequantize_iq4_nl>;
|
|
9618
|
+
template [[host_name("kernel_get_rows_iq4_xs")]] kernel get_rows_q_t kernel_get_rows_q<block_iq4_xs, QK_NL, dequantize_iq4_xs>;
|
|
9619
|
+
|
|
9620
|
+
template<typename TS, typename TI, typename block_q, void (*quantize_func)(device const float *, device block_q &)>
|
|
8871
9621
|
kernel void kernel_set_rows_q32(
|
|
8872
9622
|
constant ggml_metal_kargs_set_rows & args,
|
|
8873
9623
|
device const void * src0,
|
|
@@ -8891,14 +9641,14 @@ kernel void kernel_set_rows_q32(
|
|
|
8891
9641
|
const TI i1 = ((const device TI *) ((const device char *) src1 + i10*args.nb10 + i11*args.nb11 + i12*args.nb12))[0];
|
|
8892
9642
|
|
|
8893
9643
|
device block_q * dst_row = ( device block_q *) (( device char *) dst + i1*args.nb1 + i02*args.nb2 + i03*args.nb3);
|
|
8894
|
-
const device
|
|
9644
|
+
const device TS * src_row = (const device TS *) ((const device char *) src0 + i01*args.nb01 + i02*args.nb02 + i03*args.nb03);
|
|
8895
9645
|
|
|
8896
9646
|
for (int ind = tiitg%tptg.x; ind < args.nk0; ind += tptg.x) {
|
|
8897
9647
|
quantize_func(src_row + 32*ind, dst_row[ind]);
|
|
8898
9648
|
}
|
|
8899
9649
|
}
|
|
8900
9650
|
|
|
8901
|
-
template<typename
|
|
9651
|
+
template<typename TS, typename TI, typename TD>
|
|
8902
9652
|
kernel void kernel_set_rows_f(
|
|
8903
9653
|
constant ggml_metal_kargs_set_rows & args,
|
|
8904
9654
|
device const void * src0,
|
|
@@ -8921,14 +9671,47 @@ kernel void kernel_set_rows_f(
|
|
|
8921
9671
|
const int32_t i10 = i01;
|
|
8922
9672
|
const TI i1 = ((const device TI *) ((const device char *) src1 + i10*args.nb10 + i11*args.nb11 + i12*args.nb12))[0];
|
|
8923
9673
|
|
|
8924
|
-
device
|
|
8925
|
-
const device
|
|
9674
|
+
device TD * dst_row = ( device TD *) (( device char *) dst + i1*args.nb1 + i02*args.nb2 + i03*args.nb3);
|
|
9675
|
+
const device TS * src_row = (const device TS *) ((const device char *) src0 + i01*args.nb01 + i02*args.nb02 + i03*args.nb03);
|
|
8926
9676
|
|
|
8927
9677
|
for (int ind = tiitg%tptg.x; ind < args.nk0; ind += tptg.x) {
|
|
8928
|
-
dst_row[ind] = (
|
|
9678
|
+
dst_row[ind] = (TD) src_row[ind];
|
|
8929
9679
|
}
|
|
8930
9680
|
}
|
|
8931
9681
|
|
|
9682
|
+
typedef decltype(kernel_set_rows_f<float, int64_t, float>) set_rows_f_t;
|
|
9683
|
+
|
|
9684
|
+
template [[host_name("kernel_set_rows_f32_i64_f32")]] kernel set_rows_f_t kernel_set_rows_f<float, int64_t, float>;
|
|
9685
|
+
template [[host_name("kernel_set_rows_f32_i32_f32")]] kernel set_rows_f_t kernel_set_rows_f<float, int32_t, float>;
|
|
9686
|
+
template [[host_name("kernel_set_rows_f32_i64_f16")]] kernel set_rows_f_t kernel_set_rows_f<float, int64_t, half>;
|
|
9687
|
+
template [[host_name("kernel_set_rows_f32_i32_f16")]] kernel set_rows_f_t kernel_set_rows_f<float, int32_t, half>;
|
|
9688
|
+
#if defined(GGML_METAL_HAS_BF16)
|
|
9689
|
+
template [[host_name("kernel_set_rows_f32_i64_bf16")]] kernel set_rows_f_t kernel_set_rows_f<float, int64_t, bfloat>;
|
|
9690
|
+
template [[host_name("kernel_set_rows_f32_i32_bf16")]] kernel set_rows_f_t kernel_set_rows_f<float, int32_t, bfloat>;
|
|
9691
|
+
#endif
|
|
9692
|
+
|
|
9693
|
+
template [[host_name("kernel_set_rows_f16_i64_f16")]] kernel set_rows_f_t kernel_set_rows_f<half, int64_t, half>;
|
|
9694
|
+
template [[host_name("kernel_set_rows_f16_i32_f16")]] kernel set_rows_f_t kernel_set_rows_f<half, int32_t, half>;
|
|
9695
|
+
#if defined(GGML_METAL_HAS_BF16)
|
|
9696
|
+
template [[host_name("kernel_set_rows_bf16_i64_bf16")]] kernel set_rows_f_t kernel_set_rows_f<bfloat, int64_t, bfloat>;
|
|
9697
|
+
template [[host_name("kernel_set_rows_bf16_i32_bf16")]] kernel set_rows_f_t kernel_set_rows_f<bfloat, int32_t, bfloat>;
|
|
9698
|
+
#endif
|
|
9699
|
+
|
|
9700
|
+
typedef decltype(kernel_set_rows_q32<float, int64_t, block_q8_0, quantize_q8_0>) set_rows_q32_t;
|
|
9701
|
+
|
|
9702
|
+
template [[host_name("kernel_set_rows_f32_i64_q8_0")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int64_t, block_q8_0, quantize_q8_0>;
|
|
9703
|
+
template [[host_name("kernel_set_rows_f32_i32_q8_0")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int32_t, block_q8_0, quantize_q8_0>;
|
|
9704
|
+
template [[host_name("kernel_set_rows_f32_i64_q4_0")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int64_t, block_q4_0, quantize_q4_0>;
|
|
9705
|
+
template [[host_name("kernel_set_rows_f32_i32_q4_0")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int32_t, block_q4_0, quantize_q4_0>;
|
|
9706
|
+
template [[host_name("kernel_set_rows_f32_i64_q4_1")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int64_t, block_q4_1, quantize_q4_1>;
|
|
9707
|
+
template [[host_name("kernel_set_rows_f32_i32_q4_1")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int32_t, block_q4_1, quantize_q4_1>;
|
|
9708
|
+
template [[host_name("kernel_set_rows_f32_i64_q5_0")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int64_t, block_q5_0, quantize_q5_0>;
|
|
9709
|
+
template [[host_name("kernel_set_rows_f32_i32_q5_0")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int32_t, block_q5_0, quantize_q5_0>;
|
|
9710
|
+
template [[host_name("kernel_set_rows_f32_i64_q5_1")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int64_t, block_q5_1, quantize_q5_1>;
|
|
9711
|
+
template [[host_name("kernel_set_rows_f32_i32_q5_1")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int32_t, block_q5_1, quantize_q5_1>;
|
|
9712
|
+
template [[host_name("kernel_set_rows_f32_i64_iq4_nl")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int64_t, block_iq4_nl, quantize_iq4_nl>;
|
|
9713
|
+
template [[host_name("kernel_set_rows_f32_i32_iq4_nl")]] kernel set_rows_q32_t kernel_set_rows_q32<float, int32_t, block_iq4_nl, quantize_iq4_nl>;
|
|
9714
|
+
|
|
8932
9715
|
kernel void kernel_diag_f32(
|
|
8933
9716
|
constant ggml_metal_kargs_diag & args,
|
|
8934
9717
|
device const char * src0,
|
|
@@ -8951,9 +9734,143 @@ kernel void kernel_diag_f32(
|
|
|
8951
9734
|
|
|
8952
9735
|
constant bool FC_mul_mm_bc_inp [[function_constant(FC_MUL_MM + 0)]];
|
|
8953
9736
|
constant bool FC_mul_mm_bc_out [[function_constant(FC_MUL_MM + 1)]];
|
|
9737
|
+
constant short FC_mul_mm_ne12 [[function_constant(FC_MUL_MM + 2)]];
|
|
9738
|
+
constant short FC_mul_mm_ne13 [[function_constant(FC_MUL_MM + 3)]];
|
|
9739
|
+
constant short FC_mul_mm_r2 [[function_constant(FC_MUL_MM + 4)]];
|
|
9740
|
+
constant short FC_mul_mm_r3 [[function_constant(FC_MUL_MM + 5)]];
|
|
8954
9741
|
|
|
8955
9742
|
// each block_q contains 16*nl weights
|
|
8956
|
-
|
|
9743
|
+
#ifdef GGML_METAL_HAS_TENSOR
|
|
9744
|
+
template<
|
|
9745
|
+
typename SA, typename SA_4x4, typename SA_8x8,
|
|
9746
|
+
typename SB, typename SB_2x4, typename SB_8x8,
|
|
9747
|
+
typename block_q, short nl, void (*dequantize_func)(device const block_q *, short, thread SA_4x4 &),
|
|
9748
|
+
typename T0, typename T0_4x4, typename T1, typename T1_2x4>
|
|
9749
|
+
kernel void kernel_mul_mm(
|
|
9750
|
+
constant ggml_metal_kargs_mul_mm & args,
|
|
9751
|
+
device const char * srcA,
|
|
9752
|
+
device const char * srcB,
|
|
9753
|
+
device char * dst,
|
|
9754
|
+
threadgroup char * shmem [[threadgroup(0)]],
|
|
9755
|
+
uint3 tgpig [[threadgroup_position_in_grid]],
|
|
9756
|
+
ushort tiitg [[thread_index_in_threadgroup]],
|
|
9757
|
+
ushort sgitg [[simdgroup_index_in_threadgroup]]) {
|
|
9758
|
+
(void) sgitg;
|
|
9759
|
+
|
|
9760
|
+
// Matrix dimensions: A(M,K) x B(K,N) -> C(M,N)
|
|
9761
|
+
const int K = args.ne00;
|
|
9762
|
+
const int M = args.ne0;
|
|
9763
|
+
const int N = args.ne1;
|
|
9764
|
+
|
|
9765
|
+
// Batch dimension handling
|
|
9766
|
+
const int im = tgpig.z;
|
|
9767
|
+
const int i12 = im % FC_mul_mm_ne12;
|
|
9768
|
+
const int i13 = im / FC_mul_mm_ne12;
|
|
9769
|
+
|
|
9770
|
+
// Batch offsets for srcA and srcB
|
|
9771
|
+
const uint64_t offset0 = (i12/FC_mul_mm_r2)*args.nb02 + (i13/FC_mul_mm_r3)*args.nb03;
|
|
9772
|
+
|
|
9773
|
+
// Tile dimensions
|
|
9774
|
+
constexpr int NRB = SZ_SIMDGROUP * N_MM_BLOCK_X * N_MM_SIMD_GROUP_X;
|
|
9775
|
+
constexpr int NRA = SZ_SIMDGROUP * N_MM_BLOCK_Y * N_MM_SIMD_GROUP_Y;
|
|
9776
|
+
|
|
9777
|
+
// Tile offsets in output matrix
|
|
9778
|
+
const int ra = tgpig.y * NRA;
|
|
9779
|
+
const int rb = tgpig.x * NRB;
|
|
9780
|
+
|
|
9781
|
+
// Threadgroup memory for dequantized A tile only
|
|
9782
|
+
threadgroup SA * sa = (threadgroup SA *)(shmem);
|
|
9783
|
+
|
|
9784
|
+
// Work-item count for A loading
|
|
9785
|
+
constexpr int A_WORK_ITEMS = NRA * N_MM_NK;
|
|
9786
|
+
constexpr int NUM_THREADS = N_SIMDWIDTH * N_MM_SIMD_GROUP_X * N_MM_SIMD_GROUP_Y;
|
|
9787
|
+
|
|
9788
|
+
// tA wraps threadgroup memory
|
|
9789
|
+
auto tA = tensor(sa, dextents<int32_t, 2>(N_MM_NK_TOTAL, NRA));
|
|
9790
|
+
|
|
9791
|
+
// tB wraps device memory directly
|
|
9792
|
+
device T1 * ptrB = (device T1 *)(srcB + args.nb12*i12 + args.nb13*i13);
|
|
9793
|
+
const int strideB = args.nb11 / sizeof(T1);
|
|
9794
|
+
auto tB = tensor(ptrB, dextents<int32_t, 2>(K, N), array<int, 2>({1, strideB}));
|
|
9795
|
+
|
|
9796
|
+
// Configure matmul operation
|
|
9797
|
+
mpp::tensor_ops::matmul2d<
|
|
9798
|
+
mpp::tensor_ops::matmul2d_descriptor(
|
|
9799
|
+
NRB, NRA, N_MM_NK_TOTAL, false, true, true,
|
|
9800
|
+
mpp::tensor_ops::matmul2d_descriptor::mode::multiply_accumulate),
|
|
9801
|
+
execution_simdgroups<N_MM_SIMD_GROUP_X * N_MM_SIMD_GROUP_Y>> mm;
|
|
9802
|
+
|
|
9803
|
+
auto cT = mm.get_destination_cooperative_tensor<decltype(tB), decltype(tA), float>();
|
|
9804
|
+
|
|
9805
|
+
// Accumulate partial results over K dimension
|
|
9806
|
+
for (int loop_k = 0; loop_k < K; loop_k += N_MM_NK_TOTAL) {
|
|
9807
|
+
// === PHASE 1: Dequantization of A into threadgroup memory ===
|
|
9808
|
+
for (int work = tiitg; work < A_WORK_ITEMS; work += NUM_THREADS) {
|
|
9809
|
+
const int row = work / N_MM_NK;
|
|
9810
|
+
const int k_chunk = work % N_MM_NK;
|
|
9811
|
+
const int k_pos = loop_k + k_chunk * 16;
|
|
9812
|
+
const short k_base = k_chunk * 16;
|
|
9813
|
+
|
|
9814
|
+
// Bounds check: skip device read if row is out of matrix bounds
|
|
9815
|
+
if (ra + row < M) {
|
|
9816
|
+
if (is_same<T0_4x4, block_q>::value && FC_mul_mm_bc_inp) {
|
|
9817
|
+
// Element-wise reads when K is not aligned (nb01 not aligned for half4x4/float4x4).
|
|
9818
|
+
// MSL spec Table 2.5: half4x4 requires 8-byte alignment. When K is odd,
|
|
9819
|
+
// nb01 = K*2 is not 8-byte aligned, so odd-row pointers are misaligned.
|
|
9820
|
+
// Mirrors the legacy kernel's existing guard.
|
|
9821
|
+
device const T0 * row_ptr = (device const T0 *)(srcA + args.nb01 * (ra + row) + offset0);
|
|
9822
|
+
|
|
9823
|
+
FOR_UNROLL (short i = 0; i < 16; i++) {
|
|
9824
|
+
sa[row * N_MM_NK_TOTAL + (k_base + i)] = (k_pos + i < K) ? (SA) row_ptr[k_pos + i] : (SA)0;
|
|
9825
|
+
}
|
|
9826
|
+
} else {
|
|
9827
|
+
const int block_idx = k_pos / (16 * nl);
|
|
9828
|
+
const short il = (k_pos / 16) % nl;
|
|
9829
|
+
|
|
9830
|
+
device const block_q * row_ptr = (device const block_q *)(srcA + args.nb01 * (ra + row) + offset0);
|
|
9831
|
+
|
|
9832
|
+
SA_4x4 temp_a;
|
|
9833
|
+
dequantize_func(row_ptr + block_idx, il, temp_a);
|
|
9834
|
+
|
|
9835
|
+
FOR_UNROLL (short i = 0; i < 16; i++) {
|
|
9836
|
+
// Zero-pad A for K positions beyond valid range (handles partial K iterations)
|
|
9837
|
+
sa[row * N_MM_NK_TOTAL + (k_base + i)] = (k_pos + i < K) ? temp_a[i/4][i%4] : (SA)0;
|
|
9838
|
+
}
|
|
9839
|
+
}
|
|
9840
|
+
} else {
|
|
9841
|
+
// Zero-pad rows beyond matrix bounds
|
|
9842
|
+
FOR_UNROLL (short i = 0; i < 16; i++) {
|
|
9843
|
+
sa[row * N_MM_NK_TOTAL + (k_base + i)] = (SA)0;
|
|
9844
|
+
}
|
|
9845
|
+
}
|
|
9846
|
+
}
|
|
9847
|
+
|
|
9848
|
+
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
9849
|
+
|
|
9850
|
+
// === PHASE 2: Tensor matmul ===
|
|
9851
|
+
auto mA = tA.slice(0, 0);
|
|
9852
|
+
auto mB = tB.slice(loop_k, rb);
|
|
9853
|
+
|
|
9854
|
+
mm.run(mB, mA, cT);
|
|
9855
|
+
|
|
9856
|
+
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
9857
|
+
}
|
|
9858
|
+
|
|
9859
|
+
// Store result tile to output matrix (with batch offset)
|
|
9860
|
+
// cT.store handles bounds checking via tD's extents (M, N)
|
|
9861
|
+
device float * dstBatch = (device float *)dst + im * N * M;
|
|
9862
|
+
|
|
9863
|
+
auto tD = tensor(dstBatch, dextents<int32_t, 2>(M, N), array<int, 2>({1, M}));
|
|
9864
|
+
cT.store(tD.slice(ra, rb));
|
|
9865
|
+
}
|
|
9866
|
+
|
|
9867
|
+
#else
|
|
9868
|
+
|
|
9869
|
+
template<
|
|
9870
|
+
typename S0, typename S0_4x4, typename S0_8x8,
|
|
9871
|
+
typename S1, typename S1_2x4, typename S1_8x8,
|
|
9872
|
+
typename block_q, short nl, void (*dequantize_func)(device const block_q *, short, thread S0_4x4 &),
|
|
9873
|
+
typename T0, typename T0_4x4, typename T1, typename T1_2x4>
|
|
8957
9874
|
kernel void kernel_mul_mm(
|
|
8958
9875
|
constant ggml_metal_kargs_mul_mm & args,
|
|
8959
9876
|
device const char * src0,
|
|
@@ -8967,10 +9884,6 @@ kernel void kernel_mul_mm(
|
|
|
8967
9884
|
threadgroup S0 * sa = (threadgroup S0 *)(shmem);
|
|
8968
9885
|
threadgroup S1 * sb = (threadgroup S1 *)(shmem + 4096);
|
|
8969
9886
|
|
|
8970
|
-
#ifdef GGML_METAL_HAS_TENSOR
|
|
8971
|
-
threadgroup float * sc = (threadgroup float *)(shmem);
|
|
8972
|
-
#endif
|
|
8973
|
-
|
|
8974
9887
|
constexpr int NR0 = 64;
|
|
8975
9888
|
constexpr int NR1 = 32;
|
|
8976
9889
|
|
|
@@ -8994,10 +9907,10 @@ kernel void kernel_mul_mm(
|
|
|
8994
9907
|
|
|
8995
9908
|
short il = il0;
|
|
8996
9909
|
|
|
8997
|
-
const int i12 = im%
|
|
8998
|
-
const int i13 = im/
|
|
9910
|
+
const int i12 = im % FC_mul_mm_ne12;
|
|
9911
|
+
const int i13 = im / FC_mul_mm_ne12;
|
|
8999
9912
|
|
|
9000
|
-
const uint64_t offset0 = (i12/
|
|
9913
|
+
const uint64_t offset0 = (i12/FC_mul_mm_r2)*args.nb02 + (i13/FC_mul_mm_r3)*args.nb03;
|
|
9001
9914
|
const short offset1 = il0/nl;
|
|
9002
9915
|
|
|
9003
9916
|
device const block_q * x = (device const block_q *)(src0 + args.nb01*(r0 + lr0) + offset0) + offset1;
|
|
@@ -9010,7 +9923,6 @@ kernel void kernel_mul_mm(
|
|
|
9010
9923
|
+ args.nb11*(r1 + lr1)
|
|
9011
9924
|
+ args.nb10*iy);
|
|
9012
9925
|
|
|
9013
|
-
#ifndef GGML_METAL_HAS_TENSOR
|
|
9014
9926
|
S0_8x8 ma[4];
|
|
9015
9927
|
S1_8x8 mb[2];
|
|
9016
9928
|
|
|
@@ -9019,19 +9931,8 @@ kernel void kernel_mul_mm(
|
|
|
9019
9931
|
for (short i = 0; i < 8; i++){
|
|
9020
9932
|
mc[i] = make_filled_simdgroup_matrix<float, 8>(0.f);
|
|
9021
9933
|
}
|
|
9022
|
-
#else
|
|
9023
|
-
auto tA = tensor<threadgroup S0, dextents<int32_t, 2>, tensor_inline>(sa, dextents<int32_t, 2>(NK, NR0));
|
|
9024
|
-
auto tB = tensor<threadgroup S1, dextents<int32_t, 2>, tensor_inline>(sb, dextents<int32_t, 2>(NR1, NK ));
|
|
9025
|
-
|
|
9026
|
-
mpp::tensor_ops::matmul2d<
|
|
9027
|
-
mpp::tensor_ops::matmul2d_descriptor(NR1, NR0, NK, false, true, false, mpp::tensor_ops::matmul2d_descriptor::mode::multiply_accumulate),
|
|
9028
|
-
execution_simdgroups<4>> mm;
|
|
9029
|
-
|
|
9030
|
-
auto cT = mm.get_destination_cooperative_tensor<decltype(tA), decltype(tB), float>();
|
|
9031
|
-
#endif
|
|
9032
9934
|
|
|
9033
9935
|
for (int loop_k = 0; loop_k < args.ne00; loop_k += NK) {
|
|
9034
|
-
#ifndef GGML_METAL_HAS_TENSOR
|
|
9035
9936
|
// load data and store to threadgroup memory
|
|
9036
9937
|
if (is_same<T0_4x4, block_q>::value && FC_mul_mm_bc_inp) {
|
|
9037
9938
|
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
@@ -9101,66 +10002,6 @@ kernel void kernel_mul_mm(
|
|
|
9101
10002
|
|
|
9102
10003
|
*(threadgroup S1_2x4 *)(sb + 64*ib + 8*ly) = (S1_2x4)(*((device T1_2x4 *) y));
|
|
9103
10004
|
}
|
|
9104
|
-
#else
|
|
9105
|
-
// load data and store to threadgroup memory
|
|
9106
|
-
if (is_same<T0_4x4, block_q>::value && FC_mul_mm_bc_inp) {
|
|
9107
|
-
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
9108
|
-
|
|
9109
|
-
// no need for dequantization
|
|
9110
|
-
for (short i = 0; i < 16; i++) {
|
|
9111
|
-
const short sx = 2*il0 + i/8;
|
|
9112
|
-
const short sy = (tiitg/NL0)/8;
|
|
9113
|
-
|
|
9114
|
-
const short lx = i%8;
|
|
9115
|
-
const short ly = (tiitg/NL0)%8;
|
|
9116
|
-
//const short lx = (tiitg/NL0)%8;
|
|
9117
|
-
//const short ly = i%8;
|
|
9118
|
-
|
|
9119
|
-
*(sa + NK*(8*sy + ly) + 8*sx + lx) = loop_k + 16*il + i < args.ne00 ? *((device T0 *) x + i) : 0;
|
|
9120
|
-
}
|
|
9121
|
-
} else {
|
|
9122
|
-
S0_4x4 temp_a;
|
|
9123
|
-
dequantize_func(x, il, temp_a);
|
|
9124
|
-
|
|
9125
|
-
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
9126
|
-
|
|
9127
|
-
FOR_UNROLL (short i = 0; i < 16; i++) {
|
|
9128
|
-
const short sx = 2*il0 + i/8;
|
|
9129
|
-
const short sy = (tiitg/NL0)/8;
|
|
9130
|
-
|
|
9131
|
-
const short lx = i%8;
|
|
9132
|
-
const short ly = (tiitg/NL0)%8;
|
|
9133
|
-
//const short lx = (tiitg/NL0)%8;
|
|
9134
|
-
//const short ly = i%8;
|
|
9135
|
-
|
|
9136
|
-
*(sa + NK*(8*sy + ly) + 8*sx + lx) = temp_a[i/4][i%4];
|
|
9137
|
-
}
|
|
9138
|
-
}
|
|
9139
|
-
|
|
9140
|
-
if (FC_mul_mm_bc_inp) {
|
|
9141
|
-
for (short i = 0; i < 8; ++i) {
|
|
9142
|
-
const short sx = (tiitg%NL1);
|
|
9143
|
-
const short sy = (tiitg/NL1)/8;
|
|
9144
|
-
|
|
9145
|
-
const short lx = i;
|
|
9146
|
-
const short ly = (tiitg/NL1)%8;
|
|
9147
|
-
//const short lx = (tiitg/NL1)%8;
|
|
9148
|
-
//const short ly = i;
|
|
9149
|
-
|
|
9150
|
-
*(sb + NK*(8*sy + ly) + 8*sx + lx) = loop_k + iy + i < args.ne00 ? (S1) *((device T1 *) y + i) : 0;
|
|
9151
|
-
}
|
|
9152
|
-
} else {
|
|
9153
|
-
const short sx = (tiitg%NL1);
|
|
9154
|
-
const short sy = (tiitg/NL1)/8;
|
|
9155
|
-
|
|
9156
|
-
//const short lx = i;
|
|
9157
|
-
const short ly = (tiitg/NL1)%8;
|
|
9158
|
-
//const short lx = (tiitg/NL1)%8;
|
|
9159
|
-
//const short ly = i;
|
|
9160
|
-
|
|
9161
|
-
*(threadgroup S1_2x4 *)(sb + NK*(8*sy + ly) + 8*sx) = (S1_2x4)(*((device T1_2x4 *) y));
|
|
9162
|
-
}
|
|
9163
|
-
#endif
|
|
9164
10005
|
|
|
9165
10006
|
il = (il + 2 < nl) ? il + 2 : il % 2;
|
|
9166
10007
|
x = (il < 2) ? x + (2 + nl - 1)/nl : x;
|
|
@@ -9169,7 +10010,6 @@ kernel void kernel_mul_mm(
|
|
|
9169
10010
|
|
|
9170
10011
|
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
9171
10012
|
|
|
9172
|
-
#ifndef GGML_METAL_HAS_TENSOR
|
|
9173
10013
|
// load matrices from threadgroup memory and conduct outer products
|
|
9174
10014
|
threadgroup const S0 * lsma = (sa + 4*64*(sgitg%2));
|
|
9175
10015
|
threadgroup const S1 * lsmb = (sb + 2*64*(sgitg/2));
|
|
@@ -9196,24 +10036,10 @@ kernel void kernel_mul_mm(
|
|
|
9196
10036
|
lsma += 8*64;
|
|
9197
10037
|
lsmb += 4*64;
|
|
9198
10038
|
}
|
|
9199
|
-
#else
|
|
9200
|
-
auto sA = tA.slice(0, 0);
|
|
9201
|
-
auto sB = tB.slice(0, 0);
|
|
9202
|
-
|
|
9203
|
-
mm.run(sB, sA, cT);
|
|
9204
|
-
#endif
|
|
9205
10039
|
}
|
|
9206
10040
|
|
|
9207
10041
|
if (!FC_mul_mm_bc_out || (r0 + NR0 <= args.ne0 && r1 + NR1 <= args.ne1)) {
|
|
9208
10042
|
// if no bounds checks on the output are needed, we can directly write to device memory
|
|
9209
|
-
#ifdef GGML_METAL_HAS_TENSOR
|
|
9210
|
-
device float * C = (device float *) dst +
|
|
9211
|
-
r0 + \
|
|
9212
|
-
r1 * args.ne0 + im*args.ne1*args.ne0;
|
|
9213
|
-
|
|
9214
|
-
auto tC = tensor<device float, dextents<int32_t, 2>, tensor_inline>(C, dextents<int32_t, 2>(args.ne0, NR1));
|
|
9215
|
-
cT.store(tC);
|
|
9216
|
-
#else
|
|
9217
10043
|
device float * C = (device float *) dst +
|
|
9218
10044
|
(r0 + 32*(sgitg & 1)) + \
|
|
9219
10045
|
(r1 + 16*(sgitg >> 1)) * args.ne0 + im*args.ne1*args.ne0;
|
|
@@ -9221,21 +10047,15 @@ kernel void kernel_mul_mm(
|
|
|
9221
10047
|
for (short i = 0; i < 8; i++) {
|
|
9222
10048
|
simdgroup_store(mc[i], C + 8*(i%4) + 8*args.ne0*(i/4), args.ne0, 0, false);
|
|
9223
10049
|
}
|
|
9224
|
-
#endif
|
|
9225
10050
|
} else {
|
|
9226
10051
|
// block is smaller than 64x32, we should avoid writing data outside of the matrix
|
|
9227
10052
|
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
9228
10053
|
|
|
9229
10054
|
threadgroup float * temp_str = ((threadgroup float *) shmem) + 32*(sgitg&1) + (16*(sgitg >> 1))*NR0;
|
|
9230
10055
|
|
|
9231
|
-
#ifdef GGML_METAL_HAS_TENSOR
|
|
9232
|
-
auto tC = tensor<threadgroup float, dextents<int32_t, 2>, tensor_inline>(sc, dextents<int32_t, 2>(NR0, NR1));
|
|
9233
|
-
cT.store(tC);
|
|
9234
|
-
#else
|
|
9235
10056
|
for (short i = 0; i < 8; i++) {
|
|
9236
10057
|
simdgroup_store(mc[i], temp_str + 8*(i%4) + 8*NR0*(i/4), NR0, 0, false);
|
|
9237
10058
|
}
|
|
9238
|
-
#endif
|
|
9239
10059
|
|
|
9240
10060
|
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
9241
10061
|
|
|
@@ -9261,6 +10081,8 @@ kernel void kernel_mul_mm(
|
|
|
9261
10081
|
}
|
|
9262
10082
|
}
|
|
9263
10083
|
|
|
10084
|
+
#endif // GGML_METAL_HAS_TENSOR
|
|
10085
|
+
|
|
9264
10086
|
template<short ne20> // n_expert_used
|
|
9265
10087
|
kernel void kernel_mul_mm_id_map0(
|
|
9266
10088
|
constant ggml_metal_kargs_mul_mm_id_map0 & args,
|
|
@@ -9436,7 +10258,7 @@ kernel void kernel_mul_mm_id(
|
|
|
9436
10258
|
|
|
9437
10259
|
const short ib = 8*sx + sy;
|
|
9438
10260
|
|
|
9439
|
-
*(sa + 64*ib + 8*ly + lx) = loop_k + 16*il + i < args.ne00 ? *((device T0 *) x + i) : 0;
|
|
10261
|
+
*(sa + 64*ib + 8*ly + lx) = loop_k + 16*il + i < args.ne00 ? (S0) *((device T0 *) x + i) : (S0) 0;
|
|
9440
10262
|
}
|
|
9441
10263
|
} else {
|
|
9442
10264
|
S0_4x4 temp_a;
|
|
@@ -9632,74 +10454,6 @@ kernel void kernel_mul_mm_id(
|
|
|
9632
10454
|
}
|
|
9633
10455
|
}
|
|
9634
10456
|
|
|
9635
|
-
#define QK_NL 16
|
|
9636
|
-
|
|
9637
|
-
//
|
|
9638
|
-
// get rows
|
|
9639
|
-
//
|
|
9640
|
-
|
|
9641
|
-
typedef decltype(kernel_get_rows_f<float, float>) get_rows_f_t;
|
|
9642
|
-
|
|
9643
|
-
template [[host_name("kernel_get_rows_f32")]] kernel get_rows_f_t kernel_get_rows_f<float, float>;
|
|
9644
|
-
template [[host_name("kernel_get_rows_f16")]] kernel get_rows_f_t kernel_get_rows_f<half, float>;
|
|
9645
|
-
template [[host_name("kernel_get_rows_i32")]] kernel get_rows_f_t kernel_get_rows_f<int32_t, int32_t>;
|
|
9646
|
-
#if defined(GGML_METAL_HAS_BF16)
|
|
9647
|
-
template [[host_name("kernel_get_rows_bf16")]] kernel get_rows_f_t kernel_get_rows_f<bfloat, float>;
|
|
9648
|
-
#endif
|
|
9649
|
-
|
|
9650
|
-
typedef decltype(kernel_get_rows_q<block_q4_0, 2, dequantize_q4_0>) get_rows_q_t;
|
|
9651
|
-
|
|
9652
|
-
template [[host_name("kernel_get_rows_q4_0")]] kernel get_rows_q_t kernel_get_rows_q<block_q4_0, 2, dequantize_q4_0>;
|
|
9653
|
-
template [[host_name("kernel_get_rows_q4_1")]] kernel get_rows_q_t kernel_get_rows_q<block_q4_1, 2, dequantize_q4_1>;
|
|
9654
|
-
template [[host_name("kernel_get_rows_q5_0")]] kernel get_rows_q_t kernel_get_rows_q<block_q5_0, 2, dequantize_q5_0>;
|
|
9655
|
-
template [[host_name("kernel_get_rows_q5_1")]] kernel get_rows_q_t kernel_get_rows_q<block_q5_1, 2, dequantize_q5_1>;
|
|
9656
|
-
template [[host_name("kernel_get_rows_q8_0")]] kernel get_rows_q_t kernel_get_rows_q<block_q8_0, 2, dequantize_q8_0>;
|
|
9657
|
-
template [[host_name("kernel_get_rows_mxfp4")]] kernel get_rows_q_t kernel_get_rows_q<block_mxfp4, 2, dequantize_mxfp4>;
|
|
9658
|
-
template [[host_name("kernel_get_rows_q2_K")]] kernel get_rows_q_t kernel_get_rows_q<block_q2_K, QK_NL, dequantize_q2_K>;
|
|
9659
|
-
template [[host_name("kernel_get_rows_q3_K")]] kernel get_rows_q_t kernel_get_rows_q<block_q3_K, QK_NL, dequantize_q3_K>;
|
|
9660
|
-
template [[host_name("kernel_get_rows_q4_K")]] kernel get_rows_q_t kernel_get_rows_q<block_q4_K, QK_NL, dequantize_q4_K>;
|
|
9661
|
-
template [[host_name("kernel_get_rows_q5_K")]] kernel get_rows_q_t kernel_get_rows_q<block_q5_K, QK_NL, dequantize_q5_K>;
|
|
9662
|
-
template [[host_name("kernel_get_rows_q6_K")]] kernel get_rows_q_t kernel_get_rows_q<block_q6_K, QK_NL, dequantize_q6_K>;
|
|
9663
|
-
template [[host_name("kernel_get_rows_iq2_xxs")]] kernel get_rows_q_t kernel_get_rows_q<block_iq2_xxs, QK_NL, dequantize_iq2_xxs>;
|
|
9664
|
-
template [[host_name("kernel_get_rows_iq2_xs")]] kernel get_rows_q_t kernel_get_rows_q<block_iq2_xs, QK_NL, dequantize_iq2_xs>;
|
|
9665
|
-
template [[host_name("kernel_get_rows_iq3_xxs")]] kernel get_rows_q_t kernel_get_rows_q<block_iq3_xxs, QK_NL, dequantize_iq3_xxs>;
|
|
9666
|
-
template [[host_name("kernel_get_rows_iq3_s")]] kernel get_rows_q_t kernel_get_rows_q<block_iq3_s, QK_NL, dequantize_iq3_s>;
|
|
9667
|
-
template [[host_name("kernel_get_rows_iq2_s")]] kernel get_rows_q_t kernel_get_rows_q<block_iq2_s, QK_NL, dequantize_iq2_s>;
|
|
9668
|
-
template [[host_name("kernel_get_rows_iq1_s")]] kernel get_rows_q_t kernel_get_rows_q<block_iq1_s, QK_NL, dequantize_iq1_s>;
|
|
9669
|
-
template [[host_name("kernel_get_rows_iq1_m")]] kernel get_rows_q_t kernel_get_rows_q<block_iq1_m, QK_NL, dequantize_iq1_m>;
|
|
9670
|
-
template [[host_name("kernel_get_rows_iq4_nl")]] kernel get_rows_q_t kernel_get_rows_q<block_iq4_nl, 2, dequantize_iq4_nl>;
|
|
9671
|
-
template [[host_name("kernel_get_rows_iq4_xs")]] kernel get_rows_q_t kernel_get_rows_q<block_iq4_xs, QK_NL, dequantize_iq4_xs>;
|
|
9672
|
-
|
|
9673
|
-
//
|
|
9674
|
-
// set rows
|
|
9675
|
-
//
|
|
9676
|
-
|
|
9677
|
-
typedef decltype(kernel_set_rows_f<float, int64_t>) set_rows_f_t;
|
|
9678
|
-
|
|
9679
|
-
template [[host_name("kernel_set_rows_f32_i64")]] kernel set_rows_f_t kernel_set_rows_f<float, int64_t>;
|
|
9680
|
-
template [[host_name("kernel_set_rows_f32_i32")]] kernel set_rows_f_t kernel_set_rows_f<float, int32_t>;
|
|
9681
|
-
template [[host_name("kernel_set_rows_f16_i64")]] kernel set_rows_f_t kernel_set_rows_f<half, int64_t>;
|
|
9682
|
-
template [[host_name("kernel_set_rows_f16_i32")]] kernel set_rows_f_t kernel_set_rows_f<half, int32_t>;
|
|
9683
|
-
#if defined(GGML_METAL_HAS_BF16)
|
|
9684
|
-
template [[host_name("kernel_set_rows_bf16_i64")]] kernel set_rows_f_t kernel_set_rows_f<bfloat, int64_t>;
|
|
9685
|
-
template [[host_name("kernel_set_rows_bf16_i32")]] kernel set_rows_f_t kernel_set_rows_f<bfloat, int32_t>;
|
|
9686
|
-
#endif
|
|
9687
|
-
|
|
9688
|
-
typedef decltype(kernel_set_rows_q32<int64_t, block_q8_0, quantize_q8_0>) set_rows_q32_t;
|
|
9689
|
-
|
|
9690
|
-
template [[host_name("kernel_set_rows_q8_0_i64")]] kernel set_rows_q32_t kernel_set_rows_q32<int64_t, block_q8_0, quantize_q8_0>;
|
|
9691
|
-
template [[host_name("kernel_set_rows_q8_0_i32")]] kernel set_rows_q32_t kernel_set_rows_q32<int32_t, block_q8_0, quantize_q8_0>;
|
|
9692
|
-
template [[host_name("kernel_set_rows_q4_0_i64")]] kernel set_rows_q32_t kernel_set_rows_q32<int64_t, block_q4_0, quantize_q4_0>;
|
|
9693
|
-
template [[host_name("kernel_set_rows_q4_0_i32")]] kernel set_rows_q32_t kernel_set_rows_q32<int32_t, block_q4_0, quantize_q4_0>;
|
|
9694
|
-
template [[host_name("kernel_set_rows_q4_1_i64")]] kernel set_rows_q32_t kernel_set_rows_q32<int64_t, block_q4_1, quantize_q4_1>;
|
|
9695
|
-
template [[host_name("kernel_set_rows_q4_1_i32")]] kernel set_rows_q32_t kernel_set_rows_q32<int32_t, block_q4_1, quantize_q4_1>;
|
|
9696
|
-
template [[host_name("kernel_set_rows_q5_0_i64")]] kernel set_rows_q32_t kernel_set_rows_q32<int64_t, block_q5_0, quantize_q5_0>;
|
|
9697
|
-
template [[host_name("kernel_set_rows_q5_0_i32")]] kernel set_rows_q32_t kernel_set_rows_q32<int32_t, block_q5_0, quantize_q5_0>;
|
|
9698
|
-
template [[host_name("kernel_set_rows_q5_1_i64")]] kernel set_rows_q32_t kernel_set_rows_q32<int64_t, block_q5_1, quantize_q5_1>;
|
|
9699
|
-
template [[host_name("kernel_set_rows_q5_1_i32")]] kernel set_rows_q32_t kernel_set_rows_q32<int32_t, block_q5_1, quantize_q5_1>;
|
|
9700
|
-
template [[host_name("kernel_set_rows_iq4_nl_i64")]] kernel set_rows_q32_t kernel_set_rows_q32<int64_t, block_iq4_nl, quantize_iq4_nl>;
|
|
9701
|
-
template [[host_name("kernel_set_rows_iq4_nl_i32")]] kernel set_rows_q32_t kernel_set_rows_q32<int32_t, block_iq4_nl, quantize_iq4_nl>;
|
|
9702
|
-
|
|
9703
10457
|
//
|
|
9704
10458
|
// matrix-matrix multiplication
|
|
9705
10459
|
//
|
|
@@ -9711,6 +10465,7 @@ template [[host_name("kernel_mul_mm_f16_f32")]] kernel mul_mm_t kernel_mul_m
|
|
|
9711
10465
|
#if defined(GGML_METAL_HAS_BF16)
|
|
9712
10466
|
template [[host_name("kernel_mul_mm_bf16_f32")]] kernel mul_mm_t kernel_mul_mm<bfloat, bfloat4x4, simdgroup_bfloat8x8, bfloat, bfloat2x4, simdgroup_bfloat8x8, bfloat4x4, 1, dequantize_bf16, bfloat, bfloat4x4, float, float2x4>;
|
|
9713
10467
|
#endif
|
|
10468
|
+
template [[host_name("kernel_mul_mm_q1_0_f32")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q1_0, 8, dequantize_q1_0, float, float4x4, float, float2x4>;
|
|
9714
10469
|
template [[host_name("kernel_mul_mm_q4_0_f32")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q4_0, 2, dequantize_q4_0, float, float4x4, float, float2x4>;
|
|
9715
10470
|
template [[host_name("kernel_mul_mm_q4_1_f32")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q4_1, 2, dequantize_q4_1, float, float4x4, float, float2x4>;
|
|
9716
10471
|
template [[host_name("kernel_mul_mm_q5_0_f32")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q5_0, 2, dequantize_q5_0, float, float4x4, float, float2x4>;
|
|
@@ -9734,6 +10489,7 @@ template [[host_name("kernel_mul_mm_iq4_xs_f32")]] kernel mul_mm_t kernel_mul_m
|
|
|
9734
10489
|
|
|
9735
10490
|
template [[host_name("kernel_mul_mm_f32_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, float4x4, 1, dequantize_f32, float, float4x4, half, half2x4>;
|
|
9736
10491
|
template [[host_name("kernel_mul_mm_f16_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, half4x4, 1, dequantize_f16, half, half4x4, half, half2x4>;
|
|
10492
|
+
template [[host_name("kernel_mul_mm_q1_0_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q1_0, 8, dequantize_q1_0, float, float4x4, half, half2x4>;
|
|
9737
10493
|
template [[host_name("kernel_mul_mm_q4_0_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q4_0, 2, dequantize_q4_0, float, float4x4, half, half2x4>;
|
|
9738
10494
|
template [[host_name("kernel_mul_mm_q4_1_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q4_1, 2, dequantize_q4_1, float, float4x4, half, half2x4>;
|
|
9739
10495
|
template [[host_name("kernel_mul_mm_q5_0_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q5_0, 2, dequantize_q5_0, float, float4x4, half, half2x4>;
|
|
@@ -9766,6 +10522,7 @@ template [[host_name("kernel_mul_mm_id_f16_f32")]] kernel mul_mm_id kernel_m
|
|
|
9766
10522
|
#if defined(GGML_METAL_HAS_BF16)
|
|
9767
10523
|
template [[host_name("kernel_mul_mm_id_bf16_f32")]] kernel mul_mm_id kernel_mul_mm_id<bfloat, bfloat4x4, simdgroup_bfloat8x8, bfloat, bfloat2x4, simdgroup_bfloat8x8, bfloat4x4, 1, dequantize_bf16, bfloat, bfloat4x4, float, float2x4>;
|
|
9768
10524
|
#endif
|
|
10525
|
+
template [[host_name("kernel_mul_mm_id_q1_0_f32")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q1_0, 8, dequantize_q1_0, float, float4x4, float, float2x4>;
|
|
9769
10526
|
template [[host_name("kernel_mul_mm_id_q4_0_f32")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q4_0, 2, dequantize_q4_0, float, float4x4, float, float2x4>;
|
|
9770
10527
|
template [[host_name("kernel_mul_mm_id_q4_1_f32")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q4_1, 2, dequantize_q4_1, float, float4x4, float, float2x4>;
|
|
9771
10528
|
template [[host_name("kernel_mul_mm_id_q5_0_f32")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q5_0, 2, dequantize_q5_0, float, float4x4, float, float2x4>;
|
|
@@ -9789,6 +10546,7 @@ template [[host_name("kernel_mul_mm_id_iq4_xs_f32")]] kernel mul_mm_id kernel_m
|
|
|
9789
10546
|
|
|
9790
10547
|
template [[host_name("kernel_mul_mm_id_f32_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, float4x4, 1, dequantize_f32, float, float4x4, half, half2x4>;
|
|
9791
10548
|
template [[host_name("kernel_mul_mm_id_f16_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, half4x4, 1, dequantize_f16, half, half4x4, half, half2x4>;
|
|
10549
|
+
template [[host_name("kernel_mul_mm_id_q1_0_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q1_0, 8, dequantize_q1_0, float, float4x4, half, half2x4>;
|
|
9792
10550
|
template [[host_name("kernel_mul_mm_id_q4_0_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q4_0, 2, dequantize_q4_0, float, float4x4, half, half2x4>;
|
|
9793
10551
|
template [[host_name("kernel_mul_mm_id_q4_1_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q4_1, 2, dequantize_q4_1, float, float4x4, half, half2x4>;
|
|
9794
10552
|
template [[host_name("kernel_mul_mm_id_q5_0_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_q5_0, 2, dequantize_q5_0, float, float4x4, half, half2x4>;
|
|
@@ -9943,6 +10701,7 @@ template [[host_name("kernel_mul_mv_id_bf16_f32_4")]] kernel kernel_mul_mv_id_4
|
|
|
9943
10701
|
|
|
9944
10702
|
template [[host_name("kernel_mul_mv_id_q8_0_f32")]] kernel kernel_mul_mv_id_t kernel_mul_mv_id<mmv_fn<kernel_mul_mv_q8_0_f32_impl<N_R0_Q8_0>>>;
|
|
9945
10703
|
|
|
10704
|
+
template [[host_name("kernel_mul_mv_id_q1_0_f32")]] kernel kernel_mul_mv_id_t kernel_mul_mv_id<mmv_fn<kernel_mul_mv_q1_0_f32_impl<N_R0_Q1_0>>>;
|
|
9946
10705
|
template [[host_name("kernel_mul_mv_id_q4_0_f32")]] kernel kernel_mul_mv_id_t kernel_mul_mv_id<mmv_fn<mul_vec_q_n_f32_impl<block_q4_0, N_R0_Q4_0>>>;
|
|
9947
10706
|
template [[host_name("kernel_mul_mv_id_q4_1_f32")]] kernel kernel_mul_mv_id_t kernel_mul_mv_id<mmv_fn<mul_vec_q_n_f32_impl<block_q4_1, N_R0_Q4_1>>>;
|
|
9948
10707
|
template [[host_name("kernel_mul_mv_id_q5_0_f32")]] kernel kernel_mul_mv_id_t kernel_mul_mv_id<mmv_fn<mul_vec_q_n_f32_impl<block_q5_0, N_R0_Q5_0>>>;
|