whispercpp 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +60 -43
- data/ext/extconf.rb +2 -2
- data/ext/ruby_whisper.c +14 -2
- data/ext/ruby_whisper.h +39 -0
- data/ext/ruby_whisper_context.c +22 -22
- data/ext/ruby_whisper_model.c +12 -12
- data/ext/ruby_whisper_params.c +47 -23
- data/ext/ruby_whisper_segment.c +84 -19
- data/ext/ruby_whisper_token.c +351 -0
- data/ext/ruby_whisper_transcribe.cpp +1 -1
- data/ext/ruby_whisper_vad_context.c +75 -0
- data/ext/ruby_whisper_vad_context_detect.cpp +50 -0
- data/ext/ruby_whisper_vad_segment.c +139 -0
- data/ext/ruby_whisper_vad_segments.c +106 -0
- data/ext/sources/CMakeLists.txt +4 -1
- data/ext/sources/bindings/javascript/package.json +1 -1
- data/ext/sources/cmake/arm64-apple-clang.cmake +16 -0
- data/ext/sources/cmake/arm64-windows-llvm.cmake +16 -0
- data/ext/sources/cmake/riscv64-spacemit-linux-gnu-gcc.cmake +29 -0
- data/ext/sources/cmake/x64-windows-llvm.cmake +5 -0
- data/ext/sources/examples/addon.node/vad-example.js +2 -2
- data/ext/sources/examples/cli/cli.cpp +121 -112
- data/ext/sources/examples/lsp/CMakeLists.txt +2 -1
- data/ext/sources/examples/quantize/CMakeLists.txt +2 -1
- data/ext/sources/examples/server/server.cpp +10 -11
- data/ext/sources/examples/talk-llama/CMakeLists.txt +5 -1
- data/ext/sources/examples/talk-llama/llama-adapter.cpp +12 -3
- data/ext/sources/examples/talk-llama/llama-adapter.h +7 -1
- data/ext/sources/examples/talk-llama/llama-arch.cpp +2046 -1974
- data/ext/sources/examples/talk-llama/llama-arch.h +67 -2
- data/ext/sources/examples/talk-llama/llama-batch.cpp +75 -33
- data/ext/sources/examples/talk-llama/llama-batch.h +17 -4
- data/ext/sources/examples/talk-llama/llama-chat.cpp +79 -3
- data/ext/sources/examples/talk-llama/llama-chat.h +4 -0
- data/ext/sources/examples/talk-llama/llama-context.cpp +775 -78
- data/ext/sources/examples/talk-llama/llama-context.h +57 -9
- data/ext/sources/examples/talk-llama/llama-cparams.h +1 -0
- data/ext/sources/examples/talk-llama/llama-grammar.cpp +288 -53
- data/ext/sources/examples/talk-llama/llama-grammar.h +22 -1
- data/ext/sources/examples/talk-llama/llama-graph.cpp +381 -64
- data/ext/sources/examples/talk-llama/llama-graph.h +103 -13
- data/ext/sources/examples/talk-llama/llama-hparams.cpp +26 -2
- data/ext/sources/examples/talk-llama/llama-hparams.h +41 -10
- data/ext/sources/examples/talk-llama/llama-impl.cpp +7 -3
- data/ext/sources/examples/talk-llama/llama-impl.h +1 -1
- data/ext/sources/examples/talk-llama/llama-kv-cache-iswa.cpp +5 -3
- data/ext/sources/examples/talk-llama/llama-kv-cache.cpp +145 -65
- data/ext/sources/examples/talk-llama/llama-kv-cache.h +22 -7
- data/ext/sources/examples/talk-llama/llama-kv-cells.h +44 -2
- data/ext/sources/examples/talk-llama/llama-memory-hybrid.cpp +12 -10
- data/ext/sources/examples/talk-llama/llama-memory-recurrent.cpp +32 -19
- data/ext/sources/examples/talk-llama/llama-memory-recurrent.h +2 -2
- data/ext/sources/examples/talk-llama/llama-mmap.cpp +172 -37
- data/ext/sources/examples/talk-llama/llama-mmap.h +8 -3
- data/ext/sources/examples/talk-llama/llama-model-loader.cpp +91 -9
- data/ext/sources/examples/talk-llama/llama-model-loader.h +6 -0
- data/ext/sources/examples/talk-llama/llama-model-saver.cpp +3 -0
- data/ext/sources/examples/talk-llama/llama-model.cpp +1529 -13134
- data/ext/sources/examples/talk-llama/llama-model.h +44 -3
- data/ext/sources/examples/talk-llama/llama-quant.cpp +8 -23
- data/ext/sources/examples/talk-llama/llama-sampling.cpp +1294 -198
- data/ext/sources/examples/talk-llama/llama-sampling.h +19 -7
- data/ext/sources/examples/talk-llama/llama-vocab.cpp +133 -37
- data/ext/sources/examples/talk-llama/llama-vocab.h +45 -40
- data/ext/sources/examples/talk-llama/llama.cpp +729 -2
- data/ext/sources/examples/talk-llama/llama.h +152 -14
- data/ext/sources/examples/talk-llama/models/afmoe.cpp +191 -0
- data/ext/sources/examples/talk-llama/models/apertus.cpp +125 -0
- data/ext/sources/examples/talk-llama/models/arcee.cpp +135 -0
- data/ext/sources/examples/talk-llama/models/arctic.cpp +138 -0
- data/ext/sources/examples/talk-llama/models/arwkv7.cpp +86 -0
- data/ext/sources/examples/talk-llama/models/baichuan.cpp +122 -0
- data/ext/sources/examples/talk-llama/models/bailingmoe.cpp +144 -0
- data/ext/sources/examples/talk-llama/models/bailingmoe2.cpp +135 -0
- data/ext/sources/examples/talk-llama/models/bert.cpp +178 -0
- data/ext/sources/examples/talk-llama/models/bitnet.cpp +160 -0
- data/ext/sources/examples/talk-llama/models/bloom.cpp +101 -0
- data/ext/sources/examples/talk-llama/models/chameleon.cpp +178 -0
- data/ext/sources/examples/talk-llama/models/chatglm.cpp +132 -0
- data/ext/sources/examples/talk-llama/models/codeshell.cpp +111 -0
- data/ext/sources/examples/talk-llama/models/cogvlm.cpp +102 -0
- data/ext/sources/examples/talk-llama/models/cohere2-iswa.cpp +134 -0
- data/ext/sources/examples/talk-llama/models/command-r.cpp +122 -0
- data/ext/sources/examples/talk-llama/models/dbrx.cpp +123 -0
- data/ext/sources/examples/talk-llama/models/deci.cpp +135 -0
- data/ext/sources/examples/talk-llama/models/deepseek.cpp +144 -0
- data/ext/sources/examples/talk-llama/models/deepseek2.cpp +259 -0
- data/ext/sources/examples/talk-llama/models/dots1.cpp +134 -0
- data/ext/sources/examples/talk-llama/models/dream.cpp +105 -0
- data/ext/sources/examples/talk-llama/models/ernie4-5-moe.cpp +150 -0
- data/ext/sources/examples/talk-llama/models/ernie4-5.cpp +110 -0
- data/ext/sources/examples/talk-llama/models/exaone.cpp +114 -0
- data/ext/sources/examples/talk-llama/models/exaone4.cpp +123 -0
- data/ext/sources/examples/talk-llama/models/falcon-h1.cpp +113 -0
- data/ext/sources/examples/talk-llama/models/falcon.cpp +120 -0
- data/ext/sources/examples/talk-llama/models/gemma-embedding.cpp +116 -0
- data/ext/sources/examples/talk-llama/models/gemma.cpp +112 -0
- data/ext/sources/examples/talk-llama/models/gemma2-iswa.cpp +128 -0
- data/ext/sources/examples/talk-llama/models/gemma3.cpp +155 -0
- data/ext/sources/examples/talk-llama/models/gemma3n-iswa.cpp +384 -0
- data/ext/sources/examples/talk-llama/models/glm4-moe.cpp +170 -0
- data/ext/sources/examples/talk-llama/models/glm4.cpp +150 -0
- data/ext/sources/examples/talk-llama/models/gpt2.cpp +105 -0
- data/ext/sources/examples/talk-llama/models/gptneox.cpp +144 -0
- data/ext/sources/examples/talk-llama/models/granite-hybrid.cpp +196 -0
- data/ext/sources/examples/talk-llama/models/granite.cpp +211 -0
- data/ext/sources/examples/talk-llama/models/graph-context-mamba.cpp +283 -0
- data/ext/sources/examples/talk-llama/models/grok.cpp +159 -0
- data/ext/sources/examples/talk-llama/models/grovemoe.cpp +141 -0
- data/ext/sources/examples/talk-llama/models/hunyuan-dense.cpp +132 -0
- data/ext/sources/examples/talk-llama/models/hunyuan-moe.cpp +154 -0
- data/ext/sources/examples/talk-llama/models/internlm2.cpp +120 -0
- data/ext/sources/examples/talk-llama/models/jais.cpp +86 -0
- data/ext/sources/examples/talk-llama/models/jamba.cpp +106 -0
- data/ext/sources/examples/talk-llama/models/lfm2.cpp +175 -0
- data/ext/sources/examples/talk-llama/models/llada-moe.cpp +122 -0
- data/ext/sources/examples/talk-llama/models/llada.cpp +99 -0
- data/ext/sources/examples/talk-llama/models/llama-iswa.cpp +178 -0
- data/ext/sources/examples/talk-llama/models/llama.cpp +168 -0
- data/ext/sources/examples/talk-llama/models/maincoder.cpp +117 -0
- data/ext/sources/examples/talk-llama/models/mamba.cpp +55 -0
- data/ext/sources/examples/talk-llama/models/mimo2-iswa.cpp +123 -0
- data/ext/sources/examples/talk-llama/models/minicpm3.cpp +199 -0
- data/ext/sources/examples/talk-llama/models/minimax-m2.cpp +124 -0
- data/ext/sources/examples/talk-llama/models/mistral3.cpp +160 -0
- data/ext/sources/examples/talk-llama/models/models.h +569 -0
- data/ext/sources/examples/talk-llama/models/modern-bert.cpp +116 -0
- data/ext/sources/examples/talk-llama/models/mpt.cpp +126 -0
- data/ext/sources/examples/talk-llama/models/nemotron-h.cpp +150 -0
- data/ext/sources/examples/talk-llama/models/nemotron.cpp +122 -0
- data/ext/sources/examples/talk-llama/models/neo-bert.cpp +104 -0
- data/ext/sources/examples/talk-llama/models/olmo.cpp +121 -0
- data/ext/sources/examples/talk-llama/models/olmo2.cpp +150 -0
- data/ext/sources/examples/talk-llama/models/olmoe.cpp +124 -0
- data/ext/sources/examples/talk-llama/models/openai-moe-iswa.cpp +127 -0
- data/ext/sources/examples/talk-llama/models/openelm.cpp +124 -0
- data/ext/sources/examples/talk-llama/models/orion.cpp +123 -0
- data/ext/sources/examples/talk-llama/models/pangu-embedded.cpp +121 -0
- data/ext/sources/examples/talk-llama/models/phi2.cpp +121 -0
- data/ext/sources/examples/talk-llama/models/phi3.cpp +152 -0
- data/ext/sources/examples/talk-llama/models/plamo.cpp +110 -0
- data/ext/sources/examples/talk-llama/models/plamo2.cpp +316 -0
- data/ext/sources/examples/talk-llama/models/plamo3.cpp +128 -0
- data/ext/sources/examples/talk-llama/models/plm.cpp +168 -0
- data/ext/sources/examples/talk-llama/models/qwen.cpp +108 -0
- data/ext/sources/examples/talk-llama/models/qwen2.cpp +126 -0
- data/ext/sources/examples/talk-llama/models/qwen2moe.cpp +151 -0
- data/ext/sources/examples/talk-llama/models/qwen2vl.cpp +117 -0
- data/ext/sources/examples/talk-llama/models/qwen3.cpp +117 -0
- data/ext/sources/examples/talk-llama/models/qwen3moe.cpp +124 -0
- data/ext/sources/examples/talk-llama/models/qwen3next.cpp +873 -0
- data/ext/sources/examples/talk-llama/models/qwen3vl-moe.cpp +149 -0
- data/ext/sources/examples/talk-llama/models/qwen3vl.cpp +141 -0
- data/ext/sources/examples/talk-llama/models/refact.cpp +94 -0
- data/ext/sources/examples/talk-llama/models/rnd1.cpp +126 -0
- data/ext/sources/examples/talk-llama/models/rwkv6-base.cpp +162 -0
- data/ext/sources/examples/talk-llama/models/rwkv6.cpp +94 -0
- data/ext/sources/examples/talk-llama/models/rwkv6qwen2.cpp +86 -0
- data/ext/sources/examples/talk-llama/models/rwkv7-base.cpp +135 -0
- data/ext/sources/examples/talk-llama/models/rwkv7.cpp +90 -0
- data/ext/sources/examples/talk-llama/models/seed-oss.cpp +124 -0
- data/ext/sources/examples/talk-llama/models/smallthinker.cpp +126 -0
- data/ext/sources/examples/talk-llama/models/smollm3.cpp +128 -0
- data/ext/sources/examples/talk-llama/models/stablelm.cpp +146 -0
- data/ext/sources/examples/talk-llama/models/starcoder.cpp +100 -0
- data/ext/sources/examples/talk-llama/models/starcoder2.cpp +121 -0
- data/ext/sources/examples/talk-llama/models/t5-dec.cpp +166 -0
- data/ext/sources/examples/talk-llama/models/t5-enc.cpp +96 -0
- data/ext/sources/examples/talk-llama/models/wavtokenizer-dec.cpp +149 -0
- data/ext/sources/examples/talk-llama/models/xverse.cpp +108 -0
- data/ext/sources/examples/talk-llama/unicode.cpp +102 -16
- data/ext/sources/examples/vad-speech-segments/CMakeLists.txt +1 -1
- data/ext/sources/examples/whisper.wasm/index-tmpl.html +1 -1
- data/ext/sources/ggml/CMakeLists.txt +82 -54
- data/ext/sources/ggml/include/ggml-alloc.h +9 -0
- data/ext/sources/ggml/include/ggml-backend.h +4 -1
- data/ext/sources/ggml/include/ggml-cpu.h +1 -0
- data/ext/sources/ggml/include/ggml-hexagon.h +19 -0
- data/ext/sources/ggml/include/ggml-rpc.h +8 -11
- data/ext/sources/ggml/include/ggml-zendnn.h +22 -0
- data/ext/sources/ggml/include/ggml.h +190 -12
- data/ext/sources/ggml/src/CMakeLists.txt +82 -11
- data/ext/sources/ggml/src/ggml-alloc.c +124 -41
- data/ext/sources/ggml/src/ggml-backend-impl.h +1 -4
- data/ext/sources/ggml/src/ggml-backend-reg.cpp +27 -3
- data/ext/sources/ggml/src/ggml-backend.cpp +71 -21
- data/ext/sources/ggml/src/ggml-blas/CMakeLists.txt +17 -3
- data/ext/sources/ggml/src/ggml-blas/ggml-blas.cpp +5 -9
- data/ext/sources/ggml/src/ggml-cann/acl_tensor.cpp +57 -45
- data/ext/sources/ggml/src/ggml-cann/acl_tensor.h +138 -47
- data/ext/sources/ggml/src/ggml-cann/aclnn_ops.cpp +2179 -1696
- data/ext/sources/ggml/src/ggml-cann/aclnn_ops.h +238 -317
- data/ext/sources/ggml/src/ggml-cann/common.h +283 -208
- data/ext/sources/ggml/src/ggml-cann/ggml-cann.cpp +626 -776
- data/ext/sources/ggml/src/ggml-cpu/CMakeLists.txt +156 -86
- data/ext/sources/ggml/src/ggml-cpu/amx/amx.cpp +1 -0
- data/ext/sources/ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp +4 -0
- data/ext/sources/ggml/src/ggml-cpu/arch/arm/quants.c +428 -26
- data/ext/sources/ggml/src/ggml-cpu/arch/arm/repack.cpp +1004 -0
- data/ext/sources/ggml/src/ggml-cpu/arch/loongarch/quants.c +4 -5
- data/ext/sources/ggml/src/ggml-cpu/arch/riscv/cpu-feats.cpp +38 -0
- data/ext/sources/ggml/src/ggml-cpu/arch/riscv/quants.c +108 -49
- data/ext/sources/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp +50 -0
- data/ext/sources/ggml/src/ggml-cpu/arch/x86/repack.cpp +6 -6
- data/ext/sources/ggml/src/ggml-cpu/arch-fallback.h +50 -2
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu-impl.h +5 -3
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.c +195 -71
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.cpp +4 -0
- data/ext/sources/ggml/src/ggml-cpu/kleidiai/kernels.cpp +573 -106
- data/ext/sources/ggml/src/ggml-cpu/kleidiai/kernels.h +33 -44
- data/ext/sources/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +298 -112
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm-ppc.h +333 -0
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm.cpp +819 -125
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm.h +6 -0
- data/ext/sources/ggml/src/ggml-cpu/ops.cpp +708 -431
- data/ext/sources/ggml/src/ggml-cpu/ops.h +5 -4
- data/ext/sources/ggml/src/ggml-cpu/repack.cpp +671 -31
- data/ext/sources/ggml/src/ggml-cpu/repack.h +14 -0
- data/ext/sources/ggml/src/ggml-cpu/simd-mappings.h +41 -43
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime.cpp +3 -2
- data/ext/sources/ggml/src/ggml-cpu/unary-ops.cpp +151 -0
- data/ext/sources/ggml/src/ggml-cpu/unary-ops.h +7 -0
- data/ext/sources/ggml/src/ggml-cpu/vec.cpp +124 -1
- data/ext/sources/ggml/src/ggml-cpu/vec.h +261 -146
- data/ext/sources/ggml/src/ggml-cuda/CMakeLists.txt +72 -1
- data/ext/sources/ggml/src/ggml-cuda/argmax.cu +2 -2
- data/ext/sources/ggml/src/ggml-cuda/argsort.cu +123 -6
- data/ext/sources/ggml/src/ggml-cuda/argsort.cuh +16 -0
- data/ext/sources/ggml/src/ggml-cuda/binbcast.cu +1 -1
- data/ext/sources/ggml/src/ggml-cuda/common.cuh +353 -80
- data/ext/sources/ggml/src/ggml-cuda/convert.cuh +10 -0
- data/ext/sources/ggml/src/ggml-cuda/cpy-utils.cuh +1 -1
- data/ext/sources/ggml/src/ggml-cuda/cpy.cu +339 -246
- data/ext/sources/ggml/src/ggml-cuda/cpy.cuh +1 -5
- data/ext/sources/ggml/src/ggml-cuda/cumsum.cu +307 -0
- data/ext/sources/ggml/src/ggml-cuda/cumsum.cuh +5 -0
- data/ext/sources/ggml/src/ggml-cuda/diag.cu +77 -0
- data/ext/sources/ggml/src/ggml-cuda/diag.cuh +5 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn-common.cuh +31 -21
- data/ext/sources/ggml/src/ggml-cuda/fattn-mma-f16.cuh +663 -596
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile.cu +35 -741
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile.cuh +1241 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn-vec.cuh +30 -37
- data/ext/sources/ggml/src/ggml-cuda/fattn-wmma-f16.cu +14 -13
- data/ext/sources/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +48 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn.cu +83 -37
- data/ext/sources/ggml/src/ggml-cuda/fill.cu +37 -0
- data/ext/sources/ggml/src/ggml-cuda/fill.cuh +3 -0
- data/ext/sources/ggml/src/ggml-cuda/ggml-cuda.cu +1155 -164
- data/ext/sources/ggml/src/ggml-cuda/mean.cu +5 -4
- data/ext/sources/ggml/src/ggml-cuda/mma.cuh +741 -48
- data/ext/sources/ggml/src/ggml-cuda/mmf.cu +60 -12
- data/ext/sources/ggml/src/ggml-cuda/mmf.cuh +381 -42
- data/ext/sources/ggml/src/ggml-cuda/mmid.cu +164 -0
- data/ext/sources/ggml/src/ggml-cuda/mmid.cuh +5 -0
- data/ext/sources/ggml/src/ggml-cuda/mmq.cu +69 -176
- data/ext/sources/ggml/src/ggml-cuda/mmq.cuh +498 -171
- data/ext/sources/ggml/src/ggml-cuda/mmvf.cu +375 -79
- data/ext/sources/ggml/src/ggml-cuda/mmvf.cuh +3 -2
- data/ext/sources/ggml/src/ggml-cuda/mmvq.cu +241 -95
- data/ext/sources/ggml/src/ggml-cuda/mmvq.cuh +1 -1
- data/ext/sources/ggml/src/ggml-cuda/pad.cu +64 -33
- data/ext/sources/ggml/src/ggml-cuda/quantize.cu +151 -0
- data/ext/sources/ggml/src/ggml-cuda/quantize.cuh +14 -0
- data/ext/sources/ggml/src/ggml-cuda/rope.cu +192 -77
- data/ext/sources/ggml/src/ggml-cuda/rope.cuh +2 -0
- data/ext/sources/ggml/src/ggml-cuda/set-rows.cu +101 -47
- data/ext/sources/ggml/src/ggml-cuda/set.cu +39 -0
- data/ext/sources/ggml/src/ggml-cuda/set.cuh +7 -0
- data/ext/sources/ggml/src/ggml-cuda/softmax.cu +203 -6
- data/ext/sources/ggml/src/ggml-cuda/solve_tri.cu +275 -0
- data/ext/sources/ggml/src/ggml-cuda/solve_tri.cuh +3 -0
- data/ext/sources/ggml/src/ggml-cuda/ssm-conv.cu +14 -20
- data/ext/sources/ggml/src/ggml-cuda/ssm-scan.cu +49 -84
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq112-dv112.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq128-dv128.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq256-dv256.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq40-dv40.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq576-dv512.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq64-dv64.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq72-dv72.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq80-dv80.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq96-dv96.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/generate_cu_files.py +19 -1
- data/ext/sources/ggml/src/ggml-cuda/top-k.cu +96 -0
- data/ext/sources/ggml/src/ggml-cuda/top-k.cuh +3 -0
- data/ext/sources/ggml/src/ggml-cuda/topk-moe.cu +168 -76
- data/ext/sources/ggml/src/ggml-cuda/topk-moe.cuh +11 -4
- data/ext/sources/ggml/src/ggml-cuda/tri.cu +136 -0
- data/ext/sources/ggml/src/ggml-cuda/tri.cuh +5 -0
- data/ext/sources/ggml/src/ggml-cuda/unary.cu +105 -11
- data/ext/sources/ggml/src/ggml-cuda/unary.cuh +36 -0
- data/ext/sources/ggml/src/ggml-cuda/upscale.cu +163 -7
- data/ext/sources/ggml/src/ggml-cuda/vendors/cuda.h +4 -0
- data/ext/sources/ggml/src/ggml-cuda/vendors/hip.h +12 -1
- data/ext/sources/ggml/src/ggml-cuda/vendors/musa.h +6 -0
- data/ext/sources/ggml/src/ggml-hexagon/CMakeLists.txt +80 -0
- data/ext/sources/ggml/src/ggml-hexagon/ggml-hexagon.cpp +3151 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/CMakeLists.txt +44 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/act-ops.c +682 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/binary-ops.c +360 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/cmake-toolchain.cmake +157 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/flash-attn-ops.c +566 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/get-rows-ops.c +112 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ctx.h +35 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-dma.c +63 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-dma.h +157 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-msg.h +165 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ops.h +92 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp_iface.idl +16 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-exp.c +94 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-inverse.c +72 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-sigmoid.c +49 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-utils.c +1020 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-utils.h +1353 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/main.c +1001 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/matmul-ops.c +2503 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/ops-utils.h +149 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/rope-ops.c +487 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/set-rows-ops.c +168 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/softmax-ops.c +402 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/unary-ops.c +287 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/worker-pool.c +297 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/worker-pool.h +57 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp-utils.c +454 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp-utils.h +221 -0
- data/ext/sources/ggml/src/ggml-hexagon/op-desc.h +153 -0
- data/ext/sources/ggml/src/ggml-hip/CMakeLists.txt +8 -13
- data/ext/sources/ggml/src/ggml-impl.h +67 -6
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-common.cpp +2 -2
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-context.m +29 -20
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.cpp +652 -285
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.h +103 -56
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.m +496 -118
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-impl.h +231 -9
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.cpp +1227 -224
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.h +12 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.cpp +14 -8
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.metal +1972 -704
- data/ext/sources/ggml/src/ggml-musa/CMakeLists.txt +3 -1
- data/ext/sources/ggml/src/ggml-opencl/CMakeLists.txt +11 -0
- data/ext/sources/ggml/src/ggml-opencl/ggml-opencl.cpp +1430 -120
- data/ext/sources/ggml/src/ggml-opencl/kernels/cvt.cl +63 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/expm1.cl +82 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/fill.cl +17 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32.cl +4 -3
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_mxfp4_f32.cl +162 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_moe_mxfp4_f32.cl +156 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/get_rows.cl +36 -12
- data/ext/sources/ggml/src/ggml-opencl/kernels/mean.cl +39 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_f16_f32_kq_kqv.cl +273 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_f16_f32_l4_lm.cl +24 -10
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_f32_f32_l4_lm.cl +24 -10
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q8_0_f32_l4_lm.cl +154 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/pad.cl +29 -20
- data/ext/sources/ggml/src/ggml-opencl/kernels/rms_norm.cl +25 -10
- data/ext/sources/ggml/src/ggml-opencl/kernels/rope.cl +50 -24
- data/ext/sources/ggml/src/ggml-opencl/kernels/set_rows.cl +35 -16
- data/ext/sources/ggml/src/ggml-opencl/kernels/softplus.cl +88 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/sqr.cl +53 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/sqrt.cl +53 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/ssm_conv.cl +77 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/transpose.cl +13 -0
- data/ext/sources/ggml/src/ggml-rpc/ggml-rpc.cpp +438 -156
- data/ext/sources/ggml/src/ggml-sycl/CMakeLists.txt +48 -3
- data/ext/sources/ggml/src/ggml-sycl/add-id.cpp +77 -0
- data/ext/sources/ggml/src/ggml-sycl/add-id.hpp +8 -0
- data/ext/sources/ggml/src/ggml-sycl/backend.hpp +6 -0
- data/ext/sources/ggml/src/ggml-sycl/binbcast.cpp +0 -9
- data/ext/sources/ggml/src/ggml-sycl/binbcast.hpp +0 -6
- data/ext/sources/ggml/src/ggml-sycl/common.hpp +117 -15
- data/ext/sources/ggml/src/ggml-sycl/concat.cpp +55 -44
- data/ext/sources/ggml/src/ggml-sycl/convert.cpp +34 -0
- data/ext/sources/ggml/src/ggml-sycl/count-equal.cpp +79 -0
- data/ext/sources/ggml/src/ggml-sycl/count-equal.hpp +9 -0
- data/ext/sources/ggml/src/ggml-sycl/cpy.cpp +0 -3
- data/ext/sources/ggml/src/ggml-sycl/dequantize.hpp +18 -0
- data/ext/sources/ggml/src/ggml-sycl/dpct/helper.hpp +76 -3
- data/ext/sources/ggml/src/ggml-sycl/element_wise.cpp +333 -300
- data/ext/sources/ggml/src/ggml-sycl/element_wise.hpp +10 -2
- data/ext/sources/ggml/src/ggml-sycl/ggml-sycl.cpp +335 -110
- data/ext/sources/ggml/src/ggml-sycl/mmvq.cpp +22 -0
- data/ext/sources/ggml/src/ggml-sycl/norm.cpp +156 -0
- data/ext/sources/ggml/src/ggml-sycl/norm.hpp +2 -0
- data/ext/sources/ggml/src/ggml-sycl/pad.cpp +97 -0
- data/ext/sources/ggml/src/ggml-sycl/pad.hpp +24 -0
- data/ext/sources/ggml/src/ggml-sycl/pad_reflect_1d.cpp +100 -0
- data/ext/sources/ggml/src/ggml-sycl/pad_reflect_1d.hpp +10 -0
- data/ext/sources/ggml/src/ggml-sycl/presets.hpp +2 -0
- data/ext/sources/ggml/src/ggml-sycl/repeat_back.cpp +76 -0
- data/ext/sources/ggml/src/ggml-sycl/repeat_back.hpp +8 -0
- data/ext/sources/ggml/src/ggml-sycl/roll.cpp +122 -0
- data/ext/sources/ggml/src/ggml-sycl/roll.hpp +20 -0
- data/ext/sources/ggml/src/ggml-sycl/rope.cpp +30 -17
- data/ext/sources/ggml/src/ggml-sycl/set.cpp +73 -0
- data/ext/sources/ggml/src/ggml-sycl/set.hpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/softmax.cpp +327 -162
- data/ext/sources/ggml/src/ggml-sycl/softmax.hpp +4 -0
- data/ext/sources/ggml/src/ggml-sycl/ssm_conv.cpp +127 -0
- data/ext/sources/ggml/src/ggml-sycl/ssm_conv.hpp +5 -0
- data/ext/sources/ggml/src/ggml-sycl/vecdotq.hpp +58 -0
- data/ext/sources/ggml/src/ggml-vulkan/CMakeLists.txt +38 -18
- data/ext/sources/ggml/src/ggml-vulkan/ggml-vulkan.cpp +5013 -2859
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/abs.comp +21 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/acc.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/add.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/add1.comp +28 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/add_id.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/arange.comp +20 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/argmax.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/argsort.comp +33 -26
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/argsort_large.comp +114 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/ceil.comp +22 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/concat.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/contig_copy.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_dw.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_mm.comp +47 -49
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv_transpose_1d.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/copy.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/copy_from_quant.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp +4 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/copy_transpose.comp +67 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/cos.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/count_equal.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/count_experts.comp +51 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/cumsum.comp +83 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/cumsum_multipass1.comp +60 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/cumsum_multipass2.comp +66 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_f32.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{dequant_funcs.comp → dequant_funcs.glsl} +9 -21
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{dequant_funcs_cm2.comp → dequant_funcs_cm2.glsl} +18 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{dequant_head.comp → dequant_head.glsl} +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_m.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_s.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_s.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xs.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xxs.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_s.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_xxs.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_nl.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_xs.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_mxfp4.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q2_k.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q3_k.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_0.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_1.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_k.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_0.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_1.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_k.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q6_k.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q8_0.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp +29 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/diag_mask_inf.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/div.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/exp.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/fill.comp +19 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +39 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{flash_attn_base.comp → flash_attn_base.glsl} +19 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +45 -7
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +50 -12
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_split_k_reduce.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/floor.comp +22 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/geglu.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/geglu_erf.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/geglu_quick.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu_erf.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu_quick.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{generic_binary_head.comp → generic_binary_head.glsl} +17 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{generic_head.comp → generic_head.glsl} +2 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{generic_unary_head.comp → generic_unary_head.glsl} +7 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/get_rows.comp +4 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/get_rows_quant.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{glu_head.comp → glu_head.glsl} +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/group_norm.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/hardsigmoid.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/hardswish.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/im2col.comp +19 -7
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/im2col_3d.comp +2 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/leaky_relu.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/log.comp +18 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{mul_mat_vec_base.comp → mul_mat_vec_base.glsl} +70 -25
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iface.glsl +35 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_m.comp +71 -21
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_s.comp +41 -25
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_s.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xs.comp +44 -26
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xxs.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_s.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_xxs.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_nc.comp +9 -7
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_p021.comp +9 -7
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q2_k.comp +4 -6
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q3_k.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q4_k.comp +4 -6
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q5_k.comp +4 -6
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q6_k.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq.comp +39 -36
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq_funcs.glsl +494 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +78 -103
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +34 -23
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{mul_mm_funcs.comp → mul_mm_funcs.glsl} +69 -59
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_id_funcs.glsl +72 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp +88 -228
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.glsl +454 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_shmem_types.glsl +78 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/multi_add.comp +97 -13
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/neg.comp +20 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/norm.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/opt_step_adamw.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/opt_step_sgd.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/pad.comp +21 -6
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/pool2d.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/quantize_q8_1.comp +10 -10
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/reglu.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/relu.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/repeat.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/repeat_back.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm.comp +50 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm_back.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm_partials.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/roll.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_funcs.glsl +234 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_head.glsl +20 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_multi.comp +6 -50
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_neox.comp +6 -33
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_norm.comp +6 -33
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_params.glsl +28 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_vision.comp +6 -39
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/round.comp +29 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/scale.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sigmoid.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/silu.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/silu_back.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sin.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/soft_max.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_back.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large1.comp +62 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large2.comp +79 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large3.comp +65 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large_common.glsl +53 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/softplus.comp +23 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/solve_tri.comp +81 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sqrt.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/square.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/ssm_conv.comp +44 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/ssm_scan.comp +124 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/step.comp +22 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sub.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sum_rows.comp +2 -25
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sum_rows.glsl +25 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/swiglu.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/swiglu_oai.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/tanh.comp +2 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/timestep_embedding.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/topk_argsort.comp +118 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/topk_moe.comp +213 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/topk_nary_search.comp +246 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp +43 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/trunc.comp +22 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{types.comp → types.glsl} +345 -26
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/upscale.comp +90 -12
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +335 -151
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/xielu.comp +35 -0
- data/ext/sources/ggml/src/ggml-webgpu/CMakeLists.txt +28 -2
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp +169 -0
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu.cpp +1964 -435
- data/ext/sources/ggml/src/ggml-webgpu/pre_wgsl.hpp +778 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/bin_op.tmpl.wgsl +188 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/cpy.tmpl.wgsl +101 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/embed_wgsl.py +33 -10
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn.wgsl +591 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/get_rows.tmpl.wgsl +1 -1
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/glu.tmpl.wgsl +323 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat.tmpl.wgsl +6 -6
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_decls.tmpl +97 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_reg_tile.tmpl.wgsl +247 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_subgroup_matrix.tmpl.wgsl +302 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec.tmpl.wgsl +267 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/rms_norm.wgsl +83 -17
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/rope.tmpl.wgsl +295 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/scale.tmpl.wgsl +90 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/set_rows.tmpl.wgsl +112 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/soft_max.tmpl.wgsl +345 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/unary_op.wgsl +483 -0
- data/ext/sources/ggml/src/ggml-zendnn/CMakeLists.txt +92 -0
- data/ext/sources/ggml/src/ggml-zendnn/ggml-zendnn.cpp +466 -0
- data/ext/sources/ggml/src/ggml.c +425 -33
- data/ext/sources/include/whisper.h +1 -0
- data/ext/sources/src/CMakeLists.txt +3 -1
- data/ext/sources/src/whisper.cpp +101 -35
- data/ext/sources/tests/CMakeLists.txt +2 -2
- data/ext/sources/tests/test-vad-full.cpp +4 -2
- data/ext/sources/tests/test-vad.cpp +1 -1
- data/extsources.rb +1 -0
- data/lib/whisper/model/uri.rb +17 -18
- data/sig/whisper.rbs +119 -2
- data/test/test_params.rb +16 -8
- data/test/test_segment.rb +0 -1
- data/test/test_token.rb +70 -0
- data/test/test_vad.rb +1 -1
- data/test/test_vad_context.rb +50 -0
- data/test/test_vad_segment.rb +19 -0
- data/test/test_vad_segments.rb +16 -0
- data/test/test_whisper.rb +7 -0
- data/whispercpp.gemspec +1 -1
- metadata +287 -34
- data/ext/sources/build-xcframework.sh +0 -571
- data/ext/sources/ggml/src/ggml-cann/Doxyfile +0 -2579
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.comp +0 -105
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_head.comp +0 -55
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/add.tmpl.wgsl +0 -44
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/add_in_place.tmpl.wgsl +0 -41
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/cpy.wgsl +0 -60
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul.tmpl.wgsl +0 -44
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_in_place.tmpl.wgsl +0 -41
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/rms_norm_in_place.wgsl +0 -48
- /data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{test_bfloat16_support.comp → feature-tests/bfloat16.comp} +0 -0
- /data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{test_coopmat_support.comp → feature-tests/coopmat.comp} +0 -0
- /data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{test_coopmat2_support.comp → feature-tests/coopmat2.comp} +0 -0
- /data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{test_integer_dot_support.comp → feature-tests/integer_dot.comp} +0 -0
- /data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{glu_main.comp → glu_main.glsl} +0 -0
- /data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{rte.comp → rte.glsl} +0 -0
- /data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{utils.comp → utils.glsl} +0 -0
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
#ifndef PRE_WGSL_HPP
|
|
2
|
+
#define PRE_WGSL_HPP
|
|
3
|
+
|
|
4
|
+
#include <cctype>
|
|
5
|
+
#include <fstream>
|
|
6
|
+
#include <sstream>
|
|
7
|
+
#include <stdexcept>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <string_view>
|
|
10
|
+
#include <unordered_map>
|
|
11
|
+
#include <unordered_set>
|
|
12
|
+
#include <vector>
|
|
13
|
+
|
|
14
|
+
namespace pre_wgsl {
|
|
15
|
+
|
|
16
|
+
//==============================================================
|
|
17
|
+
// Options
|
|
18
|
+
//==============================================================
|
|
19
|
+
struct Options {
|
|
20
|
+
std::string include_path = ".";
|
|
21
|
+
std::vector<std::string> macros;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//==============================================================
|
|
25
|
+
// Utility: trim
|
|
26
|
+
//==============================================================
|
|
27
|
+
static std::string trim(const std::string & s) {
|
|
28
|
+
size_t a = 0;
|
|
29
|
+
while (a < s.size() && std::isspace((unsigned char) s[a])) {
|
|
30
|
+
a++;
|
|
31
|
+
}
|
|
32
|
+
size_t b = s.size();
|
|
33
|
+
while (b > a && std::isspace((unsigned char) s[b - 1])) {
|
|
34
|
+
b--;
|
|
35
|
+
}
|
|
36
|
+
return s.substr(a, b - a);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static std::string trim_value(std::istream & is) {
|
|
40
|
+
std::string str;
|
|
41
|
+
std::getline(is, str);
|
|
42
|
+
return trim(str);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static bool isIdentChar(char c) {
|
|
46
|
+
return std::isalnum(static_cast<unsigned char>(c)) || c == '_';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static std::string expandMacrosRecursiveInternal(const std::string & line,
|
|
50
|
+
const std::unordered_map<std::string, std::string> & macros,
|
|
51
|
+
std::unordered_set<std::string> & visiting);
|
|
52
|
+
|
|
53
|
+
static std::string expandMacroValue(const std::string & name,
|
|
54
|
+
const std::unordered_map<std::string, std::string> & macros,
|
|
55
|
+
std::unordered_set<std::string> & visiting) {
|
|
56
|
+
if (visiting.count(name)) {
|
|
57
|
+
throw std::runtime_error("Recursive macro: " + name);
|
|
58
|
+
}
|
|
59
|
+
visiting.insert(name);
|
|
60
|
+
|
|
61
|
+
auto it = macros.find(name);
|
|
62
|
+
if (it == macros.end()) {
|
|
63
|
+
visiting.erase(name);
|
|
64
|
+
return name;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const std::string & value = it->second;
|
|
68
|
+
if (value.empty()) {
|
|
69
|
+
visiting.erase(name);
|
|
70
|
+
return "";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
std::string expanded = expandMacrosRecursiveInternal(value, macros, visiting);
|
|
74
|
+
visiting.erase(name);
|
|
75
|
+
return expanded;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static std::string expandMacrosRecursiveInternal(const std::string & line,
|
|
79
|
+
const std::unordered_map<std::string, std::string> & macros,
|
|
80
|
+
std::unordered_set<std::string> & visiting) {
|
|
81
|
+
std::string result;
|
|
82
|
+
result.reserve(line.size());
|
|
83
|
+
|
|
84
|
+
size_t i = 0;
|
|
85
|
+
while (i < line.size()) {
|
|
86
|
+
if (isIdentChar(line[i])) {
|
|
87
|
+
size_t start = i;
|
|
88
|
+
while (i < line.size() && isIdentChar(line[i])) {
|
|
89
|
+
i++;
|
|
90
|
+
}
|
|
91
|
+
std::string token = line.substr(start, i - start);
|
|
92
|
+
|
|
93
|
+
auto it = macros.find(token);
|
|
94
|
+
if (it != macros.end()) {
|
|
95
|
+
result += expandMacroValue(token, macros, visiting);
|
|
96
|
+
} else {
|
|
97
|
+
result += token;
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
result += line[i];
|
|
101
|
+
i++;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static std::string expandMacrosRecursive(const std::string & line,
|
|
109
|
+
const std::unordered_map<std::string, std::string> & macros) {
|
|
110
|
+
std::unordered_set<std::string> visiting;
|
|
111
|
+
return expandMacrosRecursiveInternal(line, macros, visiting);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//==============================================================
|
|
115
|
+
// Tokenizer for expressions in #if/#elif
|
|
116
|
+
//==============================================================
|
|
117
|
+
class ExprLexer {
|
|
118
|
+
public:
|
|
119
|
+
enum Kind { END, IDENT, NUMBER, OP, LPAREN, RPAREN };
|
|
120
|
+
|
|
121
|
+
struct Tok {
|
|
122
|
+
Kind kind;
|
|
123
|
+
std::string text;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
explicit ExprLexer(std::string_view sv) : src(sv), pos(0) {}
|
|
127
|
+
|
|
128
|
+
Tok next() {
|
|
129
|
+
skipWS();
|
|
130
|
+
if (pos >= src.size()) {
|
|
131
|
+
return { END, "" };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
char c = src[pos];
|
|
135
|
+
|
|
136
|
+
// number
|
|
137
|
+
if (std::isdigit((unsigned char) c)) {
|
|
138
|
+
size_t start = pos;
|
|
139
|
+
while (pos < src.size() && std::isdigit((unsigned char) src[pos])) {
|
|
140
|
+
pos++;
|
|
141
|
+
}
|
|
142
|
+
return { NUMBER, std::string(src.substr(start, pos - start)) };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// identifier
|
|
146
|
+
if (std::isalpha((unsigned char) c) || c == '_') {
|
|
147
|
+
size_t start = pos;
|
|
148
|
+
while (pos < src.size() && (std::isalnum((unsigned char) src[pos]) || src[pos] == '_')) {
|
|
149
|
+
pos++;
|
|
150
|
+
}
|
|
151
|
+
return { IDENT, std::string(src.substr(start, pos - start)) };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (c == '(') {
|
|
155
|
+
pos++;
|
|
156
|
+
return { LPAREN, "(" };
|
|
157
|
+
}
|
|
158
|
+
if (c == ')') {
|
|
159
|
+
pos++;
|
|
160
|
+
return { RPAREN, ")" };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// multi-char operators
|
|
164
|
+
static const char * two_ops[] = { "==", "!=", "<=", ">=", "&&", "||", "<<", ">>" };
|
|
165
|
+
for (auto op : two_ops) {
|
|
166
|
+
if (src.substr(pos, 2) == op) {
|
|
167
|
+
pos += 2;
|
|
168
|
+
return { OP, std::string(op) };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// single-char operators
|
|
173
|
+
if (std::string("+-*/%<>!").find(c) != std::string::npos) {
|
|
174
|
+
pos++;
|
|
175
|
+
return { OP, std::string(1, c) };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// unexpected
|
|
179
|
+
pos++;
|
|
180
|
+
return { END, "" };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private:
|
|
184
|
+
std::string_view src;
|
|
185
|
+
size_t pos;
|
|
186
|
+
|
|
187
|
+
void skipWS() {
|
|
188
|
+
while (pos < src.size() && std::isspace((unsigned char) src[pos])) {
|
|
189
|
+
pos++;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
//==============================================================
|
|
195
|
+
// Expression Parser (recursive descent)
|
|
196
|
+
//==============================================================
|
|
197
|
+
class ExprParser {
|
|
198
|
+
public:
|
|
199
|
+
ExprParser(std::string_view expr,
|
|
200
|
+
const std::unordered_map<std::string, std::string> & macros,
|
|
201
|
+
std::unordered_set<std::string> & visiting) :
|
|
202
|
+
lex(expr),
|
|
203
|
+
macros(macros),
|
|
204
|
+
visiting(visiting) {
|
|
205
|
+
advance();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
int parse() { return parseLogicalOr(); }
|
|
209
|
+
|
|
210
|
+
private:
|
|
211
|
+
ExprLexer lex;
|
|
212
|
+
ExprLexer::Tok tok;
|
|
213
|
+
const std::unordered_map<std::string, std::string> & macros;
|
|
214
|
+
std::unordered_set<std::string> & visiting;
|
|
215
|
+
|
|
216
|
+
void advance() { tok = lex.next(); }
|
|
217
|
+
|
|
218
|
+
bool acceptOp(const std::string & s) {
|
|
219
|
+
if (tok.kind == ExprLexer::OP && tok.text == s) {
|
|
220
|
+
advance();
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
bool acceptKind(ExprLexer::Kind k) {
|
|
227
|
+
if (tok.kind == k) {
|
|
228
|
+
advance();
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
int parseLogicalOr() {
|
|
235
|
+
int v = parseLogicalAnd();
|
|
236
|
+
while (acceptOp("||")) {
|
|
237
|
+
int rhs = parseLogicalAnd();
|
|
238
|
+
v = (v || rhs);
|
|
239
|
+
}
|
|
240
|
+
return v;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
int parseLogicalAnd() {
|
|
244
|
+
int v = parseEquality();
|
|
245
|
+
while (acceptOp("&&")) {
|
|
246
|
+
int rhs = parseEquality();
|
|
247
|
+
v = (v && rhs);
|
|
248
|
+
}
|
|
249
|
+
return v;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
int parseEquality() {
|
|
253
|
+
int v = parseRelational();
|
|
254
|
+
for (;;) {
|
|
255
|
+
if (acceptOp("==")) {
|
|
256
|
+
int rhs = parseRelational();
|
|
257
|
+
v = (v == rhs);
|
|
258
|
+
} else if (acceptOp("!=")) {
|
|
259
|
+
int rhs = parseRelational();
|
|
260
|
+
v = (v != rhs);
|
|
261
|
+
} else {
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return v;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
int parseRelational() {
|
|
269
|
+
int v = parseShift();
|
|
270
|
+
for (;;) {
|
|
271
|
+
if (acceptOp("<")) {
|
|
272
|
+
int rhs = parseShift();
|
|
273
|
+
v = (v < rhs);
|
|
274
|
+
} else if (acceptOp(">")) {
|
|
275
|
+
int rhs = parseShift();
|
|
276
|
+
v = (v > rhs);
|
|
277
|
+
} else if (acceptOp("<=")) {
|
|
278
|
+
int rhs = parseShift();
|
|
279
|
+
v = (v <= rhs);
|
|
280
|
+
} else if (acceptOp(">=")) {
|
|
281
|
+
int rhs = parseShift();
|
|
282
|
+
v = (v >= rhs);
|
|
283
|
+
} else {
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return v;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
int parseShift() {
|
|
291
|
+
int v = parseAdd();
|
|
292
|
+
for (;;) {
|
|
293
|
+
if (acceptOp("<<")) {
|
|
294
|
+
int rhs = parseAdd();
|
|
295
|
+
v = (v << rhs);
|
|
296
|
+
} else if (acceptOp(">>")) {
|
|
297
|
+
int rhs = parseAdd();
|
|
298
|
+
v = (v >> rhs);
|
|
299
|
+
} else {
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return v;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
int parseAdd() {
|
|
307
|
+
int v = parseMult();
|
|
308
|
+
for (;;) {
|
|
309
|
+
if (acceptOp("+")) {
|
|
310
|
+
int rhs = parseMult();
|
|
311
|
+
v = (v + rhs);
|
|
312
|
+
} else if (acceptOp("-")) {
|
|
313
|
+
int rhs = parseMult();
|
|
314
|
+
v = (v - rhs);
|
|
315
|
+
} else {
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return v;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
int parseMult() {
|
|
323
|
+
int v = parseUnary();
|
|
324
|
+
for (;;) {
|
|
325
|
+
if (acceptOp("*")) {
|
|
326
|
+
int rhs = parseUnary();
|
|
327
|
+
v = (v * rhs);
|
|
328
|
+
} else if (acceptOp("/")) {
|
|
329
|
+
int rhs = parseUnary();
|
|
330
|
+
v = (rhs == 0 ? 0 : v / rhs);
|
|
331
|
+
} else if (acceptOp("%")) {
|
|
332
|
+
int rhs = parseUnary();
|
|
333
|
+
v = (rhs == 0 ? 0 : v % rhs);
|
|
334
|
+
} else {
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return v;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
int parseUnary() {
|
|
342
|
+
if (acceptOp("!")) {
|
|
343
|
+
return !parseUnary();
|
|
344
|
+
}
|
|
345
|
+
if (acceptOp("-")) {
|
|
346
|
+
return -parseUnary();
|
|
347
|
+
}
|
|
348
|
+
if (acceptOp("+")) {
|
|
349
|
+
return +parseUnary();
|
|
350
|
+
}
|
|
351
|
+
return parsePrimary();
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
int parsePrimary() {
|
|
355
|
+
// '(' expr ')'
|
|
356
|
+
if (acceptKind(ExprLexer::LPAREN)) {
|
|
357
|
+
int v = parse();
|
|
358
|
+
if (!acceptKind(ExprLexer::RPAREN)) {
|
|
359
|
+
throw std::runtime_error("missing ')'");
|
|
360
|
+
}
|
|
361
|
+
return v;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// number
|
|
365
|
+
if (tok.kind == ExprLexer::NUMBER) {
|
|
366
|
+
int v = std::stoi(tok.text);
|
|
367
|
+
advance();
|
|
368
|
+
return v;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// defined(identifier)
|
|
372
|
+
if (tok.kind == ExprLexer::IDENT && tok.text == "defined") {
|
|
373
|
+
advance();
|
|
374
|
+
if (acceptKind(ExprLexer::LPAREN)) {
|
|
375
|
+
if (tok.kind != ExprLexer::IDENT) {
|
|
376
|
+
throw std::runtime_error("expected identifier in defined()");
|
|
377
|
+
}
|
|
378
|
+
std::string name = tok.text;
|
|
379
|
+
advance();
|
|
380
|
+
if (!acceptKind(ExprLexer::RPAREN)) {
|
|
381
|
+
throw std::runtime_error("missing ) in defined()");
|
|
382
|
+
}
|
|
383
|
+
return macros.count(name) ? 1 : 0;
|
|
384
|
+
} else {
|
|
385
|
+
// defined NAME
|
|
386
|
+
if (tok.kind != ExprLexer::IDENT) {
|
|
387
|
+
throw std::runtime_error("expected identifier in defined NAME");
|
|
388
|
+
}
|
|
389
|
+
std::string name = tok.text;
|
|
390
|
+
advance();
|
|
391
|
+
return macros.count(name) ? 1 : 0;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// identifier -> treat as integer, if defined use its value else 0
|
|
396
|
+
if (tok.kind == ExprLexer::IDENT) {
|
|
397
|
+
std::string name = tok.text;
|
|
398
|
+
advance();
|
|
399
|
+
auto it = macros.find(name);
|
|
400
|
+
if (it == macros.end()) {
|
|
401
|
+
return 0;
|
|
402
|
+
}
|
|
403
|
+
if (it->second.empty()) {
|
|
404
|
+
return 1;
|
|
405
|
+
}
|
|
406
|
+
return evalMacroExpression(name, it->second);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// unexpected
|
|
410
|
+
return 0;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
int evalMacroExpression(const std::string & name, const std::string & value) {
|
|
414
|
+
if (visiting.count(name)) {
|
|
415
|
+
throw std::runtime_error("Recursive macro: " + name);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
visiting.insert(name);
|
|
419
|
+
ExprParser ep(value, macros, visiting);
|
|
420
|
+
int v = ep.parse();
|
|
421
|
+
visiting.erase(name);
|
|
422
|
+
return v;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
//==============================================================
|
|
427
|
+
// Preprocessor
|
|
428
|
+
//==============================================================
|
|
429
|
+
class Preprocessor {
|
|
430
|
+
public:
|
|
431
|
+
explicit Preprocessor(Options opts = {}) : opts_(std::move(opts)) {
|
|
432
|
+
// Treat empty include path as current directory
|
|
433
|
+
if (opts_.include_path.empty()) {
|
|
434
|
+
opts_.include_path = ".";
|
|
435
|
+
}
|
|
436
|
+
parseMacroDefinitions(opts_.macros);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
std::string preprocess_file(const std::string & filename, const std::vector<std::string> & additional_macros = {}) {
|
|
440
|
+
std::unordered_map<std::string, std::string> macros;
|
|
441
|
+
std::unordered_set<std::string> predefined;
|
|
442
|
+
std::unordered_set<std::string> include_stack;
|
|
443
|
+
buildMacros(additional_macros, macros, predefined);
|
|
444
|
+
|
|
445
|
+
std::string result = processFile(filename, macros, predefined, include_stack, DirectiveMode::All);
|
|
446
|
+
return result;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
std::string preprocess(const std::string & contents, const std::vector<std::string> & additional_macros = {}) {
|
|
450
|
+
std::unordered_map<std::string, std::string> macros;
|
|
451
|
+
std::unordered_set<std::string> predefined;
|
|
452
|
+
std::unordered_set<std::string> include_stack;
|
|
453
|
+
buildMacros(additional_macros, macros, predefined);
|
|
454
|
+
|
|
455
|
+
std::string result = processString(contents, macros, predefined, include_stack, DirectiveMode::All);
|
|
456
|
+
return result;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
std::string preprocess_includes_file(const std::string & filename) {
|
|
460
|
+
std::unordered_map<std::string, std::string> macros;
|
|
461
|
+
std::unordered_set<std::string> predefined;
|
|
462
|
+
std::unordered_set<std::string> include_stack;
|
|
463
|
+
std::string result = processFile(filename, macros, predefined, include_stack, DirectiveMode::IncludesOnly);
|
|
464
|
+
return result;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
std::string preprocess_includes(const std::string & contents) {
|
|
468
|
+
std::unordered_map<std::string, std::string> macros;
|
|
469
|
+
std::unordered_set<std::string> predefined;
|
|
470
|
+
std::unordered_set<std::string> include_stack;
|
|
471
|
+
std::string result = processString(contents, macros, predefined, include_stack, DirectiveMode::IncludesOnly);
|
|
472
|
+
return result;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
private:
|
|
476
|
+
Options opts_;
|
|
477
|
+
std::unordered_map<std::string, std::string> global_macros;
|
|
478
|
+
|
|
479
|
+
enum class DirectiveMode { All, IncludesOnly };
|
|
480
|
+
|
|
481
|
+
struct Cond {
|
|
482
|
+
bool parent_active;
|
|
483
|
+
bool active;
|
|
484
|
+
bool taken;
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
//----------------------------------------------------------
|
|
488
|
+
// Parse macro definitions into global_macros
|
|
489
|
+
//----------------------------------------------------------
|
|
490
|
+
void parseMacroDefinitions(const std::vector<std::string> & macro_defs) {
|
|
491
|
+
for (const auto & def : macro_defs) {
|
|
492
|
+
size_t eq_pos = def.find('=');
|
|
493
|
+
if (eq_pos != std::string::npos) {
|
|
494
|
+
// Format: NAME=VALUE
|
|
495
|
+
std::string name = trim(def.substr(0, eq_pos));
|
|
496
|
+
std::string value = trim(def.substr(eq_pos + 1));
|
|
497
|
+
global_macros[name] = value;
|
|
498
|
+
} else {
|
|
499
|
+
// Format: NAME
|
|
500
|
+
std::string name = trim(def);
|
|
501
|
+
global_macros[name] = "";
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
//----------------------------------------------------------
|
|
507
|
+
// Build combined macro map and predefined set for a preprocessing operation
|
|
508
|
+
//----------------------------------------------------------
|
|
509
|
+
void buildMacros(const std::vector<std::string> & additional_macros,
|
|
510
|
+
std::unordered_map<std::string, std::string> & macros,
|
|
511
|
+
std::unordered_set<std::string> & predefined) {
|
|
512
|
+
macros = global_macros;
|
|
513
|
+
predefined.clear();
|
|
514
|
+
|
|
515
|
+
for (const auto & [name, value] : global_macros) {
|
|
516
|
+
predefined.insert(name);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
for (const auto & def : additional_macros) {
|
|
520
|
+
size_t eq_pos = def.find('=');
|
|
521
|
+
std::string name, value;
|
|
522
|
+
if (eq_pos != std::string::npos) {
|
|
523
|
+
name = trim(def.substr(0, eq_pos));
|
|
524
|
+
value = trim(def.substr(eq_pos + 1));
|
|
525
|
+
} else {
|
|
526
|
+
name = trim(def);
|
|
527
|
+
value = "";
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// Add to macros map (will override global if same name)
|
|
531
|
+
macros[name] = value;
|
|
532
|
+
predefined.insert(name);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
//----------------------------------------------------------
|
|
537
|
+
// Helpers
|
|
538
|
+
//----------------------------------------------------------
|
|
539
|
+
std::string loadFile(const std::string & fname) {
|
|
540
|
+
std::ifstream f(fname);
|
|
541
|
+
if (!f.is_open()) {
|
|
542
|
+
throw std::runtime_error("Could not open file: " + fname);
|
|
543
|
+
}
|
|
544
|
+
std::stringstream ss;
|
|
545
|
+
ss << f.rdbuf();
|
|
546
|
+
return ss.str();
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
bool condActive(const std::vector<Cond> & cond) const {
|
|
550
|
+
if (cond.empty()) {
|
|
551
|
+
return true;
|
|
552
|
+
}
|
|
553
|
+
return cond.back().active;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
//----------------------------------------------------------
|
|
557
|
+
// Process a file
|
|
558
|
+
//----------------------------------------------------------
|
|
559
|
+
std::string processFile(const std::string & name,
|
|
560
|
+
std::unordered_map<std::string, std::string> & macros,
|
|
561
|
+
const std::unordered_set<std::string> & predefined_macros,
|
|
562
|
+
std::unordered_set<std::string> & include_stack,
|
|
563
|
+
DirectiveMode mode) {
|
|
564
|
+
if (include_stack.count(name)) {
|
|
565
|
+
throw std::runtime_error("Recursive include: " + name);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
include_stack.insert(name);
|
|
569
|
+
std::string shader_code = loadFile(name);
|
|
570
|
+
std::string out = processString(shader_code, macros, predefined_macros, include_stack, mode);
|
|
571
|
+
include_stack.erase(name);
|
|
572
|
+
return out;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
std::string processIncludeFile(const std::string & fname,
|
|
576
|
+
std::unordered_map<std::string, std::string> & macros,
|
|
577
|
+
const std::unordered_set<std::string> & predefined_macros,
|
|
578
|
+
std::unordered_set<std::string> & include_stack,
|
|
579
|
+
DirectiveMode mode) {
|
|
580
|
+
std::string full_path = opts_.include_path + "/" + fname;
|
|
581
|
+
return processFile(full_path, macros, predefined_macros, include_stack, mode);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
//----------------------------------------------------------
|
|
585
|
+
// Process text
|
|
586
|
+
//----------------------------------------------------------
|
|
587
|
+
std::string processString(const std::string & shader_code,
|
|
588
|
+
std::unordered_map<std::string, std::string> & macros,
|
|
589
|
+
const std::unordered_set<std::string> & predefined_macros,
|
|
590
|
+
std::unordered_set<std::string> & include_stack,
|
|
591
|
+
DirectiveMode mode) {
|
|
592
|
+
std::vector<Cond> cond; // Conditional stack for this shader
|
|
593
|
+
std::stringstream out;
|
|
594
|
+
std::istringstream in(shader_code);
|
|
595
|
+
std::string line;
|
|
596
|
+
|
|
597
|
+
while (std::getline(in, line)) {
|
|
598
|
+
std::string t = trim(line);
|
|
599
|
+
|
|
600
|
+
if (!t.empty() && t[0] == '#') {
|
|
601
|
+
bool handled = handleDirective(t, out, macros, predefined_macros, cond, include_stack, mode);
|
|
602
|
+
if (mode == DirectiveMode::IncludesOnly && !handled) {
|
|
603
|
+
out << line << "\n";
|
|
604
|
+
}
|
|
605
|
+
} else {
|
|
606
|
+
if (mode == DirectiveMode::IncludesOnly) {
|
|
607
|
+
out << line << "\n";
|
|
608
|
+
} else if (condActive(cond)) {
|
|
609
|
+
// Expand macros in the line before outputting
|
|
610
|
+
std::string expanded = expandMacrosRecursive(line, macros);
|
|
611
|
+
out << expanded << "\n";
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (mode == DirectiveMode::All && !cond.empty()) {
|
|
617
|
+
throw std::runtime_error("Unclosed #if directive");
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return out.str();
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
//----------------------------------------------------------
|
|
624
|
+
// Directive handler
|
|
625
|
+
//----------------------------------------------------------
|
|
626
|
+
bool handleDirective(const std::string & t,
|
|
627
|
+
std::stringstream & out,
|
|
628
|
+
std::unordered_map<std::string, std::string> & macros,
|
|
629
|
+
const std::unordered_set<std::string> & predefined_macros,
|
|
630
|
+
std::vector<Cond> & cond,
|
|
631
|
+
std::unordered_set<std::string> & include_stack,
|
|
632
|
+
DirectiveMode mode) {
|
|
633
|
+
// split into tokens
|
|
634
|
+
std::string body = t.substr(1);
|
|
635
|
+
std::istringstream iss(body);
|
|
636
|
+
std::string cmd;
|
|
637
|
+
iss >> cmd;
|
|
638
|
+
|
|
639
|
+
if (cmd == "include") {
|
|
640
|
+
if (mode == DirectiveMode::All && !condActive(cond)) {
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
643
|
+
std::string file;
|
|
644
|
+
iss >> file;
|
|
645
|
+
if (file.size() >= 2 && file.front() == '"' && file.back() == '"') {
|
|
646
|
+
file = file.substr(1, file.size() - 2);
|
|
647
|
+
}
|
|
648
|
+
out << processIncludeFile(file, macros, predefined_macros, include_stack, mode);
|
|
649
|
+
return true;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
if (mode == DirectiveMode::IncludesOnly) {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (cmd == "define") {
|
|
657
|
+
if (!condActive(cond)) {
|
|
658
|
+
return true;
|
|
659
|
+
}
|
|
660
|
+
std::string name;
|
|
661
|
+
iss >> name;
|
|
662
|
+
// Don't override predefined macros from options
|
|
663
|
+
if (predefined_macros.count(name)) {
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
std::string value = trim_value(iss);
|
|
667
|
+
macros[name] = value;
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (cmd == "undef") {
|
|
672
|
+
if (!condActive(cond)) {
|
|
673
|
+
return true;
|
|
674
|
+
}
|
|
675
|
+
std::string name;
|
|
676
|
+
iss >> name;
|
|
677
|
+
// Don't undef predefined macros from options
|
|
678
|
+
if (predefined_macros.count(name)) {
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
681
|
+
macros.erase(name);
|
|
682
|
+
return true;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
if (cmd == "ifdef") {
|
|
686
|
+
std::string name;
|
|
687
|
+
iss >> name;
|
|
688
|
+
bool p = condActive(cond);
|
|
689
|
+
bool v = macros.count(name);
|
|
690
|
+
cond.push_back({ p, p && v, p && v });
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
if (cmd == "ifndef") {
|
|
695
|
+
std::string name;
|
|
696
|
+
iss >> name;
|
|
697
|
+
bool p = condActive(cond);
|
|
698
|
+
bool v = !macros.count(name);
|
|
699
|
+
cond.push_back({ p, p && v, p && v });
|
|
700
|
+
return true;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
if (cmd == "if") {
|
|
704
|
+
std::string expr = trim_value(iss);
|
|
705
|
+
bool p = condActive(cond);
|
|
706
|
+
bool v = false;
|
|
707
|
+
if (p) {
|
|
708
|
+
std::unordered_set<std::string> visiting;
|
|
709
|
+
ExprParser ep(expr, macros, visiting);
|
|
710
|
+
v = ep.parse() != 0;
|
|
711
|
+
}
|
|
712
|
+
cond.push_back({ p, p && v, p && v });
|
|
713
|
+
return true;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (cmd == "elif") {
|
|
717
|
+
std::string expr = trim_value(iss);
|
|
718
|
+
|
|
719
|
+
if (cond.empty()) {
|
|
720
|
+
throw std::runtime_error("#elif without #if");
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
Cond & c = cond.back();
|
|
724
|
+
if (!c.parent_active) {
|
|
725
|
+
c.active = false;
|
|
726
|
+
return true;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
if (c.taken) {
|
|
730
|
+
c.active = false;
|
|
731
|
+
return true;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
std::unordered_set<std::string> visiting;
|
|
735
|
+
ExprParser ep(expr, macros, visiting);
|
|
736
|
+
bool v = ep.parse() != 0;
|
|
737
|
+
c.active = v;
|
|
738
|
+
if (v) {
|
|
739
|
+
c.taken = true;
|
|
740
|
+
}
|
|
741
|
+
return true;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (cmd == "else") {
|
|
745
|
+
if (cond.empty()) {
|
|
746
|
+
throw std::runtime_error("#else without #if");
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
Cond & c = cond.back();
|
|
750
|
+
if (!c.parent_active) {
|
|
751
|
+
c.active = false;
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
if (c.taken) {
|
|
755
|
+
c.active = false;
|
|
756
|
+
} else {
|
|
757
|
+
c.active = true;
|
|
758
|
+
c.taken = true;
|
|
759
|
+
}
|
|
760
|
+
return true;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
if (cmd == "endif") {
|
|
764
|
+
if (cond.empty()) {
|
|
765
|
+
throw std::runtime_error("#endif without #if");
|
|
766
|
+
}
|
|
767
|
+
cond.pop_back();
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// Unknown directive
|
|
772
|
+
throw std::runtime_error("Unknown directive: #" + cmd);
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
} // namespace pre_wgsl
|
|
777
|
+
|
|
778
|
+
#endif // PRE_WGSL_HPP
|