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,823 @@
|
|
|
1
|
+
#include "utils.h"
|
|
2
|
+
|
|
3
|
+
#include "ggml-impl.h"
|
|
4
|
+
#include "ggml-openvino-extra.h"
|
|
5
|
+
#include "ggml-openvino/ggml-decoder.h"
|
|
6
|
+
#include "ggml.h"
|
|
7
|
+
#include "openvino/frontend.h"
|
|
8
|
+
#include "openvino/input_model.h"
|
|
9
|
+
|
|
10
|
+
#include <algorithm>
|
|
11
|
+
#include <cassert>
|
|
12
|
+
#include <cmath>
|
|
13
|
+
#include <cstddef>
|
|
14
|
+
#include <cstdint>
|
|
15
|
+
#include <cstdlib>
|
|
16
|
+
#include <cstring>
|
|
17
|
+
#include <iomanip>
|
|
18
|
+
#include <iostream>
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include <openvino/core/any.hpp>
|
|
21
|
+
#include <openvino/core/graph_util.hpp>
|
|
22
|
+
#include <openvino/core/shape.hpp>
|
|
23
|
+
#include <openvino/core/type/float16.hpp>
|
|
24
|
+
#include <openvino/frontend/manager.hpp>
|
|
25
|
+
#include <openvino/openvino.hpp>
|
|
26
|
+
#include <openvino/runtime/compiled_model.hpp>
|
|
27
|
+
#include <openvino/runtime/infer_request.hpp>
|
|
28
|
+
#include <openvino/runtime/intel_npu/properties.hpp>
|
|
29
|
+
#include <openvino/runtime/properties.hpp>
|
|
30
|
+
#include <openvino/runtime/tensor.hpp>
|
|
31
|
+
#include <string>
|
|
32
|
+
#include <unordered_map>
|
|
33
|
+
#include <vector>
|
|
34
|
+
|
|
35
|
+
// Suppress deprecation warning for ov::Tensor::data()
|
|
36
|
+
#pragma GCC diagnostic push
|
|
37
|
+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
38
|
+
|
|
39
|
+
enum ggml_status ov_graph_compute(ggml_cgraph * cgraph, ggml_backend_t backend) {
|
|
40
|
+
ggml_backend_openvino_context * ctx = (ggml_backend_openvino_context *) backend->context;
|
|
41
|
+
try {
|
|
42
|
+
if (getenv("GGML_OPENVINO_DUMP_CGRAPH")) {
|
|
43
|
+
std::string filename = "cgraph_ov.txt";
|
|
44
|
+
GgmlOvDecoder::dump_cgraph(cgraph, filename);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const auto is_static = ggml_openvino_is_npu();
|
|
48
|
+
|
|
49
|
+
GGML_ASSERT(ctx->runtime_context != nullptr);
|
|
50
|
+
std::shared_ptr<ov_runtime_context> r_ctx = std::static_pointer_cast<ov_runtime_context>(ctx->runtime_context);
|
|
51
|
+
|
|
52
|
+
return is_static ? ov_graph_compute_static(cgraph, r_ctx) : ov_graph_compute_dynamic(cgraph, r_ctx);
|
|
53
|
+
} catch (const ov::Exception & e) {
|
|
54
|
+
GGML_LOG_ERROR("GGML OpenVINO backend ov::Exception: %s\n", e.what());
|
|
55
|
+
return GGML_STATUS_FAILED;
|
|
56
|
+
} catch (const std::exception & e) {
|
|
57
|
+
GGML_LOG_ERROR("GGML OpenVINO backend std::exception: %s\n", e.what());
|
|
58
|
+
return GGML_STATUS_FAILED;
|
|
59
|
+
} catch (...) {
|
|
60
|
+
GGML_LOG_ERROR("GGML OpenVINO backend unknown exception\n");
|
|
61
|
+
return GGML_STATUS_FAILED;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
ov::Tensor create_ov_output_tensor(std::shared_ptr<GgmlOvDecoder> ggml_decoder,
|
|
66
|
+
std::shared_ptr<ov::InferRequest> infer_request,
|
|
67
|
+
int output_index,
|
|
68
|
+
const ggml_tensor * ggml_tensor) {
|
|
69
|
+
auto output_type = ggml_decoder->get_ov_type(ggml_tensor);
|
|
70
|
+
ov::Shape output_shape;
|
|
71
|
+
if (ggml_decoder->is_static()) {
|
|
72
|
+
output_shape = infer_request->get_output_tensor(output_index).get_shape();
|
|
73
|
+
} else {
|
|
74
|
+
output_shape = ggml_decoder->get_shape(ggml_tensor);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
ov::Tensor output_tensor(output_type, output_shape, ggml_tensor->data);
|
|
78
|
+
return output_tensor;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<ov_runtime_context> r_ctx) {
|
|
82
|
+
auto & core = ov_singleton_core();
|
|
83
|
+
const auto & config = ggml_openvino_get_compile_config();
|
|
84
|
+
auto device = r_ctx->device;
|
|
85
|
+
bool stateful = r_ctx->stateful;
|
|
86
|
+
static auto is_static = false;
|
|
87
|
+
|
|
88
|
+
if (is_naive(cgraph)) {
|
|
89
|
+
return naive_compute(cgraph, core, device, config);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
auto start_time = ggml_time_us();
|
|
93
|
+
|
|
94
|
+
std::shared_ptr<GgmlOvDecoder> ggml_decoder;
|
|
95
|
+
std::shared_ptr<ov::InferRequest> infer_request;
|
|
96
|
+
ModelParams m_params;
|
|
97
|
+
ComputeParams c_params;
|
|
98
|
+
std::tie(m_params, c_params) = GgmlOvDecoder::compute_llm_params(cgraph, is_static);
|
|
99
|
+
|
|
100
|
+
graph_key key(cgraph);
|
|
101
|
+
bool cache_hit;
|
|
102
|
+
|
|
103
|
+
int64_t decoder_end_time;
|
|
104
|
+
int64_t conversion_end_time;
|
|
105
|
+
int64_t compile_end_time;
|
|
106
|
+
int64_t infer_end_time;
|
|
107
|
+
|
|
108
|
+
{
|
|
109
|
+
std::lock_guard<std::mutex> lock(r_ctx->ov_compute_mutex);
|
|
110
|
+
|
|
111
|
+
auto it = r_ctx->decoder_cache.find(key);
|
|
112
|
+
|
|
113
|
+
cache_hit = it != r_ctx->decoder_cache.end();
|
|
114
|
+
ModelParams old_m_params;
|
|
115
|
+
if (cache_hit) {
|
|
116
|
+
ggml_decoder = it->second;
|
|
117
|
+
old_m_params = ggml_decoder->get_model_params();
|
|
118
|
+
cache_hit = old_m_params.can_reuse_dynamically(m_params);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (cache_hit) {
|
|
122
|
+
std::map<std::string, std::shared_ptr<ov::Node>> model_weights;
|
|
123
|
+
ggml_decoder->set_compute_params(c_params);
|
|
124
|
+
ggml_decoder->set_model_params(m_params);
|
|
125
|
+
if (old_m_params.kv_buffer_changed(m_params)) {
|
|
126
|
+
ggml_decoder->update_io(cgraph);
|
|
127
|
+
}
|
|
128
|
+
ggml_decoder->add_extra_inputs();
|
|
129
|
+
infer_request = r_ctx->infer_request_cache.at(key);
|
|
130
|
+
|
|
131
|
+
if (stateful) {
|
|
132
|
+
const auto * inp_pos = get_inp_pos_tensor(cgraph);
|
|
133
|
+
int32_t * pos_data = (int32_t *) inp_pos->data;
|
|
134
|
+
auto pos_shape = ggml_decoder->get_shape(inp_pos);
|
|
135
|
+
if (pos_data[0] == 0) {
|
|
136
|
+
infer_request->reset_state();
|
|
137
|
+
r_ctx->stateful_kv_size = pos_shape[3];
|
|
138
|
+
} else if (r_ctx->stateful_kv_size == static_cast<size_t>(pos_data[0])) {
|
|
139
|
+
r_ctx->stateful_kv_size += pos_shape[3];
|
|
140
|
+
} else {
|
|
141
|
+
auto states = infer_request->query_state();
|
|
142
|
+
for (auto state : states) {
|
|
143
|
+
auto state_tensor = state.get_state();
|
|
144
|
+
auto state_tensor_shape = state_tensor.get_shape();
|
|
145
|
+
if (static_cast<uint32_t>(pos_data[0]) > r_ctx->stateful_kv_size) {
|
|
146
|
+
std::string state_name;
|
|
147
|
+
try {
|
|
148
|
+
state_name = r_ctx->kv_state_input_name_map.at(state.get_name());
|
|
149
|
+
} catch (...) {
|
|
150
|
+
GGML_LOG_ERROR("GGML OpenVINO backend stateful inference failed: no input found for the state\n");
|
|
151
|
+
return GGML_STATUS_FAILED;
|
|
152
|
+
}
|
|
153
|
+
auto kv_tensor = get_ov_input_tensor(ggml_decoder, state_name);
|
|
154
|
+
kv_tensor.set_shape({state_tensor_shape[0], kv_tensor.get_shape()[2],
|
|
155
|
+
state_tensor_shape[2], state_tensor_shape[3]});
|
|
156
|
+
state_tensor = kv_tensor;
|
|
157
|
+
state_tensor_shape = state_tensor.get_shape();
|
|
158
|
+
}
|
|
159
|
+
ov::Coordinate begin = {0, 0, 0, 0};
|
|
160
|
+
ov::Coordinate end = {state_tensor_shape[0], static_cast<uint32_t>(pos_data[0]),
|
|
161
|
+
state_tensor_shape[2], state_tensor_shape[3]};
|
|
162
|
+
ov::Tensor new_state_tensor(state_tensor, begin, end);
|
|
163
|
+
state.set_state(new_state_tensor);
|
|
164
|
+
}
|
|
165
|
+
r_ctx->stateful_kv_size = pos_data[0] + 1;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
decoder_end_time = ggml_time_us();
|
|
170
|
+
conversion_end_time = decoder_end_time;
|
|
171
|
+
compile_end_time = decoder_end_time;
|
|
172
|
+
} else {
|
|
173
|
+
r_ctx->infer_request_cache.erase(key);
|
|
174
|
+
|
|
175
|
+
std::shared_ptr<ov::Model> model;
|
|
176
|
+
auto model_weights = GgmlOvDecoder::create_weight_nodes(cgraph);
|
|
177
|
+
|
|
178
|
+
ggml_decoder = std::make_shared<GgmlOvDecoder>(cgraph, m_params, c_params, model_weights, is_static, stateful);
|
|
179
|
+
decoder_end_time = ggml_time_us();
|
|
180
|
+
|
|
181
|
+
auto input_model = std::make_shared<ov::frontend::ggml::InputModel>(ggml_decoder);
|
|
182
|
+
model = ov::frontend::ggml::FrontEnd::convert(input_model);
|
|
183
|
+
ggml_decoder->clear_model_weights();
|
|
184
|
+
conversion_end_time = ggml_time_us();
|
|
185
|
+
|
|
186
|
+
if (getenv("GGML_OPENVINO_DUMP_IR")) {
|
|
187
|
+
char timestamped_filename[64];
|
|
188
|
+
auto timestamp = (long long) ggml_time_us();
|
|
189
|
+
snprintf(timestamped_filename, sizeof(timestamped_filename), "model_%lld.xml", timestamp);
|
|
190
|
+
ov::serialize(model, timestamped_filename);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
ov::CompiledModel compiled_model;
|
|
194
|
+
auto remote_context = ggml_openvino_get_remote_context();
|
|
195
|
+
if (remote_context.has_value()) {
|
|
196
|
+
compiled_model = core.compile_model(model, remote_context.value(), config);
|
|
197
|
+
} else {
|
|
198
|
+
compiled_model = core.compile_model(model, device, config);
|
|
199
|
+
}
|
|
200
|
+
compile_end_time = ggml_time_us();
|
|
201
|
+
infer_request = std::make_shared<ov::InferRequest>(compiled_model.create_infer_request());
|
|
202
|
+
r_ctx->infer_request_cache[key] = infer_request;
|
|
203
|
+
r_ctx->decoder_cache[key] = ggml_decoder;
|
|
204
|
+
|
|
205
|
+
std::vector<std::string> ov_input_names;
|
|
206
|
+
std::vector<std::string> ov_output_names;
|
|
207
|
+
for (const auto & ov_param : model->get_parameters()) {
|
|
208
|
+
ov_input_names.push_back(ov_param->get_friendly_name());
|
|
209
|
+
}
|
|
210
|
+
for (const auto & ov_output : model->get_results()) {
|
|
211
|
+
ov_output_names.push_back(ov_output->get_friendly_name());
|
|
212
|
+
}
|
|
213
|
+
r_ctx->ov_input_names_cache[key] = std::move(ov_input_names);
|
|
214
|
+
r_ctx->ov_output_names_cache[key] = std::move(ov_output_names);
|
|
215
|
+
|
|
216
|
+
if (stateful) {
|
|
217
|
+
const auto * inp_pos = get_inp_pos_tensor(cgraph);
|
|
218
|
+
auto pos_shape = ggml_decoder->get_shape(inp_pos);
|
|
219
|
+
r_ctx->stateful_kv_size = pos_shape[3];
|
|
220
|
+
const auto kv_param_res_names = ggml_decoder->get_kv_param_res_names();
|
|
221
|
+
for (const auto& pair : kv_param_res_names) {
|
|
222
|
+
r_ctx->kv_state_input_name_map[pair.first+pair.second] = pair.first;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
auto ov_input_names = r_ctx->ov_input_names_cache[key];
|
|
228
|
+
auto ov_output_names = r_ctx->ov_output_names_cache[key];
|
|
229
|
+
|
|
230
|
+
for (size_t i = 0; i < ov_input_names.size(); i++) {
|
|
231
|
+
auto param_name = ov_input_names[i];
|
|
232
|
+
auto input_tensor = get_ov_input_tensor(ggml_decoder, param_name);
|
|
233
|
+
infer_request->set_input_tensor(i, input_tensor);
|
|
234
|
+
|
|
235
|
+
if (getenv("GGML_OPENVINO_DEBUG_INPUT")) {
|
|
236
|
+
print_input_tensor_info(param_name, input_tensor);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
for (size_t i = 0; i < ov_output_names.size(); i++) {
|
|
241
|
+
auto * ggml_tensor = ggml_decoder->get_model_outputs().at(ov_output_names[i]);
|
|
242
|
+
auto output_tensor = create_ov_output_tensor(ggml_decoder, infer_request, i, ggml_tensor);
|
|
243
|
+
infer_request->set_output_tensor(i, output_tensor);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
infer_request->infer();
|
|
247
|
+
infer_end_time = ggml_time_us();
|
|
248
|
+
|
|
249
|
+
if (getenv("GGML_OPENVINO_DEBUG_OUTPUT")) {
|
|
250
|
+
for (size_t i = 0; i < ov_output_names.size(); i++) {
|
|
251
|
+
const auto output_tensor = infer_request->get_output_tensor(i);
|
|
252
|
+
print_output_tensor_info(ov_output_names[i], output_tensor, output_tensor.data());
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (getenv("GGML_OPENVINO_PROFILING")) {
|
|
257
|
+
GGML_LOG_INFO("\nGGML OpenVINO Backend: \n");
|
|
258
|
+
GGML_LOG_INFO(" - Graph decoder time: %ld ms \n", (decoder_end_time - start_time) / 1000);
|
|
259
|
+
if (!cache_hit) {
|
|
260
|
+
GGML_LOG_INFO(" - Graph conversion time: %ld ms \n", (conversion_end_time - decoder_end_time) / 1000);
|
|
261
|
+
GGML_LOG_INFO(" - Graph compile time: %ld ms \n", (compile_end_time - conversion_end_time) / 1000);
|
|
262
|
+
}
|
|
263
|
+
GGML_LOG_INFO(" - Graph inference time: %ld ms \n", (infer_end_time - compile_end_time) / 1000);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return GGML_STATUS_SUCCESS;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<ov_runtime_context> r_ctx) {
|
|
271
|
+
auto & core = ov_singleton_core();
|
|
272
|
+
|
|
273
|
+
auto get_prefill_chunk_size = [] {
|
|
274
|
+
const char * chunk_size_str = getenv("GGML_OPENVINO_PREFILL_CHUNK_SIZE");
|
|
275
|
+
if (chunk_size_str && atoi(chunk_size_str) > 0) {
|
|
276
|
+
return atoi(chunk_size_str);
|
|
277
|
+
}
|
|
278
|
+
return 256;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
static std::string device = "NPU";
|
|
282
|
+
static auto is_static = true;
|
|
283
|
+
static auto stateful = false;
|
|
284
|
+
static auto prefill_chunk_size = get_prefill_chunk_size();
|
|
285
|
+
const auto & config = ggml_openvino_get_compile_config();
|
|
286
|
+
|
|
287
|
+
if (is_naive(cgraph)) {
|
|
288
|
+
return naive_compute(cgraph, core, device, config);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
auto start_time = ggml_time_us();
|
|
292
|
+
|
|
293
|
+
std::shared_ptr<GgmlOvDecoder> ggml_decoder;
|
|
294
|
+
std::shared_ptr<ov::InferRequest> infer_request;
|
|
295
|
+
ModelParams m_params;
|
|
296
|
+
ComputeParams c_params;
|
|
297
|
+
std::tie(m_params, c_params) = GgmlOvDecoder::compute_llm_params(cgraph, is_static);
|
|
298
|
+
|
|
299
|
+
const auto * inp_pos = get_inp_pos_tensor(cgraph);
|
|
300
|
+
const auto is_prefill = get_is_prefill(inp_pos);
|
|
301
|
+
graph_key key(cgraph);
|
|
302
|
+
bool cache_hit;
|
|
303
|
+
|
|
304
|
+
int64_t decoder_end_time;
|
|
305
|
+
int64_t conversion_end_time;
|
|
306
|
+
int64_t compile_end_time;
|
|
307
|
+
int64_t infer_end_time;
|
|
308
|
+
|
|
309
|
+
auto it = r_ctx->decoder_cache.find(key);
|
|
310
|
+
|
|
311
|
+
cache_hit = it != r_ctx->decoder_cache.end();
|
|
312
|
+
ModelParams old_m_params;
|
|
313
|
+
if (cache_hit) {
|
|
314
|
+
ggml_decoder = it->second;
|
|
315
|
+
old_m_params = ggml_decoder->get_model_params();
|
|
316
|
+
cache_hit = old_m_params.can_reuse_statically(m_params);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (cache_hit) {
|
|
320
|
+
std::map<std::string, std::shared_ptr<ov::Node>> model_weights;
|
|
321
|
+
ggml_decoder->m_is_prefill = is_prefill;
|
|
322
|
+
ggml_decoder->set_model_params(m_params);
|
|
323
|
+
ggml_decoder->set_compute_params(c_params);
|
|
324
|
+
if (old_m_params.kv_buffer_changed(m_params)) {
|
|
325
|
+
ggml_decoder->update_io(cgraph);
|
|
326
|
+
}
|
|
327
|
+
ggml_decoder->add_extra_inputs();
|
|
328
|
+
infer_request = is_prefill ? r_ctx->infer_request_cache_prefill.at(key) : r_ctx->infer_request_cache.at(key);
|
|
329
|
+
|
|
330
|
+
decoder_end_time = ggml_time_us();
|
|
331
|
+
conversion_end_time = decoder_end_time;
|
|
332
|
+
compile_end_time = decoder_end_time;
|
|
333
|
+
} else {
|
|
334
|
+
r_ctx->infer_request_cache.erase(key);
|
|
335
|
+
r_ctx->infer_request_cache_prefill.erase(key);
|
|
336
|
+
|
|
337
|
+
std::shared_ptr<ov::Model> model;
|
|
338
|
+
auto model_weights = GgmlOvDecoder::create_weight_nodes(cgraph);
|
|
339
|
+
|
|
340
|
+
auto ggml_decoder_prefill = std::make_shared<GgmlOvDecoder>(cgraph, m_params, c_params, model_weights,
|
|
341
|
+
is_static, stateful, true, prefill_chunk_size);
|
|
342
|
+
auto ggml_decoder_decode = std::make_shared<GgmlOvDecoder>(cgraph, m_params, c_params, model_weights, is_static,
|
|
343
|
+
stateful, false, prefill_chunk_size);
|
|
344
|
+
decoder_end_time = ggml_time_us();
|
|
345
|
+
|
|
346
|
+
auto input_model_prefill = std::make_shared<ov::frontend::ggml::InputModel>(ggml_decoder_prefill);
|
|
347
|
+
auto input_model_decode = std::make_shared<ov::frontend::ggml::InputModel>(ggml_decoder_decode);
|
|
348
|
+
|
|
349
|
+
auto model_prefill = ov::frontend::ggml::FrontEnd::convert(input_model_prefill);
|
|
350
|
+
ggml_decoder_prefill->clear_model_weights();
|
|
351
|
+
auto model_decode = ov::frontend::ggml::FrontEnd::convert(input_model_decode);
|
|
352
|
+
ggml_decoder_decode->clear_model_weights();
|
|
353
|
+
conversion_end_time = ggml_time_us();
|
|
354
|
+
|
|
355
|
+
if (getenv("GGML_OPENVINO_DUMP_IR")) {
|
|
356
|
+
char timestamped_filename[64];
|
|
357
|
+
auto timestamp = (long long) ggml_time_us();
|
|
358
|
+
snprintf(timestamped_filename, sizeof(timestamped_filename), "model_prefill_%lld.xml", timestamp);
|
|
359
|
+
ov::serialize(model_prefill, timestamped_filename);
|
|
360
|
+
snprintf(timestamped_filename, sizeof(timestamped_filename), "model_decode_%lld.xml", timestamp);
|
|
361
|
+
ov::serialize(model_decode, timestamped_filename);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
ov::CompiledModel compiled_model_prefill;
|
|
365
|
+
ov::CompiledModel compiled_model_decode;
|
|
366
|
+
auto remote_context = ggml_openvino_get_remote_context();
|
|
367
|
+
if (remote_context.has_value()) {
|
|
368
|
+
compiled_model_prefill = core.compile_model(model_prefill, remote_context.value(), config);
|
|
369
|
+
compiled_model_decode = core.compile_model(model_decode, remote_context.value(), config);
|
|
370
|
+
} else {
|
|
371
|
+
compiled_model_prefill = core.compile_model(model_prefill, device, config);
|
|
372
|
+
compiled_model_decode = core.compile_model(model_decode, device, config);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
r_ctx->infer_request_cache_prefill[key] =
|
|
376
|
+
std::make_shared<ov::InferRequest>(compiled_model_prefill.create_infer_request());
|
|
377
|
+
r_ctx->infer_request_cache[key] =
|
|
378
|
+
std::make_shared<ov::InferRequest>(compiled_model_decode.create_infer_request());
|
|
379
|
+
compile_end_time = ggml_time_us();
|
|
380
|
+
|
|
381
|
+
model = is_prefill ? model_prefill : model_decode;
|
|
382
|
+
ggml_decoder = is_prefill ? ggml_decoder_prefill : ggml_decoder_decode;
|
|
383
|
+
infer_request = is_prefill ? r_ctx->infer_request_cache_prefill[key] : r_ctx->infer_request_cache[key];
|
|
384
|
+
r_ctx->decoder_cache[key] = ggml_decoder;
|
|
385
|
+
|
|
386
|
+
std::vector<std::string> ov_input_names;
|
|
387
|
+
std::vector<std::string> ov_output_names;
|
|
388
|
+
for (const auto & ov_param : model->get_parameters()) {
|
|
389
|
+
ov_input_names.push_back(ov_param->get_friendly_name());
|
|
390
|
+
}
|
|
391
|
+
for (const auto & ov_output : model->get_results()) {
|
|
392
|
+
ov_output_names.push_back(ov_output->get_friendly_name());
|
|
393
|
+
}
|
|
394
|
+
r_ctx->ov_input_names_cache[key] = std::move(ov_input_names);
|
|
395
|
+
r_ctx->ov_output_names_cache[key] = std::move(ov_output_names);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
auto ov_input_names = r_ctx->ov_input_names_cache[key];
|
|
399
|
+
auto ov_output_names = r_ctx->ov_output_names_cache[key];
|
|
400
|
+
|
|
401
|
+
if (is_prefill) {
|
|
402
|
+
auto inp_len = inp_pos->ne[0];
|
|
403
|
+
for (int chunk_index = 0; chunk_index * prefill_chunk_size < inp_len; chunk_index++) {
|
|
404
|
+
for (size_t i = 0; i < ov_input_names.size(); i++) {
|
|
405
|
+
auto param_name = ov_input_names[i];
|
|
406
|
+
auto input_tensor = get_ov_input_tensor_static_prefill(ggml_decoder, param_name, chunk_index);
|
|
407
|
+
infer_request->set_input_tensor(i, input_tensor);
|
|
408
|
+
|
|
409
|
+
if (getenv("GGML_OPENVINO_DEBUG_INPUT")) {
|
|
410
|
+
const auto input_tensor = infer_request->get_input_tensor(i);
|
|
411
|
+
print_input_tensor_info(param_name, input_tensor);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
for (size_t i = 0; i < ov_output_names.size(); i++) {
|
|
416
|
+
auto * ggml_tensor = ggml_decoder->get_model_outputs().at(ov_output_names[i]);
|
|
417
|
+
auto output_tensor = create_ov_output_tensor(ggml_decoder, infer_request, i, ggml_tensor);
|
|
418
|
+
infer_request->set_output_tensor(i, output_tensor);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
infer_request->infer();
|
|
422
|
+
|
|
423
|
+
if (getenv("GGML_OPENVINO_DEBUG_OUTPUT")) {
|
|
424
|
+
for (size_t i = 0; i < ov_output_names.size(); i++) {
|
|
425
|
+
const auto output_tensor = infer_request->get_output_tensor(i);
|
|
426
|
+
print_output_tensor_info(ov_output_names[i], output_tensor, output_tensor.data());
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
infer_end_time = ggml_time_us();
|
|
431
|
+
} else {
|
|
432
|
+
for (size_t i = 0; i < ov_input_names.size(); i++) {
|
|
433
|
+
auto param_name = ov_input_names[i];
|
|
434
|
+
auto input_tensor = get_ov_input_tensor_static_decode(ggml_decoder, param_name);
|
|
435
|
+
infer_request->set_input_tensor(i, input_tensor);
|
|
436
|
+
|
|
437
|
+
if (getenv("GGML_OPENVINO_DEBUG_INPUT")) {
|
|
438
|
+
const auto input_tensor = infer_request->get_input_tensor(i);
|
|
439
|
+
print_input_tensor_info(param_name, input_tensor);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
for (size_t i = 0; i < ov_output_names.size(); i++) {
|
|
444
|
+
auto * ggml_tensor = ggml_decoder->get_model_outputs().at(ov_output_names[i]);
|
|
445
|
+
auto output_tensor = create_ov_output_tensor(ggml_decoder, infer_request, i, ggml_tensor);
|
|
446
|
+
infer_request->set_output_tensor(i, output_tensor);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
infer_request->infer();
|
|
450
|
+
infer_end_time = ggml_time_us();
|
|
451
|
+
|
|
452
|
+
if (getenv("GGML_OPENVINO_DEBUG_OUTPUT")) {
|
|
453
|
+
for (size_t i = 0; i < ov_output_names.size(); i++) {
|
|
454
|
+
const auto output_tensor = infer_request->get_output_tensor(i);
|
|
455
|
+
print_output_tensor_info(ov_output_names[i], output_tensor, output_tensor.data());
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (getenv("GGML_OPENVINO_PROFILING")) {
|
|
461
|
+
GGML_LOG_INFO("\nGGML OpenVINO Backend: \n");
|
|
462
|
+
GGML_LOG_INFO(" - Graph decoder time: %ld ms \n", (decoder_end_time - start_time) / 1000);
|
|
463
|
+
if (!cache_hit) {
|
|
464
|
+
GGML_LOG_INFO(" - Graph conversion time: %ld ms \n", (conversion_end_time - decoder_end_time) / 1000);
|
|
465
|
+
GGML_LOG_INFO(" - Graph compile time: %ld ms \n", (compile_end_time - conversion_end_time) / 1000);
|
|
466
|
+
}
|
|
467
|
+
GGML_LOG_INFO(" - Graph inference time: %ld ms \n", (infer_end_time - compile_end_time) / 1000);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
return GGML_STATUS_SUCCESS;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
bool is_naive(ggml_cgraph * cgraph) {
|
|
474
|
+
constexpr int naive_graph_size_threshold = 20;
|
|
475
|
+
int count = 0;
|
|
476
|
+
for (int i = 0; i < cgraph->n_nodes; i++) {
|
|
477
|
+
if (cgraph->nodes[i]->op != GGML_OP_NONE) {
|
|
478
|
+
count++;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return count < naive_graph_size_threshold;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
enum ggml_status naive_compute(ggml_cgraph * cgraph,
|
|
485
|
+
ov::Core & core,
|
|
486
|
+
const std::string & device,
|
|
487
|
+
const ov::AnyMap & config) {
|
|
488
|
+
if (cgraph->n_nodes == 1 && (cgraph->nodes[0]->op == GGML_OP_NONE || cgraph->nodes[0]->op == GGML_OP_VIEW)) {
|
|
489
|
+
return GGML_STATUS_SUCCESS;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
bool naive = true;
|
|
493
|
+
auto model_weights = GgmlOvDecoder::create_weight_nodes(cgraph, naive);
|
|
494
|
+
auto decoder = std::make_shared<GgmlOvDecoder>(cgraph, model_weights);
|
|
495
|
+
auto input_model = std::make_shared<ov::frontend::ggml::InputModel>(decoder);
|
|
496
|
+
auto model = ov::frontend::ggml::FrontEnd::convert(input_model, naive);
|
|
497
|
+
if (getenv("GGML_OPENVINO_DUMP_IR")) {
|
|
498
|
+
ov::serialize(model, "IR_naive.xml");
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
std::shared_ptr<ov::InferRequest> infer_request;
|
|
502
|
+
auto remote_context = ggml_openvino_get_remote_context();
|
|
503
|
+
if (cgraph->nodes[0]->op == GGML_OP_MUL_MAT) {
|
|
504
|
+
// TODO ACCURACY hint triggers a bug in GPU plugin/driver on Lunar Lake. Remove once CVS-182166 is resolved
|
|
505
|
+
core.set_property(device, ov::hint::execution_mode(ov::hint::ExecutionMode::PERFORMANCE));
|
|
506
|
+
} else {
|
|
507
|
+
core.set_property(device, ov::hint::execution_mode(ov::hint::ExecutionMode::ACCURACY));
|
|
508
|
+
}
|
|
509
|
+
if (remote_context.has_value()) {
|
|
510
|
+
infer_request = std::make_shared<ov::InferRequest>(
|
|
511
|
+
core.compile_model(model, remote_context.value(), config).create_infer_request());
|
|
512
|
+
} else {
|
|
513
|
+
infer_request =
|
|
514
|
+
std::make_shared<ov::InferRequest>(core.compile_model(model, device, config).create_infer_request());
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
auto ov_params = model->get_parameters();
|
|
518
|
+
for (size_t i = 0; i < ov_params.size(); i++) {
|
|
519
|
+
auto param_name = ov_params[i]->get_friendly_name();
|
|
520
|
+
auto input_tensor = get_ov_input_tensor(decoder, param_name);
|
|
521
|
+
infer_request->set_input_tensor(i, input_tensor);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
auto ov_results = model->get_results();
|
|
525
|
+
for (size_t i = 0; i < ov_results.size(); i++) {
|
|
526
|
+
auto * ggml_tensor = decoder->get_model_outputs().at(ov_results[i]->get_friendly_name());
|
|
527
|
+
auto output_tensor = create_ov_output_tensor(decoder, infer_request, i, ggml_tensor);
|
|
528
|
+
infer_request->set_output_tensor(i, output_tensor);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
infer_request->infer();
|
|
532
|
+
return GGML_STATUS_SUCCESS;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
namespace {
|
|
536
|
+
ov::Tensor convert_ggml_input_to_ov(std::shared_ptr<GgmlOvDecoder> ggml_decoder, const std::string & name) {
|
|
537
|
+
const auto * ggml_tensor = ggml_decoder->get_input_ggml_tensor(name);
|
|
538
|
+
|
|
539
|
+
if (ggml_tensor->extra != nullptr) {
|
|
540
|
+
// GGML_LOG_DEBUG("Using ggml_tensor->extra as ov::Tensor for input: %s\n", name.c_str());
|
|
541
|
+
auto * extra_base = static_cast<ggml_openvino_extra_base *>(ggml_tensor->extra);
|
|
542
|
+
if (extra_base->type != ggml_openvino_extra_base::Type::TENSOR) {
|
|
543
|
+
throw std::runtime_error("ggml tensor extra is not of type TENSOR for input: " + name);
|
|
544
|
+
}
|
|
545
|
+
auto * tensor_extra = static_cast<ggml_openvino_tensor_extra *>(extra_base);
|
|
546
|
+
return *tensor_extra->tensor;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// GGML_LOG_DEBUG("Converting ggml tensor to ov::Tensor for input: %s\n", name.c_str());
|
|
550
|
+
auto * input_data = ggml_tensor->data;
|
|
551
|
+
ov::Shape input_shape;
|
|
552
|
+
if (ggml_tensor->op == GGML_OP_VIEW) {
|
|
553
|
+
// This case is added to make test-backend-ops work
|
|
554
|
+
input_shape = ggml_decoder->get_shape(ggml_tensor->view_src);
|
|
555
|
+
} else {
|
|
556
|
+
input_shape = ggml_decoder->get_shape(ggml_tensor);
|
|
557
|
+
}
|
|
558
|
+
auto input_tensor = ov::Tensor(ggml_decoder->get_ov_type(ggml_tensor), input_shape, input_data);
|
|
559
|
+
return input_tensor;
|
|
560
|
+
}
|
|
561
|
+
} // namespace
|
|
562
|
+
|
|
563
|
+
ov::Tensor get_ov_input_tensor(std::shared_ptr<GgmlOvDecoder> ggml_decoder, const std::string & param_name) {
|
|
564
|
+
ov::Tensor input_tensor;
|
|
565
|
+
if (ggml_decoder->get_model_extra_inputs().find(param_name) != ggml_decoder->get_model_extra_inputs().end()) {
|
|
566
|
+
input_tensor = *ggml_decoder->get_model_extra_input_values().at(param_name);
|
|
567
|
+
} else {
|
|
568
|
+
input_tensor = convert_ggml_input_to_ov(ggml_decoder, param_name);
|
|
569
|
+
}
|
|
570
|
+
return input_tensor;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
ov::Tensor get_ov_input_tensor_static_decode(std::shared_ptr<GgmlOvDecoder> ggml_decoder,
|
|
574
|
+
const std::string & param_name) {
|
|
575
|
+
// NPU decoding stage
|
|
576
|
+
const auto * ggml_tensor = ggml_decoder->get_input_ggml_tensor(param_name);
|
|
577
|
+
const auto * op = ggml_decoder->get_tensor_used_op(ggml_tensor);
|
|
578
|
+
|
|
579
|
+
if (GgmlOvDecoder::is_inp_tok(ggml_tensor, op) || GgmlOvDecoder::is_inp_pos(ggml_tensor, op) ||
|
|
580
|
+
GgmlOvDecoder::is_kv_idx(ggml_tensor, op)) {
|
|
581
|
+
assert(ggml_tensor->ne[0] == 1);
|
|
582
|
+
ov::Shape input_shape = {1, 1, 1, 1};
|
|
583
|
+
ov::Tensor input_tensor(ggml_decoder->get_ov_type(ggml_tensor), input_shape);
|
|
584
|
+
if (ggml_tensor->type == GGML_TYPE_I32) {
|
|
585
|
+
*input_tensor.data<int32_t>() = *((int32_t *) ggml_tensor->data);
|
|
586
|
+
} else if (ggml_tensor->type == GGML_TYPE_I64) {
|
|
587
|
+
*input_tensor.data<int64_t>() = *((int64_t *) ggml_tensor->data);
|
|
588
|
+
} else {
|
|
589
|
+
throw std::runtime_error("Unexpected tensor type for " + param_name);
|
|
590
|
+
}
|
|
591
|
+
return input_tensor;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (GgmlOvDecoder::is_output_idx(ggml_tensor, op)) {
|
|
595
|
+
ov::Shape input_shape = {1, 1, 1, 1};
|
|
596
|
+
ov::Tensor input_tensor(ggml_decoder->get_ov_type(ggml_tensor), input_shape);
|
|
597
|
+
int32_t inp_out_id = *((int32_t *) ggml_tensor->data);
|
|
598
|
+
assert(ggml_tensor->ne[0] == 1);
|
|
599
|
+
assert(inp_out_id == 0);
|
|
600
|
+
*input_tensor.data<int32_t>() = inp_out_id;
|
|
601
|
+
return input_tensor;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
if (GgmlOvDecoder::is_inp_mask(ggml_tensor, op)) {
|
|
605
|
+
size_t context_size = ggml_decoder->get_ctx_size();
|
|
606
|
+
std::vector<float> padded_data = pad_input<float>(ggml_tensor, 1, context_size, -INFINITY);
|
|
607
|
+
ov::Tensor input_tensor(ov::element::f32, ov::Shape{1, 1, 1, context_size});
|
|
608
|
+
auto * data_ptr = input_tensor.data<float>();
|
|
609
|
+
std::copy(padded_data.begin(), padded_data.begin() + context_size, data_ptr);
|
|
610
|
+
return input_tensor;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return get_ov_input_tensor(ggml_decoder, param_name);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
ov::Tensor get_ov_input_tensor_static_prefill(std::shared_ptr<GgmlOvDecoder> ggml_decoder,
|
|
617
|
+
const std::string & param_name,
|
|
618
|
+
int chunk_index) {
|
|
619
|
+
// NPU prompt processing stage
|
|
620
|
+
const auto * ggml_tensor = ggml_decoder->get_input_ggml_tensor(param_name);
|
|
621
|
+
const auto * op = ggml_decoder->get_tensor_used_op(ggml_tensor);
|
|
622
|
+
|
|
623
|
+
const size_t input_len = ggml_decoder->get_input_len();
|
|
624
|
+
const size_t chunk_size = ggml_decoder->m_prefill_chunk_size;
|
|
625
|
+
const size_t chunk_valid_size = std::min(chunk_size, input_len - chunk_index * chunk_size);
|
|
626
|
+
const size_t chunk_pad_size = chunk_size - chunk_valid_size;
|
|
627
|
+
|
|
628
|
+
if (GgmlOvDecoder::is_inp_tok(ggml_tensor, op) || GgmlOvDecoder::is_inp_pos(ggml_tensor, op) ||
|
|
629
|
+
GgmlOvDecoder::is_kv_idx(ggml_tensor, op)) {
|
|
630
|
+
ov::Shape input_shape = {1, 1, 1, chunk_size};
|
|
631
|
+
ov::Tensor input_tensor(ggml_decoder->get_ov_type(ggml_tensor), input_shape);
|
|
632
|
+
// copy the chunk_index-th chunk from ggml_tensor
|
|
633
|
+
size_t element_size = ggml_type_size(ggml_tensor->type);
|
|
634
|
+
void * input_data = (char *) ggml_tensor->data + chunk_index * chunk_size * element_size;
|
|
635
|
+
std::memcpy(input_tensor.data(), input_data, chunk_valid_size * element_size);
|
|
636
|
+
// pad the rest with last_value + 1, so that kv's of padded positions are inserted
|
|
637
|
+
// to the next row after the valids row in the kvcache
|
|
638
|
+
if (chunk_pad_size > 0) {
|
|
639
|
+
if (ggml_tensor->type == GGML_TYPE_I32) {
|
|
640
|
+
int32_t last_value =
|
|
641
|
+
*((int32_t *) ggml_tensor->data + (chunk_index * chunk_size + chunk_valid_size - 1));
|
|
642
|
+
int32_t * output_data = input_tensor.data<int32_t>();
|
|
643
|
+
std::fill(output_data + chunk_valid_size, output_data + chunk_size, last_value + 1);
|
|
644
|
+
} else if (ggml_tensor->type == GGML_TYPE_I64) {
|
|
645
|
+
int64_t last_value =
|
|
646
|
+
*((int64_t *) ggml_tensor->data + (chunk_index * chunk_size + chunk_valid_size - 1));
|
|
647
|
+
int64_t * output_data = input_tensor.data<int64_t>();
|
|
648
|
+
std::fill(output_data + chunk_valid_size, output_data + chunk_size, last_value + 1);
|
|
649
|
+
} else {
|
|
650
|
+
throw std::runtime_error("Unexpected tensor type for " + param_name);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return input_tensor;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (GgmlOvDecoder::is_output_idx(ggml_tensor, op)) {
|
|
657
|
+
size_t output_len = ggml_decoder->get_compute_params().output_len;
|
|
658
|
+
ov::Shape input_shape = {1, 1, 1, output_len};
|
|
659
|
+
ov::Tensor input_tensor(ggml_decoder->get_ov_type(ggml_tensor), input_shape);
|
|
660
|
+
if (ggml_tensor->ne[0] == 0) {
|
|
661
|
+
*input_tensor.data<int32_t>() = 0;
|
|
662
|
+
} else {
|
|
663
|
+
auto * data_addr = input_tensor.data<int32_t>();
|
|
664
|
+
for (size_t i = 0; i < output_len; i++) {
|
|
665
|
+
data_addr[i] = ((int32_t *) ggml_tensor->data)[i] % chunk_size;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return input_tensor;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (GgmlOvDecoder::is_inp_mask(ggml_tensor, op)) {
|
|
672
|
+
size_t cols = ggml_tensor->ne[0];
|
|
673
|
+
size_t rows = ggml_tensor->ne[1];
|
|
674
|
+
float * ggml_data = (float *) ggml_tensor->data + chunk_index * chunk_size * cols;
|
|
675
|
+
size_t chunk_valid_rows = std::min(chunk_size, rows - chunk_index * chunk_size);
|
|
676
|
+
size_t context_size = ggml_decoder->get_ctx_size();
|
|
677
|
+
std::vector<float> padded_data =
|
|
678
|
+
pad_input<float>(ggml_data, chunk_valid_rows, cols, chunk_size, context_size, -INFINITY);
|
|
679
|
+
set_zero_diagonal(padded_data, chunk_size, context_size);
|
|
680
|
+
ov::Tensor input_tensor(ov::element::f32, ov::Shape{1, 1, chunk_size, context_size});
|
|
681
|
+
auto * data_ptr = input_tensor.data<float>();
|
|
682
|
+
std::copy(padded_data.begin(), padded_data.begin() + chunk_size * context_size, data_ptr);
|
|
683
|
+
return input_tensor;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
return get_ov_input_tensor(ggml_decoder, param_name);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
size_t checksum(const void * data, size_t size) {
|
|
690
|
+
const uint8_t * bytes = static_cast<const uint8_t *>(data);
|
|
691
|
+
size_t sum = 0;
|
|
692
|
+
for (size_t i = 0; i < size; ++i) {
|
|
693
|
+
sum += (uint8_t) i;
|
|
694
|
+
sum += bytes[i];
|
|
695
|
+
}
|
|
696
|
+
return sum;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
void print_input_tensor_info(const std::string & name, const ov::Tensor & tensor) {
|
|
700
|
+
std::cout << "Input name: " << name << ", Input shape: " << tensor.get_shape() << ", Address: " << tensor.data()
|
|
701
|
+
<< std::endl;
|
|
702
|
+
switch (tensor.get_element_type()) {
|
|
703
|
+
case ov::element::f32: {
|
|
704
|
+
if (name.find("self_kq_mask") == std::string::npos) {
|
|
705
|
+
std::cout << *(tensor.data<float>()) << std::endl;
|
|
706
|
+
} else {
|
|
707
|
+
size_t rows = tensor.get_shape()[2];
|
|
708
|
+
size_t cols = tensor.get_shape()[3];
|
|
709
|
+
auto * data = tensor.data<float>();
|
|
710
|
+
for (size_t i = 0; i < rows; ++i) {
|
|
711
|
+
for (size_t j = 0; j < cols; ++j) {
|
|
712
|
+
float val = data[i * cols + j];
|
|
713
|
+
if (std::isinf(val) && val < 0) {
|
|
714
|
+
std::cout << std::setw(5) << "-inf";
|
|
715
|
+
} else {
|
|
716
|
+
std::cout << std::setw(5) << val;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
std::cout << std::endl;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
case ov::element::f16:
|
|
726
|
+
std::cout << *(tensor.data<ov::float16>()) << std::endl;
|
|
727
|
+
break;
|
|
728
|
+
case ov::element::i32:
|
|
729
|
+
for (size_t i = 0; i < tensor.get_size(); ++i) {
|
|
730
|
+
std::cout << tensor.data<int32_t>()[i] << " ";
|
|
731
|
+
}
|
|
732
|
+
std::cout << std::endl;
|
|
733
|
+
break;
|
|
734
|
+
case ov::element::i64:
|
|
735
|
+
for (size_t i = 0; i < tensor.get_size(); ++i) {
|
|
736
|
+
std::cout << tensor.data<int64_t>()[i] << " ";
|
|
737
|
+
}
|
|
738
|
+
std::cout << std::endl;
|
|
739
|
+
break;
|
|
740
|
+
default:
|
|
741
|
+
break;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
void print_output_tensor_info(const std::string & name, const ov::Tensor & tensor, const void * output_dst) {
|
|
746
|
+
std::cout << "Output name: " << name << ", Output shape: " << tensor.get_shape() << ", Address: " << output_dst
|
|
747
|
+
<< std::endl;
|
|
748
|
+
|
|
749
|
+
auto print_float_stats = [](const std::string & type_name, size_t size, auto get_value) {
|
|
750
|
+
if (size == 0) {
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
float first = get_value(0);
|
|
755
|
+
float min = first;
|
|
756
|
+
float max = first;
|
|
757
|
+
double sum = first;
|
|
758
|
+
|
|
759
|
+
for (size_t i = 1; i < size; ++i) {
|
|
760
|
+
float v = get_value(i);
|
|
761
|
+
if (v < min) {
|
|
762
|
+
min = v;
|
|
763
|
+
}
|
|
764
|
+
if (v > max) {
|
|
765
|
+
max = v;
|
|
766
|
+
}
|
|
767
|
+
sum += v;
|
|
768
|
+
}
|
|
769
|
+
double mean = sum / size;
|
|
770
|
+
|
|
771
|
+
std::cout << std::right << std::setw(6) << type_name << std::right << std::setw(12) << "First" << std::setw(12)
|
|
772
|
+
<< "Min" << std::setw(12) << "Max" << std::setw(12) << "Mean" << std::endl;
|
|
773
|
+
std::cout << std::right << std::setw(6) << "" << std::right << std::setw(12) << first << std::setw(12) << min
|
|
774
|
+
<< std::setw(12) << max << std::setw(12) << mean << std::endl;
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
switch (tensor.get_element_type()) {
|
|
778
|
+
case ov::element::f32: {
|
|
779
|
+
const float * data = tensor.data<float>();
|
|
780
|
+
size_t size = tensor.get_size();
|
|
781
|
+
print_float_stats("[f32]", size, [data](size_t i) { return data[i]; });
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
case ov::element::f16: {
|
|
785
|
+
const ov::float16 * data = tensor.data<ov::float16>();
|
|
786
|
+
size_t size = tensor.get_size();
|
|
787
|
+
print_float_stats("[f16]", size, [data](size_t i) { return static_cast<float>(data[i]); });
|
|
788
|
+
break;
|
|
789
|
+
}
|
|
790
|
+
default:
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
void set_zero_diagonal(std::vector<float> & matrix, size_t rows, size_t cols) {
|
|
796
|
+
for (size_t i = 0; i < rows; ++i) {
|
|
797
|
+
size_t diag_col = std::min(i, cols - 1);
|
|
798
|
+
matrix[i * cols + diag_col] = 0.0f;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
const ggml_tensor * get_inp_pos_tensor(ggml_cgraph * cgraph) {
|
|
803
|
+
for (int i = 0; i < cgraph->n_nodes; ++i) {
|
|
804
|
+
auto * op = cgraph->nodes[i];
|
|
805
|
+
for (int j = 0; j < GGML_MAX_SRC; ++j) {
|
|
806
|
+
auto * src = op->src[j];
|
|
807
|
+
if (src == nullptr) {
|
|
808
|
+
break;
|
|
809
|
+
}
|
|
810
|
+
if (GgmlOvDecoder::is_inp_pos(src, op)) {
|
|
811
|
+
return src;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
GGML_LOG_ERROR("get_inp_pos_tensor: inp_pos not found in cgraph");
|
|
816
|
+
throw std::runtime_error("get_inp_pos_tensor: inp_pos not found in cgraph");
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
bool get_is_prefill(const ggml_tensor * inp_pos) {
|
|
820
|
+
return inp_pos->ne[0] > 1;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
#pragma GCC diagnostic pop
|