whispercpp 1.3.3 → 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 +79 -25
- 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/CMakeLists.txt +1 -0
- data/ext/sources/examples/addon.node/addon.cpp +19 -19
- data/ext/sources/examples/addon.node/index.js +7 -5
- data/ext/sources/examples/addon.node/vad-example.js +2 -2
- data/ext/sources/examples/bench/bench.cpp +26 -16
- data/ext/sources/examples/bench.wasm/index-tmpl.html +10 -9
- data/ext/sources/examples/cli/cli.cpp +122 -111
- data/ext/sources/examples/command/command.cpp +26 -24
- data/ext/sources/examples/command.wasm/index-tmpl.html +5 -4
- data/ext/sources/examples/common-ggml.cpp +2 -0
- data/ext/sources/examples/lsp/CMakeLists.txt +2 -1
- data/ext/sources/examples/lsp/lsp.cpp +19 -17
- data/ext/sources/examples/quantize/CMakeLists.txt +2 -1
- data/ext/sources/examples/server/server.cpp +34 -24
- data/ext/sources/examples/server.py +6 -1
- data/ext/sources/examples/stream/stream.cpp +4 -2
- data/ext/sources/examples/stream.wasm/emscripten.cpp +6 -6
- data/ext/sources/examples/stream.wasm/index-tmpl.html +82 -5
- data/ext/sources/examples/talk-llama/CMakeLists.txt +7 -3
- data/ext/sources/examples/talk-llama/llama-adapter.cpp +113 -7
- data/ext/sources/examples/talk-llama/llama-adapter.h +13 -1
- data/ext/sources/examples/talk-llama/llama-arch.cpp +2136 -1491
- data/ext/sources/examples/talk-llama/llama-arch.h +125 -3
- data/ext/sources/examples/talk-llama/llama-batch.cpp +174 -100
- data/ext/sources/examples/talk-llama/llama-batch.h +46 -20
- data/ext/sources/examples/talk-llama/llama-chat.cpp +199 -8
- data/ext/sources/examples/talk-llama/llama-chat.h +11 -0
- data/ext/sources/examples/talk-llama/llama-context.cpp +1213 -413
- data/ext/sources/examples/talk-llama/llama-context.h +99 -36
- data/ext/sources/examples/talk-llama/llama-cparams.h +5 -4
- 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 +883 -294
- data/ext/sources/examples/talk-llama/llama-graph.h +361 -161
- data/ext/sources/examples/talk-llama/llama-hparams.cpp +144 -6
- data/ext/sources/examples/talk-llama/llama-hparams.h +100 -23
- data/ext/sources/examples/talk-llama/llama-impl.cpp +7 -3
- data/ext/sources/examples/talk-llama/llama-impl.h +3 -1
- data/ext/sources/examples/talk-llama/llama-kv-cache-iswa.cpp +328 -0
- data/ext/sources/examples/talk-llama/{llama-kv-cache-unified-iswa.h → llama-kv-cache-iswa.h} +38 -29
- data/ext/sources/examples/talk-llama/llama-kv-cache.cpp +2100 -0
- data/ext/sources/examples/talk-llama/llama-kv-cache.h +373 -27
- data/ext/sources/examples/talk-llama/llama-kv-cells.h +124 -30
- data/ext/sources/examples/talk-llama/llama-memory-hybrid.cpp +63 -41
- data/ext/sources/examples/talk-llama/llama-memory-hybrid.h +30 -29
- data/ext/sources/examples/talk-llama/llama-memory-recurrent.cpp +77 -35
- data/ext/sources/examples/talk-llama/llama-memory-recurrent.h +15 -16
- data/ext/sources/examples/talk-llama/llama-memory.h +16 -10
- 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 +93 -9
- data/ext/sources/examples/talk-llama/llama-model-loader.h +9 -2
- data/ext/sources/examples/talk-llama/llama-model-saver.cpp +3 -0
- data/ext/sources/examples/talk-llama/llama-model.cpp +3369 -10145
- data/ext/sources/examples/talk-llama/llama-model.h +104 -12
- data/ext/sources/examples/talk-llama/llama-quant.cpp +53 -30
- data/ext/sources/examples/talk-llama/llama-sampling.cpp +1520 -324
- data/ext/sources/examples/talk-llama/llama-sampling.h +19 -7
- data/ext/sources/examples/talk-llama/llama-vocab.cpp +562 -39
- data/ext/sources/examples/talk-llama/llama-vocab.h +50 -0
- data/ext/sources/examples/talk-llama/llama.cpp +794 -12
- data/ext/sources/examples/talk-llama/llama.h +246 -190
- 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/talk-llama.cpp +9 -6
- data/ext/sources/examples/talk-llama/unicode.cpp +309 -16
- data/ext/sources/examples/talk-llama/unicode.h +45 -0
- data/ext/sources/examples/vad-speech-segments/CMakeLists.txt +1 -1
- data/ext/sources/examples/wchess/wchess.cmd/wchess.cmd.cpp +4 -2
- data/ext/sources/examples/whisper.wasm/index-tmpl.html +18 -17
- data/ext/sources/ggml/CMakeLists.txt +135 -79
- data/ext/sources/ggml/cmake/ggml-config.cmake.in +132 -93
- data/ext/sources/ggml/include/ggml-alloc.h +9 -0
- data/ext/sources/ggml/include/ggml-backend.h +21 -2
- data/ext/sources/ggml/include/ggml-cpu.h +2 -1
- data/ext/sources/ggml/include/ggml-hexagon.h +19 -0
- data/ext/sources/ggml/include/ggml-metal.h +1 -6
- data/ext/sources/ggml/include/ggml-opt.h +25 -6
- data/ext/sources/ggml/include/ggml-rpc.h +8 -11
- data/ext/sources/ggml/include/ggml-webgpu.h +19 -0
- data/ext/sources/ggml/include/ggml-zdnn.h +17 -0
- data/ext/sources/ggml/include/ggml-zendnn.h +22 -0
- data/ext/sources/ggml/include/ggml.h +406 -23
- data/ext/sources/ggml/src/CMakeLists.txt +99 -13
- data/ext/sources/ggml/src/ggml-alloc.c +368 -161
- data/ext/sources/ggml/src/ggml-backend-impl.h +5 -5
- data/ext/sources/ggml/src/ggml-backend-reg.cpp +55 -14
- data/ext/sources/ggml/src/ggml-backend.cpp +290 -57
- data/ext/sources/ggml/src/ggml-blas/CMakeLists.txt +17 -3
- data/ext/sources/ggml/src/ggml-blas/ggml-blas.cpp +10 -13
- data/ext/sources/ggml/src/ggml-cann/CMakeLists.txt +14 -0
- data/ext/sources/ggml/src/ggml-cann/acl_tensor.cpp +59 -45
- data/ext/sources/ggml/src/ggml-cann/acl_tensor.h +138 -47
- data/ext/sources/ggml/src/ggml-cann/aclnn_ops.cpp +2586 -1917
- data/ext/sources/ggml/src/ggml-cann/aclnn_ops.h +348 -309
- data/ext/sources/ggml/src/ggml-cann/common.h +350 -133
- data/ext/sources/ggml/src/ggml-cann/ggml-cann.cpp +894 -625
- data/ext/sources/ggml/src/ggml-common.h +17 -0
- data/ext/sources/ggml/src/ggml-cpu/CMakeLists.txt +167 -75
- data/ext/sources/ggml/src/ggml-cpu/amx/amx.cpp +5 -2
- 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 +560 -622
- data/ext/sources/ggml/src/ggml-cpu/arch/arm/repack.cpp +1002 -270
- data/ext/sources/ggml/src/ggml-cpu/arch/loongarch/quants.c +107 -587
- data/ext/sources/ggml/src/ggml-cpu/arch/powerpc/quants.c +162 -589
- 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 +373 -486
- data/ext/sources/ggml/src/ggml-cpu/arch/riscv/repack.cpp +3 -58
- data/ext/sources/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp +50 -0
- data/ext/sources/ggml/src/ggml-cpu/arch/s390/quants.c +521 -353
- data/ext/sources/ggml/src/ggml-cpu/arch/wasm/quants.c +54 -314
- data/ext/sources/ggml/src/ggml-cpu/arch/x86/quants.c +184 -675
- data/ext/sources/ggml/src/ggml-cpu/arch/x86/repack.cpp +4682 -1660
- data/ext/sources/ggml/src/ggml-cpu/arch-fallback.h +82 -4
- data/ext/sources/ggml/src/ggml-cpu/common.h +14 -0
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu-impl.h +18 -9
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.c +263 -111
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.cpp +39 -28
- data/ext/sources/ggml/src/ggml-cpu/kleidiai/kernels.cpp +683 -82
- data/ext/sources/ggml/src/ggml-cpu/kleidiai/kernels.h +38 -43
- data/ext/sources/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +435 -119
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm-ppc.h +333 -0
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm.cpp +1234 -1182
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm.h +6 -0
- data/ext/sources/ggml/src/ggml-cpu/ops.cpp +2167 -1480
- data/ext/sources/ggml/src/ggml-cpu/ops.h +10 -12
- data/ext/sources/ggml/src/ggml-cpu/quants.c +35 -0
- data/ext/sources/ggml/src/ggml-cpu/quants.h +8 -0
- data/ext/sources/ggml/src/ggml-cpu/repack.cpp +1132 -81
- data/ext/sources/ggml/src/ggml-cpu/repack.h +36 -0
- data/ext/sources/ggml/src/ggml-cpu/simd-mappings.h +120 -93
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime.cpp +1025 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime.h +13 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime1_kernels.cpp +3196 -0
- data/ext/sources/ggml/src/ggml-cpu/spacemit/ime_kernels.h +26 -0
- data/ext/sources/ggml/src/ggml-cpu/traits.cpp +2 -2
- data/ext/sources/ggml/src/ggml-cpu/traits.h +1 -1
- 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 +294 -27
- data/ext/sources/ggml/src/ggml-cpu/vec.h +606 -48
- data/ext/sources/ggml/src/ggml-cuda/CMakeLists.txt +92 -17
- data/ext/sources/ggml/src/ggml-cuda/add-id.cu +58 -0
- data/ext/sources/ggml/src/ggml-cuda/add-id.cuh +3 -0
- 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 +330 -191
- data/ext/sources/ggml/src/ggml-cuda/binbcast.cuh +2 -0
- data/ext/sources/ggml/src/ggml-cuda/common.cuh +588 -128
- data/ext/sources/ggml/src/ggml-cuda/conv-transpose-1d.cu +1 -4
- data/ext/sources/ggml/src/ggml-cuda/conv2d.cu +166 -0
- data/ext/sources/ggml/src/ggml-cuda/conv2d.cuh +5 -0
- data/ext/sources/ggml/src/ggml-cuda/convert.cu +95 -22
- data/ext/sources/ggml/src/ggml-cuda/convert.cuh +25 -0
- data/ext/sources/ggml/src/ggml-cuda/cpy-utils.cuh +217 -0
- data/ext/sources/ggml/src/ggml-cuda/cpy.cu +335 -485
- data/ext/sources/ggml/src/ggml-cuda/cpy.cuh +1 -5
- data/ext/sources/ggml/src/ggml-cuda/cross-entropy-loss.cu +2 -14
- 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/dequantize.cuh +14 -40
- 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 +519 -378
- data/ext/sources/ggml/src/ggml-cuda/fattn-mma-f16.cuh +750 -637
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile.cu +49 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile.cuh +1244 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn-vec.cuh +586 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn-wmma-f16.cu +98 -61
- data/ext/sources/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +48 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn.cu +230 -197
- data/ext/sources/ggml/src/ggml-cuda/fattn.cuh +2 -0
- 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/getrows.cu +50 -39
- data/ext/sources/ggml/src/ggml-cuda/ggml-cuda.cu +1557 -294
- data/ext/sources/ggml/src/ggml-cuda/im2col.cu +196 -35
- data/ext/sources/ggml/src/ggml-cuda/im2col.cuh +1 -0
- data/ext/sources/ggml/src/ggml-cuda/mean.cu +57 -2
- data/ext/sources/ggml/src/ggml-cuda/mma.cuh +915 -69
- data/ext/sources/ggml/src/ggml-cuda/mmf.cu +171 -0
- data/ext/sources/ggml/src/ggml-cuda/mmf.cuh +835 -0
- 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 +109 -67
- data/ext/sources/ggml/src/ggml-cuda/mmq.cuh +1601 -733
- data/ext/sources/ggml/src/ggml-cuda/mmvf.cu +802 -0
- data/ext/sources/ggml/src/ggml-cuda/mmvf.cuh +12 -0
- data/ext/sources/ggml/src/ggml-cuda/mmvq.cu +286 -149
- data/ext/sources/ggml/src/ggml-cuda/mmvq.cuh +1 -1
- data/ext/sources/ggml/src/ggml-cuda/norm.cu +284 -12
- data/ext/sources/ggml/src/ggml-cuda/norm.cuh +7 -0
- data/ext/sources/ggml/src/ggml-cuda/opt-step-sgd.cu +49 -0
- data/ext/sources/ggml/src/ggml-cuda/opt-step-sgd.cuh +5 -0
- data/ext/sources/ggml/src/ggml-cuda/pad.cu +86 -32
- data/ext/sources/ggml/src/ggml-cuda/pad_reflect_1d.cu +91 -0
- data/ext/sources/ggml/src/ggml-cuda/pad_reflect_1d.cuh +5 -0
- data/ext/sources/ggml/src/ggml-cuda/quantize.cu +163 -10
- data/ext/sources/ggml/src/ggml-cuda/quantize.cuh +14 -0
- data/ext/sources/ggml/src/ggml-cuda/reduce_rows.cuh +53 -0
- data/ext/sources/ggml/src/ggml-cuda/roll.cu +67 -0
- data/ext/sources/ggml/src/ggml-cuda/roll.cuh +5 -0
- data/ext/sources/ggml/src/ggml-cuda/rope.cu +207 -98
- data/ext/sources/ggml/src/ggml-cuda/rope.cuh +2 -0
- data/ext/sources/ggml/src/ggml-cuda/scale.cu +14 -11
- data/ext/sources/ggml/src/ggml-cuda/set-rows.cu +330 -0
- data/ext/sources/ggml/src/ggml-cuda/set-rows.cuh +7 -0
- 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/softcap.cu +34 -0
- data/ext/sources/ggml/src/ggml-cuda/softcap.cuh +5 -0
- data/ext/sources/ggml/src/ggml-cuda/softmax.cu +325 -61
- 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 -12
- data/ext/sources/ggml/src/ggml-cuda/ssm-scan.cu +291 -104
- data/ext/sources/ggml/src/ggml-cuda/sum.cu +6 -10
- data/ext/sources/ggml/src/ggml-cuda/sumrows.cu +21 -4
- 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/fattn-vec-instance-f16-f16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q8_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-f16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q8_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-f16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q8_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-f16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q8_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-f16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q8_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-f16.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_1.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q8_0.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/generate_cu_files.py +40 -19
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_1.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_10.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_11.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_12.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_13.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_14.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_15.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_16.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_2.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_3.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_4.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_5.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_6.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_7.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_8.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_9.cu +5 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/mmq-instance-mxfp4.cu +5 -0
- 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 +351 -0
- data/ext/sources/ggml/src/ggml-cuda/topk-moe.cuh +21 -0
- 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/tsembd.cu +3 -3
- data/ext/sources/ggml/src/ggml-cuda/unary.cu +189 -5
- data/ext/sources/ggml/src/ggml-cuda/unary.cuh +44 -0
- data/ext/sources/ggml/src/ggml-cuda/upscale.cu +248 -6
- data/ext/sources/ggml/src/ggml-cuda/vecdotq.cuh +110 -22
- data/ext/sources/ggml/src/ggml-cuda/vendors/cuda.h +8 -0
- data/ext/sources/ggml/src/ggml-cuda/vendors/hip.h +70 -37
- data/ext/sources/ggml/src/ggml-cuda/vendors/musa.h +10 -3
- 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 +16 -13
- data/ext/sources/ggml/src/ggml-impl.h +186 -15
- data/ext/sources/ggml/src/ggml-metal/CMakeLists.txt +10 -7
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-common.cpp +446 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-common.h +52 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-context.h +33 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-context.m +609 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.cpp +1743 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.h +273 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.m +1686 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-impl.h +356 -61
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.cpp +4161 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.h +94 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.cpp +724 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.metal +4495 -1876
- data/ext/sources/ggml/src/ggml-musa/CMakeLists.txt +21 -9
- data/ext/sources/ggml/src/ggml-opencl/CMakeLists.txt +29 -0
- data/ext/sources/ggml/src/ggml-opencl/ggml-opencl.cpp +4005 -427
- data/ext/sources/ggml/src/ggml-opencl/kernels/add.cl +107 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/add_id.cl +42 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/conv2d.cl +185 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/conv2d_f16_f32.cl +176 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/cvt.cl +147 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/div.cl +66 -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_f16.cl +370 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32.cl +371 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32_f16.cl +373 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gelu.cl +27 -0
- 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/glu.cl +177 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/group_norm.cl +49 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/im2col_f16.cl +1 -1
- data/ext/sources/ggml/src/ggml-opencl/kernels/im2col_f32.cl +1 -1
- data/ext/sources/ggml/src/ggml-opencl/kernels/mean.cl +39 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul.cl +73 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mat_f16_f32.cl +130 -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 +146 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_f32_f32_l4_lm.cl +147 -0
- 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/mul_mv_id_mxfp4_f32.cl +189 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_id_mxfp4_f32_flat.cl +176 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_id_q8_0_f32.cl +140 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_id_q8_0_f32_flat.cl +222 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_mxfp4_f32.cl +144 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_mxfp4_f32_flat.cl +167 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q8_0_f32.cl +125 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q8_0_f32_flat.cl +202 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/norm.cl +80 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/pad.cl +29 -20
- data/ext/sources/ggml/src/ggml-opencl/kernels/rms_norm.cl +94 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/rope.cl +50 -24
- data/ext/sources/ggml/src/ggml-opencl/kernels/scale.cl +3 -2
- data/ext/sources/ggml/src/ggml-opencl/kernels/set_rows.cl +208 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/softmax_4_f16.cl +34 -13
- data/ext/sources/ggml/src/ggml-opencl/kernels/softmax_4_f32.cl +34 -13
- data/ext/sources/ggml/src/ggml-opencl/kernels/softmax_f16.cl +34 -13
- data/ext/sources/ggml/src/ggml-opencl/kernels/softmax_f32.cl +34 -13
- 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/sub.cl +66 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/transpose.cl +33 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/tsembd.cl +2 -2
- data/ext/sources/ggml/src/ggml-opencl/kernels/upscale.cl +2 -3
- data/ext/sources/ggml/src/ggml-opt.cpp +97 -41
- data/ext/sources/ggml/src/ggml-quants.c +111 -16
- data/ext/sources/ggml/src/ggml-quants.h +6 -0
- data/ext/sources/ggml/src/ggml-rpc/ggml-rpc.cpp +497 -195
- 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 +8 -0
- data/ext/sources/ggml/src/ggml-sycl/binbcast.cpp +6 -5
- data/ext/sources/ggml/src/ggml-sycl/common.hpp +117 -15
- data/ext/sources/ggml/src/ggml-sycl/concat.cpp +50 -30
- data/ext/sources/ggml/src/ggml-sycl/conv.cpp +10 -4
- data/ext/sources/ggml/src/ggml-sycl/convert.cpp +200 -99
- 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 +72 -309
- data/ext/sources/ggml/src/ggml-sycl/cpy.hpp +213 -1
- data/ext/sources/ggml/src/ggml-sycl/dequantize.hpp +18 -0
- data/ext/sources/ggml/src/ggml-sycl/dmmv.cpp +67 -49
- data/ext/sources/ggml/src/ggml-sycl/dpct/helper.hpp +77 -34
- data/ext/sources/ggml/src/ggml-sycl/element_wise.cpp +397 -314
- data/ext/sources/ggml/src/ggml-sycl/element_wise.hpp +12 -2
- data/ext/sources/ggml/src/ggml-sycl/gemm.hpp +14 -26
- data/ext/sources/ggml/src/ggml-sycl/getrows.cpp +9 -6
- data/ext/sources/ggml/src/ggml-sycl/ggml-sycl.cpp +643 -413
- data/ext/sources/ggml/src/ggml-sycl/gla.cpp +2 -2
- data/ext/sources/ggml/src/ggml-sycl/im2col.cpp +2 -2
- data/ext/sources/ggml/src/ggml-sycl/mmq.cpp +80 -60
- data/ext/sources/ggml/src/ggml-sycl/mmvq.cpp +223 -132
- data/ext/sources/ggml/src/ggml-sycl/norm.cpp +230 -55
- 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/quantize.hpp +133 -0
- data/ext/sources/ggml/src/ggml-sycl/quants.hpp +8 -9
- 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 +65 -59
- 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/set_rows.cpp +234 -0
- data/ext/sources/ggml/src/ggml-sycl/set_rows.hpp +8 -0
- data/ext/sources/ggml/src/ggml-sycl/softmax.cpp +330 -165
- 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/tsembd.cpp +12 -6
- data/ext/sources/ggml/src/ggml-sycl/vecdotq.hpp +60 -6
- data/ext/sources/ggml/src/ggml-sycl/wkv.cpp +16 -12
- data/ext/sources/ggml/src/ggml-vulkan/CMakeLists.txt +38 -18
- data/ext/sources/ggml/src/ggml-vulkan/ggml-vulkan.cpp +7398 -2635
- 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 +43 -3
- 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 +42 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/arange.comp +20 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/argmax.comp +15 -6
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/argsort.comp +56 -39
- 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 +347 -0
- 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 +5 -5
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp +67 -13
- 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} +158 -16
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{dequant_funcs_cm2.comp → dequant_funcs_cm2.glsl} +38 -3
- 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 +2 -2
- 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 +3 -2
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_s.comp +7 -6
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_xxs.comp +5 -3
- 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 +32 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q2_k.comp +4 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q3_k.comp +2 -2
- 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 +4 -4
- 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 +4 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q6_k.comp +2 -2
- 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 +21 -0
- 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 +103 -36
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_base.glsl +220 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +139 -45
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +113 -38
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_split_k_reduce.comp +75 -14
- 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 +27 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/geglu_quick.comp +11 -0
- 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 +39 -0
- 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} +19 -17
- 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 +21 -12
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/get_rows_quant.comp +28 -18
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/{glu_head.comp → glu_head.glsl} +4 -0
- 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 +22 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/hardswish.comp +22 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/im2col.comp +33 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/im2col_3d.comp +125 -0
- 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.glsl +227 -0
- 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 +20 -14
- 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 +143 -0
- 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 +144 -556
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +230 -51
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_funcs.glsl +566 -0
- 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 +90 -223
- 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 +195 -0
- 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 +22 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/pad.comp +41 -5
- 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 +59 -9
- 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 +104 -14
- 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 +65 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/roll.comp +46 -0
- 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 -52
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_neox.comp +6 -35
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_norm.comp +6 -35
- 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/rte.glsl +5 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/scale.comp +3 -3
- 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 +30 -8
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_back.comp +6 -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 +17 -0
- 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 +16 -6
- 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 +14 -0
- 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 +5 -4
- 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} +435 -24
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/upscale.comp +148 -6
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/utils.glsl +25 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +619 -177
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/xielu.comp +35 -0
- data/ext/sources/ggml/src/ggml-webgpu/CMakeLists.txt +80 -0
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp +169 -0
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu.cpp +3087 -0
- 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/binary_head.tmpl +45 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/common_decls.tmpl +930 -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 +147 -0
- 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 +874 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/glu.tmpl.wgsl +323 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/memset.wgsl +40 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat.tmpl.wgsl +907 -0
- 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 +123 -0
- 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/set_rows.wgsl +81 -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-zdnn/CMakeLists.txt +36 -0
- data/ext/sources/ggml/src/ggml-zdnn/common.hpp +59 -0
- data/ext/sources/ggml/src/ggml-zdnn/ggml-zdnn.cpp +628 -0
- data/ext/sources/ggml/src/ggml-zdnn/mmf.cpp +80 -0
- data/ext/sources/ggml/src/ggml-zdnn/mmf.hpp +12 -0
- data/ext/sources/ggml/src/ggml-zdnn/utils.cpp +79 -0
- data/ext/sources/ggml/src/ggml-zdnn/utils.hpp +19 -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 +901 -129
- data/ext/sources/ggml/src/gguf.cpp +8 -1
- data/ext/sources/include/whisper.h +1 -0
- data/ext/sources/src/CMakeLists.txt +3 -1
- data/ext/sources/src/whisper.cpp +124 -81
- data/ext/sources/tests/CMakeLists.txt +8 -1
- data/ext/sources/tests/test-vad-full.cpp +7 -5
- data/ext/sources/tests/test-vad.cpp +3 -3
- data/extsources.rb +1 -0
- data/lib/whisper/model/uri.rb +17 -18
- data/sig/whisper.rbs +126 -2
- data/test/test_params.rb +24 -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 +8 -1
- data/whispercpp.gemspec +1 -1
- metadata +439 -179
- data/ext/sources/build-xcframework.sh +0 -547
- data/ext/sources/examples/talk-llama/llama-kv-cache-unified-iswa.cpp +0 -279
- data/ext/sources/examples/talk-llama/llama-kv-cache-unified.cpp +0 -1841
- data/ext/sources/examples/talk-llama/llama-kv-cache-unified.h +0 -303
- data/ext/sources/ggml/include/ggml-kompute.h +0 -50
- data/ext/sources/ggml/src/ggml-amx/CMakeLists.txt +0 -107
- data/ext/sources/ggml/src/ggml-amx/common.h +0 -94
- data/ext/sources/ggml/src/ggml-amx/ggml-amx.cpp +0 -446
- data/ext/sources/ggml/src/ggml-amx/mmq.cpp +0 -2510
- data/ext/sources/ggml/src/ggml-amx/mmq.h +0 -17
- data/ext/sources/ggml/src/ggml-cann/Doxyfile +0 -2579
- data/ext/sources/ggml/src/ggml-cann/kernels/CMakeLists.txt +0 -30
- data/ext/sources/ggml/src/ggml-cann/kernels/ascendc_kernels.h +0 -19
- data/ext/sources/ggml/src/ggml-cann/kernels/dup.cpp +0 -234
- data/ext/sources/ggml/src/ggml-cann/kernels/get_row_f16.cpp +0 -197
- data/ext/sources/ggml/src/ggml-cann/kernels/get_row_f32.cpp +0 -190
- data/ext/sources/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp +0 -204
- data/ext/sources/ggml/src/ggml-cann/kernels/get_row_q8_0.cpp +0 -191
- data/ext/sources/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp +0 -218
- data/ext/sources/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp +0 -216
- data/ext/sources/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp +0 -295
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile-f16.cu +0 -357
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile-f16.cuh +0 -3
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile-f32.cu +0 -365
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile-f32.cuh +0 -3
- data/ext/sources/ggml/src/ggml-cuda/fattn-vec-f16.cuh +0 -482
- data/ext/sources/ggml/src/ggml-cuda/fattn-vec-f32.cuh +0 -472
- data/ext/sources/ggml/src/ggml-cuda/mmv.cu +0 -506
- data/ext/sources/ggml/src/ggml-cuda/mmv.cuh +0 -11
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs256-f16-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs256-f16-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-f16.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q4_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q4_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q5_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q5_1.cu +0 -5
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q8_0.cu +0 -5
- data/ext/sources/ggml/src/ggml-kompute/CMakeLists.txt +0 -166
- data/ext/sources/ggml/src/ggml-kompute/ggml-kompute.cpp +0 -2251
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/common.comp +0 -112
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_add.comp +0 -58
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_addrow.comp +0 -25
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f16.comp +0 -52
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f32.comp +0 -52
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f16.comp +0 -52
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f32.comp +0 -52
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_diagmask.comp +0 -30
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_gelu.comp +0 -22
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_getrows.comp +0 -17
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f16.comp +0 -31
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f32.comp +0 -31
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_0.comp +0 -38
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_1.comp +0 -39
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q6_k.comp +0 -44
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_mul.comp +0 -52
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_f16.comp +0 -69
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_mat_f32.comp +0 -51
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_0.comp +0 -33
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_1.comp +0 -35
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_k.comp +0 -140
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q6_k.comp +0 -106
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q8_0.comp +0 -73
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n.comp +0 -52
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n_pre.comp +0 -28
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_norm.comp +0 -84
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_relu.comp +0 -21
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_rmsnorm.comp +0 -53
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f16.comp +0 -52
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f32.comp +0 -52
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f16.comp +0 -52
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f32.comp +0 -52
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_scale.comp +0 -19
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_scale_8.comp +0 -23
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_silu.comp +0 -22
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/op_softmax.comp +0 -72
- data/ext/sources/ggml/src/ggml-kompute/kompute-shaders/rope_common.comp +0 -71
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.m +0 -6280
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_base.comp +0 -162
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_base.comp +0 -118
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.comp +0 -99
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/rope_head.comp +0 -58
- /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
|
@@ -0,0 +1,1686 @@
|
|
|
1
|
+
#import "ggml-metal-device.h"
|
|
2
|
+
|
|
3
|
+
#import "ggml-impl.h"
|
|
4
|
+
|
|
5
|
+
#include <Foundation/Foundation.h>
|
|
6
|
+
|
|
7
|
+
#include <Metal/Metal.h>
|
|
8
|
+
|
|
9
|
+
#include <stdatomic.h>
|
|
10
|
+
|
|
11
|
+
#ifndef TARGET_OS_VISION
|
|
12
|
+
#define TARGET_OS_VISION 0
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
// create residency sets only on macOS >= 15.0
|
|
16
|
+
#if !TARGET_CPU_X86_64 && TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 150000 || \
|
|
17
|
+
TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 180000 || \
|
|
18
|
+
TARGET_OS_TV && __TV_OS_VERSION_MAX_ALLOWED >= 180000 || \
|
|
19
|
+
TARGET_OS_VISION && __VISION_OS_VERSION_MAX_ALLOWED >= 200000
|
|
20
|
+
#define GGML_METAL_HAS_RESIDENCY_SETS 1
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
// overload of MTLGPUFamilyMetalX (not available in some environments)
|
|
24
|
+
static const NSInteger MTLGPUFamilyMetal3_GGML = 5001;
|
|
25
|
+
static const NSInteger MTLGPUFamilyMetal4_GGML = 5002;
|
|
26
|
+
|
|
27
|
+
// virtual address for GPU memory allocations
|
|
28
|
+
static atomic_uintptr_t g_addr_device = 0x000000400ULL;
|
|
29
|
+
|
|
30
|
+
#if !GGML_METAL_EMBED_LIBRARY
|
|
31
|
+
// Here to assist with NSBundle Path Hack
|
|
32
|
+
@interface GGMLMetalClass : NSObject
|
|
33
|
+
@end
|
|
34
|
+
@implementation GGMLMetalClass
|
|
35
|
+
@end
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
//
|
|
39
|
+
// MTLFunctionConstantValues wrapper
|
|
40
|
+
//
|
|
41
|
+
|
|
42
|
+
struct ggml_metal_cv {
|
|
43
|
+
MTLFunctionConstantValues * obj;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
ggml_metal_cv_t ggml_metal_cv_init(void) {
|
|
47
|
+
ggml_metal_cv_t res = calloc(1, sizeof(struct ggml_metal_cv));
|
|
48
|
+
|
|
49
|
+
res->obj = [[MTLFunctionConstantValues alloc] init];
|
|
50
|
+
|
|
51
|
+
return res;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void ggml_metal_cv_free(ggml_metal_cv_t cv) {
|
|
55
|
+
[cv->obj release];
|
|
56
|
+
free(cv);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void ggml_metal_cv_set_int16(ggml_metal_cv_t cv, int16_t value, int32_t idx) {
|
|
60
|
+
[cv->obj setConstantValue:&value type:MTLDataTypeShort atIndex:idx];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void ggml_metal_cv_set_int32(ggml_metal_cv_t cv, int32_t value, int32_t idx) {
|
|
64
|
+
[cv->obj setConstantValue:&value type:MTLDataTypeInt atIndex:idx];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
void ggml_metal_cv_set_bool(ggml_metal_cv_t cv, bool value, int32_t idx) {
|
|
68
|
+
[cv->obj setConstantValue:&value type:MTLDataTypeBool atIndex:idx];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//
|
|
72
|
+
// MTLComputePipelineState wrapper
|
|
73
|
+
//
|
|
74
|
+
|
|
75
|
+
struct ggml_metal_pipeline {
|
|
76
|
+
id<MTLComputePipelineState> obj;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
ggml_metal_pipeline_t ggml_metal_pipeline_init(void) {
|
|
80
|
+
ggml_metal_pipeline_t res = calloc(1, sizeof(struct ggml_metal_pipeline));
|
|
81
|
+
|
|
82
|
+
*res = (struct ggml_metal_pipeline) {
|
|
83
|
+
/*.obj =*/ nil,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return res;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
void ggml_metal_pipeline_free(ggml_metal_pipeline_t pipeline) {
|
|
90
|
+
[pipeline->obj release];
|
|
91
|
+
|
|
92
|
+
free(pipeline);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
int ggml_metal_pipeline_max_theads_per_threadgroup(struct ggml_metal_pipeline_with_params pipeline) {
|
|
96
|
+
return pipeline.pipeline->obj.maxTotalThreadsPerThreadgroup;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
struct ggml_metal_library {
|
|
100
|
+
id<MTLLibrary> obj;
|
|
101
|
+
id<MTLDevice> device;
|
|
102
|
+
|
|
103
|
+
ggml_metal_pipelines_t pipelines; // cache of compiled pipelines
|
|
104
|
+
|
|
105
|
+
NSLock * lock;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
ggml_metal_library_t ggml_metal_library_init(ggml_metal_device_t dev) {
|
|
109
|
+
id<MTLLibrary> library = nil;
|
|
110
|
+
id<MTLDevice> device = ggml_metal_device_get_obj(dev);
|
|
111
|
+
|
|
112
|
+
// load library
|
|
113
|
+
//
|
|
114
|
+
// - first check if the library is embedded
|
|
115
|
+
// - then check if the library is in the bundle
|
|
116
|
+
// - if not found, load the source and compile it
|
|
117
|
+
// - if that fails, return NULL
|
|
118
|
+
//
|
|
119
|
+
// TODO: move to a function
|
|
120
|
+
{
|
|
121
|
+
const int64_t t_start = ggml_time_us();
|
|
122
|
+
|
|
123
|
+
NSError * error = nil;
|
|
124
|
+
NSString * src = nil;
|
|
125
|
+
|
|
126
|
+
#if GGML_METAL_EMBED_LIBRARY
|
|
127
|
+
GGML_LOG_INFO("%s: using embedded metal library\n", __func__);
|
|
128
|
+
|
|
129
|
+
extern const char ggml_metallib_start[];
|
|
130
|
+
extern const char ggml_metallib_end[];
|
|
131
|
+
|
|
132
|
+
src = [[NSString alloc] initWithBytes:ggml_metallib_start length:(ggml_metallib_end-ggml_metallib_start) encoding:NSUTF8StringEncoding];
|
|
133
|
+
#else
|
|
134
|
+
|
|
135
|
+
#ifdef SWIFT_PACKAGE
|
|
136
|
+
NSBundle * bundle = SWIFTPM_MODULE_BUNDLE;
|
|
137
|
+
#else
|
|
138
|
+
NSBundle * bundle = [NSBundle bundleForClass:[GGMLMetalClass class]];
|
|
139
|
+
#endif
|
|
140
|
+
|
|
141
|
+
NSString * path_lib = [bundle pathForResource:@"default" ofType:@"metallib"];
|
|
142
|
+
if (path_lib == nil) {
|
|
143
|
+
// Try to find the resource in the directory where the current binary located.
|
|
144
|
+
NSString * bin_cur = [[NSProcessInfo processInfo] arguments][0];
|
|
145
|
+
NSString * bin_dir = [bin_cur stringByDeletingLastPathComponent];
|
|
146
|
+
|
|
147
|
+
NSString * path_lib_default = [NSString pathWithComponents:@[bin_dir, @"default.metallib"]];
|
|
148
|
+
if ([[NSFileManager defaultManager] isReadableFileAtPath:path_lib_default]) {
|
|
149
|
+
GGML_LOG_INFO("%s: found '%s'\n", __func__, [path_lib_default UTF8String]);
|
|
150
|
+
|
|
151
|
+
NSDictionary * atts = [[NSFileManager defaultManager] attributesOfItemAtPath:path_lib_default error:&error];
|
|
152
|
+
if (atts && atts[NSFileType] == NSFileTypeSymbolicLink) {
|
|
153
|
+
// Optionally, if this is a symlink, try to resolve it.
|
|
154
|
+
path_lib_default = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath:path_lib_default error:&error];
|
|
155
|
+
if (path_lib_default && [path_lib_default length] > 0 && ![[path_lib_default substringToIndex:1] isEqualToString:@"/"]) {
|
|
156
|
+
// It is a relative path, adding the binary directory as directory prefix.
|
|
157
|
+
path_lib_default = [NSString pathWithComponents:@[bin_dir, path_lib_default]];
|
|
158
|
+
}
|
|
159
|
+
if (!path_lib_default || ![[NSFileManager defaultManager] isReadableFileAtPath:path_lib_default]) {
|
|
160
|
+
// Link to the resource could not be resolved.
|
|
161
|
+
path_lib_default = nil;
|
|
162
|
+
} else {
|
|
163
|
+
GGML_LOG_INFO("%s: symlink resolved '%s'\n", __func__, [path_lib_default UTF8String]);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
// The resource couldn't be found in the binary's directory.
|
|
168
|
+
path_lib_default = nil;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
path_lib = path_lib_default;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (path_lib != nil) {
|
|
175
|
+
// pre-compiled library found
|
|
176
|
+
NSURL * libURL = [NSURL fileURLWithPath:path_lib];
|
|
177
|
+
GGML_LOG_INFO("%s: loading '%s'\n", __func__, [path_lib UTF8String]);
|
|
178
|
+
|
|
179
|
+
library = [device newLibraryWithURL:libURL error:&error];
|
|
180
|
+
if (error) {
|
|
181
|
+
GGML_LOG_ERROR("%s: error: %s\n", __func__, [[error description] UTF8String]);
|
|
182
|
+
return nil;
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
GGML_LOG_INFO("%s: default.metallib not found, loading from source\n", __func__);
|
|
186
|
+
|
|
187
|
+
NSString * path_source;
|
|
188
|
+
NSString * path_resource = [[NSProcessInfo processInfo].environment objectForKey:@"GGML_METAL_PATH_RESOURCES"];
|
|
189
|
+
|
|
190
|
+
GGML_LOG_INFO("%s: GGML_METAL_PATH_RESOURCES = %s\n", __func__, path_resource ? [path_resource UTF8String] : "nil");
|
|
191
|
+
|
|
192
|
+
if (path_resource) {
|
|
193
|
+
path_source = [path_resource stringByAppendingPathComponent:@"ggml-metal.metal"];
|
|
194
|
+
} else {
|
|
195
|
+
path_source = [bundle pathForResource:@"ggml-metal" ofType:@"metal"];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (path_source == nil) {
|
|
199
|
+
GGML_LOG_WARN("%s: error: could not use bundle path to find ggml-metal.metal, falling back to trying cwd\n", __func__);
|
|
200
|
+
path_source = @"ggml-metal.metal";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
GGML_LOG_INFO("%s: loading '%s'\n", __func__, [path_source UTF8String]);
|
|
204
|
+
|
|
205
|
+
src = [NSString stringWithContentsOfFile:path_source encoding:NSUTF8StringEncoding error:&error];
|
|
206
|
+
if (error) {
|
|
207
|
+
GGML_LOG_ERROR("%s: error: %s\n", __func__, [[error description] UTF8String]);
|
|
208
|
+
return nil;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
#endif
|
|
212
|
+
|
|
213
|
+
if (!library) {
|
|
214
|
+
@autoreleasepool {
|
|
215
|
+
// dictionary of preprocessor macros
|
|
216
|
+
NSMutableDictionary * prep = [NSMutableDictionary dictionary];
|
|
217
|
+
|
|
218
|
+
if (ggml_metal_device_get_props(dev)->has_bfloat) {
|
|
219
|
+
[prep setObject:@"1" forKey:@"GGML_METAL_HAS_BF16"];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (ggml_metal_device_get_props(dev)->has_tensor) {
|
|
223
|
+
[prep setObject:@"1" forKey:@"GGML_METAL_HAS_TENSOR"];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
#if GGML_METAL_EMBED_LIBRARY
|
|
227
|
+
[prep setObject:@"1" forKey:@"GGML_METAL_EMBED_LIBRARY"];
|
|
228
|
+
#endif
|
|
229
|
+
|
|
230
|
+
MTLCompileOptions * options = [MTLCompileOptions new];
|
|
231
|
+
options.preprocessorMacros = prep;
|
|
232
|
+
|
|
233
|
+
//[options setFastMathEnabled:false];
|
|
234
|
+
|
|
235
|
+
library = [device newLibraryWithSource:src options:options error:&error];
|
|
236
|
+
if (error) {
|
|
237
|
+
GGML_LOG_ERROR("%s: error: %s\n", __func__, [[error description] UTF8String]);
|
|
238
|
+
return nil;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
#if !__has_feature(objc_arc)
|
|
242
|
+
[options release];
|
|
243
|
+
#endif
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
#if GGML_METAL_EMBED_LIBRARY
|
|
248
|
+
[src release];
|
|
249
|
+
#endif // GGML_METAL_EMBED_LIBRARY
|
|
250
|
+
|
|
251
|
+
GGML_LOG_INFO("%s: loaded in %.3f sec\n", __func__, (ggml_time_us() - t_start) / 1e6);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
ggml_metal_library_t res = calloc(1, sizeof(struct ggml_metal_library));
|
|
255
|
+
|
|
256
|
+
res->obj = library;
|
|
257
|
+
res->device = device;
|
|
258
|
+
res->pipelines = ggml_metal_pipelines_init();
|
|
259
|
+
res->lock = [NSLock new];
|
|
260
|
+
|
|
261
|
+
return res;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
ggml_metal_library_t ggml_metal_library_init_from_source(ggml_metal_device_t dev, const char * source, bool verbose) {
|
|
265
|
+
if (source == NULL) {
|
|
266
|
+
GGML_LOG_ERROR("%s: source is NULL\n", __func__);
|
|
267
|
+
return NULL;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
id<MTLDevice> device = ggml_metal_device_get_obj(dev);
|
|
271
|
+
id<MTLLibrary> library = nil;
|
|
272
|
+
NSError * error = nil;
|
|
273
|
+
|
|
274
|
+
const int64_t t_start = ggml_time_us();
|
|
275
|
+
|
|
276
|
+
NSString * src = [[NSString alloc] initWithBytes:source
|
|
277
|
+
length:strlen(source)
|
|
278
|
+
encoding:NSUTF8StringEncoding];
|
|
279
|
+
if (!src) {
|
|
280
|
+
GGML_LOG_ERROR("%s: failed to create NSString from source\n", __func__);
|
|
281
|
+
return NULL;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
@autoreleasepool {
|
|
285
|
+
NSMutableDictionary * prep = [NSMutableDictionary dictionary];
|
|
286
|
+
|
|
287
|
+
MTLCompileOptions * options = [MTLCompileOptions new];
|
|
288
|
+
options.preprocessorMacros = prep;
|
|
289
|
+
|
|
290
|
+
library = [device newLibraryWithSource:src options:options error:&error];
|
|
291
|
+
if (error) {
|
|
292
|
+
if (verbose) {
|
|
293
|
+
GGML_LOG_ERROR("%s: error compiling source: %s\n", __func__, [[error description] UTF8String]);
|
|
294
|
+
} else {
|
|
295
|
+
GGML_LOG_ERROR("%s: error compiling source\n", __func__);
|
|
296
|
+
}
|
|
297
|
+
library = nil;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
[options release];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
[src release];
|
|
304
|
+
|
|
305
|
+
if (!library) {
|
|
306
|
+
if (verbose) {
|
|
307
|
+
GGML_LOG_ERROR("%s: failed to create Metal library from source\n", __func__);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return NULL;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (verbose) {
|
|
314
|
+
GGML_LOG_INFO("%s: compiled in %.3f sec\n", __func__, (ggml_time_us() - t_start) / 1e6);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
ggml_metal_library_t res = calloc(1, sizeof(struct ggml_metal_library));
|
|
318
|
+
if (!res) {
|
|
319
|
+
GGML_LOG_ERROR("%s: calloc failed\n", __func__);
|
|
320
|
+
return NULL;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
res->obj = library;
|
|
324
|
+
res->device = device;
|
|
325
|
+
res->pipelines = ggml_metal_pipelines_init();
|
|
326
|
+
res->lock = [NSLock new];
|
|
327
|
+
|
|
328
|
+
return res;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
void ggml_metal_library_free(ggml_metal_library_t lib) {
|
|
332
|
+
if (!lib) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (lib->obj) {
|
|
337
|
+
[lib->obj release];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
ggml_metal_pipelines_free(lib->pipelines);
|
|
341
|
+
|
|
342
|
+
[lib->lock release];
|
|
343
|
+
|
|
344
|
+
free(lib);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline(ggml_metal_library_t lib, const char * name) {
|
|
348
|
+
[lib->lock lock];
|
|
349
|
+
|
|
350
|
+
struct ggml_metal_pipeline_with_params res = {
|
|
351
|
+
/*.pipeline =*/ nil,
|
|
352
|
+
/*.nr0 =*/ 0,
|
|
353
|
+
/*.nr1 =*/ 0,
|
|
354
|
+
/*.nsg =*/ 0,
|
|
355
|
+
/*.smem =*/ 0,
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
res.pipeline = ggml_metal_pipelines_get(lib->pipelines, name);
|
|
359
|
+
|
|
360
|
+
[lib->lock unlock];
|
|
361
|
+
|
|
362
|
+
return res;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
struct ggml_metal_pipeline_with_params ggml_metal_library_compile_pipeline(ggml_metal_library_t lib, const char * base, const char * name, ggml_metal_cv_t cv) {
|
|
366
|
+
struct ggml_metal_pipeline_with_params res = {
|
|
367
|
+
/*.pipeline =*/ nil,
|
|
368
|
+
/*.nr0 =*/ 0,
|
|
369
|
+
/*.nr1 =*/ 0,
|
|
370
|
+
/*.nsg =*/ 0,
|
|
371
|
+
/*.smem =*/ 0,
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
[lib->lock lock];
|
|
375
|
+
|
|
376
|
+
res.pipeline = ggml_metal_pipelines_get(lib->pipelines, name);
|
|
377
|
+
if (res.pipeline) {
|
|
378
|
+
[lib->lock unlock];
|
|
379
|
+
|
|
380
|
+
return res;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
@autoreleasepool {
|
|
384
|
+
NSError * error = nil;
|
|
385
|
+
|
|
386
|
+
NSString * base_func = [NSString stringWithUTF8String:base];
|
|
387
|
+
|
|
388
|
+
GGML_LOG_DEBUG("%s: compiling pipeline: base = '%s', name = '%s'\n", __func__, base, name);
|
|
389
|
+
|
|
390
|
+
id<MTLFunction> mtl_function;
|
|
391
|
+
if (!cv) {
|
|
392
|
+
mtl_function = [lib->obj newFunctionWithName:base_func];
|
|
393
|
+
} else {
|
|
394
|
+
mtl_function = [lib->obj newFunctionWithName:base_func constantValues:cv->obj error:&error];
|
|
395
|
+
}
|
|
396
|
+
if (!mtl_function) {
|
|
397
|
+
[lib->lock unlock];
|
|
398
|
+
|
|
399
|
+
GGML_LOG_ERROR("%s: failed to compile pipeline: base = '%s', name = '%s'\n", __func__, base, name);
|
|
400
|
+
if (error) {
|
|
401
|
+
GGML_LOG_ERROR("%s: %s\n", __func__, [[error description] UTF8String]);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return res;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
id<MTLComputePipelineState> obj = [lib->device newComputePipelineStateWithFunction:mtl_function error:&error];
|
|
408
|
+
|
|
409
|
+
[mtl_function release];
|
|
410
|
+
|
|
411
|
+
if (!obj) {
|
|
412
|
+
[lib->lock unlock];
|
|
413
|
+
|
|
414
|
+
GGML_LOG_ERROR("%s: failed to create pipeline state: base = '%s', name = '%s'\n", __func__, base, name);
|
|
415
|
+
if (error) {
|
|
416
|
+
GGML_LOG_ERROR("%s: %s\n", __func__, [[error description] UTF8String]);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return res;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
GGML_LOG_DEBUG("%s: loaded %-40s %16p | th_max = %4d | th_width = %4d\n", __func__, name,
|
|
423
|
+
(void *) obj,
|
|
424
|
+
(int) obj.maxTotalThreadsPerThreadgroup,
|
|
425
|
+
(int) obj.threadExecutionWidth);
|
|
426
|
+
|
|
427
|
+
if (obj.maxTotalThreadsPerThreadgroup == 0 || obj.threadExecutionWidth == 0) {
|
|
428
|
+
[obj release];
|
|
429
|
+
|
|
430
|
+
[lib->lock unlock];
|
|
431
|
+
|
|
432
|
+
GGML_LOG_ERROR("%s: incompatible pipeline %s\n", __func__, name);
|
|
433
|
+
|
|
434
|
+
return res;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
res.pipeline = ggml_metal_pipeline_init();
|
|
438
|
+
res.pipeline->obj = obj;
|
|
439
|
+
|
|
440
|
+
ggml_metal_pipelines_add(lib->pipelines, name, res.pipeline);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
[lib->lock unlock];
|
|
444
|
+
|
|
445
|
+
return res;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
//
|
|
449
|
+
// MTLComputeCommandEncoder wrapper
|
|
450
|
+
//
|
|
451
|
+
|
|
452
|
+
struct ggml_metal_encoder {
|
|
453
|
+
id<MTLComputeCommandEncoder> obj;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
ggml_metal_encoder_t ggml_metal_encoder_init(ggml_metal_cmd_buf_t cmd_buf_raw, bool concurrent) {
|
|
457
|
+
ggml_metal_encoder_t res = calloc(1, sizeof(struct ggml_metal_encoder));
|
|
458
|
+
|
|
459
|
+
id<MTLCommandBuffer> cmd_buf = (id<MTLCommandBuffer>) cmd_buf_raw;
|
|
460
|
+
|
|
461
|
+
if (concurrent) {
|
|
462
|
+
res->obj = [cmd_buf computeCommandEncoderWithDispatchType: MTLDispatchTypeConcurrent];
|
|
463
|
+
} else {
|
|
464
|
+
res->obj = [cmd_buf computeCommandEncoder];
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
[res->obj retain];
|
|
468
|
+
|
|
469
|
+
return res;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
void ggml_metal_encoder_free(ggml_metal_encoder_t encoder) {
|
|
473
|
+
[encoder->obj release];
|
|
474
|
+
free(encoder);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
void ggml_metal_encoder_debug_group_push(ggml_metal_encoder_t encoder, const char * name) {
|
|
478
|
+
[encoder->obj pushDebugGroup:[NSString stringWithCString:name encoding:NSUTF8StringEncoding]];
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
void ggml_metal_encoder_debug_group_pop (ggml_metal_encoder_t encoder) {
|
|
482
|
+
[encoder->obj popDebugGroup];
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
void ggml_metal_encoder_set_pipeline(ggml_metal_encoder_t encoder, struct ggml_metal_pipeline_with_params pipeline) {
|
|
486
|
+
[encoder->obj setComputePipelineState:pipeline.pipeline->obj];
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
void ggml_metal_encoder_set_bytes(ggml_metal_encoder_t encoder, void * data, size_t size, int idx) {
|
|
490
|
+
[encoder->obj setBytes:data length:size atIndex:idx];
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
void ggml_metal_encoder_set_buffer(ggml_metal_encoder_t encoder, struct ggml_metal_buffer_id buffer, int idx) {
|
|
494
|
+
[encoder->obj setBuffer:buffer.metal offset:buffer.offs atIndex:idx];
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
void ggml_metal_encoder_set_threadgroup_memory_size(ggml_metal_encoder_t encoder, size_t size, int idx) {
|
|
498
|
+
[encoder->obj setThreadgroupMemoryLength:size atIndex:idx];
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
void ggml_metal_encoder_dispatch_threadgroups(ggml_metal_encoder_t encoder, int tg0, int tg1, int tg2, int tptg0, int tptg1, int tptg2) {
|
|
502
|
+
[encoder->obj dispatchThreadgroups:MTLSizeMake(tg0, tg1, tg2) threadsPerThreadgroup:MTLSizeMake(tptg0, tptg1, tptg2)];
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
void ggml_metal_encoder_memory_barrier(ggml_metal_encoder_t encoder) {
|
|
506
|
+
[encoder->obj memoryBarrierWithScope:MTLBarrierScopeBuffers];
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
void ggml_metal_encoder_end_encoding(ggml_metal_encoder_t encoder) {
|
|
510
|
+
[encoder->obj endEncoding];
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
struct ggml_metal_device {
|
|
514
|
+
id<MTLDevice> mtl_device;
|
|
515
|
+
|
|
516
|
+
// a single global queue shared by all Metal backends
|
|
517
|
+
// technically not needed for devices with unified memory, but enables discrete GPUs support
|
|
518
|
+
// ref: https://github.com/ggml-org/llama.cpp/pull/15906
|
|
519
|
+
id<MTLCommandQueue> mtl_queue;
|
|
520
|
+
|
|
521
|
+
ggml_metal_rsets_t rsets;
|
|
522
|
+
|
|
523
|
+
ggml_metal_library_t library;
|
|
524
|
+
|
|
525
|
+
struct ggml_metal_device_props props;
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
//
|
|
529
|
+
// MTLResidenceSet wrapper
|
|
530
|
+
//
|
|
531
|
+
|
|
532
|
+
struct ggml_metal_rsets {
|
|
533
|
+
NSLock * lock;
|
|
534
|
+
|
|
535
|
+
NSMutableArray * data;
|
|
536
|
+
|
|
537
|
+
// number of seconds since the last graph computation
|
|
538
|
+
// keep the residency sets wired for that amount of time to avoid being collected by the OS
|
|
539
|
+
int keep_alive_s;
|
|
540
|
+
|
|
541
|
+
// background heartbeat thread to keep the residency sets alive
|
|
542
|
+
atomic_bool d_stop;
|
|
543
|
+
atomic_int d_loop;
|
|
544
|
+
|
|
545
|
+
dispatch_group_t d_group;
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
ggml_metal_rsets_t ggml_metal_rsets_init(void) {
|
|
549
|
+
ggml_metal_rsets_t res = calloc(1, sizeof(struct ggml_metal_rsets));
|
|
550
|
+
|
|
551
|
+
res->lock = [[NSLock alloc] init];
|
|
552
|
+
res->data = [[NSMutableArray alloc] init];
|
|
553
|
+
|
|
554
|
+
// by default keep the memory wired for 3 minutes
|
|
555
|
+
res->keep_alive_s = 3*60;
|
|
556
|
+
|
|
557
|
+
const char * GGML_METAL_RESIDENCY_KEEP_ALIVE_S = getenv("GGML_METAL_RESIDENCY_KEEP_ALIVE_S");
|
|
558
|
+
if (GGML_METAL_RESIDENCY_KEEP_ALIVE_S) {
|
|
559
|
+
res->keep_alive_s = atoi(GGML_METAL_RESIDENCY_KEEP_ALIVE_S);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (res->keep_alive_s <= 0) {
|
|
563
|
+
res->keep_alive_s = 3*60;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
GGML_LOG_INFO("%s: creating a residency set collection (keep_alive = %d s)\n", __func__, res->keep_alive_s);
|
|
567
|
+
|
|
568
|
+
atomic_store_explicit(&res->d_stop, false, memory_order_relaxed);
|
|
569
|
+
atomic_store_explicit(&res->d_loop, 2*res->keep_alive_s, memory_order_relaxed);
|
|
570
|
+
|
|
571
|
+
res->d_group = dispatch_group_create();
|
|
572
|
+
|
|
573
|
+
// start a background thread that periodically requests residency for all the currently active sets in the collection
|
|
574
|
+
// the requests stop after a certain amount of time (keep_alive_s) of inactivity
|
|
575
|
+
dispatch_queue_t d_queue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0);
|
|
576
|
+
dispatch_group_async(res->d_group, d_queue, ^{
|
|
577
|
+
#if defined(GGML_METAL_HAS_RESIDENCY_SETS)
|
|
578
|
+
if (@available(macOS 15.0, iOS 18.0, tvOS 18.0, visionOS 2.0, *)) {
|
|
579
|
+
while (!atomic_load_explicit(&res->d_stop, memory_order_relaxed)) {
|
|
580
|
+
if (atomic_load_explicit(&res->d_loop, memory_order_relaxed) > 0) {
|
|
581
|
+
[res->lock lock];
|
|
582
|
+
|
|
583
|
+
for (int i = 0; i < (int) res->data.count; ++i) {
|
|
584
|
+
[res->data[i] requestResidency];
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
atomic_fetch_sub_explicit(&res->d_loop, 1, memory_order_relaxed);
|
|
588
|
+
|
|
589
|
+
[res->lock unlock];
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// half a second
|
|
593
|
+
usleep(500 * 1000);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
#endif
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
return res;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
void ggml_metal_rsets_free(ggml_metal_rsets_t rsets) {
|
|
603
|
+
if (rsets == NULL) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// note: if you hit this assert, most likely you haven't deallocated all Metal resources before exiting
|
|
608
|
+
GGML_ASSERT([rsets->data count] == 0);
|
|
609
|
+
|
|
610
|
+
atomic_store_explicit(&rsets->d_stop, true, memory_order_relaxed);
|
|
611
|
+
|
|
612
|
+
dispatch_group_wait(rsets->d_group, DISPATCH_TIME_FOREVER);
|
|
613
|
+
dispatch_release(rsets->d_group);
|
|
614
|
+
|
|
615
|
+
[rsets->data release];
|
|
616
|
+
[rsets->lock release];
|
|
617
|
+
|
|
618
|
+
free(rsets);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
ggml_metal_device_t ggml_metal_device_init(void) {
|
|
622
|
+
ggml_metal_device_t dev = calloc(1, sizeof(struct ggml_metal_device));
|
|
623
|
+
|
|
624
|
+
assert(dev != NULL);
|
|
625
|
+
|
|
626
|
+
if (dev->mtl_device == nil) {
|
|
627
|
+
dev->mtl_device = MTLCreateSystemDefaultDevice();
|
|
628
|
+
|
|
629
|
+
if (dev->mtl_device) {
|
|
630
|
+
dev->mtl_queue = [dev->mtl_device newCommandQueue];
|
|
631
|
+
if (dev->mtl_queue == nil) {
|
|
632
|
+
GGML_LOG_ERROR("%s: error: failed to create command queue\n", __func__);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
dev->props.has_simdgroup_reduction = [dev->mtl_device supportsFamily:MTLGPUFamilyApple7];
|
|
636
|
+
dev->props.has_simdgroup_reduction |= [dev->mtl_device supportsFamily:MTLGPUFamilyMetal3_GGML];
|
|
637
|
+
|
|
638
|
+
dev->props.has_simdgroup_mm = [dev->mtl_device supportsFamily:MTLGPUFamilyApple7];
|
|
639
|
+
dev->props.has_unified_memory = dev->mtl_device.hasUnifiedMemory;
|
|
640
|
+
|
|
641
|
+
dev->props.has_bfloat = [dev->mtl_device supportsFamily:MTLGPUFamilyMetal3_GGML];
|
|
642
|
+
dev->props.has_bfloat |= [dev->mtl_device supportsFamily:MTLGPUFamilyApple6];
|
|
643
|
+
if (getenv("GGML_METAL_BF16_DISABLE") != NULL) {
|
|
644
|
+
dev->props.has_bfloat = false;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
dev->props.has_tensor = [dev->mtl_device supportsFamily:MTLGPUFamilyMetal4_GGML];
|
|
648
|
+
if (getenv("GGML_METAL_TENSOR_DISABLE") != NULL) {
|
|
649
|
+
dev->props.has_tensor = false;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// note: disable the tensor API by default for old chips because with the current implementation it is not useful
|
|
653
|
+
// - M2 Ultra: ~5% slower
|
|
654
|
+
// - M4, M4 Max: no significant difference
|
|
655
|
+
//
|
|
656
|
+
// TODO: try to update the tensor API kernels to at least match the simdgroup performance
|
|
657
|
+
if (getenv("GGML_METAL_TENSOR_ENABLE") == NULL &&
|
|
658
|
+
![[dev->mtl_device name] containsString:@"M5"] &&
|
|
659
|
+
![[dev->mtl_device name] containsString:@"M6"] &&
|
|
660
|
+
![[dev->mtl_device name] containsString:@"A19"] &&
|
|
661
|
+
![[dev->mtl_device name] containsString:@"A20"]) {
|
|
662
|
+
GGML_LOG_WARN("%s: tensor API disabled for pre-M5 and pre-A19 devices\n", __func__);
|
|
663
|
+
dev->props.has_tensor = false;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// double-check that the tensor API compiles
|
|
667
|
+
if (dev->props.has_tensor) {
|
|
668
|
+
const char * src_tensor_f16 = "\n"
|
|
669
|
+
"#include <metal_stdlib> \n"
|
|
670
|
+
"#include <metal_tensor> \n"
|
|
671
|
+
"#include <MetalPerformancePrimitives/MetalPerformancePrimitives.h> \n"
|
|
672
|
+
" \n"
|
|
673
|
+
"using namespace metal; \n"
|
|
674
|
+
"using namespace mpp::tensor_ops; \n"
|
|
675
|
+
" \n"
|
|
676
|
+
"kernel void dummy_kernel( \n"
|
|
677
|
+
" tensor<device half, dextents<int32_t, 2>> A [[buffer(0)]], \n"
|
|
678
|
+
" tensor<device half, dextents<int32_t, 2>> B [[buffer(1)]], \n"
|
|
679
|
+
" device float * C [[buffer(2)]], \n"
|
|
680
|
+
" uint2 tgid [[threadgroup_position_in_grid]]) \n"
|
|
681
|
+
"{ \n"
|
|
682
|
+
" auto tA = A.slice(0, (int)tgid.y); \n"
|
|
683
|
+
" auto tB = B.slice((int)tgid.x, 0); \n"
|
|
684
|
+
" \n"
|
|
685
|
+
" matmul2d< \n"
|
|
686
|
+
" matmul2d_descriptor(8, 8, dynamic_extent), \n"
|
|
687
|
+
" execution_simdgroups<4>> mm; \n"
|
|
688
|
+
" \n"
|
|
689
|
+
" auto cT = mm.get_destination_cooperative_tensor<decltype(tA), decltype(tB), float>(); \n"
|
|
690
|
+
" \n"
|
|
691
|
+
" auto sA = tA.slice(0, 0); \n"
|
|
692
|
+
" auto sB = tB.slice(0, 0); \n"
|
|
693
|
+
" mm.run(sB, sA, cT); \n"
|
|
694
|
+
" \n"
|
|
695
|
+
" auto tC = tensor<device float, dextents<int32_t, 2>, tensor_inline>(C, dextents<int32_t, 2>(4, 4)); \n"
|
|
696
|
+
" \n"
|
|
697
|
+
" cT.store(tC); \n"
|
|
698
|
+
"}";
|
|
699
|
+
|
|
700
|
+
GGML_LOG_INFO("%s: testing tensor API for f16 support\n", __func__);
|
|
701
|
+
ggml_metal_library_t lib = ggml_metal_library_init_from_source(dev, src_tensor_f16, false);
|
|
702
|
+
if (lib == NULL) {
|
|
703
|
+
GGML_LOG_WARN("%s: - the tensor API is not supported in this environment - disabling\n", __func__);
|
|
704
|
+
dev->props.has_tensor = false;
|
|
705
|
+
} else {
|
|
706
|
+
struct ggml_metal_pipeline_with_params ppl = ggml_metal_library_compile_pipeline(lib, "dummy_kernel", "dummy_kernel", nil);
|
|
707
|
+
if (!ppl.pipeline) {
|
|
708
|
+
GGML_LOG_WARN("%s: - the tensor API is not supported in this environment - disabling\n", __func__);
|
|
709
|
+
dev->props.has_tensor = false;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
ggml_metal_library_free(lib);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// try to compile a dummy kernel to determine if the tensor API is supported for bfloat
|
|
717
|
+
if (dev->props.has_tensor && dev->props.has_bfloat) {
|
|
718
|
+
const char * src_tensor_bf16 = "\n"
|
|
719
|
+
"#include <metal_stdlib> \n"
|
|
720
|
+
"#include <metal_tensor> \n"
|
|
721
|
+
"#include <MetalPerformancePrimitives/MetalPerformancePrimitives.h> \n"
|
|
722
|
+
" \n"
|
|
723
|
+
"using namespace metal; \n"
|
|
724
|
+
"using namespace mpp::tensor_ops; \n"
|
|
725
|
+
" \n"
|
|
726
|
+
"kernel void dummy_kernel( \n"
|
|
727
|
+
" tensor<device bfloat, dextents<int32_t, 2>> A [[buffer(0)]], \n"
|
|
728
|
+
" tensor<device bfloat, dextents<int32_t, 2>> B [[buffer(1)]], \n"
|
|
729
|
+
" device float * C [[buffer(2)]], \n"
|
|
730
|
+
" uint2 tgid [[threadgroup_position_in_grid]]) \n"
|
|
731
|
+
"{ \n"
|
|
732
|
+
" auto tA = A.slice(0, (int)tgid.y); \n"
|
|
733
|
+
" auto tB = B.slice((int)tgid.x, 0); \n"
|
|
734
|
+
" \n"
|
|
735
|
+
" matmul2d< \n"
|
|
736
|
+
" matmul2d_descriptor(8, 8, dynamic_extent), \n"
|
|
737
|
+
" execution_simdgroups<4>> mm; \n"
|
|
738
|
+
" \n"
|
|
739
|
+
" auto cT = mm.get_destination_cooperative_tensor<decltype(tA), decltype(tB), float>(); \n"
|
|
740
|
+
" \n"
|
|
741
|
+
" auto sA = tA.slice(0, 0); \n"
|
|
742
|
+
" auto sB = tB.slice(0, 0); \n"
|
|
743
|
+
" mm.run(sB, sA, cT); \n"
|
|
744
|
+
" \n"
|
|
745
|
+
" auto tC = tensor<device float, dextents<int32_t, 2>, tensor_inline>(C, dextents<int32_t, 2>(4, 4)); \n"
|
|
746
|
+
" \n"
|
|
747
|
+
" cT.store(tC); \n"
|
|
748
|
+
"}";
|
|
749
|
+
|
|
750
|
+
GGML_LOG_INFO("%s: testing tensor API for bfloat support\n", __func__);
|
|
751
|
+
ggml_metal_library_t lib = ggml_metal_library_init_from_source(dev, src_tensor_bf16, false);
|
|
752
|
+
if (lib == NULL) {
|
|
753
|
+
GGML_LOG_WARN("%s: - the tensor API does not support bfloat - disabling bfloat support\n", __func__);
|
|
754
|
+
dev->props.has_bfloat = false;
|
|
755
|
+
} else {
|
|
756
|
+
struct ggml_metal_pipeline_with_params ppl = ggml_metal_library_compile_pipeline(lib, "dummy_kernel", "dummy_kernel", nil);
|
|
757
|
+
if (!ppl.pipeline) {
|
|
758
|
+
GGML_LOG_WARN("%s: - the tensor API does not support bfloat - disabling bfloat support\n", __func__);
|
|
759
|
+
dev->props.has_bfloat = false;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
ggml_metal_library_free(lib);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
dev->props.use_residency_sets = true;
|
|
767
|
+
#if defined(GGML_METAL_HAS_RESIDENCY_SETS)
|
|
768
|
+
dev->props.use_residency_sets = getenv("GGML_METAL_NO_RESIDENCY") == nil;
|
|
769
|
+
#endif
|
|
770
|
+
|
|
771
|
+
dev->props.use_shared_buffers = dev->props.has_unified_memory;
|
|
772
|
+
#if TARGET_OS_OSX
|
|
773
|
+
// In case of eGPU, shared memory may be preferable.
|
|
774
|
+
dev->props.use_shared_buffers |= [dev->mtl_device location] == MTLDeviceLocationExternal;
|
|
775
|
+
#endif
|
|
776
|
+
if (getenv("GGML_METAL_SHARED_BUFFERS_DISABLE") != NULL) {
|
|
777
|
+
dev->props.use_shared_buffers = false;
|
|
778
|
+
}
|
|
779
|
+
if (getenv("GGML_METAL_SHARED_BUFFERS_ENABLE") != NULL) {
|
|
780
|
+
dev->props.use_shared_buffers = true;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
dev->props.supports_gpu_family_apple7 = [dev->mtl_device supportsFamily:MTLGPUFamilyApple7];
|
|
784
|
+
|
|
785
|
+
dev->props.op_offload_min_batch_size = getenv("GGML_OP_OFFLOAD_MIN_BATCH") ? atoi(getenv("GGML_OP_OFFLOAD_MIN_BATCH")) : 32;
|
|
786
|
+
|
|
787
|
+
dev->props.max_buffer_size = dev->mtl_device.maxBufferLength;
|
|
788
|
+
dev->props.max_working_set_size = dev->mtl_device.recommendedMaxWorkingSetSize;
|
|
789
|
+
dev->props.max_theadgroup_memory_size = dev->mtl_device.maxThreadgroupMemoryLength;
|
|
790
|
+
|
|
791
|
+
strncpy(dev->props.name, [[dev->mtl_device name] UTF8String], sizeof(dev->props.name) - 1);
|
|
792
|
+
|
|
793
|
+
dev->library = ggml_metal_library_init(dev);
|
|
794
|
+
if (!dev->library) {
|
|
795
|
+
GGML_LOG_ERROR("%s: error: failed to create library\n", __func__);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if (dev->props.use_residency_sets) {
|
|
799
|
+
dev->rsets = ggml_metal_rsets_init();
|
|
800
|
+
} else {
|
|
801
|
+
dev->rsets = nil;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// print MTL GPU family:
|
|
805
|
+
GGML_LOG_INFO("%s: GPU name: %s\n", __func__, dev->props.name);
|
|
806
|
+
|
|
807
|
+
// determine max supported GPU family
|
|
808
|
+
// https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf
|
|
809
|
+
// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
|
|
810
|
+
{
|
|
811
|
+
for (int i = MTLGPUFamilyApple1 + 20; i >= MTLGPUFamilyApple1; --i) {
|
|
812
|
+
if ([dev->mtl_device supportsFamily:i]) {
|
|
813
|
+
GGML_LOG_INFO("%s: GPU family: MTLGPUFamilyApple%d (%d)\n", __func__, i - (int) MTLGPUFamilyApple1 + 1, i);
|
|
814
|
+
break;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
for (int i = MTLGPUFamilyCommon1 + 5; i >= MTLGPUFamilyCommon1; --i) {
|
|
819
|
+
if ([dev->mtl_device supportsFamily:i]) {
|
|
820
|
+
GGML_LOG_INFO("%s: GPU family: MTLGPUFamilyCommon%d (%d)\n", __func__, i - (int) MTLGPUFamilyCommon1 + 1, i);
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
for (int i = MTLGPUFamilyMetal3_GGML + 5; i >= MTLGPUFamilyMetal3_GGML; --i) {
|
|
826
|
+
if ([dev->mtl_device supportsFamily:i]) {
|
|
827
|
+
GGML_LOG_INFO("%s: GPU family: MTLGPUFamilyMetal%d (%d)\n", __func__, i - (int) MTLGPUFamilyMetal3_GGML + 3, i);
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
GGML_LOG_INFO("%s: simdgroup reduction = %s\n", __func__, dev->props.has_simdgroup_reduction ? "true" : "false");
|
|
834
|
+
GGML_LOG_INFO("%s: simdgroup matrix mul. = %s\n", __func__, dev->props.has_simdgroup_mm ? "true" : "false");
|
|
835
|
+
GGML_LOG_INFO("%s: has unified memory = %s\n", __func__, dev->props.has_unified_memory ? "true" : "false");
|
|
836
|
+
GGML_LOG_INFO("%s: has bfloat = %s\n", __func__, dev->props.has_bfloat ? "true" : "false");
|
|
837
|
+
GGML_LOG_INFO("%s: has tensor = %s\n", __func__, dev->props.has_tensor ? "true" : "false");
|
|
838
|
+
GGML_LOG_INFO("%s: use residency sets = %s\n", __func__, dev->props.use_residency_sets ? "true" : "false");
|
|
839
|
+
GGML_LOG_INFO("%s: use shared buffers = %s\n", __func__, dev->props.use_shared_buffers ? "true" : "false");
|
|
840
|
+
|
|
841
|
+
#if TARGET_OS_OSX || (TARGET_OS_IOS && __clang_major__ >= 15)
|
|
842
|
+
if (@available(macOS 10.12, iOS 16.0, *)) {
|
|
843
|
+
GGML_LOG_INFO("%s: recommendedMaxWorkingSetSize = %8.2f MB\n", __func__, dev->props.max_working_set_size / 1e6);
|
|
844
|
+
}
|
|
845
|
+
#endif
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
return dev;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
void ggml_metal_device_free(ggml_metal_device_t dev) {
|
|
853
|
+
assert(dev != NULL);
|
|
854
|
+
|
|
855
|
+
ggml_metal_rsets_free(dev->rsets);
|
|
856
|
+
|
|
857
|
+
ggml_metal_library_free(dev->library);
|
|
858
|
+
dev->library = NULL;
|
|
859
|
+
|
|
860
|
+
if (dev->mtl_queue) {
|
|
861
|
+
[dev->mtl_queue release];
|
|
862
|
+
dev->mtl_queue = nil;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
if (dev->mtl_device) {
|
|
866
|
+
[dev->mtl_device release];
|
|
867
|
+
dev->mtl_device = nil;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
free(dev);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
void * ggml_metal_device_get_obj(ggml_metal_device_t dev) {
|
|
874
|
+
return dev->mtl_device;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
void * ggml_metal_device_get_queue(ggml_metal_device_t dev) {
|
|
878
|
+
return dev->mtl_queue;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
ggml_metal_library_t ggml_metal_device_get_library(ggml_metal_device_t dev) {
|
|
882
|
+
return dev->library;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
void ggml_metal_device_rsets_add(ggml_metal_device_t dev, ggml_metal_rset_t rset) {
|
|
886
|
+
if (rset == nil) {
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
GGML_ASSERT(dev->rsets);
|
|
891
|
+
|
|
892
|
+
[dev->rsets->lock lock];
|
|
893
|
+
|
|
894
|
+
[dev->rsets->data addObject:rset];
|
|
895
|
+
|
|
896
|
+
[dev->rsets->lock unlock];
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
void ggml_metal_device_rsets_rm(ggml_metal_device_t dev, ggml_metal_rset_t rset) {
|
|
900
|
+
if (rset == nil) {
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
GGML_ASSERT(dev->rsets);
|
|
905
|
+
|
|
906
|
+
[dev->rsets->lock lock];
|
|
907
|
+
|
|
908
|
+
[dev->rsets->data removeObject:rset];
|
|
909
|
+
|
|
910
|
+
[dev->rsets->lock unlock];
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
void ggml_metal_device_rsets_keep_alive(ggml_metal_device_t dev) {
|
|
914
|
+
if (dev->rsets == NULL) {
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
atomic_store_explicit(&dev->rsets->d_loop, 2*dev->rsets->keep_alive_s, memory_order_relaxed);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
void ggml_metal_device_get_memory(ggml_metal_device_t dev, size_t * free, size_t * total) {
|
|
922
|
+
if (@available(macOS 10.12, iOS 16.0, *)) {
|
|
923
|
+
*total = dev->mtl_device.recommendedMaxWorkingSetSize;
|
|
924
|
+
*free = *total - dev->mtl_device.currentAllocatedSize;
|
|
925
|
+
} else {
|
|
926
|
+
*free = 0;
|
|
927
|
+
*total = 0;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
bool ggml_metal_device_supports_op(ggml_metal_device_t dev, const struct ggml_tensor * op) {
|
|
932
|
+
const bool has_simdgroup_mm = dev->props.has_simdgroup_mm;
|
|
933
|
+
const bool has_simdgroup_reduction = dev->props.has_simdgroup_reduction;
|
|
934
|
+
const bool has_bfloat = dev->props.has_bfloat;
|
|
935
|
+
|
|
936
|
+
if (!has_bfloat) {
|
|
937
|
+
if (op->type == GGML_TYPE_BF16) {
|
|
938
|
+
return false;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
for (size_t i = 0, n = 3; i < n; ++i) {
|
|
942
|
+
if (op->src[i] != NULL && op->src[i]->type == GGML_TYPE_BF16) {
|
|
943
|
+
return false;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
switch (op->op) {
|
|
949
|
+
case GGML_OP_UNARY:
|
|
950
|
+
switch (ggml_get_unary_op(op)) {
|
|
951
|
+
case GGML_UNARY_OP_TANH:
|
|
952
|
+
case GGML_UNARY_OP_RELU:
|
|
953
|
+
case GGML_UNARY_OP_SIGMOID:
|
|
954
|
+
case GGML_UNARY_OP_GELU:
|
|
955
|
+
case GGML_UNARY_OP_GELU_ERF:
|
|
956
|
+
case GGML_UNARY_OP_GELU_QUICK:
|
|
957
|
+
case GGML_UNARY_OP_SILU:
|
|
958
|
+
case GGML_UNARY_OP_ELU:
|
|
959
|
+
case GGML_UNARY_OP_NEG:
|
|
960
|
+
case GGML_UNARY_OP_ABS:
|
|
961
|
+
case GGML_UNARY_OP_SGN:
|
|
962
|
+
case GGML_UNARY_OP_STEP:
|
|
963
|
+
case GGML_UNARY_OP_HARDSWISH:
|
|
964
|
+
case GGML_UNARY_OP_HARDSIGMOID:
|
|
965
|
+
case GGML_UNARY_OP_EXP:
|
|
966
|
+
case GGML_UNARY_OP_SOFTPLUS:
|
|
967
|
+
case GGML_UNARY_OP_EXPM1:
|
|
968
|
+
return ggml_is_contiguous(op->src[0]) && op->src[0]->type == GGML_TYPE_F32;
|
|
969
|
+
default:
|
|
970
|
+
return false;
|
|
971
|
+
}
|
|
972
|
+
case GGML_OP_GLU:
|
|
973
|
+
switch (ggml_get_glu_op(op)) {
|
|
974
|
+
case GGML_GLU_OP_REGLU:
|
|
975
|
+
case GGML_GLU_OP_GEGLU:
|
|
976
|
+
case GGML_GLU_OP_SWIGLU:
|
|
977
|
+
case GGML_GLU_OP_SWIGLU_OAI:
|
|
978
|
+
case GGML_GLU_OP_GEGLU_ERF:
|
|
979
|
+
case GGML_GLU_OP_GEGLU_QUICK:
|
|
980
|
+
return ggml_is_contiguous_1(op->src[0]) && op->src[0]->type == GGML_TYPE_F32;
|
|
981
|
+
default:
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
984
|
+
case GGML_OP_NONE:
|
|
985
|
+
case GGML_OP_RESHAPE:
|
|
986
|
+
case GGML_OP_VIEW:
|
|
987
|
+
case GGML_OP_TRANSPOSE:
|
|
988
|
+
case GGML_OP_PERMUTE:
|
|
989
|
+
case GGML_OP_CONCAT:
|
|
990
|
+
return true;
|
|
991
|
+
case GGML_OP_ADD:
|
|
992
|
+
case GGML_OP_SUB:
|
|
993
|
+
case GGML_OP_MUL:
|
|
994
|
+
case GGML_OP_DIV:
|
|
995
|
+
case GGML_OP_ADD_ID:
|
|
996
|
+
return op->src[0]->type == GGML_TYPE_F32;
|
|
997
|
+
case GGML_OP_ACC:
|
|
998
|
+
case GGML_OP_REPEAT:
|
|
999
|
+
case GGML_OP_SCALE:
|
|
1000
|
+
case GGML_OP_FILL:
|
|
1001
|
+
case GGML_OP_CONV_TRANSPOSE_1D:
|
|
1002
|
+
return true;
|
|
1003
|
+
case GGML_OP_CONV_TRANSPOSE_2D:
|
|
1004
|
+
return ggml_is_contiguous(op->src[0]) && ggml_is_contiguous(op->src[1]) &&
|
|
1005
|
+
(op->src[0]->type == GGML_TYPE_F16 || op->src[0]->type == GGML_TYPE_F32) &&
|
|
1006
|
+
op->src[1]->type == GGML_TYPE_F32 &&
|
|
1007
|
+
op->type == GGML_TYPE_F32;
|
|
1008
|
+
case GGML_OP_CLAMP:
|
|
1009
|
+
return op->src[0]->type == GGML_TYPE_F32;
|
|
1010
|
+
case GGML_OP_SQR:
|
|
1011
|
+
case GGML_OP_SQRT:
|
|
1012
|
+
case GGML_OP_SIN:
|
|
1013
|
+
case GGML_OP_COS:
|
|
1014
|
+
case GGML_OP_LOG:
|
|
1015
|
+
return ggml_is_contiguous(op->src[0]) && op->src[0]->type == GGML_TYPE_F32;
|
|
1016
|
+
case GGML_OP_SUM:
|
|
1017
|
+
return has_simdgroup_reduction && ggml_is_contiguous(op->src[0]);
|
|
1018
|
+
case GGML_OP_TRI:
|
|
1019
|
+
return ggml_is_contiguous_rows(op->src[0]);
|
|
1020
|
+
case GGML_OP_SUM_ROWS:
|
|
1021
|
+
case GGML_OP_CUMSUM:
|
|
1022
|
+
case GGML_OP_MEAN:
|
|
1023
|
+
case GGML_OP_SOFT_MAX:
|
|
1024
|
+
case GGML_OP_GROUP_NORM:
|
|
1025
|
+
return has_simdgroup_reduction && ggml_is_contiguous_rows(op->src[0]);
|
|
1026
|
+
case GGML_OP_L2_NORM:
|
|
1027
|
+
return has_simdgroup_reduction && (op->ne[0] % 4 == 0 && ggml_is_contiguous_1(op->src[0]));
|
|
1028
|
+
case GGML_OP_COUNT_EQUAL:
|
|
1029
|
+
return has_simdgroup_reduction &&
|
|
1030
|
+
op->src[0]->type == GGML_TYPE_I32 &&
|
|
1031
|
+
op->src[1]->type == GGML_TYPE_I32 &&
|
|
1032
|
+
op->type == GGML_TYPE_I64;
|
|
1033
|
+
case GGML_OP_ARGMAX:
|
|
1034
|
+
return has_simdgroup_reduction;
|
|
1035
|
+
case GGML_OP_NORM:
|
|
1036
|
+
case GGML_OP_RMS_NORM:
|
|
1037
|
+
return has_simdgroup_reduction && (ggml_is_contiguous_rows(op->src[0]));
|
|
1038
|
+
case GGML_OP_ROPE:
|
|
1039
|
+
return true;
|
|
1040
|
+
case GGML_OP_IM2COL:
|
|
1041
|
+
return ggml_is_contiguous(op->src[1]) && op->src[1]->type == GGML_TYPE_F32 && (op->type == GGML_TYPE_F16 || op->type == GGML_TYPE_F32);
|
|
1042
|
+
case GGML_OP_CONV_2D:
|
|
1043
|
+
return ggml_is_contiguous(op->src[0]) &&
|
|
1044
|
+
op->src[1]->type == GGML_TYPE_F32 &&
|
|
1045
|
+
op->type == GGML_TYPE_F32 &&
|
|
1046
|
+
(op->src[0]->type == GGML_TYPE_F16 || op->src[0]->type == GGML_TYPE_F32);
|
|
1047
|
+
case GGML_OP_POOL_1D:
|
|
1048
|
+
return false;
|
|
1049
|
+
case GGML_OP_UPSCALE:
|
|
1050
|
+
return op->src[0]->type == GGML_TYPE_F32 && op->op_params[0] == GGML_SCALE_MODE_NEAREST && !(op->op_params[0] & GGML_SCALE_FLAG_ANTIALIAS);
|
|
1051
|
+
case GGML_OP_POOL_2D:
|
|
1052
|
+
return op->src[0]->type == GGML_TYPE_F32;
|
|
1053
|
+
case GGML_OP_PAD:
|
|
1054
|
+
// TODO: add circular padding support for metal, see https://github.com/ggml-org/llama.cpp/pull/16985
|
|
1055
|
+
if (ggml_get_op_params_i32(op, 8) != 0) {
|
|
1056
|
+
return false;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
return (ggml_get_op_params_i32(op, 0) == 0) && (ggml_get_op_params_i32(op, 2) == 0) &&
|
|
1060
|
+
(ggml_get_op_params_i32(op, 4) == 0) && (ggml_get_op_params_i32(op, 6) == 0);
|
|
1061
|
+
case GGML_OP_PAD_REFLECT_1D:
|
|
1062
|
+
case GGML_OP_TIMESTEP_EMBEDDING:
|
|
1063
|
+
case GGML_OP_LEAKY_RELU:
|
|
1064
|
+
return op->src[0]->type == GGML_TYPE_F32;
|
|
1065
|
+
case GGML_OP_ARGSORT:
|
|
1066
|
+
case GGML_OP_TOP_K:
|
|
1067
|
+
case GGML_OP_ARANGE:
|
|
1068
|
+
return true;
|
|
1069
|
+
case GGML_OP_FLASH_ATTN_EXT:
|
|
1070
|
+
// for new head sizes, add checks here
|
|
1071
|
+
if (op->src[0]->ne[0] != 32 &&
|
|
1072
|
+
op->src[0]->ne[0] != 40 &&
|
|
1073
|
+
op->src[0]->ne[0] != 48 &&
|
|
1074
|
+
op->src[0]->ne[0] != 64 &&
|
|
1075
|
+
op->src[0]->ne[0] != 72 &&
|
|
1076
|
+
op->src[0]->ne[0] != 80 &&
|
|
1077
|
+
op->src[0]->ne[0] != 96 &&
|
|
1078
|
+
op->src[0]->ne[0] != 112 &&
|
|
1079
|
+
op->src[0]->ne[0] != 128 &&
|
|
1080
|
+
op->src[0]->ne[0] != 192 &&
|
|
1081
|
+
op->src[0]->ne[0] != 256) {
|
|
1082
|
+
return false;
|
|
1083
|
+
}
|
|
1084
|
+
if (op->src[0]->ne[0] == 576) {
|
|
1085
|
+
// DeepSeek sizes
|
|
1086
|
+
// TODO: disabled for now, until optmized
|
|
1087
|
+
return false;
|
|
1088
|
+
}
|
|
1089
|
+
if (op->src[1]->type != op->src[2]->type) {
|
|
1090
|
+
return false;
|
|
1091
|
+
}
|
|
1092
|
+
return has_simdgroup_mm; // TODO: over-restricted for vec-kernels
|
|
1093
|
+
case GGML_OP_SSM_CONV:
|
|
1094
|
+
case GGML_OP_SSM_SCAN:
|
|
1095
|
+
return has_simdgroup_reduction;
|
|
1096
|
+
case GGML_OP_RWKV_WKV6:
|
|
1097
|
+
case GGML_OP_RWKV_WKV7:
|
|
1098
|
+
return true;
|
|
1099
|
+
case GGML_OP_MUL_MAT:
|
|
1100
|
+
case GGML_OP_MUL_MAT_ID:
|
|
1101
|
+
return has_simdgroup_reduction;
|
|
1102
|
+
case GGML_OP_CPY:
|
|
1103
|
+
case GGML_OP_DUP:
|
|
1104
|
+
case GGML_OP_CONT:
|
|
1105
|
+
{
|
|
1106
|
+
switch (op->src[0]->type) {
|
|
1107
|
+
case GGML_TYPE_F32:
|
|
1108
|
+
switch (op->type) {
|
|
1109
|
+
case GGML_TYPE_F32:
|
|
1110
|
+
case GGML_TYPE_F16:
|
|
1111
|
+
case GGML_TYPE_BF16:
|
|
1112
|
+
case GGML_TYPE_Q8_0:
|
|
1113
|
+
case GGML_TYPE_Q4_0:
|
|
1114
|
+
case GGML_TYPE_Q4_1:
|
|
1115
|
+
case GGML_TYPE_Q5_0:
|
|
1116
|
+
case GGML_TYPE_Q5_1:
|
|
1117
|
+
case GGML_TYPE_IQ4_NL:
|
|
1118
|
+
case GGML_TYPE_I32:
|
|
1119
|
+
return true;
|
|
1120
|
+
default:
|
|
1121
|
+
return false;
|
|
1122
|
+
}
|
|
1123
|
+
case GGML_TYPE_F16:
|
|
1124
|
+
switch (op->type) {
|
|
1125
|
+
case GGML_TYPE_F32:
|
|
1126
|
+
case GGML_TYPE_F16:
|
|
1127
|
+
return true;
|
|
1128
|
+
default:
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
case GGML_TYPE_BF16:
|
|
1132
|
+
switch (op->type) {
|
|
1133
|
+
case GGML_TYPE_F32:
|
|
1134
|
+
case GGML_TYPE_BF16:
|
|
1135
|
+
return true;
|
|
1136
|
+
default:
|
|
1137
|
+
return false;
|
|
1138
|
+
}
|
|
1139
|
+
case GGML_TYPE_Q4_0:
|
|
1140
|
+
case GGML_TYPE_Q4_1:
|
|
1141
|
+
case GGML_TYPE_Q5_0:
|
|
1142
|
+
case GGML_TYPE_Q5_1:
|
|
1143
|
+
case GGML_TYPE_Q8_0:
|
|
1144
|
+
switch (op->type) {
|
|
1145
|
+
case GGML_TYPE_F32:
|
|
1146
|
+
case GGML_TYPE_F16:
|
|
1147
|
+
return true;
|
|
1148
|
+
default:
|
|
1149
|
+
return false;
|
|
1150
|
+
}
|
|
1151
|
+
case GGML_TYPE_I32:
|
|
1152
|
+
return op->type == GGML_TYPE_F32 || op->type == GGML_TYPE_I32;
|
|
1153
|
+
default:
|
|
1154
|
+
return false;
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
case GGML_OP_GET_ROWS:
|
|
1158
|
+
return true;
|
|
1159
|
+
case GGML_OP_SET_ROWS:
|
|
1160
|
+
{
|
|
1161
|
+
if (op->src[0]->type != GGML_TYPE_F32) {
|
|
1162
|
+
return false;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
switch (op->type) {
|
|
1166
|
+
case GGML_TYPE_F32:
|
|
1167
|
+
case GGML_TYPE_F16:
|
|
1168
|
+
case GGML_TYPE_BF16:
|
|
1169
|
+
case GGML_TYPE_Q8_0:
|
|
1170
|
+
case GGML_TYPE_Q4_0:
|
|
1171
|
+
case GGML_TYPE_Q4_1:
|
|
1172
|
+
case GGML_TYPE_Q5_0:
|
|
1173
|
+
case GGML_TYPE_Q5_1:
|
|
1174
|
+
case GGML_TYPE_IQ4_NL:
|
|
1175
|
+
return true;
|
|
1176
|
+
default:
|
|
1177
|
+
return false;
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
case GGML_OP_OPT_STEP_ADAMW:
|
|
1181
|
+
case GGML_OP_OPT_STEP_SGD:
|
|
1182
|
+
return has_simdgroup_reduction;
|
|
1183
|
+
default:
|
|
1184
|
+
return false;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
const struct ggml_metal_device_props * ggml_metal_device_get_props(ggml_metal_device_t dev) {
|
|
1189
|
+
return &dev->props;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
//
|
|
1193
|
+
// device buffers
|
|
1194
|
+
//
|
|
1195
|
+
|
|
1196
|
+
// max memory buffers that can be mapped to the device
|
|
1197
|
+
#define GGML_METAL_MAX_BUFFERS 64
|
|
1198
|
+
|
|
1199
|
+
struct ggml_metal_buffer_wrapper {
|
|
1200
|
+
void * data;
|
|
1201
|
+
size_t size;
|
|
1202
|
+
|
|
1203
|
+
id<MTLBuffer> metal;
|
|
1204
|
+
};
|
|
1205
|
+
|
|
1206
|
+
struct ggml_metal_buffer {
|
|
1207
|
+
void * all_data;
|
|
1208
|
+
size_t all_size;
|
|
1209
|
+
|
|
1210
|
+
// if false, the Metal buffer data is allocated in private GPU memory and is not shared with the host
|
|
1211
|
+
bool is_shared;
|
|
1212
|
+
bool owned;
|
|
1213
|
+
|
|
1214
|
+
// multiple buffers are used only to avoid the maximum buffer size limitation when using mmap
|
|
1215
|
+
int n_buffers;
|
|
1216
|
+
struct ggml_metal_buffer_wrapper buffers[GGML_METAL_MAX_BUFFERS];
|
|
1217
|
+
|
|
1218
|
+
bool use_residency_sets;
|
|
1219
|
+
|
|
1220
|
+
// optional MTLResidencySet
|
|
1221
|
+
// note: cannot use explicity "id<MTLResidencySet>" here because it is not available on certain OSes
|
|
1222
|
+
id rset;
|
|
1223
|
+
|
|
1224
|
+
// pointers to global device
|
|
1225
|
+
ggml_metal_device_t dev;
|
|
1226
|
+
};
|
|
1227
|
+
|
|
1228
|
+
static void ggml_metal_log_allocated_size(id<MTLDevice> device, size_t size_aligned) {
|
|
1229
|
+
#ifndef GGML_METAL_NDEBUG
|
|
1230
|
+
#if TARGET_OS_OSX || (TARGET_OS_IOS && __clang_major__ >= 15)
|
|
1231
|
+
if (@available(macOS 10.12, iOS 16.0, *)) {
|
|
1232
|
+
GGML_LOG_DEBUG("%s: allocated buffer, size = %8.2f MiB, (%8.2f / %8.2f)\n",
|
|
1233
|
+
__func__,
|
|
1234
|
+
size_aligned / 1024.0 / 1024.0,
|
|
1235
|
+
device.currentAllocatedSize / 1024.0 / 1024.0,
|
|
1236
|
+
device.recommendedMaxWorkingSetSize / 1024.0 / 1024.0);
|
|
1237
|
+
|
|
1238
|
+
if (device.currentAllocatedSize > device.recommendedMaxWorkingSetSize) {
|
|
1239
|
+
GGML_LOG_WARN("%s: warning: current allocated size is greater than the recommended max working set size\n", __func__);
|
|
1240
|
+
}
|
|
1241
|
+
} else {
|
|
1242
|
+
GGML_LOG_INFO("%s: allocated buffer, size = %8.2f MiB, (%8.2f)\n",
|
|
1243
|
+
__func__,
|
|
1244
|
+
size_aligned / 1024.0 / 1024.0,
|
|
1245
|
+
device.currentAllocatedSize / 1024.0 / 1024.0);
|
|
1246
|
+
}
|
|
1247
|
+
#endif
|
|
1248
|
+
#endif
|
|
1249
|
+
GGML_UNUSED(device);
|
|
1250
|
+
GGML_UNUSED(size_aligned);
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// rset init
|
|
1254
|
+
static bool ggml_metal_buffer_rset_init(ggml_metal_buffer_t buf) {
|
|
1255
|
+
buf->rset = nil;
|
|
1256
|
+
|
|
1257
|
+
if (!buf->use_residency_sets) {
|
|
1258
|
+
return true;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
#if defined(GGML_METAL_HAS_RESIDENCY_SETS)
|
|
1262
|
+
if (@available(macOS 15.0, iOS 18.0, tvOS 18.0, visionOS 2.0, *)) {
|
|
1263
|
+
MTLResidencySetDescriptor * desc = [[MTLResidencySetDescriptor alloc] init];
|
|
1264
|
+
desc.label = @"ggml_metal";
|
|
1265
|
+
desc.initialCapacity = buf->n_buffers;
|
|
1266
|
+
|
|
1267
|
+
NSError * error;
|
|
1268
|
+
buf->rset = [buf->dev->mtl_device newResidencySetWithDescriptor:desc error:&error];
|
|
1269
|
+
if (error) {
|
|
1270
|
+
GGML_LOG_ERROR("%s: error: %s\n", __func__, [[error description] UTF8String]);
|
|
1271
|
+
[desc release];
|
|
1272
|
+
return false;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
[desc release];
|
|
1276
|
+
|
|
1277
|
+
for (int i = 0; i < buf->n_buffers; i++) {
|
|
1278
|
+
[buf->rset addAllocation:buf->buffers[i].metal];
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
[buf->rset commit];
|
|
1282
|
+
[buf->rset requestResidency];
|
|
1283
|
+
|
|
1284
|
+
return true;
|
|
1285
|
+
}
|
|
1286
|
+
#endif
|
|
1287
|
+
|
|
1288
|
+
return true;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
// rset free
|
|
1292
|
+
static void ggml_metal_buffer_rset_free(ggml_metal_buffer_t buf) {
|
|
1293
|
+
#if defined(GGML_METAL_HAS_RESIDENCY_SETS)
|
|
1294
|
+
if (@available(macOS 15.0, iOS 18.0, tvOS 18.0, visionOS 2.0, *)) {
|
|
1295
|
+
if (buf->rset) {
|
|
1296
|
+
[buf->rset endResidency];
|
|
1297
|
+
[buf->rset removeAllAllocations];
|
|
1298
|
+
[buf->rset release];
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
#else
|
|
1302
|
+
GGML_UNUSED(buf);
|
|
1303
|
+
#endif
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
static void * ggml_metal_host_malloc(size_t n) {
|
|
1307
|
+
void * data = NULL;
|
|
1308
|
+
|
|
1309
|
+
#if TARGET_OS_OSX
|
|
1310
|
+
kern_return_t err = vm_allocate((vm_map_t) mach_task_self(), (void *) &data, n, VM_FLAGS_ANYWHERE);
|
|
1311
|
+
if (err != KERN_SUCCESS) {
|
|
1312
|
+
GGML_LOG_ERROR("%s: error: vm_allocate failed\n", __func__);
|
|
1313
|
+
return NULL;
|
|
1314
|
+
}
|
|
1315
|
+
#else
|
|
1316
|
+
const int result = posix_memalign((void **) &data, sysconf(_SC_PAGESIZE), n);
|
|
1317
|
+
if (result != 0) {
|
|
1318
|
+
GGML_LOG_ERROR("%s: error: posix_memalign failed\n", __func__);
|
|
1319
|
+
return NULL;
|
|
1320
|
+
}
|
|
1321
|
+
#endif
|
|
1322
|
+
|
|
1323
|
+
return data;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
ggml_metal_buffer_t ggml_metal_buffer_init(ggml_metal_device_t dev, size_t size, bool shared) {
|
|
1327
|
+
ggml_metal_buffer_t res = calloc(1, sizeof(struct ggml_metal_buffer));
|
|
1328
|
+
|
|
1329
|
+
res->dev = dev;
|
|
1330
|
+
|
|
1331
|
+
const size_t size_page = sysconf(_SC_PAGESIZE);
|
|
1332
|
+
|
|
1333
|
+
size_t size_aligned = size;
|
|
1334
|
+
if ((size_aligned % size_page) != 0) {
|
|
1335
|
+
size_aligned += (size_page - (size_aligned % size_page));
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
const struct ggml_metal_device_props * props_dev = ggml_metal_device_get_props(dev);
|
|
1339
|
+
|
|
1340
|
+
shared = shared && props_dev->use_shared_buffers;
|
|
1341
|
+
|
|
1342
|
+
// allocate shared buffer if the device supports it and it is required by the buffer type
|
|
1343
|
+
if (shared) {
|
|
1344
|
+
res->all_data = ggml_metal_host_malloc(size_aligned);
|
|
1345
|
+
res->is_shared = true;
|
|
1346
|
+
} else {
|
|
1347
|
+
// use virtual address from g_addr_device counter
|
|
1348
|
+
res->all_data = (void *) atomic_fetch_add_explicit(&g_addr_device, size_aligned, memory_order_relaxed);
|
|
1349
|
+
res->is_shared = false;
|
|
1350
|
+
}
|
|
1351
|
+
res->all_size = size_aligned;
|
|
1352
|
+
|
|
1353
|
+
res->owned = true;
|
|
1354
|
+
|
|
1355
|
+
res->n_buffers = 1;
|
|
1356
|
+
|
|
1357
|
+
if (res->all_data != NULL) {
|
|
1358
|
+
res->buffers[0].size = size;
|
|
1359
|
+
res->buffers[0].metal = nil;
|
|
1360
|
+
|
|
1361
|
+
if (size_aligned > 0) {
|
|
1362
|
+
if (props_dev->use_shared_buffers && shared) {
|
|
1363
|
+
res->buffers[0].metal = [res->dev->mtl_device newBufferWithBytesNoCopy:res->all_data
|
|
1364
|
+
length:size_aligned
|
|
1365
|
+
options:MTLResourceStorageModeShared
|
|
1366
|
+
deallocator:nil];
|
|
1367
|
+
} else {
|
|
1368
|
+
res->buffers[0].metal = [res->dev->mtl_device newBufferWithLength:size_aligned options:MTLResourceStorageModePrivate];
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
res->buffers[0].data = res->all_data;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
if (size_aligned > 0 && (res->all_data == NULL || res->buffers[0].metal == nil)) {
|
|
1376
|
+
GGML_LOG_ERROR("%s: error: failed to allocate buffer, size = %8.2f MiB\n", __func__, size_aligned / 1024.0 / 1024.0);
|
|
1377
|
+
free(res);
|
|
1378
|
+
return NULL;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
res->use_residency_sets = props_dev->use_residency_sets;
|
|
1382
|
+
|
|
1383
|
+
if (!ggml_metal_buffer_rset_init(res)) {
|
|
1384
|
+
GGML_LOG_ERROR("%s: error: failed to initialize residency set\n", __func__);
|
|
1385
|
+
free(res);
|
|
1386
|
+
return NULL;
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
ggml_metal_device_rsets_add(dev, res->rset);
|
|
1390
|
+
|
|
1391
|
+
//ggml_metal_log_allocated_size(device, size_aligned);
|
|
1392
|
+
|
|
1393
|
+
return res;
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
ggml_metal_buffer_t ggml_metal_buffer_map(ggml_metal_device_t dev, void * ptr, size_t size, size_t max_tensor_size) {
|
|
1397
|
+
ggml_metal_buffer_t res = calloc(1, sizeof(struct ggml_metal_buffer));
|
|
1398
|
+
|
|
1399
|
+
res->dev = dev;
|
|
1400
|
+
|
|
1401
|
+
res->all_data = ptr;
|
|
1402
|
+
res->all_size = size;
|
|
1403
|
+
|
|
1404
|
+
res->is_shared = true;
|
|
1405
|
+
res->owned = false;
|
|
1406
|
+
|
|
1407
|
+
res->n_buffers = 0;
|
|
1408
|
+
|
|
1409
|
+
const size_t size_page = sysconf(_SC_PAGESIZE);
|
|
1410
|
+
|
|
1411
|
+
// page-align the data ptr
|
|
1412
|
+
{
|
|
1413
|
+
const uintptr_t offs = (uintptr_t) ptr % size_page;
|
|
1414
|
+
ptr = (void *) ((char *) ptr - offs);
|
|
1415
|
+
size += offs;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
size_t size_aligned = size;
|
|
1419
|
+
if ((size_aligned % size_page) != 0) {
|
|
1420
|
+
size_aligned += (size_page - (size_aligned % size_page));
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
const struct ggml_metal_device_props * props_dev = ggml_metal_device_get_props(dev);
|
|
1424
|
+
|
|
1425
|
+
// the buffer fits into the max buffer size allowed by the device
|
|
1426
|
+
if (size_aligned <= props_dev->max_buffer_size) {
|
|
1427
|
+
res->buffers[res->n_buffers].data = ptr;
|
|
1428
|
+
res->buffers[res->n_buffers].size = size;
|
|
1429
|
+
res->buffers[res->n_buffers].metal = nil;
|
|
1430
|
+
|
|
1431
|
+
if (size_aligned > 0) {
|
|
1432
|
+
res->buffers[res->n_buffers].metal = [res->dev->mtl_device newBufferWithBytesNoCopy:ptr length:size_aligned options:MTLResourceStorageModeShared deallocator:nil];
|
|
1433
|
+
|
|
1434
|
+
if (res->buffers[res->n_buffers].metal == nil) {
|
|
1435
|
+
GGML_LOG_ERROR("%s: error: failed to allocate buffer, size = %8.2f MiB\n", __func__, size_aligned / 1024.0 / 1024.0);
|
|
1436
|
+
free(res);
|
|
1437
|
+
return NULL;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
ggml_metal_log_allocated_size(res->dev->mtl_device, size_aligned);
|
|
1442
|
+
|
|
1443
|
+
++res->n_buffers;
|
|
1444
|
+
} else {
|
|
1445
|
+
// this overlap between the views will guarantee that the tensor with the maximum size will fully fit into
|
|
1446
|
+
// one of the views
|
|
1447
|
+
const size_t size_ovlp = ((max_tensor_size + size_page - 1) / size_page + 1) * size_page; // round-up 2 pages just in case
|
|
1448
|
+
const size_t size_step = props_dev->max_buffer_size - size_ovlp;
|
|
1449
|
+
const size_t size_view = props_dev->max_buffer_size;
|
|
1450
|
+
|
|
1451
|
+
for (size_t i = 0; i < size; i += size_step) {
|
|
1452
|
+
const size_t size_step_aligned = (i + size_view <= size) ? size_view : (size_aligned - i);
|
|
1453
|
+
|
|
1454
|
+
res->buffers[res->n_buffers].data = (void *) ((uint8_t *) ptr + i);
|
|
1455
|
+
res->buffers[res->n_buffers].size = size_step_aligned;
|
|
1456
|
+
res->buffers[res->n_buffers].metal = nil;
|
|
1457
|
+
|
|
1458
|
+
if (size_step_aligned > 0) {
|
|
1459
|
+
res->buffers[res->n_buffers].metal = [res->dev->mtl_device newBufferWithBytesNoCopy:(void *) ((uint8_t *) ptr + i) length:size_step_aligned options:MTLResourceStorageModeShared deallocator:nil];
|
|
1460
|
+
|
|
1461
|
+
if (res->buffers[res->n_buffers].metal == nil) {
|
|
1462
|
+
GGML_LOG_ERROR("%s: error: failed to allocate buffer, size = %8.2f MiB\n", __func__, size_step_aligned / 1024.0 / 1024.0);
|
|
1463
|
+
free(res);
|
|
1464
|
+
return NULL;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
ggml_metal_log_allocated_size(res->dev->mtl_device, size_step_aligned);
|
|
1469
|
+
|
|
1470
|
+
if (i + size_step < size) {
|
|
1471
|
+
GGML_LOG_INFO("\n");
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
++res->n_buffers;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
res->use_residency_sets = props_dev->use_residency_sets;
|
|
1479
|
+
|
|
1480
|
+
if (!ggml_metal_buffer_rset_init(res)) {
|
|
1481
|
+
GGML_LOG_ERROR("%s: error: failed to initialize residency set\n", __func__);
|
|
1482
|
+
free(res);
|
|
1483
|
+
return NULL;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
ggml_metal_device_rsets_add(dev, res->rset);
|
|
1487
|
+
|
|
1488
|
+
return res;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
void ggml_metal_buffer_free(ggml_metal_buffer_t buf) {
|
|
1492
|
+
ggml_metal_device_rsets_rm(buf->dev, buf->rset);
|
|
1493
|
+
|
|
1494
|
+
for (int i = 0; i < buf->n_buffers; i++) {
|
|
1495
|
+
[buf->buffers[i].metal release];
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
ggml_metal_buffer_rset_free(buf);
|
|
1499
|
+
|
|
1500
|
+
if (buf->is_shared && buf->owned) {
|
|
1501
|
+
#if TARGET_OS_OSX
|
|
1502
|
+
vm_deallocate((vm_map_t)mach_task_self(), (vm_address_t)buf->all_data, buf->all_size);
|
|
1503
|
+
#else
|
|
1504
|
+
free(buf->all_data);
|
|
1505
|
+
#endif
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
free(buf);
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
void * ggml_metal_buffer_get_base(ggml_metal_buffer_t buf) {
|
|
1512
|
+
return buf->all_data;
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
bool ggml_metal_buffer_is_shared(ggml_metal_buffer_t buf) {
|
|
1516
|
+
return buf->is_shared;
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
void ggml_metal_buffer_memset_tensor(ggml_metal_buffer_t buf, struct ggml_tensor * tensor, uint8_t value, size_t offset, size_t size) {
|
|
1520
|
+
if (buf->is_shared) {
|
|
1521
|
+
memset((char *) tensor->data + offset, value, size);
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
@autoreleasepool {
|
|
1526
|
+
// dst
|
|
1527
|
+
struct ggml_metal_buffer_id bid_dst = ggml_metal_buffer_get_id(buf, tensor);
|
|
1528
|
+
bid_dst.offs += offset;
|
|
1529
|
+
|
|
1530
|
+
id<MTLCommandBuffer> cmd_buf = [buf->dev->mtl_queue commandBufferWithUnretainedReferences];
|
|
1531
|
+
|
|
1532
|
+
{
|
|
1533
|
+
id<MTLBlitCommandEncoder> encoder = [cmd_buf blitCommandEncoder];
|
|
1534
|
+
|
|
1535
|
+
[encoder fillBuffer:bid_dst.metal
|
|
1536
|
+
range:NSMakeRange(bid_dst.offs, bid_dst.offs + size)
|
|
1537
|
+
value:value];
|
|
1538
|
+
|
|
1539
|
+
[encoder endEncoding];
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
[cmd_buf commit];
|
|
1543
|
+
[cmd_buf waitUntilCompleted];
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
void ggml_metal_buffer_set_tensor(ggml_metal_buffer_t buf, struct ggml_tensor * tensor, const void * data, size_t offset, size_t size) {
|
|
1548
|
+
if (buf->is_shared) {
|
|
1549
|
+
memcpy((char *) tensor->data + offset, data, size);
|
|
1550
|
+
return;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
@autoreleasepool {
|
|
1554
|
+
// src
|
|
1555
|
+
void * data_ptr = (void *)(uintptr_t) data; // "const cast" the src data
|
|
1556
|
+
id<MTLBuffer> buf_src = [buf->dev->mtl_device newBufferWithBytesNoCopy:data_ptr
|
|
1557
|
+
length:size
|
|
1558
|
+
options:MTLResourceStorageModeShared
|
|
1559
|
+
deallocator:nil];
|
|
1560
|
+
|
|
1561
|
+
GGML_ASSERT(buf_src);
|
|
1562
|
+
|
|
1563
|
+
// dst
|
|
1564
|
+
struct ggml_metal_buffer_id bid_dst = ggml_metal_buffer_get_id(buf, tensor);
|
|
1565
|
+
bid_dst.offs += offset;
|
|
1566
|
+
|
|
1567
|
+
// note: for experimentation purposes, here we use a semaphore to wait for the copy to complete
|
|
1568
|
+
// this is alternative to waitUntilCompleted, which should be faster, but don't seem to make much difference
|
|
1569
|
+
dispatch_semaphore_t completion_semaphore = dispatch_semaphore_create(0);
|
|
1570
|
+
|
|
1571
|
+
id<MTLCommandBuffer> cmd_buf = [buf->dev->mtl_queue commandBufferWithUnretainedReferences];
|
|
1572
|
+
|
|
1573
|
+
{
|
|
1574
|
+
id<MTLBlitCommandEncoder> encoder = [cmd_buf blitCommandEncoder];
|
|
1575
|
+
|
|
1576
|
+
[encoder copyFromBuffer:buf_src
|
|
1577
|
+
sourceOffset:0
|
|
1578
|
+
toBuffer:bid_dst.metal
|
|
1579
|
+
destinationOffset:bid_dst.offs
|
|
1580
|
+
size:size];
|
|
1581
|
+
|
|
1582
|
+
[encoder endEncoding];
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
[cmd_buf addCompletedHandler:^(id<MTLCommandBuffer> cb) {
|
|
1586
|
+
// TODO: can check for errors here
|
|
1587
|
+
GGML_UNUSED(cb);
|
|
1588
|
+
|
|
1589
|
+
dispatch_semaphore_signal(completion_semaphore);
|
|
1590
|
+
}];
|
|
1591
|
+
|
|
1592
|
+
[cmd_buf commit];
|
|
1593
|
+
|
|
1594
|
+
dispatch_semaphore_wait(completion_semaphore, DISPATCH_TIME_FOREVER);
|
|
1595
|
+
dispatch_release(completion_semaphore);
|
|
1596
|
+
|
|
1597
|
+
//[cmd_buf waitUntilCompleted];
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
void ggml_metal_buffer_get_tensor(ggml_metal_buffer_t buf, const struct ggml_tensor * tensor, void * data, size_t offset, size_t size) {
|
|
1602
|
+
if (buf->is_shared) {
|
|
1603
|
+
memcpy(data, (const char *) tensor->data + offset, size);
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
@autoreleasepool {
|
|
1608
|
+
// src
|
|
1609
|
+
struct ggml_metal_buffer_id bid_src = ggml_metal_buffer_get_id(buf, tensor);
|
|
1610
|
+
bid_src.offs += offset;
|
|
1611
|
+
|
|
1612
|
+
// dst
|
|
1613
|
+
id<MTLBuffer> buf_dst = [buf->dev->mtl_device newBufferWithBytesNoCopy:data
|
|
1614
|
+
length:size
|
|
1615
|
+
options:MTLResourceStorageModeShared
|
|
1616
|
+
deallocator:nil];
|
|
1617
|
+
|
|
1618
|
+
GGML_ASSERT(buf_dst);
|
|
1619
|
+
|
|
1620
|
+
id<MTLCommandBuffer> cmd_buf = [buf->dev->mtl_queue commandBufferWithUnretainedReferences];
|
|
1621
|
+
|
|
1622
|
+
{
|
|
1623
|
+
id<MTLBlitCommandEncoder> encoder = [cmd_buf blitCommandEncoder];
|
|
1624
|
+
|
|
1625
|
+
[encoder copyFromBuffer:bid_src.metal
|
|
1626
|
+
sourceOffset:bid_src.offs
|
|
1627
|
+
toBuffer:buf_dst
|
|
1628
|
+
destinationOffset:0
|
|
1629
|
+
size:size];
|
|
1630
|
+
|
|
1631
|
+
[encoder endEncoding];
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
[cmd_buf commit];
|
|
1635
|
+
[cmd_buf waitUntilCompleted];
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
void ggml_metal_buffer_clear(ggml_metal_buffer_t buf, uint8_t value) {
|
|
1640
|
+
if (buf->is_shared) {
|
|
1641
|
+
memset(buf->all_data, value, buf->all_size);
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
@autoreleasepool {
|
|
1646
|
+
id<MTLCommandBuffer> cmd_buf = [buf->dev->mtl_queue commandBufferWithUnretainedReferences];
|
|
1647
|
+
|
|
1648
|
+
{
|
|
1649
|
+
id<MTLBlitCommandEncoder> encoder = [cmd_buf blitCommandEncoder];
|
|
1650
|
+
|
|
1651
|
+
[encoder fillBuffer:buf->buffers[0].metal
|
|
1652
|
+
range:NSMakeRange(0, buf->buffers[0].size)
|
|
1653
|
+
value:value];
|
|
1654
|
+
|
|
1655
|
+
[encoder endEncoding];
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
[cmd_buf commit];
|
|
1659
|
+
[cmd_buf waitUntilCompleted];
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
struct ggml_metal_buffer_id ggml_metal_buffer_get_id(ggml_metal_buffer_t buf, const struct ggml_tensor * t) {
|
|
1664
|
+
struct ggml_metal_buffer_id res = { nil, 0 };
|
|
1665
|
+
|
|
1666
|
+
const int64_t tsize = ggml_nbytes(t);
|
|
1667
|
+
|
|
1668
|
+
// find the view that contains the tensor fully
|
|
1669
|
+
for (int i = 0; i < buf->n_buffers; ++i) {
|
|
1670
|
+
const int64_t ioffs = (int64_t) t->data - (int64_t) buf->buffers[i].data;
|
|
1671
|
+
|
|
1672
|
+
//GGML_LOG_INFO("ioffs = %10ld, tsize = %10ld, sum = %10ld, buf->buffers[%d].size = %10ld\n", ioffs, tsize, ioffs + tsize, i, buf->buffers[i].size);
|
|
1673
|
+
if (ioffs >= 0 && ioffs + tsize <= (int64_t) buf->buffers[i].size) {
|
|
1674
|
+
res.metal = buf->buffers[i].metal;
|
|
1675
|
+
res.offs = (size_t) ioffs;
|
|
1676
|
+
|
|
1677
|
+
//GGML_LOG_INFO("%s: tensor '%16s', offs = %8ld\n", __func__, t->name, *offs);
|
|
1678
|
+
|
|
1679
|
+
return res;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
GGML_LOG_ERROR("%s: error: tensor '%s' buffer is nil\n", __func__, t->name);
|
|
1684
|
+
|
|
1685
|
+
return res;
|
|
1686
|
+
}
|