cohere-transcribe 0.1.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 +21 -0
- data/LICENSE.txt +201 -0
- data/NOTICE +5 -0
- data/README.md +265 -0
- data/THIRD_PARTY_NOTICES.md +67 -0
- data/exe/cohere-transcribe +8 -0
- data/exe/cohere-transcribe-doctor +8 -0
- data/ext/cohere_transcribe_native/CMakeLists.txt +262 -0
- data/ext/cohere_transcribe_native/README.md +26 -0
- data/ext/cohere_transcribe_native/audio_abi.cpp +1416 -0
- data/ext/cohere_transcribe_native/audio_exports.macos +5 -0
- data/ext/cohere_transcribe_native/audio_exports.map +10 -0
- data/ext/cohere_transcribe_native/cohere_abi.cpp +1209 -0
- data/ext/cohere_transcribe_native/exports.macos +40 -0
- data/ext/cohere_transcribe_native/exports.map +45 -0
- data/ext/cohere_transcribe_native/extconf.rb +89 -0
- data/ext/cohere_transcribe_native/test/abi_smoke.rb +232 -0
- data/ext/cohere_transcribe_native/test/audio_matrix_smoke.cpp +121 -0
- data/ext/cohere_transcribe_native/test/audio_reliability_smoke.cpp +198 -0
- data/ext/cohere_transcribe_native/test/native_abi_reliability_smoke.cpp +186 -0
- data/ext/cohere_transcribe_native/test/native_batch_projection_probe.rb +81 -0
- data/ext/cohere_transcribe_native/test/native_cancellation_smoke.cpp +194 -0
- data/lib/cohere/transcribe/alignment/ATTRIBUTION.md +23 -0
- data/lib/cohere/transcribe/alignment/LICENSE.ctc-forced-aligner +407 -0
- data/lib/cohere/transcribe/alignment/LICENSE.torchaudio +25 -0
- data/lib/cohere/transcribe/alignment/LICENSE.uroman +26 -0
- data/lib/cohere/transcribe/alignment/aligner.rb +476 -0
- data/lib/cohere/transcribe/alignment/ctc.rb +224 -0
- data/lib/cohere/transcribe/alignment/text.rb +237 -0
- data/lib/cohere/transcribe/alignment/uroman_data.rb +4950 -0
- data/lib/cohere/transcribe/api.rb +173 -0
- data/lib/cohere/transcribe/asr/batching.rb +472 -0
- data/lib/cohere/transcribe/asr/failure_policy.rb +112 -0
- data/lib/cohere/transcribe/asr/native.rb +676 -0
- data/lib/cohere/transcribe/audio/ATTRIBUTION.md +8 -0
- data/lib/cohere/transcribe/audio/LICENSE.auditok +21 -0
- data/lib/cohere/transcribe/audio/decoder.rb +315 -0
- data/lib/cohere/transcribe/audio/ffmpeg_native.rb +248 -0
- data/lib/cohere/transcribe/audio/segmentation.rb +260 -0
- data/lib/cohere/transcribe/cli.rb +727 -0
- data/lib/cohere/transcribe/configuration.rb +282 -0
- data/lib/cohere/transcribe/constants.rb +14 -0
- data/lib/cohere/transcribe/dense_converter.rb +548 -0
- data/lib/cohere/transcribe/doctor.rb +576 -0
- data/lib/cohere/transcribe/errors.rb +57 -0
- data/lib/cohere/transcribe/gguf_writer.rb +268 -0
- data/lib/cohere/transcribe/hub.rb +436 -0
- data/lib/cohere/transcribe/input.rb +110 -0
- data/lib/cohere/transcribe/licenses/crispasr.txt +21 -0
- data/lib/cohere/transcribe/loader.rb +128 -0
- data/lib/cohere/transcribe/model_identity.rb +440 -0
- data/lib/cohere/transcribe/output/publication.rb +1118 -0
- data/lib/cohere/transcribe/output/rendering.rb +105 -0
- data/lib/cohere/transcribe/output/timing.rb +86 -0
- data/lib/cohere/transcribe/python_text.rb +70 -0
- data/lib/cohere/transcribe/pytorch_checkpoint.rb +1180 -0
- data/lib/cohere/transcribe/runtime/engine.rb +1676 -0
- data/lib/cohere/transcribe/runtime/model_provider.rb +390 -0
- data/lib/cohere/transcribe/runtime/precision.rb +57 -0
- data/lib/cohere/transcribe/runtime/preparation.rb +215 -0
- data/lib/cohere/transcribe/runtime/resources.rb +165 -0
- data/lib/cohere/transcribe/runtime/word_pipeline.rb +364 -0
- data/lib/cohere/transcribe/safetensors.rb +579 -0
- data/lib/cohere/transcribe/state/checkpoint.rb +224 -0
- data/lib/cohere/transcribe/state/contracts.rb +141 -0
- data/lib/cohere/transcribe/state/io.rb +727 -0
- data/lib/cohere/transcribe/state/locking.rb +211 -0
- data/lib/cohere/transcribe/state/manifest.rb +155 -0
- data/lib/cohere/transcribe/state.rb +7 -0
- data/lib/cohere/transcribe/types.rb +535 -0
- data/lib/cohere/transcribe/vad/ATTRIBUTION.md +14 -0
- data/lib/cohere/transcribe/vad/LICENSE.faster-whisper +21 -0
- data/lib/cohere/transcribe/vad/LICENSE.silero-vad +21 -0
- data/lib/cohere/transcribe/vad/silero.rb +344 -0
- data/lib/cohere/transcribe/vad/silero_vad_v6.onnx +0 -0
- data/lib/cohere/transcribe/vad/timestamps.rb +219 -0
- data/lib/cohere/transcribe/version.rb +7 -0
- data/lib/cohere/transcribe.rb +26 -0
- data/sig/cohere/transcribe.rbs +250 -0
- data/vendor/crispasr/AUTHORS +510 -0
- data/vendor/crispasr/LICENSE +21 -0
- data/vendor/crispasr/UPSTREAM.md +9 -0
- data/vendor/crispasr/VERSION +1 -0
- data/vendor/crispasr/ggml/AUTHORS +335 -0
- data/vendor/crispasr/ggml/CMakeLists.txt +512 -0
- data/vendor/crispasr/ggml/LICENSE +21 -0
- data/vendor/crispasr/ggml/README.md +49 -0
- data/vendor/crispasr/ggml/cmake/FindNCCL.cmake +36 -0
- data/vendor/crispasr/ggml/cmake/GitVars.cmake +22 -0
- data/vendor/crispasr/ggml/cmake/common.cmake +50 -0
- data/vendor/crispasr/ggml/cmake/ggml-config.cmake.in +191 -0
- data/vendor/crispasr/ggml/ggml.pc.in +10 -0
- data/vendor/crispasr/ggml/include/ggml-alloc.h +85 -0
- data/vendor/crispasr/ggml/include/ggml-backend.h +431 -0
- data/vendor/crispasr/ggml/include/ggml-blas.h +25 -0
- data/vendor/crispasr/ggml/include/ggml-cann.h +123 -0
- data/vendor/crispasr/ggml/include/ggml-cpp.h +39 -0
- data/vendor/crispasr/ggml/include/ggml-cpu.h +151 -0
- data/vendor/crispasr/ggml/include/ggml-cuda.h +50 -0
- data/vendor/crispasr/ggml/include/ggml-hexagon.h +19 -0
- data/vendor/crispasr/ggml/include/ggml-metal.h +61 -0
- data/vendor/crispasr/ggml/include/ggml-opencl.h +26 -0
- data/vendor/crispasr/ggml/include/ggml-openvino.h +37 -0
- data/vendor/crispasr/ggml/include/ggml-opt.h +256 -0
- data/vendor/crispasr/ggml/include/ggml-rpc.h +35 -0
- data/vendor/crispasr/ggml/include/ggml-sycl.h +49 -0
- data/vendor/crispasr/ggml/include/ggml-virtgpu.h +14 -0
- data/vendor/crispasr/ggml/include/ggml-vulkan.h +29 -0
- data/vendor/crispasr/ggml/include/ggml-webgpu.h +19 -0
- data/vendor/crispasr/ggml/include/ggml-zdnn.h +17 -0
- data/vendor/crispasr/ggml/include/ggml-zendnn.h +22 -0
- data/vendor/crispasr/ggml/include/ggml.h +2887 -0
- data/vendor/crispasr/ggml/include/gguf.h +204 -0
- data/vendor/crispasr/ggml/src/CMakeLists.txt +493 -0
- data/vendor/crispasr/ggml/src/ggml-alloc.c +1323 -0
- data/vendor/crispasr/ggml/src/ggml-backend-dl.cpp +48 -0
- data/vendor/crispasr/ggml/src/ggml-backend-dl.h +44 -0
- data/vendor/crispasr/ggml/src/ggml-backend-impl.h +275 -0
- data/vendor/crispasr/ggml/src/ggml-backend-meta.cpp +2145 -0
- data/vendor/crispasr/ggml/src/ggml-backend-reg.cpp +586 -0
- data/vendor/crispasr/ggml/src/ggml-backend.cpp +2437 -0
- data/vendor/crispasr/ggml/src/ggml-common.h +1900 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/CMakeLists.txt +718 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.cpp +249 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.h +8 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/common.h +115 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.cpp +2512 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.h +10 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp +98 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/quants.c +4244 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/repack.cpp +5156 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/loongarch/quants.c +2158 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp +82 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/quants.c +2304 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/cpu-feats.cpp +38 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/quants.c +4455 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/repack.cpp +1703 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp +50 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/quants.c +1465 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/wasm/quants.c +1220 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/quants.c +3970 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/repack.cpp +6407 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch-fallback.h +349 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.cpp +154 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.h +16 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/common.h +95 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu-impl.h +539 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.c +3791 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.cpp +703 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/hbm.cpp +55 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/hbm.h +8 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.cpp +939 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.h +90 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +1513 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.cpp +4051 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.h +25 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ops.cpp +11662 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ops.h +121 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/quants.c +1288 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/quants.h +103 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/repack.cpp +4836 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/repack.h +245 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/simd-gemm.h +226 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/simd-mappings.h +1329 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.cpp +1025 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.h +13 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime1_kernels.cpp +3196 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime_kernels.h +26 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/traits.cpp +36 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/traits.h +38 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.cpp +336 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.h +35 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/vec.cpp +681 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/vec.h +1606 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/CMakeLists.txt +272 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/acc.cu +61 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/acc.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cu +58 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/arange.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/arange.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cu +91 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cu +265 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cuh +19 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cu +534 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cuh +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cu +45 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cu +81 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/common.cuh +1489 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/concat.cu +204 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/concat.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cu +97 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cu +161 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cu +115 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cu +166 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/convert.cu +892 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/convert.cuh +66 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cu +64 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cp-async.cuh +57 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy-utils.cuh +217 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cu +581 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cu +177 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cu +307 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/dequantize.cuh +99 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diag.cu +77 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diag.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cu +40 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-common.cuh +1212 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-mma-f16.cuh +1860 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cu +57 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cuh +1309 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-vec.cuh +600 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cu +696 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +51 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cu +620 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fill.cu +37 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fill.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cu +273 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cuh +4 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cu +332 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cuh +15 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ggml-cuda.cu +5580 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gla.cu +93 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gla.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cu +274 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cuh +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mean.cu +75 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mean.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mma.cuh +1333 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cu +191 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cuh +908 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cu +164 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cu +372 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cuh +4175 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cu +862 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cuh +14 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cu +1161 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cuh +16 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/norm.cu +756 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/norm.cuh +20 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cu +49 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cu +68 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad.cu +106 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cu +91 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cu +94 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cu +443 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cuh +41 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/reduce_rows.cuh +39 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/roll.cu +67 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/roll.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/rope.cu +665 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/rope.cuh +9 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/scale.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/scale.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cu +330 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set.cu +39 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cu +472 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cu +275 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cu +197 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cu +342 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sum.cu +41 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sum.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cu +43 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cuh +4 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_32.cu +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_32.cu +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq112-dv112.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq128-dv128.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq256-dv256.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq320-dv256.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq40-dv40.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq512-dv512.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq576-dv512.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq64-dv64.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq72-dv72.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq80-dv80.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq96-dv96.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_10.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_11.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_12.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_13.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_14.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_15.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_2.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_3.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_5.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_6.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_7.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_8.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_9.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-mxfp4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-nvfp4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q1_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cu +95 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cu +415 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cuh +27 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tri.cu +136 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tri.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cu +47 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/unary.cu +644 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/unary.cuh +116 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cu +293 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vecdotq.cuh +1317 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/cuda.h +28 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/hip.h +306 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/musa.h +148 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cu +199 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-impl.h +783 -0
- data/vendor/crispasr/ggml/src/ggml-metal/CMakeLists.txt +124 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.cpp +457 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.h +52 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.h +41 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.m +778 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.cpp +2117 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.h +299 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.m +2093 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-impl.h +1267 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.cpp +5023 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.h +111 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.cpp +954 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.metal +11756 -0
- data/vendor/crispasr/ggml/src/ggml-opt.cpp +1094 -0
- data/vendor/crispasr/ggml/src/ggml-quants.c +5491 -0
- data/vendor/crispasr/ggml/src/ggml-quants.h +112 -0
- data/vendor/crispasr/ggml/src/ggml-threading.cpp +12 -0
- data/vendor/crispasr/ggml/src/ggml-threading.h +14 -0
- data/vendor/crispasr/ggml/src/ggml.c +7925 -0
- data/vendor/crispasr/ggml/src/ggml.cpp +26 -0
- data/vendor/crispasr/ggml/src/gguf.cpp +1556 -0
- data/vendor/crispasr/src/cohere-arch.h +137 -0
- data/vendor/crispasr/src/cohere.cpp +5642 -0
- data/vendor/crispasr/src/cohere.h +327 -0
- data/vendor/crispasr/src/cohere_batch_planner.h +82 -0
- data/vendor/crispasr/src/cohere_chunking.h +64 -0
- data/vendor/crispasr/src/cohere_decoder_batch_layout.h +60 -0
- data/vendor/crispasr/src/cohere_encoder_padded_layout.h +27 -0
- data/vendor/crispasr/src/cohere_frontend.cpp +189 -0
- data/vendor/crispasr/src/cohere_frontend.h +31 -0
- data/vendor/crispasr/src/cohere_ragged_controller.h +149 -0
- data/vendor/crispasr/src/cohere_token_renderer.h +181 -0
- data/vendor/crispasr/src/core/attention.h +924 -0
- data/vendor/crispasr/src/core/audio_chunking.h +97 -0
- data/vendor/crispasr/src/core/beam_decode.h +486 -0
- data/vendor/crispasr/src/core/cpu_ops.h +135 -0
- data/vendor/crispasr/src/core/gguf_loader.cpp +1021 -0
- data/vendor/crispasr/src/core/gguf_loader.h +216 -0
- data/vendor/crispasr/src/core/gpu_backend_pref.h +119 -0
- data/vendor/crispasr/src/core/mel.cpp +519 -0
- data/vendor/crispasr/src/core/mel.h +265 -0
- data/vendor/crispasr/src/core/ngram_loop_fix.h +173 -0
- data/vendor/crispasr/src/core/repetition_loop_guard.h +54 -0
- data/vendor/crispasr/src/crispasr_imatrix.cpp +255 -0
- data/vendor/crispasr/src/crispasr_imatrix.h +38 -0
- metadata +596 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "common.cuh"
|
|
4
|
+
|
|
5
|
+
#if defined(GGML_USE_MUSA)
|
|
6
|
+
#define GGML_USE_WMMA_FATTN
|
|
7
|
+
#endif // defined(GGML_USE_MUSA)
|
|
8
|
+
|
|
9
|
+
#if defined(GGML_HIP_ROCWMMA_FATTN)
|
|
10
|
+
#if defined(CDNA) && (ROCWMMA_VERSION_MAJOR < 2 || ROCWMMA_VERSION_MINOR > 0 || ROCWMMA_VERSION_PATCH > 0)
|
|
11
|
+
#define GGML_USE_WMMA_FATTN
|
|
12
|
+
#elif defined(CDNA)
|
|
13
|
+
#warning "rocwmma fattn on CDNA is broken on rocwmma v2.0.0, expect degraded performance"
|
|
14
|
+
#endif // defined(CDNA) && (ROCWMMA_VERSION_MAJOR < 2 || ROCWMMA_VERSION_MINOR > 0 || ROCWMMA_VERSION_PATCH > 0)
|
|
15
|
+
#if defined(RDNA3)
|
|
16
|
+
#define GGML_USE_WMMA_FATTN
|
|
17
|
+
#endif // defined(RDNA3)
|
|
18
|
+
#if defined(RDNA4) && ROCWMMA_VERSION_MAJOR > 1
|
|
19
|
+
#define GGML_USE_WMMA_FATTN
|
|
20
|
+
#elif defined(RDNA4)
|
|
21
|
+
#warning "rocwmma fattn is not supported on RDNA4 on rocwmma < v2.0.0, expect degraded performance"
|
|
22
|
+
#endif // defined(RDNA4) && ROCWMMA_VERSION_MAJOR > 1
|
|
23
|
+
#endif // defined(GGML_HIP_ROCWMMA_FATTN)
|
|
24
|
+
|
|
25
|
+
// WMMA flash attention requires FP16 matrix instructions to be available for ggml code.
|
|
26
|
+
static bool ggml_cuda_should_use_wmma_fattn(const int cc) {
|
|
27
|
+
#if defined(GGML_USE_HIP) && !defined(GGML_HIP_ROCWMMA_FATTN)
|
|
28
|
+
return false;
|
|
29
|
+
#else
|
|
30
|
+
if ((GGML_CUDA_CC_IS_NVIDIA(cc) && ggml_cuda_highest_compiled_arch(cc) == GGML_CUDA_CC_VOLTA) ||
|
|
31
|
+
GGML_CUDA_CC_IS_RDNA3(cc) || GGML_CUDA_CC_IS_MTHREADS(cc)) {
|
|
32
|
+
return true;
|
|
33
|
+
} else if (GGML_CUDA_CC_IS_CDNA(cc)){
|
|
34
|
+
#if defined(GGML_HIP_ROCWMMA_FATTN) && (ROCWMMA_VERSION_MAJOR < 2 || ROCWMMA_VERSION_MINOR > 0 || ROCWMMA_VERSION_PATCH > 0)
|
|
35
|
+
return true;
|
|
36
|
+
#else
|
|
37
|
+
return false;
|
|
38
|
+
#endif // defined(GGML_HIP_ROCWMMA_FATTN) (ROCWMMA_VERSION_MAJOR < 2 || ROCWMMA_VERSION_MINOR > 0 || ROCWMMA_VERSION_PATCH > 0)
|
|
39
|
+
} else if (GGML_CUDA_CC_IS_RDNA4(cc)) {
|
|
40
|
+
#if defined(GGML_HIP_ROCWMMA_FATTN) && ROCWMMA_VERSION_MAJOR > 1
|
|
41
|
+
return true;
|
|
42
|
+
#else
|
|
43
|
+
return false;
|
|
44
|
+
#endif // defined(GGML_HIP_ROCWMMA_FATTN) && ROCWMMA_VERSION_MAJOR > 1
|
|
45
|
+
} else {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
#endif // defined(GGML_USE_HIP) && !defined(GGML_HIP_ROCWMMA_FATTN)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
void ggml_cuda_flash_attn_ext_wmma_f16(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
#include "common.cuh"
|
|
2
|
+
#include "fattn-common.cuh"
|
|
3
|
+
#include "fattn-mma-f16.cuh"
|
|
4
|
+
#include "fattn-tile.cuh"
|
|
5
|
+
#include "fattn-vec.cuh"
|
|
6
|
+
#include "fattn-wmma-f16.cuh"
|
|
7
|
+
#include "fattn.cuh"
|
|
8
|
+
|
|
9
|
+
template <int DKQ, int DV, int ncols2>
|
|
10
|
+
static void ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
11
|
+
const int cc = ggml_cuda_info().devices[ggml_cuda_get_device()].cc;
|
|
12
|
+
const ggml_tensor * Q = dst->src[0];
|
|
13
|
+
|
|
14
|
+
if constexpr (ncols2 <= 8) {
|
|
15
|
+
if (turing_mma_available(cc) && Q->ne[1] <= 8/ncols2) {
|
|
16
|
+
ggml_cuda_flash_attn_ext_mma_f16_case<DKQ, DV, 8/ncols2, ncols2>(ctx, dst);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if constexpr (ncols2 <= 16) {
|
|
22
|
+
if ((turing_mma_available(cc) || amd_wmma_available(cc)) && Q->ne[1] <= 16/ncols2) {
|
|
23
|
+
ggml_cuda_flash_attn_ext_mma_f16_case<DKQ, DV, 16/ncols2, ncols2>(ctx, dst);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (ggml_cuda_highest_compiled_arch(cc) == GGML_CUDA_CC_TURING || amd_wmma_available(cc) || Q->ne[1] <= 32/ncols2) {
|
|
29
|
+
ggml_cuda_flash_attn_ext_mma_f16_case<DKQ, DV, 32/ncols2, ncols2>(ctx, dst);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
ggml_cuda_flash_attn_ext_mma_f16_case<DKQ, DV, 64/ncols2, ncols2>(ctx, dst);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
template <int DKQ, int DV>
|
|
37
|
+
static void ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
38
|
+
const int cc = ggml_cuda_info().devices[ggml_cuda_get_device()].cc;
|
|
39
|
+
const ggml_tensor * KQV = dst;
|
|
40
|
+
const ggml_tensor * Q = dst->src[0];
|
|
41
|
+
const ggml_tensor * K = dst->src[1];
|
|
42
|
+
const ggml_tensor * V = dst->src[2];
|
|
43
|
+
const ggml_tensor * mask = dst->src[3];
|
|
44
|
+
|
|
45
|
+
float max_bias = 0.0f;
|
|
46
|
+
memcpy(&max_bias, (const float *) KQV->op_params + 1, sizeof(float));
|
|
47
|
+
|
|
48
|
+
// Edge cases like no mask, ALiBi, unpadded K/V, or misaligned addresses for large data transfers
|
|
49
|
+
// are put into the template specialization without GQA optimizations.
|
|
50
|
+
bool use_gqa_opt = mask && max_bias == 0.0f && K->ne[1] % FATTN_KQ_STRIDE == 0;
|
|
51
|
+
for (const ggml_tensor * t : {Q, K, V, mask}) {
|
|
52
|
+
if (t == nullptr || ggml_is_quantized(t->type)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
for (size_t i = 1; i < GGML_MAX_DIMS; ++i) {
|
|
56
|
+
if (t->nb[i] % 16 != 0) {
|
|
57
|
+
use_gqa_opt = false;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
GGML_ASSERT(Q->ne[2] % K->ne[2] == 0);
|
|
64
|
+
const int gqa_ratio = Q->ne[2] / K->ne[2];
|
|
65
|
+
|
|
66
|
+
// On Volta the GQA optimizations aren't as impactful vs. minimizing wasted compute:
|
|
67
|
+
if (cc == GGML_CUDA_CC_VOLTA) {
|
|
68
|
+
if (use_gqa_opt && gqa_ratio % 8 == 0) {
|
|
69
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 8>(ctx, dst);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (use_gqa_opt && gqa_ratio % 4 == 0) {
|
|
74
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 4>(ctx, dst);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if constexpr (DKQ <= 256) {
|
|
79
|
+
if (use_gqa_opt && gqa_ratio % 2 == 0) {
|
|
80
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 2>(ctx, dst);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 1>(ctx, dst);
|
|
85
|
+
return;
|
|
86
|
+
} else {
|
|
87
|
+
GGML_ABORT("fatal error");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (use_gqa_opt && gqa_ratio > 4) {
|
|
92
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 8>(ctx, dst);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (use_gqa_opt && gqa_ratio > 2) {
|
|
97
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 4>(ctx, dst);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if constexpr (DKQ <= 256) {
|
|
102
|
+
if (use_gqa_opt && gqa_ratio > 1) {
|
|
103
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 2>(ctx, dst);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 1>(ctx, dst);
|
|
108
|
+
} else {
|
|
109
|
+
GGML_ABORT("fatal error");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static void ggml_cuda_flash_attn_ext_mma_f16(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
114
|
+
const int cc = ggml_cuda_info().devices[ggml_cuda_get_device()].cc;
|
|
115
|
+
const ggml_tensor * KQV = dst;
|
|
116
|
+
const ggml_tensor * Q = dst->src[0];
|
|
117
|
+
const ggml_tensor * K = dst->src[1];
|
|
118
|
+
const ggml_tensor * V = dst->src[2];
|
|
119
|
+
const ggml_tensor * mask = dst->src[3];
|
|
120
|
+
|
|
121
|
+
switch (Q->ne[0]) {
|
|
122
|
+
case 64:
|
|
123
|
+
GGML_ASSERT(V->ne[0] == 64);
|
|
124
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2< 64, 64>(ctx, dst);
|
|
125
|
+
break;
|
|
126
|
+
case 80:
|
|
127
|
+
GGML_ASSERT(V->ne[0] == 80);
|
|
128
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2< 80, 80>(ctx, dst);
|
|
129
|
+
break;
|
|
130
|
+
case 96:
|
|
131
|
+
GGML_ASSERT(V->ne[0] == 96);
|
|
132
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2< 96, 96>(ctx, dst);
|
|
133
|
+
break;
|
|
134
|
+
case 112:
|
|
135
|
+
GGML_ASSERT(V->ne[0] == 112);
|
|
136
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2<112, 112>(ctx, dst);
|
|
137
|
+
break;
|
|
138
|
+
case 128:
|
|
139
|
+
GGML_ASSERT(V->ne[0] == 128);
|
|
140
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2<128, 128>(ctx, dst);
|
|
141
|
+
break;
|
|
142
|
+
case 256:
|
|
143
|
+
GGML_ASSERT(V->ne[0] == 256);
|
|
144
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2<256, 256>(ctx, dst);
|
|
145
|
+
break;
|
|
146
|
+
case 320:
|
|
147
|
+
// For Mistral Small 4, go straight to the ncols1 switch (ncols2=32-only build).
|
|
148
|
+
GGML_ASSERT(V->ne[0] == 256);
|
|
149
|
+
{
|
|
150
|
+
float max_bias = 0.0f;
|
|
151
|
+
memcpy(&max_bias, (const float *) KQV->op_params + 1, sizeof(float));
|
|
152
|
+
|
|
153
|
+
const bool use_gqa_opt = mask && max_bias == 0.0f;
|
|
154
|
+
GGML_ASSERT(use_gqa_opt);
|
|
155
|
+
GGML_ASSERT(Q->ne[2] % K->ne[2] == 0);
|
|
156
|
+
const int gqa_ratio = Q->ne[2] / K->ne[2];
|
|
157
|
+
GGML_ASSERT(gqa_ratio % 32 == 0);
|
|
158
|
+
|
|
159
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<320, 256, 32>(ctx, dst);
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case 512:
|
|
163
|
+
GGML_ASSERT(V->ne[0] == 512);
|
|
164
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2<512, 512>(ctx, dst);
|
|
165
|
+
break;
|
|
166
|
+
case 576: {
|
|
167
|
+
// For Deepseek, go straight to the ncols1 switch to avoid compiling unnecessary kernels.
|
|
168
|
+
GGML_ASSERT(V->ne[0] == 512);
|
|
169
|
+
float max_bias = 0.0f;
|
|
170
|
+
memcpy(&max_bias, (const float *) KQV->op_params + 1, sizeof(float));
|
|
171
|
+
|
|
172
|
+
const bool use_gqa_opt = mask && max_bias == 0.0f;
|
|
173
|
+
GGML_ASSERT(use_gqa_opt);
|
|
174
|
+
|
|
175
|
+
GGML_ASSERT(Q->ne[2] % K->ne[2] == 0);
|
|
176
|
+
const int gqa_ratio = Q->ne[2] / K->ne[2];
|
|
177
|
+
if (gqa_ratio == 20) { // GLM 4.7 Flash
|
|
178
|
+
if (cc >= GGML_CUDA_CC_DGX_SPARK) {
|
|
179
|
+
if (Q->ne[1] <= 8) {
|
|
180
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 16>(ctx, dst);
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 4>(ctx, dst);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
if (cc >= GGML_CUDA_CC_BLACKWELL) {
|
|
187
|
+
if (Q->ne[1] <= 4 && K->ne[1] >= 65536) {
|
|
188
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 16>(ctx, dst);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 4>(ctx, dst);
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
if (cc >= GGML_CUDA_CC_ADA_LOVELACE) {
|
|
195
|
+
if (Q->ne[1] <= 4) {
|
|
196
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 16>(ctx, dst);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 4>(ctx, dst);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
if (cc >= GGML_CUDA_CC_TURING) {
|
|
203
|
+
if (Q->ne[1] <= 4) {
|
|
204
|
+
if (K->ne[1] <= 16384) {
|
|
205
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 16>(ctx, dst);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 32>(ctx, dst);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 4>(ctx, dst);
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
// Volta:
|
|
215
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 4>(ctx, dst);
|
|
216
|
+
} else if (gqa_ratio % 16 == 0) {
|
|
217
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 16>(ctx, dst);
|
|
218
|
+
} else {
|
|
219
|
+
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<576, 512, 4>(ctx, dst);
|
|
220
|
+
}
|
|
221
|
+
} break;
|
|
222
|
+
default:
|
|
223
|
+
GGML_ABORT("fatal error");
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
#define FATTN_VEC_CASE(D, type_K, type_V) \
|
|
229
|
+
{ \
|
|
230
|
+
const bool type_K_okay = K->type == (type_K) || (K->type == GGML_TYPE_F32 && (type_K) == GGML_TYPE_F16); \
|
|
231
|
+
const bool type_V_okay = V->type == (type_V) || (V->type == GGML_TYPE_F32 && (type_V) == GGML_TYPE_F16); \
|
|
232
|
+
if (Q->ne[0] == (D) && type_K_okay && type_V_okay) { \
|
|
233
|
+
ggml_cuda_flash_attn_ext_vec_case<D, type_K, type_V>(ctx, dst); \
|
|
234
|
+
return; \
|
|
235
|
+
} \
|
|
236
|
+
} \
|
|
237
|
+
|
|
238
|
+
#define FATTN_VEC_CASES_ALL_D(type_K, type_V) \
|
|
239
|
+
FATTN_VEC_CASE( 64, type_K, type_V) \
|
|
240
|
+
FATTN_VEC_CASE(128, type_K, type_V) \
|
|
241
|
+
FATTN_VEC_CASE(256, type_K, type_V) \
|
|
242
|
+
|
|
243
|
+
static void ggml_cuda_flash_attn_ext_vec(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
244
|
+
ggml_tensor * Q = dst->src[0];
|
|
245
|
+
ggml_tensor * K = dst->src[1];
|
|
246
|
+
ggml_tensor * V = dst->src[2];
|
|
247
|
+
|
|
248
|
+
#ifdef GGML_CUDA_FA_ALL_QUANTS
|
|
249
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_F16, GGML_TYPE_F16)
|
|
250
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_0, GGML_TYPE_F16)
|
|
251
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_1, GGML_TYPE_F16)
|
|
252
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_0, GGML_TYPE_F16)
|
|
253
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_1, GGML_TYPE_F16)
|
|
254
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q8_0, GGML_TYPE_F16)
|
|
255
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_BF16, GGML_TYPE_F16)
|
|
256
|
+
|
|
257
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_F16, GGML_TYPE_Q4_0)
|
|
258
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_0, GGML_TYPE_Q4_0)
|
|
259
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_1, GGML_TYPE_Q4_0)
|
|
260
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_0, GGML_TYPE_Q4_0)
|
|
261
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_1, GGML_TYPE_Q4_0)
|
|
262
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q8_0, GGML_TYPE_Q4_0)
|
|
263
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_BF16, GGML_TYPE_Q4_0)
|
|
264
|
+
|
|
265
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_F16, GGML_TYPE_Q4_1)
|
|
266
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_0, GGML_TYPE_Q4_1)
|
|
267
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_1, GGML_TYPE_Q4_1)
|
|
268
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_0, GGML_TYPE_Q4_1)
|
|
269
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_1, GGML_TYPE_Q4_1)
|
|
270
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q8_0, GGML_TYPE_Q4_1)
|
|
271
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_BF16, GGML_TYPE_Q4_1)
|
|
272
|
+
|
|
273
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_F16, GGML_TYPE_Q5_0)
|
|
274
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_0, GGML_TYPE_Q5_0)
|
|
275
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_1, GGML_TYPE_Q5_0)
|
|
276
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_0, GGML_TYPE_Q5_0)
|
|
277
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_1, GGML_TYPE_Q5_0)
|
|
278
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q8_0, GGML_TYPE_Q5_0)
|
|
279
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_BF16, GGML_TYPE_Q5_0)
|
|
280
|
+
|
|
281
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_F16, GGML_TYPE_Q5_1)
|
|
282
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_0, GGML_TYPE_Q5_1)
|
|
283
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_1, GGML_TYPE_Q5_1)
|
|
284
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_0, GGML_TYPE_Q5_1)
|
|
285
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_1, GGML_TYPE_Q5_1)
|
|
286
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q8_0, GGML_TYPE_Q5_1)
|
|
287
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_BF16, GGML_TYPE_Q5_1)
|
|
288
|
+
|
|
289
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_F16, GGML_TYPE_Q8_0)
|
|
290
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_0, GGML_TYPE_Q8_0)
|
|
291
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_1, GGML_TYPE_Q8_0)
|
|
292
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_0, GGML_TYPE_Q8_0)
|
|
293
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_1, GGML_TYPE_Q8_0)
|
|
294
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q8_0, GGML_TYPE_Q8_0)
|
|
295
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_BF16, GGML_TYPE_Q8_0)
|
|
296
|
+
|
|
297
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_F16, GGML_TYPE_BF16)
|
|
298
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_0, GGML_TYPE_BF16)
|
|
299
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_1, GGML_TYPE_BF16)
|
|
300
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_0, GGML_TYPE_BF16)
|
|
301
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q5_1, GGML_TYPE_BF16)
|
|
302
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q8_0, GGML_TYPE_BF16)
|
|
303
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_BF16, GGML_TYPE_BF16)
|
|
304
|
+
#else
|
|
305
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_F16, GGML_TYPE_F16)
|
|
306
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q4_0, GGML_TYPE_Q4_0)
|
|
307
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_Q8_0, GGML_TYPE_Q8_0)
|
|
308
|
+
FATTN_VEC_CASES_ALL_D(GGML_TYPE_BF16, GGML_TYPE_BF16)
|
|
309
|
+
#endif // GGML_CUDA_FA_ALL_QUANTS
|
|
310
|
+
|
|
311
|
+
GGML_ABORT("fatal error");
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Best FlashAttention kernel for a specific GPU:
|
|
315
|
+
enum best_fattn_kernel {
|
|
316
|
+
BEST_FATTN_KERNEL_NONE = 0,
|
|
317
|
+
BEST_FATTN_KERNEL_TILE = 200,
|
|
318
|
+
BEST_FATTN_KERNEL_VEC = 100,
|
|
319
|
+
BEST_FATTN_KERNEL_WMMA_F16 = 300,
|
|
320
|
+
BEST_FATTN_KERNEL_MMA_F16 = 400,
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
static best_fattn_kernel ggml_cuda_get_best_fattn_kernel(const int device, const ggml_tensor * dst) {
|
|
324
|
+
#ifndef FLASH_ATTN_AVAILABLE
|
|
325
|
+
GGML_UNUSED(device); GGML_UNUSED(dst);
|
|
326
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
327
|
+
#endif// FLASH_ATTN_AVAILABLE
|
|
328
|
+
|
|
329
|
+
const ggml_tensor * KQV = dst;
|
|
330
|
+
const ggml_tensor * Q = dst->src[0];
|
|
331
|
+
const ggml_tensor * K = dst->src[1];
|
|
332
|
+
const ggml_tensor * V = dst->src[2];
|
|
333
|
+
const ggml_tensor * mask = dst->src[3];
|
|
334
|
+
|
|
335
|
+
const int gqa_ratio = Q->ne[2] / K->ne[2];
|
|
336
|
+
GGML_ASSERT(Q->ne[2] % K->ne[2] == 0);
|
|
337
|
+
|
|
338
|
+
float max_bias = 0.0f;
|
|
339
|
+
memcpy(&max_bias, (const float *) KQV->op_params + 1, sizeof(float));
|
|
340
|
+
|
|
341
|
+
// The effective batch size for the kernel can be increased by gqa_ratio.
|
|
342
|
+
// The kernel versions without this optimization are also used for ALiBi, if there is no mask, or if the KV cache is not padded,
|
|
343
|
+
bool gqa_opt_applies = gqa_ratio >= 2 && mask && max_bias == 0.0f && K->ne[1] % FATTN_KQ_STRIDE == 0;
|
|
344
|
+
for (const ggml_tensor * t : {Q, K, V, mask}) {
|
|
345
|
+
if (t == nullptr || ggml_is_quantized(t->type)) {
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
for (size_t i = 1; i < GGML_MAX_DIMS; ++i) {
|
|
349
|
+
if (t->nb[i] % 16 != 0) {
|
|
350
|
+
gqa_opt_applies = false;
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const int cc = ggml_cuda_info().devices[device].cc;
|
|
357
|
+
|
|
358
|
+
switch (K->ne[0]) {
|
|
359
|
+
case 40:
|
|
360
|
+
case 64:
|
|
361
|
+
case 72:
|
|
362
|
+
case 80:
|
|
363
|
+
case 96:
|
|
364
|
+
case 128:
|
|
365
|
+
case 112:
|
|
366
|
+
case 256:
|
|
367
|
+
if (V->ne[0] != K->ne[0]) {
|
|
368
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
369
|
+
}
|
|
370
|
+
break;
|
|
371
|
+
case 320:
|
|
372
|
+
if (V->ne[0] != 256 || !gqa_opt_applies) {
|
|
373
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
374
|
+
}
|
|
375
|
+
if (gqa_ratio % 32 != 0) {
|
|
376
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
case 512:
|
|
380
|
+
if (V->ne[0] != K->ne[0]) {
|
|
381
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
382
|
+
}
|
|
383
|
+
if (!gqa_opt_applies) {
|
|
384
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
385
|
+
}
|
|
386
|
+
break;
|
|
387
|
+
case 576:
|
|
388
|
+
if (V->ne[0] != 512) {
|
|
389
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
390
|
+
}
|
|
391
|
+
if (!gqa_opt_applies) {
|
|
392
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
393
|
+
}
|
|
394
|
+
break;
|
|
395
|
+
default:
|
|
396
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
#ifndef GGML_CUDA_FA_ALL_QUANTS
|
|
400
|
+
if (K->type != V->type) {
|
|
401
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
402
|
+
}
|
|
403
|
+
#endif // GGML_CUDA_FA_ALL_QUANTS
|
|
404
|
+
|
|
405
|
+
switch (K->type) {
|
|
406
|
+
case GGML_TYPE_F32:
|
|
407
|
+
case GGML_TYPE_F16:
|
|
408
|
+
break;
|
|
409
|
+
case GGML_TYPE_Q4_1:
|
|
410
|
+
case GGML_TYPE_Q5_0:
|
|
411
|
+
case GGML_TYPE_Q5_1:
|
|
412
|
+
#ifndef GGML_CUDA_FA_ALL_QUANTS
|
|
413
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
414
|
+
#endif // GGML_CUDA_FA_ALL_QUANTS
|
|
415
|
+
case GGML_TYPE_Q4_0:
|
|
416
|
+
case GGML_TYPE_Q8_0:
|
|
417
|
+
case GGML_TYPE_BF16:
|
|
418
|
+
break;
|
|
419
|
+
default:
|
|
420
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
424
|
+
// CrispASR: allow per-head additive masks; only the MMA-F16 kernel body has been
|
|
425
|
+
// patched to consume nb32. Other kernels (VEC/TILE/WMMA-F16) still broadcast the
|
|
426
|
+
// mask across heads, so we force per-head-mask cases to fall through to MMA-F16
|
|
427
|
+
// or, on arches where MMA-F16 is not reachable, to CPU fallback (NONE).
|
|
428
|
+
//
|
|
429
|
+
// The MMA-F16 mask offset patch (fattn-mma-f16.cuh) is only correct for
|
|
430
|
+
// ncols2 == 1 — when gqa_ratio > 1 the launcher may fold multiple Q heads
|
|
431
|
+
// into one tile (ncols2 > 1) and our per-tile offset would broadcast head
|
|
432
|
+
// zt_Q's mask across the folded heads. Force CPU fallback for that case
|
|
433
|
+
// (== upstream pre-patch behaviour, no regression).
|
|
434
|
+
const bool mask_is_per_head = (mask && mask->ne[2] != 1);
|
|
435
|
+
if (mask_is_per_head && gqa_ratio > 1) {
|
|
436
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
437
|
+
}
|
|
438
|
+
#else
|
|
439
|
+
if (mask && mask->ne[2] != 1) {
|
|
440
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
441
|
+
}
|
|
442
|
+
#endif
|
|
443
|
+
|
|
444
|
+
// For small batch sizes the vector kernel may be preferable over the kernels optimized for large batch sizes:
|
|
445
|
+
const bool can_use_vector_kernel = Q->ne[0] <= 256 && Q->ne[0] % 64 == 0 && K->ne[1] % FATTN_KQ_STRIDE == 0;
|
|
446
|
+
|
|
447
|
+
// If Turing tensor cores are available, use them:
|
|
448
|
+
if (turing_mma_available(cc) && Q->ne[0] != 40 && Q->ne[0] != 72) {
|
|
449
|
+
if (can_use_vector_kernel) {
|
|
450
|
+
if (!ggml_is_quantized(K->type) && !ggml_is_quantized(V->type)) {
|
|
451
|
+
if (cc >= GGML_CUDA_CC_ADA_LOVELACE && Q->ne[1] == 1 && Q->ne[3] == 1 && !(gqa_ratio > 4 && K->ne[1] >= 8192)) {
|
|
452
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
453
|
+
if (!mask_is_per_head)
|
|
454
|
+
#endif
|
|
455
|
+
return BEST_FATTN_KERNEL_VEC;
|
|
456
|
+
}
|
|
457
|
+
} else {
|
|
458
|
+
if (cc >= GGML_CUDA_CC_ADA_LOVELACE) {
|
|
459
|
+
if (Q->ne[1] <= 2) {
|
|
460
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
461
|
+
if (!mask_is_per_head)
|
|
462
|
+
#endif
|
|
463
|
+
return BEST_FATTN_KERNEL_VEC;
|
|
464
|
+
}
|
|
465
|
+
} else {
|
|
466
|
+
if (Q->ne[1] == 1) {
|
|
467
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
468
|
+
if (!mask_is_per_head)
|
|
469
|
+
#endif
|
|
470
|
+
return BEST_FATTN_KERNEL_VEC;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (!gqa_opt_applies && Q->ne[1] == 1) {
|
|
475
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
476
|
+
if (!mask_is_per_head)
|
|
477
|
+
#endif
|
|
478
|
+
return BEST_FATTN_KERNEL_VEC;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return BEST_FATTN_KERNEL_MMA_F16;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (volta_mma_available(cc) && Q->ne[0] != 40 && Q->ne[0] != 72) {
|
|
485
|
+
int gqa_ratio_eff = 1;
|
|
486
|
+
const int ncols2_max = Q->ne[0] == 576 ? 16 : 8;
|
|
487
|
+
while (gqa_ratio % (2*gqa_ratio_eff) == 0 && gqa_ratio_eff < ncols2_max) {
|
|
488
|
+
gqa_ratio_eff *= 2;
|
|
489
|
+
}
|
|
490
|
+
if (can_use_vector_kernel && Q->ne[1] * gqa_ratio_eff <= 2) {
|
|
491
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
492
|
+
if (!mask_is_per_head)
|
|
493
|
+
#endif
|
|
494
|
+
return BEST_FATTN_KERNEL_VEC;
|
|
495
|
+
}
|
|
496
|
+
if (Q->ne[1] * gqa_ratio_eff <= 16) {
|
|
497
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
498
|
+
if (!mask_is_per_head)
|
|
499
|
+
#endif
|
|
500
|
+
return BEST_FATTN_KERNEL_TILE; // On Volta tensor cores are only faster for sufficiently large matrices.
|
|
501
|
+
}
|
|
502
|
+
return BEST_FATTN_KERNEL_MMA_F16;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// Use the WMMA kernel if possible:
|
|
506
|
+
if (ggml_cuda_should_use_wmma_fattn(cc) && K->ne[1] % FATTN_KQ_STRIDE == 0 && Q->ne[0] != 40 && Q->ne[0] != 72 && Q->ne[0] != 512 && Q->ne[0] != 576) {
|
|
507
|
+
if (can_use_vector_kernel && Q->ne[1] <= 2) {
|
|
508
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
509
|
+
if (!mask_is_per_head)
|
|
510
|
+
#endif
|
|
511
|
+
return BEST_FATTN_KERNEL_VEC;
|
|
512
|
+
}
|
|
513
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
514
|
+
// WMMA-F16 doesn't yet consume per-head mask strides; fall through to
|
|
515
|
+
// NONE (CPU fallback) via the safety net at the end of this function.
|
|
516
|
+
if (!mask_is_per_head)
|
|
517
|
+
#endif
|
|
518
|
+
return BEST_FATTN_KERNEL_WMMA_F16;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (amd_wmma_available(cc) && GGML_CUDA_CC_IS_RDNA4(cc) && gqa_opt_applies && Q->ne[0] <= 128 && Q->ne[0] != 40 && Q->ne[0] != 72) {
|
|
522
|
+
if (can_use_vector_kernel) {
|
|
523
|
+
if (!ggml_is_quantized(K->type) && !ggml_is_quantized(V->type)) {
|
|
524
|
+
if (Q->ne[1] == 1) {
|
|
525
|
+
if (!gqa_opt_applies) {
|
|
526
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
527
|
+
if (!mask_is_per_head)
|
|
528
|
+
#endif
|
|
529
|
+
return BEST_FATTN_KERNEL_VEC;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
} else {
|
|
533
|
+
if (Q->ne[1] <= 2) {
|
|
534
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
535
|
+
if (!mask_is_per_head)
|
|
536
|
+
#endif
|
|
537
|
+
return BEST_FATTN_KERNEL_VEC;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
int gqa_ratio_eff = 1;
|
|
542
|
+
const int ncols2_max = Q->ne[0] == 576 ? 16 : 8;
|
|
543
|
+
while (gqa_ratio % (2*gqa_ratio_eff) == 0 && gqa_ratio_eff < ncols2_max) {
|
|
544
|
+
gqa_ratio_eff *= 2;
|
|
545
|
+
}
|
|
546
|
+
if (Q->ne[1] * gqa_ratio_eff <= 8) {
|
|
547
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
548
|
+
if (!mask_is_per_head)
|
|
549
|
+
#endif
|
|
550
|
+
return BEST_FATTN_KERNEL_TILE; // AMD WMMA is only faster if the full tile width of 16 can be utilized.
|
|
551
|
+
}
|
|
552
|
+
return BEST_FATTN_KERNEL_MMA_F16;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// Use MFMA flash attention for CDNA (MI100+):
|
|
556
|
+
if (amd_mfma_available(cc) && Q->ne[0] != 40 && Q->ne[0] != 72 && Q->ne[0] != 256 && Q->ne[0] != 512 && Q->ne[0] != 576) {
|
|
557
|
+
const int64_t eff_nq = Q->ne[1] * (gqa_opt_applies ? gqa_ratio : 1);
|
|
558
|
+
// MMA vs tile crossover benchmarked on MI300X @ d32768:
|
|
559
|
+
// hsk=64 (gqa=4): MMA wins at eff >= 128 (+11%)
|
|
560
|
+
// hsk=128 (gqa=4): MMA wins at eff >= 128 (+4%)
|
|
561
|
+
if (eff_nq >= (GGML_CUDA_CC_IS_CDNA1(cc) && Q->ne[0] == 64 ? 64 : 128)) {
|
|
562
|
+
return BEST_FATTN_KERNEL_MMA_F16;
|
|
563
|
+
}
|
|
564
|
+
// Fall through to tile kernel for small effective batch sizes.
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// If there are no tensor cores available, use the generic tile kernel:
|
|
568
|
+
if (can_use_vector_kernel) {
|
|
569
|
+
if (!ggml_is_quantized(K->type) && !ggml_is_quantized(V->type)) {
|
|
570
|
+
if (Q->ne[1] == 1) {
|
|
571
|
+
if (!gqa_opt_applies) {
|
|
572
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
573
|
+
if (!mask_is_per_head)
|
|
574
|
+
#endif
|
|
575
|
+
return BEST_FATTN_KERNEL_VEC;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
} else {
|
|
579
|
+
if (Q->ne[1] <= 2) {
|
|
580
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
581
|
+
if (!mask_is_per_head)
|
|
582
|
+
#endif
|
|
583
|
+
return BEST_FATTN_KERNEL_VEC;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
#ifdef GGML_CUDA_CRISPASR_FA_PERHEAD_MASK
|
|
588
|
+
// Safety net: per-head masks reaching this point have no MMA-F16 fallback on
|
|
589
|
+
// this arch (e.g. WMMA-only Pascal, or generic-tile CPU). Return NONE so the
|
|
590
|
+
// scheduler falls back to CPU FA — same behaviour as upstream pre-patch.
|
|
591
|
+
if (mask_is_per_head) {
|
|
592
|
+
return BEST_FATTN_KERNEL_NONE;
|
|
593
|
+
}
|
|
594
|
+
#endif
|
|
595
|
+
return BEST_FATTN_KERNEL_TILE;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
void ggml_cuda_flash_attn_ext(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
599
|
+
ggml_cuda_set_device(ctx.device);
|
|
600
|
+
switch (ggml_cuda_get_best_fattn_kernel(ggml_cuda_get_device(), dst)) {
|
|
601
|
+
case BEST_FATTN_KERNEL_NONE:
|
|
602
|
+
GGML_ABORT("fatal error");
|
|
603
|
+
case BEST_FATTN_KERNEL_TILE:
|
|
604
|
+
ggml_cuda_flash_attn_ext_tile(ctx, dst);
|
|
605
|
+
break;
|
|
606
|
+
case BEST_FATTN_KERNEL_VEC:
|
|
607
|
+
ggml_cuda_flash_attn_ext_vec(ctx, dst);
|
|
608
|
+
break;
|
|
609
|
+
case BEST_FATTN_KERNEL_WMMA_F16:
|
|
610
|
+
ggml_cuda_flash_attn_ext_wmma_f16(ctx, dst);
|
|
611
|
+
break;
|
|
612
|
+
case BEST_FATTN_KERNEL_MMA_F16:
|
|
613
|
+
ggml_cuda_flash_attn_ext_mma_f16(ctx, dst);
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
bool ggml_cuda_flash_attn_ext_supported(int device, const ggml_tensor * dst) {
|
|
619
|
+
return ggml_cuda_get_best_fattn_kernel(device, dst) != BEST_FATTN_KERNEL_NONE;
|
|
620
|
+
}
|