whispercpp 1.3.5 → 1.3.6
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/LICENSE +1 -1
- data/README.md +99 -2
- data/ext/extconf.rb +1 -0
- data/ext/ruby_whisper.c +20 -4
- data/ext/ruby_whisper.h +30 -2
- data/ext/ruby_whisper_context.c +216 -124
- data/ext/ruby_whisper_context_params.c +163 -0
- data/ext/ruby_whisper_model.c +0 -1
- data/ext/ruby_whisper_params.c +0 -1
- data/ext/ruby_whisper_segment.c +0 -1
- data/ext/ruby_whisper_token.c +29 -9
- data/ext/ruby_whisper_transcribe.cpp +4 -1
- data/ext/ruby_whisper_vad_context.c +48 -1
- data/ext/ruby_whisper_vad_context_detect.cpp +6 -5
- data/ext/ruby_whisper_vad_params.c +0 -1
- data/ext/ruby_whisper_vad_segment.c +0 -1
- data/ext/ruby_whisper_vad_segments.c +0 -1
- data/ext/sources/CMakeLists.txt +1 -1
- data/ext/sources/bindings/javascript/package.json +1 -1
- data/ext/sources/cmake/whisper-config.cmake.in +5 -40
- data/ext/sources/examples/bench/bench.cpp +23 -18
- data/ext/sources/examples/cli/cli.cpp +8 -0
- data/ext/sources/examples/common-ggml.cpp +2 -0
- data/ext/sources/examples/miniaudio.h +4507 -2131
- data/ext/sources/examples/server/server.cpp +18 -4
- data/ext/sources/examples/talk-llama/CMakeLists.txt +3 -2
- data/ext/sources/examples/talk-llama/llama-adapter.cpp +7 -13
- data/ext/sources/examples/talk-llama/llama-adapter.h +4 -3
- data/ext/sources/examples/talk-llama/llama-arch.cpp +335 -17
- data/ext/sources/examples/talk-llama/llama-arch.h +42 -0
- data/ext/sources/examples/talk-llama/llama-batch.cpp +3 -1
- data/ext/sources/examples/talk-llama/llama-chat.cpp +21 -1
- data/ext/sources/examples/talk-llama/llama-chat.h +1 -0
- data/ext/sources/examples/talk-llama/llama-context.cpp +508 -520
- data/ext/sources/examples/talk-llama/llama-context.h +27 -28
- data/ext/sources/examples/talk-llama/llama-cparams.h +5 -0
- data/ext/sources/examples/talk-llama/llama-ext.h +12 -0
- data/ext/sources/examples/talk-llama/llama-grammar.cpp +8 -8
- data/ext/sources/examples/talk-llama/llama-graph.cpp +583 -130
- data/ext/sources/examples/talk-llama/llama-graph.h +131 -10
- data/ext/sources/examples/talk-llama/llama-hparams.cpp +57 -40
- data/ext/sources/examples/talk-llama/llama-hparams.h +79 -10
- data/ext/sources/examples/talk-llama/llama-impl.cpp +4 -4
- data/ext/sources/examples/talk-llama/llama-impl.h +13 -1
- data/ext/sources/examples/talk-llama/llama-kv-cache-iswa.cpp +3 -1
- data/ext/sources/examples/talk-llama/llama-kv-cache.cpp +274 -89
- data/ext/sources/examples/talk-llama/llama-kv-cache.h +2 -3
- data/ext/sources/examples/talk-llama/llama-memory-hybrid-iswa.cpp +275 -0
- data/ext/sources/examples/talk-llama/llama-memory-hybrid-iswa.h +140 -0
- data/ext/sources/examples/talk-llama/llama-memory-recurrent.cpp +11 -13
- data/ext/sources/examples/talk-llama/llama-mmap.cpp +28 -11
- data/ext/sources/examples/talk-llama/llama-model-loader.cpp +527 -119
- data/ext/sources/examples/talk-llama/llama-model-loader.h +35 -5
- data/ext/sources/examples/talk-llama/llama-model-saver.cpp +60 -46
- data/ext/sources/examples/talk-llama/llama-model-saver.h +5 -2
- data/ext/sources/examples/talk-llama/llama-model.cpp +1365 -647
- data/ext/sources/examples/talk-llama/llama-model.h +72 -19
- data/ext/sources/examples/talk-llama/llama-quant.cpp +578 -346
- data/ext/sources/examples/talk-llama/{llama-sampling.cpp → llama-sampler.cpp} +190 -76
- data/ext/sources/examples/talk-llama/{llama-sampling.h → llama-sampler.h} +0 -2
- data/ext/sources/examples/talk-llama/llama-vocab.cpp +118 -48
- data/ext/sources/examples/talk-llama/llama-vocab.h +5 -0
- data/ext/sources/examples/talk-llama/llama.cpp +76 -22
- data/ext/sources/examples/talk-llama/llama.h +63 -30
- data/ext/sources/examples/talk-llama/models/afmoe.cpp +2 -3
- data/ext/sources/examples/talk-llama/models/apertus.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/arcee.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/arctic.cpp +4 -5
- data/ext/sources/examples/talk-llama/models/baichuan.cpp +4 -3
- data/ext/sources/examples/talk-llama/models/bailingmoe.cpp +1 -2
- data/ext/sources/examples/talk-llama/models/bailingmoe2.cpp +3 -5
- data/ext/sources/examples/talk-llama/models/bert.cpp +13 -7
- data/ext/sources/examples/talk-llama/models/bitnet.cpp +9 -24
- data/ext/sources/examples/talk-llama/models/bloom.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/chameleon.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/chatglm.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/codeshell.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/cogvlm.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/cohere2-iswa.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/command-r.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/dbrx.cpp +4 -5
- data/ext/sources/examples/talk-llama/models/deci.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/deepseek.cpp +4 -6
- data/ext/sources/examples/talk-llama/models/deepseek2.cpp +24 -21
- data/ext/sources/examples/talk-llama/models/delta-net-base.cpp +445 -0
- data/ext/sources/examples/talk-llama/models/dots1.cpp +4 -6
- data/ext/sources/examples/talk-llama/models/dream.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/ernie4-5-moe.cpp +4 -6
- data/ext/sources/examples/talk-llama/models/ernie4-5.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/eurobert.cpp +97 -0
- data/ext/sources/examples/talk-llama/models/exaone-moe.cpp +145 -0
- data/ext/sources/examples/talk-llama/models/exaone.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/exaone4.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/falcon-h1.cpp +2 -4
- data/ext/sources/examples/talk-llama/models/falcon.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/gemma-embedding.cpp +1 -1
- data/ext/sources/examples/talk-llama/models/gemma.cpp +1 -1
- data/ext/sources/examples/talk-llama/models/gemma2-iswa.cpp +1 -1
- data/ext/sources/examples/talk-llama/models/gemma3.cpp +1 -1
- data/ext/sources/examples/talk-llama/models/gemma3n-iswa.cpp +7 -7
- data/ext/sources/examples/talk-llama/models/glm4-moe.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/glm4.cpp +14 -7
- data/ext/sources/examples/talk-llama/models/gpt2.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/gptneox.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/granite-hybrid.cpp +4 -5
- data/ext/sources/examples/talk-llama/models/granite.cpp +4 -5
- data/ext/sources/examples/talk-llama/models/grok.cpp +4 -4
- data/ext/sources/examples/talk-llama/models/grovemoe.cpp +5 -7
- data/ext/sources/examples/talk-llama/models/hunyuan-dense.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/hunyuan-moe.cpp +4 -5
- data/ext/sources/examples/talk-llama/models/internlm2.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/jais.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/jais2.cpp +123 -0
- data/ext/sources/examples/talk-llama/models/jamba.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/kimi-linear.cpp +381 -0
- data/ext/sources/examples/talk-llama/models/lfm2.cpp +145 -124
- data/ext/sources/examples/talk-llama/models/llada-moe.cpp +4 -4
- data/ext/sources/examples/talk-llama/models/llada.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/llama-iswa.cpp +4 -4
- data/ext/sources/examples/talk-llama/models/llama.cpp +18 -11
- data/ext/sources/examples/talk-llama/models/maincoder.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/{graph-context-mamba.cpp → mamba-base.cpp} +9 -3
- data/ext/sources/examples/talk-llama/models/mamba.cpp +1 -2
- data/ext/sources/examples/talk-llama/models/mimo2-iswa.cpp +11 -5
- data/ext/sources/examples/talk-llama/models/minicpm3.cpp +14 -13
- data/ext/sources/examples/talk-llama/models/minimax-m2.cpp +4 -5
- data/ext/sources/examples/talk-llama/models/mistral3.cpp +4 -4
- data/ext/sources/examples/talk-llama/models/models.h +181 -46
- data/ext/sources/examples/talk-llama/models/modern-bert.cpp +2 -9
- data/ext/sources/examples/talk-llama/models/mpt.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/nemotron-h.cpp +26 -14
- data/ext/sources/examples/talk-llama/models/nemotron.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/neo-bert.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/olmo.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/olmo2.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/olmoe.cpp +4 -4
- data/ext/sources/examples/talk-llama/models/openai-moe-iswa.cpp +1 -1
- data/ext/sources/examples/talk-llama/models/openelm.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/orion.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/paddleocr.cpp +122 -0
- data/ext/sources/examples/talk-llama/models/pangu-embedded.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/phi2.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/phi3.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/plamo.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/plamo2.cpp +9 -5
- data/ext/sources/examples/talk-llama/models/plamo3.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/plm.cpp +15 -14
- data/ext/sources/examples/talk-llama/models/qwen.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/qwen2.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/qwen2moe.cpp +4 -4
- data/ext/sources/examples/talk-llama/models/qwen2vl.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/qwen3.cpp +12 -9
- data/ext/sources/examples/talk-llama/models/qwen35.cpp +381 -0
- data/ext/sources/examples/talk-llama/models/qwen35moe.cpp +422 -0
- data/ext/sources/examples/talk-llama/models/qwen3moe.cpp +15 -8
- data/ext/sources/examples/talk-llama/models/qwen3next.cpp +84 -432
- data/ext/sources/examples/talk-llama/models/qwen3vl-moe.cpp +9 -18
- data/ext/sources/examples/talk-llama/models/qwen3vl.cpp +8 -17
- data/ext/sources/examples/talk-llama/models/refact.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/rnd1.cpp +4 -4
- data/ext/sources/examples/talk-llama/models/rwkv6-base.cpp +2 -0
- data/ext/sources/examples/talk-llama/models/rwkv7-base.cpp +2 -0
- data/ext/sources/examples/talk-llama/models/seed-oss.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/smallthinker.cpp +4 -4
- data/ext/sources/examples/talk-llama/models/smollm3.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/stablelm.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/starcoder.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/starcoder2.cpp +3 -3
- data/ext/sources/examples/talk-llama/models/step35-iswa.cpp +165 -0
- data/ext/sources/examples/talk-llama/models/t5-dec.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/t5-enc.cpp +2 -2
- data/ext/sources/examples/talk-llama/models/xverse.cpp +3 -3
- data/ext/sources/examples/talk-llama/unicode.cpp +21 -65
- data/ext/sources/ggml/CMakeLists.txt +9 -3
- data/ext/sources/ggml/include/ggml-backend.h +1 -1
- data/ext/sources/ggml/include/ggml-cann.h +1 -1
- data/ext/sources/ggml/include/ggml-cpu.h +5 -0
- data/ext/sources/ggml/include/ggml-openvino.h +37 -0
- data/ext/sources/ggml/include/ggml-opt.h +1 -1
- data/ext/sources/ggml/include/ggml-rpc.h +6 -1
- data/ext/sources/ggml/include/ggml-virtgpu.h +14 -0
- data/ext/sources/ggml/include/ggml.h +56 -9
- data/ext/sources/ggml/src/CMakeLists.txt +3 -0
- data/ext/sources/ggml/src/ggml-alloc.c +4 -9
- data/ext/sources/ggml/src/ggml-backend-dl.cpp +48 -0
- data/ext/sources/ggml/src/ggml-backend-dl.h +45 -0
- data/ext/sources/ggml/src/ggml-backend-reg.cpp +28 -86
- data/ext/sources/ggml/src/ggml-backend.cpp +5 -2
- data/ext/sources/ggml/src/ggml-blas/CMakeLists.txt +1 -1
- data/ext/sources/ggml/src/ggml-blas/ggml-blas.cpp +6 -2
- data/ext/sources/ggml/src/ggml-cann/acl_tensor.cpp +1 -1
- data/ext/sources/ggml/src/ggml-cann/acl_tensor.h +1 -1
- data/ext/sources/ggml/src/ggml-cann/aclnn_ops.cpp +348 -189
- data/ext/sources/ggml/src/ggml-cann/aclnn_ops.h +40 -85
- data/ext/sources/ggml/src/ggml-cann/common.h +3 -4
- data/ext/sources/ggml/src/ggml-cann/ggml-cann.cpp +44 -62
- data/ext/sources/ggml/src/ggml-common.h +11 -0
- data/ext/sources/ggml/src/ggml-cpu/CMakeLists.txt +16 -11
- data/ext/sources/ggml/src/ggml-cpu/amx/amx.cpp +42 -19
- data/ext/sources/ggml/src/ggml-cpu/amx/common.h +34 -10
- data/ext/sources/ggml/src/ggml-cpu/amx/mmq.cpp +85 -85
- data/ext/sources/ggml/src/ggml-cpu/arch/arm/quants.c +85 -1
- data/ext/sources/ggml/src/ggml-cpu/arch/arm/repack.cpp +2744 -548
- data/ext/sources/ggml/src/ggml-cpu/arch/riscv/quants.c +1653 -0
- data/ext/sources/ggml/src/ggml-cpu/arch/riscv/repack.cpp +1391 -0
- data/ext/sources/ggml/src/ggml-cpu/arch/s390/quants.c +8 -10
- data/ext/sources/ggml/src/ggml-cpu/arch/x86/quants.c +9 -9
- data/ext/sources/ggml/src/ggml-cpu/arch/x86/repack.cpp +118 -18
- data/ext/sources/ggml/src/ggml-cpu/arch-fallback.h +107 -26
- data/ext/sources/ggml/src/ggml-cpu/binary-ops.cpp +2 -6
- data/ext/sources/ggml/src/ggml-cpu/common.h +8 -0
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu-impl.h +3 -0
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.c +59 -12
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.cpp +15 -0
- data/ext/sources/ggml/src/ggml-cpu/kleidiai/kernels.cpp +21 -20
- data/ext/sources/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +965 -252
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm.cpp +584 -197
- data/ext/sources/ggml/src/ggml-cpu/ops.cpp +903 -188
- data/ext/sources/ggml/src/ggml-cpu/ops.h +1 -0
- data/ext/sources/ggml/src/ggml-cpu/quants.c +40 -0
- data/ext/sources/ggml/src/ggml-cpu/quants.h +3 -0
- data/ext/sources/ggml/src/ggml-cpu/repack.cpp +2890 -679
- data/ext/sources/ggml/src/ggml-cpu/repack.h +119 -8
- data/ext/sources/ggml/src/ggml-cpu/simd-gemm.h +136 -0
- data/ext/sources/ggml/src/ggml-cpu/simd-mappings.h +111 -3
- data/ext/sources/ggml/src/ggml-cpu/unary-ops.cpp +1 -1
- data/ext/sources/ggml/src/ggml-cpu/vec.cpp +17 -0
- data/ext/sources/ggml/src/ggml-cuda/CMakeLists.txt +1 -1
- data/ext/sources/ggml/src/ggml-cuda/argsort.cu +19 -10
- data/ext/sources/ggml/src/ggml-cuda/binbcast.cu +32 -30
- data/ext/sources/ggml/src/ggml-cuda/common.cuh +134 -18
- data/ext/sources/ggml/src/ggml-cuda/convert.cu +41 -27
- data/ext/sources/ggml/src/ggml-cuda/cpy.cu +6 -3
- data/ext/sources/ggml/src/ggml-cuda/fattn-common.cuh +78 -64
- data/ext/sources/ggml/src/ggml-cuda/fattn-mma-f16.cuh +384 -143
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile.cuh +36 -22
- data/ext/sources/ggml/src/ggml-cuda/fattn-vec.cuh +3 -3
- data/ext/sources/ggml/src/ggml-cuda/fattn-wmma-f16.cu +26 -5
- data/ext/sources/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +1 -1
- data/ext/sources/ggml/src/ggml-cuda/fattn.cu +127 -12
- data/ext/sources/ggml/src/ggml-cuda/gated_delta_net.cu +263 -0
- data/ext/sources/ggml/src/ggml-cuda/gated_delta_net.cuh +4 -0
- data/ext/sources/ggml/src/ggml-cuda/ggml-cuda.cu +595 -200
- data/ext/sources/ggml/src/ggml-cuda/mean.cu +9 -8
- data/ext/sources/ggml/src/ggml-cuda/mma.cuh +173 -6
- data/ext/sources/ggml/src/ggml-cuda/mmf.cu +30 -10
- data/ext/sources/ggml/src/ggml-cuda/mmf.cuh +158 -85
- data/ext/sources/ggml/src/ggml-cuda/mmq.cuh +34 -22
- data/ext/sources/ggml/src/ggml-cuda/mmvf.cu +127 -67
- data/ext/sources/ggml/src/ggml-cuda/mmvf.cuh +2 -0
- data/ext/sources/ggml/src/ggml-cuda/mmvq.cu +157 -65
- data/ext/sources/ggml/src/ggml-cuda/mmvq.cuh +1 -0
- data/ext/sources/ggml/src/ggml-cuda/norm.cu +18 -76
- data/ext/sources/ggml/src/ggml-cuda/pad.cu +13 -10
- data/ext/sources/ggml/src/ggml-cuda/quantize.cu +1 -1
- data/ext/sources/ggml/src/ggml-cuda/reduce_rows.cuh +2 -16
- data/ext/sources/ggml/src/ggml-cuda/rope.cu +233 -133
- data/ext/sources/ggml/src/ggml-cuda/softmax.cu +8 -83
- data/ext/sources/ggml/src/ggml-cuda/solve_tri.cu +1 -1
- data/ext/sources/ggml/src/ggml-cuda/ssm-conv.cu +56 -32
- data/ext/sources/ggml/src/ggml-cuda/ssm-conv.cuh +1 -1
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_32.cu +5 -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_32.cu +5 -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_4-ncols2_4.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/generate_cu_files.py +3 -3
- data/ext/sources/ggml/src/ggml-cuda/top-k.cu +0 -1
- data/ext/sources/ggml/src/ggml-cuda/topk-moe.cu +199 -135
- data/ext/sources/ggml/src/ggml-cuda/topk-moe.cuh +20 -14
- data/ext/sources/ggml/src/ggml-cuda/unary.cu +55 -0
- data/ext/sources/ggml/src/ggml-cuda/unary.cuh +2 -0
- data/ext/sources/ggml/src/ggml-cuda/vecdotq.cuh +31 -17
- data/ext/sources/ggml/src/ggml-cuda/vendors/hip.h +10 -0
- data/ext/sources/ggml/src/ggml-hexagon/CMakeLists.txt +82 -45
- data/ext/sources/ggml/src/ggml-hexagon/ggml-hexagon.cpp +334 -160
- data/ext/sources/ggml/src/ggml-hexagon/htp/CMakeLists.txt +7 -5
- data/ext/sources/ggml/src/ggml-hexagon/htp/act-ops.c +328 -197
- data/ext/sources/ggml/src/ggml-hexagon/htp/argsort-ops.c +281 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/binary-ops.c +765 -234
- data/ext/sources/ggml/src/ggml-hexagon/htp/cpy-ops.c +252 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/flash-attn-ops.c +412 -265
- data/ext/sources/ggml/src/ggml-hexagon/htp/get-rows-ops.c +23 -23
- data/ext/sources/ggml/src/ggml-hexagon/htp/{htp-dma.c → hex-dma.c} +1 -1
- data/ext/sources/ggml/src/ggml-hexagon/htp/{htp-dma.h → hex-dma.h} +28 -3
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-dump.h +77 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-fastdiv.h +37 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-utils.h +51 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ctx.h +1 -1
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-msg.h +27 -37
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ops.h +6 -35
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-arith.h +443 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-base.h +240 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-copy.h +245 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-div.h +251 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-dump.h +129 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-exp.h +215 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-floor.h +100 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-inverse.h +210 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-reduce.h +296 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-scale.h +133 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-sigmoid.h +141 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-sqrt.h +126 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-types.h +36 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-utils.h +20 -1347
- data/ext/sources/ggml/src/ggml-hexagon/htp/main.c +211 -13
- data/ext/sources/ggml/src/ggml-hexagon/htp/matmul-ops.c +1119 -952
- data/ext/sources/ggml/src/ggml-hexagon/htp/rope-ops.c +254 -244
- data/ext/sources/ggml/src/ggml-hexagon/htp/set-rows-ops.c +36 -36
- data/ext/sources/ggml/src/ggml-hexagon/htp/softmax-ops.c +155 -138
- data/ext/sources/ggml/src/ggml-hexagon/htp/ssm-conv.c +339 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/sum-rows-ops.c +128 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/unary-ops.c +209 -114
- data/ext/sources/ggml/src/ggml-hexagon/htp/worker-pool.c +1 -5
- data/ext/sources/ggml/src/ggml-hexagon/htp-drv.cpp +418 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp-drv.h +121 -0
- data/ext/sources/ggml/src/ggml-hexagon/libdl.h +79 -0
- data/ext/sources/ggml/src/ggml-hexagon/libggml-htp.inf +38 -0
- data/ext/sources/ggml/src/ggml-hip/CMakeLists.txt +6 -0
- data/ext/sources/ggml/src/ggml-impl.h +62 -0
- data/ext/sources/ggml/src/ggml-metal/CMakeLists.txt +10 -10
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-common.cpp +13 -2
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-context.h +8 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-context.m +147 -17
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.cpp +274 -73
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.h +22 -4
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.m +102 -36
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-impl.h +174 -23
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.cpp +580 -280
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.h +5 -4
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.cpp +320 -107
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.metal +1068 -825
- data/ext/sources/ggml/src/ggml-opencl/CMakeLists.txt +19 -1
- data/ext/sources/ggml/src/ggml-opencl/ggml-opencl.cpp +3108 -636
- data/ext/sources/ggml/src/ggml-opencl/kernels/concat.cl +41 -99
- data/ext/sources/ggml/src/ggml-opencl/kernels/cpy.cl +45 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/cumsum.cl +139 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/cvt.cl +204 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/diag.cl +27 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/exp.cl +125 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/expm1.cl +87 -56
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q4_1_f32.cl +132 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_general_q8_0_f32.cl +195 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q4_1_f32.cl +283 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/l2_norm.cl +71 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mean.cl +114 -13
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q4_0_f32_l4_lm.cl +163 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q4_1_f32_l4_lm.cl +165 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q6_k_f32_l4_lm.cl +158 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q8_0_f32_8x4.cl +129 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q4_1_f32.cl +219 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q4_1_f32_flat.cl +229 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q4_k_f32.cl +180 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/{mul_mv_q6_k.cl → mul_mv_q6_k_f32.cl} +4 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q6_k_f32_flat.cl +194 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/neg.cl +125 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/repeat.cl +31 -32
- data/ext/sources/ggml/src/ggml-opencl/kernels/scale.cl +14 -4
- data/ext/sources/ggml/src/ggml-opencl/kernels/softplus.cl +88 -60
- data/ext/sources/ggml/src/ggml-opencl/kernels/solve_tri.cl +51 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/sum_rows.cl +114 -13
- data/ext/sources/ggml/src/ggml-opencl/kernels/tanh.cl +94 -48
- data/ext/sources/ggml/src/ggml-opencl/kernels/transpose.cl +26 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/tri.cl +32 -0
- data/ext/sources/ggml/src/ggml-openvino/.clang-format +154 -0
- data/ext/sources/ggml/src/ggml-openvino/CMakeLists.txt +22 -0
- data/ext/sources/ggml/src/ggml-openvino/ggml-decoder.cpp +975 -0
- data/ext/sources/ggml/src/ggml-openvino/ggml-decoder.h +294 -0
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino-extra.cpp +373 -0
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino-extra.h +182 -0
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino.cpp +1110 -0
- data/ext/sources/ggml/src/ggml-openvino/ggml-quants.cpp +884 -0
- data/ext/sources/ggml/src/ggml-openvino/ggml-quants.h +153 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/decoder.h +74 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/frontend.cpp +27 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/frontend.h +23 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/input_model.cpp +17 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/input_model.h +29 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/node_context.h +112 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/cont.cpp +48 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/cpy.cpp +21 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/flash_attn_ext.cpp +90 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/get_rows.cpp +69 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/glu_geglu.cpp +61 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/glu_swiglu.cpp +62 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/mulmat.cpp +90 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/permute.cpp +102 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/reshape.cpp +83 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/rms_norm.cpp +46 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/rope.cpp +123 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/scale.cpp +41 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/set_rows.cpp +76 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/softmax.cpp +89 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/transpose.cpp +23 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/unary_silu.cpp +27 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/view.cpp +53 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op_table.cpp +46 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op_table.h +39 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/eliminate_zp.cpp +123 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/eliminate_zp.h +17 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/fuse_to_sdpa.cpp +60 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/fuse_to_sdpa.h +17 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/mark_decompression_convert_constant_folding.h +29 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/squeeze_matmul.cpp +58 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/squeeze_matmul.h +17 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/translate_session.cpp +293 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/translate_session.h +28 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/utils.cpp +226 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/utils.h +85 -0
- data/ext/sources/ggml/src/ggml-openvino/utils.cpp +823 -0
- data/ext/sources/ggml/src/ggml-openvino/utils.h +123 -0
- data/ext/sources/ggml/src/ggml-quants.c +96 -5
- data/ext/sources/ggml/src/ggml-quants.h +3 -0
- data/ext/sources/ggml/src/ggml-sycl/CMakeLists.txt +15 -88
- data/ext/sources/ggml/src/ggml-sycl/add-id.cpp +5 -1
- data/ext/sources/ggml/src/ggml-sycl/backend.hpp +1 -0
- data/ext/sources/ggml/src/ggml-sycl/binbcast.cpp +21 -20
- data/ext/sources/ggml/src/ggml-sycl/common.hpp +315 -10
- data/ext/sources/ggml/src/ggml-sycl/convert.cpp +69 -1
- data/ext/sources/ggml/src/ggml-sycl/convert.hpp +22 -1
- data/ext/sources/ggml/src/ggml-sycl/count-equal.cpp +1 -1
- data/ext/sources/ggml/src/ggml-sycl/dpct/helper.hpp +791 -47
- data/ext/sources/ggml/src/ggml-sycl/element_wise.cpp +78 -68
- data/ext/sources/ggml/src/ggml-sycl/element_wise.hpp +2 -0
- data/ext/sources/ggml/src/ggml-sycl/fattn-common.hpp +1179 -0
- data/ext/sources/ggml/src/ggml-sycl/fattn-tile.cpp +55 -0
- data/ext/sources/ggml/src/ggml-sycl/fattn-tile.hpp +1338 -0
- data/ext/sources/ggml/src/ggml-sycl/fattn-vec.hpp +667 -0
- data/ext/sources/ggml/src/ggml-sycl/fattn.cpp +225 -0
- data/ext/sources/ggml/src/ggml-sycl/fattn.hpp +22 -0
- data/ext/sources/ggml/src/ggml-sycl/gated_delta_net.cpp +309 -0
- data/ext/sources/ggml/src/ggml-sycl/gated_delta_net.hpp +8 -0
- data/ext/sources/ggml/src/ggml-sycl/ggml-sycl.cpp +316 -51
- data/ext/sources/ggml/src/ggml-sycl/norm.cpp +65 -66
- data/ext/sources/ggml/src/ggml-sycl/outprod.cpp +3 -3
- data/ext/sources/ggml/src/ggml-sycl/presets.hpp +3 -0
- data/ext/sources/ggml/src/ggml-sycl/quants.hpp +1 -1
- data/ext/sources/ggml/src/ggml-sycl/rope.cpp +450 -287
- data/ext/sources/ggml/src/ggml-sycl/rope.hpp +6 -0
- data/ext/sources/ggml/src/ggml-sycl/softmax.cpp +6 -6
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq112-dv112.cpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq128-dv128.cpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq256-dv256.cpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq40-dv40.cpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq576-dv512.cpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq64-dv64.cpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq72-dv72.cpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq80-dv80.cpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq96-dv96.cpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-f16.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q4_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q4_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q5_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q5_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q8_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-f16.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q4_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q4_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q5_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q5_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q8_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-f16.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q4_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q4_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q5_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q5_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q8_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-f16.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q4_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q4_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q5_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q5_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q8_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-f16.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q4_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q4_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q5_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q5_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q8_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-f16.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q4_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q4_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q5_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q5_1.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q8_0.cpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/vecdotq.hpp +13 -0
- data/ext/sources/ggml/src/ggml-sycl/wkv.cpp +1 -1
- data/ext/sources/ggml/src/ggml-virtgpu/CMakeLists.txt +70 -0
- data/ext/sources/ggml/src/ggml-virtgpu/apir_cs_ggml-rpc-front.cpp +87 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/CMakeLists.txt +21 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/apir_cs_ggml-rpc-back.cpp +115 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/backend-convert.h +13 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/backend-dispatched-backend.cpp +102 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/backend-dispatched-buffer-type.cpp +105 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/backend-dispatched-buffer.cpp +179 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/backend-dispatched-device.cpp +148 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/backend-dispatched.cpp +51 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/backend-dispatched.gen.h +73 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/backend-dispatched.h +27 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/backend-virgl-apir.h +32 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/backend.cpp +144 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/shared/api_remoting.h +95 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/shared/apir_backend.gen.h +94 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/shared/apir_backend.h +50 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/shared/apir_cs.h +378 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/shared/apir_cs_ggml.h +232 -0
- data/ext/sources/ggml/src/ggml-virtgpu/backend/shared/apir_cs_rpc.h +58 -0
- data/ext/sources/ggml/src/ggml-virtgpu/ggml-backend-buffer-type.cpp +81 -0
- data/ext/sources/ggml/src/ggml-virtgpu/ggml-backend-buffer.cpp +119 -0
- data/ext/sources/ggml/src/ggml-virtgpu/ggml-backend-device.cpp +158 -0
- data/ext/sources/ggml/src/ggml-virtgpu/ggml-backend-reg.cpp +213 -0
- data/ext/sources/ggml/src/ggml-virtgpu/ggml-backend.cpp +69 -0
- data/ext/sources/ggml/src/ggml-virtgpu/ggml-remoting.h +71 -0
- data/ext/sources/ggml/src/ggml-virtgpu/ggmlremoting_functions.yaml +166 -0
- data/ext/sources/ggml/src/ggml-virtgpu/include/apir_hw.h +9 -0
- data/ext/sources/ggml/src/ggml-virtgpu/regenerate_remoting.py +333 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-apir.h +15 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-forward-backend.cpp +58 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-forward-buffer-type.cpp +110 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-forward-buffer.cpp +173 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-forward-device.cpp +192 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-forward-impl.h +36 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-forward.gen.h +53 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-shm.cpp +98 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-shm.h +23 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-utils.cpp +179 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu-utils.h +86 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu.cpp +544 -0
- data/ext/sources/ggml/src/ggml-virtgpu/virtgpu.h +117 -0
- data/ext/sources/ggml/src/ggml-vulkan/CMakeLists.txt +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/ggml-vulkan.cpp +1250 -465
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/acc.comp +16 -8
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/elu.comp +27 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +374 -170
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_base.glsl +66 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +389 -201
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +106 -58
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_mask_opt.comp +162 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_split_k_reduce.comp +9 -8
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gated_delta_net.comp +128 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +12 -9
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_base.glsl +20 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +11 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +8 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_id_funcs.glsl +3 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp +5 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.glsl +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm.comp +2 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_funcs.glsl +36 -63
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_multi.comp +7 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_neox.comp +7 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_norm.comp +7 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_params.glsl +10 -5
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_vision.comp +7 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sgn.comp +21 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/ssm_conv.comp +16 -10
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +55 -35
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp +1314 -109
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu.cpp +1660 -1371
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/argmax.wgsl +72 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/argsort.wgsl +106 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/argsort_merge.wgsl +134 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/binary.wgsl +141 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/common_decls.tmpl +65 -72
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/concat.wgsl +75 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/cpy.tmpl.wgsl +6 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/cumsum.wgsl +66 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/embed_wgsl.py +40 -5
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn.wgsl +105 -60
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/{get_rows.tmpl.wgsl → get_rows.wgsl} +53 -259
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/{mul_mat.tmpl.wgsl → mul_mat.wgsl} +68 -257
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_decls.tmpl +692 -23
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/{mul_mat_reg_tile.tmpl.wgsl → mul_mat_reg_tile.wgsl} +28 -128
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/{mul_mat_subgroup_matrix.tmpl.wgsl → mul_mat_subgroup_matrix.wgsl} +31 -137
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec.wgsl +480 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/pad.wgsl +86 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/repeat.wgsl +67 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/{scale.tmpl.wgsl → scale.wgsl} +9 -36
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/set_rows.wgsl +40 -12
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/sum_rows.wgsl +55 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/unary.wgsl +193 -0
- data/ext/sources/ggml/src/ggml-zdnn/ggml-zdnn.cpp +6 -1
- data/ext/sources/ggml/src/ggml-zendnn/CMakeLists.txt +31 -32
- data/ext/sources/ggml/src/ggml-zendnn/ggml-zendnn.cpp +9 -6
- data/ext/sources/ggml/src/ggml.c +167 -33
- data/ext/sources/ggml/src/gguf.cpp +229 -44
- data/ext/sources/src/whisper.cpp +6 -28
- data/sig/whisper.rbs +43 -2
- data/test/test_context_params.rb +82 -0
- data/test/test_token.rb +11 -0
- data/test/test_vad_context.rb +58 -8
- data/test/test_whisper.rb +20 -0
- data/whispercpp.gemspec +1 -1
- metadata +240 -28
- data/ext/sources/ggml/cmake/BuildTypes.cmake +0 -54
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm-ppc.h +0 -333
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-exp.c +0 -94
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-inverse.c +0 -72
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-sigmoid.c +0 -49
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-utils.c +0 -1020
- data/ext/sources/ggml/src/ggml-hexagon/htp/ops-utils.h +0 -149
- data/ext/sources/ggml/src/ggml-hexagon/htp-utils.c +0 -454
- data/ext/sources/ggml/src/ggml-hexagon/htp-utils.h +0 -221
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/bin_op.tmpl.wgsl +0 -188
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/binary_head.tmpl +0 -45
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec.tmpl.wgsl +0 -267
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/set_rows.tmpl.wgsl +0 -112
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/unary_op.wgsl +0 -483
|
@@ -0,0 +1,1338 @@
|
|
|
1
|
+
#include <sycl/sycl.hpp>
|
|
2
|
+
#include <sycl/ext/oneapi/work_group_static.hpp>
|
|
3
|
+
#include "dpct/helper.hpp"
|
|
4
|
+
#include "common.hpp"
|
|
5
|
+
#include "fattn-common.hpp"
|
|
6
|
+
|
|
7
|
+
#include <cmath>
|
|
8
|
+
#include <float.h>
|
|
9
|
+
|
|
10
|
+
namespace syclex = sycl::ext::oneapi::experimental;
|
|
11
|
+
|
|
12
|
+
#define GGML_SYCL_FATTN_TILE_CONFIG_CASE(DKQ_, DV_, ncols_, nthreads, occupancy, nbatch_fa, nbatch_K) \
|
|
13
|
+
if (DKQ == (DKQ_) && DV == (DV_) && ncols == (ncols_)) { \
|
|
14
|
+
static_assert((nthreads) <= 512, "bad nthreads"); \
|
|
15
|
+
static_assert((occupancy) <= 8, "bad occupancy"); \
|
|
16
|
+
static_assert((nbatch_fa) <= 256, "bad nbatch_fa"); \
|
|
17
|
+
static_assert((nbatch_K) <= 256, "bad nbatch_K"); \
|
|
18
|
+
return ((nthreads) << 0) | ((occupancy) << 10) | ((nbatch_fa) << 14) | ((nbatch_K) << 23); \
|
|
19
|
+
} \
|
|
20
|
+
|
|
21
|
+
static constexpr uint32_t ggml_sycl_fattn_tile_get_config_fp16(const int DKQ, const int DV, const int ncols) {
|
|
22
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 2, 64, 2, 64, 40)
|
|
23
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 4, 128, 2, 64, 40)
|
|
24
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 8, 256, 2, 64, 40)
|
|
25
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 16, 256, 2, 64, 40)
|
|
26
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 32, 256, 2, 64, 40)
|
|
27
|
+
|
|
28
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 2, 64, 2, 64, 64)
|
|
29
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 4, 128, 2, 64, 64)
|
|
30
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 8, 256, 2, 64, 64)
|
|
31
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 16, 256, 2, 64, 64)
|
|
32
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 32, 256, 2, 64, 64)
|
|
33
|
+
|
|
34
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 2, 64, 2, 64, 72)
|
|
35
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 4, 128, 2, 64, 72)
|
|
36
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 8, 256, 2, 64, 72)
|
|
37
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 16, 256, 2, 64, 72)
|
|
38
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 32, 256, 2, 64, 72)
|
|
39
|
+
|
|
40
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 2, 64, 2, 64, 40)
|
|
41
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 4, 128, 2, 64, 40)
|
|
42
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 8, 256, 2, 64, 40)
|
|
43
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 16, 256, 2, 64, 40)
|
|
44
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 32, 256, 2, 64, 40)
|
|
45
|
+
|
|
46
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 2, 64, 2, 64, 48)
|
|
47
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 4, 128, 2, 64, 48)
|
|
48
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 8, 256, 2, 64, 48)
|
|
49
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 16, 256, 2, 64, 48)
|
|
50
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 32, 256, 2, 64, 48)
|
|
51
|
+
|
|
52
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 2, 64, 2, 64, 56)
|
|
53
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 4, 128, 2, 64, 56)
|
|
54
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 8, 256, 2, 64, 56)
|
|
55
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 16, 256, 2, 64, 56)
|
|
56
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 32, 256, 2, 64, 56)
|
|
57
|
+
|
|
58
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 2, 64, 2, 64, 64)
|
|
59
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 4, 128, 2, 64, 64)
|
|
60
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 8, 256, 2, 64, 64)
|
|
61
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 16, 256, 2, 64, 64)
|
|
62
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 32, 256, 2, 64, 64)
|
|
63
|
+
|
|
64
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 2, 64, 2, 64, 64)
|
|
65
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 4, 128, 2, 64, 64)
|
|
66
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 8, 256, 2, 64, 64)
|
|
67
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 16, 256, 2, 64, 64)
|
|
68
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 32, 256, 2, 64, 64)
|
|
69
|
+
|
|
70
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 4, 128, 2, 64, 64)
|
|
71
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 8, 256, 2, 64, 64)
|
|
72
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 16, 256, 2, 64, 64)
|
|
73
|
+
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static constexpr uint32_t ggml_sycl_fattn_tile_get_config_fp32(const int DKQ, const int DV, const int ncols) {
|
|
78
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 2, 64, 2, 32, 40)
|
|
79
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 4, 128, 2, 32, 40)
|
|
80
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 8, 256, 2, 32, 40)
|
|
81
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 16, 256, 2, 32, 40)
|
|
82
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 32, 256, 2, 32, 40)
|
|
83
|
+
|
|
84
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 2, 128, 3, 64, 64)
|
|
85
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 4, 128, 3, 32, 64)
|
|
86
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 8, 128, 3, 32, 64)
|
|
87
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 16, 128, 3, 64, 64)
|
|
88
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 32, 256, 2, 64, 64)
|
|
89
|
+
|
|
90
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 2, 64, 2, 32, 72)
|
|
91
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 4, 128, 2, 32, 72)
|
|
92
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 8, 256, 2, 32, 72)
|
|
93
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 16, 256, 2, 32, 72)
|
|
94
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 32, 256, 2, 32, 72)
|
|
95
|
+
|
|
96
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 2, 64, 2, 32, 40)
|
|
97
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 4, 128, 2, 32, 40)
|
|
98
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 8, 256, 2, 32, 40)
|
|
99
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 16, 256, 2, 32, 40)
|
|
100
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 32, 256, 2, 32, 40)
|
|
101
|
+
|
|
102
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 2, 64, 2, 32, 48)
|
|
103
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 4, 128, 2, 32, 48)
|
|
104
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 8, 256, 2, 32, 48)
|
|
105
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 16, 256, 2, 32, 48)
|
|
106
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 32, 256, 2, 32, 48)
|
|
107
|
+
|
|
108
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 2, 64, 2, 32, 56)
|
|
109
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 4, 128, 2, 32, 56)
|
|
110
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 8, 256, 2, 32, 56)
|
|
111
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 16, 256, 2, 32, 56)
|
|
112
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 32, 256, 2, 32, 56)
|
|
113
|
+
|
|
114
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 2, 128, 3, 64, 64)
|
|
115
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 4, 128, 3, 32, 128)
|
|
116
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 8, 128, 3, 64, 128)
|
|
117
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 16, 128, 3, 32, 128)
|
|
118
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 32, 256, 2, 64, 64)
|
|
119
|
+
|
|
120
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 2, 128, 3, 64, 64)
|
|
121
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 4, 128, 3, 32, 64)
|
|
122
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 8, 256, 2, 32, 256)
|
|
123
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 16, 256, 2, 32, 128)
|
|
124
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 32, 256, 2, 32, 64)
|
|
125
|
+
|
|
126
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 4, 128, 2, 32, 64)
|
|
127
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 8, 256, 2, 32, 64)
|
|
128
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 16, 256, 2, 32, 64)
|
|
129
|
+
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static constexpr uint32_t ggml_sycl_fattn_tile_get_config_amd(const int DKQ, const int DV, const int ncols) {
|
|
134
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 2, 64, 2, 32, 40)
|
|
135
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 4, 128, 2, 32, 40)
|
|
136
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 8, 256, 2, 32, 40)
|
|
137
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 16, 256, 2, 32, 40)
|
|
138
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 32, 256, 2, 32, 40)
|
|
139
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 64, 256, 2, 32, 40)
|
|
140
|
+
|
|
141
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 2, 64, 3, 32, 64)
|
|
142
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 4, 128, 3, 64, 64)
|
|
143
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 8, 128, 2, 32, 64)
|
|
144
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 16, 256, 2, 128, 64)
|
|
145
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 32, 256, 2, 64, 64)
|
|
146
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 64, 256, 2, 64, 64)
|
|
147
|
+
|
|
148
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 2, 64, 2, 32, 72)
|
|
149
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 4, 128, 2, 32, 72)
|
|
150
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 8, 256, 2, 32, 72)
|
|
151
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 16, 256, 2, 32, 72)
|
|
152
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 32, 256, 2, 32, 72)
|
|
153
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 64, 256, 2, 32, 72)
|
|
154
|
+
|
|
155
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 2, 64, 2, 32, 40)
|
|
156
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 4, 128, 2, 32, 40)
|
|
157
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 8, 256, 2, 32, 40)
|
|
158
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 16, 256, 2, 32, 40)
|
|
159
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 32, 256, 2, 32, 40)
|
|
160
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 64, 256, 2, 32, 40)
|
|
161
|
+
|
|
162
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 2, 64, 2, 32, 48)
|
|
163
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 4, 128, 2, 32, 48)
|
|
164
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 8, 256, 2, 32, 48)
|
|
165
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 16, 256, 2, 32, 48)
|
|
166
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 32, 256, 2, 32, 48)
|
|
167
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 64, 256, 2, 32, 48)
|
|
168
|
+
|
|
169
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 2, 64, 2, 32, 56)
|
|
170
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 4, 128, 2, 32, 56)
|
|
171
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 8, 256, 2, 32, 56)
|
|
172
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 16, 256, 2, 32, 56)
|
|
173
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 32, 256, 2, 32, 56)
|
|
174
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 64, 256, 2, 32, 56)
|
|
175
|
+
|
|
176
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 2, 256, 2, 128, 64)
|
|
177
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 4, 128, 2, 64, 128)
|
|
178
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 8, 256, 2, 64, 128)
|
|
179
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 16, 256, 2, 64, 128)
|
|
180
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 32, 256, 2, 64, 64)
|
|
181
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 64, 256, 2, 64, 32)
|
|
182
|
+
|
|
183
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 2, 256, 2, 128, 64)
|
|
184
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 4, 256, 2, 64, 128)
|
|
185
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 8, 256, 2, 64, 128)
|
|
186
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 16, 256, 2, 32, 128)
|
|
187
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 32, 256, 2, 32, 128)
|
|
188
|
+
|
|
189
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 4, 128, 2, 64, 64)
|
|
190
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 8, 256, 2, 64, 64)
|
|
191
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 16, 256, 2, 64, 64)
|
|
192
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 32, 512, 1, 128, 64)
|
|
193
|
+
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
static constexpr uint32_t ggml_sycl_fattn_tile_get_config_amd_rdna(const int DKQ, const int DV, const int ncols) {
|
|
198
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 2, 64, 2, 32, 40)
|
|
199
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 4, 128, 2, 32, 40)
|
|
200
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 8, 256, 2, 32, 40)
|
|
201
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 16, 256, 2, 32, 40)
|
|
202
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 32, 256, 2, 32, 40)
|
|
203
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 40, 40, 64, 256, 2, 32, 40)
|
|
204
|
+
|
|
205
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 2, 64, 8, 32, 64)
|
|
206
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 4, 64, 8, 32, 64)
|
|
207
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 8, 128, 5, 128, 64)
|
|
208
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 16, 128, 5, 128, 64)
|
|
209
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 32, 128, 4, 64, 64)
|
|
210
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 64, 64, 64, 128, 5, 64, 64)
|
|
211
|
+
|
|
212
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 2, 64, 2, 32, 72)
|
|
213
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 4, 128, 2, 32, 72)
|
|
214
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 8, 256, 2, 32, 72)
|
|
215
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 16, 256, 2, 32, 72)
|
|
216
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 32, 256, 2, 32, 72)
|
|
217
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 72, 72, 64, 256, 2, 32, 72)
|
|
218
|
+
|
|
219
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 2, 64, 2, 32, 40)
|
|
220
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 4, 128, 2, 32, 40)
|
|
221
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 8, 256, 2, 32, 40)
|
|
222
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 16, 256, 2, 32, 40)
|
|
223
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 32, 256, 2, 32, 40)
|
|
224
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 80, 80, 64, 256, 2, 32, 40)
|
|
225
|
+
|
|
226
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 2, 64, 2, 32, 48)
|
|
227
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 4, 128, 2, 32, 48)
|
|
228
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 8, 256, 2, 32, 48)
|
|
229
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 16, 256, 2, 32, 48)
|
|
230
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 32, 256, 2, 32, 48)
|
|
231
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE( 96, 96, 64, 256, 2, 32, 48)
|
|
232
|
+
|
|
233
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 2, 64, 2, 32, 56)
|
|
234
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 4, 128, 2, 32, 56)
|
|
235
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 8, 256, 2, 32, 56)
|
|
236
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 16, 256, 2, 32, 56)
|
|
237
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 32, 256, 2, 32, 56)
|
|
238
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(112, 112, 64, 256, 2, 32, 56)
|
|
239
|
+
|
|
240
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 2, 64, 8, 32, 64)
|
|
241
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 4, 128, 8, 64, 64)
|
|
242
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 8, 128, 8, 64, 64)
|
|
243
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 16, 256, 3, 128, 128)
|
|
244
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 32, 256, 3, 128, 64)
|
|
245
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(128, 128, 64, 256, 3, 64, 64)
|
|
246
|
+
|
|
247
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 2, 64, 8, 32, 64)
|
|
248
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 4, 128, 6, 32, 256)
|
|
249
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 8, 128, 6, 32, 256)
|
|
250
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 16, 256, 5, 32, 256)
|
|
251
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(256, 256, 32, 256, 3, 64, 128)
|
|
252
|
+
|
|
253
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 4, 128, 2, 64, 64)
|
|
254
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 8, 256, 2, 64, 64)
|
|
255
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 16, 256, 4, 64, 64)
|
|
256
|
+
GGML_SYCL_FATTN_TILE_CONFIG_CASE(576, 512, 32, 256, 2, 128, 64)
|
|
257
|
+
|
|
258
|
+
return 0;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
static constexpr uint32_t ggml_sycl_fattn_tile_get_config(const int DKQ, const int DV, const int ncols, const int cc) {
|
|
262
|
+
if(fast_fp16_available(cc))
|
|
263
|
+
return ggml_sycl_fattn_tile_get_config_fp16(DKQ, DV, ncols);
|
|
264
|
+
else
|
|
265
|
+
return ggml_sycl_fattn_tile_get_config_fp32(DKQ, DV, ncols);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
static constexpr uint32_t ggml_sycl_fattn_tile_get_config(const int DKQ, const int DV, const int ncols) {
|
|
269
|
+
#ifdef SYCL_FAST_FP16
|
|
270
|
+
return ggml_sycl_fattn_tile_get_config_fp16(DKQ, DV, ncols);
|
|
271
|
+
#else
|
|
272
|
+
return ggml_sycl_fattn_tile_get_config_fp32(DKQ, DV, ncols);
|
|
273
|
+
#endif // SYCL_FAST_FP16
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
static int ggml_sycl_fattn_tile_get_nthreads(const int DKQ, const int DV, const int ncols, const int cc) {
|
|
277
|
+
return (ggml_sycl_fattn_tile_get_config(DKQ, DV, ncols, cc) >> 0) & ((1 << 10) - 1);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
static constexpr int ggml_sycl_fattn_tile_get_nthreads(const int DKQ, const int DV, const int ncols) {
|
|
281
|
+
return (ggml_sycl_fattn_tile_get_config(DKQ, DV, ncols) >> 0) & ((1 << 10) - 1);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
static int ggml_sycl_fattn_tile_get_occupancy(const int DKQ, const int DV, const int ncols, const int cc) {
|
|
285
|
+
return (ggml_sycl_fattn_tile_get_config(DKQ, DV, ncols, cc) >> 10) & ((1 << 4) - 1);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
static constexpr int ggml_sycl_fattn_tile_get_occupancy(const int DKQ, const int DV, const int ncols) {
|
|
289
|
+
return (ggml_sycl_fattn_tile_get_config(DKQ, DV, ncols) >> 10) & ((1 << 4) - 1);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
static int ggml_sycl_fattn_tile_get_nbatch_fa(const int DKQ, const int DV, const int ncols, const int cc) {
|
|
293
|
+
return (ggml_sycl_fattn_tile_get_config(DKQ, DV, ncols, cc) >> 14) & ((1 << 9) - 1);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
static constexpr int ggml_sycl_fattn_tile_get_nbatch_fa(const int DKQ, const int DV, const int ncols) {
|
|
297
|
+
return (ggml_sycl_fattn_tile_get_config(DKQ, DV, ncols) >> 14) & ((1 << 9) - 1);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
static int ggml_sycl_fattn_tile_get_nbatch_K(const int DKQ, const int DV, const int ncols, const int cc) {
|
|
301
|
+
return (ggml_sycl_fattn_tile_get_config(DKQ, DV, ncols, cc) >> 23) & ((1 << 9) - 1);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
static constexpr int ggml_sycl_fattn_tile_get_nbatch_K(const int DKQ, const int DV, const int ncols) {
|
|
305
|
+
return (ggml_sycl_fattn_tile_get_config(DKQ, DV, ncols) >> 23) & ((1 << 9) - 1);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
template <int warp_size, int nwarps, int I, int J, int J_padding, bool oob_check>
|
|
309
|
+
static __dpct_inline__ void flash_attn_tile_load_tile(const sycl::half2 * const __restrict__ KV,
|
|
310
|
+
sycl::half2 * const __restrict__ tile_KV,
|
|
311
|
+
const int stride_KV,
|
|
312
|
+
const int i_sup) {
|
|
313
|
+
constexpr int cpy_nb = ggml_sycl_get_max_cpy_bytes();
|
|
314
|
+
constexpr int cpy_ne = cpy_nb / 4;
|
|
315
|
+
|
|
316
|
+
auto load = [&] (const int n) {
|
|
317
|
+
auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item<3>();
|
|
318
|
+
const int stride_j = warp_size >> n;
|
|
319
|
+
|
|
320
|
+
if (stride_j == 0) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const int j0_start = stride_j == warp_size ? 0 : ((J/2)/cpy_ne) - ((J/2)/cpy_ne) % (2*stride_j);
|
|
325
|
+
const int j0_stop = ((J/2)/cpy_ne) - ((J/2)/cpy_ne) % (1*stride_j);
|
|
326
|
+
const int stride_i = warp_size / stride_j;
|
|
327
|
+
|
|
328
|
+
if (j0_start == j0_stop) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
#pragma unroll
|
|
333
|
+
for (int i0 = 0; i0 < I; i0 += nwarps*stride_i) {
|
|
334
|
+
const int i = i0 + item_ct1.get_local_id(1) * stride_i +
|
|
335
|
+
(stride_j == warp_size ? 0 : item_ct1.get_local_id(2) / stride_j);
|
|
336
|
+
|
|
337
|
+
if (i0 + nwarps*stride_i <= I || i < I) {
|
|
338
|
+
#pragma unroll
|
|
339
|
+
for (int j0 = j0_start; j0 < j0_stop; j0 += stride_j) {
|
|
340
|
+
const int j = j0 * cpy_ne + (stride_j == warp_size ? item_ct1.get_local_id(2) :
|
|
341
|
+
item_ct1.get_local_id(2) % stride_j) *
|
|
342
|
+
cpy_ne;
|
|
343
|
+
|
|
344
|
+
const __dpct_align__(16) sycl::half2 zero[cpy_ne] = {
|
|
345
|
+
{ 0.0f, 0.0f }
|
|
346
|
+
};
|
|
347
|
+
ggml_sycl_memcpy_1<cpy_nb>(
|
|
348
|
+
tile_KV + i*(J/2 + J_padding) + j,
|
|
349
|
+
!oob_check || i < i_sup ? KV + i*stride_KV + j : zero);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
// 1: max 64*16=512 bytes, 512 half
|
|
355
|
+
// 2: max 32*16=512 bytes, 256 half
|
|
356
|
+
// 3: max 16*16=256 bytes, 128 half
|
|
357
|
+
// 4: max 8*16=128 bytes, 64 half
|
|
358
|
+
// 5: max 4*16= 64 bytes, 32 half
|
|
359
|
+
// 6: max 2*16= 32 bytes, 16 half
|
|
360
|
+
// 7: max 1*16= 16 bytes, 8 half
|
|
361
|
+
static_assert(J % 8 == 0, "bad J");
|
|
362
|
+
static_assert((J/2) % cpy_ne == 0, "bad J");
|
|
363
|
+
ggml_sycl_unroll<7>{}(load);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
template <int warp_size, int nwarps, int I, int J, int J_padding, bool oob_check>
|
|
367
|
+
static __dpct_inline__ void flash_attn_tile_load_tile(const sycl::half2 * const __restrict__ KV,
|
|
368
|
+
float * const __restrict__ tile_KV,
|
|
369
|
+
const int stride_KV,
|
|
370
|
+
const int i_sup) {
|
|
371
|
+
constexpr int cpy_nb = ggml_sycl_get_max_cpy_bytes();
|
|
372
|
+
constexpr int cpy_ne = cpy_nb / 4;
|
|
373
|
+
|
|
374
|
+
auto load = [&] (const int n) {
|
|
375
|
+
auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item<3>();
|
|
376
|
+
const int stride_j = warp_size >> n;
|
|
377
|
+
|
|
378
|
+
if (stride_j == 0) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const int j0_start = stride_j == warp_size ? 0 : (J/cpy_ne) - (J/cpy_ne) % (2*stride_j);
|
|
383
|
+
const int j0_stop = (J/cpy_ne) - (J/cpy_ne) % (1*stride_j);
|
|
384
|
+
const int stride_i = warp_size / stride_j;
|
|
385
|
+
|
|
386
|
+
if (j0_start == j0_stop) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
#pragma unroll
|
|
391
|
+
for (int i0 = 0; i0 < I; i0 += nwarps*stride_i) {
|
|
392
|
+
const int i = i0 + item_ct1.get_local_id(1) * stride_i +
|
|
393
|
+
(stride_j == warp_size ? 0 : item_ct1.get_local_id(2) / stride_j);
|
|
394
|
+
|
|
395
|
+
if (i0 + nwarps*stride_i <= I || i < I) {
|
|
396
|
+
#pragma unroll
|
|
397
|
+
for (int j0 = j0_start; j0 < j0_stop; j0 += stride_j) {
|
|
398
|
+
const int j = j0 * (cpy_ne / 2) + (stride_j == warp_size ? item_ct1.get_local_id(2) :
|
|
399
|
+
item_ct1.get_local_id(2) % stride_j) *
|
|
400
|
+
(cpy_ne / 2);
|
|
401
|
+
|
|
402
|
+
const sycl::half2 zero[cpy_ne / 2] = {
|
|
403
|
+
{ 0.0f, 0.0f }
|
|
404
|
+
};
|
|
405
|
+
__dpct_align__(16) sycl::half2 tmp_h2[cpy_ne / 2];
|
|
406
|
+
ggml_sycl_memcpy_1<sizeof(tmp_h2)>(
|
|
407
|
+
tmp_h2, !oob_check || i < i_sup ? KV + i*stride_KV + j : zero);
|
|
408
|
+
|
|
409
|
+
__dpct_align__(16) sycl::float2 tmp_f2[cpy_ne / 2];
|
|
410
|
+
#pragma unroll
|
|
411
|
+
for (int l = 0; l < cpy_ne/2; ++l) {
|
|
412
|
+
tmp_f2[l] = tmp_h2[l].template convert<float, sycl::rounding_mode::automatic>();
|
|
413
|
+
}
|
|
414
|
+
ggml_sycl_memcpy_1<sizeof(tmp_f2)>(tile_KV + i*(J + J_padding) + 2*j, tmp_f2);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
// 1: max 32*16=512 bytes, 128 float
|
|
420
|
+
// 2: max 16*16=256 bytes, 64 float
|
|
421
|
+
// 3: max 8*16=128 bytes, 32 float
|
|
422
|
+
// 4: max 4*16= 64 bytes, 16 float
|
|
423
|
+
// 5: max 2*16= 32 bytes, 8 float
|
|
424
|
+
static_assert(J % 8 == 0, "bad J");
|
|
425
|
+
static_assert(J % cpy_ne == 0, "bad J");
|
|
426
|
+
ggml_sycl_unroll<5>{}(load);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Function that performs a single iteration in for the KQ matrix multiplication:
|
|
430
|
+
template <int warp_size,
|
|
431
|
+
int nwarps,
|
|
432
|
+
int ncols1,
|
|
433
|
+
int ncols2,
|
|
434
|
+
int DKQ,
|
|
435
|
+
int nbatch_fa,
|
|
436
|
+
int nbatch_K,
|
|
437
|
+
bool use_logit_softcap,
|
|
438
|
+
bool oob_check,
|
|
439
|
+
typename T_vec_dot>
|
|
440
|
+
static __dpct_inline__ void flash_attn_tile_iter_KQ(T_vec_dot * const Q_tmp,
|
|
441
|
+
const sycl::half2 * const __restrict__ K_h2,
|
|
442
|
+
T_vec_dot * const KV_tmp,
|
|
443
|
+
const int stride_K2,
|
|
444
|
+
const int k_VKQ_0,
|
|
445
|
+
const int k_VKQ_sup,
|
|
446
|
+
const int k_KQ_0,
|
|
447
|
+
float * KQ_acc) {
|
|
448
|
+
auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item<3>();
|
|
449
|
+
constexpr int cpy_nb = ggml_sycl_get_max_cpy_bytes();
|
|
450
|
+
constexpr int cpy_ne = cpy_nb / 4;
|
|
451
|
+
|
|
452
|
+
constexpr int ncols = ncols1*ncols2;
|
|
453
|
+
constexpr int cpw = ncols > nwarps ? ncols/nwarps : 1; // Q columns per warp
|
|
454
|
+
constexpr int np = nwarps > ncols ? nwarps/ncols : 1; // number of parallel warps per Q column
|
|
455
|
+
|
|
456
|
+
flash_attn_tile_load_tile<warp_size, nwarps, nbatch_fa, nbatch_K, cpy_ne, oob_check>
|
|
457
|
+
(K_h2 + int64_t(k_VKQ_0)*stride_K2 + k_KQ_0/2, KV_tmp, stride_K2, k_VKQ_sup);
|
|
458
|
+
item_ct1.barrier();
|
|
459
|
+
|
|
460
|
+
#ifdef SYCL_FAST_FP16
|
|
461
|
+
static_assert((nbatch_K/2) % cpy_ne == 0, "bad nbatch_K");
|
|
462
|
+
#pragma unroll
|
|
463
|
+
for (int k_KQ_1 = 0; k_KQ_1 < nbatch_K/2; k_KQ_1 += cpy_ne) {
|
|
464
|
+
__dpct_align__(16) sycl::half2 K_k[nbatch_fa / (np * warp_size)][cpy_ne];
|
|
465
|
+
__dpct_align__(16) sycl::half2 Q_k[cpw][cpy_ne];
|
|
466
|
+
#else
|
|
467
|
+
static_assert(nbatch_K % cpy_ne == 0, "bad nbatch_K");
|
|
468
|
+
#pragma unroll
|
|
469
|
+
for (int k_KQ_1 = 0; k_KQ_1 < nbatch_K; k_KQ_1 += cpy_ne) {
|
|
470
|
+
__dpct_align__(16) float K_k[nbatch_fa/(np*warp_size)][cpy_ne];
|
|
471
|
+
__dpct_align__(16) float Q_k[cpw][cpy_ne];
|
|
472
|
+
#endif // SYCL_FAST_FP16
|
|
473
|
+
|
|
474
|
+
#pragma unroll
|
|
475
|
+
for (int i_KQ_0 = 0; i_KQ_0 < nbatch_fa; i_KQ_0 += np*warp_size) {
|
|
476
|
+
const int i_KQ = i_KQ_0 + (item_ct1.get_local_id(1) % np) * warp_size + item_ct1.get_local_id(2);
|
|
477
|
+
|
|
478
|
+
#ifdef SYCL_FAST_FP16
|
|
479
|
+
ggml_sycl_memcpy_1<cpy_nb>(&K_k[i_KQ_0/(np*warp_size)], &KV_tmp[i_KQ*(nbatch_K/2 + cpy_ne) + k_KQ_1]);
|
|
480
|
+
#else
|
|
481
|
+
ggml_sycl_memcpy_1<cpy_nb>(&K_k[i_KQ_0/(np*warp_size)], &KV_tmp[i_KQ*(nbatch_K + cpy_ne) + k_KQ_1]);
|
|
482
|
+
#endif // SYCL_FAST_FP16
|
|
483
|
+
}
|
|
484
|
+
#pragma unroll
|
|
485
|
+
for (int jc0 = 0; jc0 < cpw; ++jc0) {
|
|
486
|
+
const int jc = jc0 + (item_ct1.get_local_id(1) / np) * cpw;
|
|
487
|
+
|
|
488
|
+
#ifdef SYCL_FAST_FP16
|
|
489
|
+
ggml_sycl_memcpy_1<cpy_nb>(&Q_k[jc0], &Q_tmp[jc*(DKQ/2) + k_KQ_0/2 + k_KQ_1]);
|
|
490
|
+
#else
|
|
491
|
+
ggml_sycl_memcpy_1<cpy_nb>(&Q_k[jc0], &Q_tmp[jc* DKQ + k_KQ_0 + k_KQ_1]);
|
|
492
|
+
#endif // SYCL_FAST_FP16
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
#pragma unroll
|
|
496
|
+
for (int i_KQ_0 = 0; i_KQ_0 < nbatch_fa; i_KQ_0 += np*warp_size) {
|
|
497
|
+
#pragma unroll
|
|
498
|
+
for (int jc0 = 0; jc0 < cpw; ++jc0) {
|
|
499
|
+
#pragma unroll
|
|
500
|
+
for (int k = 0; k < cpy_ne; ++k) {
|
|
501
|
+
ggml_sycl_mad(KQ_acc[i_KQ_0/(np*warp_size)*cpw + jc0], K_k[i_KQ_0/(np*warp_size)][k], Q_k[jc0][k]);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (k_KQ_0 + nbatch_K < DKQ) {
|
|
508
|
+
item_ct1.barrier(); // Sync not needed on last iteration.
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Function that performs a single iteration of the main loop over up to nbatch_fa tokens.
|
|
513
|
+
template <int warp_size,
|
|
514
|
+
int nwarps,
|
|
515
|
+
int ncols1,
|
|
516
|
+
int ncols2,
|
|
517
|
+
int DKQ,
|
|
518
|
+
int DV,
|
|
519
|
+
int nbatch_fa,
|
|
520
|
+
int nbatch_K,
|
|
521
|
+
bool use_logit_softcap,
|
|
522
|
+
bool oob_check,
|
|
523
|
+
typename T_vec_dot,
|
|
524
|
+
typename T_KQ,
|
|
525
|
+
typename T_acc>
|
|
526
|
+
/*
|
|
527
|
+
The total declared local variable size in device function flash_attn_tile_iter exceeds 128 bytes and may cause high register pressure. Consult with your hardware vendor to find the total register size available and adjust the code, or use smaller sub-group size to avoid high register pressure.
|
|
528
|
+
*/
|
|
529
|
+
static __dpct_inline__ void flash_attn_tile_iter(T_vec_dot * const Q_tmp,
|
|
530
|
+
const sycl::half2 * const __restrict__ K_h2,
|
|
531
|
+
const sycl::half2 * const __restrict__ V_h2,
|
|
532
|
+
const sycl::half * const __restrict__ mask,
|
|
533
|
+
const sycl::uint3 ne01,
|
|
534
|
+
const float logit_softcap,
|
|
535
|
+
const float slope,
|
|
536
|
+
T_KQ * const KQ,
|
|
537
|
+
T_vec_dot * const KV_tmp,
|
|
538
|
+
const int stride_K2,
|
|
539
|
+
const int stride_V2,
|
|
540
|
+
const int stride_mask,
|
|
541
|
+
float * const KQ_max,
|
|
542
|
+
float * const KQ_sum,
|
|
543
|
+
T_acc * const VKQ,
|
|
544
|
+
const int k_VKQ_0,
|
|
545
|
+
const int k_VKQ_max,
|
|
546
|
+
const int col_Q_0,
|
|
547
|
+
float * KQ_max_new_shared) {
|
|
548
|
+
auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item<3>();
|
|
549
|
+
constexpr int cpy_nb = ggml_sycl_get_max_cpy_bytes();
|
|
550
|
+
constexpr int cpy_ne = cpy_nb / 4;
|
|
551
|
+
|
|
552
|
+
constexpr int ncols = ncols1*ncols2;
|
|
553
|
+
constexpr int cpw = ncols > nwarps ? ncols/nwarps : 1; // Q columns per warp
|
|
554
|
+
constexpr int np = nwarps > ncols ? nwarps/ncols : 1; // number of parallel warps per Q column
|
|
555
|
+
|
|
556
|
+
constexpr int DVp = (DV + 2*warp_size - 1) & ~(2*warp_size - 1); // DV padded to multiple of 2*warp_size.
|
|
557
|
+
|
|
558
|
+
#ifdef SYCL_FAST_FP16
|
|
559
|
+
constexpr int KQ_cs = cpw < 2*cpy_ne ? cpw : 2*cpy_ne;
|
|
560
|
+
#else
|
|
561
|
+
constexpr int KQ_cs = cpw < 1*cpy_ne ? cpw : 1*cpy_ne;
|
|
562
|
+
#endif // SYCL_FAST_FP16
|
|
563
|
+
static_assert(cpw % KQ_cs == 0, "bad KQ_cs");
|
|
564
|
+
const int k_VKQ_sup = k_VKQ_max - k_VKQ_0; // k supremum, only smaller k values have valid KV data
|
|
565
|
+
|
|
566
|
+
float KQ_max_new[cpw];
|
|
567
|
+
#pragma unroll
|
|
568
|
+
for (int jc0 = 0; jc0 < cpw; ++jc0) {
|
|
569
|
+
KQ_max_new[jc0] = KQ_max[jc0];
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
float KQ_acc[nbatch_fa/(np*warp_size) * cpw] = {0.0f}; // Accumulators for KQ matrix multiplication.
|
|
573
|
+
|
|
574
|
+
// KQ = K @ Q matrix multiplication:
|
|
575
|
+
constexpr int nbatch_K_last = DKQ % nbatch_K;
|
|
576
|
+
#pragma unroll
|
|
577
|
+
for (int k_KQ_0 = 0; k_KQ_0 < DKQ - nbatch_K_last; k_KQ_0 += nbatch_K) {
|
|
578
|
+
flash_attn_tile_iter_KQ<warp_size, nwarps, ncols1, ncols2, DKQ, nbatch_fa, nbatch_K, use_logit_softcap, oob_check>(
|
|
579
|
+
Q_tmp, K_h2, KV_tmp, stride_K2, k_VKQ_0, k_VKQ_sup, k_KQ_0, KQ_acc);
|
|
580
|
+
}
|
|
581
|
+
if (nbatch_K_last > 0) {
|
|
582
|
+
constexpr int k_KQ_0 = DKQ - nbatch_K_last;
|
|
583
|
+
flash_attn_tile_iter_KQ<warp_size, nwarps, ncols1, ncols2, DKQ, nbatch_fa, nbatch_K_last, use_logit_softcap, oob_check>(
|
|
584
|
+
Q_tmp, K_h2, KV_tmp, stride_K2, k_VKQ_0, k_VKQ_sup, k_KQ_0, KQ_acc);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// Apply logit softcap + mask, update KQ_max:
|
|
588
|
+
#pragma unroll
|
|
589
|
+
for (int jc0 = 0; jc0 < cpw; ++jc0) {
|
|
590
|
+
const int j = fastmodulo(col_Q_0 + (jc0 + (item_ct1.get_local_id(1) / np) * cpw) / ncols2, ne01);
|
|
591
|
+
|
|
592
|
+
#pragma unroll
|
|
593
|
+
for (int i_KQ_0 = 0; i_KQ_0 < nbatch_fa; i_KQ_0 += np*warp_size) {
|
|
594
|
+
const int i_KQ = i_KQ_0 + (item_ct1.get_local_id(1) % np) * warp_size + item_ct1.get_local_id(2);
|
|
595
|
+
|
|
596
|
+
#if defined(SYCL_FAST_FP16) && !defined(GGML_SYCL_F16)
|
|
597
|
+
// Without the v_dot2_f32_f16 instruction there is a higher risk of numerical overflow in the KQ calculation.
|
|
598
|
+
// Therefore, scale down Q values and apply the inverse scale the FP32 KQ values afterwards again.
|
|
599
|
+
KQ_acc[i_KQ_0/(np*warp_size)*cpw + jc0] *= 4.0f;
|
|
600
|
+
#endif // defined(SYCL_FAST_FP16) && !defined(GGML_SYCL_F16)
|
|
601
|
+
|
|
602
|
+
if (use_logit_softcap) {
|
|
603
|
+
KQ_acc[(i_KQ_0 / (np * warp_size)) * cpw + jc0] =
|
|
604
|
+
logit_softcap * sycl::tanh((float) KQ_acc[(i_KQ_0 / (np * warp_size)) * cpw + jc0]);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
if (!oob_check || i_KQ < k_VKQ_sup) {
|
|
608
|
+
KQ_acc[(i_KQ_0 / (np * warp_size)) * cpw + jc0] +=
|
|
609
|
+
(ncols2 > 1 || mask) ? slope * sycl::vec<sycl::half, 1>(mask[j * stride_mask + k_VKQ_0 + i_KQ])
|
|
610
|
+
.convert<float, sycl::rounding_mode::automatic>()[0] :
|
|
611
|
+
0.0f;
|
|
612
|
+
|
|
613
|
+
KQ_max_new[jc0] =
|
|
614
|
+
sycl::fmax((float) KQ_max_new[jc0],
|
|
615
|
+
(float) (KQ_acc[(i_KQ_0 / (np * warp_size)) * cpw + jc0] + FATTN_KQ_MAX_OFFSET));
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
KQ_max_new[jc0] = warp_reduce_max<warp_size>(KQ_max_new[jc0]);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if constexpr (np == 1) {
|
|
623
|
+
item_ct1.barrier();
|
|
624
|
+
} else {
|
|
625
|
+
static_assert(cpw == 1, "bad cpw");
|
|
626
|
+
|
|
627
|
+
if (item_ct1.get_local_id(2) == 0) {
|
|
628
|
+
KQ_max_new_shared[item_ct1.get_local_id(1)] = KQ_max_new[0];
|
|
629
|
+
}
|
|
630
|
+
item_ct1.barrier();
|
|
631
|
+
KQ_max_new[0] = KQ_max_new_shared[(item_ct1.get_local_id(1) & ~(np - 1)) + item_ct1.get_local_id(2) % np];
|
|
632
|
+
KQ_max_new[0] = warp_reduce_max<np>(KQ_max_new[0]);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// Calculate KQ softmax, write to shared KQ buffer, re-scale VKQ accumulators:
|
|
636
|
+
#pragma unroll
|
|
637
|
+
for (int jc0 = 0; jc0 < cpw; jc0 += KQ_cs) {
|
|
638
|
+
#ifdef SYCL_FAST_FP16
|
|
639
|
+
__dpct_align__(16) sycl::half tmp[nbatch_fa / (np * warp_size)][KQ_cs];
|
|
640
|
+
#else
|
|
641
|
+
__dpct_align__(16) float tmp[nbatch_fa/(np*warp_size)][KQ_cs];
|
|
642
|
+
#endif // SYCL_FAST_FP16
|
|
643
|
+
|
|
644
|
+
#pragma unroll
|
|
645
|
+
for (int jc1 = 0; jc1 < KQ_cs; ++jc1) {
|
|
646
|
+
const int jc = jc0 + jc1;
|
|
647
|
+
|
|
648
|
+
const float KQ_max_scale = sycl::native::exp((float) (KQ_max[jc] - KQ_max_new[jc]));
|
|
649
|
+
KQ_max[jc] = KQ_max_new[jc];
|
|
650
|
+
|
|
651
|
+
float KQ_sum_add = 0.0f;
|
|
652
|
+
#pragma unroll
|
|
653
|
+
for (int i0 = 0; i0 < nbatch_fa; i0 += np*warp_size) {
|
|
654
|
+
const float val =
|
|
655
|
+
!oob_check || i0 + (item_ct1.get_local_id(1) % np) * warp_size + item_ct1.get_local_id(2) <
|
|
656
|
+
static_cast<uint32_t>(k_VKQ_sup) ?
|
|
657
|
+
sycl::native::exp((float) (KQ_acc[(i0 / (np * warp_size)) * cpw + jc] - KQ_max[jc])) :
|
|
658
|
+
0.0f;
|
|
659
|
+
KQ_sum_add += val;
|
|
660
|
+
tmp[i0/(np*warp_size)][jc1] = val;
|
|
661
|
+
}
|
|
662
|
+
KQ_sum[jc] = KQ_sum[jc]*KQ_max_scale + KQ_sum_add;
|
|
663
|
+
|
|
664
|
+
#ifdef SYCL_FAST_FP16
|
|
665
|
+
const sycl::half2 KQ_max_scale_h2 = sycl::half2(KQ_max_scale, KQ_max_scale);
|
|
666
|
+
#pragma unroll
|
|
667
|
+
for (int i0 = 0; i0 < DVp/2; i0 += warp_size) {
|
|
668
|
+
VKQ[jc*((DVp/2)/warp_size) + i0/warp_size].x() *= KQ_max_scale_h2.x();
|
|
669
|
+
VKQ[jc*((DVp/2)/warp_size) + i0/warp_size].y() *= KQ_max_scale_h2.y();
|
|
670
|
+
}
|
|
671
|
+
#else
|
|
672
|
+
#pragma unroll
|
|
673
|
+
for (int i0 = 0; i0 < DVp/2; i0 += warp_size) {
|
|
674
|
+
VKQ[jc*((DVp/2)/warp_size) + i0/warp_size].x() *= KQ_max_scale;
|
|
675
|
+
VKQ[jc*((DVp/2)/warp_size) + i0/warp_size].y() *= KQ_max_scale;
|
|
676
|
+
}
|
|
677
|
+
#endif // SYCL_FAST_FP16
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
#pragma unroll
|
|
681
|
+
for (int i0 = 0; i0 < nbatch_fa; i0 += np*warp_size) {
|
|
682
|
+
const int i = i0 + (item_ct1.get_local_id(1) % np) * warp_size + item_ct1.get_local_id(2);
|
|
683
|
+
|
|
684
|
+
ggml_sycl_memcpy_1<sizeof(tmp[0])>(
|
|
685
|
+
KQ + (jc0 / KQ_cs + (item_ct1.get_local_id(1) / np) * (cpw / KQ_cs)) * (nbatch_fa * KQ_cs) + i * KQ_cs,
|
|
686
|
+
tmp[i0 / (np * warp_size)]);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// VKQ = V @ KQ matrix multiplication:
|
|
691
|
+
static_assert(DV <= DKQ, "bad DV");
|
|
692
|
+
static_assert(DV % nbatch_K == 0 || (nbatch_K % 3 == 0 && DV % (nbatch_K*2/3) == 0), "bad nbatch_K");
|
|
693
|
+
constexpr int nbatch_V = (DV % nbatch_K == 0 ? nbatch_K : nbatch_K*2/3) * nbatch_fa / DV; // Number of V columns that fit in SRAM for K.
|
|
694
|
+
static_assert(nbatch_fa % nbatch_V == 0, "bad nbatch_V");
|
|
695
|
+
static_assert(nbatch_V % np == 0, "bad nbatch_V");
|
|
696
|
+
#pragma unroll
|
|
697
|
+
for (int k0 = 0; k0 < nbatch_fa; k0 += nbatch_V) {
|
|
698
|
+
flash_attn_tile_load_tile<warp_size, nwarps, nbatch_V, DV, 0, oob_check>
|
|
699
|
+
(V_h2 + int64_t(k_VKQ_0 + k0)*stride_V2, KV_tmp, stride_V2, k_VKQ_sup - k0);
|
|
700
|
+
item_ct1.barrier();
|
|
701
|
+
|
|
702
|
+
#ifdef SYCL_FAST_FP16
|
|
703
|
+
#pragma unroll
|
|
704
|
+
for (int k1 = 0; k1 < nbatch_V; k1 += np) {
|
|
705
|
+
__dpct_align__(16) sycl::half2 V_k[(DVp / 2) / warp_size];
|
|
706
|
+
__dpct_align__(16) sycl::half2 KQ_k[cpw];
|
|
707
|
+
|
|
708
|
+
constexpr int cpy_ne_D = cpy_ne/2 < (DVp/2)/warp_size ? cpy_ne/2 : (DVp/2)/warp_size;
|
|
709
|
+
#pragma unroll
|
|
710
|
+
for (int i0 = 0; i0 < DVp/2; i0 += warp_size*cpy_ne_D) {
|
|
711
|
+
ggml_sycl_memcpy_1<cpy_ne_D * 4>(&V_k[i0 / warp_size],
|
|
712
|
+
&KV_tmp[(k1 + item_ct1.get_local_id(1) % np) * (DV / 2) + i0 +
|
|
713
|
+
item_ct1.get_local_id(2) * cpy_ne_D]);
|
|
714
|
+
}
|
|
715
|
+
#pragma unroll
|
|
716
|
+
for (int jc_VKQ_0 = 0; jc_VKQ_0 < cpw; jc_VKQ_0 += KQ_cs) {
|
|
717
|
+
const int jc_KQ = jc_VKQ_0 / KQ_cs + (item_ct1.get_local_id(1) / np) * (cpw / KQ_cs);
|
|
718
|
+
|
|
719
|
+
__dpct_align__(16) sycl::half tmp[KQ_cs];
|
|
720
|
+
ggml_sycl_memcpy_1<KQ_cs * sizeof(sycl::half)>(
|
|
721
|
+
&tmp, KQ + jc_KQ * (nbatch_fa * KQ_cs) + (k0 + k1 + item_ct1.get_local_id(1) % np) * KQ_cs);
|
|
722
|
+
#pragma unroll
|
|
723
|
+
for (int jc_VKQ_1 = 0; jc_VKQ_1 < KQ_cs; ++jc_VKQ_1) {
|
|
724
|
+
KQ_k[jc_VKQ_0 + jc_VKQ_1] = sycl::half2(tmp[jc_VKQ_1]);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
#pragma unroll
|
|
729
|
+
for (int i0 = 0; i0 < DVp/2; i0 += warp_size) {
|
|
730
|
+
#pragma unroll
|
|
731
|
+
for (int jc_VKQ_0 = 0; jc_VKQ_0 < cpw; ++jc_VKQ_0) {
|
|
732
|
+
VKQ[jc_VKQ_0*((DVp/2)/warp_size) + i0/warp_size].x() +=
|
|
733
|
+
V_k[i0/warp_size].x()*KQ_k[jc_VKQ_0].x();
|
|
734
|
+
VKQ[jc_VKQ_0*((DVp/2)/warp_size) + i0/warp_size].y() +=
|
|
735
|
+
V_k[i0/warp_size].y()*KQ_k[jc_VKQ_0].y();
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
#else
|
|
740
|
+
#pragma unroll
|
|
741
|
+
for (int k1 = 0; k1 < nbatch_V; k1 += np) {
|
|
742
|
+
__dpct_align__(16) sycl::float2 V_k[(DVp/2)/warp_size];
|
|
743
|
+
__dpct_align__(16) float KQ_k[cpw];
|
|
744
|
+
|
|
745
|
+
constexpr int cpy_ne_D = cpy_ne < DVp/warp_size ? cpy_ne : DVp/warp_size;
|
|
746
|
+
#pragma unroll
|
|
747
|
+
for (int i0 = 0; i0 < DVp; i0 += warp_size*cpy_ne_D) {
|
|
748
|
+
ggml_sycl_memcpy_1<cpy_ne_D*4>(&V_k[i0/(2*warp_size)], &KV_tmp[(k1 + item_ct1.get_local_id(1) % np)*DV + i0 + item_ct1.get_local_id(2)*cpy_ne_D]);
|
|
749
|
+
}
|
|
750
|
+
#pragma unroll
|
|
751
|
+
for (int jc_VKQ_0 = 0; jc_VKQ_0 < cpw; jc_VKQ_0 += KQ_cs) {
|
|
752
|
+
const int jc_KQ = jc_VKQ_0/KQ_cs + (item_ct1.get_local_id(1) / np)*(cpw/KQ_cs);
|
|
753
|
+
|
|
754
|
+
ggml_sycl_memcpy_1<KQ_cs*sizeof(float)>(
|
|
755
|
+
&KQ_k[jc_VKQ_0], KQ + jc_KQ*(nbatch_fa*KQ_cs) + (k0 + k1 + item_ct1.get_local_id(1) % np)*KQ_cs);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
#pragma unroll
|
|
759
|
+
for (int i0 = 0; i0 < DVp/2; i0 += warp_size) {
|
|
760
|
+
#pragma unroll
|
|
761
|
+
for (int jc_VKQ_0 = 0; jc_VKQ_0 < cpw; ++jc_VKQ_0) {
|
|
762
|
+
VKQ[jc_VKQ_0*((DVp/2)/warp_size) + i0/warp_size].x() += V_k[i0/warp_size].x()*KQ_k[jc_VKQ_0];
|
|
763
|
+
VKQ[jc_VKQ_0*((DVp/2)/warp_size) + i0/warp_size].y() += V_k[i0/warp_size].y()*KQ_k[jc_VKQ_0];
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
#endif // SYCL_FAST_FP16
|
|
768
|
+
item_ct1.barrier();
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
template <int DKQ, int DV, int ncols1, int ncols2, bool use_logit_softcap, int warp_size> // D == head size
|
|
773
|
+
/*
|
|
774
|
+
The total declared local variable size in device function flash_attn_tile exceeds 128 bytes and may cause high register pressure. Consult with your hardware vendor to find the total register size available and adjust the code, or use smaller sub-group size to avoid high register pressure.
|
|
775
|
+
*/
|
|
776
|
+
static void flash_attn_tile(const char * Q,
|
|
777
|
+
const char * K,
|
|
778
|
+
const char * V,
|
|
779
|
+
const char * mask,
|
|
780
|
+
const char * sinks,
|
|
781
|
+
const int * KV_max,
|
|
782
|
+
float * dst,
|
|
783
|
+
sycl::float2 * dst_meta,
|
|
784
|
+
const float scale,
|
|
785
|
+
const float max_bias,
|
|
786
|
+
const float m0,
|
|
787
|
+
const float m1,
|
|
788
|
+
const uint32_t n_head_log2,
|
|
789
|
+
const float logit_softcap,
|
|
790
|
+
const int32_t ne00,
|
|
791
|
+
const sycl::uint3 ne01,
|
|
792
|
+
const int32_t ne02,
|
|
793
|
+
const int32_t ne03,
|
|
794
|
+
const int32_t nb01,
|
|
795
|
+
const int32_t nb02,
|
|
796
|
+
const int32_t nb03,
|
|
797
|
+
const int32_t ne10,
|
|
798
|
+
const int32_t ne11,
|
|
799
|
+
const int32_t ne12,
|
|
800
|
+
const int32_t ne13,
|
|
801
|
+
const int32_t nb11,
|
|
802
|
+
const int32_t nb12,
|
|
803
|
+
const int64_t nb13,
|
|
804
|
+
const int32_t nb21,
|
|
805
|
+
const int32_t nb22,
|
|
806
|
+
const int64_t nb23,
|
|
807
|
+
const int32_t ne31,
|
|
808
|
+
const int32_t ne32,
|
|
809
|
+
const int32_t ne33,
|
|
810
|
+
const int32_t nb31,
|
|
811
|
+
const int32_t nb32,
|
|
812
|
+
const int64_t nb33) {
|
|
813
|
+
#ifdef SYCL_FLASH_ATTN
|
|
814
|
+
// Skip unused kernel variants for faster compilation:
|
|
815
|
+
auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item<3>();
|
|
816
|
+
if ((use_logit_softcap && !(DV == 128 || DV == 256))) {
|
|
817
|
+
GGML_UNUSED_VARS(Q, K, V, mask, sinks, KV_max, dst, dst_meta, scale,
|
|
818
|
+
max_bias, m0, m1, n_head_log2, logit_softcap,
|
|
819
|
+
ne00, ne01, ne02, ne03,
|
|
820
|
+
nb01, nb02, nb03,
|
|
821
|
+
ne10, ne11, ne12, ne13,
|
|
822
|
+
nb11, nb12, nb13,
|
|
823
|
+
nb21, nb22, nb23,
|
|
824
|
+
ne31, ne32, ne33,
|
|
825
|
+
nb31, nb32, nb33);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
static_assert(ggml_sycl_fattn_tile_get_config(DKQ, DV, ncols1*ncols2) != 0, "kernel config not defined");
|
|
830
|
+
|
|
831
|
+
constexpr int ncols = ncols1*ncols2;
|
|
832
|
+
|
|
833
|
+
constexpr int nwarps = ggml_sycl_fattn_tile_get_nthreads (DKQ, DV, ncols1*ncols2) / warp_size;
|
|
834
|
+
constexpr int nbatch_fa = ggml_sycl_fattn_tile_get_nbatch_fa(DKQ, DV, ncols1*ncols2);
|
|
835
|
+
constexpr int nbatch_K = ggml_sycl_fattn_tile_get_nbatch_K (DKQ, DV, ncols1*ncols2);
|
|
836
|
+
|
|
837
|
+
// In this kernel Q, K, V are matrices while i, j, k are matrix indices.
|
|
838
|
+
|
|
839
|
+
const int col_Q_0 = item_ct1.get_group(2) * ncols1; // Index of the first Q column for this SYCL block to work on.
|
|
840
|
+
|
|
841
|
+
const int sequence = item_ct1.get_group(0) / (ne02 / ncols2);
|
|
842
|
+
const int head0 = item_ct1.get_group(0) * ncols2 - sequence * ne02; // == item_ct1.get_group(0) % (ne02/ncols2)
|
|
843
|
+
const int gqa_ratio = ne02 / ne12; // With grouped query attention there are > 1 Q matrices per K, V matrix.
|
|
844
|
+
const float * Q_f = (const float *) (Q + nb03*sequence + nb02* head0);
|
|
845
|
+
const sycl::half2 * K_h2 = (const sycl::half2 *) (K + nb13 * sequence + nb12 * (head0 / gqa_ratio));
|
|
846
|
+
const sycl::half2 * V_h2 =
|
|
847
|
+
(const sycl::half2 *) (V + nb23 * sequence + nb22 * (head0 / gqa_ratio)); // K and V have same shape
|
|
848
|
+
|
|
849
|
+
const sycl::half * maskh = mask ? (const sycl::half *) (mask + nb33 * (sequence % ne33)) : nullptr;
|
|
850
|
+
|
|
851
|
+
const int stride_K2 = nb11 / sizeof(sycl::half2);
|
|
852
|
+
const int stride_V2 = nb21 / sizeof(sycl::half2);
|
|
853
|
+
const int stride_mask = nb31 / sizeof(sycl::half);
|
|
854
|
+
|
|
855
|
+
const float slope = ncols2 == 1 ? get_alibi_slope(max_bias, head0, n_head_log2, m0, m1) : 1.0f;
|
|
856
|
+
|
|
857
|
+
constexpr int cpy_nb = ggml_sycl_get_max_cpy_bytes();
|
|
858
|
+
constexpr int cpy_ne = cpy_nb / 4;
|
|
859
|
+
|
|
860
|
+
constexpr int cpw = ncols > nwarps ? ncols/nwarps : 1; // Q columns per warp.
|
|
861
|
+
constexpr int np = nwarps > ncols ? nwarps/ncols : 1; // Number of parallel warps per Q column.
|
|
862
|
+
|
|
863
|
+
static_assert(cpw == 1 || np == 1, "bad cpw / np");
|
|
864
|
+
static_assert(nbatch_fa % (np*warp_size) == 0, "nbatch_fa % (np*warp_size) != 0");
|
|
865
|
+
|
|
866
|
+
constexpr int DKQp = (DKQ + 2*warp_size - 1) & ~(2*warp_size - 1); // DKQ padded to multiple of 2*warp_size.
|
|
867
|
+
constexpr int DVp = (DV + 2*warp_size - 1) & ~(2*warp_size - 1); // DV padded to multiple of 2*warp_size.
|
|
868
|
+
|
|
869
|
+
// Q_tmp == SRAM buffer to hold Q data for the entire lifetime of the kernel.
|
|
870
|
+
// KV_tmp == SRAM buffer to hold fragments of K/V data while iterating over ne11.
|
|
871
|
+
// KV_tmp is padded to avoid memory conflicts for K (cpy_ne) and OOB accesses for V (DVp-DV).
|
|
872
|
+
// KQ == SRAM buffer to hold KQ fragments between KQ and VKQ matrix multiplications.
|
|
873
|
+
// VKQ == Accumulators in registers for the final VKQ result.
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
#ifdef SYCL_FAST_FP16
|
|
877
|
+
constexpr size_t lsm_size1 = ncols * DKQ/2 ;
|
|
878
|
+
constexpr size_t lsm_size2 = nbatch_fa * (nbatch_K/2 + cpy_ne) + DVp-DV ;
|
|
879
|
+
constexpr size_t lsm_size3 = ncols * nbatch_fa;
|
|
880
|
+
constexpr size_t lsm_size4 = nwarps;
|
|
881
|
+
|
|
882
|
+
constexpr size_t local_share_mem_size = lsm_size1 * sizeof(sycl::half2) +
|
|
883
|
+
lsm_size2 * sizeof(sycl::half2) +
|
|
884
|
+
lsm_size3 * sizeof(sycl::half) +
|
|
885
|
+
lsm_size4 * sizeof(float);
|
|
886
|
+
|
|
887
|
+
syclex::work_group_static<char[local_share_mem_size]> lsm;
|
|
888
|
+
|
|
889
|
+
sycl::half2 *Q_tmp = (sycl::half2 *)&lsm;
|
|
890
|
+
sycl::half2 *KV_tmp = (sycl::half2*)(Q_tmp +lsm_size1);
|
|
891
|
+
sycl::half *KQ = (sycl::half *)(KV_tmp+lsm_size2);
|
|
892
|
+
float *KQ_max_new_shared = (float *)(KQ+lsm_size3);
|
|
893
|
+
|
|
894
|
+
__dpct_align__(16) sycl::half2 VKQ[cpw * ((DVp / 2) / warp_size)] = {
|
|
895
|
+
{ 0.0f, 0.0f }
|
|
896
|
+
};
|
|
897
|
+
#else
|
|
898
|
+
constexpr size_t lsm_size1 = ncols * DKQ ;
|
|
899
|
+
constexpr size_t lsm_size2 = nbatch_fa * (nbatch_K + cpy_ne) + DVp-DV;
|
|
900
|
+
constexpr size_t lsm_size3 = ncols * nbatch_fa;
|
|
901
|
+
constexpr size_t lsm_size4 = nwarps;
|
|
902
|
+
|
|
903
|
+
constexpr size_t local_share_mem_size = (lsm_size1 + lsm_size2 +lsm_size3 + lsm_size4) * sizeof(float);
|
|
904
|
+
|
|
905
|
+
syclex::work_group_static<char[local_share_mem_size]> lsm;
|
|
906
|
+
|
|
907
|
+
float *Q_tmp = (float *)&lsm;
|
|
908
|
+
float *KV_tmp = Q_tmp +lsm_size1;
|
|
909
|
+
float *KQ = KV_tmp+lsm_size2;
|
|
910
|
+
float *KQ_max_new_shared = KQ+lsm_size3;
|
|
911
|
+
|
|
912
|
+
__dpct_align__(16) sycl::float2 VKQ[cpw * ((DVp/2)/warp_size)] = {{0.0f, 0.0f}};
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
#endif // SYCL_FAST_FP16
|
|
916
|
+
|
|
917
|
+
float KQ_max[cpw] = {};
|
|
918
|
+
|
|
919
|
+
#pragma unroll
|
|
920
|
+
for (int j0 = 0; j0 < ncols; j0 += nwarps) {
|
|
921
|
+
KQ_max[j0/nwarps] = -FLT_MAX/2.0f;
|
|
922
|
+
}
|
|
923
|
+
float KQ_sum[cpw] = {0.0f};
|
|
924
|
+
|
|
925
|
+
// Load Q data, convert to FP16 if fast:
|
|
926
|
+
#pragma unroll
|
|
927
|
+
for (int jc0 = 0; jc0 < cpw; ++jc0) {
|
|
928
|
+
const int jc = jc0 + (item_ct1.get_local_id(1) / np) * cpw;
|
|
929
|
+
|
|
930
|
+
const int j = jc / ncols2;
|
|
931
|
+
const int c = jc % ncols2;
|
|
932
|
+
|
|
933
|
+
constexpr int cpy_ne_D = cpy_ne < DKQp/warp_size ? cpy_ne : DKQp/warp_size;
|
|
934
|
+
|
|
935
|
+
#pragma unroll
|
|
936
|
+
for (int i0 = 0; i0 < DKQp; i0 += np*warp_size*cpy_ne_D) {
|
|
937
|
+
if (i0 + np * warp_size * cpy_ne_D <= DKQ ||
|
|
938
|
+
i0 + (item_ct1.get_local_id(1) % np) * (warp_size * cpy_ne_D) + item_ct1.get_local_id(2) * cpy_ne_D <
|
|
939
|
+
DKQ) {
|
|
940
|
+
__dpct_align__(16) float tmp_f[cpy_ne_D] = { 0.0f };
|
|
941
|
+
ggml_sycl_memcpy_1<sizeof(tmp_f)>(
|
|
942
|
+
tmp_f, &Q_f[c * (nb02 / sizeof(float)) + fastmodulo(col_Q_0 + j, ne01) * (nb01 / sizeof(float)) +
|
|
943
|
+
i0 + (item_ct1.get_local_id(1) % np) * (warp_size * cpy_ne_D) +
|
|
944
|
+
item_ct1.get_local_id(2) * cpy_ne_D]);
|
|
945
|
+
|
|
946
|
+
#pragma unroll
|
|
947
|
+
for (int i1 = 0; i1 < cpy_ne_D; ++i1) {
|
|
948
|
+
tmp_f[i1] *= scale;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
#ifdef SYCL_FAST_FP16
|
|
952
|
+
__dpct_align__(16) sycl::half2 tmp_h2[cpy_ne_D / 2];
|
|
953
|
+
#pragma unroll
|
|
954
|
+
for (int i1 = 0; i1 < cpy_ne_D; i1 += 2) {
|
|
955
|
+
tmp_h2[i1/2] = make_half2(tmp_f[i1 + 0], tmp_f[i1 + 1]);
|
|
956
|
+
#if defined(SYCL_FAST_FP16) && !defined(GGML_SYCL_F16)
|
|
957
|
+
// Without the v_dot2_f32_f16 instruction there is a higher risk of numerical overflow in the KQ calculation.
|
|
958
|
+
// Therefore, scale down Q values and apply the inverse scale the FP32 KQ values afterwards again.
|
|
959
|
+
tmp_h2[i1 / 2] *= sycl::half2(0.25f, 0.25f);
|
|
960
|
+
#endif // defined(SYCL_FAST_FP16) && !defined(GGML_SYCL_F16)
|
|
961
|
+
}
|
|
962
|
+
ggml_sycl_memcpy_1<sizeof(tmp_h2)>(
|
|
963
|
+
&Q_tmp[jc * (DKQ / 2) + i0 / 2 + (item_ct1.get_local_id(1) % np) * (warp_size * cpy_ne_D / 2) +
|
|
964
|
+
item_ct1.get_local_id(2) * (cpy_ne_D / 2)],
|
|
965
|
+
tmp_h2);
|
|
966
|
+
#else
|
|
967
|
+
ggml_sycl_memcpy_1<sizeof(tmp_f)>(
|
|
968
|
+
&Q_tmp[jc* DKQ + i0 + (item_ct1.get_local_id(1) % np)*(warp_size*cpy_ne_D) + item_ct1.get_local_id(2)* cpy_ne_D],
|
|
969
|
+
tmp_f);
|
|
970
|
+
#endif // SYCL_FAST_FP16
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
item_ct1.barrier();
|
|
976
|
+
|
|
977
|
+
// Main loop over KV cache:
|
|
978
|
+
const int k_VKQ_max = KV_max ? KV_max[sequence * item_ct1.get_group_range(2) + item_ct1.get_group(2)] : ne11;
|
|
979
|
+
if (ncols2 == 1) {
|
|
980
|
+
// Branch with out-of-bounds checks.
|
|
981
|
+
int k_VKQ_0 = item_ct1.get_group(1) * nbatch_fa;
|
|
982
|
+
while (k_VKQ_0 < k_VKQ_max - nbatch_fa) {
|
|
983
|
+
constexpr bool oob_check = false;
|
|
984
|
+
flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap,
|
|
985
|
+
oob_check>(Q_tmp, K_h2, V_h2, maskh, ne01, logit_softcap, slope, KQ, KV_tmp, stride_K2,
|
|
986
|
+
stride_V2, stride_mask, KQ_max, KQ_sum, VKQ, k_VKQ_0, k_VKQ_max, col_Q_0,
|
|
987
|
+
KQ_max_new_shared);
|
|
988
|
+
k_VKQ_0 += item_ct1.get_group_range(1) * nbatch_fa;
|
|
989
|
+
}
|
|
990
|
+
if (k_VKQ_0 < k_VKQ_max) {
|
|
991
|
+
constexpr bool oob_check = true;
|
|
992
|
+
flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap,
|
|
993
|
+
oob_check>(Q_tmp, K_h2, V_h2, maskh, ne01, logit_softcap, slope, KQ, KV_tmp, stride_K2,
|
|
994
|
+
stride_V2, stride_mask, KQ_max, KQ_sum, VKQ, k_VKQ_0, k_VKQ_max, col_Q_0,
|
|
995
|
+
KQ_max_new_shared);
|
|
996
|
+
}
|
|
997
|
+
} else {
|
|
998
|
+
// Branch without out-of-bounds checks.
|
|
999
|
+
for (int k_VKQ_0 = item_ct1.get_group(1) * nbatch_fa; k_VKQ_0 < k_VKQ_max;
|
|
1000
|
+
k_VKQ_0 += item_ct1.get_group_range(1) * nbatch_fa) {
|
|
1001
|
+
|
|
1002
|
+
constexpr bool oob_check = false;
|
|
1003
|
+
flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap,
|
|
1004
|
+
oob_check>(Q_tmp, K_h2, V_h2, maskh, ne01, logit_softcap, slope, KQ, KV_tmp, stride_K2,
|
|
1005
|
+
stride_V2, stride_mask, KQ_max, KQ_sum, VKQ, k_VKQ_0, k_VKQ_max, col_Q_0,
|
|
1006
|
+
KQ_max_new_shared);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
#pragma unroll
|
|
1011
|
+
for (int jc0 = 0; jc0 < cpw; ++jc0) {
|
|
1012
|
+
KQ_sum[jc0] = warp_reduce_sum<warp_size>(KQ_sum[jc0]);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
if constexpr (np > 1) {
|
|
1016
|
+
static_assert(cpw == 1, "bad cpw");
|
|
1017
|
+
static_assert(nbatch_fa*nbatch_K >= nwarps*DVp, "KV_tmp too small");
|
|
1018
|
+
|
|
1019
|
+
#ifdef SYCL_FAST_FP16
|
|
1020
|
+
sycl::half2 * VKQ_combine = (sycl::half2 *) KV_tmp;
|
|
1021
|
+
#else
|
|
1022
|
+
float * VKQ_combine = (float *) KV_tmp;
|
|
1023
|
+
#endif // SYCL_FAST_FP16
|
|
1024
|
+
|
|
1025
|
+
float * KQ_sum_combine = (float *) Q_tmp;
|
|
1026
|
+
|
|
1027
|
+
if (item_ct1.get_local_id(1) % np != 0) {
|
|
1028
|
+
|
|
1029
|
+
#ifdef SYCL_FAST_FP16
|
|
1030
|
+
constexpr int cpy_ne_D = cpy_ne < (DVp/2)/warp_size ? cpy_ne : (DVp/2)/warp_size;
|
|
1031
|
+
#pragma unroll
|
|
1032
|
+
for (int i0 = 0; i0 < DVp/2; i0 += warp_size*cpy_ne_D) {
|
|
1033
|
+
ggml_sycl_memcpy_1<cpy_ne_D * 4>(
|
|
1034
|
+
&VKQ_combine[item_ct1.get_local_id(1) * (DVp / 2) + i0 + item_ct1.get_local_id(2) * cpy_ne_D],
|
|
1035
|
+
&VKQ[i0 / warp_size]);
|
|
1036
|
+
}
|
|
1037
|
+
#else
|
|
1038
|
+
|
|
1039
|
+
constexpr int cpy_ne_D = cpy_ne < DVp/warp_size ? cpy_ne : DVp/warp_size;
|
|
1040
|
+
|
|
1041
|
+
#pragma unroll
|
|
1042
|
+
for (int i0 = 0; i0 < DVp; i0 += warp_size*cpy_ne_D) {
|
|
1043
|
+
ggml_sycl_memcpy_1<cpy_ne_D*4>(
|
|
1044
|
+
&VKQ_combine[item_ct1.get_local_id(1)*DVp + i0 + item_ct1.get_local_id(2)*cpy_ne_D], ((const float *) VKQ) + i0/warp_size);
|
|
1045
|
+
}
|
|
1046
|
+
#endif // SYCL_FAST_FP16
|
|
1047
|
+
|
|
1048
|
+
if (item_ct1.get_local_id(2) == 0) {
|
|
1049
|
+
KQ_sum_combine[item_ct1.get_local_id(1)] = KQ_sum[0];
|
|
1050
|
+
}
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
item_ct1.barrier();
|
|
1055
|
+
|
|
1056
|
+
#pragma unroll
|
|
1057
|
+
for (int ip = 1; ip < np; ++ip) {
|
|
1058
|
+
#ifdef SYCL_FAST_FP16
|
|
1059
|
+
constexpr int cpy_ne_D = cpy_ne < (DVp/2)/warp_size ? cpy_ne : (DVp/2)/warp_size;
|
|
1060
|
+
#pragma unroll
|
|
1061
|
+
for (int i0 = 0; i0 < DVp/2; i0 += warp_size*cpy_ne_D) {
|
|
1062
|
+
__dpct_align__(16) sycl::half2 tmp[cpy_ne_D];
|
|
1063
|
+
ggml_sycl_memcpy_1<cpy_ne_D * 4>(tmp, &VKQ_combine[(item_ct1.get_local_id(1) + ip) * (DVp / 2) + i0 +
|
|
1064
|
+
item_ct1.get_local_id(2) * cpy_ne_D]);
|
|
1065
|
+
#pragma unroll
|
|
1066
|
+
for (int i1 = 0; i1 < cpy_ne_D; ++i1) {
|
|
1067
|
+
VKQ[i0/warp_size + i1] += tmp[i1];
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
#else
|
|
1071
|
+
constexpr int cpy_ne_D = cpy_ne < DVp/warp_size ? cpy_ne : DVp/warp_size;
|
|
1072
|
+
#pragma unroll
|
|
1073
|
+
for (int i0 = 0; i0 < DVp; i0 += warp_size*cpy_ne_D) {
|
|
1074
|
+
__dpct_align__(16) float tmp[cpy_ne_D];
|
|
1075
|
+
ggml_sycl_memcpy_1<cpy_ne_D*4>(tmp, &VKQ_combine[(item_ct1.get_local_id(1) + ip)*DVp + i0 + item_ct1.get_local_id(2)*cpy_ne_D]);
|
|
1076
|
+
#pragma unroll
|
|
1077
|
+
for (int i1 = 0; i1 < cpy_ne_D; ++i1) {
|
|
1078
|
+
((float *)VKQ)[i0/warp_size + i1] += tmp[i1];
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
#endif // SYCL_FAST_FP16
|
|
1082
|
+
|
|
1083
|
+
KQ_sum[0] += KQ_sum_combine[item_ct1.get_local_id(1) + ip];
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
// Attention sink: adjust KQ max and sum only for the first of all parallel blocks:
|
|
1088
|
+
if (sinks && item_ct1.get_group(1) == 0) {
|
|
1089
|
+
#pragma unroll
|
|
1090
|
+
for (int jc0 = 0; jc0 < cpw; ++jc0) {
|
|
1091
|
+
const int jc = jc0 + (item_ct1.get_local_id(1) / np) * cpw;
|
|
1092
|
+
const float sink = ((const float *) sinks)[head0 + jc % ncols2];
|
|
1093
|
+
|
|
1094
|
+
float KQ_max_new_j = sycl::fmax((float) KQ_max[jc0], sink);
|
|
1095
|
+
const float KQ_max_scale = sycl::native::exp((float) (KQ_max[jc0] - KQ_max_new_j));
|
|
1096
|
+
KQ_max[jc0] = KQ_max_new_j;
|
|
1097
|
+
|
|
1098
|
+
const float val = sycl::native::exp((float) (sink - KQ_max[jc0]));
|
|
1099
|
+
KQ_sum[jc0] = KQ_sum[jc0]*KQ_max_scale + val;
|
|
1100
|
+
|
|
1101
|
+
#ifdef SYCL_FAST_FP16
|
|
1102
|
+
const sycl::half2 KQ_max_scale_h2 = sycl::half2(KQ_max_scale, KQ_max_scale);
|
|
1103
|
+
#pragma unroll
|
|
1104
|
+
for (int i0 = 0; i0 < DVp/2; i0 += warp_size) {
|
|
1105
|
+
VKQ[jc0*((DVp/2)/warp_size) + i0/warp_size] *= KQ_max_scale_h2;
|
|
1106
|
+
}
|
|
1107
|
+
#else
|
|
1108
|
+
#pragma unroll
|
|
1109
|
+
for (int i0 = 0; i0 < DVp/2; i0 += warp_size) {
|
|
1110
|
+
VKQ[jc0*((DVp/2)/warp_size) + i0/warp_size].x() *= KQ_max_scale;
|
|
1111
|
+
VKQ[jc0*((DVp/2)/warp_size) + i0/warp_size].y() *= KQ_max_scale;
|
|
1112
|
+
}
|
|
1113
|
+
#endif // SYCL_FAST_FP16
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// Write back results:
|
|
1118
|
+
#pragma unroll
|
|
1119
|
+
for (int jc0 = 0; jc0 < cpw; ++jc0) {
|
|
1120
|
+
const int jc = jc0 + (item_ct1.get_local_id(1) / np) * cpw;
|
|
1121
|
+
|
|
1122
|
+
const int j = jc / ncols2;
|
|
1123
|
+
const int c = jc % ncols2;
|
|
1124
|
+
|
|
1125
|
+
if (ncols1 > 1 && col_Q_0 + j >= int(ne01.z())) {
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
const float scale = item_ct1.get_group_range(1) == 1 ? 1.0f / KQ_sum[jc0] : 1.0f;
|
|
1130
|
+
|
|
1131
|
+
const int j_dst_unrolled =
|
|
1132
|
+
((sequence * int(ne01.z()) + col_Q_0 + j) * ne02 + head0 + c) * item_ct1.get_group_range(1) +
|
|
1133
|
+
item_ct1.get_group(1);
|
|
1134
|
+
|
|
1135
|
+
#ifdef SYCL_FAST_FP16
|
|
1136
|
+
constexpr int cpy_ne_D = cpy_ne/2 < (DVp/2)/warp_size ? cpy_ne/2 : (DVp/2)/warp_size;
|
|
1137
|
+
#pragma unroll
|
|
1138
|
+
for (int i0 = 0; i0 < DVp/2; i0 += warp_size*cpy_ne_D) {
|
|
1139
|
+
__dpct_align__(16) sycl::float2 tmp[cpy_ne_D];
|
|
1140
|
+
#pragma unroll
|
|
1141
|
+
for (int i1 = 0; i1 < cpy_ne_D; ++i1) {
|
|
1142
|
+
tmp[i1] = VKQ[jc0 * ((DVp / 2) / warp_size) + i0 / warp_size + i1]
|
|
1143
|
+
.template convert<float, sycl::rounding_mode::automatic>();
|
|
1144
|
+
tmp[i1].x() *= scale;
|
|
1145
|
+
tmp[i1].y() *= scale;
|
|
1146
|
+
}
|
|
1147
|
+
if (i0 + warp_size * cpy_ne_D <= DV / 2 || i0 + item_ct1.get_local_id(2) * cpy_ne_D < DV / 2) {
|
|
1148
|
+
ggml_sycl_memcpy_1<sizeof(tmp)>(
|
|
1149
|
+
&dst[j_dst_unrolled * DV + 2 * i0 + item_ct1.get_local_id(2) * (2 * cpy_ne_D)], tmp);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
#else
|
|
1153
|
+
constexpr int cpy_ne_D = cpy_ne < DVp/warp_size ? cpy_ne : DVp/warp_size;
|
|
1154
|
+
#pragma unroll
|
|
1155
|
+
for (int i0 = 0; i0 < DVp; i0 += warp_size*cpy_ne_D) {
|
|
1156
|
+
if (i0 + warp_size*cpy_ne_D <= DV || i0 + item_ct1.get_local_id(2)*cpy_ne_D < DV) {
|
|
1157
|
+
#pragma unroll
|
|
1158
|
+
for (int i1 = 0; i1 < cpy_ne_D/2; ++i1) {
|
|
1159
|
+
VKQ[jc0*((DVp/2)/warp_size) + i0/(2*warp_size) + i1].x() *= scale;
|
|
1160
|
+
VKQ[jc0*((DVp/2)/warp_size) + i0/(2*warp_size) + i1].y() *= scale;
|
|
1161
|
+
}
|
|
1162
|
+
ggml_sycl_memcpy_1<cpy_ne_D*4>(
|
|
1163
|
+
&dst[j_dst_unrolled*DV + i0 + item_ct1.get_local_id(2)*cpy_ne_D],
|
|
1164
|
+
&VKQ[jc0*((DVp/2)/warp_size) + i0/(2*warp_size)]);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
#endif // SYCL_FAST_FP16
|
|
1168
|
+
|
|
1169
|
+
if (item_ct1.get_group_range(1) != 1 && item_ct1.get_local_id(2) == 0) {
|
|
1170
|
+
dst_meta[j_dst_unrolled] = make_float2(KQ_max[jc0], KQ_sum[jc0]);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
#else
|
|
1174
|
+
GGML_UNUSED_VARS(Q, K, V, mask, sinks, KV_max, dst, dst_meta, scale,
|
|
1175
|
+
max_bias, m0, m1, n_head_log2, logit_softcap,
|
|
1176
|
+
ne00, ne01, ne02, ne03,
|
|
1177
|
+
nb01, nb02, nb03,
|
|
1178
|
+
ne10, ne11, ne12, ne13,
|
|
1179
|
+
nb11, nb12, nb13,
|
|
1180
|
+
nb21, nb22, nb23,
|
|
1181
|
+
ne31, ne32, ne33,
|
|
1182
|
+
nb31, nb32, nb33);
|
|
1183
|
+
#endif // SYCL_FLASH_ATTN
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
template <int DKQ, int DV, int ncols2, bool use_logit_softcap>
|
|
1187
|
+
static void launch_fattn_tile_switch_ncols1(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
|
|
1188
|
+
const ggml_tensor * Q = dst->src[0];
|
|
1189
|
+
|
|
1190
|
+
const int id = ggml_sycl_get_device();
|
|
1191
|
+
const int cc = ggml_sycl_info().devices[id].cc;
|
|
1192
|
+
const int warp_size = WARP_32_SIZE; //can't support WARP_16_SIZE
|
|
1193
|
+
|
|
1194
|
+
constexpr size_t nbytes_shared = 0;
|
|
1195
|
+
|
|
1196
|
+
if constexpr (DV <= 256) {
|
|
1197
|
+
if (Q->ne[1] > 16/ncols2) {
|
|
1198
|
+
constexpr int cols_per_block = 32;
|
|
1199
|
+
const int nwarps = ggml_sycl_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
|
1200
|
+
const int nbatch_fa = ggml_sycl_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
|
1201
|
+
launch_fattn<DV, cols_per_block/ncols2, ncols2,
|
|
1202
|
+
flash_attn_tile<DKQ, DV, cols_per_block / ncols2, ncols2, use_logit_softcap, warp_size>, warp_size>
|
|
1203
|
+
(ctx, dst, nwarps, nbytes_shared, nbatch_fa, true, true, false);
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
if (Q->ne[1] > 8/ncols2) {
|
|
1209
|
+
constexpr int cols_per_block = 16;
|
|
1210
|
+
const int nwarps = ggml_sycl_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
|
1211
|
+
const int nbatch_fa = ggml_sycl_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
|
1212
|
+
launch_fattn<DV, cols_per_block/ncols2, ncols2,
|
|
1213
|
+
flash_attn_tile<DKQ, DV, cols_per_block / ncols2, ncols2, use_logit_softcap, warp_size>, warp_size>
|
|
1214
|
+
(ctx, dst, nwarps, nbytes_shared, nbatch_fa, true, true, false);
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
if constexpr (ncols2 <= 8) {
|
|
1219
|
+
if (Q->ne[1] > 4/ncols2) {
|
|
1220
|
+
constexpr int cols_per_block = 8;
|
|
1221
|
+
const int nwarps = ggml_sycl_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
|
1222
|
+
const int nbatch_fa = ggml_sycl_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
|
1223
|
+
launch_fattn<DV, cols_per_block/ncols2, ncols2,
|
|
1224
|
+
flash_attn_tile<DKQ, DV, cols_per_block / ncols2, ncols2, use_logit_softcap, warp_size>, warp_size>
|
|
1225
|
+
(ctx, dst, nwarps, nbytes_shared, nbatch_fa, true, true, false);
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
if constexpr (ncols2 <= 4) {
|
|
1231
|
+
if (Q->ne[1] > 2/ncols2) {
|
|
1232
|
+
constexpr int cols_per_block = 4;
|
|
1233
|
+
const int nwarps = ggml_sycl_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
|
1234
|
+
const int nbatch_fa = ggml_sycl_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
|
1235
|
+
launch_fattn<DV, cols_per_block/ncols2, ncols2,
|
|
1236
|
+
flash_attn_tile<DKQ, DV, cols_per_block / ncols2, ncols2, use_logit_softcap, warp_size>, warp_size>
|
|
1237
|
+
(ctx, dst, nwarps, nbytes_shared, nbatch_fa, true, true, false);
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
if constexpr (ncols2 <= 2) {
|
|
1243
|
+
constexpr int cols_per_block = 2;
|
|
1244
|
+
const int nwarps = ggml_sycl_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
|
1245
|
+
const int nbatch_fa = ggml_sycl_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
|
1246
|
+
launch_fattn<DV, cols_per_block/ncols2, ncols2,
|
|
1247
|
+
flash_attn_tile<DKQ, DV, cols_per_block / ncols2, ncols2, use_logit_softcap, warp_size>, warp_size>
|
|
1248
|
+
(ctx, dst, nwarps, nbytes_shared, nbatch_fa, true, true, false);
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
GGML_ABORT("fatal error");
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
template <int DKQ, int DV, bool use_logit_softcap>
|
|
1256
|
+
static void launch_fattn_tile_switch_ncols2(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
|
|
1257
|
+
const ggml_tensor * KQV = dst;
|
|
1258
|
+
const ggml_tensor * Q = dst->src[0];
|
|
1259
|
+
const ggml_tensor * K = dst->src[1];
|
|
1260
|
+
const ggml_tensor * mask = dst->src[3];
|
|
1261
|
+
|
|
1262
|
+
float max_bias = 0.0f;
|
|
1263
|
+
memcpy(&max_bias, (const float *) KQV->op_params + 1, sizeof(float));
|
|
1264
|
+
|
|
1265
|
+
GGML_ASSERT(Q->ne[2] % K->ne[2] == 0);
|
|
1266
|
+
const int gqa_ratio = Q->ne[2] / K->ne[2];
|
|
1267
|
+
|
|
1268
|
+
// On NVIDIA (Pascal and older) the GQA optimizations seem to be detrimental in some cases.
|
|
1269
|
+
// However, for DKQ == 576, DV == 512 only the kernel variant with GQA optimizations is implemented.
|
|
1270
|
+
//const bool nvidia = GGML_SYCL_CC_IS_NVIDIA(ggml_sycl_info().devices[ggml_sycl_get_device()].cc);
|
|
1271
|
+
const int gqa_limit = gqa_ratio <= 4 && DV <= 256 ? 16 : INT_MAX;
|
|
1272
|
+
const bool use_gqa_opt = mask && max_bias == 0.0f && Q->ne[1] <= gqa_limit && K->ne[1] % FATTN_KQ_STRIDE == 0;
|
|
1273
|
+
|
|
1274
|
+
if constexpr (DV == 512) {
|
|
1275
|
+
if (use_gqa_opt && gqa_ratio % 16 == 0) {
|
|
1276
|
+
launch_fattn_tile_switch_ncols1<DKQ, DV, 16, use_logit_softcap>(ctx, dst);
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
if (use_gqa_opt && gqa_ratio % 4 == 0) {
|
|
1280
|
+
launch_fattn_tile_switch_ncols1<DKQ, DV, 4, use_logit_softcap>(ctx, dst);
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
if constexpr (DV <= 256) {
|
|
1286
|
+
if (use_gqa_opt && gqa_ratio % 8 == 0) {
|
|
1287
|
+
launch_fattn_tile_switch_ncols1<DKQ, DV, 8, use_logit_softcap>(ctx, dst);
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
if (use_gqa_opt && gqa_ratio % 4 == 0) {
|
|
1292
|
+
launch_fattn_tile_switch_ncols1<DKQ, DV, 4, use_logit_softcap>(ctx, dst);
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
if (use_gqa_opt && gqa_ratio % 2 == 0) {
|
|
1297
|
+
launch_fattn_tile_switch_ncols1<DKQ, DV, 2, use_logit_softcap>(ctx, dst);
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
launch_fattn_tile_switch_ncols1<DKQ, DV, 1, use_logit_softcap>(ctx, dst);
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
GGML_ABORT("fatal error");
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
template <int DKQ, int DV>
|
|
1308
|
+
void ggml_sycl_flash_attn_ext_tile_case(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
|
|
1309
|
+
const ggml_tensor * KQV = dst;
|
|
1310
|
+
|
|
1311
|
+
float logit_softcap;
|
|
1312
|
+
memcpy(&logit_softcap, (const float *) KQV->op_params + 2, sizeof(float));
|
|
1313
|
+
|
|
1314
|
+
if (logit_softcap == 0.0f) {
|
|
1315
|
+
constexpr bool use_logit_softcap = false;
|
|
1316
|
+
launch_fattn_tile_switch_ncols2<DKQ, DV, use_logit_softcap>(ctx, dst);
|
|
1317
|
+
} else {
|
|
1318
|
+
constexpr bool use_logit_softcap = true;
|
|
1319
|
+
launch_fattn_tile_switch_ncols2<DKQ, DV, use_logit_softcap>(ctx, dst);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
void ggml_sycl_flash_attn_ext_tile(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
|
|
1324
|
+
|
|
1325
|
+
#define DECL_FATTN_TILE_CASE(DKQ, DV) \
|
|
1326
|
+
template void ggml_sycl_flash_attn_ext_tile_case \
|
|
1327
|
+
<DKQ, DV>(ggml_backend_sycl_context & ctx, ggml_tensor * dst) \
|
|
1328
|
+
|
|
1329
|
+
extern DECL_FATTN_TILE_CASE( 40, 40);
|
|
1330
|
+
extern DECL_FATTN_TILE_CASE( 64, 64);
|
|
1331
|
+
extern DECL_FATTN_TILE_CASE( 72, 72);
|
|
1332
|
+
extern DECL_FATTN_TILE_CASE( 80, 80);
|
|
1333
|
+
extern DECL_FATTN_TILE_CASE( 96, 96);
|
|
1334
|
+
extern DECL_FATTN_TILE_CASE(112, 112);
|
|
1335
|
+
extern DECL_FATTN_TILE_CASE(128, 128);
|
|
1336
|
+
extern DECL_FATTN_TILE_CASE(256, 256);
|
|
1337
|
+
extern DECL_FATTN_TILE_CASE(576, 512);
|
|
1338
|
+
|