toy 0.8.0
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 +7 -0
- data/CHANGELOG.md +1124 -0
- data/LICENSE +21 -0
- data/Makefile +2022 -0
- data/README.md +154 -0
- data/bin/toy +10 -0
- data/lib/toy/compute.rb +135 -0
- data/lib/toy/compute_cuda.rb +104 -0
- data/lib/toy/compute_metal.rb +97 -0
- data/lib/toy/core/cli/describe.rb +188 -0
- data/lib/toy/core/cli/eval.rb +385 -0
- data/lib/toy/core/cli/exit_codes.rb +15 -0
- data/lib/toy/core/cli/fetch.rb +238 -0
- data/lib/toy/core/cli/infer.rb +268 -0
- data/lib/toy/core/cli/install.rb +228 -0
- data/lib/toy/core/cli/list.rb +86 -0
- data/lib/toy/core/cli/manifest.rb +49 -0
- data/lib/toy/core/cli/new.rb +594 -0
- data/lib/toy/core/cli/serve.rb +237 -0
- data/lib/toy/core/cli/train.rb +471 -0
- data/lib/toy/core/cli.rb +165 -0
- data/lib/toy/core/config.rb +64 -0
- data/lib/toy/core/gguf_meta.rb +161 -0
- data/lib/toy/core/model_scan.rb +221 -0
- data/lib/toy/core/run_log.rb +94 -0
- data/lib/toy/core/toy_root.rb +95 -0
- data/lib/toy/dev/toy_card.rb +299 -0
- data/lib/toy/dev/toy_describe_flow.rb +412 -0
- data/lib/toy/dev/toy_logprobs.rb +86 -0
- data/lib/toy/dev/toy_tap.rb +183 -0
- data/lib/toy/dev/toy_token_drift.rb +121 -0
- data/lib/toy/ffi/tinynn.rb +1491 -0
- data/lib/toy/ffi/tinynn_cuda.rb +1124 -0
- data/lib/toy/ffi/tinynn_metal.rb +359 -0
- data/lib/toy/ffi_manifest.rb +84 -0
- data/lib/toy/io/bpe.rb +325 -0
- data/lib/toy/io/gguf_kv.rb +35 -0
- data/lib/toy/io/gguf_load.rb +331 -0
- data/lib/toy/io/loaders/toy_gpt2_loader.rb +70 -0
- data/lib/toy/io/loaders/toy_smollm2_loader.rb +754 -0
- data/lib/toy/io/model_index.rb +206 -0
- data/lib/toy/io/run_bundle.rb +280 -0
- data/lib/toy/io/tokenizer.rb +613 -0
- data/lib/toy/io/toy_corpus_loader.rb +52 -0
- data/lib/toy/io/toy_events.rb +56 -0
- data/lib/toy/io/toy_image_loader.rb +48 -0
- data/lib/toy/llm/adamw.rb +169 -0
- data/lib/toy/llm/archs/llama_arch.rb +233 -0
- data/lib/toy/llm/archs/llama_arch_cuda.rb +237 -0
- data/lib/toy/llm/archs/llama_arch_metal.rb +237 -0
- data/lib/toy/llm/blocks/transformer_block.rb +876 -0
- data/lib/toy/llm/blocks/transformer_block_cuda.rb +880 -0
- data/lib/toy/llm/blocks/transformer_block_metal.rb +880 -0
- data/lib/toy/llm/classify_batch.rb +88 -0
- data/lib/toy/llm/engine/gpt2_fwd_engine.rb +360 -0
- data/lib/toy/llm/engine/gpt2_fwd_engine_cuda.rb +362 -0
- data/lib/toy/llm/engine/gpt2_fwd_engine_metal.rb +362 -0
- data/lib/toy/llm/engine/gpt2_kv_engine.rb +346 -0
- data/lib/toy/llm/engine/gpt2_kv_engine_cuda.rb +348 -0
- data/lib/toy/llm/engine/gpt2_kv_engine_metal.rb +348 -0
- data/lib/toy/llm/engine/gpt2_seq_engine.rb +289 -0
- data/lib/toy/llm/engine/gpt2_seq_engine_cuda.rb +293 -0
- data/lib/toy/llm/engine/gpt2_seq_engine_metal.rb +293 -0
- data/lib/toy/llm/engine/llama_kv_engine.rb +1593 -0
- data/lib/toy/llm/engine/llama_kv_engine_cuda.rb +1526 -0
- data/lib/toy/llm/engine/llama_kv_engine_metal.rb +1526 -0
- data/lib/toy/llm/engine/llama_seq_engine.rb +1233 -0
- data/lib/toy/llm/engine/llama_seq_engine_cuda.rb +1238 -0
- data/lib/toy/llm/engine/llama_seq_engine_metal.rb +1238 -0
- data/lib/toy/llm/engine/vit_tiny_engine.rb +467 -0
- data/lib/toy/llm/labels.rb +142 -0
- data/lib/toy/llm/primitives/gqa.rb +62 -0
- data/lib/toy/llm/primitives/gqa_cuda.rb +66 -0
- data/lib/toy/llm/primitives/gqa_metal.rb +66 -0
- data/lib/toy/llm/primitives/rms_norm.rb +39 -0
- data/lib/toy/llm/primitives/rms_norm_cuda.rb +43 -0
- data/lib/toy/llm/primitives/rms_norm_metal.rb +43 -0
- data/lib/toy/llm/primitives/rope.rb +68 -0
- data/lib/toy/llm/primitives/rope_cuda.rb +72 -0
- data/lib/toy/llm/primitives/rope_metal.rb +72 -0
- data/lib/toy/llm/primitives/swiglu.rb +41 -0
- data/lib/toy/llm/primitives/swiglu_cuda.rb +45 -0
- data/lib/toy/llm/primitives/swiglu_metal.rb +45 -0
- data/lib/toy/llm/recipe_options.rb +71 -0
- data/lib/toy/llm/recipes/from_scratch.rb +105 -0
- data/lib/toy/llm/recipes/from_scratch_cuda.rb +109 -0
- data/lib/toy/llm/recipes/from_scratch_metal.rb +109 -0
- data/lib/toy/llm/recipes/lora.rb +110 -0
- data/lib/toy/llm/recipes/lora_cuda.rb +114 -0
- data/lib/toy/llm/recipes/lora_metal.rb +114 -0
- data/lib/toy/llm/recipes/vit_tiny.rb +75 -0
- data/lib/toy/llm/recipes/warm_start.rb +235 -0
- data/lib/toy/llm/recipes/warm_start_cuda.rb +239 -0
- data/lib/toy/llm/recipes/warm_start_metal.rb +239 -0
- data/lib/toy/llm/training_batch.rb +133 -0
- data/lib/toy/models/arch.rb +253 -0
- data/lib/toy/models/gpt2.rb +311 -0
- data/lib/toy/models/toy_gpt2.rb +177 -0
- data/lib/toy/models/toy_smollm2.rb +393 -0
- data/lib/toy/models/toy_vit.rb +83 -0
- data/lib/toy/models/transformer.rb +1494 -0
- data/lib/toy/models/transformer_lm.rb +298 -0
- data/lib/toy/models/transformer_lm_cuda.rb +159 -0
- data/lib/toy/models/transformer_lm_metal.rb +142 -0
- data/lib/toy/mri.rb +300 -0
- data/lib/toy/run/eval.rb +76 -0
- data/lib/toy/run/eval_cuda.rb +66 -0
- data/lib/toy/run/eval_lmc.rb +334 -0
- data/lib/toy/run/eval_metal.rb +67 -0
- data/lib/toy/run/infer.rb +130 -0
- data/lib/toy/run/infer_cuda.rb +118 -0
- data/lib/toy/run/infer_metal.rb +119 -0
- data/lib/toy/run/infer_trace.rb +37 -0
- data/lib/toy/run/serve.rb +144 -0
- data/lib/toy/run/train.rb +404 -0
- data/lib/toy/run/train_cuda.rb +397 -0
- data/lib/toy/run/train_gpt2.rb +103 -0
- data/lib/toy/run/train_gpt2_cuda.rb +85 -0
- data/lib/toy/run/train_gpt2_metal.rb +85 -0
- data/lib/toy/run/train_lora.rb +207 -0
- data/lib/toy/run/train_lora_cuda.rb +219 -0
- data/lib/toy/run/train_metal.rb +227 -0
- data/lib/toy/run/train_vit.rb +251 -0
- data/lib/toy/serve/openai/embeddings_handler.rb +92 -0
- data/lib/toy/serve/openai/handlers.rb +143 -0
- data/lib/toy/serve/openai/server.rb +159 -0
- data/lib/toy/train/sampler.rb +314 -0
- data/lib/toy/train/toy_chat_template.rb +179 -0
- data/lib/toy/train/toy_drift_grad.rb +176 -0
- data/lib/toy/train/toy_gguf_fuse.rb +428 -0
- data/lib/toy/train/toy_gguf_writer.rb +100 -0
- data/lib/toy/train/toy_lr_schedule.rb +39 -0
- data/lib/toy/train/toy_sample.rb +125 -0
- data/lib/toy/train/toy_trainer.rb +86 -0
- data/lib/toy/train/training.rb +160 -0
- data/lib/toy/version.rb +11 -0
- data/lib/toy.rb +902 -0
- data/prep/progress +118 -0
- data/prep/quietly +64 -0
- data/sig/toy.rbs +397 -0
- data/sig/toy_compute.rbs +450 -0
- data/spinel-ext.json +122 -0
- data/tinynn/Makefile +71 -0
- data/tinynn/tinynn_backend_cuda.c +99 -0
- data/tinynn/tinynn_backend_metal.m +75 -0
- data/tinynn/tinynn_events.c +122 -0
- data/tinynn/tinynn_events.h +83 -0
- data/tinynn/tinynn_ggml.c +2460 -0
- data/tinynn/tinynn_ggml.h +545 -0
- data/tinynn/tinynn_gguf.c +783 -0
- data/tinynn/tinynn_gguf.h +167 -0
- data/tinynn/tinynn_trace.c +180 -0
- data/tinynn/tinynn_trace.h +85 -0
- data/vendor/ggml/AUTHORS +335 -0
- data/vendor/ggml/CMakeLists.txt +505 -0
- data/vendor/ggml/CONTRIBUTING.md +3 -0
- data/vendor/ggml/LICENSE +21 -0
- data/vendor/ggml/README.md +50 -0
- data/vendor/ggml/ci/run.sh +395 -0
- data/vendor/ggml/cmake/FindNCCL.cmake +36 -0
- data/vendor/ggml/cmake/GitVars.cmake +22 -0
- data/vendor/ggml/cmake/common.cmake +50 -0
- data/vendor/ggml/cmake/ggml-config.cmake.in +191 -0
- data/vendor/ggml/docs/gguf.md +828 -0
- data/vendor/ggml/examples/CMakeLists.txt +34 -0
- data/vendor/ggml/examples/common-ggml.cpp +244 -0
- data/vendor/ggml/examples/common-ggml.h +18 -0
- data/vendor/ggml/examples/common.cpp +675 -0
- data/vendor/ggml/examples/common.h +322 -0
- data/vendor/ggml/examples/gpt-2/CMakeLists.txt +32 -0
- data/vendor/ggml/examples/gpt-2/README.md +225 -0
- data/vendor/ggml/examples/gpt-2/convert-cerebras-to-ggml.py +183 -0
- data/vendor/ggml/examples/gpt-2/convert-ckpt-to-ggml.py +159 -0
- data/vendor/ggml/examples/gpt-2/convert-h5-to-ggml.py +195 -0
- data/vendor/ggml/examples/gpt-2/download-ggml-model.sh +69 -0
- data/vendor/ggml/examples/gpt-2/download-model.sh +48 -0
- data/vendor/ggml/examples/gpt-2/main-alloc.cpp +880 -0
- data/vendor/ggml/examples/gpt-2/main-backend.cpp +946 -0
- data/vendor/ggml/examples/gpt-2/main-batched.cpp +1210 -0
- data/vendor/ggml/examples/gpt-2/main-ctx.cpp +840 -0
- data/vendor/ggml/examples/gpt-2/main-sched.cpp +1079 -0
- data/vendor/ggml/examples/gpt-2/quantize.cpp +184 -0
- data/vendor/ggml/examples/gpt-j/CMakeLists.txt +13 -0
- data/vendor/ggml/examples/gpt-j/README.md +239 -0
- data/vendor/ggml/examples/gpt-j/convert-h5-to-ggml.py +173 -0
- data/vendor/ggml/examples/gpt-j/download-ggml-model.sh +69 -0
- data/vendor/ggml/examples/gpt-j/download-model.sh +11 -0
- data/vendor/ggml/examples/gpt-j/main.cpp +755 -0
- data/vendor/ggml/examples/gpt-j/quantize.cpp +182 -0
- data/vendor/ggml/examples/magika/CMakeLists.txt +17 -0
- data/vendor/ggml/examples/magika/README.md +23 -0
- data/vendor/ggml/examples/magika/convert.py +32 -0
- data/vendor/ggml/examples/magika/main.cpp +374 -0
- data/vendor/ggml/examples/mnist/CMakeLists.txt +58 -0
- data/vendor/ggml/examples/mnist/README.md +206 -0
- data/vendor/ggml/examples/mnist/mnist-common.cpp +496 -0
- data/vendor/ggml/examples/mnist/mnist-common.h +166 -0
- data/vendor/ggml/examples/mnist/mnist-eval.cpp +67 -0
- data/vendor/ggml/examples/mnist/mnist-train-cnn.py +91 -0
- data/vendor/ggml/examples/mnist/mnist-train-fc.py +131 -0
- data/vendor/ggml/examples/mnist/mnist-train.cpp +39 -0
- data/vendor/ggml/examples/mnist/server.py +36 -0
- data/vendor/ggml/examples/mnist/web/index.html +178 -0
- data/vendor/ggml/examples/perf-metal/CMakeLists.txt +7 -0
- data/vendor/ggml/examples/perf-metal/perf-metal.cpp +152 -0
- data/vendor/ggml/examples/prompts/dolly-v2.txt +100 -0
- data/vendor/ggml/examples/prompts/gpt-2-chinese.txt +1 -0
- data/vendor/ggml/examples/prompts/gpt-2.txt +100 -0
- data/vendor/ggml/examples/prompts/gpt-j.txt +100 -0
- data/vendor/ggml/examples/prompts/gpt-neox-japanese.txt +1 -0
- data/vendor/ggml/examples/prompts/gpt-neox.txt +100 -0
- data/vendor/ggml/examples/prompts/polyglot-ko.txt +3 -0
- data/vendor/ggml/examples/prompts/replit.txt +100 -0
- data/vendor/ggml/examples/prompts/starcoder.txt +100 -0
- data/vendor/ggml/examples/prompts/test-cases.txt +110 -0
- data/vendor/ggml/examples/prompts/tokenize_huggingface.py +65 -0
- data/vendor/ggml/examples/prompts/whisper.txt +100 -0
- data/vendor/ggml/examples/python/README.md +115 -0
- data/vendor/ggml/examples/python/api.h +14 -0
- data/vendor/ggml/examples/python/example_add_quant.py +25 -0
- data/vendor/ggml/examples/python/example_test_all_quants.py +68 -0
- data/vendor/ggml/examples/python/ggml/__init__.py +58 -0
- data/vendor/ggml/examples/python/ggml/__init__.pyi +2406 -0
- data/vendor/ggml/examples/python/ggml/cffi.py +11 -0
- data/vendor/ggml/examples/python/ggml/ffi/__init__.pyi +7 -0
- data/vendor/ggml/examples/python/ggml/utils.py +182 -0
- data/vendor/ggml/examples/python/regenerate.py +42 -0
- data/vendor/ggml/examples/python/stubs.py +128 -0
- data/vendor/ggml/examples/python/test_tensor.py +258 -0
- data/vendor/ggml/examples/sam/CMakeLists.txt +13 -0
- data/vendor/ggml/examples/sam/README.md +95 -0
- data/vendor/ggml/examples/sam/convert-pth-to-ggml.py +147 -0
- data/vendor/ggml/examples/sam/example.jpg +0 -0
- data/vendor/ggml/examples/sam/sam.cpp +2370 -0
- data/vendor/ggml/examples/simple/CMakeLists.txt +21 -0
- data/vendor/ggml/examples/simple/README.md +61 -0
- data/vendor/ggml/examples/simple/simple-backend.cpp +153 -0
- data/vendor/ggml/examples/simple/simple-ctx.cpp +127 -0
- data/vendor/ggml/examples/stb_image.h +7987 -0
- data/vendor/ggml/examples/stb_image_write.h +1724 -0
- data/vendor/ggml/examples/test-cmake/CMakeLists.txt +10 -0
- data/vendor/ggml/examples/test-cmake/README.md +3 -0
- data/vendor/ggml/examples/test-cmake/test-cmake.cpp +6 -0
- data/vendor/ggml/examples/yolo/CMakeLists.txt +6 -0
- data/vendor/ggml/examples/yolo/README.md +59 -0
- data/vendor/ggml/examples/yolo/convert-yolov3-tiny.py +53 -0
- data/vendor/ggml/examples/yolo/data/coco.names +80 -0
- data/vendor/ggml/examples/yolo/data/labels/100_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/100_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/101_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/102_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/103_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/104_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/105_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/106_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/107_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/108_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/109_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/110_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/111_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/112_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/113_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/114_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/115_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/116_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/117_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/118_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/119_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/120_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/121_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/122_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/123_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/124_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/125_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/126_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/32_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/33_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/34_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/35_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/36_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/37_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/38_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/39_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/40_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/41_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/42_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/43_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/44_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/45_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/46_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/47_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/48_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/49_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/50_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/51_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/52_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/53_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/54_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/55_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/56_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/57_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/58_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/59_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/60_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/61_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/62_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/63_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/64_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/65_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/66_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/67_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/68_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/69_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/70_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/71_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/72_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/73_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/74_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/75_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/76_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/77_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/78_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/79_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/80_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/81_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/82_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/83_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/84_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/85_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/86_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/87_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/88_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/89_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/90_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/91_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/92_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/93_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/94_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/95_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/96_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/97_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/98_7.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_0.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_1.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_2.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_3.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_4.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_5.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_6.png +0 -0
- data/vendor/ggml/examples/yolo/data/labels/99_7.png +0 -0
- data/vendor/ggml/examples/yolo/yolo-image.cpp +210 -0
- data/vendor/ggml/examples/yolo/yolo-image.h +39 -0
- data/vendor/ggml/examples/yolo/yolov3-tiny.cpp +661 -0
- data/vendor/ggml/ggml.pc.in +10 -0
- data/vendor/ggml/include/ggml-alloc.h +85 -0
- data/vendor/ggml/include/ggml-backend.h +431 -0
- data/vendor/ggml/include/ggml-blas.h +25 -0
- data/vendor/ggml/include/ggml-cann.h +123 -0
- data/vendor/ggml/include/ggml-cpp.h +39 -0
- data/vendor/ggml/include/ggml-cpu.h +151 -0
- data/vendor/ggml/include/ggml-cuda.h +50 -0
- data/vendor/ggml/include/ggml-hexagon.h +19 -0
- data/vendor/ggml/include/ggml-metal.h +61 -0
- data/vendor/ggml/include/ggml-opencl.h +26 -0
- data/vendor/ggml/include/ggml-openvino.h +37 -0
- data/vendor/ggml/include/ggml-opt.h +256 -0
- data/vendor/ggml/include/ggml-rpc.h +35 -0
- data/vendor/ggml/include/ggml-sycl.h +49 -0
- data/vendor/ggml/include/ggml-virtgpu.h +14 -0
- data/vendor/ggml/include/ggml-vulkan.h +29 -0
- data/vendor/ggml/include/ggml-webgpu.h +19 -0
- data/vendor/ggml/include/ggml-zdnn.h +17 -0
- data/vendor/ggml/include/ggml-zendnn.h +22 -0
- data/vendor/ggml/include/ggml.h +2845 -0
- data/vendor/ggml/include/gguf.h +204 -0
- data/vendor/ggml/requirements.txt +12 -0
- data/vendor/ggml/scripts/gen-authors.sh +9 -0
- data/vendor/ggml/scripts/release.sh +296 -0
- data/vendor/ggml/scripts/sync-llama-am.sh +167 -0
- data/vendor/ggml/scripts/sync-llama.last +1 -0
- data/vendor/ggml/scripts/sync-llama.sh +21 -0
- data/vendor/ggml/scripts/sync-whisper-am.sh +138 -0
- data/vendor/ggml/scripts/sync-whisper.last +1 -0
- data/vendor/ggml/scripts/sync-whisper.sh +17 -0
- data/vendor/ggml/src/CMakeLists.txt +493 -0
- data/vendor/ggml/src/ggml-alloc.c +1248 -0
- data/vendor/ggml/src/ggml-backend-dl.cpp +48 -0
- data/vendor/ggml/src/ggml-backend-dl.h +45 -0
- data/vendor/ggml/src/ggml-backend-impl.h +275 -0
- data/vendor/ggml/src/ggml-backend-meta.cpp +2144 -0
- data/vendor/ggml/src/ggml-backend-reg.cpp +586 -0
- data/vendor/ggml/src/ggml-backend.cpp +2371 -0
- data/vendor/ggml/src/ggml-blas/CMakeLists.txt +101 -0
- data/vendor/ggml/src/ggml-blas/ggml-blas.cpp +522 -0
- data/vendor/ggml/src/ggml-cann/CMakeLists.txt +89 -0
- data/vendor/ggml/src/ggml-cann/acl_tensor.cpp +195 -0
- data/vendor/ggml/src/ggml-cann/acl_tensor.h +349 -0
- data/vendor/ggml/src/ggml-cann/aclnn_ops.cpp +4436 -0
- data/vendor/ggml/src/ggml-cann/aclnn_ops.h +1190 -0
- data/vendor/ggml/src/ggml-cann/common.h +651 -0
- data/vendor/ggml/src/ggml-cann/ggml-cann.cpp +3062 -0
- data/vendor/ggml/src/ggml-common.h +1900 -0
- data/vendor/ggml/src/ggml-cpu/CMakeLists.txt +731 -0
- data/vendor/ggml/src/ggml-cpu/amx/amx.cpp +249 -0
- data/vendor/ggml/src/ggml-cpu/amx/amx.h +8 -0
- data/vendor/ggml/src/ggml-cpu/amx/common.h +115 -0
- data/vendor/ggml/src/ggml-cpu/amx/mmq.cpp +2512 -0
- data/vendor/ggml/src/ggml-cpu/amx/mmq.h +10 -0
- data/vendor/ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp +98 -0
- data/vendor/ggml/src/ggml-cpu/arch/arm/quants.c +4245 -0
- data/vendor/ggml/src/ggml-cpu/arch/arm/repack.cpp +5156 -0
- data/vendor/ggml/src/ggml-cpu/arch/loongarch/quants.c +2158 -0
- data/vendor/ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp +82 -0
- data/vendor/ggml/src/ggml-cpu/arch/powerpc/quants.c +2304 -0
- data/vendor/ggml/src/ggml-cpu/arch/riscv/cpu-feats.cpp +38 -0
- data/vendor/ggml/src/ggml-cpu/arch/riscv/quants.c +4553 -0
- data/vendor/ggml/src/ggml-cpu/arch/riscv/repack.cpp +1703 -0
- data/vendor/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp +50 -0
- data/vendor/ggml/src/ggml-cpu/arch/s390/quants.c +1465 -0
- data/vendor/ggml/src/ggml-cpu/arch/wasm/quants.c +1220 -0
- data/vendor/ggml/src/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
- data/vendor/ggml/src/ggml-cpu/arch/x86/quants.c +3970 -0
- data/vendor/ggml/src/ggml-cpu/arch/x86/repack.cpp +6407 -0
- data/vendor/ggml/src/ggml-cpu/arch-fallback.h +348 -0
- data/vendor/ggml/src/ggml-cpu/binary-ops.cpp +154 -0
- data/vendor/ggml/src/ggml-cpu/binary-ops.h +16 -0
- data/vendor/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
- data/vendor/ggml/src/ggml-cpu/cmake/FindSMTIME.cmake +32 -0
- data/vendor/ggml/src/ggml-cpu/common.h +95 -0
- data/vendor/ggml/src/ggml-cpu/ggml-cpu-impl.h +539 -0
- data/vendor/ggml/src/ggml-cpu/ggml-cpu.c +3835 -0
- data/vendor/ggml/src/ggml-cpu/ggml-cpu.cpp +703 -0
- data/vendor/ggml/src/ggml-cpu/hbm.cpp +55 -0
- data/vendor/ggml/src/ggml-cpu/hbm.h +8 -0
- data/vendor/ggml/src/ggml-cpu/kleidiai/kernels.cpp +939 -0
- data/vendor/ggml/src/ggml-cpu/kleidiai/kernels.h +90 -0
- data/vendor/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +1513 -0
- data/vendor/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
- data/vendor/ggml/src/ggml-cpu/llamafile/sgemm.cpp +4051 -0
- data/vendor/ggml/src/ggml-cpu/llamafile/sgemm.h +25 -0
- data/vendor/ggml/src/ggml-cpu/ops.cpp +11373 -0
- data/vendor/ggml/src/ggml-cpu/ops.h +119 -0
- data/vendor/ggml/src/ggml-cpu/quants.c +1288 -0
- data/vendor/ggml/src/ggml-cpu/quants.h +103 -0
- data/vendor/ggml/src/ggml-cpu/repack.cpp +4836 -0
- data/vendor/ggml/src/ggml-cpu/repack.h +245 -0
- data/vendor/ggml/src/ggml-cpu/simd-gemm.h +226 -0
- data/vendor/ggml/src/ggml-cpu/simd-mappings.h +1319 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime.cpp +1740 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime.h +21 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime1_kernels.cpp +1027 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime2_kernels.cpp +5768 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime_env.cpp +320 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime_env.h +55 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/ime_kernels.h +189 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/repack.cpp +1795 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/repack.h +14 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/rvv_kernels.cpp +3178 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/rvv_kernels.h +95 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/spine_barrier.h +34 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/spine_mem_pool.cpp +760 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/spine_mem_pool.h +32 -0
- data/vendor/ggml/src/ggml-cpu/spacemit/spine_tcm.h +409 -0
- data/vendor/ggml/src/ggml-cpu/traits.cpp +36 -0
- data/vendor/ggml/src/ggml-cpu/traits.h +38 -0
- data/vendor/ggml/src/ggml-cpu/unary-ops.cpp +337 -0
- data/vendor/ggml/src/ggml-cpu/unary-ops.h +35 -0
- data/vendor/ggml/src/ggml-cpu/vec.cpp +629 -0
- data/vendor/ggml/src/ggml-cpu/vec.h +1588 -0
- data/vendor/ggml/src/ggml-cuda/CMakeLists.txt +268 -0
- data/vendor/ggml/src/ggml-cuda/acc.cu +61 -0
- data/vendor/ggml/src/ggml-cuda/acc.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/add-id.cu +58 -0
- data/vendor/ggml/src/ggml-cuda/add-id.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/allreduce.cu +971 -0
- data/vendor/ggml/src/ggml-cuda/allreduce.cuh +29 -0
- data/vendor/ggml/src/ggml-cuda/arange.cu +34 -0
- data/vendor/ggml/src/ggml-cuda/arange.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/argmax.cu +91 -0
- data/vendor/ggml/src/ggml-cuda/argmax.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/argsort.cu +266 -0
- data/vendor/ggml/src/ggml-cuda/argsort.cuh +19 -0
- data/vendor/ggml/src/ggml-cuda/binbcast.cu +534 -0
- data/vendor/ggml/src/ggml-cuda/binbcast.cuh +12 -0
- data/vendor/ggml/src/ggml-cuda/clamp.cu +45 -0
- data/vendor/ggml/src/ggml-cuda/clamp.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/common.cuh +1489 -0
- data/vendor/ggml/src/ggml-cuda/concat.cu +204 -0
- data/vendor/ggml/src/ggml-cuda/concat.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/conv-transpose-1d.cu +86 -0
- data/vendor/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/conv2d-dw.cu +161 -0
- data/vendor/ggml/src/ggml-cuda/conv2d-dw.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/conv2d-transpose.cu +115 -0
- data/vendor/ggml/src/ggml-cuda/conv2d-transpose.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/conv2d.cu +166 -0
- data/vendor/ggml/src/ggml-cuda/conv2d.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/convert.cu +892 -0
- data/vendor/ggml/src/ggml-cuda/convert.cuh +66 -0
- data/vendor/ggml/src/ggml-cuda/count-equal.cu +64 -0
- data/vendor/ggml/src/ggml-cuda/count-equal.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/cp-async.cuh +57 -0
- data/vendor/ggml/src/ggml-cuda/cpy-utils.cuh +217 -0
- data/vendor/ggml/src/ggml-cuda/cpy.cu +558 -0
- data/vendor/ggml/src/ggml-cuda/cpy.cuh +7 -0
- data/vendor/ggml/src/ggml-cuda/cross-entropy-loss.cu +177 -0
- data/vendor/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
- data/vendor/ggml/src/ggml-cuda/cumsum.cu +307 -0
- data/vendor/ggml/src/ggml-cuda/cumsum.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/dequantize.cuh +99 -0
- data/vendor/ggml/src/ggml-cuda/diag.cu +77 -0
- data/vendor/ggml/src/ggml-cuda/diag.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/diagmask.cu +40 -0
- data/vendor/ggml/src/ggml-cuda/diagmask.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/fattn-common.cuh +1212 -0
- data/vendor/ggml/src/ggml-cuda/fattn-mma-f16.cuh +2020 -0
- data/vendor/ggml/src/ggml-cuda/fattn-tile.cu +61 -0
- data/vendor/ggml/src/ggml-cuda/fattn-tile.cuh +1347 -0
- data/vendor/ggml/src/ggml-cuda/fattn-vec.cuh +600 -0
- data/vendor/ggml/src/ggml-cuda/fattn-wmma-f16.cu +696 -0
- data/vendor/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +51 -0
- data/vendor/ggml/src/ggml-cuda/fattn.cu +562 -0
- data/vendor/ggml/src/ggml-cuda/fattn.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/fill.cu +37 -0
- data/vendor/ggml/src/ggml-cuda/fill.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/gated_delta_net.cu +311 -0
- data/vendor/ggml/src/ggml-cuda/gated_delta_net.cuh +4 -0
- data/vendor/ggml/src/ggml-cuda/getrows.cu +300 -0
- data/vendor/ggml/src/ggml-cuda/getrows.cuh +15 -0
- data/vendor/ggml/src/ggml-cuda/ggml-cuda.cu +5684 -0
- data/vendor/ggml/src/ggml-cuda/gla.cu +93 -0
- data/vendor/ggml/src/ggml-cuda/gla.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/im2col.cu +267 -0
- data/vendor/ggml/src/ggml-cuda/im2col.cuh +6 -0
- data/vendor/ggml/src/ggml-cuda/mean.cu +75 -0
- data/vendor/ggml/src/ggml-cuda/mean.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/mma.cuh +1456 -0
- data/vendor/ggml/src/ggml-cuda/mmf.cu +191 -0
- data/vendor/ggml/src/ggml-cuda/mmf.cuh +908 -0
- data/vendor/ggml/src/ggml-cuda/mmid.cu +164 -0
- data/vendor/ggml/src/ggml-cuda/mmid.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/mmq.cu +372 -0
- data/vendor/ggml/src/ggml-cuda/mmq.cuh +4176 -0
- data/vendor/ggml/src/ggml-cuda/mmvf.cu +862 -0
- data/vendor/ggml/src/ggml-cuda/mmvf.cuh +14 -0
- data/vendor/ggml/src/ggml-cuda/mmvq.cu +1161 -0
- data/vendor/ggml/src/ggml-cuda/mmvq.cuh +16 -0
- data/vendor/ggml/src/ggml-cuda/norm.cu +672 -0
- data/vendor/ggml/src/ggml-cuda/norm.cuh +18 -0
- data/vendor/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
- data/vendor/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/opt-step-sgd.cu +49 -0
- data/vendor/ggml/src/ggml-cuda/opt-step-sgd.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/out-prod.cu +84 -0
- data/vendor/ggml/src/ggml-cuda/out-prod.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/pad.cu +106 -0
- data/vendor/ggml/src/ggml-cuda/pad.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/pad_reflect_1d.cu +91 -0
- data/vendor/ggml/src/ggml-cuda/pad_reflect_1d.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/pool2d.cu +94 -0
- data/vendor/ggml/src/ggml-cuda/pool2d.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/quantize.cu +443 -0
- data/vendor/ggml/src/ggml-cuda/quantize.cuh +41 -0
- data/vendor/ggml/src/ggml-cuda/reduce_rows.cuh +39 -0
- data/vendor/ggml/src/ggml-cuda/roll.cu +67 -0
- data/vendor/ggml/src/ggml-cuda/roll.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/rope.cu +665 -0
- data/vendor/ggml/src/ggml-cuda/rope.cuh +9 -0
- data/vendor/ggml/src/ggml-cuda/scale.cu +34 -0
- data/vendor/ggml/src/ggml-cuda/scale.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/set-rows.cu +330 -0
- data/vendor/ggml/src/ggml-cuda/set-rows.cuh +7 -0
- data/vendor/ggml/src/ggml-cuda/set.cu +39 -0
- data/vendor/ggml/src/ggml-cuda/set.cuh +7 -0
- data/vendor/ggml/src/ggml-cuda/snake.cu +72 -0
- data/vendor/ggml/src/ggml-cuda/snake.cuh +8 -0
- data/vendor/ggml/src/ggml-cuda/softcap.cu +34 -0
- data/vendor/ggml/src/ggml-cuda/softcap.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/softmax.cu +472 -0
- data/vendor/ggml/src/ggml-cuda/softmax.cuh +7 -0
- data/vendor/ggml/src/ggml-cuda/solve_tri.cu +275 -0
- data/vendor/ggml/src/ggml-cuda/solve_tri.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/ssm-conv.cu +197 -0
- data/vendor/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/ssm-scan.cu +342 -0
- data/vendor/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/sum.cu +41 -0
- data/vendor/ggml/src/ggml-cuda/sum.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/sumrows.cu +43 -0
- data/vendor/ggml/src/ggml-cuda/sumrows.cuh +4 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +6 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_32.cu +6 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +6 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_32.cu +6 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +6 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +12 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq112-dv112.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq128-dv128.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq192-dv128.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq256-dv256.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq320-dv256.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq40-dv40.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq512-dv512.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq576-dv512.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq64-dv64.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq72-dv72.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq80-dv80.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq96-dv96.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-bf16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-f16.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_1.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q8_0.cu +7 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/generate_cu_files.py +110 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_1.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_10.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_11.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_12.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_13.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_14.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_15.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_16.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_2.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_3.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_4.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_5.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_6.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_7.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_8.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_9.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-mxfp4.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-nvfp4.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q1_0.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
- data/vendor/ggml/src/ggml-cuda/top-k.cu +95 -0
- data/vendor/ggml/src/ggml-cuda/top-k.cuh +3 -0
- data/vendor/ggml/src/ggml-cuda/topk-moe.cu +415 -0
- data/vendor/ggml/src/ggml-cuda/topk-moe.cuh +27 -0
- data/vendor/ggml/src/ggml-cuda/tri.cu +136 -0
- data/vendor/ggml/src/ggml-cuda/tri.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/tsembd.cu +47 -0
- data/vendor/ggml/src/ggml-cuda/tsembd.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/unary.cu +640 -0
- data/vendor/ggml/src/ggml-cuda/unary.cuh +114 -0
- data/vendor/ggml/src/ggml-cuda/upscale.cu +293 -0
- data/vendor/ggml/src/ggml-cuda/upscale.cuh +5 -0
- data/vendor/ggml/src/ggml-cuda/vecdotq.cuh +1317 -0
- data/vendor/ggml/src/ggml-cuda/vendors/cuda.h +28 -0
- data/vendor/ggml/src/ggml-cuda/vendors/hip.h +304 -0
- data/vendor/ggml/src/ggml-cuda/vendors/musa.h +150 -0
- data/vendor/ggml/src/ggml-cuda/wkv.cu +199 -0
- data/vendor/ggml/src/ggml-cuda/wkv.cuh +7 -0
- data/vendor/ggml/src/ggml-hexagon/CMakeLists.txt +118 -0
- data/vendor/ggml/src/ggml-hexagon/ggml-hexagon.cpp +3680 -0
- data/vendor/ggml/src/ggml-hexagon/htp/CMakeLists.txt +78 -0
- data/vendor/ggml/src/ggml-hexagon/htp/act-ops.c +782 -0
- data/vendor/ggml/src/ggml-hexagon/htp/argsort-ops.c +293 -0
- data/vendor/ggml/src/ggml-hexagon/htp/binary-ops.c +872 -0
- data/vendor/ggml/src/ggml-hexagon/htp/cmake-toolchain.cmake +157 -0
- data/vendor/ggml/src/ggml-hexagon/htp/cpy-ops.c +275 -0
- data/vendor/ggml/src/ggml-hexagon/htp/cumsum-ops.c +270 -0
- data/vendor/ggml/src/ggml-hexagon/htp/diag-ops.c +216 -0
- data/vendor/ggml/src/ggml-hexagon/htp/fill-ops.c +123 -0
- data/vendor/ggml/src/ggml-hexagon/htp/flash-attn-ops.c +727 -0
- data/vendor/ggml/src/ggml-hexagon/htp/gated-delta-net-ops.c +955 -0
- data/vendor/ggml/src/ggml-hexagon/htp/get-rows-ops.c +124 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hex-dma.c +63 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hex-dma.h +372 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hex-dump.h +86 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hex-fastdiv.h +37 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hex-utils.h +137 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-flash-attn-ops.c +1841 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-matmul-ops.c +1785 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-ops.h +71 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-profile.h +34 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-queue.c +158 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-queue.h +134 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hmx-utils.h +200 -0
- data/vendor/ggml/src/ggml-hexagon/htp/htp-ctx.h +111 -0
- data/vendor/ggml/src/ggml-hexagon/htp/htp-ops.h +181 -0
- data/vendor/ggml/src/ggml-hexagon/htp/htp_iface.idl +22 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-arith.h +443 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-base.h +308 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-copy.h +262 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-div.h +291 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-dump.h +129 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-exp.h +216 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-floor.h +100 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-inverse.h +210 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-reduce.h +296 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-repl.h +74 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-scale.h +133 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-sigmoid.h +142 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-sqrt.h +126 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-types.h +36 -0
- data/vendor/ggml/src/ggml-hexagon/htp/hvx-utils.h +19 -0
- data/vendor/ggml/src/ggml-hexagon/htp/main.c +880 -0
- data/vendor/ggml/src/ggml-hexagon/htp/matmul-ops.c +3173 -0
- data/vendor/ggml/src/ggml-hexagon/htp/repeat-ops.c +148 -0
- data/vendor/ggml/src/ggml-hexagon/htp/rope-ops.c +494 -0
- data/vendor/ggml/src/ggml-hexagon/htp/set-rows-ops.c +184 -0
- data/vendor/ggml/src/ggml-hexagon/htp/softmax-ops.c +407 -0
- data/vendor/ggml/src/ggml-hexagon/htp/solve-tri-ops.c +267 -0
- data/vendor/ggml/src/ggml-hexagon/htp/ssm-conv.c +340 -0
- data/vendor/ggml/src/ggml-hexagon/htp/sum-rows-ops.c +128 -0
- data/vendor/ggml/src/ggml-hexagon/htp/unary-ops.c +657 -0
- data/vendor/ggml/src/ggml-hexagon/htp/vtcm-utils.h +16 -0
- data/vendor/ggml/src/ggml-hexagon/htp/worker-pool.c +293 -0
- data/vendor/ggml/src/ggml-hexagon/htp/worker-pool.h +57 -0
- data/vendor/ggml/src/ggml-hexagon/htp-drv.cpp +418 -0
- data/vendor/ggml/src/ggml-hexagon/htp-drv.h +121 -0
- data/vendor/ggml/src/ggml-hexagon/libdl.h +79 -0
- data/vendor/ggml/src/ggml-hexagon/libggml-htp.inf +40 -0
- data/vendor/ggml/src/ggml-hexagon/op-desc.h +153 -0
- data/vendor/ggml/src/ggml-hip/CMakeLists.txt +157 -0
- data/vendor/ggml/src/ggml-impl.h +783 -0
- data/vendor/ggml/src/ggml-metal/CMakeLists.txt +124 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-common.cpp +457 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-common.h +52 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-context.h +41 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-context.m +739 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-device.cpp +2053 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-device.h +296 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-device.m +1829 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-impl.h +1175 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-ops.cpp +4606 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal-ops.h +97 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal.cpp +950 -0
- data/vendor/ggml/src/ggml-metal/ggml-metal.metal +10679 -0
- data/vendor/ggml/src/ggml-musa/CMakeLists.txt +124 -0
- data/vendor/ggml/src/ggml-musa/mudnn.cu +112 -0
- data/vendor/ggml/src/ggml-musa/mudnn.cuh +12 -0
- data/vendor/ggml/src/ggml-opencl/CMakeLists.txt +189 -0
- data/vendor/ggml/src/ggml-opencl/ggml-opencl.cpp +16374 -0
- data/vendor/ggml/src/ggml-opencl/kernels/add.cl +190 -0
- data/vendor/ggml/src/ggml-opencl/kernels/add_id.cl +42 -0
- data/vendor/ggml/src/ggml-opencl/kernels/argsort.cl +86 -0
- data/vendor/ggml/src/ggml-opencl/kernels/clamp.cl +20 -0
- data/vendor/ggml/src/ggml-opencl/kernels/concat.cl +51 -0
- data/vendor/ggml/src/ggml-opencl/kernels/conv2d.cl +185 -0
- data/vendor/ggml/src/ggml-opencl/kernels/conv2d_f16_f32.cl +176 -0
- data/vendor/ggml/src/ggml-opencl/kernels/cpy.cl +229 -0
- data/vendor/ggml/src/ggml-opencl/kernels/cumsum.cl +139 -0
- data/vendor/ggml/src/ggml-opencl/kernels/cvt.cl +1471 -0
- data/vendor/ggml/src/ggml-opencl/kernels/diag.cl +27 -0
- data/vendor/ggml/src/ggml-opencl/kernels/diag_mask_inf.cl +58 -0
- data/vendor/ggml/src/ggml-opencl/kernels/div.cl +138 -0
- data/vendor/ggml/src/ggml-opencl/kernels/embed_kernel.py +26 -0
- data/vendor/ggml/src/ggml-opencl/kernels/exp.cl +125 -0
- data/vendor/ggml/src/ggml-opencl/kernels/expm1.cl +113 -0
- data/vendor/ggml/src/ggml-opencl/kernels/fill.cl +17 -0
- data/vendor/ggml/src/ggml-opencl/kernels/flash_attn_f16.cl +370 -0
- data/vendor/ggml/src/ggml-opencl/kernels/flash_attn_f32.cl +371 -0
- data/vendor/ggml/src/ggml-opencl/kernels/flash_attn_f32_f16.cl +373 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gelu.cl +89 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_mxfp4_f32.cl +162 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_mxfp4_f32_ns.cl +302 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_q4_0_f32_ns.cl +252 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_q4_1_f32_ns.cl +254 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_q5_0_f32_ns.cl +256 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_moe_q5_1_f32_ns.cl +258 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_iq4_nl_f32.cl +150 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q4_0_f32.cl +139 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q4_1_f32.cl +132 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q4_k_f32.cl +172 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q5_k_f32.cl +176 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q6_k_f32.cl +140 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q8_0_f32.cl +129 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemm_xmem_f16_f32_os8.cl +233 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_mxfp4_f32.cl +156 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_mxfp4_f32_ns.cl +161 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_q4_0_f32_ns.cl +116 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_q4_1_f32_ns.cl +119 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_q5_0_f32_ns.cl +119 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_moe_q5_1_f32_ns.cl +121 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_iq4_nl_f32.cl +302 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q4_0_f32.cl +274 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q4_0_f32_spec.cl +268 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q4_1_f32.cl +283 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q4_k_f32.cl +318 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q5_k_f32.cl +326 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q6_k_f32.cl +293 -0
- data/vendor/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q8_0_f32.cl +195 -0
- data/vendor/ggml/src/ggml-opencl/kernels/get_rows.cl +187 -0
- data/vendor/ggml/src/ggml-opencl/kernels/glu.cl +378 -0
- data/vendor/ggml/src/ggml-opencl/kernels/group_norm.cl +121 -0
- data/vendor/ggml/src/ggml-opencl/kernels/im2col_f16.cl +57 -0
- data/vendor/ggml/src/ggml-opencl/kernels/im2col_f32.cl +57 -0
- data/vendor/ggml/src/ggml-opencl/kernels/l2_norm.cl +71 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mean.cl +140 -0
- data/vendor/ggml/src/ggml-opencl/kernels/moe_reorder_b.cl +30 -0
- data/vendor/ggml/src/ggml-opencl/kernels/moe_sort_by_expert.cl +82 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul.cl +152 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mat_f16_f32.cl +130 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_f16_f32_kq_kqv.cl +273 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_f16_f32_l4_lm.cl +146 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_f32_f32_l4_lm.cl +147 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_iq4_nl_f32_l4_lm.cl +171 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q4_0_f32_l4_lm.cl +163 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q4_1_f32_l4_lm.cl +165 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q4_k_f32_l4_lm.cl +179 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q5_k_f32_l4_lm.cl +192 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q6_k_f32_l4_lm.cl +158 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mm_q8_0_f32_l4_lm.cl +154 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_f16_f16.cl +118 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32.cl +118 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_1row.cl +94 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_l4.cl +84 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_f32_f32.cl +118 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_id_mxfp4_f32.cl +189 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_id_mxfp4_f32_flat.cl +176 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_id_q4_0_f32_8x_flat.cl +283 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_id_q8_0_f32.cl +140 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_id_q8_0_f32_flat.cl +222 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_iq4_nl_f32.cl +164 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_iq4_nl_f32_flat.cl +202 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_mxfp4_f32.cl +144 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_mxfp4_f32_flat.cl +167 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32.cl +192 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_1d_16x_flat.cl +307 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_1d_8x_flat.cl +265 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_8x_flat.cl +272 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_v.cl +254 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_1_f32.cl +219 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_1_f32_flat.cl +229 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_k_f32.cl +180 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q4_k_f32_flat.cl +196 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q5_k_f32.cl +187 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q5_k_f32_flat.cl +203 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q6_k_f32.cl +194 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q6_k_f32_flat.cl +194 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q8_0_f32.cl +125 -0
- data/vendor/ggml/src/ggml-opencl/kernels/mul_mv_q8_0_f32_flat.cl +202 -0
- data/vendor/ggml/src/ggml-opencl/kernels/neg.cl +125 -0
- data/vendor/ggml/src/ggml-opencl/kernels/norm.cl +161 -0
- data/vendor/ggml/src/ggml-opencl/kernels/pad.cl +39 -0
- data/vendor/ggml/src/ggml-opencl/kernels/relu.cl +16 -0
- data/vendor/ggml/src/ggml-opencl/kernels/repeat.cl +38 -0
- data/vendor/ggml/src/ggml-opencl/kernels/rms_norm.cl +190 -0
- data/vendor/ggml/src/ggml-opencl/kernels/rope.cl +747 -0
- data/vendor/ggml/src/ggml-opencl/kernels/scale.cl +27 -0
- data/vendor/ggml/src/ggml-opencl/kernels/set_rows.cl +208 -0
- data/vendor/ggml/src/ggml-opencl/kernels/sigmoid.cl +29 -0
- data/vendor/ggml/src/ggml-opencl/kernels/silu.cl +30 -0
- data/vendor/ggml/src/ggml-opencl/kernels/softmax_4_f16.cl +108 -0
- data/vendor/ggml/src/ggml-opencl/kernels/softmax_4_f32.cl +108 -0
- data/vendor/ggml/src/ggml-opencl/kernels/softmax_f16.cl +107 -0
- data/vendor/ggml/src/ggml-opencl/kernels/softmax_f32.cl +107 -0
- data/vendor/ggml/src/ggml-opencl/kernels/softplus.cl +116 -0
- data/vendor/ggml/src/ggml-opencl/kernels/solve_tri.cl +51 -0
- data/vendor/ggml/src/ggml-opencl/kernels/sqr.cl +53 -0
- data/vendor/ggml/src/ggml-opencl/kernels/sqrt.cl +53 -0
- data/vendor/ggml/src/ggml-opencl/kernels/ssm_conv.cl +77 -0
- data/vendor/ggml/src/ggml-opencl/kernels/sub.cl +138 -0
- data/vendor/ggml/src/ggml-opencl/kernels/sum_rows.cl +140 -0
- data/vendor/ggml/src/ggml-opencl/kernels/tanh.cl +109 -0
- data/vendor/ggml/src/ggml-opencl/kernels/transpose.cl +143 -0
- data/vendor/ggml/src/ggml-opencl/kernels/tri.cl +32 -0
- data/vendor/ggml/src/ggml-opencl/kernels/tsembd.cl +48 -0
- data/vendor/ggml/src/ggml-opencl/kernels/upscale.cl +120 -0
- data/vendor/ggml/src/ggml-openvino/CMakeLists.txt +22 -0
- data/vendor/ggml/src/ggml-openvino/ggml-decoder.cpp +985 -0
- data/vendor/ggml/src/ggml-openvino/ggml-decoder.h +294 -0
- data/vendor/ggml/src/ggml-openvino/ggml-openvino-extra.cpp +380 -0
- data/vendor/ggml/src/ggml-openvino/ggml-openvino-extra.h +182 -0
- data/vendor/ggml/src/ggml-openvino/ggml-openvino.cpp +1132 -0
- data/vendor/ggml/src/ggml-openvino/ggml-quants.cpp +956 -0
- data/vendor/ggml/src/ggml-openvino/ggml-quants.h +153 -0
- data/vendor/ggml/src/ggml-openvino/openvino/decoder.h +74 -0
- data/vendor/ggml/src/ggml-openvino/openvino/frontend.cpp +27 -0
- data/vendor/ggml/src/ggml-openvino/openvino/frontend.h +23 -0
- data/vendor/ggml/src/ggml-openvino/openvino/input_model.cpp +17 -0
- data/vendor/ggml/src/ggml-openvino/openvino/input_model.h +29 -0
- data/vendor/ggml/src/ggml-openvino/openvino/node_context.h +112 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/cont.cpp +48 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/cpy.cpp +21 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/flash_attn_ext.cpp +90 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/get_rows.cpp +69 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/glu_geglu.cpp +61 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/glu_swiglu.cpp +62 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/mulmat.cpp +90 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/permute.cpp +102 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/reshape.cpp +83 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/rms_norm.cpp +46 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/rope.cpp +149 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/scale.cpp +41 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/set_rows.cpp +76 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/softmax.cpp +89 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/transpose.cpp +23 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/unary_gelu.cpp +25 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/unary_silu.cpp +27 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op/view.cpp +53 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op_table.cpp +47 -0
- data/vendor/ggml/src/ggml-openvino/openvino/op_table.h +40 -0
- data/vendor/ggml/src/ggml-openvino/openvino/pass/fuse_to_sdpa.cpp +60 -0
- data/vendor/ggml/src/ggml-openvino/openvino/pass/fuse_to_sdpa.h +17 -0
- data/vendor/ggml/src/ggml-openvino/openvino/pass/mark_decompression_convert_constant_folding.h +29 -0
- data/vendor/ggml/src/ggml-openvino/openvino/pass/squeeze_matmul.cpp +58 -0
- data/vendor/ggml/src/ggml-openvino/openvino/pass/squeeze_matmul.h +17 -0
- data/vendor/ggml/src/ggml-openvino/openvino/rt_info/weightless_caching_attributes.hpp +41 -0
- data/vendor/ggml/src/ggml-openvino/openvino/translate_session.cpp +317 -0
- data/vendor/ggml/src/ggml-openvino/openvino/translate_session.h +28 -0
- data/vendor/ggml/src/ggml-openvino/openvino/utils.cpp +257 -0
- data/vendor/ggml/src/ggml-openvino/openvino/utils.h +86 -0
- data/vendor/ggml/src/ggml-openvino/utils.cpp +880 -0
- data/vendor/ggml/src/ggml-openvino/utils.h +143 -0
- data/vendor/ggml/src/ggml-opt.cpp +1094 -0
- data/vendor/ggml/src/ggml-quants.c +5491 -0
- data/vendor/ggml/src/ggml-quants.h +112 -0
- data/vendor/ggml/src/ggml-rpc/CMakeLists.txt +33 -0
- data/vendor/ggml/src/ggml-rpc/ggml-rpc.cpp +1974 -0
- data/vendor/ggml/src/ggml-rpc/transport.cpp +683 -0
- data/vendor/ggml/src/ggml-rpc/transport.h +34 -0
- data/vendor/ggml/src/ggml-sycl/CMakeLists.txt +207 -0
- data/vendor/ggml/src/ggml-sycl/add-id.cpp +81 -0
- data/vendor/ggml/src/ggml-sycl/add-id.hpp +8 -0
- data/vendor/ggml/src/ggml-sycl/backend.hpp +48 -0
- data/vendor/ggml/src/ggml-sycl/binbcast.cpp +346 -0
- data/vendor/ggml/src/ggml-sycl/binbcast.hpp +39 -0
- data/vendor/ggml/src/ggml-sycl/common.cpp +155 -0
- data/vendor/ggml/src/ggml-sycl/common.hpp +1002 -0
- data/vendor/ggml/src/ggml-sycl/concat.cpp +202 -0
- data/vendor/ggml/src/ggml-sycl/concat.hpp +20 -0
- data/vendor/ggml/src/ggml-sycl/conv.cpp +101 -0
- data/vendor/ggml/src/ggml-sycl/conv.hpp +20 -0
- data/vendor/ggml/src/ggml-sycl/convert.cpp +825 -0
- data/vendor/ggml/src/ggml-sycl/convert.hpp +64 -0
- data/vendor/ggml/src/ggml-sycl/count-equal.cpp +79 -0
- data/vendor/ggml/src/ggml-sycl/count-equal.hpp +9 -0
- data/vendor/ggml/src/ggml-sycl/cpy.cpp +602 -0
- data/vendor/ggml/src/ggml-sycl/cpy.hpp +223 -0
- data/vendor/ggml/src/ggml-sycl/cumsum.cpp +148 -0
- data/vendor/ggml/src/ggml-sycl/cumsum.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/dequantize.hpp +975 -0
- data/vendor/ggml/src/ggml-sycl/diag.cpp +67 -0
- data/vendor/ggml/src/ggml-sycl/diag.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/dmmv.cpp +1579 -0
- data/vendor/ggml/src/ggml-sycl/dmmv.hpp +27 -0
- data/vendor/ggml/src/ggml-sycl/dpct/helper.hpp +3774 -0
- data/vendor/ggml/src/ggml-sycl/element_wise.cpp +1124 -0
- data/vendor/ggml/src/ggml-sycl/element_wise.hpp +94 -0
- data/vendor/ggml/src/ggml-sycl/fattn-buffers.cpp +56 -0
- data/vendor/ggml/src/ggml-sycl/fattn-buffers.hpp +63 -0
- data/vendor/ggml/src/ggml-sycl/fattn-common.hpp +1181 -0
- data/vendor/ggml/src/ggml-sycl/fattn-tile.cpp +59 -0
- data/vendor/ggml/src/ggml-sycl/fattn-tile.hpp +1246 -0
- data/vendor/ggml/src/ggml-sycl/fattn-vec.hpp +674 -0
- data/vendor/ggml/src/ggml-sycl/fattn.cpp +227 -0
- data/vendor/ggml/src/ggml-sycl/fattn.hpp +22 -0
- data/vendor/ggml/src/ggml-sycl/fill.cpp +55 -0
- data/vendor/ggml/src/ggml-sycl/fill.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/gated_delta_net.cpp +307 -0
- data/vendor/ggml/src/ggml-sycl/gated_delta_net.hpp +9 -0
- data/vendor/ggml/src/ggml-sycl/gemm.hpp +93 -0
- data/vendor/ggml/src/ggml-sycl/getrows.cpp +219 -0
- data/vendor/ggml/src/ggml-sycl/getrows.hpp +20 -0
- data/vendor/ggml/src/ggml-sycl/ggml-sycl.cpp +5520 -0
- data/vendor/ggml/src/ggml-sycl/gla.cpp +106 -0
- data/vendor/ggml/src/ggml-sycl/gla.hpp +8 -0
- data/vendor/ggml/src/ggml-sycl/im2col.cpp +400 -0
- data/vendor/ggml/src/ggml-sycl/im2col.hpp +23 -0
- data/vendor/ggml/src/ggml-sycl/mmq.cpp +3030 -0
- data/vendor/ggml/src/ggml-sycl/mmq.hpp +33 -0
- data/vendor/ggml/src/ggml-sycl/mmvq.cpp +1380 -0
- data/vendor/ggml/src/ggml-sycl/mmvq.hpp +43 -0
- data/vendor/ggml/src/ggml-sycl/norm.cpp +656 -0
- data/vendor/ggml/src/ggml-sycl/norm.hpp +28 -0
- data/vendor/ggml/src/ggml-sycl/outprod.cpp +47 -0
- data/vendor/ggml/src/ggml-sycl/outprod.hpp +10 -0
- data/vendor/ggml/src/ggml-sycl/pad.cpp +97 -0
- data/vendor/ggml/src/ggml-sycl/pad.hpp +24 -0
- data/vendor/ggml/src/ggml-sycl/pad_reflect_1d.cpp +100 -0
- data/vendor/ggml/src/ggml-sycl/pad_reflect_1d.hpp +10 -0
- data/vendor/ggml/src/ggml-sycl/presets.hpp +79 -0
- data/vendor/ggml/src/ggml-sycl/quantize.hpp +133 -0
- data/vendor/ggml/src/ggml-sycl/quants.hpp +156 -0
- data/vendor/ggml/src/ggml-sycl/repeat_back.cpp +76 -0
- data/vendor/ggml/src/ggml-sycl/repeat_back.hpp +8 -0
- data/vendor/ggml/src/ggml-sycl/roll.cpp +122 -0
- data/vendor/ggml/src/ggml-sycl/roll.hpp +20 -0
- data/vendor/ggml/src/ggml-sycl/rope.cpp +641 -0
- data/vendor/ggml/src/ggml-sycl/rope.hpp +26 -0
- data/vendor/ggml/src/ggml-sycl/set.cpp +73 -0
- data/vendor/ggml/src/ggml-sycl/set.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/set_rows.cpp +240 -0
- data/vendor/ggml/src/ggml-sycl/set_rows.hpp +8 -0
- data/vendor/ggml/src/ggml-sycl/softmax.cpp +426 -0
- data/vendor/ggml/src/ggml-sycl/softmax.hpp +24 -0
- data/vendor/ggml/src/ggml-sycl/solve_tri.cpp +172 -0
- data/vendor/ggml/src/ggml-sycl/solve_tri.hpp +8 -0
- data/vendor/ggml/src/ggml-sycl/ssm_conv.cpp +132 -0
- data/vendor/ggml/src/ggml-sycl/ssm_conv.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/ssm_scan.cpp +156 -0
- data/vendor/ggml/src/ggml-sycl/ssm_scan.hpp +5 -0
- data/vendor/ggml/src/ggml-sycl/sycl_hw.cpp +67 -0
- data/vendor/ggml/src/ggml-sycl/sycl_hw.hpp +38 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq112-dv112.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq128-dv128.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq256-dv256.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq40-dv40.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq512-dv512.cpp +6 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq576-dv512.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq64-dv64.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq72-dv72.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq80-dv80.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-tile-instance-dkq96-dv96.cpp +5 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_0-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q4_1-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_0-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q5_1-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-f16.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q4_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q4_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q5_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q5_1.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-q8_0.cpp +8 -0
- data/vendor/ggml/src/ggml-sycl/tsembd.cpp +73 -0
- data/vendor/ggml/src/ggml-sycl/tsembd.hpp +20 -0
- data/vendor/ggml/src/ggml-sycl/type.hpp +112 -0
- data/vendor/ggml/src/ggml-sycl/upscale.cpp +410 -0
- data/vendor/ggml/src/ggml-sycl/upscale.hpp +9 -0
- data/vendor/ggml/src/ggml-sycl/vecdotq.hpp +1508 -0
- data/vendor/ggml/src/ggml-sycl/wkv.cpp +293 -0
- data/vendor/ggml/src/ggml-sycl/wkv.hpp +10 -0
- data/vendor/ggml/src/ggml-threading.cpp +12 -0
- data/vendor/ggml/src/ggml-threading.h +14 -0
- data/vendor/ggml/src/ggml-virtgpu/CMakeLists.txt +70 -0
- data/vendor/ggml/src/ggml-virtgpu/apir_cs_ggml-rpc-front.cpp +87 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/CMakeLists.txt +21 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/apir_cs_ggml-rpc-back.cpp +115 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-convert.h +13 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched-backend.cpp +102 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched-buffer-type.cpp +105 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched-buffer.cpp +179 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched-device.cpp +148 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched.cpp +51 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched.gen.h +73 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-dispatched.h +27 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend-virgl-apir.h +32 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/backend.cpp +144 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/api_remoting.h +95 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/apir_backend.gen.h +94 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/apir_backend.h +50 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/apir_cs.h +378 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/apir_cs_ggml.h +232 -0
- data/vendor/ggml/src/ggml-virtgpu/backend/shared/apir_cs_rpc.h +58 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-backend-buffer-type.cpp +81 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-backend-buffer.cpp +123 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-backend-device.cpp +160 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-backend-reg.cpp +213 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-backend.cpp +71 -0
- data/vendor/ggml/src/ggml-virtgpu/ggml-remoting.h +71 -0
- data/vendor/ggml/src/ggml-virtgpu/ggmlremoting_functions.yaml +166 -0
- data/vendor/ggml/src/ggml-virtgpu/include/apir_hw.h +9 -0
- data/vendor/ggml/src/ggml-virtgpu/regenerate_remoting.py +333 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-apir.h +15 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward-backend.cpp +58 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward-buffer-type.cpp +110 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward-buffer.cpp +173 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward-device.cpp +192 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward-impl.h +36 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-forward.gen.h +53 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-shm.cpp +99 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-shm.h +23 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-utils.cpp +179 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu-utils.h +86 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu.cpp +545 -0
- data/vendor/ggml/src/ggml-virtgpu/virtgpu.h +115 -0
- data/vendor/ggml/src/ggml-vulkan/CMakeLists.txt +220 -0
- data/vendor/ggml/src/ggml-vulkan/cmake/host-toolchain.cmake.in +15 -0
- data/vendor/ggml/src/ggml-vulkan/ggml-vulkan.cpp +17208 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +31 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/abs.comp +21 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/acc.comp +37 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/add.comp +69 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/add1.comp +28 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/add_id.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/arange.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/argmax.comp +60 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/argsort.comp +86 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/argsort_large.comp +114 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/ceil.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/concat.comp +41 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/contig_copy.comp +49 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_dw.comp +105 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_mm.comp +347 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/conv_transpose_1d.comp +98 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/copy.comp +23 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/copy_from_quant.comp +51 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp +320 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/copy_transpose.comp +67 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/cos.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/count_equal.comp +31 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/count_experts.comp +51 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/cumsum.comp +83 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/cumsum_multipass1.comp +60 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/cumsum_multipass2.comp +66 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_f32.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs.glsl +653 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs_cm2.glsl +768 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_head.glsl +13 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_m.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_s.comp +35 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_s.comp +44 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xs.comp +43 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xxs.comp +49 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_s.comp +40 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_xxs.comp +51 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_nl.comp +32 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_xs.comp +34 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_mxfp4.comp +32 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_nvfp4.comp +32 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q1_0.comp +29 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q2_k.comp +34 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q3_k.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_0.comp +30 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_1.comp +32 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_k.comp +68 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_0.comp +34 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_1.comp +35 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_k.comp +70 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q6_k.comp +33 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q8_0.comp +31 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp +28 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/diag_mask_inf.comp +34 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/div.comp +27 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/elu.comp +27 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/exp.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/feature-tests/bfloat16.comp +7 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/feature-tests/coopmat.comp +7 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/feature-tests/coopmat2.comp +7 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/feature-tests/integer_dot.comp +7 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/fill.comp +19 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +756 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_base.glsl +255 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +626 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +427 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_dequant.glsl +123 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_mask_opt.comp +162 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_mmq_funcs.glsl +203 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_split_k_reduce.comp +121 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/floor.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/gated_delta_net.comp +190 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/geglu.comp +13 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/geglu_erf.comp +27 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/geglu_quick.comp +11 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/gelu.comp +25 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/gelu_erf.comp +39 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/gelu_quick.comp +23 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/generic_binary_head.glsl +65 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/generic_head.glsl +11 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/generic_unary_head.glsl +83 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/get_rows.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/get_rows_quant.comp +51 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/glu_head.glsl +28 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/glu_main.glsl +39 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/group_norm.comp +66 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/hardsigmoid.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/hardswish.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/im2col.comp +93 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/im2col_3d.comp +124 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +44 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/leaky_relu.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/log.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul.comp +27 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_split_k_reduce.comp +48 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec.comp +169 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_base.glsl +230 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iface.glsl +35 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_m.comp +132 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_s.comp +95 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_s.comp +90 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xs.comp +105 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xxs.comp +87 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_s.comp +90 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_xxs.comp +88 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_nc.comp +124 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_p021.comp +156 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q2_k.comp +128 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q3_k.comp +132 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q4_k.comp +134 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q5_k.comp +165 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q6_k.comp +130 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq.comp +143 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq_funcs.glsl +503 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +464 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +624 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_funcs.glsl +600 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_id_funcs.glsl +74 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp +311 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.glsl +454 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_shmem_types.glsl +93 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/multi_add.comp +194 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/neg.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/norm.comp +44 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/opt_step_adamw.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/opt_step_sgd.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/pad.comp +64 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/pool2d.comp +74 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/quantize_q8_1.comp +127 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/reglu.comp +9 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/relu.comp +21 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/repeat.comp +26 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/repeat_back.comp +37 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm.comp +150 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm_back.comp +55 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm_partials.comp +65 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/roll.comp +46 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_funcs.glsl +207 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_head.glsl +19 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_multi.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_neox.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_norm.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_params.glsl +31 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/rope_vision.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/round.comp +29 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/scale.comp +24 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sgn.comp +21 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sigmoid.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/silu.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/silu_back.comp +26 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sin.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max.comp +195 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_back.comp +54 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large1.comp +62 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large2.comp +79 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large3.comp +65 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_large_common.glsl +53 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/softplus.comp +23 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/solve_tri.comp +81 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sqrt.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/square.comp +17 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/ssm_conv.comp +50 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/ssm_scan.comp +124 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/step.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sub.comp +29 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sum_rows.comp +47 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/sum_rows.glsl +25 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/swiglu.comp +9 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/swiglu_oai.comp +14 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/tanh.comp +20 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/timestep_embedding.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/topk_argsort.comp +118 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/topk_moe.comp +213 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/topk_nary_search.comp +246 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp +42 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/trunc.comp +22 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/types.glsl +1846 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/upscale.comp +178 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/utils.glsl +25 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +1183 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/wkv6.comp +87 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/wkv7.comp +91 -0
- data/vendor/ggml/src/ggml-vulkan/vulkan-shaders/xielu.comp +35 -0
- data/vendor/ggml/src/ggml-webgpu/CMakeLists.txt +80 -0
- data/vendor/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp +3231 -0
- data/vendor/ggml/src/ggml-webgpu/ggml-webgpu.cpp +4461 -0
- data/vendor/ggml/src/ggml-webgpu/pre_wgsl.hpp +778 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/add_id.wgsl +64 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/argmax.wgsl +72 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/argsort.wgsl +106 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/argsort_merge.wgsl +134 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/binary.wgsl +139 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/common_decls.tmpl +905 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/concat.wgsl +75 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/conv2d.wgsl +165 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/cpy.wgsl +81 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/cumsum.wgsl +66 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/embed_wgsl.py +89 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn.wgsl +706 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_tile.wgsl +351 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_blk.wgsl +101 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_reduce.wgsl +84 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_split.wgsl +720 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/gated_delta_net.wgsl +132 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/get_rows.wgsl +773 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/glu.wgsl +155 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/im2col.wgsl +101 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/memset.wgsl +40 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat.wgsl +747 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_decls.tmpl +1210 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id.wgsl +195 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id_gather.wgsl +55 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id_vec.wgsl +154 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_reg_tile.wgsl +149 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_subgroup_matrix.wgsl +200 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec.wgsl +133 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec_acc.tmpl +1433 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/pad.wgsl +86 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/repeat.wgsl +67 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/rms_norm_mul.wgsl +152 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/rope.wgsl +224 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/row_norm.wgsl +153 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/scale.wgsl +63 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/set.wgsl +109 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/set_rows.wgsl +109 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/soft_max.wgsl +245 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/solve_tri.wgsl +121 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/ssm_conv.wgsl +65 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/ssm_scan.wgsl +193 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/sum_rows.wgsl +55 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/unary.wgsl +210 -0
- data/vendor/ggml/src/ggml-webgpu/wgsl-shaders/upscale.wgsl +240 -0
- data/vendor/ggml/src/ggml-zdnn/CMakeLists.txt +36 -0
- data/vendor/ggml/src/ggml-zdnn/common.hpp +59 -0
- data/vendor/ggml/src/ggml-zdnn/ggml-zdnn.cpp +637 -0
- data/vendor/ggml/src/ggml-zdnn/mmf.cpp +80 -0
- data/vendor/ggml/src/ggml-zdnn/mmf.hpp +12 -0
- data/vendor/ggml/src/ggml-zdnn/utils.cpp +79 -0
- data/vendor/ggml/src/ggml-zdnn/utils.hpp +19 -0
- data/vendor/ggml/src/ggml-zendnn/CMakeLists.txt +91 -0
- data/vendor/ggml/src/ggml-zendnn/ggml-zendnn.cpp +669 -0
- data/vendor/ggml/src/ggml.c +7777 -0
- data/vendor/ggml/src/ggml.cpp +26 -0
- data/vendor/ggml/src/gguf.cpp +1556 -0
- data/vendor/ggml/tests/CMakeLists.txt +356 -0
- data/vendor/ggml/tests/test-arange.cpp +100 -0
- data/vendor/ggml/tests/test-backend-ops.cpp +9786 -0
- data/vendor/ggml/tests/test-cont.c +170 -0
- data/vendor/ggml/tests/test-conv-transpose-1d.cpp +691 -0
- data/vendor/ggml/tests/test-conv-transpose.c +248 -0
- data/vendor/ggml/tests/test-conv1d-dw-c1.cpp +243 -0
- data/vendor/ggml/tests/test-conv1d-dw-c2.cpp +243 -0
- data/vendor/ggml/tests/test-conv1d.cpp +289 -0
- data/vendor/ggml/tests/test-conv2d-dw.cpp +153 -0
- data/vendor/ggml/tests/test-conv2d.cpp +391 -0
- data/vendor/ggml/tests/test-customop.c +300 -0
- data/vendor/ggml/tests/test-dup.c +111 -0
- data/vendor/ggml/tests/test-interpolate.cpp +166 -0
- data/vendor/ggml/tests/test-opt.cpp +1003 -0
- data/vendor/ggml/tests/test-pad-reflect-1d.cpp +213 -0
- data/vendor/ggml/tests/test-pool.c +274 -0
- data/vendor/ggml/tests/test-quantize-fns.cpp +196 -0
- data/vendor/ggml/tests/test-quantize-perf.cpp +356 -0
- data/vendor/ggml/tests/test-rel-pos.c +87 -0
- data/vendor/ggml/tests/test-roll.cpp +128 -0
- data/vendor/ggml/tests/test-timestep_embedding.cpp +180 -0
- data/vendor-patches/0001-cuda-buffer_from_ptr.patch +253 -0
- data/vendor-patches/0002-cuda-buffer_from_ptr-reuse-iface.patch +117 -0
- data/vendor-patches/0003-cuda-buffer_from_ptr-copy-mode.patch +128 -0
- data/vendor-patches/0004-cuda-cpy-strided.patch +61 -0
- data/vendor-patches/0005-concat-backward.patch +36 -0
- data/vendor-patches/0006-getrows-back-large-vocab.patch +69 -0
- data/vendor-patches/0007-gpt2-backward-kernels.patch +438 -0
- data/vendor-patches/0008-mul-mat-backward-mixed-precision.patch +50 -0
- data/vendor-patches/0009-sched-unsupported-node-diagnostic.patch +26 -0
- metadata +2161 -0
|
@@ -0,0 +1,4606 @@
|
|
|
1
|
+
#include "ggml-metal-ops.h"
|
|
2
|
+
|
|
3
|
+
#include "ggml.h"
|
|
4
|
+
#include "ggml-impl.h"
|
|
5
|
+
#include "ggml-backend-impl.h"
|
|
6
|
+
|
|
7
|
+
#include "ggml-metal-impl.h"
|
|
8
|
+
#include "ggml-metal-common.h"
|
|
9
|
+
#include "ggml-metal-device.h"
|
|
10
|
+
|
|
11
|
+
#include <cassert>
|
|
12
|
+
#include <algorithm>
|
|
13
|
+
#include <limits>
|
|
14
|
+
#include <cmath>
|
|
15
|
+
|
|
16
|
+
static ggml_metal_buffer_id ggml_metal_get_buffer_id(const ggml_tensor * t) {
|
|
17
|
+
if (!t) {
|
|
18
|
+
return { nullptr, 0 };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
ggml_backend_buffer_t buffer = t->view_src ? t->view_src->buffer : t->buffer;
|
|
22
|
+
|
|
23
|
+
ggml_metal_buffer_t ctx = (ggml_metal_buffer_t) buffer->context;
|
|
24
|
+
|
|
25
|
+
return ggml_metal_buffer_get_id(ctx, t);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
struct ggml_metal_op {
|
|
29
|
+
ggml_metal_op(
|
|
30
|
+
ggml_metal_device_t dev,
|
|
31
|
+
ggml_metal_cmd_buf_t cmd_buf,
|
|
32
|
+
ggml_cgraph * gf,
|
|
33
|
+
int idx_start,
|
|
34
|
+
int idx_end,
|
|
35
|
+
bool use_fusion,
|
|
36
|
+
bool use_concurrency,
|
|
37
|
+
bool use_capture,
|
|
38
|
+
int debug_graph,
|
|
39
|
+
int debug_fusion) {
|
|
40
|
+
this->dev = dev;
|
|
41
|
+
this->lib = ggml_metal_device_get_library(dev);
|
|
42
|
+
this->enc = ggml_metal_encoder_init(cmd_buf, use_concurrency);
|
|
43
|
+
this->mem_ranges = ggml_mem_ranges_init(debug_graph);
|
|
44
|
+
this->idx_start = idx_start;
|
|
45
|
+
this->idx_end = idx_end;
|
|
46
|
+
this->use_fusion = use_fusion;
|
|
47
|
+
this->use_concurrency = use_concurrency;
|
|
48
|
+
this->use_capture = use_capture;
|
|
49
|
+
this->debug_graph = debug_graph;
|
|
50
|
+
this->debug_fusion = debug_fusion;
|
|
51
|
+
this->gf = gf;
|
|
52
|
+
|
|
53
|
+
idxs.reserve(gf->n_nodes);
|
|
54
|
+
|
|
55
|
+
// filter empty nodes
|
|
56
|
+
// TODO: this can be removed when the allocator starts filtering them earlier
|
|
57
|
+
// https://github.com/ggml-org/llama.cpp/pull/16130#issuecomment-3327905830
|
|
58
|
+
for (int i = idx_start; i < idx_end; i++) {
|
|
59
|
+
if (!ggml_op_is_empty(gf->nodes[i]->op) && !ggml_is_empty(gf->nodes[i])) {
|
|
60
|
+
idxs.push_back(i);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
~ggml_metal_op() {
|
|
66
|
+
ggml_metal_encoder_end_encoding(this->enc);
|
|
67
|
+
ggml_metal_encoder_free(this->enc);
|
|
68
|
+
ggml_mem_ranges_free(this->mem_ranges);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
int n_nodes() const {
|
|
72
|
+
return idxs.size();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
ggml_tensor * node(int i) const {
|
|
76
|
+
assert(i >= 0 && i < (int) idxs.size());
|
|
77
|
+
return ggml_graph_node(gf, idxs[i]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
bool can_fuse(int i0, const ggml_op * ops, int n_ops) const {
|
|
81
|
+
assert(use_fusion);
|
|
82
|
+
assert(i0 >= 0 && i0 < n_nodes());
|
|
83
|
+
|
|
84
|
+
if (i0 + n_ops > n_nodes()) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return ggml_can_fuse_ext(gf, idxs.data() + i0, ops, n_ops);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
ggml_metal_device_t dev;
|
|
92
|
+
ggml_metal_library_t lib;
|
|
93
|
+
ggml_metal_encoder_t enc;
|
|
94
|
+
ggml_mem_ranges_t mem_ranges;
|
|
95
|
+
|
|
96
|
+
bool use_fusion;
|
|
97
|
+
bool use_concurrency;
|
|
98
|
+
bool use_capture;
|
|
99
|
+
|
|
100
|
+
int debug_graph;
|
|
101
|
+
int debug_fusion;
|
|
102
|
+
|
|
103
|
+
private:
|
|
104
|
+
ggml_cgraph * gf;
|
|
105
|
+
|
|
106
|
+
int idx_start;
|
|
107
|
+
int idx_end;
|
|
108
|
+
|
|
109
|
+
// non-empty node indices
|
|
110
|
+
std::vector<int> idxs;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
ggml_metal_op_t ggml_metal_op_init(
|
|
114
|
+
ggml_metal_device_t dev,
|
|
115
|
+
ggml_metal_cmd_buf_t cmd_buf,
|
|
116
|
+
ggml_cgraph * gf,
|
|
117
|
+
int idx_start,
|
|
118
|
+
int idx_end,
|
|
119
|
+
bool use_fusion,
|
|
120
|
+
bool use_concurrency,
|
|
121
|
+
bool use_capture,
|
|
122
|
+
int debug_graph,
|
|
123
|
+
int debug_fusion) {
|
|
124
|
+
ggml_metal_op_t res = new ggml_metal_op(
|
|
125
|
+
dev,
|
|
126
|
+
cmd_buf,
|
|
127
|
+
gf,
|
|
128
|
+
idx_start,
|
|
129
|
+
idx_end,
|
|
130
|
+
use_fusion,
|
|
131
|
+
use_concurrency,
|
|
132
|
+
use_capture,
|
|
133
|
+
debug_graph,
|
|
134
|
+
debug_fusion);
|
|
135
|
+
|
|
136
|
+
return res;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
void ggml_metal_op_free(ggml_metal_op_t ctx) {
|
|
140
|
+
delete ctx;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
int ggml_metal_op_n_nodes(ggml_metal_op_t ctx) {
|
|
144
|
+
return ctx->n_nodes();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static bool ggml_metal_op_concurrency_reset(ggml_metal_op_t ctx) {
|
|
148
|
+
if (!ctx->mem_ranges) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
ggml_metal_encoder_memory_barrier(ctx->enc);
|
|
153
|
+
|
|
154
|
+
ggml_mem_ranges_reset(ctx->mem_ranges);
|
|
155
|
+
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static bool ggml_metal_op_concurrency_check(ggml_metal_op_t ctx, const ggml_tensor * node) {
|
|
160
|
+
if (!ctx->mem_ranges) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return ggml_mem_ranges_check(ctx->mem_ranges, node);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
static bool ggml_metal_op_concurrency_add(ggml_metal_op_t ctx, const ggml_tensor * node) {
|
|
168
|
+
if (!ctx->mem_ranges) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return ggml_mem_ranges_add(ctx->mem_ranges, node);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static int ggml_metal_op_encode_impl(ggml_metal_op_t ctx, int idx) {
|
|
176
|
+
struct ggml_tensor * node = ctx->node(idx);
|
|
177
|
+
|
|
178
|
+
//GGML_LOG_INFO("%s: encoding node %3d, op = %8s\n", __func__, idx, ggml_op_name(node->op));
|
|
179
|
+
|
|
180
|
+
if (ggml_is_empty(node)) {
|
|
181
|
+
return 1;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
switch (node->op) {
|
|
185
|
+
case GGML_OP_NONE:
|
|
186
|
+
case GGML_OP_RESHAPE:
|
|
187
|
+
case GGML_OP_VIEW:
|
|
188
|
+
case GGML_OP_TRANSPOSE:
|
|
189
|
+
case GGML_OP_PERMUTE:
|
|
190
|
+
{
|
|
191
|
+
// noop -> next node
|
|
192
|
+
if (ctx->debug_graph > 0) {
|
|
193
|
+
GGML_LOG_DEBUG("%s: node[%5d] - %-12s %s\n", __func__, idx, ggml_op_name(node->op), "(noop)");
|
|
194
|
+
}
|
|
195
|
+
} return 1;
|
|
196
|
+
default:
|
|
197
|
+
{
|
|
198
|
+
} break;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!ggml_metal_device_supports_op(ctx->dev, node)) {
|
|
202
|
+
GGML_LOG_ERROR("%s: error: unsupported op '%s'\n", __func__, ggml_op_desc(node));
|
|
203
|
+
GGML_ABORT("unsupported op");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if ((node->flags & GGML_TENSOR_FLAG_COMPUTE) == 0) {
|
|
207
|
+
return 1;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
int n_fuse = 1;
|
|
211
|
+
|
|
212
|
+
// check if the current node can run concurrently with other nodes before it
|
|
213
|
+
// the condition is that:
|
|
214
|
+
// - the current node cannot write to any previous src or dst ranges
|
|
215
|
+
// - the current node cannot read from any previous dst ranges
|
|
216
|
+
//
|
|
217
|
+
// if the condition is not satisfied, we put a memory barrier and clear all ranges
|
|
218
|
+
// otherwise, we add the new ranges to the encoding context and process the node concurrently
|
|
219
|
+
//
|
|
220
|
+
{
|
|
221
|
+
const bool is_concurrent = ggml_metal_op_concurrency_check(ctx, node);
|
|
222
|
+
|
|
223
|
+
if (!is_concurrent) {
|
|
224
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (ctx->debug_graph > 0) {
|
|
228
|
+
GGML_LOG_DEBUG("%s: node[%5d] - %-12s %-12s %s\n", __func__, idx, ggml_op_name(node->op), ggml_get_name(node), is_concurrent ? "(concurrent)" : "");
|
|
229
|
+
}
|
|
230
|
+
if (ctx->debug_graph > 1) {
|
|
231
|
+
GGML_TENSOR_LOCALS( int64_t, ne0, node->src[0], ne);
|
|
232
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, node->src[0], nb);
|
|
233
|
+
GGML_TENSOR_LOCALS( int64_t, ne1, node->src[1], ne);
|
|
234
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, node->src[1], nb);
|
|
235
|
+
GGML_TENSOR_LOCALS( int64_t, ne2, node->src[2], ne);
|
|
236
|
+
GGML_TENSOR_LOCALS(uint64_t, nb2, node->src[2], nb);
|
|
237
|
+
GGML_TENSOR_LOCALS( int64_t, ne3, node->src[3], ne);
|
|
238
|
+
GGML_TENSOR_LOCALS(uint64_t, nb3, node->src[3], nb);
|
|
239
|
+
GGML_TENSOR_LOCALS( int64_t, ne, node, ne);
|
|
240
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, node, nb);
|
|
241
|
+
|
|
242
|
+
if (node->src[0]) {
|
|
243
|
+
GGML_LOG_DEBUG("%s: src0 - %4s [%5lld, %5lld, %5lld, %5lld] [%5lld, %5lld, %5lld, %5lld], %d, %s\n", __func__, ggml_type_name(node->src[0]->type), ne00, ne01, ne02, ne03, nb00, nb01, nb02, nb03,
|
|
244
|
+
ggml_is_contiguous(node->src[0]), node->src[0]->name);
|
|
245
|
+
}
|
|
246
|
+
if (node->src[1]) {
|
|
247
|
+
GGML_LOG_DEBUG("%s: src1 - %4s [%5lld, %5lld, %5lld, %5lld] [%5lld, %5lld, %5lld, %5lld], %d, %s\n", __func__, ggml_type_name(node->src[1]->type), ne10, ne11, ne12, ne13, nb10, nb11, nb12, nb13,
|
|
248
|
+
ggml_is_contiguous(node->src[1]), node->src[1]->name);
|
|
249
|
+
}
|
|
250
|
+
if (node->src[2]) {
|
|
251
|
+
GGML_LOG_DEBUG("%s: src2 - %4s [%5lld, %5lld, %5lld, %5lld] [%5lld, %5lld, %5lld, %5lld], %d, %s\n", __func__, ggml_type_name(node->src[2]->type), ne20, ne21, ne22, ne23, nb20, nb21, nb22, nb23,
|
|
252
|
+
ggml_is_contiguous(node->src[2]), node->src[2]->name);
|
|
253
|
+
}
|
|
254
|
+
if (node->src[3]) {
|
|
255
|
+
GGML_LOG_DEBUG("%s: src3 - %4s [%5lld, %5lld, %5lld, %5lld] [%5lld, %5lld, %5lld, %5lld], %d, %s\n", __func__, ggml_type_name(node->src[3]->type), ne30, ne31, ne32, ne33, nb30, nb31, nb32, nb33,
|
|
256
|
+
ggml_is_contiguous(node->src[3]), node->src[3]->name);
|
|
257
|
+
}
|
|
258
|
+
if (node) {
|
|
259
|
+
GGML_LOG_DEBUG("%s: node - %4s [%5lld, %5lld, %5lld, %5lld] [%5lld, %5lld, %5lld, %5lld], 1, %s\n", __func__, ggml_type_name(node->type), ne0, ne1, ne2, ne3, nb0, nb1, nb2, nb3,
|
|
260
|
+
node->name);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
switch (node->op) {
|
|
266
|
+
case GGML_OP_CONCAT:
|
|
267
|
+
{
|
|
268
|
+
n_fuse = ggml_metal_op_concat(ctx, idx);
|
|
269
|
+
} break;
|
|
270
|
+
case GGML_OP_ADD:
|
|
271
|
+
case GGML_OP_SUB:
|
|
272
|
+
case GGML_OP_MUL:
|
|
273
|
+
case GGML_OP_DIV:
|
|
274
|
+
{
|
|
275
|
+
n_fuse = ggml_metal_op_bin(ctx, idx);
|
|
276
|
+
} break;
|
|
277
|
+
case GGML_OP_ADD_ID:
|
|
278
|
+
{
|
|
279
|
+
n_fuse = ggml_metal_op_add_id(ctx, idx);
|
|
280
|
+
} break;
|
|
281
|
+
case GGML_OP_REPEAT:
|
|
282
|
+
{
|
|
283
|
+
n_fuse = ggml_metal_op_repeat(ctx, idx);
|
|
284
|
+
} break;
|
|
285
|
+
case GGML_OP_ACC:
|
|
286
|
+
{
|
|
287
|
+
n_fuse = ggml_metal_op_acc(ctx, idx);
|
|
288
|
+
} break;
|
|
289
|
+
case GGML_OP_SCALE:
|
|
290
|
+
case GGML_OP_FILL:
|
|
291
|
+
case GGML_OP_CLAMP:
|
|
292
|
+
case GGML_OP_LEAKY_RELU:
|
|
293
|
+
case GGML_OP_SQR:
|
|
294
|
+
case GGML_OP_SQRT:
|
|
295
|
+
case GGML_OP_SIN:
|
|
296
|
+
case GGML_OP_COS:
|
|
297
|
+
case GGML_OP_LOG:
|
|
298
|
+
case GGML_OP_UNARY:
|
|
299
|
+
{
|
|
300
|
+
n_fuse = ggml_metal_op_unary(ctx, idx);
|
|
301
|
+
} break;
|
|
302
|
+
case GGML_OP_GLU:
|
|
303
|
+
{
|
|
304
|
+
n_fuse = ggml_metal_op_glu(ctx, idx);
|
|
305
|
+
} break;
|
|
306
|
+
case GGML_OP_SUM:
|
|
307
|
+
{
|
|
308
|
+
n_fuse = ggml_metal_op_sum(ctx, idx);
|
|
309
|
+
} break;
|
|
310
|
+
case GGML_OP_SUM_ROWS:
|
|
311
|
+
case GGML_OP_MEAN:
|
|
312
|
+
{
|
|
313
|
+
n_fuse = ggml_metal_op_sum_rows(ctx, idx);
|
|
314
|
+
} break;
|
|
315
|
+
case GGML_OP_CUMSUM:
|
|
316
|
+
{
|
|
317
|
+
n_fuse = ggml_metal_op_cumsum(ctx, idx);
|
|
318
|
+
} break;
|
|
319
|
+
case GGML_OP_SOFT_MAX:
|
|
320
|
+
{
|
|
321
|
+
n_fuse = ggml_metal_op_soft_max(ctx, idx);
|
|
322
|
+
} break;
|
|
323
|
+
case GGML_OP_SSM_CONV:
|
|
324
|
+
{
|
|
325
|
+
n_fuse = ggml_metal_op_ssm_conv(ctx, idx);
|
|
326
|
+
} break;
|
|
327
|
+
case GGML_OP_SSM_SCAN:
|
|
328
|
+
{
|
|
329
|
+
n_fuse = ggml_metal_op_ssm_scan(ctx, idx);
|
|
330
|
+
} break;
|
|
331
|
+
case GGML_OP_RWKV_WKV6:
|
|
332
|
+
case GGML_OP_RWKV_WKV7:
|
|
333
|
+
{
|
|
334
|
+
n_fuse = ggml_metal_op_rwkv(ctx, idx);
|
|
335
|
+
} break;
|
|
336
|
+
case GGML_OP_GATED_DELTA_NET:
|
|
337
|
+
{
|
|
338
|
+
n_fuse = ggml_metal_op_gated_delta_net(ctx, idx);
|
|
339
|
+
} break;
|
|
340
|
+
case GGML_OP_SOLVE_TRI:
|
|
341
|
+
{
|
|
342
|
+
n_fuse = ggml_metal_op_solve_tri(ctx, idx);
|
|
343
|
+
} break;
|
|
344
|
+
case GGML_OP_MUL_MAT:
|
|
345
|
+
{
|
|
346
|
+
n_fuse = ggml_metal_op_mul_mat(ctx, idx);
|
|
347
|
+
} break;
|
|
348
|
+
case GGML_OP_MUL_MAT_ID:
|
|
349
|
+
{
|
|
350
|
+
n_fuse = ggml_metal_op_mul_mat_id(ctx, idx);
|
|
351
|
+
} break;
|
|
352
|
+
case GGML_OP_GET_ROWS:
|
|
353
|
+
{
|
|
354
|
+
n_fuse = ggml_metal_op_get_rows(ctx, idx);
|
|
355
|
+
} break;
|
|
356
|
+
case GGML_OP_SET_ROWS:
|
|
357
|
+
{
|
|
358
|
+
n_fuse = ggml_metal_op_set_rows(ctx, idx);
|
|
359
|
+
} break;
|
|
360
|
+
case GGML_OP_DIAG:
|
|
361
|
+
{
|
|
362
|
+
n_fuse = ggml_metal_op_diag(ctx, idx);
|
|
363
|
+
} break;
|
|
364
|
+
case GGML_OP_L2_NORM:
|
|
365
|
+
{
|
|
366
|
+
n_fuse = ggml_metal_op_l2_norm(ctx, idx);
|
|
367
|
+
} break;
|
|
368
|
+
case GGML_OP_GROUP_NORM:
|
|
369
|
+
{
|
|
370
|
+
n_fuse = ggml_metal_op_group_norm(ctx, idx);
|
|
371
|
+
} break;
|
|
372
|
+
case GGML_OP_NORM:
|
|
373
|
+
case GGML_OP_RMS_NORM:
|
|
374
|
+
{
|
|
375
|
+
n_fuse = ggml_metal_op_norm(ctx, idx);
|
|
376
|
+
} break;
|
|
377
|
+
case GGML_OP_ROPE:
|
|
378
|
+
{
|
|
379
|
+
n_fuse = ggml_metal_op_rope(ctx, idx);
|
|
380
|
+
} break;
|
|
381
|
+
case GGML_OP_IM2COL:
|
|
382
|
+
{
|
|
383
|
+
n_fuse = ggml_metal_op_im2col(ctx, idx);
|
|
384
|
+
} break;
|
|
385
|
+
case GGML_OP_CONV_2D:
|
|
386
|
+
{
|
|
387
|
+
n_fuse = ggml_metal_op_conv_2d(ctx, idx);
|
|
388
|
+
} break;
|
|
389
|
+
case GGML_OP_CONV_TRANSPOSE_1D:
|
|
390
|
+
{
|
|
391
|
+
n_fuse = ggml_metal_op_conv_transpose_1d(ctx, idx);
|
|
392
|
+
} break;
|
|
393
|
+
case GGML_OP_CONV_TRANSPOSE_2D:
|
|
394
|
+
{
|
|
395
|
+
n_fuse = ggml_metal_op_conv_transpose_2d(ctx, idx);
|
|
396
|
+
} break;
|
|
397
|
+
case GGML_OP_CONV_3D:
|
|
398
|
+
{
|
|
399
|
+
n_fuse = ggml_metal_op_conv_3d(ctx, idx);
|
|
400
|
+
} break;
|
|
401
|
+
case GGML_OP_UPSCALE:
|
|
402
|
+
{
|
|
403
|
+
n_fuse = ggml_metal_op_upscale(ctx, idx);
|
|
404
|
+
} break;
|
|
405
|
+
case GGML_OP_PAD:
|
|
406
|
+
{
|
|
407
|
+
n_fuse = ggml_metal_op_pad(ctx, idx);
|
|
408
|
+
} break;
|
|
409
|
+
case GGML_OP_PAD_REFLECT_1D:
|
|
410
|
+
{
|
|
411
|
+
n_fuse = ggml_metal_op_pad_reflect_1d(ctx, idx);
|
|
412
|
+
} break;
|
|
413
|
+
case GGML_OP_ROLL:
|
|
414
|
+
{
|
|
415
|
+
n_fuse = ggml_metal_op_roll(ctx, idx);
|
|
416
|
+
} break;
|
|
417
|
+
case GGML_OP_ARANGE:
|
|
418
|
+
{
|
|
419
|
+
n_fuse = ggml_metal_op_arange(ctx, idx);
|
|
420
|
+
} break;
|
|
421
|
+
case GGML_OP_TIMESTEP_EMBEDDING:
|
|
422
|
+
{
|
|
423
|
+
n_fuse = ggml_metal_op_timestep_embedding(ctx, idx);
|
|
424
|
+
} break;
|
|
425
|
+
case GGML_OP_ARGSORT:
|
|
426
|
+
{
|
|
427
|
+
n_fuse = ggml_metal_op_argsort(ctx, idx);
|
|
428
|
+
} break;
|
|
429
|
+
case GGML_OP_TOP_K:
|
|
430
|
+
{
|
|
431
|
+
n_fuse = ggml_metal_op_top_k(ctx, idx);
|
|
432
|
+
} break;
|
|
433
|
+
case GGML_OP_TRI:
|
|
434
|
+
{
|
|
435
|
+
n_fuse = ggml_metal_op_tri(ctx, idx);
|
|
436
|
+
} break;
|
|
437
|
+
case GGML_OP_FLASH_ATTN_EXT:
|
|
438
|
+
{
|
|
439
|
+
n_fuse = ggml_metal_op_flash_attn_ext(ctx, idx);
|
|
440
|
+
} break;
|
|
441
|
+
case GGML_OP_SET:
|
|
442
|
+
{
|
|
443
|
+
n_fuse = ggml_metal_op_set(ctx, idx);
|
|
444
|
+
} break;
|
|
445
|
+
case GGML_OP_DUP:
|
|
446
|
+
case GGML_OP_CPY:
|
|
447
|
+
case GGML_OP_CONT:
|
|
448
|
+
{
|
|
449
|
+
n_fuse = ggml_metal_op_cpy(ctx, idx);
|
|
450
|
+
} break;
|
|
451
|
+
case GGML_OP_POOL_1D:
|
|
452
|
+
{
|
|
453
|
+
n_fuse = ggml_metal_op_pool_1d(ctx, idx);
|
|
454
|
+
} break;
|
|
455
|
+
case GGML_OP_POOL_2D:
|
|
456
|
+
{
|
|
457
|
+
n_fuse = ggml_metal_op_pool_2d(ctx, idx);
|
|
458
|
+
} break;
|
|
459
|
+
case GGML_OP_ARGMAX:
|
|
460
|
+
{
|
|
461
|
+
n_fuse = ggml_metal_op_argmax(ctx, idx);
|
|
462
|
+
} break;
|
|
463
|
+
case GGML_OP_OPT_STEP_ADAMW:
|
|
464
|
+
{
|
|
465
|
+
n_fuse = ggml_metal_op_opt_step_adamw(ctx, idx);
|
|
466
|
+
} break;
|
|
467
|
+
case GGML_OP_OPT_STEP_SGD:
|
|
468
|
+
{
|
|
469
|
+
n_fuse = ggml_metal_op_opt_step_sgd(ctx, idx);
|
|
470
|
+
} break;
|
|
471
|
+
case GGML_OP_COUNT_EQUAL:
|
|
472
|
+
{
|
|
473
|
+
n_fuse = ggml_metal_op_count_equal(ctx, idx);
|
|
474
|
+
} break;
|
|
475
|
+
default:
|
|
476
|
+
{
|
|
477
|
+
GGML_LOG_ERROR("%s: error: node %3d, op = %8s not implemented\n", __func__, idx, ggml_op_name(node->op));
|
|
478
|
+
GGML_ABORT("fatal error");
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (ctx->debug_graph > 0) {
|
|
483
|
+
if (n_fuse > 1) {
|
|
484
|
+
GGML_LOG_DEBUG("%s: fuse %d ops\n", __func__, n_fuse);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// update the mem ranges in the encoding context
|
|
489
|
+
for (int i = 0; i < n_fuse; ++i) {
|
|
490
|
+
if (!ggml_metal_op_concurrency_add(ctx, ctx->node(idx + i))) {
|
|
491
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return n_fuse;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
int ggml_metal_op_encode(ggml_metal_op_t ctx, int idx) {
|
|
499
|
+
if (ctx->use_capture) {
|
|
500
|
+
ggml_metal_encoder_debug_group_push(ctx->enc, ggml_op_desc(ctx->node(idx)));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
int res = ggml_metal_op_encode_impl(ctx, idx);
|
|
504
|
+
if (idx + res > ctx->n_nodes()) {
|
|
505
|
+
GGML_ABORT("fusion error: nodes spanning multiple encoders have been fused. this indicates a bug in the fusion logic %s",
|
|
506
|
+
"https://github.com/ggml-org/llama.cpp/pull/14849");
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
if (ctx->use_capture) {
|
|
510
|
+
ggml_metal_encoder_debug_group_pop(ctx->enc);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
return res;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
int ggml_metal_op_concat(ggml_metal_op_t ctx, int idx) {
|
|
517
|
+
ggml_tensor * op = ctx->node(idx);
|
|
518
|
+
|
|
519
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
520
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
521
|
+
|
|
522
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
523
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
524
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
525
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
526
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
527
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
528
|
+
|
|
529
|
+
const int32_t dim = ((const int32_t *) op->op_params)[0];
|
|
530
|
+
|
|
531
|
+
ggml_metal_kargs_concat args = {
|
|
532
|
+
/*.ne00 =*/ ne00,
|
|
533
|
+
/*.ne01 =*/ ne01,
|
|
534
|
+
/*.ne02 =*/ ne02,
|
|
535
|
+
/*.ne03 =*/ ne03,
|
|
536
|
+
/*.nb00 =*/ nb00,
|
|
537
|
+
/*.nb01 =*/ nb01,
|
|
538
|
+
/*.nb02 =*/ nb02,
|
|
539
|
+
/*.nb03 =*/ nb03,
|
|
540
|
+
/*.ne10 =*/ ne10,
|
|
541
|
+
/*.ne11 =*/ ne11,
|
|
542
|
+
/*.ne12 =*/ ne12,
|
|
543
|
+
/*.ne13 =*/ ne13,
|
|
544
|
+
/*.nb10 =*/ nb10,
|
|
545
|
+
/*.nb11 =*/ nb11,
|
|
546
|
+
/*.nb12 =*/ nb12,
|
|
547
|
+
/*.nb13 =*/ nb13,
|
|
548
|
+
/*.ne0 =*/ ne0,
|
|
549
|
+
/*.ne1 =*/ ne1,
|
|
550
|
+
/*.ne2 =*/ ne2,
|
|
551
|
+
/*.ne3 =*/ ne3,
|
|
552
|
+
/*.nb0 =*/ nb0,
|
|
553
|
+
/*.nb1 =*/ nb1,
|
|
554
|
+
/*.nb2 =*/ nb2,
|
|
555
|
+
/*.nb3 =*/ nb3,
|
|
556
|
+
/*.dim =*/ dim,
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
auto pipeline = ggml_metal_library_get_pipeline_base(lib, GGML_OP_CONCAT);
|
|
560
|
+
|
|
561
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
562
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
563
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
564
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
565
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
566
|
+
|
|
567
|
+
const int nth = std::min(1024, ne0);
|
|
568
|
+
|
|
569
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne1, ne2, ne3, nth, 1, 1);
|
|
570
|
+
|
|
571
|
+
return 1;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
int ggml_metal_op_repeat(ggml_metal_op_t ctx, int idx) {
|
|
575
|
+
ggml_tensor * op = ctx->node(idx);
|
|
576
|
+
|
|
577
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
578
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
579
|
+
|
|
580
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
581
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
582
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
583
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
584
|
+
|
|
585
|
+
auto pipeline = ggml_metal_library_get_pipeline_repeat(lib, op->type);
|
|
586
|
+
|
|
587
|
+
ggml_metal_kargs_repeat args = {
|
|
588
|
+
/*.ne00 =*/ ne00,
|
|
589
|
+
/*.ne01 =*/ ne01,
|
|
590
|
+
/*.ne02 =*/ ne02,
|
|
591
|
+
/*.ne03 =*/ ne03,
|
|
592
|
+
/*.nb00 =*/ nb00,
|
|
593
|
+
/*.nb01 =*/ nb01,
|
|
594
|
+
/*.nb02 =*/ nb02,
|
|
595
|
+
/*.nb03 =*/ nb03,
|
|
596
|
+
/*.ne0 =*/ ne0,
|
|
597
|
+
/*.ne1 =*/ ne1,
|
|
598
|
+
/*.ne2 =*/ ne2,
|
|
599
|
+
/*.ne3 =*/ ne3,
|
|
600
|
+
/*.nb0 =*/ nb0,
|
|
601
|
+
/*.nb1 =*/ nb1,
|
|
602
|
+
/*.nb2 =*/ nb2,
|
|
603
|
+
/*.nb3 =*/ nb3,
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
607
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
608
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
609
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
610
|
+
|
|
611
|
+
const int nth = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline), ne0);
|
|
612
|
+
|
|
613
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne1, ne2, ne3, nth, 1, 1);
|
|
614
|
+
|
|
615
|
+
return 1;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
int ggml_metal_op_acc(ggml_metal_op_t ctx, int idx) {
|
|
619
|
+
ggml_tensor * op = ctx->node(idx);
|
|
620
|
+
|
|
621
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
622
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
623
|
+
|
|
624
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
625
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
626
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
627
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
628
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
629
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
630
|
+
|
|
631
|
+
GGML_ASSERT(op->src[0]->type == GGML_TYPE_F32);
|
|
632
|
+
GGML_ASSERT(op->src[1]->type == GGML_TYPE_F32);
|
|
633
|
+
GGML_ASSERT(op->type == GGML_TYPE_F32);
|
|
634
|
+
|
|
635
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[0]));
|
|
636
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[1]));
|
|
637
|
+
|
|
638
|
+
const size_t pnb1 = ((const int32_t *) op->op_params)[0];
|
|
639
|
+
const size_t pnb2 = ((const int32_t *) op->op_params)[1];
|
|
640
|
+
const size_t pnb3 = ((const int32_t *) op->op_params)[2];
|
|
641
|
+
const size_t offs = ((const int32_t *) op->op_params)[3];
|
|
642
|
+
|
|
643
|
+
const bool inplace = (bool) ((const int32_t *) op->op_params)[4];
|
|
644
|
+
|
|
645
|
+
if (!inplace) {
|
|
646
|
+
// run a separate kernel to cpy src->dst
|
|
647
|
+
// not sure how to avoid this
|
|
648
|
+
// TODO: make a simpler cpy_bytes kernel
|
|
649
|
+
|
|
650
|
+
//const id<MTLComputePipelineState> pipeline = ctx->pipelines[GGML_METAL_PIPELINE_TYPE_CPY_F32_F32].obj;
|
|
651
|
+
auto pipeline = ggml_metal_library_get_pipeline_cpy(lib, op->src[0]->type, op->type);
|
|
652
|
+
|
|
653
|
+
ggml_metal_kargs_cpy args = {
|
|
654
|
+
/*.nk0 =*/ ne00,
|
|
655
|
+
/*.ne00 =*/ ne00,
|
|
656
|
+
/*.ne01 =*/ ne01,
|
|
657
|
+
/*.ne02 =*/ ne02,
|
|
658
|
+
/*.ne03 =*/ ne03,
|
|
659
|
+
/*.nb00 =*/ nb00,
|
|
660
|
+
/*.nb01 =*/ nb01,
|
|
661
|
+
/*.nb02 =*/ nb02,
|
|
662
|
+
/*.nb03 =*/ nb03,
|
|
663
|
+
/*.ne0 =*/ ne0,
|
|
664
|
+
/*.ne1 =*/ ne1,
|
|
665
|
+
/*.ne2 =*/ ne2,
|
|
666
|
+
/*.ne3 =*/ ne3,
|
|
667
|
+
/*.nb0 =*/ nb0,
|
|
668
|
+
/*.nb1 =*/ nb1,
|
|
669
|
+
/*.nb2 =*/ nb2,
|
|
670
|
+
/*.nb3 =*/ nb3,
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
674
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
675
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
676
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
677
|
+
|
|
678
|
+
const int nth = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline), ne00);
|
|
679
|
+
|
|
680
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, ne03, nth, 1, 1);
|
|
681
|
+
|
|
682
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
ggml_metal_kargs_bin args = {
|
|
686
|
+
/*.ne00 =*/ ne10,
|
|
687
|
+
/*.ne01 =*/ ne11,
|
|
688
|
+
/*.ne02 =*/ ne12,
|
|
689
|
+
/*.ne03 =*/ ne13,
|
|
690
|
+
/*.nb00 =*/ nb00,
|
|
691
|
+
/*.nb01 =*/ pnb1,
|
|
692
|
+
/*.nb02 =*/ pnb2,
|
|
693
|
+
/*.nb03 =*/ pnb3,
|
|
694
|
+
/*.ne10 =*/ ne10,
|
|
695
|
+
/*.ne11 =*/ ne11,
|
|
696
|
+
/*.ne12 =*/ ne12,
|
|
697
|
+
/*.ne13 =*/ ne13,
|
|
698
|
+
/*.nb10 =*/ nb10,
|
|
699
|
+
/*.nb11 =*/ nb11,
|
|
700
|
+
/*.nb12 =*/ nb12,
|
|
701
|
+
/*.nb13 =*/ nb13,
|
|
702
|
+
/*.ne0 =*/ ne10,
|
|
703
|
+
/*.ne1 =*/ ne11,
|
|
704
|
+
/*.ne2 =*/ ne12,
|
|
705
|
+
/*.ne3 =*/ ne13,
|
|
706
|
+
/*.nb0 =*/ nb0,
|
|
707
|
+
/*.nb1 =*/ pnb1,
|
|
708
|
+
/*.nb2 =*/ pnb2,
|
|
709
|
+
/*.nb3 =*/ pnb3,
|
|
710
|
+
/*.offs =*/ offs,
|
|
711
|
+
/*.o1 =*/ { 0 },
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
auto pipeline = ggml_metal_library_get_pipeline_bin_one(lib, GGML_OP_ADD);
|
|
715
|
+
|
|
716
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
717
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
718
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
719
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
720
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
721
|
+
|
|
722
|
+
const int nth_max = MIN(256, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
723
|
+
|
|
724
|
+
int nth = 1;
|
|
725
|
+
|
|
726
|
+
while (2*nth < args.ne0 && nth < nth_max) {
|
|
727
|
+
nth *= 2;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne11, ne12, ne13, nth, 1, 1);
|
|
731
|
+
|
|
732
|
+
return 1;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
int ggml_metal_op_unary(ggml_metal_op_t ctx, int idx) {
|
|
736
|
+
ggml_tensor * op = ctx->node(idx);
|
|
737
|
+
|
|
738
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
739
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
740
|
+
|
|
741
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
742
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
743
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
744
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
745
|
+
|
|
746
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[0]));
|
|
747
|
+
|
|
748
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
749
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
750
|
+
|
|
751
|
+
ggml_metal_kargs_unary args = {
|
|
752
|
+
/*.ne00 =*/ ne00,
|
|
753
|
+
/*.ne01 =*/ ne01,
|
|
754
|
+
/*.ne02 =*/ ne02,
|
|
755
|
+
/*.ne03 =*/ ne03,
|
|
756
|
+
/*.nb00 =*/ nb00,
|
|
757
|
+
/*.nb01 =*/ nb01,
|
|
758
|
+
/*.nb02 =*/ nb02,
|
|
759
|
+
/*.nb03 =*/ nb03,
|
|
760
|
+
/*.ne0 =*/ ne0,
|
|
761
|
+
/*.ne1 =*/ ne1,
|
|
762
|
+
/*.ne2 =*/ ne2,
|
|
763
|
+
/*.ne3 =*/ ne3,
|
|
764
|
+
/*.nb0 =*/ nb0,
|
|
765
|
+
/*.nb1 =*/ nb1,
|
|
766
|
+
/*.nb2 =*/ nb2,
|
|
767
|
+
/*.nb3 =*/ nb3,
|
|
768
|
+
/*.slope =*/ 0.0,
|
|
769
|
+
/*.scale =*/ 0.0,
|
|
770
|
+
/*.bias =*/ 0.0,
|
|
771
|
+
/*.val =*/ 0.0,
|
|
772
|
+
/*.min =*/ 0.0,
|
|
773
|
+
/*.max =*/ 0.0,
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
if (op->op == GGML_OP_LEAKY_RELU) {
|
|
777
|
+
args.slope = ggml_get_op_params_f32(op, 0);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
if (op->op == GGML_OP_SCALE) {
|
|
781
|
+
args.scale = ggml_get_op_params_f32(op, 0);
|
|
782
|
+
args.bias = ggml_get_op_params_f32(op, 1);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
if (op->op == GGML_OP_FILL) {
|
|
786
|
+
args.val = ggml_get_op_params_f32(op, 0);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
if (op->op == GGML_OP_CLAMP) {
|
|
790
|
+
args.min = ggml_get_op_params_f32(op, 0);
|
|
791
|
+
args.max = ggml_get_op_params_f32(op, 1);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
if (op->op == GGML_OP_UNARY && ggml_get_unary_op(op) == GGML_UNARY_OP_XIELU) {
|
|
795
|
+
args.slope = ggml_get_op_params_f32(op, 1); // alpha_n
|
|
796
|
+
args.scale = ggml_get_op_params_f32(op, 2); // alpha_p
|
|
797
|
+
args.bias = ggml_get_op_params_f32(op, 3); // beta
|
|
798
|
+
args.val = ggml_get_op_params_f32(op, 4); // eps
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
auto pipeline = ggml_metal_library_get_pipeline_unary(lib, op);
|
|
802
|
+
|
|
803
|
+
if (pipeline.c4) {
|
|
804
|
+
args.ne00 = ne00/4;
|
|
805
|
+
args.ne0 = ne0/4;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
809
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
810
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
811
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
812
|
+
|
|
813
|
+
if (pipeline.cnt) {
|
|
814
|
+
const int n = pipeline.c4 ? ggml_nelements(op)/4 : ggml_nelements(op);
|
|
815
|
+
|
|
816
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, n, 1, 1, 1, 1, 1);
|
|
817
|
+
} else {
|
|
818
|
+
const int nth_max = MIN(256, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
819
|
+
|
|
820
|
+
const int nth = MIN(args.ne00, nth_max);
|
|
821
|
+
|
|
822
|
+
const int nk0 = (args.ne00 + nth - 1)/nth;
|
|
823
|
+
|
|
824
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, nk0*ne01, ne02, ne03, nth, 1, 1);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
return 1;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
int ggml_metal_op_glu(ggml_metal_op_t ctx, int idx) {
|
|
831
|
+
ggml_tensor * op = ctx->node(idx);
|
|
832
|
+
|
|
833
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
834
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
835
|
+
|
|
836
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
837
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
838
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
839
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
840
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
841
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
842
|
+
|
|
843
|
+
if (op->src[1]) {
|
|
844
|
+
GGML_ASSERT(ggml_are_same_shape(op->src[0], op->src[1]));
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
auto pipeline = ggml_metal_library_get_pipeline_glu(lib, op);
|
|
848
|
+
|
|
849
|
+
const int32_t swp = ggml_get_op_params_i32(op, 1);
|
|
850
|
+
const float alpha = ggml_get_op_params_f32(op, 2);
|
|
851
|
+
const float limit = ggml_get_op_params_f32(op, 3);
|
|
852
|
+
|
|
853
|
+
const int32_t i00 = swp ? ne0 : 0;
|
|
854
|
+
const int32_t i10 = swp ? 0 : ne0;
|
|
855
|
+
|
|
856
|
+
ggml_metal_kargs_glu args = {
|
|
857
|
+
/*.ne00 =*/ ne00,
|
|
858
|
+
/*.nb01 =*/ nb01,
|
|
859
|
+
/*.ne10 =*/ op->src[1] ? ne10 : ne00,
|
|
860
|
+
/*.nb11 =*/ op->src[1] ? nb11 : nb01,
|
|
861
|
+
/*.ne0 =*/ ne0,
|
|
862
|
+
/*.nb1 =*/ nb1,
|
|
863
|
+
/*.i00 =*/ op->src[1] ? 0 : i00,
|
|
864
|
+
/*.i10 =*/ op->src[1] ? 0 : i10,
|
|
865
|
+
/*.alpha=*/ alpha,
|
|
866
|
+
/*.limit=*/ limit
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
const int64_t nrows = ggml_nrows(op->src[0]);
|
|
870
|
+
|
|
871
|
+
const int32_t nth = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline), ne00/2);
|
|
872
|
+
|
|
873
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
874
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
875
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
876
|
+
if (op->src[1]) {
|
|
877
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
878
|
+
} else {
|
|
879
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 2);
|
|
880
|
+
}
|
|
881
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
882
|
+
|
|
883
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, nrows, 1, 1, nth, 1, 1);
|
|
884
|
+
|
|
885
|
+
return 1;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
int ggml_metal_op_sum(ggml_metal_op_t ctx, int idx) {
|
|
889
|
+
ggml_tensor * op = ctx->node(idx);
|
|
890
|
+
|
|
891
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
892
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
893
|
+
|
|
894
|
+
const uint64_t n = (uint64_t) ggml_nelements(op->src[0]);
|
|
895
|
+
|
|
896
|
+
ggml_metal_kargs_sum args = {
|
|
897
|
+
/*.np =*/ n,
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
auto pipeline = ggml_metal_library_get_pipeline_sum(lib, op);
|
|
901
|
+
|
|
902
|
+
int nth = 32; // SIMD width
|
|
903
|
+
|
|
904
|
+
while (nth < (int) n && nth < ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
905
|
+
nth *= 2;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
nth = std::min(nth, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
909
|
+
nth = std::min(nth, (int) n);
|
|
910
|
+
|
|
911
|
+
const int nsg = (nth + 31) / 32;
|
|
912
|
+
|
|
913
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
914
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
915
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
916
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
917
|
+
|
|
918
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, nsg * sizeof(float), 0);
|
|
919
|
+
|
|
920
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, 1, 1, 1, nth, 1, 1);
|
|
921
|
+
|
|
922
|
+
return 1;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
int ggml_metal_op_sum_rows(ggml_metal_op_t ctx, int idx) {
|
|
926
|
+
ggml_tensor * op = ctx->node(idx);
|
|
927
|
+
|
|
928
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
929
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
930
|
+
|
|
931
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
932
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
933
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
934
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
935
|
+
|
|
936
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[0]));
|
|
937
|
+
|
|
938
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
939
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
940
|
+
|
|
941
|
+
ggml_metal_kargs_sum_rows args = {
|
|
942
|
+
/*.ne00 =*/ ne00,
|
|
943
|
+
/*.ne01 =*/ ne01,
|
|
944
|
+
/*.ne02 =*/ ne02,
|
|
945
|
+
/*.ne03 =*/ ne03,
|
|
946
|
+
/*.nb00 =*/ nb00,
|
|
947
|
+
/*.nb01 =*/ nb01,
|
|
948
|
+
/*.nb02 =*/ nb02,
|
|
949
|
+
/*.nb03 =*/ nb03,
|
|
950
|
+
/*.ne0 =*/ ne0,
|
|
951
|
+
/*.ne1 =*/ ne1,
|
|
952
|
+
/*.ne2 =*/ ne2,
|
|
953
|
+
/*.ne3 =*/ ne3,
|
|
954
|
+
/*.nb0 =*/ nb0,
|
|
955
|
+
/*.nb1 =*/ nb1,
|
|
956
|
+
/*.nb2 =*/ nb2,
|
|
957
|
+
/*.nb3 =*/ nb3,
|
|
958
|
+
};
|
|
959
|
+
|
|
960
|
+
auto pipeline = ggml_metal_library_get_pipeline_sum_rows(lib, op);
|
|
961
|
+
|
|
962
|
+
if (pipeline.c4) {
|
|
963
|
+
args.ne00 = ne00/4;
|
|
964
|
+
args.ne0 = ne0/4;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
int nth = 32; // SIMD width
|
|
968
|
+
|
|
969
|
+
while (nth < args.ne00 && nth < ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
970
|
+
nth *= 2;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
nth = std::min(nth, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
974
|
+
nth = std::min(nth, (int) args.ne00);
|
|
975
|
+
|
|
976
|
+
const size_t smem = pipeline.smem;
|
|
977
|
+
|
|
978
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
979
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
980
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
981
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
982
|
+
|
|
983
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
984
|
+
|
|
985
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, ne03, nth, 1, 1);
|
|
986
|
+
|
|
987
|
+
return 1;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
int ggml_metal_op_cumsum(ggml_metal_op_t ctx, int idx) {
|
|
991
|
+
ggml_tensor * op = ctx->node(idx);
|
|
992
|
+
|
|
993
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
994
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
995
|
+
|
|
996
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[0]));
|
|
997
|
+
|
|
998
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
999
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1000
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1001
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1002
|
+
|
|
1003
|
+
auto pipeline_blk = ggml_metal_library_get_pipeline_cumsum_blk(lib, op);
|
|
1004
|
+
|
|
1005
|
+
int nth = 1;
|
|
1006
|
+
while (nth < ne00 && 2*nth <= ggml_metal_pipeline_max_theads_per_threadgroup(pipeline_blk)) {
|
|
1007
|
+
nth *= 2;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
GGML_ASSERT(ne00 <= nth*nth);
|
|
1011
|
+
|
|
1012
|
+
const int64_t net0 = (ne00 + nth - 1) / nth;
|
|
1013
|
+
const int64_t net1 = ne01;
|
|
1014
|
+
const int64_t net2 = ne02;
|
|
1015
|
+
const int64_t net3 = ne03;
|
|
1016
|
+
|
|
1017
|
+
const uint64_t nbt0 = sizeof(float);
|
|
1018
|
+
const uint64_t nbt1 = net0*nbt0;
|
|
1019
|
+
const uint64_t nbt2 = net1*nbt1;
|
|
1020
|
+
const uint64_t nbt3 = net2*nbt2;
|
|
1021
|
+
|
|
1022
|
+
const size_t smem = GGML_PAD(32*sizeof(float), 16);
|
|
1023
|
+
|
|
1024
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
1025
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
1026
|
+
|
|
1027
|
+
ggml_metal_buffer_id bid_tmp = bid_dst;
|
|
1028
|
+
bid_tmp.offs += ggml_nbytes(op);
|
|
1029
|
+
|
|
1030
|
+
{
|
|
1031
|
+
ggml_metal_kargs_cumsum_blk args = {
|
|
1032
|
+
/*.ne00 =*/ ne00,
|
|
1033
|
+
/*.ne01 =*/ ne01,
|
|
1034
|
+
/*.ne02 =*/ ne02,
|
|
1035
|
+
/*.ne03 =*/ ne03,
|
|
1036
|
+
/*.nb00 =*/ nb00,
|
|
1037
|
+
/*.nb01 =*/ nb01,
|
|
1038
|
+
/*.nb02 =*/ nb02,
|
|
1039
|
+
/*.nb03 =*/ nb03,
|
|
1040
|
+
/*.net0 =*/ net0,
|
|
1041
|
+
/*.net1 =*/ net1,
|
|
1042
|
+
/*.net2 =*/ net2,
|
|
1043
|
+
/*.net3 =*/ net3,
|
|
1044
|
+
/*.nbt0 =*/ nbt0,
|
|
1045
|
+
/*.nbt1 =*/ nbt1,
|
|
1046
|
+
/*.nbt2 =*/ nbt2,
|
|
1047
|
+
/*.nbt3 =*/ nbt3,
|
|
1048
|
+
/*.outb =*/ ne00 > nth,
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline_blk);
|
|
1052
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
1053
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
1054
|
+
ggml_metal_encoder_set_buffer (enc, bid_tmp, 2);
|
|
1055
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 3);
|
|
1056
|
+
|
|
1057
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
1058
|
+
|
|
1059
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, net0*ne01, ne02, ne03, nth, 1, 1);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
if (ne00 > nth) {
|
|
1063
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
1064
|
+
|
|
1065
|
+
{
|
|
1066
|
+
ggml_metal_kargs_cumsum_blk args = {
|
|
1067
|
+
/*.ne00 =*/ net0,
|
|
1068
|
+
/*.ne01 =*/ net1,
|
|
1069
|
+
/*.ne02 =*/ net2,
|
|
1070
|
+
/*.ne03 =*/ net3,
|
|
1071
|
+
/*.nb00 =*/ nbt0,
|
|
1072
|
+
/*.nb01 =*/ nbt1,
|
|
1073
|
+
/*.nb02 =*/ nbt2,
|
|
1074
|
+
/*.nb03 =*/ nbt3,
|
|
1075
|
+
/*.net0 =*/ net0,
|
|
1076
|
+
/*.net1 =*/ net1,
|
|
1077
|
+
/*.net2 =*/ net2,
|
|
1078
|
+
/*.net3 =*/ net3,
|
|
1079
|
+
/*.nbt0 =*/ nbt0,
|
|
1080
|
+
/*.nbt1 =*/ nbt1,
|
|
1081
|
+
/*.nbt2 =*/ nbt2,
|
|
1082
|
+
/*.nbt3 =*/ nbt3,
|
|
1083
|
+
/*.outb =*/ false,
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline_blk);
|
|
1087
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
1088
|
+
ggml_metal_encoder_set_buffer (enc, bid_tmp, 1);
|
|
1089
|
+
ggml_metal_encoder_set_buffer (enc, bid_tmp, 2);
|
|
1090
|
+
ggml_metal_encoder_set_buffer (enc, bid_tmp, 3);
|
|
1091
|
+
|
|
1092
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
1093
|
+
|
|
1094
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, net1, net2, net3, nth, 1, 1);
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
1098
|
+
|
|
1099
|
+
{
|
|
1100
|
+
auto pipeline_add = ggml_metal_library_get_pipeline_cumsum_add(lib, op);
|
|
1101
|
+
|
|
1102
|
+
ggml_metal_kargs_cumsum_add args = {
|
|
1103
|
+
/*.ne00 =*/ ne00,
|
|
1104
|
+
/*.ne01 =*/ ne01,
|
|
1105
|
+
/*.ne02 =*/ ne02,
|
|
1106
|
+
/*.ne03 =*/ ne03,
|
|
1107
|
+
/*.nb00 =*/ nb00,
|
|
1108
|
+
/*.nb01 =*/ nb01,
|
|
1109
|
+
/*.nb02 =*/ nb02,
|
|
1110
|
+
/*.nb03 =*/ nb03,
|
|
1111
|
+
/*.net0 =*/ net0,
|
|
1112
|
+
/*.net1 =*/ net1,
|
|
1113
|
+
/*.net2 =*/ net2,
|
|
1114
|
+
/*.net3 =*/ net3,
|
|
1115
|
+
/*.nbt0 =*/ nbt0,
|
|
1116
|
+
/*.nbt1 =*/ nbt1,
|
|
1117
|
+
/*.nbt2 =*/ nbt2,
|
|
1118
|
+
/*.nbt3 =*/ nbt3,
|
|
1119
|
+
};
|
|
1120
|
+
|
|
1121
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline_add);
|
|
1122
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
1123
|
+
ggml_metal_encoder_set_buffer (enc, bid_tmp, 1);
|
|
1124
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
1125
|
+
|
|
1126
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, net0*ne01, ne02, ne03, nth, 1, 1);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
return 1;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
int ggml_metal_op_get_rows(ggml_metal_op_t ctx, int idx) {
|
|
1134
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1135
|
+
|
|
1136
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1137
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1138
|
+
|
|
1139
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1140
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1141
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
1142
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
1143
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1144
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1145
|
+
|
|
1146
|
+
auto pipeline = ggml_metal_library_get_pipeline_get_rows(lib, op->src[0]->type);
|
|
1147
|
+
|
|
1148
|
+
ggml_metal_kargs_get_rows args = {
|
|
1149
|
+
/*.ne00t =*/ ggml_is_quantized(op->src[0]->type) ? ne00/16 : ne00,
|
|
1150
|
+
/*.ne00 =*/ ne00,
|
|
1151
|
+
/*.nb01 =*/ nb01,
|
|
1152
|
+
/*.nb02 =*/ nb02,
|
|
1153
|
+
/*.nb03 =*/ nb03,
|
|
1154
|
+
/*.ne10 =*/ ne10,
|
|
1155
|
+
/*.nb10 =*/ nb10,
|
|
1156
|
+
/*.nb11 =*/ nb11,
|
|
1157
|
+
/*.nb12 =*/ nb12,
|
|
1158
|
+
/*.nb1 =*/ nb1,
|
|
1159
|
+
/*.nb2 =*/ nb2,
|
|
1160
|
+
/*.nb3 =*/ nb3,
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
const int nth = std::min(args.ne00t, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
1164
|
+
|
|
1165
|
+
const int nw0 = (args.ne00t + nth - 1)/nth;
|
|
1166
|
+
|
|
1167
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1168
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
1169
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
1170
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
1171
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
1172
|
+
|
|
1173
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, nw0*ne10, ne11, ne12, nth, 1, 1);
|
|
1174
|
+
|
|
1175
|
+
return 1;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
int ggml_metal_op_set_rows(ggml_metal_op_t ctx, int idx) {
|
|
1179
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1180
|
+
|
|
1181
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1182
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1183
|
+
|
|
1184
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1185
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1186
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
1187
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
1188
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1189
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1190
|
+
|
|
1191
|
+
auto pipeline = ggml_metal_library_get_pipeline_set_rows(lib, op->src[1]->type, op->type);
|
|
1192
|
+
|
|
1193
|
+
const int32_t nk0 = ne0/ggml_blck_size(op->type);
|
|
1194
|
+
|
|
1195
|
+
int nth = 32; // SIMD width
|
|
1196
|
+
|
|
1197
|
+
while (nth < nk0 && nth < ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
1198
|
+
nth *= 2;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
int nrptg = 1;
|
|
1202
|
+
if (nth > nk0) {
|
|
1203
|
+
nrptg = (nth + nk0 - 1)/nk0;
|
|
1204
|
+
nth = nk0;
|
|
1205
|
+
|
|
1206
|
+
if (nrptg*nth > ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
1207
|
+
nrptg--;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
nth = std::min(nth, nk0);
|
|
1212
|
+
|
|
1213
|
+
ggml_metal_kargs_set_rows args = {
|
|
1214
|
+
/*.nk0 =*/ nk0,
|
|
1215
|
+
/*.ne01 =*/ ne01,
|
|
1216
|
+
/*.nb01 =*/ nb01,
|
|
1217
|
+
/*.nb02 =*/ nb02,
|
|
1218
|
+
/*.nb03 =*/ nb03,
|
|
1219
|
+
/*.ne11 =*/ ne11,
|
|
1220
|
+
/*.ne12 =*/ ne12,
|
|
1221
|
+
/*.nb10 =*/ nb10,
|
|
1222
|
+
/*.nb11 =*/ nb11,
|
|
1223
|
+
/*.nb12 =*/ nb12,
|
|
1224
|
+
/*.nb1 =*/ nb1,
|
|
1225
|
+
/*.nb2 =*/ nb2,
|
|
1226
|
+
/*.nb3 =*/ nb3,
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1230
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
1231
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
1232
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
1233
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
1234
|
+
|
|
1235
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, (ne01 + nrptg - 1)/nrptg, ne02, ne03, nth, nrptg, 1);
|
|
1236
|
+
|
|
1237
|
+
return 1;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
int ggml_metal_op_diag(ggml_metal_op_t ctx, int idx) {
|
|
1241
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1242
|
+
|
|
1243
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1244
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1245
|
+
|
|
1246
|
+
GGML_TENSOR_LOCALS(int32_t, ne0, op->src[0], ne);
|
|
1247
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1248
|
+
GGML_TENSOR_LOCALS(int32_t, ne, op, ne);
|
|
1249
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1250
|
+
|
|
1251
|
+
ggml_metal_kargs_diag args = {
|
|
1252
|
+
/*.ne00 =*/ne00,
|
|
1253
|
+
/*.ne01 =*/ne01,
|
|
1254
|
+
/*.ne02 =*/ne02,
|
|
1255
|
+
/*.ne03 =*/ne03,
|
|
1256
|
+
/*.nb00 =*/nb00,
|
|
1257
|
+
/*.nb01 =*/nb01,
|
|
1258
|
+
/*.nb02 =*/nb02,
|
|
1259
|
+
/*.nb03 =*/nb03,
|
|
1260
|
+
/*.ne0 =*/ne0,
|
|
1261
|
+
/*.ne1 =*/ne1,
|
|
1262
|
+
/*.ne2 =*/ne2,
|
|
1263
|
+
/*.ne3 =*/ne3,
|
|
1264
|
+
/*.nb0 =*/nb0,
|
|
1265
|
+
/*.nb1 =*/nb1,
|
|
1266
|
+
/*.nb2 =*/nb2,
|
|
1267
|
+
/*.nb3 =*/nb3,
|
|
1268
|
+
};
|
|
1269
|
+
|
|
1270
|
+
auto pipeline = ggml_metal_library_get_pipeline_diag(lib, op);
|
|
1271
|
+
|
|
1272
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1273
|
+
ggml_metal_encoder_set_bytes(enc, &args, sizeof(args), 0);
|
|
1274
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
1275
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op), 2);
|
|
1276
|
+
|
|
1277
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne1, ne2, ne3, 32, 1, 1);
|
|
1278
|
+
|
|
1279
|
+
return 1;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
int ggml_metal_op_soft_max(ggml_metal_op_t ctx, int idx) {
|
|
1283
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1284
|
+
|
|
1285
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1286
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1287
|
+
|
|
1288
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1289
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1290
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
1291
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
1292
|
+
GGML_TENSOR_LOCALS( int32_t, ne2, op->src[2], ne);
|
|
1293
|
+
GGML_TENSOR_LOCALS(uint64_t, nb2, op->src[2], nb);
|
|
1294
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1295
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1296
|
+
|
|
1297
|
+
float scale;
|
|
1298
|
+
float max_bias;
|
|
1299
|
+
|
|
1300
|
+
memcpy(&scale, ((const int32_t *) op->op_params) + 0, sizeof(scale));
|
|
1301
|
+
memcpy(&max_bias, ((const int32_t *) op->op_params) + 1, sizeof(max_bias));
|
|
1302
|
+
|
|
1303
|
+
const uint32_t n_head = op->src[0]->ne[2];
|
|
1304
|
+
const int32_t n_head_log2 = 1u << (uint32_t) floorf(log2f((float) n_head));
|
|
1305
|
+
|
|
1306
|
+
const float m0 = powf(2.0f, -(max_bias ) / n_head_log2);
|
|
1307
|
+
const float m1 = powf(2.0f, -(max_bias / 2.0f) / n_head_log2);
|
|
1308
|
+
|
|
1309
|
+
// softmax
|
|
1310
|
+
|
|
1311
|
+
ggml_metal_kargs_soft_max args = {
|
|
1312
|
+
/*.ne00 =*/ ne00,
|
|
1313
|
+
/*.ne01 =*/ ne01,
|
|
1314
|
+
/*.ne02 =*/ ne02,
|
|
1315
|
+
/*.nb01 =*/ nb01,
|
|
1316
|
+
/*.nb02 =*/ nb02,
|
|
1317
|
+
/*.nb03 =*/ nb03,
|
|
1318
|
+
/*.ne11 =*/ ne11,
|
|
1319
|
+
/*.ne12 =*/ ne12,
|
|
1320
|
+
/*.ne13 =*/ ne13,
|
|
1321
|
+
/*.nb11 =*/ nb11,
|
|
1322
|
+
/*.nb12 =*/ nb12,
|
|
1323
|
+
/*.nb13 =*/ nb13,
|
|
1324
|
+
/*.nb1 =*/ nb1,
|
|
1325
|
+
/*.nb2 =*/ nb2,
|
|
1326
|
+
/*.nb3 =*/ nb3,
|
|
1327
|
+
/*.scale =*/ scale,
|
|
1328
|
+
/*.max_bias =*/ max_bias,
|
|
1329
|
+
/*.m0 =*/ m0,
|
|
1330
|
+
/*.m1 =*/ m1,
|
|
1331
|
+
/*.n_head_log2 =*/ n_head_log2,
|
|
1332
|
+
};
|
|
1333
|
+
|
|
1334
|
+
auto pipeline = ggml_metal_library_get_pipeline_soft_max(lib, op);
|
|
1335
|
+
|
|
1336
|
+
int nth = 32; // SIMD width
|
|
1337
|
+
|
|
1338
|
+
if (ne00%4 == 0) {
|
|
1339
|
+
while (nth < ne00/4 && nth*ne01*ne02*ne03 < 256) {
|
|
1340
|
+
nth *= 2;
|
|
1341
|
+
}
|
|
1342
|
+
} else {
|
|
1343
|
+
while (nth < ne00 && nth*ne01*ne02*ne03 < 256) {
|
|
1344
|
+
nth *= 2;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
const size_t smem = pipeline.smem;
|
|
1349
|
+
|
|
1350
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1351
|
+
ggml_metal_encoder_set_bytes(enc, &args, sizeof(args), 0);
|
|
1352
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
1353
|
+
if (op->src[1]) {
|
|
1354
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
1355
|
+
} else {
|
|
1356
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[0]), 2);
|
|
1357
|
+
}
|
|
1358
|
+
if (op->src[2]) {
|
|
1359
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[2]), 3);
|
|
1360
|
+
} else {
|
|
1361
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[0]), 3);
|
|
1362
|
+
}
|
|
1363
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op), 4);
|
|
1364
|
+
|
|
1365
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
1366
|
+
|
|
1367
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, ne03, nth, 1, 1);
|
|
1368
|
+
|
|
1369
|
+
return 1;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
int ggml_metal_op_ssm_conv(ggml_metal_op_t ctx, int idx) {
|
|
1373
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1374
|
+
|
|
1375
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1376
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1377
|
+
|
|
1378
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1379
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1380
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
1381
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
1382
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1383
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1384
|
+
|
|
1385
|
+
ggml_metal_kargs_ssm_conv args = {
|
|
1386
|
+
/*.ne00 =*/ ne00,
|
|
1387
|
+
/*.ne01 =*/ ne01,
|
|
1388
|
+
/*.ne02 =*/ ne02,
|
|
1389
|
+
/*.nb00 =*/ nb00,
|
|
1390
|
+
/*.nb01 =*/ nb01,
|
|
1391
|
+
/*.nb02 =*/ nb02,
|
|
1392
|
+
/*.ne10 =*/ ne10,
|
|
1393
|
+
/*.ne11 =*/ ne11,
|
|
1394
|
+
/*.nb10 =*/ nb10,
|
|
1395
|
+
/*.nb11 =*/ nb11,
|
|
1396
|
+
/*.ne0 =*/ ne0,
|
|
1397
|
+
/*.ne1 =*/ ne1,
|
|
1398
|
+
/*.ne2 =*/ ne2,
|
|
1399
|
+
/*.nb0 =*/ nb0,
|
|
1400
|
+
/*.nb1 =*/ nb1,
|
|
1401
|
+
/*.nb2 =*/ nb2,
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
// Use batched kernel for prefill (ne1 > 1) to reduce threadgroup dispatch overhead
|
|
1405
|
+
const bool use_batched = (ne1 > 1);
|
|
1406
|
+
|
|
1407
|
+
if (use_batched) {
|
|
1408
|
+
// Determine the smallest power of 2 that's >= ne1, but <= 256
|
|
1409
|
+
int BATCH_SIZE;
|
|
1410
|
+
if (ne1 > 128) BATCH_SIZE = 256;
|
|
1411
|
+
else if (ne1 > 64 ) BATCH_SIZE = 128;
|
|
1412
|
+
else if (ne1 > 32 ) BATCH_SIZE = 64;
|
|
1413
|
+
else if (ne1 > 16 ) BATCH_SIZE = 32;
|
|
1414
|
+
else if (ne1 > 8 ) BATCH_SIZE = 16;
|
|
1415
|
+
else if (ne1 > 4 ) BATCH_SIZE = 8;
|
|
1416
|
+
else BATCH_SIZE = 2;
|
|
1417
|
+
|
|
1418
|
+
auto pipeline = ggml_metal_library_get_pipeline_ssm_conv_batched(lib, op, BATCH_SIZE);
|
|
1419
|
+
|
|
1420
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1421
|
+
ggml_metal_encoder_set_bytes(enc, &args, sizeof(args), 0);
|
|
1422
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
1423
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
1424
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op), 3);
|
|
1425
|
+
|
|
1426
|
+
// Dispatch: ne01 rows, ceil(ne1/BATCH_SIZE) token batches, ne02 sequences
|
|
1427
|
+
// Each threadgroup has BATCH_SIZE threads, each handling one token
|
|
1428
|
+
const int n_token_batches = (ne1 + BATCH_SIZE - 1) / BATCH_SIZE;
|
|
1429
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, n_token_batches, ne02, BATCH_SIZE, 1, 1);
|
|
1430
|
+
} else {
|
|
1431
|
+
auto pipeline = ggml_metal_library_get_pipeline_ssm_conv(lib, op);
|
|
1432
|
+
|
|
1433
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1434
|
+
ggml_metal_encoder_set_bytes(enc, &args, sizeof(args), 0);
|
|
1435
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
1436
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
1437
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op), 3);
|
|
1438
|
+
|
|
1439
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne1, ne02, 1, 1, 1);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
return 1;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
int ggml_metal_op_ssm_scan(ggml_metal_op_t ctx, int idx) {
|
|
1446
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1447
|
+
|
|
1448
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1449
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1450
|
+
|
|
1451
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1452
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1453
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
1454
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
1455
|
+
GGML_TENSOR_LOCALS( int32_t, ne2, op->src[2], ne);
|
|
1456
|
+
GGML_TENSOR_LOCALS(uint64_t, nb2, op->src[2], nb);
|
|
1457
|
+
GGML_TENSOR_LOCALS( int32_t, ne3, op->src[3], ne);
|
|
1458
|
+
GGML_TENSOR_LOCALS(uint64_t, nb3, op->src[3], nb);
|
|
1459
|
+
GGML_TENSOR_LOCALS( int32_t, ne4, op->src[4], ne);
|
|
1460
|
+
GGML_TENSOR_LOCALS(uint64_t, nb4, op->src[4], nb);
|
|
1461
|
+
GGML_TENSOR_LOCALS( int32_t, ne5, op->src[5], ne);
|
|
1462
|
+
GGML_TENSOR_LOCALS(uint64_t, nb5, op->src[5], nb);
|
|
1463
|
+
GGML_TENSOR_LOCALS( int32_t, ne6, op->src[6], ne);
|
|
1464
|
+
GGML_TENSOR_LOCALS(uint64_t, nb6, op->src[6], nb);
|
|
1465
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1466
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1467
|
+
|
|
1468
|
+
const ggml_tensor * src3 = op->src[3];
|
|
1469
|
+
const ggml_tensor * src4 = op->src[4];
|
|
1470
|
+
const ggml_tensor * src5 = op->src[5];
|
|
1471
|
+
const ggml_tensor * src6 = op->src[6];
|
|
1472
|
+
|
|
1473
|
+
GGML_ASSERT(src3);
|
|
1474
|
+
GGML_ASSERT(src4);
|
|
1475
|
+
GGML_ASSERT(src5);
|
|
1476
|
+
GGML_ASSERT(src6);
|
|
1477
|
+
|
|
1478
|
+
const int64_t d_state = ne00;
|
|
1479
|
+
const int64_t d_inner = ne01;
|
|
1480
|
+
const int64_t n_head = ne02;
|
|
1481
|
+
const int64_t n_group = ne41;
|
|
1482
|
+
const int64_t n_seq_tokens = ne12;
|
|
1483
|
+
const int64_t n_seqs = ne13;
|
|
1484
|
+
|
|
1485
|
+
ggml_metal_kargs_ssm_scan args = {
|
|
1486
|
+
/*.d_state =*/ d_state,
|
|
1487
|
+
/*.d_inner =*/ d_inner,
|
|
1488
|
+
/*.n_head =*/ n_head,
|
|
1489
|
+
/*.n_group =*/ n_group,
|
|
1490
|
+
/*.n_seq_tokens =*/ n_seq_tokens,
|
|
1491
|
+
/*.n_seqs =*/ n_seqs,
|
|
1492
|
+
/*.s_off =*/ ggml_nelements(op->src[1]) * sizeof(float),
|
|
1493
|
+
/*.nb00 =*/ nb00,
|
|
1494
|
+
/*.nb01 =*/ nb01,
|
|
1495
|
+
/*.nb02 =*/ nb02,
|
|
1496
|
+
/*.nb03 =*/ nb03,
|
|
1497
|
+
/*.nb10 =*/ nb10,
|
|
1498
|
+
/*.nb11 =*/ nb11,
|
|
1499
|
+
/*.nb12 =*/ nb12,
|
|
1500
|
+
/*.ns12 =*/ nb12/nb10,
|
|
1501
|
+
/*.nb13 =*/ nb13,
|
|
1502
|
+
/*.nb20 =*/ nb20,
|
|
1503
|
+
/*.nb21 =*/ nb21,
|
|
1504
|
+
/*.ns21 =*/ nb21/nb20,
|
|
1505
|
+
/*.nb22 =*/ nb22,
|
|
1506
|
+
/*.ne30 =*/ ne30,
|
|
1507
|
+
/*.nb31 =*/ nb31,
|
|
1508
|
+
/*.nb41 =*/ nb41,
|
|
1509
|
+
/*.nb42 =*/ nb42,
|
|
1510
|
+
/*.ns42 =*/ nb42/nb40,
|
|
1511
|
+
/*.nb43 =*/ nb43,
|
|
1512
|
+
/*.nb51 =*/ nb51,
|
|
1513
|
+
/*.nb52 =*/ nb52,
|
|
1514
|
+
/*.ns52 =*/ nb52/nb50,
|
|
1515
|
+
/*.nb53 =*/ nb53,
|
|
1516
|
+
/*.nb0 =*/ nb0,
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
auto pipeline = ggml_metal_library_get_pipeline_ssm_scan(lib, op);
|
|
1520
|
+
|
|
1521
|
+
GGML_ASSERT(d_state <= ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
1522
|
+
|
|
1523
|
+
const size_t smem = pipeline.smem;
|
|
1524
|
+
|
|
1525
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1526
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
1527
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
1528
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
1529
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[2]), 3);
|
|
1530
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[3]), 4);
|
|
1531
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[4]), 5);
|
|
1532
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[5]), 6);
|
|
1533
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[6]), 7);
|
|
1534
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 8);
|
|
1535
|
+
|
|
1536
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
1537
|
+
|
|
1538
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, d_inner, n_head, n_seqs, d_state, 1, 1);
|
|
1539
|
+
|
|
1540
|
+
return 1;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
int ggml_metal_op_rwkv(ggml_metal_op_t ctx, int idx) {
|
|
1544
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1545
|
+
|
|
1546
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1547
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1548
|
+
|
|
1549
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1550
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1551
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1552
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1553
|
+
|
|
1554
|
+
const int64_t B = op->op == GGML_OP_RWKV_WKV6 ? op->src[5]->ne[1] : op->src[6]->ne[1];
|
|
1555
|
+
const int64_t T = op->src[0]->ne[2];
|
|
1556
|
+
const int64_t C = op->ne[0];
|
|
1557
|
+
const int64_t H = op->src[0]->ne[1];
|
|
1558
|
+
|
|
1559
|
+
auto pipeline = ggml_metal_library_get_pipeline_rwkv(lib, op);
|
|
1560
|
+
|
|
1561
|
+
int ida = 0;
|
|
1562
|
+
|
|
1563
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1564
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), ida++);
|
|
1565
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), ida++);
|
|
1566
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[2]), ida++);
|
|
1567
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[3]), ida++);
|
|
1568
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[4]), ida++);
|
|
1569
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[5]), ida++);
|
|
1570
|
+
if (op->op == GGML_OP_RWKV_WKV7) {
|
|
1571
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[6]), ida++);
|
|
1572
|
+
}
|
|
1573
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), ida++);
|
|
1574
|
+
ggml_metal_encoder_set_bytes (enc, (void *) &B, sizeof(B), ida++);
|
|
1575
|
+
ggml_metal_encoder_set_bytes (enc, (void *) &T, sizeof(T), ida++);
|
|
1576
|
+
ggml_metal_encoder_set_bytes (enc, (void *) &C, sizeof(C), ida++);
|
|
1577
|
+
ggml_metal_encoder_set_bytes (enc, (void *) &H, sizeof(H), ida++);
|
|
1578
|
+
|
|
1579
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, B * H, 1, 1, C/H, 1, 1);
|
|
1580
|
+
|
|
1581
|
+
return 1;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
int ggml_metal_op_gated_delta_net(ggml_metal_op_t ctx, int idx) {
|
|
1585
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1586
|
+
|
|
1587
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1588
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1592
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1593
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
1594
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
1595
|
+
GGML_TENSOR_LOCALS( int32_t, ne2, op->src[2], ne);
|
|
1596
|
+
GGML_TENSOR_LOCALS(uint64_t, nb2, op->src[2], nb);
|
|
1597
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1598
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1599
|
+
|
|
1600
|
+
auto pipeline = ggml_metal_library_get_pipeline_gated_delta_net(lib, op);
|
|
1601
|
+
|
|
1602
|
+
int ida = 0;
|
|
1603
|
+
|
|
1604
|
+
ggml_metal_kargs_gated_delta_net args = {
|
|
1605
|
+
/*.ne00 =*/ ne00,
|
|
1606
|
+
/*.ne01 =*/ ne01,
|
|
1607
|
+
/*.ne02 =*/ ne02,
|
|
1608
|
+
/*.ne03 =*/ ne03,
|
|
1609
|
+
/*.nb00 =*/ nb00,
|
|
1610
|
+
/*.nb01 =*/ nb01,
|
|
1611
|
+
/*.nb02 =*/ nb02,
|
|
1612
|
+
/*.nb03 =*/ nb03,
|
|
1613
|
+
/*.ne10 =*/ ne10,
|
|
1614
|
+
/*.ne11 =*/ ne11,
|
|
1615
|
+
/*.ne12 =*/ ne12,
|
|
1616
|
+
/*.ne13 =*/ ne13,
|
|
1617
|
+
/*.nb10 =*/ nb10,
|
|
1618
|
+
/*.nb11 =*/ nb11,
|
|
1619
|
+
/*.nb12 =*/ nb12,
|
|
1620
|
+
/*.nb13 =*/ nb13,
|
|
1621
|
+
/*.ne20 =*/ ne20,
|
|
1622
|
+
/*.ne21 =*/ ne21,
|
|
1623
|
+
/*.ne22 =*/ ne22,
|
|
1624
|
+
/*.ne23 =*/ ne23,
|
|
1625
|
+
/*.nb20 =*/ nb20,
|
|
1626
|
+
/*.nb21 =*/ nb21,
|
|
1627
|
+
/*.nb22 =*/ nb22,
|
|
1628
|
+
/*.nb23 =*/ nb23,
|
|
1629
|
+
/*.ns02 =*/ (int32_t) (nb02/sizeof(float)),
|
|
1630
|
+
/*.ns12 =*/ (int32_t) (nb12/sizeof(float)),
|
|
1631
|
+
/*.ns22 =*/ (int32_t) (nb22/sizeof(float)),
|
|
1632
|
+
/*.ne0 =*/ ne0,
|
|
1633
|
+
/*.ne1 =*/ ne1,
|
|
1634
|
+
/*.ne2 =*/ ne2,
|
|
1635
|
+
/*.ne3 =*/ ne3,
|
|
1636
|
+
/*.nb0 =*/ nb0,
|
|
1637
|
+
/*.nb1 =*/ nb1,
|
|
1638
|
+
/*.nb2 =*/ nb2,
|
|
1639
|
+
/*.nb3 =*/ nb3,
|
|
1640
|
+
};
|
|
1641
|
+
|
|
1642
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1643
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), ida++);
|
|
1644
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), ida++); // q
|
|
1645
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), ida++); // k
|
|
1646
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[2]), ida++); // v
|
|
1647
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[3]), ida++); // gate
|
|
1648
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[4]), ida++); // beta
|
|
1649
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[5]), ida++); // state
|
|
1650
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), ida++); // dst
|
|
1651
|
+
|
|
1652
|
+
const int nsg = pipeline.nsg;
|
|
1653
|
+
|
|
1654
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, op->src[2]->ne[0]/nsg, op->src[2]->ne[1], op->src[2]->ne[3], 32, nsg, 1);
|
|
1655
|
+
|
|
1656
|
+
return 1;
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
int ggml_metal_op_solve_tri(ggml_metal_op_t ctx, int idx) {
|
|
1660
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1661
|
+
|
|
1662
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1663
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1664
|
+
|
|
1665
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1666
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1667
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
1668
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
1669
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1670
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1671
|
+
|
|
1672
|
+
ggml_metal_kargs_solve_tri args = {
|
|
1673
|
+
/*.ne00 =*/ ne00,
|
|
1674
|
+
/*.ne01 =*/ ne01,
|
|
1675
|
+
/*.ne02 =*/ ne02,
|
|
1676
|
+
/*.ne03 =*/ ne03,
|
|
1677
|
+
/*.nb00 =*/ nb00,
|
|
1678
|
+
/*.nb01 =*/ nb01,
|
|
1679
|
+
/*.nb02 =*/ nb02,
|
|
1680
|
+
/*.nb03 =*/ nb03,
|
|
1681
|
+
/*.ne10 =*/ ne10,
|
|
1682
|
+
/*.ne11 =*/ ne11,
|
|
1683
|
+
/*.ne12 =*/ ne12,
|
|
1684
|
+
/*.ne13 =*/ ne13,
|
|
1685
|
+
/*.nb10 =*/ nb10,
|
|
1686
|
+
/*.nb11 =*/ nb11,
|
|
1687
|
+
/*.nb12 =*/ nb12,
|
|
1688
|
+
/*.nb13 =*/ nb13,
|
|
1689
|
+
/*.ne0 =*/ ne0,
|
|
1690
|
+
/*.ne1 =*/ ne1,
|
|
1691
|
+
/*.ne2 =*/ ne2,
|
|
1692
|
+
/*.ne3 =*/ ne3,
|
|
1693
|
+
/*.nb0 =*/ nb0,
|
|
1694
|
+
/*.nb1 =*/ nb1,
|
|
1695
|
+
/*.nb2 =*/ nb2,
|
|
1696
|
+
/*.nb3 =*/ nb3,
|
|
1697
|
+
};
|
|
1698
|
+
|
|
1699
|
+
auto pipeline = ggml_metal_library_get_pipeline_solve_tri(lib, op);
|
|
1700
|
+
|
|
1701
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1702
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
1703
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
1704
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
1705
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
1706
|
+
|
|
1707
|
+
const int nsg = pipeline.nsg;
|
|
1708
|
+
|
|
1709
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, pipeline.smem, 0);
|
|
1710
|
+
|
|
1711
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, (ne10 + nsg - 1)/nsg, ne02, ne03, 32, nsg, 1);
|
|
1712
|
+
|
|
1713
|
+
return 1;
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
int ggml_metal_op_set(ggml_metal_op_t ctx, int idx) {
|
|
1717
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1718
|
+
|
|
1719
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1720
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1721
|
+
|
|
1722
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1723
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1724
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
1725
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
1726
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1727
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1728
|
+
|
|
1729
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
1730
|
+
ggml_metal_buffer_id bid_src1 = ggml_metal_get_buffer_id(op->src[1]);
|
|
1731
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
1732
|
+
|
|
1733
|
+
const size_t pnb1 = ((const int32_t *) op->op_params)[0];
|
|
1734
|
+
const size_t pnb2 = ((const int32_t *) op->op_params)[1];
|
|
1735
|
+
const size_t pnb3 = ((const int32_t *) op->op_params)[2];
|
|
1736
|
+
const size_t offs = ((const int32_t *) op->op_params)[3];
|
|
1737
|
+
|
|
1738
|
+
const bool inplace = (bool) ((const int32_t *) op->op_params)[4];
|
|
1739
|
+
|
|
1740
|
+
if (!inplace) {
|
|
1741
|
+
// run a separate kernel to cpy src->dst
|
|
1742
|
+
// not sure how to avoid this
|
|
1743
|
+
// TODO: make a simpler cpy_bytes kernel
|
|
1744
|
+
|
|
1745
|
+
//const id<MTLComputePipelineState> pipeline = ctx->pipelines[GGML_METAL_PIPELINE_TYPE_CPY_F32_F32].obj;
|
|
1746
|
+
auto pipeline = ggml_metal_library_get_pipeline_cpy(lib, op->src[0]->type, op->type);
|
|
1747
|
+
|
|
1748
|
+
ggml_metal_kargs_cpy args = {
|
|
1749
|
+
/*.nk0 =*/ ne00,
|
|
1750
|
+
/*.ne00 =*/ ne00,
|
|
1751
|
+
/*.ne01 =*/ ne01,
|
|
1752
|
+
/*.ne02 =*/ ne02,
|
|
1753
|
+
/*.ne03 =*/ ne03,
|
|
1754
|
+
/*.nb00 =*/ nb00,
|
|
1755
|
+
/*.nb01 =*/ nb01,
|
|
1756
|
+
/*.nb02 =*/ nb02,
|
|
1757
|
+
/*.nb03 =*/ nb03,
|
|
1758
|
+
/*.ne0 =*/ ne0,
|
|
1759
|
+
/*.ne1 =*/ ne1,
|
|
1760
|
+
/*.ne2 =*/ ne2,
|
|
1761
|
+
/*.ne3 =*/ ne3,
|
|
1762
|
+
/*.nb0 =*/ nb0,
|
|
1763
|
+
/*.nb1 =*/ nb1,
|
|
1764
|
+
/*.nb2 =*/ nb2,
|
|
1765
|
+
/*.nb3 =*/ nb3,
|
|
1766
|
+
};
|
|
1767
|
+
|
|
1768
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1769
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
1770
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
1771
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
1772
|
+
|
|
1773
|
+
const int nth = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline), ne00);
|
|
1774
|
+
|
|
1775
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, ne03, nth, 1, 1);
|
|
1776
|
+
|
|
1777
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
auto pipeline = ggml_metal_library_get_pipeline_cpy(lib, op->src[1]->type, op->type);
|
|
1781
|
+
|
|
1782
|
+
GGML_ASSERT(ne10 % ggml_blck_size(op->src[1]->type) == 0);
|
|
1783
|
+
|
|
1784
|
+
int64_t nk0 = ne10;
|
|
1785
|
+
if (ggml_is_quantized(op->src[1]->type)) {
|
|
1786
|
+
nk0 = ne10/16;
|
|
1787
|
+
} else if (ggml_is_quantized(op->type)) {
|
|
1788
|
+
nk0 = ne10/ggml_blck_size(op->type);
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
int nth = std::min<int>(nk0, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
1792
|
+
|
|
1793
|
+
// when rows are small, we can batch them together in a single threadgroup
|
|
1794
|
+
int nrptg = 1;
|
|
1795
|
+
|
|
1796
|
+
// TODO: relax this constraint in the future
|
|
1797
|
+
if (ggml_blck_size(op->src[1]->type) == 1 && ggml_blck_size(op->type) == 1) {
|
|
1798
|
+
if (nth > nk0) {
|
|
1799
|
+
nrptg = (nth + nk0 - 1)/nk0;
|
|
1800
|
+
nth = nk0;
|
|
1801
|
+
|
|
1802
|
+
if (nrptg*nth > ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
1803
|
+
nrptg--;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
nth = std::min<int>(nth, nk0);
|
|
1809
|
+
|
|
1810
|
+
ggml_metal_kargs_cpy args = {
|
|
1811
|
+
/*.nk0 =*/ nk0,
|
|
1812
|
+
/*.ne00 =*/ ne10,
|
|
1813
|
+
/*.ne01 =*/ ne11,
|
|
1814
|
+
/*.ne02 =*/ ne12,
|
|
1815
|
+
/*.ne03 =*/ ne13,
|
|
1816
|
+
/*.nb00 =*/ nb10,
|
|
1817
|
+
/*.nb01 =*/ nb11,
|
|
1818
|
+
/*.nb02 =*/ nb12,
|
|
1819
|
+
/*.nb03 =*/ nb13,
|
|
1820
|
+
/*.ne0 =*/ ne10,
|
|
1821
|
+
/*.ne1 =*/ ne11,
|
|
1822
|
+
/*.ne2 =*/ ne12,
|
|
1823
|
+
/*.ne3 =*/ ne13,
|
|
1824
|
+
/*.nb0 =*/ ggml_element_size(op),
|
|
1825
|
+
/*.nb1 =*/ pnb1,
|
|
1826
|
+
/*.nb2 =*/ pnb2,
|
|
1827
|
+
/*.nb3 =*/ pnb3,
|
|
1828
|
+
};
|
|
1829
|
+
|
|
1830
|
+
const int nw0 = nrptg == 1 ? (nk0 + nth - 1)/nth : 1;
|
|
1831
|
+
|
|
1832
|
+
bid_dst.offs += offs;
|
|
1833
|
+
|
|
1834
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1835
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
1836
|
+
ggml_metal_encoder_set_buffer (enc, bid_src1, 1);
|
|
1837
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
1838
|
+
|
|
1839
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, nw0*(ne11 + nrptg - 1)/nrptg, ne12, ne13, nth, nrptg, 1);
|
|
1840
|
+
|
|
1841
|
+
return 1;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
int ggml_metal_op_cpy(ggml_metal_op_t ctx, int idx) {
|
|
1845
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1846
|
+
|
|
1847
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1848
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1849
|
+
|
|
1850
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1851
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1852
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1853
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1854
|
+
|
|
1855
|
+
auto pipeline = ggml_metal_library_get_pipeline_cpy(lib, op->src[0]->type, op->type);
|
|
1856
|
+
|
|
1857
|
+
GGML_ASSERT(ne00 % ggml_blck_size(op->src[0]->type) == 0);
|
|
1858
|
+
|
|
1859
|
+
int64_t nk0 = ne00;
|
|
1860
|
+
if (ggml_is_quantized(op->src[0]->type)) {
|
|
1861
|
+
nk0 = ne00/16;
|
|
1862
|
+
} else if (ggml_is_quantized(op->type)) {
|
|
1863
|
+
nk0 = ne00/ggml_blck_size(op->type);
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
int nth = std::min<int>(nk0, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
1867
|
+
|
|
1868
|
+
// when rows are small, we can batch them together in a single threadgroup
|
|
1869
|
+
int nrptg = 1;
|
|
1870
|
+
|
|
1871
|
+
// TODO: relax this constraint in the future
|
|
1872
|
+
if (ggml_blck_size(op->src[0]->type) == 1 && ggml_blck_size(op->type) == 1) {
|
|
1873
|
+
if (nth > nk0) {
|
|
1874
|
+
nrptg = (nth + nk0 - 1)/nk0;
|
|
1875
|
+
nth = nk0;
|
|
1876
|
+
|
|
1877
|
+
if (nrptg*nth > ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
1878
|
+
nrptg--;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
nth = std::min<int>(nth, nk0);
|
|
1884
|
+
|
|
1885
|
+
ggml_metal_kargs_cpy args = {
|
|
1886
|
+
/*.nk0 =*/ nk0,
|
|
1887
|
+
/*.ne00 =*/ ne00,
|
|
1888
|
+
/*.ne01 =*/ ne01,
|
|
1889
|
+
/*.ne02 =*/ ne02,
|
|
1890
|
+
/*.ne03 =*/ ne03,
|
|
1891
|
+
/*.nb00 =*/ nb00,
|
|
1892
|
+
/*.nb01 =*/ nb01,
|
|
1893
|
+
/*.nb02 =*/ nb02,
|
|
1894
|
+
/*.nb03 =*/ nb03,
|
|
1895
|
+
/*.ne0 =*/ ne0,
|
|
1896
|
+
/*.ne1 =*/ ne1,
|
|
1897
|
+
/*.ne2 =*/ ne2,
|
|
1898
|
+
/*.ne3 =*/ ne3,
|
|
1899
|
+
/*.nb0 =*/ nb0,
|
|
1900
|
+
/*.nb1 =*/ nb1,
|
|
1901
|
+
/*.nb2 =*/ nb2,
|
|
1902
|
+
/*.nb3 =*/ nb3,
|
|
1903
|
+
};
|
|
1904
|
+
|
|
1905
|
+
const int nw0 = nrptg == 1 ? (nk0 + nth - 1)/nth : 1;
|
|
1906
|
+
|
|
1907
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1908
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
1909
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
1910
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
1911
|
+
|
|
1912
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, nw0*(ne01 + nrptg - 1)/nrptg, ne02, ne03, nth, nrptg, 1);
|
|
1913
|
+
|
|
1914
|
+
return 1;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
int ggml_metal_op_pool_1d(ggml_metal_op_t ctx, int idx) {
|
|
1918
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1919
|
+
|
|
1920
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1921
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1922
|
+
|
|
1923
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1924
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1925
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1926
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1927
|
+
|
|
1928
|
+
const int32_t * opts = op->op_params;
|
|
1929
|
+
ggml_op_pool op_pool = (ggml_op_pool) opts[0];
|
|
1930
|
+
|
|
1931
|
+
const int32_t k0 = opts[1];
|
|
1932
|
+
const int32_t s0 = opts[2];
|
|
1933
|
+
const int32_t p0 = opts[3];
|
|
1934
|
+
|
|
1935
|
+
const int64_t IW = op->src[0]->ne[0];
|
|
1936
|
+
const int64_t OW = op->ne[0];
|
|
1937
|
+
|
|
1938
|
+
const int64_t np = ggml_nelements(op);
|
|
1939
|
+
|
|
1940
|
+
ggml_metal_kargs_pool_1d args_pool_1d = {
|
|
1941
|
+
/* .k0 = */ k0,
|
|
1942
|
+
/* .s0 = */ s0,
|
|
1943
|
+
/* .p0 = */ p0,
|
|
1944
|
+
/* .IW = */ IW,
|
|
1945
|
+
/* .OW = */ OW,
|
|
1946
|
+
/* .np = */ np
|
|
1947
|
+
};
|
|
1948
|
+
|
|
1949
|
+
auto pipeline = ggml_metal_library_get_pipeline_pool_1d(lib, op, op_pool);
|
|
1950
|
+
|
|
1951
|
+
const int nth = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline), (int) np);
|
|
1952
|
+
const int ntg = (np + nth - 1) / nth;
|
|
1953
|
+
|
|
1954
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
1955
|
+
ggml_metal_encoder_set_bytes (enc, &args_pool_1d, sizeof(args_pool_1d), 0);
|
|
1956
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
1957
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
1958
|
+
|
|
1959
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ntg, 1, 1, nth, 1, 1);
|
|
1960
|
+
|
|
1961
|
+
return 1;
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
|
|
1965
|
+
int ggml_metal_op_pool_2d(ggml_metal_op_t ctx, int idx) {
|
|
1966
|
+
ggml_tensor * op = ctx->node(idx);
|
|
1967
|
+
|
|
1968
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
1969
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
1970
|
+
|
|
1971
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
1972
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
1973
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
1974
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
1975
|
+
|
|
1976
|
+
const int32_t * opts = op->op_params;
|
|
1977
|
+
ggml_op_pool op_pool = (ggml_op_pool) opts[0];
|
|
1978
|
+
|
|
1979
|
+
const int32_t k0 = opts[1];
|
|
1980
|
+
const int32_t k1 = opts[2];
|
|
1981
|
+
const int32_t s0 = opts[3];
|
|
1982
|
+
const int32_t s1 = opts[4];
|
|
1983
|
+
const int32_t p0 = opts[5];
|
|
1984
|
+
const int32_t p1 = opts[6];
|
|
1985
|
+
|
|
1986
|
+
const int64_t IH = op->src[0]->ne[1];
|
|
1987
|
+
const int64_t IW = op->src[0]->ne[0];
|
|
1988
|
+
|
|
1989
|
+
const int64_t N = op->ne[3];
|
|
1990
|
+
const int64_t OC = op->ne[2];
|
|
1991
|
+
const int64_t OH = op->ne[1];
|
|
1992
|
+
const int64_t OW = op->ne[0];
|
|
1993
|
+
|
|
1994
|
+
const int64_t np = N * OC * OH * OW;
|
|
1995
|
+
|
|
1996
|
+
ggml_metal_kargs_pool_2d args_pool_2d = {
|
|
1997
|
+
/* .k0 = */ k0,
|
|
1998
|
+
/* .k1 = */ k1,
|
|
1999
|
+
/* .s0 = */ s0,
|
|
2000
|
+
/* .s1 = */ s1,
|
|
2001
|
+
/* .p0 = */ p0,
|
|
2002
|
+
/* .p1 = */ p1,
|
|
2003
|
+
/* .IH = */ IH,
|
|
2004
|
+
/* .IW = */ IW,
|
|
2005
|
+
/* .OH = */ OH,
|
|
2006
|
+
/* .OW = */ OW,
|
|
2007
|
+
/* .np = */ np
|
|
2008
|
+
};
|
|
2009
|
+
|
|
2010
|
+
auto pipeline = ggml_metal_library_get_pipeline_pool_2d(lib, op, op_pool);
|
|
2011
|
+
|
|
2012
|
+
const int nth = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline), (int) np);
|
|
2013
|
+
const int ntg = (np + nth - 1) / nth;
|
|
2014
|
+
|
|
2015
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
2016
|
+
ggml_metal_encoder_set_bytes (enc, &args_pool_2d, sizeof(args_pool_2d), 0);
|
|
2017
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
2018
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
2019
|
+
|
|
2020
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ntg, 1, 1, nth, 1, 1);
|
|
2021
|
+
|
|
2022
|
+
return 1;
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
int ggml_metal_op_mul_mat(ggml_metal_op_t ctx, int idx) {
|
|
2026
|
+
ggml_tensor * op = ctx->node(idx);
|
|
2027
|
+
|
|
2028
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
2029
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
2030
|
+
|
|
2031
|
+
const ggml_metal_device_props * props_dev = ggml_metal_device_get_props(ctx->dev);
|
|
2032
|
+
|
|
2033
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
2034
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
2035
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
2036
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
2037
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
2038
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
2039
|
+
|
|
2040
|
+
GGML_ASSERT(ne00 == ne10);
|
|
2041
|
+
|
|
2042
|
+
GGML_ASSERT(ne12 % ne02 == 0);
|
|
2043
|
+
GGML_ASSERT(ne13 % ne03 == 0);
|
|
2044
|
+
|
|
2045
|
+
const int16_t r2 = ne12/ne02;
|
|
2046
|
+
const int16_t r3 = ne13/ne03;
|
|
2047
|
+
|
|
2048
|
+
// find the break-even point where the matrix-matrix kernel becomes more efficient compared
|
|
2049
|
+
// to the matrix-vector kernel
|
|
2050
|
+
const int ne11_mm_min = 8;
|
|
2051
|
+
|
|
2052
|
+
// first try to use small-batch mat-mv kernels
|
|
2053
|
+
// these should be efficient for BS [2, ~8]
|
|
2054
|
+
if (op->src[1]->type == GGML_TYPE_F32 && (ne00%128 == 0) &&
|
|
2055
|
+
(
|
|
2056
|
+
(
|
|
2057
|
+
(
|
|
2058
|
+
op->src[0]->type == GGML_TYPE_F32 || // TODO: helper function
|
|
2059
|
+
op->src[0]->type == GGML_TYPE_F16 ||
|
|
2060
|
+
op->src[0]->type == GGML_TYPE_BF16 ||
|
|
2061
|
+
op->src[0]->type == GGML_TYPE_Q1_0 ||
|
|
2062
|
+
op->src[0]->type == GGML_TYPE_Q4_0 ||
|
|
2063
|
+
op->src[0]->type == GGML_TYPE_Q4_1 ||
|
|
2064
|
+
op->src[0]->type == GGML_TYPE_Q5_0 ||
|
|
2065
|
+
op->src[0]->type == GGML_TYPE_Q5_1 ||
|
|
2066
|
+
op->src[0]->type == GGML_TYPE_Q8_0 ||
|
|
2067
|
+
op->src[0]->type == GGML_TYPE_MXFP4 ||
|
|
2068
|
+
op->src[0]->type == GGML_TYPE_IQ4_NL ||
|
|
2069
|
+
false) && (ne11 >= 2 && ne11 <= 8)
|
|
2070
|
+
) ||
|
|
2071
|
+
(
|
|
2072
|
+
(
|
|
2073
|
+
op->src[0]->type == GGML_TYPE_Q4_K ||
|
|
2074
|
+
op->src[0]->type == GGML_TYPE_Q5_K ||
|
|
2075
|
+
op->src[0]->type == GGML_TYPE_Q6_K ||
|
|
2076
|
+
op->src[0]->type == GGML_TYPE_Q2_K ||
|
|
2077
|
+
op->src[0]->type == GGML_TYPE_Q3_K ||
|
|
2078
|
+
false) && (ne11 >= 4 && ne11 <= 8)
|
|
2079
|
+
)
|
|
2080
|
+
)
|
|
2081
|
+
) {
|
|
2082
|
+
// TODO: determine the optimal parameters based on grid utilization
|
|
2083
|
+
// I still don't know why we should not always use the maximum available threads:
|
|
2084
|
+
//
|
|
2085
|
+
// nsg = pipeline.maxTotalThreadsPerThreadgroup / 32
|
|
2086
|
+
//
|
|
2087
|
+
// my current hypothesis is that the work grid is not evenly divisible for different nsg
|
|
2088
|
+
// values and there can be some tail effects when nsg is high. need to confirm this
|
|
2089
|
+
//
|
|
2090
|
+
const int nsg = 2; // num simdgroups per threadgroup
|
|
2091
|
+
|
|
2092
|
+
// num threads along row per simdgroup
|
|
2093
|
+
int16_t nxpsg = 0;
|
|
2094
|
+
if (ne00 % 256 == 0 && ne11 < 3) {
|
|
2095
|
+
nxpsg = 16;
|
|
2096
|
+
} else if (ne00 % 128 == 0) {
|
|
2097
|
+
nxpsg = 8;
|
|
2098
|
+
} else {
|
|
2099
|
+
nxpsg = 4;
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
const int16_t nypsg = 32/nxpsg; // num threads along col per simdgroup (i.e. a simdgroup processes that many src0 rows at a time)
|
|
2103
|
+
const int16_t r0ptg = nypsg*nsg; // num src0 rows per threadgroup
|
|
2104
|
+
int16_t r1ptg = 4; // num src1 rows per threadgroup
|
|
2105
|
+
|
|
2106
|
+
// note: not sure how optimal are those across all different hardware. there might be something cleverer
|
|
2107
|
+
switch (ne11) {
|
|
2108
|
+
case 2:
|
|
2109
|
+
r1ptg = 2; break;
|
|
2110
|
+
case 3:
|
|
2111
|
+
case 6:
|
|
2112
|
+
r1ptg = 3; break;
|
|
2113
|
+
case 4:
|
|
2114
|
+
case 7:
|
|
2115
|
+
case 8:
|
|
2116
|
+
r1ptg = 4; break;
|
|
2117
|
+
case 5:
|
|
2118
|
+
r1ptg = 5; break;
|
|
2119
|
+
default:
|
|
2120
|
+
GGML_ABORT("unsupported ne11");
|
|
2121
|
+
};
|
|
2122
|
+
|
|
2123
|
+
auto pipeline = ggml_metal_library_get_pipeline_mul_mv_ext(lib, op, nsg, nxpsg, r1ptg);
|
|
2124
|
+
|
|
2125
|
+
ggml_metal_kargs_mul_mv_ext args = {
|
|
2126
|
+
/*.ne00 =*/ ne00,
|
|
2127
|
+
/*.ne01 =*/ ne01,
|
|
2128
|
+
/*.ne02 =*/ ne02,
|
|
2129
|
+
/*.nb00 =*/ nb00,
|
|
2130
|
+
/*.nb01 =*/ nb01,
|
|
2131
|
+
/*.nb02 =*/ nb02,
|
|
2132
|
+
/*.nb03 =*/ nb03,
|
|
2133
|
+
/*.ne10 =*/ ne10,
|
|
2134
|
+
/*.ne11 =*/ ne11,
|
|
2135
|
+
/*.ne12 =*/ ne12,
|
|
2136
|
+
/*.nb10 =*/ nb10,
|
|
2137
|
+
/*.nb11 =*/ nb11,
|
|
2138
|
+
/*.nb12 =*/ nb12,
|
|
2139
|
+
/*.nb13 =*/ nb13,
|
|
2140
|
+
/*.ne0 =*/ ne0,
|
|
2141
|
+
/*.ne1 =*/ ne1,
|
|
2142
|
+
/*.r2 =*/ r2,
|
|
2143
|
+
/*.r3 =*/ r3,
|
|
2144
|
+
};
|
|
2145
|
+
|
|
2146
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
2147
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
2148
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
2149
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
2150
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
2151
|
+
|
|
2152
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ((ne01 + r0ptg - 1)/r0ptg), ((ne11 + r1ptg - 1)/r1ptg), ne12*ne13, 32, nsg, 1);
|
|
2153
|
+
} else if (
|
|
2154
|
+
!ggml_is_transposed(op->src[0]) &&
|
|
2155
|
+
!ggml_is_transposed(op->src[1]) &&
|
|
2156
|
+
// for now the matrix-matrix multiplication kernel only works on A14+/M1+ SoCs
|
|
2157
|
+
// AMD GPU and older A-chips will reuse matrix-vector multiplication kernel
|
|
2158
|
+
props_dev->has_simdgroup_mm && ne00 >= 64 && ne11 > ne11_mm_min) {
|
|
2159
|
+
//GGML_LOG_INFO("matrix: ne00 = %6d, ne01 = %6d, ne02 = %6d, ne11 = %6d, ne12 = %6d\n", ne00, ne01, ne02, ne11, ne12);
|
|
2160
|
+
|
|
2161
|
+
// some Metal matrix data types require aligned pointers
|
|
2162
|
+
// ref: https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf (Table 2.5)
|
|
2163
|
+
//switch (op->src[0]->type) {
|
|
2164
|
+
// case GGML_TYPE_F32: GGML_ASSERT(nb01 % 16 == 0); break;
|
|
2165
|
+
// case GGML_TYPE_F16: GGML_ASSERT(nb01 % 8 == 0); break;
|
|
2166
|
+
// case GGML_TYPE_BF16: GGML_ASSERT(nb01 % 8 == 0); break;
|
|
2167
|
+
// default: break;
|
|
2168
|
+
//}
|
|
2169
|
+
|
|
2170
|
+
auto pipeline = ggml_metal_library_get_pipeline_mul_mm(lib, op);
|
|
2171
|
+
|
|
2172
|
+
ggml_metal_kargs_mul_mm args = {
|
|
2173
|
+
/*.ne00 =*/ ne00,
|
|
2174
|
+
/*.ne02 =*/ ne02,
|
|
2175
|
+
/*.nb01 =*/ nb01,
|
|
2176
|
+
/*.nb02 =*/ nb02,
|
|
2177
|
+
/*.nb03 =*/ nb03,
|
|
2178
|
+
/*.ne12 =*/ ne12,
|
|
2179
|
+
/*.nb10 =*/ nb10,
|
|
2180
|
+
/*.nb11 =*/ nb11,
|
|
2181
|
+
/*.nb12 =*/ nb12,
|
|
2182
|
+
/*.nb13 =*/ nb13,
|
|
2183
|
+
/*.ne0 =*/ ne0,
|
|
2184
|
+
/*.ne1 =*/ ne1,
|
|
2185
|
+
/*.r2 =*/ r2,
|
|
2186
|
+
/*.r3 =*/ r3,
|
|
2187
|
+
};
|
|
2188
|
+
|
|
2189
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
2190
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
2191
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
2192
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
2193
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
2194
|
+
|
|
2195
|
+
const size_t smem = pipeline.smem;
|
|
2196
|
+
|
|
2197
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
2198
|
+
|
|
2199
|
+
const int nr0 = pipeline.nr0;
|
|
2200
|
+
const int nr1 = pipeline.nr1;
|
|
2201
|
+
const int nsg = pipeline.nsg;
|
|
2202
|
+
|
|
2203
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ((ne11 + nr1 - 1) / nr1), ((ne01 + nr0 - 1) / nr0), ne12 * ne13, 32, nsg, 1);
|
|
2204
|
+
} else {
|
|
2205
|
+
auto pipeline = ggml_metal_library_get_pipeline_mul_mv(lib, op);
|
|
2206
|
+
|
|
2207
|
+
const int nr0 = pipeline.nr0;
|
|
2208
|
+
const int nr1 = pipeline.nr1;
|
|
2209
|
+
const int nsg = pipeline.nsg;
|
|
2210
|
+
|
|
2211
|
+
const size_t smem = pipeline.smem;
|
|
2212
|
+
|
|
2213
|
+
ggml_metal_kargs_mul_mv args = {
|
|
2214
|
+
/*.ne00 =*/ ne00,
|
|
2215
|
+
/*.ne01 =*/ ne01,
|
|
2216
|
+
/*.ne02 =*/ ne02,
|
|
2217
|
+
/*.nb00 =*/ nb00,
|
|
2218
|
+
/*.nb01 =*/ nb01,
|
|
2219
|
+
/*.nb02 =*/ nb02,
|
|
2220
|
+
/*.nb03 =*/ nb03,
|
|
2221
|
+
/*.ne10 =*/ ne10,
|
|
2222
|
+
/*.ne11 =*/ ne11,
|
|
2223
|
+
/*.ne12 =*/ ne12,
|
|
2224
|
+
/*.nb10 =*/ nb10,
|
|
2225
|
+
/*.nb11 =*/ nb11,
|
|
2226
|
+
/*.nb12 =*/ nb12,
|
|
2227
|
+
/*.nb13 =*/ nb13,
|
|
2228
|
+
/*.ne0 =*/ ne0,
|
|
2229
|
+
/*.ne1 =*/ ne1,
|
|
2230
|
+
/*.nr0 =*/ nr0,
|
|
2231
|
+
/*.r2 =*/ r2,
|
|
2232
|
+
/*.r3 =*/ r3,
|
|
2233
|
+
};
|
|
2234
|
+
|
|
2235
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
2236
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
2237
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
2238
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
2239
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
2240
|
+
|
|
2241
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
2242
|
+
|
|
2243
|
+
if (op->src[0]->type == GGML_TYPE_F32 ||
|
|
2244
|
+
op->src[0]->type == GGML_TYPE_F16 ||
|
|
2245
|
+
op->src[0]->type == GGML_TYPE_BF16 ||
|
|
2246
|
+
op->src[0]->type == GGML_TYPE_Q8_0) {
|
|
2247
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ((ne01 + nr0 - 1)/(nr0)), ((ne11 + nr1 - 1)/nr1), ne12*ne13, 32, nsg, 1);
|
|
2248
|
+
} else {
|
|
2249
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ((ne01 + nr0*nsg - 1)/(nr0*nsg)), ((ne11 + nr1 - 1)/nr1), ne12*ne13, 32, nsg, 1);
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
return 1;
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
size_t ggml_metal_op_mul_mat_id_extra_tpe(const ggml_tensor * op) {
|
|
2257
|
+
assert(op->op == GGML_OP_MUL_MAT_ID);
|
|
2258
|
+
|
|
2259
|
+
const int64_t ne02 = op->src[0]->ne[2]; // n_expert
|
|
2260
|
+
|
|
2261
|
+
return ggml_type_size(GGML_TYPE_I32)*ne02;
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
size_t ggml_metal_op_mul_mat_id_extra_ids(const ggml_tensor * op) {
|
|
2265
|
+
assert(op->op == GGML_OP_MUL_MAT_ID);
|
|
2266
|
+
|
|
2267
|
+
const int64_t ne02 = op->src[0]->ne[2]; // n_expert
|
|
2268
|
+
const int64_t ne21 = op->src[2]->ne[1]; // n_token
|
|
2269
|
+
|
|
2270
|
+
return ggml_type_size(GGML_TYPE_I32)*ne02*ne21;
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
int ggml_metal_op_mul_mat_id(ggml_metal_op_t ctx, int idx) {
|
|
2274
|
+
ggml_tensor * op = ctx->node(idx);
|
|
2275
|
+
|
|
2276
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
2277
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
2278
|
+
|
|
2279
|
+
const ggml_metal_device_props * props_dev = ggml_metal_device_get_props(ctx->dev);
|
|
2280
|
+
|
|
2281
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
2282
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
2283
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
2284
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
2285
|
+
GGML_TENSOR_LOCALS( int32_t, ne2, op->src[2], ne);
|
|
2286
|
+
GGML_TENSOR_LOCALS(uint64_t, nb2, op->src[2], nb);
|
|
2287
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
2288
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
2289
|
+
|
|
2290
|
+
// src2 = ids
|
|
2291
|
+
GGML_ASSERT(op->src[2]->type == GGML_TYPE_I32);
|
|
2292
|
+
|
|
2293
|
+
GGML_ASSERT(!ggml_is_transposed(op->src[0]));
|
|
2294
|
+
GGML_ASSERT(!ggml_is_transposed(op->src[1]));
|
|
2295
|
+
|
|
2296
|
+
GGML_ASSERT(ne03 == 1);
|
|
2297
|
+
GGML_ASSERT(ne13 == 1);
|
|
2298
|
+
|
|
2299
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
2300
|
+
ggml_metal_buffer_id bid_src1 = ggml_metal_get_buffer_id(op->src[1]);
|
|
2301
|
+
ggml_metal_buffer_id bid_src2 = ggml_metal_get_buffer_id(op->src[2]);
|
|
2302
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
2303
|
+
|
|
2304
|
+
const uint32_t r2 = 1;
|
|
2305
|
+
const uint32_t r3 = 1;
|
|
2306
|
+
|
|
2307
|
+
// find the break-even point where the matrix-matrix kernel becomes more efficient compared
|
|
2308
|
+
// to the matrix-vector kernel
|
|
2309
|
+
// ne20 = n_used_experts
|
|
2310
|
+
// ne21 = n_rows (batch size)
|
|
2311
|
+
const int ne21_mm_id_min = 32;
|
|
2312
|
+
|
|
2313
|
+
if (props_dev->has_simdgroup_mm && ne00 >= 64 && (ne21 >= ne21_mm_id_min)) {
|
|
2314
|
+
// some Metal matrix data types require aligned pointers
|
|
2315
|
+
// ref: https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf (Table 2.5)
|
|
2316
|
+
//switch (op->src[0]->type) {
|
|
2317
|
+
// case GGML_TYPE_F32: GGML_ASSERT(nb01 % 16 == 0); break;
|
|
2318
|
+
// case GGML_TYPE_F16: GGML_ASSERT(nb01 % 8 == 0); break;
|
|
2319
|
+
// case GGML_TYPE_BF16: GGML_ASSERT(nb01 % 8 == 0); break;
|
|
2320
|
+
// default: break;
|
|
2321
|
+
//}
|
|
2322
|
+
|
|
2323
|
+
// extra buffers for intermediate id mapping
|
|
2324
|
+
ggml_metal_buffer_id bid_tpe = bid_dst;
|
|
2325
|
+
bid_tpe.offs += ggml_nbytes(op);
|
|
2326
|
+
|
|
2327
|
+
ggml_metal_buffer_id bid_ids = bid_tpe;
|
|
2328
|
+
bid_ids.offs += ggml_metal_op_mul_mat_id_extra_tpe(op);
|
|
2329
|
+
|
|
2330
|
+
{
|
|
2331
|
+
ggml_metal_kargs_mul_mm_id_map0 args = {
|
|
2332
|
+
ne02,
|
|
2333
|
+
ne10,
|
|
2334
|
+
ne11, // n_expert_used (bcast)
|
|
2335
|
+
nb11,
|
|
2336
|
+
nb12,
|
|
2337
|
+
ne21, // n_tokens
|
|
2338
|
+
ne20, // n_expert_used
|
|
2339
|
+
nb21,
|
|
2340
|
+
};
|
|
2341
|
+
|
|
2342
|
+
auto pipeline = ggml_metal_library_get_pipeline_mul_mm_id_map0(lib, ne02, ne20);
|
|
2343
|
+
|
|
2344
|
+
const size_t smem = pipeline.smem;
|
|
2345
|
+
|
|
2346
|
+
GGML_ASSERT(ne02 <= ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
2347
|
+
|
|
2348
|
+
GGML_ASSERT(smem <= props_dev->max_theadgroup_memory_size);
|
|
2349
|
+
|
|
2350
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
2351
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
2352
|
+
ggml_metal_encoder_set_buffer (enc, bid_src2, 1);
|
|
2353
|
+
ggml_metal_encoder_set_buffer (enc, bid_tpe, 2);
|
|
2354
|
+
ggml_metal_encoder_set_buffer (enc, bid_ids, 3);
|
|
2355
|
+
|
|
2356
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
2357
|
+
|
|
2358
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, 1, 1, 1, ne02, 1, 1);
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
// this barrier is always needed because the next kernel has to wait for the id maps to be computed
|
|
2362
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
2363
|
+
|
|
2364
|
+
{
|
|
2365
|
+
auto pipeline = ggml_metal_library_get_pipeline_mul_mm_id(lib, op);
|
|
2366
|
+
|
|
2367
|
+
ggml_metal_kargs_mul_mm_id args = {
|
|
2368
|
+
/*.ne00 =*/ ne00,
|
|
2369
|
+
/*.ne02 =*/ ne02,
|
|
2370
|
+
/*.nb01 =*/ nb01,
|
|
2371
|
+
/*.nb02 =*/ nb02,
|
|
2372
|
+
/*.nb03 =*/ nb03,
|
|
2373
|
+
/*.ne11 =*/ ne11, // n_expert_used (bcast)
|
|
2374
|
+
/*.nb10 =*/ nb10,
|
|
2375
|
+
/*.nb11 =*/ nb11,
|
|
2376
|
+
/*.nb12 =*/ nb12,
|
|
2377
|
+
/*.nb13 =*/ nb13,
|
|
2378
|
+
/*.ne20 =*/ ne20, // n_expert_used
|
|
2379
|
+
/*.ne21 =*/ ne21, // n_tokens
|
|
2380
|
+
/*.ne0 =*/ ne0,
|
|
2381
|
+
/*.ne1 =*/ ne1,
|
|
2382
|
+
/*.r2 =*/ r2,
|
|
2383
|
+
/*.r3 =*/ r3,
|
|
2384
|
+
};
|
|
2385
|
+
|
|
2386
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
2387
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
2388
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
2389
|
+
ggml_metal_encoder_set_buffer (enc, bid_src1, 2);
|
|
2390
|
+
ggml_metal_encoder_set_buffer (enc, bid_tpe, 3);
|
|
2391
|
+
ggml_metal_encoder_set_buffer (enc, bid_ids, 4);
|
|
2392
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 5);
|
|
2393
|
+
|
|
2394
|
+
const size_t smem = pipeline.smem;
|
|
2395
|
+
|
|
2396
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
2397
|
+
|
|
2398
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, (ne21 + 31)/32, (ne01 + 63)/64, ne02, 128, 1, 1);
|
|
2399
|
+
}
|
|
2400
|
+
} else {
|
|
2401
|
+
auto pipeline = ggml_metal_library_get_pipeline_mul_mv_id(lib, op);
|
|
2402
|
+
|
|
2403
|
+
const int nr0 = pipeline.nr0;
|
|
2404
|
+
const int nr1 = pipeline.nr1;
|
|
2405
|
+
const int nsg = pipeline.nsg;
|
|
2406
|
+
|
|
2407
|
+
const size_t smem = pipeline.smem;
|
|
2408
|
+
|
|
2409
|
+
ggml_metal_kargs_mul_mv_id args = {
|
|
2410
|
+
/*.nei0 =*/ ne20,
|
|
2411
|
+
/*.nei1 =*/ ne21,
|
|
2412
|
+
/*.nbi1 =*/ nb21,
|
|
2413
|
+
/*.ne00 =*/ ne00,
|
|
2414
|
+
/*.ne01 =*/ ne01,
|
|
2415
|
+
/*.ne02 =*/ ne02,
|
|
2416
|
+
/*.nb00 =*/ nb00,
|
|
2417
|
+
/*.nb01 =*/ nb01,
|
|
2418
|
+
/*.nb02 =*/ nb02,
|
|
2419
|
+
/*.ne10 =*/ ne10,
|
|
2420
|
+
/*.ne11 =*/ ne11,
|
|
2421
|
+
/*.ne12 =*/ ne12,
|
|
2422
|
+
/*.ne13 =*/ ne13,
|
|
2423
|
+
/*.nb10 =*/ nb10,
|
|
2424
|
+
/*.nb11 =*/ nb11,
|
|
2425
|
+
/*.nb12 =*/ nb12,
|
|
2426
|
+
/*.ne0 =*/ ne0,
|
|
2427
|
+
/*.ne1 =*/ ne1,
|
|
2428
|
+
/*.nb1 =*/ nb1,
|
|
2429
|
+
/*.nr0 =*/ nr0,
|
|
2430
|
+
};
|
|
2431
|
+
|
|
2432
|
+
if (ggml_is_quantized(op->src[0]->type)) {
|
|
2433
|
+
GGML_ASSERT(ne00 >= nsg*nr0);
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
2437
|
+
ggml_metal_encoder_set_bytes(enc, &args, sizeof(args), 0);
|
|
2438
|
+
ggml_metal_encoder_set_buffer(enc, bid_src0, 1);
|
|
2439
|
+
ggml_metal_encoder_set_buffer(enc, bid_src1, 2);
|
|
2440
|
+
ggml_metal_encoder_set_buffer(enc, bid_dst, 3);
|
|
2441
|
+
ggml_metal_encoder_set_buffer(enc, bid_src2, 4);
|
|
2442
|
+
|
|
2443
|
+
const int64_t _ne1 = 1;
|
|
2444
|
+
const int64_t ne123 = ne20*ne21;
|
|
2445
|
+
|
|
2446
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
2447
|
+
|
|
2448
|
+
if (op->src[0]->type == GGML_TYPE_F32 ||
|
|
2449
|
+
op->src[0]->type == GGML_TYPE_F16 ||
|
|
2450
|
+
op->src[0]->type == GGML_TYPE_BF16 ||
|
|
2451
|
+
op->src[0]->type == GGML_TYPE_Q8_0) {
|
|
2452
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, (ne01 + nr0 - 1)/(nr0), (_ne1 + nr1 - 1)/nr1, ne123, 32, nsg, 1);
|
|
2453
|
+
} else {
|
|
2454
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, (ne01 + nr0*nsg - 1)/(nr0*nsg), (_ne1 + nr1 - 1)/nr1, ne123, 32, nsg, 1);
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
|
|
2458
|
+
return 1;
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
int ggml_metal_op_add_id(ggml_metal_op_t ctx, int idx) {
|
|
2462
|
+
ggml_tensor * op = ctx->node(idx);
|
|
2463
|
+
|
|
2464
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
2465
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
2466
|
+
|
|
2467
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
2468
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
2469
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
2470
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
2471
|
+
GGML_TENSOR_LOCALS( int32_t, ne2, op->src[2], ne);
|
|
2472
|
+
GGML_TENSOR_LOCALS(uint64_t, nb2, op->src[2], nb);
|
|
2473
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
2474
|
+
|
|
2475
|
+
GGML_ASSERT(op->src[0]->type == GGML_TYPE_F32);
|
|
2476
|
+
GGML_ASSERT(op->src[1]->type == GGML_TYPE_F32);
|
|
2477
|
+
GGML_ASSERT(op->src[2]->type == GGML_TYPE_I32);
|
|
2478
|
+
GGML_ASSERT(op->type == GGML_TYPE_F32);
|
|
2479
|
+
|
|
2480
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[0]));
|
|
2481
|
+
|
|
2482
|
+
ggml_metal_kargs_add_id args = {
|
|
2483
|
+
/*.ne0 =*/ ne0,
|
|
2484
|
+
/*.ne1 =*/ ne1,
|
|
2485
|
+
/*.nb01 =*/ nb01,
|
|
2486
|
+
/*.nb02 =*/ nb02,
|
|
2487
|
+
/*.nb11 =*/ nb11,
|
|
2488
|
+
/*.nb21 =*/ nb21,
|
|
2489
|
+
};
|
|
2490
|
+
|
|
2491
|
+
auto pipeline = ggml_metal_library_get_pipeline_base(lib, GGML_OP_ADD_ID);
|
|
2492
|
+
|
|
2493
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
2494
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
2495
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
2496
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
2497
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[2]), 3);
|
|
2498
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 4);
|
|
2499
|
+
|
|
2500
|
+
const int nth = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline), ne00);
|
|
2501
|
+
|
|
2502
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, 1, nth, 1, 1);
|
|
2503
|
+
|
|
2504
|
+
return 1;
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2507
|
+
bool ggml_metal_op_flash_attn_ext_use_vec(const ggml_tensor * op) {
|
|
2508
|
+
assert(op->op == GGML_OP_FLASH_ATTN_EXT);
|
|
2509
|
+
|
|
2510
|
+
const int64_t ne00 = op->src[0]->ne[0]; // head size
|
|
2511
|
+
const int64_t ne01 = op->src[0]->ne[1]; // batch size
|
|
2512
|
+
|
|
2513
|
+
// use vec kernel if the batch size is small and if the head size is supported
|
|
2514
|
+
return (ne01 < 20) && (ne00 % 32 == 0);
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
size_t ggml_metal_op_flash_attn_ext_extra_pad(const ggml_tensor * op) {
|
|
2518
|
+
assert(op->op == GGML_OP_FLASH_ATTN_EXT);
|
|
2519
|
+
|
|
2520
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
2521
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
2522
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
2523
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
2524
|
+
GGML_TENSOR_LOCALS( int32_t, ne2, op->src[2], ne);
|
|
2525
|
+
GGML_TENSOR_LOCALS(uint64_t, nb2, op->src[2], nb);
|
|
2526
|
+
GGML_TENSOR_LOCALS( int32_t, ne3, op->src[3], ne);
|
|
2527
|
+
GGML_TENSOR_LOCALS(uint64_t, nb3, op->src[3], nb);
|
|
2528
|
+
|
|
2529
|
+
size_t res = 0;
|
|
2530
|
+
|
|
2531
|
+
const bool has_mask = op->src[3] != nullptr;
|
|
2532
|
+
|
|
2533
|
+
// note: the non-vec kernel requires more extra memory, so always reserve for it
|
|
2534
|
+
GGML_ASSERT(OP_FLASH_ATTN_EXT_NCPSG >= OP_FLASH_ATTN_EXT_VEC_NCPSG);
|
|
2535
|
+
|
|
2536
|
+
//if (ggml_metal_op_flash_attn_ext_use_vec(op)) {
|
|
2537
|
+
if (false) {
|
|
2538
|
+
// note: always reserve the padding space to avoid graph reallocations
|
|
2539
|
+
//const bool has_kvpad = ne11 % OP_FLASH_ATTN_EXT_VEC_NCPSG != 0;
|
|
2540
|
+
const bool has_kvpad = true;
|
|
2541
|
+
|
|
2542
|
+
if (has_kvpad) {
|
|
2543
|
+
res += OP_FLASH_ATTN_EXT_VEC_NCPSG*(
|
|
2544
|
+
nb11*ne12*ne13 +
|
|
2545
|
+
nb21*ne22*ne23 +
|
|
2546
|
+
(has_mask ? ggml_type_size(GGML_TYPE_F16)*ne31*ne32*ne33 : 0));
|
|
2547
|
+
}
|
|
2548
|
+
} else {
|
|
2549
|
+
//const bool has_kvpad = ne11 % OP_FLASH_ATTN_EXT_NCPSG != 0;
|
|
2550
|
+
const bool has_kvpad = true;
|
|
2551
|
+
|
|
2552
|
+
if (has_kvpad) {
|
|
2553
|
+
res += OP_FLASH_ATTN_EXT_NCPSG*(
|
|
2554
|
+
nb11*ne12*ne13 +
|
|
2555
|
+
nb21*ne22*ne23 +
|
|
2556
|
+
(has_mask ? ggml_type_size(GGML_TYPE_F16)*ne31*ne32*ne33 : 0));
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
return res;
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
size_t ggml_metal_op_flash_attn_ext_extra_blk(const ggml_tensor * op) {
|
|
2564
|
+
assert(op->op == GGML_OP_FLASH_ATTN_EXT);
|
|
2565
|
+
|
|
2566
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
2567
|
+
//GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
2568
|
+
//GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
2569
|
+
//GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
2570
|
+
//GGML_TENSOR_LOCALS( int32_t, ne2, op->src[2], ne);
|
|
2571
|
+
//GGML_TENSOR_LOCALS(uint64_t, nb2, op->src[2], nb);
|
|
2572
|
+
GGML_TENSOR_LOCALS( int32_t, ne3, op->src[3], ne);
|
|
2573
|
+
GGML_TENSOR_LOCALS(uint64_t, nb3, op->src[3], nb);
|
|
2574
|
+
|
|
2575
|
+
size_t res = 0;
|
|
2576
|
+
|
|
2577
|
+
const bool has_mask = op->src[3] != nullptr;
|
|
2578
|
+
|
|
2579
|
+
if (!has_mask) {
|
|
2580
|
+
return res;
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
const bool is_vec = ggml_metal_op_flash_attn_ext_use_vec(op);
|
|
2584
|
+
|
|
2585
|
+
// this optimization is not useful for the vector kernels
|
|
2586
|
+
// note: always reserve the blk buffer to avoid graph reallocations
|
|
2587
|
+
//if (is_vec) {
|
|
2588
|
+
// return res;
|
|
2589
|
+
//}
|
|
2590
|
+
|
|
2591
|
+
const int nqptg = is_vec ? OP_FLASH_ATTN_EXT_VEC_NQPSG : OP_FLASH_ATTN_EXT_NQPSG;
|
|
2592
|
+
const int ncpsg = is_vec ? OP_FLASH_ATTN_EXT_VEC_NCPSG : OP_FLASH_ATTN_EXT_NCPSG;
|
|
2593
|
+
|
|
2594
|
+
const int64_t ne1 = (ne01 + nqptg - 1)/nqptg;
|
|
2595
|
+
const int64_t ne0 = (ne30 + ncpsg - 1)/ncpsg;
|
|
2596
|
+
|
|
2597
|
+
res += GGML_PAD(ggml_type_size(GGML_TYPE_I8)*ne0*ne1*ne32*ne33, 32);
|
|
2598
|
+
|
|
2599
|
+
return res;
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
size_t ggml_metal_op_flash_attn_ext_extra_tmp(const ggml_tensor * op) {
|
|
2603
|
+
assert(op->op == GGML_OP_FLASH_ATTN_EXT);
|
|
2604
|
+
|
|
2605
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
2606
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
2607
|
+
//GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
2608
|
+
//GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
2609
|
+
GGML_TENSOR_LOCALS( int32_t, ne2, op->src[2], ne);
|
|
2610
|
+
GGML_TENSOR_LOCALS(uint64_t, nb2, op->src[2], nb);
|
|
2611
|
+
//GGML_TENSOR_LOCALS( int32_t, ne3, op->src[3], ne);
|
|
2612
|
+
//GGML_TENSOR_LOCALS(uint64_t, nb3, op->src[3], nb);
|
|
2613
|
+
|
|
2614
|
+
size_t res = 0;
|
|
2615
|
+
|
|
2616
|
+
// note: always reserve the temp buffer to avoid graph reallocations
|
|
2617
|
+
//if (ggml_metal_op_flash_attn_ext_use_vec(op)) {
|
|
2618
|
+
if (true) {
|
|
2619
|
+
const int64_t nwg = 32;
|
|
2620
|
+
const int64_t ne01_max = std::min(ne01, 32);
|
|
2621
|
+
|
|
2622
|
+
// temp buffer for writing the results from each workgroup
|
|
2623
|
+
// - ne20: the size of the Value head
|
|
2624
|
+
// - + 2: the S and M values for each intermediate result
|
|
2625
|
+
res += ggml_type_size(GGML_TYPE_F32)*(ne01_max*ne02*ne03*nwg*(ne20 + 2));
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2628
|
+
return res;
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
int ggml_metal_op_flash_attn_ext(ggml_metal_op_t ctx, int idx) {
|
|
2632
|
+
ggml_tensor * op = ctx->node(idx);
|
|
2633
|
+
|
|
2634
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
2635
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
2636
|
+
|
|
2637
|
+
const ggml_metal_device_props * props_dev = ggml_metal_device_get_props(ctx->dev);
|
|
2638
|
+
|
|
2639
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
2640
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
2641
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
2642
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
2643
|
+
GGML_TENSOR_LOCALS( int32_t, ne2, op->src[2], ne);
|
|
2644
|
+
GGML_TENSOR_LOCALS(uint64_t, nb2, op->src[2], nb);
|
|
2645
|
+
GGML_TENSOR_LOCALS( int32_t, ne3, op->src[3], ne);
|
|
2646
|
+
GGML_TENSOR_LOCALS(uint64_t, nb3, op->src[3], nb);
|
|
2647
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
2648
|
+
GGML_TENSOR_LOCALS( int32_t, nb, op, nb);
|
|
2649
|
+
|
|
2650
|
+
GGML_ASSERT(ne00 % 4 == 0);
|
|
2651
|
+
|
|
2652
|
+
GGML_ASSERT(op->src[0]->type == GGML_TYPE_F32);
|
|
2653
|
+
GGML_ASSERT(op->src[1]->type == op->src[2]->type);
|
|
2654
|
+
|
|
2655
|
+
//GGML_ASSERT(ggml_are_same_shape (src1, src2));
|
|
2656
|
+
GGML_ASSERT(ne11 == ne21);
|
|
2657
|
+
GGML_ASSERT(ne12 == ne22);
|
|
2658
|
+
|
|
2659
|
+
GGML_ASSERT(!op->src[3] || op->src[3]->type == GGML_TYPE_F16);
|
|
2660
|
+
GGML_ASSERT(!op->src[3] || op->src[3]->ne[1] >= op->src[0]->ne[1] &&
|
|
2661
|
+
"the Flash-Attention Metal kernel requires the mask to be at least n_queries big");
|
|
2662
|
+
|
|
2663
|
+
float scale;
|
|
2664
|
+
float max_bias;
|
|
2665
|
+
float logit_softcap;
|
|
2666
|
+
|
|
2667
|
+
memcpy(&scale, ((const int32_t *) op->op_params) + 0, sizeof(scale));
|
|
2668
|
+
memcpy(&max_bias, ((const int32_t *) op->op_params) + 1, sizeof(max_bias));
|
|
2669
|
+
memcpy(&logit_softcap, ((const int32_t *) op->op_params) + 2, sizeof(logit_softcap));
|
|
2670
|
+
|
|
2671
|
+
if (logit_softcap != 0.0f) {
|
|
2672
|
+
scale /= logit_softcap;
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
const bool has_mask = op->src[3] != NULL;
|
|
2676
|
+
const bool has_sinks = op->src[4] != NULL;
|
|
2677
|
+
const bool has_bias = max_bias != 0.0f;
|
|
2678
|
+
const bool has_scap = logit_softcap != 0.0f;
|
|
2679
|
+
|
|
2680
|
+
const uint32_t n_head = op->src[0]->ne[2];
|
|
2681
|
+
const int32_t n_head_log2 = 1u << (uint32_t) floorf(log2f((float) n_head));
|
|
2682
|
+
|
|
2683
|
+
const float m0 = powf(2.0f, -(max_bias ) / n_head_log2);
|
|
2684
|
+
const float m1 = powf(2.0f, -(max_bias / 2.0f) / n_head_log2);
|
|
2685
|
+
|
|
2686
|
+
GGML_ASSERT(ne01 < 65536);
|
|
2687
|
+
|
|
2688
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
2689
|
+
ggml_metal_buffer_id bid_src1 = ggml_metal_get_buffer_id(op->src[1]);
|
|
2690
|
+
ggml_metal_buffer_id bid_src2 = ggml_metal_get_buffer_id(op->src[2]);
|
|
2691
|
+
ggml_metal_buffer_id bid_src3 = has_mask ? ggml_metal_get_buffer_id(op->src[3]) : bid_src0;
|
|
2692
|
+
ggml_metal_buffer_id bid_src4 = has_sinks ? ggml_metal_get_buffer_id(op->src[4]) : bid_src0;
|
|
2693
|
+
|
|
2694
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
2695
|
+
|
|
2696
|
+
ggml_metal_buffer_id bid_pad = bid_dst;
|
|
2697
|
+
bid_pad.offs += ggml_nbytes(op);
|
|
2698
|
+
|
|
2699
|
+
ggml_metal_buffer_id bid_blk = bid_pad;
|
|
2700
|
+
bid_blk.offs += ggml_metal_op_flash_attn_ext_extra_pad(op);
|
|
2701
|
+
|
|
2702
|
+
ggml_metal_buffer_id bid_tmp = bid_blk;
|
|
2703
|
+
bid_tmp.offs += ggml_metal_op_flash_attn_ext_extra_blk(op);
|
|
2704
|
+
|
|
2705
|
+
if (!ggml_metal_op_flash_attn_ext_use_vec(op)) {
|
|
2706
|
+
// half8x8 kernel
|
|
2707
|
+
const int nqptg = OP_FLASH_ATTN_EXT_NQPSG; // queries per threadgroup
|
|
2708
|
+
const int ncpsg = OP_FLASH_ATTN_EXT_NCPSG; // cache values per simdgroup
|
|
2709
|
+
|
|
2710
|
+
GGML_ASSERT(nqptg <= 32);
|
|
2711
|
+
GGML_ASSERT(nqptg % 8 == 0);
|
|
2712
|
+
GGML_ASSERT(ncpsg % 32 == 0);
|
|
2713
|
+
|
|
2714
|
+
bool need_sync = false;
|
|
2715
|
+
|
|
2716
|
+
const bool has_kvpad = ne11 % ncpsg != 0;
|
|
2717
|
+
|
|
2718
|
+
if (has_kvpad) {
|
|
2719
|
+
assert(ggml_metal_op_flash_attn_ext_extra_pad(op) != 0);
|
|
2720
|
+
|
|
2721
|
+
ggml_metal_kargs_flash_attn_ext_pad args0 = {
|
|
2722
|
+
/*.ne11 =*/ne11,
|
|
2723
|
+
/*.ne_12_2 =*/ne12,
|
|
2724
|
+
/*.ne_12_3 =*/ne13,
|
|
2725
|
+
/*.nb11 =*/nb11,
|
|
2726
|
+
/*.nb12 =*/nb12,
|
|
2727
|
+
/*.nb13 =*/nb13,
|
|
2728
|
+
/*.nb21 =*/nb21,
|
|
2729
|
+
/*.nb22 =*/nb22,
|
|
2730
|
+
/*.nb23 =*/nb23,
|
|
2731
|
+
/*.ne31 =*/ne31,
|
|
2732
|
+
/*.ne32 =*/ne32,
|
|
2733
|
+
/*.ne33 =*/ne33,
|
|
2734
|
+
/*.nb31 =*/nb31,
|
|
2735
|
+
/*.nb32 =*/nb32,
|
|
2736
|
+
/*.nb33 =*/nb33,
|
|
2737
|
+
};
|
|
2738
|
+
|
|
2739
|
+
auto pipeline0 = ggml_metal_library_get_pipeline_flash_attn_ext_pad(lib, op, has_mask, ncpsg);
|
|
2740
|
+
|
|
2741
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline0);
|
|
2742
|
+
ggml_metal_encoder_set_bytes (enc, &args0, sizeof(args0), 0);
|
|
2743
|
+
ggml_metal_encoder_set_buffer (enc, bid_src1, 1);
|
|
2744
|
+
ggml_metal_encoder_set_buffer (enc, bid_src2, 2);
|
|
2745
|
+
ggml_metal_encoder_set_buffer (enc, bid_src3, 3);
|
|
2746
|
+
ggml_metal_encoder_set_buffer (enc, bid_pad, 4);
|
|
2747
|
+
|
|
2748
|
+
assert(ne12 == ne22);
|
|
2749
|
+
assert(ne13 == ne23);
|
|
2750
|
+
|
|
2751
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ncpsg, std::max(ne12, ne32), std::max(ne13, ne33), 32, 1, 1);
|
|
2752
|
+
|
|
2753
|
+
need_sync = true;
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
if (has_mask) {
|
|
2757
|
+
assert(ggml_metal_op_flash_attn_ext_extra_blk(op) != 0);
|
|
2758
|
+
|
|
2759
|
+
ggml_metal_kargs_flash_attn_ext_blk args0 = {
|
|
2760
|
+
/*.ne01 =*/ ne01,
|
|
2761
|
+
/*.ne30 =*/ ne30,
|
|
2762
|
+
/*.ne31 =*/ ne31,
|
|
2763
|
+
/*.ne32 =*/ ne32,
|
|
2764
|
+
/*.ne33 =*/ ne33,
|
|
2765
|
+
/*.nb31 =*/ nb31,
|
|
2766
|
+
/*.nb32 =*/ nb32,
|
|
2767
|
+
/*.nb33 =*/ nb33,
|
|
2768
|
+
};
|
|
2769
|
+
|
|
2770
|
+
auto pipeline0 = ggml_metal_library_get_pipeline_flash_attn_ext_blk(lib, op, nqptg, ncpsg);
|
|
2771
|
+
|
|
2772
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline0);
|
|
2773
|
+
ggml_metal_encoder_set_bytes (enc, &args0, sizeof(args0), 0);
|
|
2774
|
+
ggml_metal_encoder_set_buffer (enc, bid_src3, 1);
|
|
2775
|
+
ggml_metal_encoder_set_buffer (enc, bid_blk, 2);
|
|
2776
|
+
|
|
2777
|
+
const int32_t nblk1 = ((ne01 + nqptg - 1)/nqptg);
|
|
2778
|
+
const int32_t nblk0 = ((ne30 + ncpsg - 1)/ncpsg);
|
|
2779
|
+
|
|
2780
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, nblk0, nblk1, ne32*ne33, 32, 1, 1);
|
|
2781
|
+
|
|
2782
|
+
need_sync = true;
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2785
|
+
if (need_sync) {
|
|
2786
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2789
|
+
const int is_q = ggml_is_quantized(op->src[1]->type) ? 1 : 0;
|
|
2790
|
+
|
|
2791
|
+
// 2*(2*ncpsg)
|
|
2792
|
+
// ncpsg soft_max values + ncpsg mask values
|
|
2793
|
+
//
|
|
2794
|
+
// 16*32*(nsg)
|
|
2795
|
+
// the shared memory needed for the simdgroups to load the KV cache
|
|
2796
|
+
// each thread loads (dequantizes) 16 head elements, there are 32 threads in th SG
|
|
2797
|
+
//
|
|
2798
|
+
#define FATTN_SMEM(nsg) (GGML_PAD((nqptg*(ne00 + 2*GGML_PAD(ne20, 64) + 2*(2*ncpsg)) + is_q*(16*32*(nsg)))*(sizeof(float)/2), 16))
|
|
2799
|
+
|
|
2800
|
+
//int64_t nsgmax = 4;
|
|
2801
|
+
//
|
|
2802
|
+
//if (is_q) {
|
|
2803
|
+
// nsgmax = 2;
|
|
2804
|
+
// while (true) {
|
|
2805
|
+
// const size_t smem = FATTN_SMEM(nsgmax);
|
|
2806
|
+
// if (smem > props_dev->max_theadgroup_memory_size) {
|
|
2807
|
+
// break;
|
|
2808
|
+
// }
|
|
2809
|
+
// nsgmax *= 2;
|
|
2810
|
+
// }
|
|
2811
|
+
// nsgmax /= 2;
|
|
2812
|
+
//}
|
|
2813
|
+
|
|
2814
|
+
// simdgroups per threadgroup (a.k.a. warps)
|
|
2815
|
+
//nsg = ne01 <= nqptg ? MAX(4, MIN(nsgmax, MIN(ne11/ncpsg, (int64_t) pipeline.maxTotalThreadsPerThreadgroup/32))) : 4;
|
|
2816
|
+
int32_t nsg = ne00 >= 512 ? 8 : 4;
|
|
2817
|
+
|
|
2818
|
+
const size_t smem = FATTN_SMEM(nsg);
|
|
2819
|
+
|
|
2820
|
+
ggml_metal_kargs_flash_attn_ext args = {
|
|
2821
|
+
/*.ne01 =*/ ne01,
|
|
2822
|
+
/*.ne02 =*/ ne02,
|
|
2823
|
+
/*.ne03 =*/ ne03,
|
|
2824
|
+
/*.nb01 =*/ nb01,
|
|
2825
|
+
/*.nb02 =*/ nb02,
|
|
2826
|
+
/*.nb03 =*/ nb03,
|
|
2827
|
+
/*.ne11 =*/ ne11,
|
|
2828
|
+
/*.ne_12_2 =*/ ne12,
|
|
2829
|
+
/*.ne_12_3 =*/ ne13,
|
|
2830
|
+
/*.ns10 =*/ int32_t(nb11/nb10),
|
|
2831
|
+
/*.nb11 =*/ nb11,
|
|
2832
|
+
/*.nb12 =*/ nb12,
|
|
2833
|
+
/*.nb13 =*/ nb13,
|
|
2834
|
+
/*.ns20 =*/ int32_t(nb21/nb20),
|
|
2835
|
+
/*.nb21 =*/ nb21,
|
|
2836
|
+
/*.nb22 =*/ nb22,
|
|
2837
|
+
/*.nb23 =*/ nb23,
|
|
2838
|
+
/*.ne31 =*/ ne31,
|
|
2839
|
+
/*.ne32 =*/ ne32,
|
|
2840
|
+
/*.ne33 =*/ ne33,
|
|
2841
|
+
/*.nb31 =*/ nb31,
|
|
2842
|
+
/*.nb32 =*/ nb32,
|
|
2843
|
+
/*.nb33 =*/ nb33,
|
|
2844
|
+
/*.ne1 =*/ ne1,
|
|
2845
|
+
/*.ne2 =*/ ne2,
|
|
2846
|
+
/*.ne3 =*/ ne3,
|
|
2847
|
+
/*.scale =*/ scale,
|
|
2848
|
+
/*.max_bias =*/ max_bias,
|
|
2849
|
+
/*.m0 =*/ m0,
|
|
2850
|
+
/*.m1 =*/ m1,
|
|
2851
|
+
/*.n_head_log2 =*/ n_head_log2,
|
|
2852
|
+
/*.logit_softcap =*/ logit_softcap,
|
|
2853
|
+
};
|
|
2854
|
+
|
|
2855
|
+
auto pipeline = ggml_metal_library_get_pipeline_flash_attn_ext(lib, op, has_mask, has_sinks, has_bias, has_scap, has_kvpad, nsg);
|
|
2856
|
+
|
|
2857
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
2858
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
2859
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
2860
|
+
ggml_metal_encoder_set_buffer (enc, bid_src1, 2);
|
|
2861
|
+
ggml_metal_encoder_set_buffer (enc, bid_src2, 3);
|
|
2862
|
+
ggml_metal_encoder_set_buffer (enc, bid_src3, 4);
|
|
2863
|
+
ggml_metal_encoder_set_buffer (enc, bid_src4, 5);
|
|
2864
|
+
ggml_metal_encoder_set_buffer (enc, bid_pad, 6);
|
|
2865
|
+
ggml_metal_encoder_set_buffer (enc, bid_blk, 7);
|
|
2866
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 8);
|
|
2867
|
+
|
|
2868
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
2869
|
+
|
|
2870
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, (ne01 + nqptg - 1)/nqptg, ne02, ne03, 32, nsg, 1);
|
|
2871
|
+
#undef FATTN_SMEM
|
|
2872
|
+
} else {
|
|
2873
|
+
// half4x4 kernel
|
|
2874
|
+
const int nqptg = OP_FLASH_ATTN_EXT_VEC_NQPSG; // queries per threadgroup
|
|
2875
|
+
const int ncpsg = OP_FLASH_ATTN_EXT_VEC_NCPSG; // cache values per simdgroup !! sync with kernel template arguments !!
|
|
2876
|
+
const int nhptg = 1; // heads per threadgroup
|
|
2877
|
+
|
|
2878
|
+
GGML_ASSERT(nqptg <= 32);
|
|
2879
|
+
GGML_ASSERT(nqptg % 1 == 0);
|
|
2880
|
+
GGML_ASSERT(ncpsg % 32 == 0);
|
|
2881
|
+
|
|
2882
|
+
bool need_sync = false;
|
|
2883
|
+
|
|
2884
|
+
const bool has_kvpad = ne11 % ncpsg != 0;
|
|
2885
|
+
|
|
2886
|
+
if (has_kvpad) {
|
|
2887
|
+
assert(ggml_metal_op_flash_attn_ext_extra_pad(op) != 0);
|
|
2888
|
+
|
|
2889
|
+
ggml_metal_kargs_flash_attn_ext_pad args0 = {
|
|
2890
|
+
/*.ne11 =*/ne11,
|
|
2891
|
+
/*.ne_12_2 =*/ne12,
|
|
2892
|
+
/*.ne_12_3 =*/ne13,
|
|
2893
|
+
/*.nb11 =*/nb11,
|
|
2894
|
+
/*.nb12 =*/nb12,
|
|
2895
|
+
/*.nb13 =*/nb13,
|
|
2896
|
+
/*.nb21 =*/nb21,
|
|
2897
|
+
/*.nb22 =*/nb22,
|
|
2898
|
+
/*.nb23 =*/nb23,
|
|
2899
|
+
/*.ne31 =*/ne31,
|
|
2900
|
+
/*.ne32 =*/ne32,
|
|
2901
|
+
/*.ne33 =*/ne33,
|
|
2902
|
+
/*.nb31 =*/nb31,
|
|
2903
|
+
/*.nb32 =*/nb32,
|
|
2904
|
+
/*.nb33 =*/nb33,
|
|
2905
|
+
};
|
|
2906
|
+
|
|
2907
|
+
auto pipeline0 = ggml_metal_library_get_pipeline_flash_attn_ext_pad(lib, op, has_mask, ncpsg);
|
|
2908
|
+
|
|
2909
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline0);
|
|
2910
|
+
ggml_metal_encoder_set_bytes (enc, &args0, sizeof(args0), 0);
|
|
2911
|
+
ggml_metal_encoder_set_buffer (enc, bid_src1, 1);
|
|
2912
|
+
ggml_metal_encoder_set_buffer (enc, bid_src2, 2);
|
|
2913
|
+
ggml_metal_encoder_set_buffer (enc, bid_src3, 3);
|
|
2914
|
+
ggml_metal_encoder_set_buffer (enc, bid_pad, 4);
|
|
2915
|
+
|
|
2916
|
+
assert(ne12 == ne22);
|
|
2917
|
+
assert(ne13 == ne23);
|
|
2918
|
+
|
|
2919
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ncpsg, std::max(ne12, ne32), std::max(ne13, ne33), 32, 1, 1);
|
|
2920
|
+
|
|
2921
|
+
need_sync = true;
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
if (need_sync) {
|
|
2925
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
2926
|
+
}
|
|
2927
|
+
|
|
2928
|
+
// note: for simplicity assume the K is larger or equal than V
|
|
2929
|
+
GGML_ASSERT(ne10 >= ne20);
|
|
2930
|
+
|
|
2931
|
+
// ne00 + 2*ncpsg*(nsg)
|
|
2932
|
+
// for each query, we load it as f16 in shared memory (ne00)
|
|
2933
|
+
// and store the soft_max values and the mask
|
|
2934
|
+
//
|
|
2935
|
+
// ne20*(nsg)
|
|
2936
|
+
// each simdgroup has a full f32 head vector in shared mem to accumulate results
|
|
2937
|
+
//
|
|
2938
|
+
#define FATTN_SMEM(nsg) (GGML_PAD(((GGML_PAD(ne00, 128) + 4*ncpsg + 2*GGML_PAD(ne20, 128))*(nsg))*(sizeof(float)/2), 16))
|
|
2939
|
+
|
|
2940
|
+
int64_t nsg = 1;
|
|
2941
|
+
|
|
2942
|
+
// workgroups
|
|
2943
|
+
// each workgroup handles nsg*nkpsg cache values
|
|
2944
|
+
int32_t nwg = 1;
|
|
2945
|
+
if (false) {
|
|
2946
|
+
// for small KV caches, we could launch a single workgroup and write the results directly to dst/
|
|
2947
|
+
// however, this does not lead to significant improvement, so disabled
|
|
2948
|
+
nwg = 1;
|
|
2949
|
+
nsg = 4;
|
|
2950
|
+
} else {
|
|
2951
|
+
nwg = 32;
|
|
2952
|
+
nsg = 1;
|
|
2953
|
+
while (2*nwg*nsg*ncpsg < ne11 && nsg < 4) {
|
|
2954
|
+
nsg *= 2;
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
ggml_metal_kargs_flash_attn_ext_vec args = {
|
|
2959
|
+
/*.ne01 =*/ ne01,
|
|
2960
|
+
/*.ne02 =*/ ne02,
|
|
2961
|
+
/*.ne03 =*/ ne03,
|
|
2962
|
+
/*.nb01 =*/ nb01,
|
|
2963
|
+
/*.nb02 =*/ nb02,
|
|
2964
|
+
/*.nb03 =*/ nb03,
|
|
2965
|
+
/*.ne11 =*/ ne11,
|
|
2966
|
+
/*.ne_12_2 =*/ ne12,
|
|
2967
|
+
/*.ne_12_3 =*/ ne13,
|
|
2968
|
+
/*.ns10 =*/ int32_t(nb11/nb10),
|
|
2969
|
+
/*.nb11 =*/ nb11,
|
|
2970
|
+
/*.nb12 =*/ nb12,
|
|
2971
|
+
/*.nb13 =*/ nb13,
|
|
2972
|
+
/*.ns20 =*/ int32_t(nb21/nb20),
|
|
2973
|
+
/*.nb21 =*/ nb21,
|
|
2974
|
+
/*.nb22 =*/ nb22,
|
|
2975
|
+
/*.nb23 =*/ nb23,
|
|
2976
|
+
/*.ne31 =*/ ne31,
|
|
2977
|
+
/*.ne32 =*/ ne32,
|
|
2978
|
+
/*.ne33 =*/ ne33,
|
|
2979
|
+
/*.nb31 =*/ nb31,
|
|
2980
|
+
/*.nb32 =*/ nb32,
|
|
2981
|
+
/*.nb33 =*/ nb33,
|
|
2982
|
+
/*.ne1 =*/ ne1,
|
|
2983
|
+
/*.ne2 =*/ ne2,
|
|
2984
|
+
/*.ne3 =*/ ne3,
|
|
2985
|
+
/*.scale =*/ scale,
|
|
2986
|
+
/*.max_bias =*/ max_bias,
|
|
2987
|
+
/*.m0 =*/ m0,
|
|
2988
|
+
/*.m1 =*/ m1,
|
|
2989
|
+
/*.n_head_log2 =*/ n_head_log2,
|
|
2990
|
+
/*.logit_softcap =*/ logit_softcap,
|
|
2991
|
+
};
|
|
2992
|
+
|
|
2993
|
+
auto pipeline = ggml_metal_library_get_pipeline_flash_attn_ext_vec(lib, op, has_mask, has_sinks, has_bias, has_scap, has_kvpad, nsg, nwg);
|
|
2994
|
+
|
|
2995
|
+
GGML_ASSERT(nsg*32 <= ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
2996
|
+
|
|
2997
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
2998
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
2999
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
3000
|
+
ggml_metal_encoder_set_buffer (enc, bid_src1, 2);
|
|
3001
|
+
ggml_metal_encoder_set_buffer (enc, bid_src2, 3);
|
|
3002
|
+
ggml_metal_encoder_set_buffer (enc, bid_src3, 4);
|
|
3003
|
+
ggml_metal_encoder_set_buffer (enc, bid_src4, 5);
|
|
3004
|
+
|
|
3005
|
+
const size_t smem = FATTN_SMEM(nsg);
|
|
3006
|
+
|
|
3007
|
+
//printf("smem: %zu, max: %zu, nsg = %d, nsgmax = %d\n", smem, props_dev->max_theadgroup_memory_size, (int) nsg, (int) nsgmax);
|
|
3008
|
+
GGML_ASSERT(smem <= props_dev->max_theadgroup_memory_size);
|
|
3009
|
+
|
|
3010
|
+
if (nwg == 1) {
|
|
3011
|
+
assert(ggml_metal_op_flash_attn_ext_extra_tmp(op) == 0);
|
|
3012
|
+
|
|
3013
|
+
// using 1 workgroup -> write the result directly into dst
|
|
3014
|
+
ggml_metal_encoder_set_buffer(enc, bid_pad, 6);
|
|
3015
|
+
ggml_metal_encoder_set_buffer(enc, bid_dst, 7);
|
|
3016
|
+
|
|
3017
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
3018
|
+
|
|
3019
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, (ne01 + nqptg - 1)/nqptg, (ne02 + nhptg - 1)/nhptg, ne03*nwg, 32, nsg, 1);
|
|
3020
|
+
} else {
|
|
3021
|
+
// sanity checks
|
|
3022
|
+
assert(ggml_metal_op_flash_attn_ext_extra_tmp(op) != 0);
|
|
3023
|
+
|
|
3024
|
+
GGML_ASSERT(ne01*ne02*ne03 == ne1*ne2*ne3);
|
|
3025
|
+
GGML_ASSERT((uint64_t)ne1*ne2*ne3 <= (1u << 31));
|
|
3026
|
+
|
|
3027
|
+
// write the results from each workgroup into a temp buffer
|
|
3028
|
+
ggml_metal_encoder_set_buffer(enc, bid_pad, 6);
|
|
3029
|
+
ggml_metal_encoder_set_buffer(enc, bid_tmp, 7);
|
|
3030
|
+
|
|
3031
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
3032
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, (ne01 + nqptg - 1)/nqptg, (ne02 + nhptg - 1)/nhptg, ne03*nwg, 32, nsg, 1);
|
|
3033
|
+
|
|
3034
|
+
// sync the 2 kernels
|
|
3035
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
3036
|
+
|
|
3037
|
+
// reduce the results from the workgroups
|
|
3038
|
+
{
|
|
3039
|
+
const int32_t nrows = ne1*ne2*ne3;
|
|
3040
|
+
|
|
3041
|
+
ggml_metal_kargs_flash_attn_ext_vec_reduce args0 = {
|
|
3042
|
+
nrows,
|
|
3043
|
+
};
|
|
3044
|
+
|
|
3045
|
+
auto pipeline0 = ggml_metal_library_get_pipeline_flash_attn_ext_vec_reduce(lib, op, ne20, nwg);
|
|
3046
|
+
|
|
3047
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline0);
|
|
3048
|
+
ggml_metal_encoder_set_bytes (enc, &args0, sizeof(args0), 0);
|
|
3049
|
+
ggml_metal_encoder_set_buffer (enc, bid_tmp, 1);
|
|
3050
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
3051
|
+
|
|
3052
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, nrows, 1, 1, 32*nwg, 1, 1);
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
#undef FATTN_SMEM
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
return 1;
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3061
|
+
int ggml_metal_op_bin(ggml_metal_op_t ctx, int idx) {
|
|
3062
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3063
|
+
|
|
3064
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3065
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3066
|
+
|
|
3067
|
+
const bool use_fusion = ctx->use_fusion;
|
|
3068
|
+
|
|
3069
|
+
const int debug_fusion = ctx->debug_fusion;
|
|
3070
|
+
|
|
3071
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3072
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3073
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
3074
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
3075
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3076
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3077
|
+
|
|
3078
|
+
GGML_ASSERT(op->src[0]->type == GGML_TYPE_F32);
|
|
3079
|
+
GGML_ASSERT(op->src[1]->type == GGML_TYPE_F32);
|
|
3080
|
+
|
|
3081
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[0]));
|
|
3082
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[1]));
|
|
3083
|
+
|
|
3084
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
3085
|
+
ggml_metal_buffer_id bid_src1 = ggml_metal_get_buffer_id(op->src[1]);
|
|
3086
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
3087
|
+
|
|
3088
|
+
ggml_metal_kargs_bin args = {
|
|
3089
|
+
/*.ne00 =*/ ne00,
|
|
3090
|
+
/*.ne01 =*/ ne01,
|
|
3091
|
+
/*.ne02 =*/ ne02,
|
|
3092
|
+
/*.ne03 =*/ ne03,
|
|
3093
|
+
/*.nb00 =*/ nb00,
|
|
3094
|
+
/*.nb01 =*/ nb01,
|
|
3095
|
+
/*.nb02 =*/ nb02,
|
|
3096
|
+
/*.nb03 =*/ nb03,
|
|
3097
|
+
/*.ne10 =*/ ne10,
|
|
3098
|
+
/*.ne11 =*/ ne11,
|
|
3099
|
+
/*.ne12 =*/ ne12,
|
|
3100
|
+
/*.ne13 =*/ ne13,
|
|
3101
|
+
/*.nb10 =*/ nb10,
|
|
3102
|
+
/*.nb11 =*/ nb11,
|
|
3103
|
+
/*.nb12 =*/ nb12,
|
|
3104
|
+
/*.nb13 =*/ nb13,
|
|
3105
|
+
/*.ne0 =*/ ne0,
|
|
3106
|
+
/*.ne1 =*/ ne1,
|
|
3107
|
+
/*.ne2 =*/ ne2,
|
|
3108
|
+
/*.ne3 =*/ ne3,
|
|
3109
|
+
/*.nb0 =*/ nb0,
|
|
3110
|
+
/*.nb1 =*/ nb1,
|
|
3111
|
+
/*.nb2 =*/ nb2,
|
|
3112
|
+
/*.nb3 =*/ nb3,
|
|
3113
|
+
/*.offs =*/ 0,
|
|
3114
|
+
/*.o1 =*/ { bid_src1.offs },
|
|
3115
|
+
};
|
|
3116
|
+
|
|
3117
|
+
ggml_op fops[8];
|
|
3118
|
+
|
|
3119
|
+
int n_fuse = 1;
|
|
3120
|
+
|
|
3121
|
+
// c[0] = add(a, b[0])
|
|
3122
|
+
// c[1] = add(c[0], b[1])
|
|
3123
|
+
// c[2] = add(c[1], b[2])
|
|
3124
|
+
// ...
|
|
3125
|
+
if (use_fusion) {
|
|
3126
|
+
fops[0] = GGML_OP_ADD;
|
|
3127
|
+
fops[1] = GGML_OP_ADD;
|
|
3128
|
+
fops[2] = GGML_OP_ADD;
|
|
3129
|
+
fops[3] = GGML_OP_ADD;
|
|
3130
|
+
fops[4] = GGML_OP_ADD;
|
|
3131
|
+
fops[5] = GGML_OP_ADD;
|
|
3132
|
+
fops[6] = GGML_OP_ADD;
|
|
3133
|
+
fops[7] = GGML_OP_ADD;
|
|
3134
|
+
|
|
3135
|
+
// note: in metal, we sometimes encode the graph in parallel so we have to avoid fusing ops
|
|
3136
|
+
// across splits. idx_end indicates the last node in the current split
|
|
3137
|
+
for (n_fuse = 0; n_fuse <= 6; ++n_fuse) {
|
|
3138
|
+
if (!ctx->can_fuse(idx + n_fuse, fops + n_fuse, 2)) {
|
|
3139
|
+
break;
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
ggml_tensor * f0 = ctx->node(idx + n_fuse);
|
|
3143
|
+
ggml_tensor * f1 = ctx->node(idx + n_fuse + 1);
|
|
3144
|
+
|
|
3145
|
+
if (f0 != f1->src[0]) {
|
|
3146
|
+
break;
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
// b[0] === b[1] === ...
|
|
3150
|
+
if (!ggml_are_same_layout(f0->src[1], f1->src[1])) {
|
|
3151
|
+
break;
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
// only fuse ops if src1 is in the same Metal buffer
|
|
3155
|
+
ggml_metal_buffer_id bid_fuse = ggml_metal_get_buffer_id(f1->src[1]);
|
|
3156
|
+
if (bid_fuse.metal != bid_src1.metal) {
|
|
3157
|
+
break;
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3160
|
+
//ctx->fuse_cnt[ops[n_fuse + 1]->op]++;
|
|
3161
|
+
|
|
3162
|
+
args.o1[n_fuse + 1] = bid_fuse.offs;
|
|
3163
|
+
}
|
|
3164
|
+
|
|
3165
|
+
++n_fuse;
|
|
3166
|
+
|
|
3167
|
+
if (debug_fusion > 1 && n_fuse > 1) {
|
|
3168
|
+
GGML_LOG_DEBUG("%s: fuse: ADD x %d\n", __func__, n_fuse);
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
|
|
3172
|
+
// the offsets of src1 and all fused buffers are relative to the start of the src1 buffer
|
|
3173
|
+
bid_src1.offs = 0;
|
|
3174
|
+
|
|
3175
|
+
struct ggml_metal_pipeline_with_params pipeline;
|
|
3176
|
+
|
|
3177
|
+
pipeline = ggml_metal_library_get_pipeline_bin(lib, op, n_fuse);
|
|
3178
|
+
|
|
3179
|
+
if (n_fuse > 1) {
|
|
3180
|
+
bid_dst = ggml_metal_get_buffer_id(ctx->node(idx + n_fuse - 1));
|
|
3181
|
+
|
|
3182
|
+
for (int i = 1; i < n_fuse; ++i) {
|
|
3183
|
+
if (!ggml_metal_op_concurrency_check(ctx, ctx->node(idx + i))) {
|
|
3184
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
3185
|
+
|
|
3186
|
+
break;
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
|
|
3191
|
+
if (pipeline.c4) {
|
|
3192
|
+
args.ne00 = ne00/4;
|
|
3193
|
+
args.ne10 = ne10/4;
|
|
3194
|
+
args.ne0 = ne0/4;
|
|
3195
|
+
}
|
|
3196
|
+
|
|
3197
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3198
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3199
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
3200
|
+
ggml_metal_encoder_set_buffer (enc, bid_src1, 2);
|
|
3201
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 3);
|
|
3202
|
+
|
|
3203
|
+
if (pipeline.cnt) {
|
|
3204
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, args.ne0, ggml_nrows(op), 1, 1, 1, 1);
|
|
3205
|
+
} else {
|
|
3206
|
+
const int nth_max = MIN(256, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
3207
|
+
|
|
3208
|
+
int nth = 1;
|
|
3209
|
+
|
|
3210
|
+
while (2*nth < args.ne0 && nth < nth_max) {
|
|
3211
|
+
nth *= 2;
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, ne03, nth, 1, 1);
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3217
|
+
return n_fuse;
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
int ggml_metal_op_l2_norm(ggml_metal_op_t ctx, int idx) {
|
|
3221
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3222
|
+
|
|
3223
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3224
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3225
|
+
|
|
3226
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3227
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3228
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3229
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3230
|
+
|
|
3231
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[0]));
|
|
3232
|
+
|
|
3233
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
3234
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
3235
|
+
|
|
3236
|
+
float eps;
|
|
3237
|
+
memcpy(&eps, op->op_params, sizeof(float));
|
|
3238
|
+
|
|
3239
|
+
ggml_metal_kargs_l2_norm args = {
|
|
3240
|
+
/*.ne00 =*/ ne00,
|
|
3241
|
+
/*.ne01 =*/ ne01,
|
|
3242
|
+
/*.ne02 =*/ ne02,
|
|
3243
|
+
/*.ne03 =*/ ne03,
|
|
3244
|
+
/*.nb00 =*/ nb00,
|
|
3245
|
+
/*.nb01 =*/ nb01,
|
|
3246
|
+
/*.nb02 =*/ nb02,
|
|
3247
|
+
/*.nb03 =*/ nb03,
|
|
3248
|
+
/*.ne0 =*/ ne0,
|
|
3249
|
+
/*.ne1 =*/ ne1,
|
|
3250
|
+
/*.ne2 =*/ ne2,
|
|
3251
|
+
/*.ne3 =*/ ne3,
|
|
3252
|
+
/*.nb0 =*/ nb0,
|
|
3253
|
+
/*.nb1 =*/ nb1,
|
|
3254
|
+
/*.nb2 =*/ nb2,
|
|
3255
|
+
/*.nb3 =*/ nb3,
|
|
3256
|
+
/*.eps =*/ eps,
|
|
3257
|
+
};
|
|
3258
|
+
|
|
3259
|
+
auto pipeline = ggml_metal_library_get_pipeline_l2_norm(lib, op);
|
|
3260
|
+
|
|
3261
|
+
if (pipeline.c4) {
|
|
3262
|
+
args.ne00 = ne00/4;
|
|
3263
|
+
args.ne0 = ne0/4;
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
int nth = 32; // SIMD width
|
|
3267
|
+
|
|
3268
|
+
while (nth < ne00 && nth < ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
3269
|
+
nth *= 2;
|
|
3270
|
+
}
|
|
3271
|
+
|
|
3272
|
+
nth = std::min(nth, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
3273
|
+
|
|
3274
|
+
const size_t smem = pipeline.smem;
|
|
3275
|
+
|
|
3276
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3277
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3278
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
3279
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
3280
|
+
|
|
3281
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
3282
|
+
|
|
3283
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, ne03, nth, 1, 1);
|
|
3284
|
+
|
|
3285
|
+
return 1;
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
int ggml_metal_op_group_norm(ggml_metal_op_t ctx, int idx) {
|
|
3289
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3290
|
+
|
|
3291
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3292
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3293
|
+
|
|
3294
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3295
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3296
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3297
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3298
|
+
|
|
3299
|
+
const int32_t ngrp = ((const int32_t *) op->op_params)[0];
|
|
3300
|
+
|
|
3301
|
+
float eps;
|
|
3302
|
+
memcpy(&eps, op->op_params + 1, sizeof(float));
|
|
3303
|
+
|
|
3304
|
+
ggml_metal_kargs_group_norm args = {
|
|
3305
|
+
/*.ne00 =*/ ne00,
|
|
3306
|
+
/*.ne01 =*/ ne01,
|
|
3307
|
+
/*.ne02 =*/ ne02,
|
|
3308
|
+
/*.nb00 =*/ nb00,
|
|
3309
|
+
/*.nb01 =*/ nb01,
|
|
3310
|
+
/*.nb02 =*/ nb02,
|
|
3311
|
+
/*.ngrp =*/ ngrp,
|
|
3312
|
+
/*.eps =*/ eps,
|
|
3313
|
+
};
|
|
3314
|
+
|
|
3315
|
+
auto pipeline = ggml_metal_library_get_pipeline_group_norm(lib, op);
|
|
3316
|
+
|
|
3317
|
+
int nth = 32; // SIMD width
|
|
3318
|
+
//while (nth < ne00/4 && nth < ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
3319
|
+
// nth *= 2;
|
|
3320
|
+
//}
|
|
3321
|
+
|
|
3322
|
+
//nth = std::min(nth, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
3323
|
+
//nth = std::min(nth, ne00/4);
|
|
3324
|
+
|
|
3325
|
+
const size_t smem = pipeline.smem;
|
|
3326
|
+
|
|
3327
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3328
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3329
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
3330
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
3331
|
+
|
|
3332
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
3333
|
+
|
|
3334
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ngrp, 1, 1, nth, 1, 1);
|
|
3335
|
+
|
|
3336
|
+
return 1;
|
|
3337
|
+
}
|
|
3338
|
+
|
|
3339
|
+
int ggml_metal_op_norm(ggml_metal_op_t ctx, int idx) {
|
|
3340
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3341
|
+
|
|
3342
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3343
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3344
|
+
|
|
3345
|
+
const bool use_fusion = ctx->use_fusion;
|
|
3346
|
+
|
|
3347
|
+
const int debug_fusion = ctx->debug_fusion;
|
|
3348
|
+
|
|
3349
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3350
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3351
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3352
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3353
|
+
|
|
3354
|
+
float eps;
|
|
3355
|
+
memcpy(&eps, op->op_params, sizeof(float));
|
|
3356
|
+
|
|
3357
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
3358
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
3359
|
+
|
|
3360
|
+
ggml_metal_kargs_norm args = {
|
|
3361
|
+
/*.ne00 =*/ ne00,
|
|
3362
|
+
/*.ne00_t =*/ ne00 % 4 == 0 ? ne00/4 : ne00,
|
|
3363
|
+
/*.nb1 =*/ nb1,
|
|
3364
|
+
/*.nb2 =*/ nb2,
|
|
3365
|
+
/*.nb3 =*/ nb3,
|
|
3366
|
+
/*.eps =*/ eps,
|
|
3367
|
+
/*.nef1 =*/ { ne01 },
|
|
3368
|
+
/*.nef2 =*/ { ne02 },
|
|
3369
|
+
/*.nef3 =*/ { ne03 },
|
|
3370
|
+
/*.nbf1 =*/ { nb01 },
|
|
3371
|
+
/*.nbf2 =*/ { nb02 },
|
|
3372
|
+
/*.nbf3 =*/ { nb03 },
|
|
3373
|
+
};
|
|
3374
|
+
|
|
3375
|
+
ggml_op fops[8];
|
|
3376
|
+
|
|
3377
|
+
int n_fuse = 1;
|
|
3378
|
+
|
|
3379
|
+
ggml_metal_buffer_id bid_fuse[2] = { bid_src0, bid_src0 };
|
|
3380
|
+
|
|
3381
|
+
// d[0] = norm(a)
|
|
3382
|
+
// d[1] = mul(d[0], b)
|
|
3383
|
+
// d[2] = add(d[1], c)
|
|
3384
|
+
if (use_fusion) {
|
|
3385
|
+
fops[0] = op->op;
|
|
3386
|
+
fops[1] = GGML_OP_MUL;
|
|
3387
|
+
fops[2] = GGML_OP_ADD;
|
|
3388
|
+
|
|
3389
|
+
for (n_fuse = 0; n_fuse <= 1; ++n_fuse) {
|
|
3390
|
+
if (!ctx->can_fuse(idx + n_fuse, fops + n_fuse, 2)) {
|
|
3391
|
+
break;
|
|
3392
|
+
}
|
|
3393
|
+
|
|
3394
|
+
ggml_tensor * f0 = ctx->node(idx + n_fuse);
|
|
3395
|
+
ggml_tensor * f1 = ctx->node(idx + n_fuse + 1);
|
|
3396
|
+
|
|
3397
|
+
if (f0 != f1->src[0]) {
|
|
3398
|
+
break;
|
|
3399
|
+
}
|
|
3400
|
+
|
|
3401
|
+
if (f1->src[1]->ne[0] != op->ne[0]) {
|
|
3402
|
+
break;
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
if (!ggml_is_contiguous_rows(f1->src[1])) {
|
|
3406
|
+
break;
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3409
|
+
if (f1->type != GGML_TYPE_F32) {
|
|
3410
|
+
break;
|
|
3411
|
+
}
|
|
3412
|
+
|
|
3413
|
+
//ctx->fuse_cnt[f1->op]++;
|
|
3414
|
+
|
|
3415
|
+
bid_fuse[n_fuse] = ggml_metal_get_buffer_id(f1->src[1]);
|
|
3416
|
+
|
|
3417
|
+
args.nef1[n_fuse + 1] = f1->src[1]->ne[1];
|
|
3418
|
+
args.nef2[n_fuse + 1] = f1->src[1]->ne[2];
|
|
3419
|
+
args.nef3[n_fuse + 1] = f1->src[1]->ne[3];
|
|
3420
|
+
|
|
3421
|
+
args.nbf1[n_fuse + 1] = f1->src[1]->nb[1];
|
|
3422
|
+
args.nbf2[n_fuse + 1] = f1->src[1]->nb[2];
|
|
3423
|
+
args.nbf3[n_fuse + 1] = f1->src[1]->nb[3];
|
|
3424
|
+
}
|
|
3425
|
+
|
|
3426
|
+
++n_fuse;
|
|
3427
|
+
|
|
3428
|
+
if (debug_fusion > 1 && n_fuse > 1) {
|
|
3429
|
+
if (n_fuse == 2) {
|
|
3430
|
+
GGML_LOG_DEBUG("%s: fuse: %s + MUL\n", __func__, ggml_op_name(op->op));
|
|
3431
|
+
}
|
|
3432
|
+
if (n_fuse == 3) {
|
|
3433
|
+
GGML_LOG_DEBUG("%s: fuse: %s + MUL + ADD\n", __func__, ggml_op_name(op->op));
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3438
|
+
if (n_fuse > 1) {
|
|
3439
|
+
bid_dst = ggml_metal_get_buffer_id(ctx->node(idx + n_fuse - 1));
|
|
3440
|
+
|
|
3441
|
+
for (int i = 1; i < n_fuse; ++i) {
|
|
3442
|
+
if (!ggml_metal_op_concurrency_check(ctx, ctx->node(idx + i))) {
|
|
3443
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
3444
|
+
|
|
3445
|
+
break;
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
|
|
3450
|
+
auto pipeline = ggml_metal_library_get_pipeline_norm(lib, op, n_fuse);
|
|
3451
|
+
|
|
3452
|
+
int nth = 32; // SIMD width
|
|
3453
|
+
|
|
3454
|
+
while (nth < args.ne00_t && nth < ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
3455
|
+
nth *= 2;
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
nth = std::min(nth, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
3459
|
+
nth = std::min(nth, args.ne00_t);
|
|
3460
|
+
|
|
3461
|
+
const size_t smem = pipeline.smem;
|
|
3462
|
+
|
|
3463
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3464
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3465
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
3466
|
+
ggml_metal_encoder_set_buffer (enc, bid_fuse[0], 2);
|
|
3467
|
+
ggml_metal_encoder_set_buffer (enc, bid_fuse[1], 3);
|
|
3468
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 4);
|
|
3469
|
+
|
|
3470
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
3471
|
+
|
|
3472
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, ne03, nth, 1, 1);
|
|
3473
|
+
|
|
3474
|
+
return n_fuse;
|
|
3475
|
+
}
|
|
3476
|
+
|
|
3477
|
+
int ggml_metal_op_rope(ggml_metal_op_t ctx, int idx) {
|
|
3478
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3479
|
+
|
|
3480
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3481
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3482
|
+
|
|
3483
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3484
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3485
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
3486
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
3487
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3488
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3489
|
+
|
|
3490
|
+
// make sure we have one or more position id(ne10) per token(ne02)
|
|
3491
|
+
GGML_ASSERT(ne10 % ne02 == 0);
|
|
3492
|
+
GGML_ASSERT(ne10 >= ne02);
|
|
3493
|
+
|
|
3494
|
+
const int nth = std::min(1024, ne00);
|
|
3495
|
+
|
|
3496
|
+
const int n_past = ((const int32_t *) op->op_params)[0];
|
|
3497
|
+
const int n_dims = ((const int32_t *) op->op_params)[1];
|
|
3498
|
+
//const int mode = ((const int32_t *) op->op_params)[2];
|
|
3499
|
+
// skip 3, n_ctx, used in GLM RoPE, unimplemented in metal
|
|
3500
|
+
const int n_ctx_orig = ((const int32_t *) op->op_params)[4];
|
|
3501
|
+
|
|
3502
|
+
float freq_base;
|
|
3503
|
+
float freq_scale;
|
|
3504
|
+
float ext_factor;
|
|
3505
|
+
float attn_factor;
|
|
3506
|
+
float beta_fast;
|
|
3507
|
+
float beta_slow;
|
|
3508
|
+
|
|
3509
|
+
memcpy(&freq_base, (const int32_t *) op->op_params + 5, sizeof(float));
|
|
3510
|
+
memcpy(&freq_scale, (const int32_t *) op->op_params + 6, sizeof(float));
|
|
3511
|
+
memcpy(&ext_factor, (const int32_t *) op->op_params + 7, sizeof(float));
|
|
3512
|
+
memcpy(&attn_factor, (const int32_t *) op->op_params + 8, sizeof(float));
|
|
3513
|
+
memcpy(&beta_fast, (const int32_t *) op->op_params + 9, sizeof(float));
|
|
3514
|
+
memcpy(&beta_slow, (const int32_t *) op->op_params + 10, sizeof(float));
|
|
3515
|
+
|
|
3516
|
+
// mrope
|
|
3517
|
+
const int sect_0 = ((const int32_t *) op->op_params)[11];
|
|
3518
|
+
const int sect_1 = ((const int32_t *) op->op_params)[12];
|
|
3519
|
+
const int sect_2 = ((const int32_t *) op->op_params)[13];
|
|
3520
|
+
const int sect_3 = ((const int32_t *) op->op_params)[14];
|
|
3521
|
+
|
|
3522
|
+
ggml_metal_kargs_rope args = {
|
|
3523
|
+
/*.ne00 =*/ ne00,
|
|
3524
|
+
/*.ne01 =*/ ne01,
|
|
3525
|
+
/*.ne02 =*/ ne02,
|
|
3526
|
+
/*.ne03 =*/ ne03,
|
|
3527
|
+
/*.nb00 =*/ nb00,
|
|
3528
|
+
/*.nb01 =*/ nb01,
|
|
3529
|
+
/*.nb02 =*/ nb02,
|
|
3530
|
+
/*.nb03 =*/ nb03,
|
|
3531
|
+
/*.ne0 =*/ ne0,
|
|
3532
|
+
/*.ne1 =*/ ne1,
|
|
3533
|
+
/*.ne2 =*/ ne2,
|
|
3534
|
+
/*.ne3 =*/ ne3,
|
|
3535
|
+
/*.nb0 =*/ nb0,
|
|
3536
|
+
/*.nb1 =*/ nb1,
|
|
3537
|
+
/*.nb2 =*/ nb2,
|
|
3538
|
+
/*.nb3 =*/ nb3,
|
|
3539
|
+
/*.n_past =*/ n_past,
|
|
3540
|
+
/*.n_dims =*/ n_dims,
|
|
3541
|
+
/*.n_ctx_orig =*/ n_ctx_orig,
|
|
3542
|
+
/*.freq_base =*/ freq_base,
|
|
3543
|
+
/*.freq_scale =*/ freq_scale,
|
|
3544
|
+
/*.ext_factor =*/ ext_factor,
|
|
3545
|
+
/*.attn_factor =*/ attn_factor,
|
|
3546
|
+
/*.beta_fast =*/ beta_fast,
|
|
3547
|
+
/*.beta_slow =*/ beta_slow,
|
|
3548
|
+
/* sect_0 =*/ sect_0,
|
|
3549
|
+
/* sect_1 =*/ sect_1,
|
|
3550
|
+
/* sect_2 =*/ sect_2,
|
|
3551
|
+
/* sect_3 =*/ sect_3,
|
|
3552
|
+
/* src2 =*/ op->src[2] != nullptr,
|
|
3553
|
+
};
|
|
3554
|
+
|
|
3555
|
+
auto pipeline = ggml_metal_library_get_pipeline_rope(lib, op);
|
|
3556
|
+
|
|
3557
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3558
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3559
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
3560
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
3561
|
+
if (op->src[2]) {
|
|
3562
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[2]), 3);
|
|
3563
|
+
} else {
|
|
3564
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 3);
|
|
3565
|
+
}
|
|
3566
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 4);
|
|
3567
|
+
|
|
3568
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, ne03, nth, 1, 1);
|
|
3569
|
+
|
|
3570
|
+
return 1;
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3573
|
+
int ggml_metal_op_im2col(ggml_metal_op_t ctx, int idx) {
|
|
3574
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3575
|
+
|
|
3576
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3577
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3578
|
+
|
|
3579
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3580
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3581
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3582
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3583
|
+
|
|
3584
|
+
const int32_t s0 = ((const int32_t *)(op->op_params))[0];
|
|
3585
|
+
const int32_t s1 = ((const int32_t *)(op->op_params))[1];
|
|
3586
|
+
const int32_t p0 = ((const int32_t *)(op->op_params))[2];
|
|
3587
|
+
const int32_t p1 = ((const int32_t *)(op->op_params))[3];
|
|
3588
|
+
const int32_t d0 = ((const int32_t *)(op->op_params))[4];
|
|
3589
|
+
const int32_t d1 = ((const int32_t *)(op->op_params))[5];
|
|
3590
|
+
|
|
3591
|
+
const bool is_2D = ((const int32_t *)(op->op_params))[6] == 1;
|
|
3592
|
+
|
|
3593
|
+
const int32_t N = op->src[1]->ne[is_2D ? 3 : 2];
|
|
3594
|
+
const int32_t IC = op->src[1]->ne[is_2D ? 2 : 1];
|
|
3595
|
+
const int32_t IH = is_2D ? op->src[1]->ne[1] : 1;
|
|
3596
|
+
const int32_t IW = op->src[1]->ne[0];
|
|
3597
|
+
|
|
3598
|
+
const int32_t KH = is_2D ? op->src[0]->ne[1] : 1;
|
|
3599
|
+
const int32_t KW = op->src[0]->ne[0];
|
|
3600
|
+
|
|
3601
|
+
const int32_t OH = is_2D ? op->ne[2] : 1;
|
|
3602
|
+
const int32_t OW = op->ne[1];
|
|
3603
|
+
|
|
3604
|
+
const int32_t CHW = IC * KH * KW;
|
|
3605
|
+
|
|
3606
|
+
const uint64_t ofs0 = op->src[1]->nb[is_2D ? 3 : 2] / 4;
|
|
3607
|
+
const uint64_t ofs1 = op->src[1]->nb[is_2D ? 2 : 1] / 4;
|
|
3608
|
+
|
|
3609
|
+
ggml_metal_kargs_im2col args = {
|
|
3610
|
+
/*.ofs0 =*/ ofs0,
|
|
3611
|
+
/*.ofs1 =*/ ofs1,
|
|
3612
|
+
/*.IW =*/ IW,
|
|
3613
|
+
/*.IH =*/ IH,
|
|
3614
|
+
/*.CHW =*/ CHW,
|
|
3615
|
+
/*.s0 =*/ s0,
|
|
3616
|
+
/*.s1 =*/ s1,
|
|
3617
|
+
/*.p0 =*/ p0,
|
|
3618
|
+
/*.p1 =*/ p1,
|
|
3619
|
+
/*.d0 =*/ d0,
|
|
3620
|
+
/*.d1 =*/ d1,
|
|
3621
|
+
/*.N =*/ N,
|
|
3622
|
+
/*.KH =*/ KH,
|
|
3623
|
+
/*.KW =*/ KW,
|
|
3624
|
+
/*.KHW =*/ KH * KW,
|
|
3625
|
+
};
|
|
3626
|
+
|
|
3627
|
+
auto pipeline = ggml_metal_library_get_pipeline_im2col(lib, op);
|
|
3628
|
+
|
|
3629
|
+
GGML_ASSERT(KH*KW <= ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
3630
|
+
|
|
3631
|
+
const uint64_t ntptg0 = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)/(KH*KW), N);
|
|
3632
|
+
|
|
3633
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3634
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3635
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 1);
|
|
3636
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
3637
|
+
|
|
3638
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, IC, OH, OW, ntptg0, KH, KW);
|
|
3639
|
+
|
|
3640
|
+
return 1;
|
|
3641
|
+
}
|
|
3642
|
+
|
|
3643
|
+
int ggml_metal_op_conv_2d(ggml_metal_op_t ctx, int idx) {
|
|
3644
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3645
|
+
|
|
3646
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3647
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3648
|
+
|
|
3649
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3650
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3651
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
3652
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
3653
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3654
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3655
|
+
|
|
3656
|
+
GGML_ASSERT(ggml_is_contiguous(op->src[0]));
|
|
3657
|
+
GGML_ASSERT(op->src[1]->type == GGML_TYPE_F32);
|
|
3658
|
+
GGML_ASSERT(op->type == GGML_TYPE_F32);
|
|
3659
|
+
GGML_ASSERT(op->src[0]->type == GGML_TYPE_F16 || op->src[0]->type == GGML_TYPE_F32);
|
|
3660
|
+
|
|
3661
|
+
const int32_t s0 = ((const int32_t *) op->op_params)[0];
|
|
3662
|
+
const int32_t s1 = ((const int32_t *) op->op_params)[1];
|
|
3663
|
+
const int32_t p0 = ((const int32_t *) op->op_params)[2];
|
|
3664
|
+
const int32_t p1 = ((const int32_t *) op->op_params)[3];
|
|
3665
|
+
const int32_t d0 = ((const int32_t *) op->op_params)[4];
|
|
3666
|
+
const int32_t d1 = ((const int32_t *) op->op_params)[5];
|
|
3667
|
+
|
|
3668
|
+
ggml_metal_kargs_conv_2d args = {
|
|
3669
|
+
/*.nb00 =*/ nb00,
|
|
3670
|
+
/*.nb01 =*/ nb01,
|
|
3671
|
+
/*.nb02 =*/ nb02,
|
|
3672
|
+
/*.nb03 =*/ nb03,
|
|
3673
|
+
/*.nb10 =*/ nb10,
|
|
3674
|
+
/*.nb11 =*/ nb11,
|
|
3675
|
+
/*.nb12 =*/ nb12,
|
|
3676
|
+
/*.nb13 =*/ nb13,
|
|
3677
|
+
/*.nb0 =*/ nb0,
|
|
3678
|
+
/*.nb1 =*/ nb1,
|
|
3679
|
+
/*.nb2 =*/ nb2,
|
|
3680
|
+
/*.nb3 =*/ nb3,
|
|
3681
|
+
/*.IW =*/ ne10,
|
|
3682
|
+
/*.IH =*/ ne11,
|
|
3683
|
+
/*.KW =*/ ne00,
|
|
3684
|
+
/*.KH =*/ ne01,
|
|
3685
|
+
/*.IC =*/ ne02,
|
|
3686
|
+
/*.OC =*/ ne03,
|
|
3687
|
+
/*.OW =*/ ne0,
|
|
3688
|
+
/*.OH =*/ ne1,
|
|
3689
|
+
/*.N =*/ ne3,
|
|
3690
|
+
/*.s0 =*/ s0,
|
|
3691
|
+
/*.s1 =*/ s1,
|
|
3692
|
+
/*.p0 =*/ p0,
|
|
3693
|
+
/*.p1 =*/ p1,
|
|
3694
|
+
/*.d0 =*/ d0,
|
|
3695
|
+
/*.d1 =*/ d1,
|
|
3696
|
+
};
|
|
3697
|
+
|
|
3698
|
+
auto pipeline = ggml_metal_library_get_pipeline_conv_2d(lib, op);
|
|
3699
|
+
|
|
3700
|
+
int nth = ggml_metal_pipeline_max_theads_per_threadgroup(pipeline);
|
|
3701
|
+
nth = std::min(nth, 256);
|
|
3702
|
+
nth = std::max(nth, 1);
|
|
3703
|
+
|
|
3704
|
+
const uint64_t n_out = ggml_nelements(op);
|
|
3705
|
+
|
|
3706
|
+
uint64_t tg = (n_out + nth - 1)/nth;
|
|
3707
|
+
tg = std::max<uint64_t>(tg, 1);
|
|
3708
|
+
tg = std::min<uint64_t>(tg, (uint64_t) std::numeric_limits<int>::max());
|
|
3709
|
+
|
|
3710
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3711
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3712
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
3713
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
3714
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
3715
|
+
|
|
3716
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, tg, 1, 1, nth, 1, 1);
|
|
3717
|
+
|
|
3718
|
+
return 1;
|
|
3719
|
+
}
|
|
3720
|
+
|
|
3721
|
+
int ggml_metal_op_conv_3d(ggml_metal_op_t ctx, int idx) {
|
|
3722
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3723
|
+
|
|
3724
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3725
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3726
|
+
|
|
3727
|
+
// 1. Extract standard dimensions and byte strides
|
|
3728
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3729
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
3730
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3731
|
+
|
|
3732
|
+
// 2. Extract hyperparams from op_params
|
|
3733
|
+
const int32_t s0 = ((const int32_t *)(op->op_params))[0];
|
|
3734
|
+
const int32_t s1 = ((const int32_t *)(op->op_params))[1];
|
|
3735
|
+
const int32_t s2 = ((const int32_t *)(op->op_params))[2];
|
|
3736
|
+
const int32_t p0 = ((const int32_t *)(op->op_params))[3];
|
|
3737
|
+
const int32_t p1 = ((const int32_t *)(op->op_params))[4];
|
|
3738
|
+
const int32_t p2 = ((const int32_t *)(op->op_params))[5];
|
|
3739
|
+
const int32_t d0 = ((const int32_t *)(op->op_params))[6];
|
|
3740
|
+
const int32_t d1 = ((const int32_t *)(op->op_params))[7];
|
|
3741
|
+
const int32_t d2 = ((const int32_t *)(op->op_params))[8];
|
|
3742
|
+
const int32_t IC = ((const int32_t *)(op->op_params))[9];
|
|
3743
|
+
const int32_t N = ((const int32_t *)(op->op_params))[10];
|
|
3744
|
+
const int32_t OC = ((const int32_t *)(op->op_params))[11];
|
|
3745
|
+
|
|
3746
|
+
// 3. Build the parameter struct using the macro-generated variables
|
|
3747
|
+
ggml_metal_kargs_conv_3d args = {
|
|
3748
|
+
/*.IW =*/ (int32_t)op->src[1]->ne[0],
|
|
3749
|
+
/*.IH =*/ (int32_t)op->src[1]->ne[1],
|
|
3750
|
+
/*.ID =*/ (int32_t)op->src[1]->ne[2],
|
|
3751
|
+
/*.OW =*/ (int32_t)op->ne[0],
|
|
3752
|
+
/*.OH =*/ (int32_t)op->ne[1],
|
|
3753
|
+
/*.OD =*/ (int32_t)op->ne[2],
|
|
3754
|
+
/*.KW =*/ (int32_t)op->src[0]->ne[0],
|
|
3755
|
+
/*.KH =*/ (int32_t)op->src[0]->ne[1],
|
|
3756
|
+
/*.KD =*/ (int32_t)op->src[0]->ne[2],
|
|
3757
|
+
s0, s1, s2,
|
|
3758
|
+
p0, p1, p2,
|
|
3759
|
+
d0, d1, d2,
|
|
3760
|
+
IC, N, OC,
|
|
3761
|
+
nb00, nb01, nb02, nb03, // Weight strides
|
|
3762
|
+
nb10, nb11, nb12, nb13, // Input strides
|
|
3763
|
+
nb0, nb1, nb2, nb3 // Output strides
|
|
3764
|
+
};
|
|
3765
|
+
|
|
3766
|
+
// 4. Fetch the JIT pipeline
|
|
3767
|
+
auto pipeline = ggml_metal_library_get_pipeline_conv_3d(lib, op);
|
|
3768
|
+
|
|
3769
|
+
// 5. Grid mapping
|
|
3770
|
+
int nth0 = 32; // Standard SIMD width for Apple Silicon
|
|
3771
|
+
int nth1 = 1;
|
|
3772
|
+
int nth2 = 1;
|
|
3773
|
+
|
|
3774
|
+
int64_t spatial_volume = args.OW * args.OH * args.OD;
|
|
3775
|
+
|
|
3776
|
+
int ntg0 = (spatial_volume + nth0 - 1) / nth0;
|
|
3777
|
+
int ntg1 = args.OC;
|
|
3778
|
+
int ntg2 = args.N;
|
|
3779
|
+
|
|
3780
|
+
// 6. Bind and Dispatch via the ggml C wrapper
|
|
3781
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3782
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3783
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
3784
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
3785
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
3786
|
+
|
|
3787
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ntg0, ntg1, ntg2, nth0, nth1, nth2);
|
|
3788
|
+
|
|
3789
|
+
return 1;
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3792
|
+
int ggml_metal_op_conv_transpose_1d(ggml_metal_op_t ctx, int idx) {
|
|
3793
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3794
|
+
|
|
3795
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3796
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3797
|
+
|
|
3798
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3799
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3800
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
3801
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
3802
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3803
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3804
|
+
|
|
3805
|
+
const int32_t s0 = ((const int32_t *)(op->op_params))[0];
|
|
3806
|
+
|
|
3807
|
+
const int32_t IC = op->src[1]->ne[1];
|
|
3808
|
+
const int32_t IL = op->src[1]->ne[0];
|
|
3809
|
+
|
|
3810
|
+
const int32_t K = op->src[0]->ne[0];
|
|
3811
|
+
|
|
3812
|
+
const int32_t OL = op->ne[0];
|
|
3813
|
+
const int32_t OC = op->ne[1];
|
|
3814
|
+
|
|
3815
|
+
ggml_metal_kargs_conv_transpose_1d args = {
|
|
3816
|
+
/*.IC =*/ IC,
|
|
3817
|
+
/*.IL =*/ IL,
|
|
3818
|
+
/*.K =*/ K,
|
|
3819
|
+
/*.s0 =*/ s0,
|
|
3820
|
+
/*.nb0 =*/ nb0,
|
|
3821
|
+
/*.nb1 =*/ nb1,
|
|
3822
|
+
};
|
|
3823
|
+
|
|
3824
|
+
auto pipeline = ggml_metal_library_get_pipeline_conv_transpose_1d(lib, op);
|
|
3825
|
+
|
|
3826
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3827
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3828
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
3829
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
3830
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
3831
|
+
|
|
3832
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, OL, OC, 1, 1, 1, 1);
|
|
3833
|
+
|
|
3834
|
+
return 1;
|
|
3835
|
+
}
|
|
3836
|
+
|
|
3837
|
+
int ggml_metal_op_conv_transpose_2d(ggml_metal_op_t ctx, int idx) {
|
|
3838
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3839
|
+
|
|
3840
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3841
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3842
|
+
|
|
3843
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3844
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3845
|
+
GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);
|
|
3846
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
3847
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3848
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3849
|
+
|
|
3850
|
+
const int32_t s0 = ((const int32_t *)(op->op_params))[0];
|
|
3851
|
+
|
|
3852
|
+
const int32_t IC = op->src[1]->ne[2];
|
|
3853
|
+
const int32_t IH = op->src[1]->ne[1];
|
|
3854
|
+
const int32_t IW = op->src[1]->ne[0];
|
|
3855
|
+
|
|
3856
|
+
const int32_t KH = op->src[0]->ne[1];
|
|
3857
|
+
const int32_t KW = op->src[0]->ne[0];
|
|
3858
|
+
|
|
3859
|
+
const int32_t OW = op->ne[0];
|
|
3860
|
+
const int32_t OH = op->ne[1];
|
|
3861
|
+
const int32_t OC = op->ne[2];
|
|
3862
|
+
|
|
3863
|
+
ggml_metal_kargs_conv_transpose_2d args = {
|
|
3864
|
+
/*.IC =*/ IC,
|
|
3865
|
+
/*.IH =*/ IH,
|
|
3866
|
+
/*.IW =*/ IW,
|
|
3867
|
+
/*.KH =*/ KH,
|
|
3868
|
+
/*.KW =*/ KW,
|
|
3869
|
+
/*.OC =*/ OC,
|
|
3870
|
+
/*.s0 =*/ s0,
|
|
3871
|
+
/*.nb0 =*/ nb0,
|
|
3872
|
+
/*.nb1 =*/ nb1,
|
|
3873
|
+
/*.nb2 =*/ nb2,
|
|
3874
|
+
};
|
|
3875
|
+
|
|
3876
|
+
auto pipeline = ggml_metal_library_get_pipeline_conv_transpose_2d(lib, op);
|
|
3877
|
+
|
|
3878
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3879
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3880
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
3881
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
3882
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
|
|
3883
|
+
|
|
3884
|
+
// Metal requires buffer size to be multiple of 16 bytes
|
|
3885
|
+
const size_t smem = GGML_PAD(KW * KH * sizeof(float), 16);
|
|
3886
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
3887
|
+
|
|
3888
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, OW, OH, OC, KW, KH, 1);
|
|
3889
|
+
|
|
3890
|
+
return 1;
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3893
|
+
int ggml_metal_op_upscale(ggml_metal_op_t ctx, int idx) {
|
|
3894
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3895
|
+
|
|
3896
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3897
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3898
|
+
|
|
3899
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3900
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3901
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3902
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3903
|
+
|
|
3904
|
+
float sf0 = (float)ne0/op->src[0]->ne[0];
|
|
3905
|
+
float sf1 = (float)ne1/op->src[0]->ne[1];
|
|
3906
|
+
float sf2 = (float)ne2/op->src[0]->ne[2];
|
|
3907
|
+
float sf3 = (float)ne3/op->src[0]->ne[3];
|
|
3908
|
+
|
|
3909
|
+
const int32_t mode_flags = ggml_get_op_params_i32(op, 0);
|
|
3910
|
+
|
|
3911
|
+
float poffs = 0.5f;
|
|
3912
|
+
|
|
3913
|
+
if (mode_flags & GGML_SCALE_FLAG_ALIGN_CORNERS) {
|
|
3914
|
+
poffs = 0.0f;
|
|
3915
|
+
sf0 = ne0 > 1 && ne00 > 1 ? (float)(ne0 - 1) / (ne00 - 1) : sf0;
|
|
3916
|
+
sf1 = ne1 > 1 && ne01 > 1 ? (float)(ne1 - 1) / (ne01 - 1) : sf1;
|
|
3917
|
+
}
|
|
3918
|
+
|
|
3919
|
+
ggml_metal_kargs_upscale args = {
|
|
3920
|
+
/*.ne00 =*/ ne00,
|
|
3921
|
+
/*.ne01 =*/ ne01,
|
|
3922
|
+
/*.ne02 =*/ ne02,
|
|
3923
|
+
/*.ne03 =*/ ne03,
|
|
3924
|
+
/*.nb00 =*/ nb00,
|
|
3925
|
+
/*.nb01 =*/ nb01,
|
|
3926
|
+
/*.nb02 =*/ nb02,
|
|
3927
|
+
/*.nb03 =*/ nb03,
|
|
3928
|
+
/*.ne0 =*/ ne0,
|
|
3929
|
+
/*.ne1 =*/ ne1,
|
|
3930
|
+
/*.ne2 =*/ ne2,
|
|
3931
|
+
/*.ne3 =*/ ne3,
|
|
3932
|
+
/*.nb0 =*/ nb0,
|
|
3933
|
+
/*.nb1 =*/ nb1,
|
|
3934
|
+
/*.nb2 =*/ nb2,
|
|
3935
|
+
/*.nb3 =*/ nb3,
|
|
3936
|
+
/*.sf0 =*/ sf0,
|
|
3937
|
+
/*.sf1 =*/ sf1,
|
|
3938
|
+
/*.sf2 =*/ sf2,
|
|
3939
|
+
/*.sf3 =*/ sf3,
|
|
3940
|
+
/*.poffs =*/ poffs,
|
|
3941
|
+
};
|
|
3942
|
+
|
|
3943
|
+
auto pipeline = ggml_metal_library_get_pipeline_upscale(lib, op);
|
|
3944
|
+
|
|
3945
|
+
const int nth = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline), ne0);
|
|
3946
|
+
|
|
3947
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
3948
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
3949
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
3950
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
3951
|
+
|
|
3952
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne1, ne2, ne3, nth, 1, 1);
|
|
3953
|
+
|
|
3954
|
+
return 1;
|
|
3955
|
+
}
|
|
3956
|
+
|
|
3957
|
+
int ggml_metal_op_roll(ggml_metal_op_t ctx, int idx) {
|
|
3958
|
+
ggml_tensor * op = ctx->node(idx);
|
|
3959
|
+
|
|
3960
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
3961
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
3962
|
+
|
|
3963
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
3964
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
3965
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
3966
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
3967
|
+
|
|
3968
|
+
const int32_t s0 = ggml_get_op_params_i32(op, 0);
|
|
3969
|
+
const int32_t s1 = ggml_get_op_params_i32(op, 1);
|
|
3970
|
+
const int32_t s2 = ggml_get_op_params_i32(op, 2);
|
|
3971
|
+
const int32_t s3 = ggml_get_op_params_i32(op, 3);
|
|
3972
|
+
|
|
3973
|
+
ggml_metal_kargs_roll args = {
|
|
3974
|
+
/*.ne00 =*/ ne00,
|
|
3975
|
+
/*.ne01 =*/ ne01,
|
|
3976
|
+
/*.ne02 =*/ ne02,
|
|
3977
|
+
/*.ne03 =*/ ne03,
|
|
3978
|
+
/*.nb00 =*/ nb00,
|
|
3979
|
+
/*.nb01 =*/ nb01,
|
|
3980
|
+
/*.nb02 =*/ nb02,
|
|
3981
|
+
/*.nb03 =*/ nb03,
|
|
3982
|
+
/*.ne0 =*/ ne0,
|
|
3983
|
+
/*.ne1 =*/ ne1,
|
|
3984
|
+
/*.ne2 =*/ ne2,
|
|
3985
|
+
/*.ne3 =*/ ne3,
|
|
3986
|
+
/*.nb0 =*/ nb0,
|
|
3987
|
+
/*.nb1 =*/ nb1,
|
|
3988
|
+
/*.nb2 =*/ nb2,
|
|
3989
|
+
/*.nb3 =*/ nb3,
|
|
3990
|
+
/*.s0 =*/ s0,
|
|
3991
|
+
/*.s1 =*/ s1,
|
|
3992
|
+
/*.s2 =*/ s2,
|
|
3993
|
+
/*.s3 =*/ s3
|
|
3994
|
+
};
|
|
3995
|
+
|
|
3996
|
+
auto pipeline = ggml_metal_library_get_pipeline_roll(lib, op);
|
|
3997
|
+
|
|
3998
|
+
const int nth = std::min(1024, ne0);
|
|
3999
|
+
|
|
4000
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4001
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
4002
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
4003
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
4004
|
+
|
|
4005
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne1, ne2, ne3, nth, 1, 1);
|
|
4006
|
+
|
|
4007
|
+
return 1;
|
|
4008
|
+
}
|
|
4009
|
+
|
|
4010
|
+
int ggml_metal_op_pad(ggml_metal_op_t ctx, int idx) {
|
|
4011
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4012
|
+
|
|
4013
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4014
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4015
|
+
|
|
4016
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
4017
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
4018
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
4019
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
4020
|
+
|
|
4021
|
+
ggml_metal_kargs_pad args = {
|
|
4022
|
+
/*.ne00 =*/ ne00,
|
|
4023
|
+
/*.ne01 =*/ ne01,
|
|
4024
|
+
/*.ne02 =*/ ne02,
|
|
4025
|
+
/*.ne03 =*/ ne03,
|
|
4026
|
+
/*.nb00 =*/ nb00,
|
|
4027
|
+
/*.nb01 =*/ nb01,
|
|
4028
|
+
/*.nb02 =*/ nb02,
|
|
4029
|
+
/*.nb03 =*/ nb03,
|
|
4030
|
+
/*.ne0 =*/ ne0,
|
|
4031
|
+
/*.ne1 =*/ ne1,
|
|
4032
|
+
/*.ne2 =*/ ne2,
|
|
4033
|
+
/*.ne3 =*/ ne3,
|
|
4034
|
+
/*.nb0 =*/ nb0,
|
|
4035
|
+
/*.nb1 =*/ nb1,
|
|
4036
|
+
/*.nb2 =*/ nb2,
|
|
4037
|
+
/*.nb3 =*/ nb3
|
|
4038
|
+
};
|
|
4039
|
+
|
|
4040
|
+
auto pipeline = ggml_metal_library_get_pipeline_pad(lib, op);
|
|
4041
|
+
|
|
4042
|
+
const int nth = std::min(1024, ne0);
|
|
4043
|
+
|
|
4044
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4045
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
4046
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
4047
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
4048
|
+
|
|
4049
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne1, ne2, ne3, nth, 1, 1);
|
|
4050
|
+
|
|
4051
|
+
return 1;
|
|
4052
|
+
}
|
|
4053
|
+
|
|
4054
|
+
int ggml_metal_op_pad_reflect_1d(ggml_metal_op_t ctx, int idx) {
|
|
4055
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4056
|
+
|
|
4057
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4058
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4059
|
+
|
|
4060
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
4061
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
4062
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
4063
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
4064
|
+
|
|
4065
|
+
ggml_metal_kargs_pad_reflect_1d args = {
|
|
4066
|
+
/*.ne00 =*/ ne00,
|
|
4067
|
+
/*.ne01 =*/ ne01,
|
|
4068
|
+
/*.ne02 =*/ ne02,
|
|
4069
|
+
/*.ne03 =*/ ne03,
|
|
4070
|
+
/*.nb00 =*/ nb00,
|
|
4071
|
+
/*.nb01 =*/ nb01,
|
|
4072
|
+
/*.nb02 =*/ nb02,
|
|
4073
|
+
/*.nb03 =*/ nb03,
|
|
4074
|
+
/*.ne0 =*/ ne0,
|
|
4075
|
+
/*.ne1 =*/ ne1,
|
|
4076
|
+
/*.ne2 =*/ ne2,
|
|
4077
|
+
/*.ne3 =*/ ne3,
|
|
4078
|
+
/*.nb0 =*/ nb0,
|
|
4079
|
+
/*.nb1 =*/ nb1,
|
|
4080
|
+
/*.nb2 =*/ nb2,
|
|
4081
|
+
/*.nb3 =*/ nb3,
|
|
4082
|
+
/*.p0 =*/ ((const int32_t *)(op->op_params))[0],
|
|
4083
|
+
/*.p1 =*/ ((const int32_t *)(op->op_params))[1]
|
|
4084
|
+
};
|
|
4085
|
+
|
|
4086
|
+
auto pipeline = ggml_metal_library_get_pipeline_pad_reflect_1d(lib, op);
|
|
4087
|
+
|
|
4088
|
+
const int nth = std::min(1024, ne0);
|
|
4089
|
+
|
|
4090
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4091
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
4092
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
4093
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
4094
|
+
|
|
4095
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne1, ne2, ne3, nth, 1, 1);
|
|
4096
|
+
|
|
4097
|
+
return 1;
|
|
4098
|
+
}
|
|
4099
|
+
|
|
4100
|
+
int ggml_metal_op_arange(ggml_metal_op_t ctx, int idx) {
|
|
4101
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4102
|
+
|
|
4103
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4104
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4105
|
+
|
|
4106
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
4107
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
4108
|
+
|
|
4109
|
+
float start;
|
|
4110
|
+
float step;
|
|
4111
|
+
|
|
4112
|
+
memcpy(&start, ((const int32_t *) op->op_params) + 0, sizeof(float));
|
|
4113
|
+
memcpy(&step, ((const int32_t *) op->op_params) + 2, sizeof(float));
|
|
4114
|
+
|
|
4115
|
+
ggml_metal_kargs_arange args = {
|
|
4116
|
+
/*.ne0 =*/ ne0,
|
|
4117
|
+
/*.start =*/ start,
|
|
4118
|
+
/*.step =*/ step
|
|
4119
|
+
};
|
|
4120
|
+
|
|
4121
|
+
const int nth = std::min(1024, ne0);
|
|
4122
|
+
|
|
4123
|
+
auto pipeline = ggml_metal_library_get_pipeline_arange(lib, op);
|
|
4124
|
+
|
|
4125
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4126
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
4127
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 1);
|
|
4128
|
+
|
|
4129
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, 1, 1, 1, nth, 1, 1);
|
|
4130
|
+
|
|
4131
|
+
return 1;
|
|
4132
|
+
}
|
|
4133
|
+
|
|
4134
|
+
int ggml_metal_op_timestep_embedding(ggml_metal_op_t ctx, int idx) {
|
|
4135
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4136
|
+
|
|
4137
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4138
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4139
|
+
|
|
4140
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
4141
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
4142
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
4143
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
4144
|
+
|
|
4145
|
+
const int dim = op->op_params[0];
|
|
4146
|
+
const int max_period = op->op_params[1];
|
|
4147
|
+
|
|
4148
|
+
ggml_metal_kargs_timestep_embedding args = {
|
|
4149
|
+
/*.nb1 =*/ nb1,
|
|
4150
|
+
/*.dim =*/ dim,
|
|
4151
|
+
/*.max_period =*/ max_period,
|
|
4152
|
+
};
|
|
4153
|
+
|
|
4154
|
+
auto pipeline = ggml_metal_library_get_pipeline_timestep_embedding(lib, op);
|
|
4155
|
+
|
|
4156
|
+
const int nth = std::max(1, std::min(1024, dim/2));
|
|
4157
|
+
|
|
4158
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4159
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
4160
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
4161
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
4162
|
+
|
|
4163
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne00, 1, 1, nth, 1, 1);
|
|
4164
|
+
|
|
4165
|
+
return 1;
|
|
4166
|
+
}
|
|
4167
|
+
|
|
4168
|
+
int ggml_metal_op_argmax(ggml_metal_op_t ctx, int idx) {
|
|
4169
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4170
|
+
|
|
4171
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4172
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4173
|
+
|
|
4174
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
4175
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
4176
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
4177
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
4178
|
+
|
|
4179
|
+
ggml_metal_kargs_argmax args = {
|
|
4180
|
+
/*.ne00 = */ ne00,
|
|
4181
|
+
/*.nb01 = */ nb01,
|
|
4182
|
+
};
|
|
4183
|
+
|
|
4184
|
+
auto pipeline = ggml_metal_library_get_pipeline_argmax(lib, op);
|
|
4185
|
+
|
|
4186
|
+
const int64_t nrows = ggml_nrows(op->src[0]);
|
|
4187
|
+
|
|
4188
|
+
int nth = 32; // SIMD width
|
|
4189
|
+
while (nth < ne00 && nth*ne01*ne02*ne03 < 256) {
|
|
4190
|
+
nth *= 2;
|
|
4191
|
+
}
|
|
4192
|
+
|
|
4193
|
+
const size_t smem = pipeline.smem;
|
|
4194
|
+
|
|
4195
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4196
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
4197
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
4198
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
4199
|
+
|
|
4200
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
4201
|
+
|
|
4202
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, nrows, 1, 1, nth, 1, 1);
|
|
4203
|
+
|
|
4204
|
+
return 1;
|
|
4205
|
+
}
|
|
4206
|
+
|
|
4207
|
+
int ggml_metal_op_argsort(ggml_metal_op_t ctx, int idx) {
|
|
4208
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4209
|
+
|
|
4210
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4211
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4212
|
+
|
|
4213
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[0]));
|
|
4214
|
+
|
|
4215
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
4216
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
4217
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
4218
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
4219
|
+
|
|
4220
|
+
auto pipeline = ggml_metal_library_get_pipeline_argsort(lib, op);
|
|
4221
|
+
|
|
4222
|
+
// bitonic sort requires the number of elements to be power of 2
|
|
4223
|
+
int nth = 1;
|
|
4224
|
+
while (nth < ne00 && 2*nth <= ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
4225
|
+
nth *= 2;
|
|
4226
|
+
}
|
|
4227
|
+
|
|
4228
|
+
const int npr = (ne00 + nth - 1)/nth;
|
|
4229
|
+
|
|
4230
|
+
// Metal kernels require the buffer size to be multiple of 16 bytes
|
|
4231
|
+
// https://developer.apple.com/documentation/metal/mtlcomputecommandencoder/1443142-setthreadgroupmemorylength
|
|
4232
|
+
const size_t smem = GGML_PAD(nth*sizeof(int32_t), 16);
|
|
4233
|
+
|
|
4234
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
4235
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
4236
|
+
|
|
4237
|
+
ggml_metal_buffer_id bid_tmp = bid_dst;
|
|
4238
|
+
bid_tmp.offs += ggml_nbytes(op);
|
|
4239
|
+
|
|
4240
|
+
if ((int) ceil(std::log(npr) / std::log(2)) % 2 == 1) {
|
|
4241
|
+
std::swap(bid_dst, bid_tmp);
|
|
4242
|
+
}
|
|
4243
|
+
|
|
4244
|
+
ggml_metal_kargs_argsort args = {
|
|
4245
|
+
/*.ne00 =*/ ne00,
|
|
4246
|
+
/*.ne01 =*/ ne01,
|
|
4247
|
+
/*.ne02 =*/ ne02,
|
|
4248
|
+
/*.ne03 =*/ ne03,
|
|
4249
|
+
/*.nb00 =*/ nb00,
|
|
4250
|
+
/*.nb01 =*/ nb01,
|
|
4251
|
+
/*.nb02 =*/ nb02,
|
|
4252
|
+
/*.nb03 =*/ nb03,
|
|
4253
|
+
/*.ne0 =*/ ne0,
|
|
4254
|
+
/*.ne1 =*/ ne1,
|
|
4255
|
+
/*.ne2 =*/ ne2,
|
|
4256
|
+
/*.ne3 =*/ ne3,
|
|
4257
|
+
/*.top_k =*/ nth,
|
|
4258
|
+
};
|
|
4259
|
+
|
|
4260
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4261
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
4262
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
4263
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
4264
|
+
|
|
4265
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
4266
|
+
|
|
4267
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, npr*ne01, ne02, ne03, nth, 1, 1);
|
|
4268
|
+
|
|
4269
|
+
auto pipeline_merge = ggml_metal_library_get_pipeline_argsort_merge(lib, op);
|
|
4270
|
+
|
|
4271
|
+
int len = nth;
|
|
4272
|
+
|
|
4273
|
+
while (len < ne00) {
|
|
4274
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
4275
|
+
|
|
4276
|
+
ggml_metal_kargs_argsort_merge args_merge = {
|
|
4277
|
+
/*.ne00 =*/ ne00,
|
|
4278
|
+
/*.ne01 =*/ ne01,
|
|
4279
|
+
/*.ne02 =*/ ne02,
|
|
4280
|
+
/*.ne03 =*/ ne03,
|
|
4281
|
+
/*.nb00 =*/ nb00,
|
|
4282
|
+
/*.nb01 =*/ nb01,
|
|
4283
|
+
/*.nb02 =*/ nb02,
|
|
4284
|
+
/*.nb03 =*/ nb03,
|
|
4285
|
+
/*.ne0 =*/ ne0,
|
|
4286
|
+
/*.ne1 =*/ ne1,
|
|
4287
|
+
/*.ne2 =*/ ne2,
|
|
4288
|
+
/*.ne3 =*/ ne3,
|
|
4289
|
+
/*.top_k =*/ ne00,
|
|
4290
|
+
/*.len =*/ len,
|
|
4291
|
+
};
|
|
4292
|
+
|
|
4293
|
+
// merges per row
|
|
4294
|
+
const int nm = (ne00 + 2*len - 1) / (2*len);
|
|
4295
|
+
|
|
4296
|
+
const int nth = std::min(512, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline_merge));
|
|
4297
|
+
|
|
4298
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline_merge);
|
|
4299
|
+
ggml_metal_encoder_set_bytes (enc, &args_merge, sizeof(args_merge), 0);
|
|
4300
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
4301
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
4302
|
+
ggml_metal_encoder_set_buffer (enc, bid_tmp, 3);
|
|
4303
|
+
|
|
4304
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, nm*ne01, ne02, ne03, nth, 1, 1);
|
|
4305
|
+
|
|
4306
|
+
std::swap(bid_dst, bid_tmp);
|
|
4307
|
+
|
|
4308
|
+
len <<= 1;
|
|
4309
|
+
}
|
|
4310
|
+
|
|
4311
|
+
return 1;
|
|
4312
|
+
}
|
|
4313
|
+
|
|
4314
|
+
int ggml_metal_op_top_k(ggml_metal_op_t ctx, int idx) {
|
|
4315
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4316
|
+
|
|
4317
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4318
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4319
|
+
|
|
4320
|
+
GGML_ASSERT(ggml_is_contiguous_rows(op->src[0]));
|
|
4321
|
+
|
|
4322
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
4323
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
4324
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
4325
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
4326
|
+
|
|
4327
|
+
auto pipeline = ggml_metal_library_get_pipeline_top_k(lib, op);
|
|
4328
|
+
|
|
4329
|
+
// bitonic sort requires the number of elements to be power of 2
|
|
4330
|
+
int nth = 1;
|
|
4331
|
+
while (nth < ne00 && 2*nth <= ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
4332
|
+
nth *= 2;
|
|
4333
|
+
}
|
|
4334
|
+
|
|
4335
|
+
// blocks per row
|
|
4336
|
+
const int npr = (ne00 + nth - 1)/nth;
|
|
4337
|
+
|
|
4338
|
+
const size_t smem = GGML_PAD(nth*sizeof(int32_t), 16);
|
|
4339
|
+
|
|
4340
|
+
ggml_metal_buffer_id bid_src0 = ggml_metal_get_buffer_id(op->src[0]);
|
|
4341
|
+
ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(op);
|
|
4342
|
+
|
|
4343
|
+
ggml_metal_buffer_id bid_tmp = bid_dst;
|
|
4344
|
+
bid_tmp.offs += sizeof(int32_t)*ggml_nelements(op->src[0]);
|
|
4345
|
+
|
|
4346
|
+
if ((int) ceil(std::log(npr) / std::log(2)) % 2 == 1) {
|
|
4347
|
+
std::swap(bid_dst, bid_tmp);
|
|
4348
|
+
}
|
|
4349
|
+
|
|
4350
|
+
const int top_k = ne0;
|
|
4351
|
+
|
|
4352
|
+
ggml_metal_kargs_argsort args = {
|
|
4353
|
+
/*.ne00 =*/ ne00,
|
|
4354
|
+
/*.ne01 =*/ ne01,
|
|
4355
|
+
/*.ne02 =*/ ne02,
|
|
4356
|
+
/*.ne03 =*/ ne03,
|
|
4357
|
+
/*.nb00 =*/ nb00,
|
|
4358
|
+
/*.nb01 =*/ nb01,
|
|
4359
|
+
/*.nb02 =*/ nb02,
|
|
4360
|
+
/*.nb03 =*/ nb03,
|
|
4361
|
+
/*.ne0 =*/ ne0,
|
|
4362
|
+
/*.ne1 =*/ ne1,
|
|
4363
|
+
/*.ne2 =*/ ne2,
|
|
4364
|
+
/*.ne3 =*/ ne3,
|
|
4365
|
+
/*.top_k =*/ std::min(nth, top_k), // for each block, keep just the top_k indices
|
|
4366
|
+
};
|
|
4367
|
+
|
|
4368
|
+
if (npr > 1) {
|
|
4369
|
+
args.ne0 = (npr - 1)*args.top_k + std::min(ne00 - (npr - 1)*nth, args.top_k);
|
|
4370
|
+
}
|
|
4371
|
+
|
|
4372
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4373
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
4374
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
4375
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
4376
|
+
|
|
4377
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
4378
|
+
|
|
4379
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, npr*ne01, ne02, ne03, nth, 1, 1);
|
|
4380
|
+
|
|
4381
|
+
auto pipeline_merge = ggml_metal_library_get_pipeline_top_k_merge(lib, op);
|
|
4382
|
+
|
|
4383
|
+
int len = args.top_k;
|
|
4384
|
+
|
|
4385
|
+
while (len < args.ne0) {
|
|
4386
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
4387
|
+
|
|
4388
|
+
// merges per row
|
|
4389
|
+
const int nm = (args.ne0 + 2*len - 1) / (2*len);
|
|
4390
|
+
|
|
4391
|
+
const int nth = std::min(512, std::min(len, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline_merge)));
|
|
4392
|
+
|
|
4393
|
+
ggml_metal_kargs_argsort_merge args_merge = {
|
|
4394
|
+
/*.ne00 =*/ ne00,
|
|
4395
|
+
/*.ne01 =*/ ne01,
|
|
4396
|
+
/*.ne02 =*/ ne02,
|
|
4397
|
+
/*.ne03 =*/ ne03,
|
|
4398
|
+
/*.nb00 =*/ nb00,
|
|
4399
|
+
/*.nb01 =*/ nb01,
|
|
4400
|
+
/*.nb02 =*/ nb02,
|
|
4401
|
+
/*.nb03 =*/ nb03,
|
|
4402
|
+
/*.ne0 =*/ args.ne0,
|
|
4403
|
+
/*.ne1 =*/ ne1,
|
|
4404
|
+
/*.ne2 =*/ ne2,
|
|
4405
|
+
/*.ne3 =*/ ne3,
|
|
4406
|
+
/*.top_k =*/ nm == 1 ? top_k : args.ne0, // the final merge outputs top_k elements
|
|
4407
|
+
/*.len =*/ len,
|
|
4408
|
+
};
|
|
4409
|
+
|
|
4410
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline_merge);
|
|
4411
|
+
ggml_metal_encoder_set_bytes (enc, &args_merge, sizeof(args_merge), 0);
|
|
4412
|
+
ggml_metal_encoder_set_buffer (enc, bid_src0, 1);
|
|
4413
|
+
ggml_metal_encoder_set_buffer (enc, bid_dst, 2);
|
|
4414
|
+
ggml_metal_encoder_set_buffer (enc, bid_tmp, 3);
|
|
4415
|
+
|
|
4416
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, nm*ne01, ne02, ne03, nth, 1, 1);
|
|
4417
|
+
|
|
4418
|
+
std::swap(bid_dst, bid_tmp);
|
|
4419
|
+
|
|
4420
|
+
len <<= 1;
|
|
4421
|
+
}
|
|
4422
|
+
|
|
4423
|
+
return 1;
|
|
4424
|
+
}
|
|
4425
|
+
|
|
4426
|
+
int ggml_metal_op_tri(ggml_metal_op_t ctx, int idx) {
|
|
4427
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4428
|
+
|
|
4429
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4430
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4431
|
+
|
|
4432
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
4433
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
4434
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
4435
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
4436
|
+
|
|
4437
|
+
ggml_metal_kargs_tri args = {
|
|
4438
|
+
/*.ne00 =*/ ne00,
|
|
4439
|
+
/*.ne01 =*/ ne01,
|
|
4440
|
+
/*.ne02 =*/ ne02,
|
|
4441
|
+
/*.ne03 =*/ ne03,
|
|
4442
|
+
/*.nb00 =*/ nb00,
|
|
4443
|
+
/*.nb01 =*/ nb01,
|
|
4444
|
+
/*.nb02 =*/ nb02,
|
|
4445
|
+
/*.nb03 =*/ nb03,
|
|
4446
|
+
/*.ne0 =*/ ne0,
|
|
4447
|
+
/*.ne1 =*/ ne1,
|
|
4448
|
+
/*.ne2 =*/ ne2,
|
|
4449
|
+
/*.ne3 =*/ ne3,
|
|
4450
|
+
/*.nb0 =*/ nb0,
|
|
4451
|
+
/*.nb1 =*/ nb1,
|
|
4452
|
+
/*.nb2 =*/ nb2,
|
|
4453
|
+
/*.nb3 =*/ nb3,
|
|
4454
|
+
};
|
|
4455
|
+
|
|
4456
|
+
auto pipeline = ggml_metal_library_get_pipeline_tri(lib, op);
|
|
4457
|
+
|
|
4458
|
+
int nth = 32; // SIMD width
|
|
4459
|
+
|
|
4460
|
+
while (nth < ne00 && nth < ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
|
|
4461
|
+
nth *= 2;
|
|
4462
|
+
}
|
|
4463
|
+
|
|
4464
|
+
nth = std::min(nth, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
4465
|
+
nth = std::min(nth, ne00);
|
|
4466
|
+
|
|
4467
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4468
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);
|
|
4469
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
4470
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 2);
|
|
4471
|
+
|
|
4472
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, ne03, nth, 1, 1);
|
|
4473
|
+
|
|
4474
|
+
return 1;
|
|
4475
|
+
}
|
|
4476
|
+
|
|
4477
|
+
int ggml_metal_op_opt_step_adamw(ggml_metal_op_t ctx, int idx) {
|
|
4478
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4479
|
+
|
|
4480
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4481
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4482
|
+
|
|
4483
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
4484
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
4485
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
4486
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
4487
|
+
|
|
4488
|
+
auto pipeline = ggml_metal_library_get_pipeline_opt_step_adamw(lib, op);
|
|
4489
|
+
|
|
4490
|
+
const int64_t np = ggml_nelements(op->src[0]);
|
|
4491
|
+
ggml_metal_kargs_opt_step_adamw args = {
|
|
4492
|
+
/*.np =*/ np,
|
|
4493
|
+
};
|
|
4494
|
+
|
|
4495
|
+
int ida = 0;
|
|
4496
|
+
|
|
4497
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4498
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), ida++);
|
|
4499
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), ida++);
|
|
4500
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), ida++);
|
|
4501
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[2]), ida++);
|
|
4502
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[3]), ida++);
|
|
4503
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[4]), ida++);
|
|
4504
|
+
|
|
4505
|
+
const int nth = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline), ne0);
|
|
4506
|
+
const int64_t n = (np + nth - 1) / nth;
|
|
4507
|
+
|
|
4508
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, n, 1, 1, nth, 1, 1);
|
|
4509
|
+
|
|
4510
|
+
return 1;
|
|
4511
|
+
}
|
|
4512
|
+
|
|
4513
|
+
int ggml_metal_op_opt_step_sgd(ggml_metal_op_t ctx, int idx) {
|
|
4514
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4515
|
+
|
|
4516
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4517
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4518
|
+
|
|
4519
|
+
GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne);
|
|
4520
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
4521
|
+
GGML_TENSOR_LOCALS( int32_t, ne, op, ne);
|
|
4522
|
+
GGML_TENSOR_LOCALS(uint64_t, nb, op, nb);
|
|
4523
|
+
|
|
4524
|
+
auto pipeline = ggml_metal_library_get_pipeline_opt_step_sgd(lib, op);
|
|
4525
|
+
|
|
4526
|
+
const int64_t np = ggml_nelements(op->src[0]);
|
|
4527
|
+
ggml_metal_kargs_opt_step_sgd args = {
|
|
4528
|
+
/*.np =*/ np,
|
|
4529
|
+
};
|
|
4530
|
+
|
|
4531
|
+
int ida = 0;
|
|
4532
|
+
|
|
4533
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4534
|
+
ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), ida++);
|
|
4535
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[0]), ida++);
|
|
4536
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), ida++);
|
|
4537
|
+
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[2]), ida++);
|
|
4538
|
+
|
|
4539
|
+
const int nth = std::min(ggml_metal_pipeline_max_theads_per_threadgroup(pipeline), ne0);
|
|
4540
|
+
const int64_t n = (np + nth - 1) / nth;
|
|
4541
|
+
|
|
4542
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, n, 1, 1, nth, 1, 1);
|
|
4543
|
+
|
|
4544
|
+
return 1;
|
|
4545
|
+
}
|
|
4546
|
+
|
|
4547
|
+
int ggml_metal_op_count_equal(ggml_metal_op_t ctx, int idx) {
|
|
4548
|
+
ggml_tensor * op = ctx->node(idx);
|
|
4549
|
+
|
|
4550
|
+
ggml_metal_library_t lib = ctx->lib;
|
|
4551
|
+
ggml_metal_encoder_t enc = ctx->enc;
|
|
4552
|
+
|
|
4553
|
+
GGML_TENSOR_LOCALS(int32_t, ne0, op->src[0], ne);
|
|
4554
|
+
GGML_TENSOR_LOCALS(uint64_t, nb0, op->src[0], nb);
|
|
4555
|
+
GGML_TENSOR_LOCALS(uint64_t, nb1, op->src[1], nb);
|
|
4556
|
+
|
|
4557
|
+
{
|
|
4558
|
+
ggml_metal_kargs_memset args = { /*.val =*/ 0 };
|
|
4559
|
+
|
|
4560
|
+
auto pipeline = ggml_metal_library_get_pipeline_memset(lib, op);
|
|
4561
|
+
|
|
4562
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4563
|
+
ggml_metal_encoder_set_bytes(enc, &args, sizeof(args), 0);
|
|
4564
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op), 1);
|
|
4565
|
+
|
|
4566
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, 1, 1, 1, 1, 1, 1);
|
|
4567
|
+
}
|
|
4568
|
+
|
|
4569
|
+
ggml_metal_op_concurrency_reset(ctx);
|
|
4570
|
+
|
|
4571
|
+
{
|
|
4572
|
+
ggml_metal_kargs_count_equal args = {
|
|
4573
|
+
/*.ne00 =*/ ne00,
|
|
4574
|
+
/*.ne01 =*/ ne01,
|
|
4575
|
+
/*.ne02 =*/ ne02,
|
|
4576
|
+
/*.ne03 =*/ ne03,
|
|
4577
|
+
/*.nb00 =*/ nb00,
|
|
4578
|
+
/*.nb01 =*/ nb01,
|
|
4579
|
+
/*.nb02 =*/ nb02,
|
|
4580
|
+
/*.nb03 =*/ nb03,
|
|
4581
|
+
/*.nb10 =*/ nb10,
|
|
4582
|
+
/*.nb11 =*/ nb11,
|
|
4583
|
+
/*.nb12 =*/ nb12,
|
|
4584
|
+
/*.nb13 =*/ nb13,
|
|
4585
|
+
};
|
|
4586
|
+
|
|
4587
|
+
auto pipeline = ggml_metal_library_get_pipeline_count_equal(lib, op);
|
|
4588
|
+
|
|
4589
|
+
const size_t smem = pipeline.smem;
|
|
4590
|
+
|
|
4591
|
+
const int nth = 32*pipeline.nsg;
|
|
4592
|
+
|
|
4593
|
+
GGML_ASSERT(nth <= ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
|
|
4594
|
+
|
|
4595
|
+
ggml_metal_encoder_set_pipeline(enc, pipeline);
|
|
4596
|
+
ggml_metal_encoder_set_bytes(enc, &args, sizeof(args), 0);
|
|
4597
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[0]), 1);
|
|
4598
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op->src[1]), 2);
|
|
4599
|
+
ggml_metal_encoder_set_buffer(enc, ggml_metal_get_buffer_id(op), 3);
|
|
4600
|
+
|
|
4601
|
+
ggml_metal_encoder_set_threadgroup_memory_size(enc, smem, 0);
|
|
4602
|
+
ggml_metal_encoder_dispatch_threadgroups(enc, ne01, ne02, ne03, nth, 1, 1);
|
|
4603
|
+
}
|
|
4604
|
+
|
|
4605
|
+
return 1;
|
|
4606
|
+
}
|