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,696 @@
|
|
|
1
|
+
// Old and deprecated WMMA FlashAttention implementation.
|
|
2
|
+
// It is still needed for Volta since the memory layout of NVIDIA tensor cores changed with Turing.
|
|
3
|
+
// Long-term the WMMA code should be replaced with a dedicated Volta implementation.
|
|
4
|
+
|
|
5
|
+
#include "common.cuh"
|
|
6
|
+
#include "fattn-common.cuh"
|
|
7
|
+
#include "fattn-wmma-f16.cuh"
|
|
8
|
+
|
|
9
|
+
#ifdef GGML_USE_WMMA_FATTN
|
|
10
|
+
#if !defined(GGML_USE_HIP)
|
|
11
|
+
#include <mma.h>
|
|
12
|
+
#if defined(GGML_USE_MUSA)
|
|
13
|
+
namespace wmma = mtmusa::wmma;
|
|
14
|
+
#else // GGML_USE_MUSA
|
|
15
|
+
namespace wmma = nvcuda::wmma;
|
|
16
|
+
#endif // GGML_USE_MUSA
|
|
17
|
+
#elif defined(GGML_USE_HIP)
|
|
18
|
+
#include <rocwmma/rocwmma.hpp>
|
|
19
|
+
namespace wmma = rocwmma;
|
|
20
|
+
#endif // !defined(GGML_USE_HIP)
|
|
21
|
+
#endif // GGML_USE_WMMA_FATTN
|
|
22
|
+
|
|
23
|
+
// D == head size, VKQ_stride == num VKQ rows calculated in parallel:
|
|
24
|
+
template<int D, int ncols, int nwarps, int VKQ_stride, typename KQ_acc_t, bool use_logit_softcap>
|
|
25
|
+
__launch_bounds__(nwarps*ggml_cuda_get_physical_warp_size(), 1)
|
|
26
|
+
static __global__ void flash_attn_ext_f16(
|
|
27
|
+
const char * __restrict__ Q,
|
|
28
|
+
const char * __restrict__ K,
|
|
29
|
+
const char * __restrict__ V,
|
|
30
|
+
const char * __restrict__ mask,
|
|
31
|
+
const char * __restrict__ sinks,
|
|
32
|
+
const int * __restrict__ KV_max,
|
|
33
|
+
float * __restrict__ dst,
|
|
34
|
+
float2 * __restrict__ dst_meta,
|
|
35
|
+
const float scale,
|
|
36
|
+
const float max_bias,
|
|
37
|
+
const float m0,
|
|
38
|
+
const float m1,
|
|
39
|
+
const uint32_t n_head_log2,
|
|
40
|
+
const float logit_softcap,
|
|
41
|
+
const int32_t ne00, const uint3 ne01, const int32_t ne02, const int32_t ne03,
|
|
42
|
+
const int32_t nb01, const int32_t nb02, const int32_t nb03,
|
|
43
|
+
const int32_t ne10, const int32_t ne11, const int32_t ne12, const int32_t ne13,
|
|
44
|
+
const int32_t nb11, const int32_t nb12, const int64_t nb13,
|
|
45
|
+
const int32_t nb21, const int32_t nb22, const int64_t nb23,
|
|
46
|
+
const int32_t ne31, const int32_t ne32, const int32_t ne33,
|
|
47
|
+
const int32_t nb31, const int32_t nb32, const int64_t nb33) {
|
|
48
|
+
#if defined(FLASH_ATTN_AVAILABLE) && (defined(GGML_HIP_ROCWMMA_FATTN) && defined(GGML_USE_WMMA_FATTN))
|
|
49
|
+
// Skip unused kernel variants for faster compilation:
|
|
50
|
+
if (use_logit_softcap && !(D == 128 || D == 256)) {
|
|
51
|
+
NO_DEVICE_CODE;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//In this kernel Q, K, V are matrices while i, j, k are matrix indices.
|
|
56
|
+
|
|
57
|
+
constexpr int warp_size = ggml_cuda_get_physical_warp_size();
|
|
58
|
+
|
|
59
|
+
const int ic0 = ncols*blockIdx.x; // Index of the first Q/QKV column to work on.
|
|
60
|
+
|
|
61
|
+
static_assert(D <= FATTN_KQ_STRIDE, "D must be <= FATTN_KQ_STRIDE.");
|
|
62
|
+
static_assert(ncols == 8 || ncols % 16 == 0, "ncols must be 8 or a multiple of 16.");
|
|
63
|
+
constexpr int frag_m = ncols == 8 ? 32 : 16;
|
|
64
|
+
constexpr int frag_n = ncols == 8 ? 8 : 16;
|
|
65
|
+
static_assert(D % frag_m == 0, "If ncols == 8 then D % frag_m must be 0.");
|
|
66
|
+
#if defined(GGML_USE_HIP) && HIP_VERSION >= 60500000
|
|
67
|
+
typedef wmma::fragment<wmma::matrix_a, frag_m, frag_n, 16, _Float16, wmma::row_major> frag_a_K;
|
|
68
|
+
typedef wmma::fragment<wmma::matrix_a, frag_m, frag_n, 16, _Float16, wmma::col_major> frag_a_V;
|
|
69
|
+
typedef wmma::fragment<wmma::matrix_b, frag_m, frag_n, 16, _Float16, wmma::col_major> frag_b;
|
|
70
|
+
typedef wmma::fragment<wmma::accumulator, frag_m, frag_n, 16, KQ_acc_t> frag_c_KQ;
|
|
71
|
+
typedef wmma::fragment<wmma::accumulator, frag_m, frag_n, 16, _Float16> frag_c_VKQ;
|
|
72
|
+
#else
|
|
73
|
+
typedef wmma::fragment<wmma::matrix_a, frag_m, frag_n, 16, half, wmma::row_major> frag_a_K;
|
|
74
|
+
typedef wmma::fragment<wmma::matrix_a, frag_m, frag_n, 16, half, wmma::col_major> frag_a_V;
|
|
75
|
+
typedef wmma::fragment<wmma::matrix_b, frag_m, frag_n, 16, half, wmma::col_major> frag_b;
|
|
76
|
+
typedef wmma::fragment<wmma::accumulator, frag_m, frag_n, 16, KQ_acc_t> frag_c_KQ;
|
|
77
|
+
typedef wmma::fragment<wmma::accumulator, frag_m, frag_n, 16, half> frag_c_VKQ;
|
|
78
|
+
#endif
|
|
79
|
+
|
|
80
|
+
constexpr int KQ_stride_tc = nwarps*frag_m; // Number of KQ rows calculated in parallel.
|
|
81
|
+
constexpr int VKQ_ratio = KQ_stride_tc/VKQ_stride; // Number of parallel VKQ accumulators needed to keep all warps busy.
|
|
82
|
+
static_assert(VKQ_ratio <= nwarps, "VKQ_ratio must be <= nwarps.");
|
|
83
|
+
|
|
84
|
+
// Pad internal representation of KQ, KQV to reduce shared memory bank conflicts:
|
|
85
|
+
constexpr int D_padded = D + 8;
|
|
86
|
+
constexpr int kqs_padded = FATTN_KQ_STRIDE + 8;
|
|
87
|
+
constexpr int kqar = sizeof(KQ_acc_t)/sizeof(half);
|
|
88
|
+
|
|
89
|
+
const int sequence = blockIdx.z / ne02;
|
|
90
|
+
const int head = blockIdx.z - sequence*ne02;
|
|
91
|
+
const int gqa_ratio = ne02 / ne12; // With grouped query attention there are > 1 Q matrices per K, V matrix.
|
|
92
|
+
const float * Q_f = (const float *) (Q + nb03* sequence + nb02* head + nb01*ic0);
|
|
93
|
+
const half * K_h = (const half *) (K + nb13* sequence + nb12*(head / gqa_ratio));
|
|
94
|
+
const half * V_h = (const half *) (V + nb13* sequence + nb12*(head / gqa_ratio)); // K and V have same shape
|
|
95
|
+
const half * maskh = (const half *) (mask + nb33*(sequence % ne33) + nb31*ic0);
|
|
96
|
+
const half2 * mask2 = (const half2 *) maskh;
|
|
97
|
+
const float * sinksf = (const float *) sinks;
|
|
98
|
+
|
|
99
|
+
const int stride_Q = nb01 / sizeof(float);
|
|
100
|
+
const int stride_KV = nb11 / sizeof(half);
|
|
101
|
+
|
|
102
|
+
const float slopef = get_alibi_slope(max_bias, head, n_head_log2, m0, m1);
|
|
103
|
+
const half slopeh = __float2half(slopef);
|
|
104
|
+
const half2 slope2 = make_half2(slopef, slopef);
|
|
105
|
+
|
|
106
|
+
const half2 logit_softcap_2 = make_half2(logit_softcap, logit_softcap);
|
|
107
|
+
|
|
108
|
+
frag_b Q_b[D/16][ncols/frag_n];
|
|
109
|
+
|
|
110
|
+
// A single buffer for temporarily holding tiles of KQ and VKQ parts:
|
|
111
|
+
constexpr int mem_KQ = ncols*kqs_padded*kqar;
|
|
112
|
+
constexpr int mem_VKQ_parts = VKQ_ratio*ncols*D_padded;
|
|
113
|
+
__shared__ half KQ[mem_KQ >= mem_VKQ_parts ? mem_KQ : mem_VKQ_parts];
|
|
114
|
+
float * KQ_f = (float *) KQ;
|
|
115
|
+
half2 * KQ2 = (half2 *) KQ;
|
|
116
|
+
|
|
117
|
+
float KQ_rowsum_f[ncols/nwarps] = {0.0f};
|
|
118
|
+
float KQ_max_f[ncols/nwarps];
|
|
119
|
+
float KQ_max_scale_f[ncols/nwarps] = {0.0f};
|
|
120
|
+
|
|
121
|
+
#pragma unroll
|
|
122
|
+
for (int j = 0; j < ncols/nwarps; ++j) {
|
|
123
|
+
KQ_max_f[j] = -FLT_MAX/2.0f;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
half2 KQ_rowsum_h2[ncols/nwarps] = {{0.0f, 0.0f}};
|
|
127
|
+
half2 KQ_max_h2[ncols/nwarps];
|
|
128
|
+
half2 KQ_max_scale_h2[ncols/nwarps] = {{0.0f, 0.0f}};
|
|
129
|
+
|
|
130
|
+
#pragma unroll
|
|
131
|
+
for (int j = 0; j < ncols/nwarps; ++j) {
|
|
132
|
+
KQ_max_h2[j] = make_half2(-HALF_MAX_HALF, -HALF_MAX_HALF);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
__shared__ half VKQ[ncols*D_padded]; // Accumulator for final VKQ slice.
|
|
136
|
+
half2 * VKQ2 = (half2 *) VKQ;
|
|
137
|
+
|
|
138
|
+
#if defined(GGML_USE_HIP) && HIP_VERSION >= 60500000
|
|
139
|
+
const _Float16 * K_h_f16 = reinterpret_cast<const _Float16 *>(K_h);
|
|
140
|
+
const _Float16 * V_h_f16 = reinterpret_cast<const _Float16 *>(V_h);
|
|
141
|
+
_Float16 * KQ_f16 = reinterpret_cast<_Float16 *>(KQ);
|
|
142
|
+
_Float16 * VKQ_f16 = reinterpret_cast<_Float16 *>(VKQ);
|
|
143
|
+
#else
|
|
144
|
+
const half * K_h_f16 = K_h;
|
|
145
|
+
const half * V_h_f16 = V_h;
|
|
146
|
+
half * KQ_f16 = KQ;
|
|
147
|
+
half * VKQ_f16 = VKQ;
|
|
148
|
+
#endif
|
|
149
|
+
|
|
150
|
+
#pragma unroll
|
|
151
|
+
for (int j0 = 0; j0 < ncols; j0 += nwarps) {
|
|
152
|
+
const int j = j0 + threadIdx.y;
|
|
153
|
+
#pragma unroll
|
|
154
|
+
for (int i0 = 0; i0 < D/2; i0 += warp_size) {
|
|
155
|
+
const int i = i0 + threadIdx.x;
|
|
156
|
+
if (i0 + warp_size > D/2 && i >= D/2) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
VKQ2[j*(D_padded/2) + i] = make_half2(0.0f, 0.0f);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Convert Q to half and apply scale, temporarily store in KQ:
|
|
164
|
+
#pragma unroll
|
|
165
|
+
for (int j0 = 0; j0 < ncols; j0 += nwarps) {
|
|
166
|
+
const int j = j0 + threadIdx.y;
|
|
167
|
+
#pragma unroll
|
|
168
|
+
for (int i0 = 0; i0 < D; i0 += warp_size) {
|
|
169
|
+
const int i = i0 + threadIdx.x;
|
|
170
|
+
if (i0 + warp_size > D && i >= D) {
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
KQ[j*D_padded + i] = ic0 + j < int(ne01.z) ? Q_f[j*stride_Q + i] * scale : 0.0f;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
__syncthreads();
|
|
178
|
+
|
|
179
|
+
// Load Q into tensor core fragments/registers since it will be used frequently:
|
|
180
|
+
#pragma unroll
|
|
181
|
+
for (int i0 = 0; i0 < D; i0 += 16) {
|
|
182
|
+
#pragma unroll
|
|
183
|
+
for (int j0 = 0; j0 < ncols; j0 += frag_n) {
|
|
184
|
+
wmma::load_matrix_sync(Q_b[i0/16][j0/frag_n], KQ_f16 + j0*D_padded + i0, D_padded);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
__syncthreads();
|
|
189
|
+
|
|
190
|
+
// Iterate over ne11 == previous tokens:
|
|
191
|
+
const int k_VKQ_max = KV_max ? KV_max[sequence*gridDim.x + blockIdx.x] : ne11;
|
|
192
|
+
for (int k_VKQ_0 = blockIdx.y*FATTN_KQ_STRIDE; k_VKQ_0 < k_VKQ_max; k_VKQ_0 += gridDim.y*FATTN_KQ_STRIDE) {
|
|
193
|
+
// Calculate tile of KQ:
|
|
194
|
+
#pragma unroll
|
|
195
|
+
for (int i_KQ_0 = 0; i_KQ_0 < FATTN_KQ_STRIDE; i_KQ_0 += KQ_stride_tc) {
|
|
196
|
+
frag_c_KQ KQ_c[ncols/frag_n];
|
|
197
|
+
#pragma unroll
|
|
198
|
+
for (int j = 0; j < ncols/frag_n; ++j) {
|
|
199
|
+
wmma::fill_fragment(KQ_c[j], static_cast<KQ_acc_t>(0.0f));
|
|
200
|
+
}
|
|
201
|
+
#pragma unroll
|
|
202
|
+
for (int k_KQ_0 = 0; k_KQ_0 < D; k_KQ_0 += 16) {
|
|
203
|
+
frag_a_K K_a;
|
|
204
|
+
wmma::load_matrix_sync(K_a, K_h_f16 + int64_t(k_VKQ_0 + i_KQ_0 + frag_m*threadIdx.y)*stride_KV + k_KQ_0, stride_KV);
|
|
205
|
+
#pragma unroll
|
|
206
|
+
for (int j = 0; j < ncols/frag_n; ++j) {
|
|
207
|
+
wmma::mma_sync(KQ_c[j], K_a, Q_b[k_KQ_0/16][j], KQ_c[j]);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
#pragma unroll
|
|
211
|
+
for (int j0 = 0; j0 < ncols; j0 += frag_n) {
|
|
212
|
+
wmma::store_matrix_sync((KQ_acc_t *) KQ + j0*kqs_padded + i_KQ_0 + frag_m*threadIdx.y, KQ_c[j0/frag_n], kqs_padded, wmma::mem_col_major);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
__syncthreads();
|
|
217
|
+
|
|
218
|
+
// Calculate softmax for each KQ column using the current max. value.
|
|
219
|
+
// The divisor is stored in KQ_rowsum and will be applied at the end.
|
|
220
|
+
#pragma unroll
|
|
221
|
+
for (int j0 = 0; j0 < ncols; j0 += nwarps) {
|
|
222
|
+
const int j = j0 + threadIdx.y;
|
|
223
|
+
|
|
224
|
+
if (std::is_same<KQ_acc_t, float>::value) {
|
|
225
|
+
float KQ_f_tmp[FATTN_KQ_STRIDE / warp_size];
|
|
226
|
+
#pragma unroll
|
|
227
|
+
for (int k0 = 0; k0 < FATTN_KQ_STRIDE; k0 += warp_size) {
|
|
228
|
+
const int k = k0 + threadIdx.x;
|
|
229
|
+
|
|
230
|
+
KQ_f_tmp[k0/warp_size] = KQ_f[j*kqs_padded + k];
|
|
231
|
+
|
|
232
|
+
if (use_logit_softcap) {
|
|
233
|
+
KQ_f_tmp[k0/warp_size] = logit_softcap*tanhf(KQ_f_tmp[k0/warp_size]);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
float KQ_max_new = KQ_max_f[j0/nwarps];
|
|
238
|
+
#pragma unroll
|
|
239
|
+
for (int k0 = 0; k0 < FATTN_KQ_STRIDE; k0 += warp_size) {
|
|
240
|
+
const int k = k0 + threadIdx.x;
|
|
241
|
+
|
|
242
|
+
KQ_f_tmp[k0/warp_size] += mask && ic0 + j < int(ne01.z) ?
|
|
243
|
+
__half2float(slopeh*maskh[j*(nb31/sizeof(half)) + k_VKQ_0 + k]) : 0.0f;
|
|
244
|
+
KQ_max_new = max(KQ_max_new, KQ_f_tmp[k0/warp_size] + FATTN_KQ_MAX_OFFSET);
|
|
245
|
+
}
|
|
246
|
+
KQ_max_new = warp_reduce_max<warp_size>(KQ_max_new);
|
|
247
|
+
|
|
248
|
+
const float diff = KQ_max_f[j0/nwarps] - KQ_max_new;
|
|
249
|
+
KQ_max_scale_f[j0/nwarps] = expf(diff);
|
|
250
|
+
if (diff <= SOFTMAX_FTZ_THRESHOLD) {
|
|
251
|
+
KQ_max_scale_f[j0/nwarps] = 0.0f;
|
|
252
|
+
}
|
|
253
|
+
KQ_max_f[j0/nwarps] = KQ_max_new;
|
|
254
|
+
|
|
255
|
+
float KQ_rowsum_add = 0.0f;
|
|
256
|
+
#pragma unroll
|
|
257
|
+
for (int k0 = 0; k0 < FATTN_KQ_STRIDE; k0 += warp_size) {
|
|
258
|
+
const int k = k0 + threadIdx.x;
|
|
259
|
+
|
|
260
|
+
const float diff = KQ_f_tmp[k0/warp_size] - KQ_max_f[j0/nwarps];
|
|
261
|
+
KQ_f_tmp[k0/warp_size] = expf(diff);
|
|
262
|
+
if (diff <= SOFTMAX_FTZ_THRESHOLD) {
|
|
263
|
+
KQ_f_tmp[k0/warp_size] = 0.0f;
|
|
264
|
+
}
|
|
265
|
+
KQ_rowsum_add += KQ_f_tmp[k0/warp_size];
|
|
266
|
+
KQ[j*(kqar*kqs_padded) + k] = KQ_f_tmp[k0/warp_size];
|
|
267
|
+
}
|
|
268
|
+
KQ_rowsum_add = warp_reduce_sum<warp_size>(KQ_rowsum_add);
|
|
269
|
+
|
|
270
|
+
// Scale previous KQ_rowsum to account for a potential increase in KQ_max:
|
|
271
|
+
KQ_rowsum_f[j0/nwarps] = KQ_max_scale_f[j0/nwarps]*KQ_rowsum_f[j0/nwarps] + KQ_rowsum_add;
|
|
272
|
+
} else {
|
|
273
|
+
half2 KQ2_tmp[FATTN_KQ_STRIDE/(2*warp_size)];
|
|
274
|
+
#pragma unroll
|
|
275
|
+
for (int k0 = 0; k0 < FATTN_KQ_STRIDE/2; k0 += warp_size) {
|
|
276
|
+
const int k = k0 + threadIdx.x;
|
|
277
|
+
|
|
278
|
+
KQ2_tmp[k0/warp_size] = KQ2[j*(kqs_padded/2) + k];
|
|
279
|
+
|
|
280
|
+
if (use_logit_softcap) {
|
|
281
|
+
// There is no dedicated tangens hyperbolicus function for half2.
|
|
282
|
+
KQ2_tmp[k0/warp_size] = h2exp(KQ2_tmp[k0/warp_size]*make_half2(2.0f, 2.0f));
|
|
283
|
+
KQ2_tmp[k0/warp_size] = (KQ2_tmp[k0/warp_size] - make_half2(1.0f, 1.0f))
|
|
284
|
+
/(KQ2_tmp[k0/warp_size] + make_half2(1.0f, 1.0f));
|
|
285
|
+
|
|
286
|
+
KQ2_tmp[k0/warp_size] *= logit_softcap_2;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
half2 KQ_max_new = KQ_max_h2[j0/nwarps];
|
|
291
|
+
#pragma unroll
|
|
292
|
+
for (int k0 = 0; k0 < FATTN_KQ_STRIDE/2; k0 += warp_size) {
|
|
293
|
+
const int k = k0 + threadIdx.x;
|
|
294
|
+
|
|
295
|
+
KQ2_tmp[k0/warp_size] += mask && ic0 + j < int(ne01.z) ? slope2*mask2[(j*ne11 + k_VKQ_0)/2 + k] : make_half2(0.0f, 0.0f);
|
|
296
|
+
KQ_max_new = ggml_cuda_hmax2(KQ_max_new, KQ2_tmp[k0/warp_size]);
|
|
297
|
+
}
|
|
298
|
+
KQ_max_new = __half2half2(warp_reduce_max<warp_size>(ggml_cuda_hmax(__low2half(KQ_max_new), __high2half(KQ_max_new))));
|
|
299
|
+
const half2 diff = KQ_max_h2[j0/nwarps] - KQ_max_new;
|
|
300
|
+
KQ_max_scale_h2[j0/nwarps] = h2exp(diff);
|
|
301
|
+
const uint32_t ftz_mask = __hgt2_mask(diff, make_half2(SOFTMAX_FTZ_THRESHOLD, SOFTMAX_FTZ_THRESHOLD));
|
|
302
|
+
*((uint32_t *) &KQ_max_scale_h2[j0/nwarps]) &= ftz_mask;
|
|
303
|
+
KQ_max_h2[j0/nwarps] = KQ_max_new;
|
|
304
|
+
|
|
305
|
+
half2 KQ_rowsum_add = make_half2(0.0f, 0.0f);
|
|
306
|
+
#pragma unroll
|
|
307
|
+
for (int k0 = 0; k0 < FATTN_KQ_STRIDE/2; k0 += warp_size) {
|
|
308
|
+
const int k = k0 + threadIdx.x;
|
|
309
|
+
|
|
310
|
+
const half2 diff = KQ2_tmp[k0/warp_size] - KQ_max_h2[j0/nwarps];
|
|
311
|
+
KQ2_tmp[k0/warp_size] = h2exp(diff);
|
|
312
|
+
const uint32_t ftz_mask = __hgt2_mask(diff, make_half2(SOFTMAX_FTZ_THRESHOLD, SOFTMAX_FTZ_THRESHOLD));
|
|
313
|
+
*((uint32_t *) &KQ2_tmp[k0/warp_size]) &= ftz_mask;
|
|
314
|
+
KQ_rowsum_add += KQ2_tmp[k0/warp_size];
|
|
315
|
+
KQ2[j*(kqs_padded/2) + k] = KQ2_tmp[k0/warp_size];
|
|
316
|
+
}
|
|
317
|
+
KQ_rowsum_add = warp_reduce_sum<warp_size>(KQ_rowsum_add);
|
|
318
|
+
|
|
319
|
+
// Scale previous KQ_rowsum to account for a potential increase in KQ_max:
|
|
320
|
+
KQ_rowsum_h2[j0/nwarps] = KQ_max_scale_h2[j0/nwarps]*KQ_rowsum_h2[j0/nwarps] + KQ_rowsum_add;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
__syncthreads();
|
|
325
|
+
|
|
326
|
+
frag_b KQ_b[FATTN_KQ_STRIDE/(VKQ_ratio*16)][ncols/frag_n];
|
|
327
|
+
#pragma unroll
|
|
328
|
+
for (int j0 = 0; j0 < ncols; j0 += frag_n) {
|
|
329
|
+
#pragma unroll
|
|
330
|
+
for (int k0 = 0; k0 < FATTN_KQ_STRIDE; k0 += VKQ_ratio*16) {
|
|
331
|
+
const int k = k0 + (threadIdx.y % VKQ_ratio)*16;
|
|
332
|
+
wmma::load_matrix_sync(
|
|
333
|
+
KQ_b[k0/(VKQ_ratio*16)][j0/frag_n],
|
|
334
|
+
KQ_f16 + j0*(kqar*kqs_padded) + k,
|
|
335
|
+
kqar*kqs_padded);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
frag_c_VKQ VKQ_c[D/VKQ_stride][ncols/frag_n];
|
|
340
|
+
#pragma unroll
|
|
341
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D; i_VKQ_0 += VKQ_stride) {
|
|
342
|
+
#pragma unroll
|
|
343
|
+
for (int j = 0; j < ncols/frag_n; ++j) {
|
|
344
|
+
wmma::fill_fragment(VKQ_c[i_VKQ_0/VKQ_stride][j], static_cast<half>(0.0f));
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
#pragma unroll
|
|
348
|
+
for (int k0 = 0; k0 < FATTN_KQ_STRIDE; k0 += VKQ_ratio*16) {
|
|
349
|
+
const int k = k0 + (threadIdx.y % VKQ_ratio)*16;
|
|
350
|
+
|
|
351
|
+
frag_a_V v_a;
|
|
352
|
+
wmma::load_matrix_sync(v_a, V_h_f16 + int64_t(k_VKQ_0 + k)*stride_KV + i_VKQ_0 + frag_m*(threadIdx.y/VKQ_ratio), stride_KV);
|
|
353
|
+
#pragma unroll
|
|
354
|
+
for (int j = 0; j < ncols/frag_n; ++j) {
|
|
355
|
+
wmma::mma_sync(VKQ_c[i_VKQ_0/VKQ_stride][j], v_a, KQ_b[k0/(VKQ_ratio*16)][j], VKQ_c[i_VKQ_0/VKQ_stride][j]);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
__syncthreads();
|
|
361
|
+
|
|
362
|
+
const int offset_k = (threadIdx.y % VKQ_ratio) * (ncols*D_padded);
|
|
363
|
+
#pragma unroll
|
|
364
|
+
for (int i_KQ_0 = 0; i_KQ_0 < D; i_KQ_0 += VKQ_stride) {
|
|
365
|
+
#pragma unroll
|
|
366
|
+
for (int j0 = 0; j0 < ncols; j0 += frag_n) {
|
|
367
|
+
wmma::store_matrix_sync(
|
|
368
|
+
KQ_f16 + offset_k + j0*D_padded + i_KQ_0 + frag_m*(threadIdx.y/VKQ_ratio),
|
|
369
|
+
VKQ_c[i_KQ_0/VKQ_stride][j0/frag_n],
|
|
370
|
+
D_padded, wmma::mem_col_major);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
__syncthreads();
|
|
375
|
+
|
|
376
|
+
#pragma unroll
|
|
377
|
+
for (int j0 = 0; j0 < ncols; j0 += nwarps) {
|
|
378
|
+
const int j = j0 + threadIdx.y;
|
|
379
|
+
|
|
380
|
+
half2 VKQ_scale;
|
|
381
|
+
if (std::is_same<KQ_acc_t, float>::value) {
|
|
382
|
+
VKQ_scale = make_half2(KQ_max_scale_f[j0/nwarps], KQ_max_scale_f[j0/nwarps]);
|
|
383
|
+
} else {
|
|
384
|
+
VKQ_scale = KQ_max_scale_h2[j0/nwarps];
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
#pragma unroll
|
|
388
|
+
for (int i0 = 0; i0 < D/2; i0 += warp_size) {
|
|
389
|
+
const int i = i0 + threadIdx.x;
|
|
390
|
+
if (i0 + warp_size > D/2 && i >= D/2) {
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
half2 VKQ_add = make_half2(0.0f, 0.0f);
|
|
395
|
+
#pragma unroll
|
|
396
|
+
for (int l = 0; l < VKQ_ratio; ++l) {
|
|
397
|
+
VKQ_add += KQ2[l*(ncols*D_padded/2) + j*(D_padded/2) + i];
|
|
398
|
+
}
|
|
399
|
+
VKQ2[j*(D_padded/2) + i] = VKQ_scale*VKQ2[j*(D_padded/2) + i] + VKQ_add;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
__syncthreads();
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Apply attention sinks
|
|
407
|
+
if (sinksf && blockIdx.y == 0) {
|
|
408
|
+
const float sinkf = sinksf[head];
|
|
409
|
+
const half sinkh = __float2half(sinkf);
|
|
410
|
+
|
|
411
|
+
#pragma unroll
|
|
412
|
+
for (int j0 = 0; j0 < ncols; j0 += nwarps) {
|
|
413
|
+
const int j = j0 + threadIdx.y;
|
|
414
|
+
|
|
415
|
+
if (std::is_same<KQ_acc_t, float>::value) {
|
|
416
|
+
float kqmax_new = fmaxf(KQ_max_f[j0/nwarps], sinkf);
|
|
417
|
+
|
|
418
|
+
const float KQ_max_scale = expf(KQ_max_f[j0/nwarps] - kqmax_new);
|
|
419
|
+
KQ_max_f[j0/nwarps] = kqmax_new;
|
|
420
|
+
|
|
421
|
+
KQ_rowsum_f[j0/nwarps] = KQ_rowsum_f[j0/nwarps] * KQ_max_scale + expf(sinkf - KQ_max_f[j0/nwarps]);
|
|
422
|
+
|
|
423
|
+
const half2 scale_h2 = make_half2(KQ_max_scale, KQ_max_scale);
|
|
424
|
+
#pragma unroll
|
|
425
|
+
for (int i0 = 0; i0 < D/2; i0 += warp_size) {
|
|
426
|
+
const int i = i0 + threadIdx.x;
|
|
427
|
+
if (i0 + warp_size > D/2 && i >= D/2) break;
|
|
428
|
+
VKQ2[j*(D_padded/2) + i] *= scale_h2;
|
|
429
|
+
}
|
|
430
|
+
} else {
|
|
431
|
+
half kqmax_old = __low2half(KQ_max_h2[j0/nwarps]);
|
|
432
|
+
half kqmax_new = fmaxf(kqmax_old, sinkh);
|
|
433
|
+
KQ_max_h2[j0/nwarps] = __half2half2(kqmax_new);
|
|
434
|
+
|
|
435
|
+
const half KQ_max_scale_h = hexp(kqmax_old - kqmax_new);
|
|
436
|
+
const half2 KQ_max_scale = __half2half2(KQ_max_scale_h);
|
|
437
|
+
|
|
438
|
+
KQ_rowsum_h2[j0/nwarps] = KQ_rowsum_h2[j0/nwarps] * KQ_max_scale;
|
|
439
|
+
const half val = hexp(sinkh - kqmax_new);
|
|
440
|
+
KQ_rowsum_h2[j0/nwarps].x = __hadd(KQ_rowsum_h2[j0/nwarps].x, val);
|
|
441
|
+
|
|
442
|
+
#pragma unroll
|
|
443
|
+
for (int i0 = 0; i0 < D/2; i0 += warp_size) {
|
|
444
|
+
const int i = i0 + threadIdx.x;
|
|
445
|
+
if (i0 + warp_size > D/2 && i >= D/2) break;
|
|
446
|
+
VKQ2[j*(D_padded/2) + i] *= KQ_max_scale;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
__syncthreads();
|
|
452
|
+
}
|
|
453
|
+
#pragma unroll
|
|
454
|
+
for (int j0 = 0; j0 < ncols; j0 += nwarps) {
|
|
455
|
+
const int j_VKQ = j0 + threadIdx.y;
|
|
456
|
+
if (ic0 + j_VKQ >= int(ne01.z)) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
float KQ_rowsum_j;
|
|
461
|
+
if (std::is_same<KQ_acc_t, float>::value) {
|
|
462
|
+
KQ_rowsum_j = KQ_rowsum_f[j0/nwarps];
|
|
463
|
+
} else {
|
|
464
|
+
KQ_rowsum_j = __low2float(KQ_rowsum_h2[j0/nwarps]) + __high2float(KQ_rowsum_h2[j0/nwarps]);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const int j_dst_unrolled = ((sequence*int(ne01.z) + ic0 + j_VKQ)*ne02 + head)*gridDim.y + blockIdx.y;
|
|
468
|
+
|
|
469
|
+
#pragma unroll
|
|
470
|
+
for (int i0 = 0; i0 < D; i0 += warp_size) {
|
|
471
|
+
const int i = i0 + threadIdx.x;
|
|
472
|
+
if (i0 + warp_size > D && i >= D) {
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
float dst_val = VKQ[j_VKQ*D_padded + i];
|
|
476
|
+
if (gridDim.y == 1) {
|
|
477
|
+
dst_val /= KQ_rowsum_j;
|
|
478
|
+
}
|
|
479
|
+
dst[j_dst_unrolled*D + i] = dst_val;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (gridDim.y == 1 || threadIdx.x != 0) {
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
float2 dst_meta_val;
|
|
487
|
+
if (std::is_same<KQ_acc_t, float>::value) {
|
|
488
|
+
dst_meta_val.x = KQ_max_f[j0/nwarps];
|
|
489
|
+
} else {
|
|
490
|
+
dst_meta_val.x = __low2float(KQ_max_h2[j0/nwarps]);
|
|
491
|
+
}
|
|
492
|
+
dst_meta_val.y = KQ_rowsum_j;
|
|
493
|
+
dst_meta[j_dst_unrolled] = dst_meta_val;
|
|
494
|
+
}
|
|
495
|
+
#else
|
|
496
|
+
GGML_UNUSED_VARS(Q, K, V, mask, sinks, KV_max, dst, dst_meta, scale,
|
|
497
|
+
max_bias, m0, m1, n_head_log2, logit_softcap,
|
|
498
|
+
ne00, ne01, ne02, ne03,
|
|
499
|
+
nb01, nb02, nb03,
|
|
500
|
+
ne10, ne11, ne12, ne13,
|
|
501
|
+
nb11, nb12, nb13,
|
|
502
|
+
nb21, nb22, nb23,
|
|
503
|
+
ne31, ne32, ne33,
|
|
504
|
+
nb31, nb32, nb33);
|
|
505
|
+
NO_DEVICE_CODE;
|
|
506
|
+
#endif // defined(FLASH_ATTN_AVAILABLE) && (defined(GGML_HIP_ROCWMMA_FATTN) && defined(GGML_USE_WMMA_FATTN))
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
constexpr int get_max_power_of_2(int x) {
|
|
510
|
+
return x % 2 == 0 ? 2*get_max_power_of_2(x/2) : 1;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
static_assert(get_max_power_of_2(1) == 1, "Test failed.");
|
|
514
|
+
static_assert(get_max_power_of_2(2) == 2, "Test failed.");
|
|
515
|
+
static_assert(get_max_power_of_2(4) == 4, "Test failed.");
|
|
516
|
+
static_assert(get_max_power_of_2(6) == 2, "Test failed.");
|
|
517
|
+
|
|
518
|
+
// Number of VKQ rows calculated in parallel:
|
|
519
|
+
constexpr int get_VKQ_stride(int D, int nwarps, int frag_m) {
|
|
520
|
+
return (get_max_power_of_2(D/frag_m) < nwarps ? get_max_power_of_2(D/frag_m) : nwarps)*frag_m;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
static_assert(get_VKQ_stride(128, 1, 32) == 32, "Test failed.");
|
|
524
|
+
static_assert(get_VKQ_stride(128, 2, 32) == 64, "Test failed.");
|
|
525
|
+
static_assert(get_VKQ_stride(128, 4, 32) == 128, "Test failed.");
|
|
526
|
+
static_assert(get_VKQ_stride( 64, 1, 32) == 32, "Test failed.");
|
|
527
|
+
static_assert(get_VKQ_stride( 64, 2, 32) == 64, "Test failed.");
|
|
528
|
+
static_assert(get_VKQ_stride( 64, 4, 32) == 64, "Test failed.");
|
|
529
|
+
static_assert(get_VKQ_stride( 80, 1, 16) == 16, "Test failed.");
|
|
530
|
+
static_assert(get_VKQ_stride( 80, 2, 16) == 16, "Test failed.");
|
|
531
|
+
static_assert(get_VKQ_stride( 80, 4, 16) == 16, "Test failed.");
|
|
532
|
+
|
|
533
|
+
template <int D, int cols_per_block, typename KQ_acc_t>
|
|
534
|
+
void ggml_cuda_flash_attn_ext_wmma_f16_case(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
535
|
+
const ggml_tensor * KQV = dst;
|
|
536
|
+
|
|
537
|
+
constexpr int nwarps = 4;
|
|
538
|
+
|
|
539
|
+
constexpr int frag_m = cols_per_block == 8 && D % 32 == 0 ? 32 : 16;
|
|
540
|
+
const int warp_size = ggml_cuda_info().devices[ggml_cuda_get_device()].warp_size;
|
|
541
|
+
|
|
542
|
+
float logit_softcap;
|
|
543
|
+
memcpy(&logit_softcap, (const float *) KQV->op_params + 2, sizeof(float));
|
|
544
|
+
|
|
545
|
+
fattn_kernel_t fattn_kernel;
|
|
546
|
+
if (logit_softcap == 0.0f) {
|
|
547
|
+
constexpr bool use_logit_softcap = false;
|
|
548
|
+
fattn_kernel = flash_attn_ext_f16<
|
|
549
|
+
D, cols_per_block, nwarps, get_VKQ_stride(D, nwarps, frag_m), KQ_acc_t, use_logit_softcap>;
|
|
550
|
+
} else {
|
|
551
|
+
constexpr bool use_logit_softcap = true;
|
|
552
|
+
fattn_kernel = flash_attn_ext_f16<
|
|
553
|
+
D, cols_per_block, nwarps, get_VKQ_stride(D, nwarps, frag_m), KQ_acc_t, use_logit_softcap>;
|
|
554
|
+
}
|
|
555
|
+
launch_fattn<D, cols_per_block, 1>(ctx, dst, fattn_kernel, nwarps, 0, FATTN_KQ_STRIDE, true, true, false, warp_size);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
void ggml_cuda_flash_attn_ext_wmma_f16(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
559
|
+
const ggml_tensor * KQV = dst;
|
|
560
|
+
const ggml_tensor * Q = dst->src[0];
|
|
561
|
+
|
|
562
|
+
const enum ggml_prec prec = ggml_flash_attn_ext_get_prec(KQV);
|
|
563
|
+
const int warp_size = ggml_cuda_info().devices[ctx.device].warp_size;
|
|
564
|
+
|
|
565
|
+
if (prec != GGML_PREC_DEFAULT) {
|
|
566
|
+
if (Q->ne[1] <= 32 || Q->ne[0] > 128) {
|
|
567
|
+
constexpr int cols_per_block = 16;
|
|
568
|
+
switch (Q->ne[0]) {
|
|
569
|
+
case 64:
|
|
570
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 64, cols_per_block, float>(ctx, dst);
|
|
571
|
+
break;
|
|
572
|
+
case 80:
|
|
573
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 80, cols_per_block, float>(ctx, dst);
|
|
574
|
+
break;
|
|
575
|
+
case 96:
|
|
576
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 96, cols_per_block, float>(ctx, dst);
|
|
577
|
+
break;
|
|
578
|
+
case 112:
|
|
579
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<112, cols_per_block, float>(ctx, dst);
|
|
580
|
+
break;
|
|
581
|
+
case 128:
|
|
582
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<128, cols_per_block, float>(ctx, dst);
|
|
583
|
+
break;
|
|
584
|
+
case 256:
|
|
585
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<256, cols_per_block, float>(ctx, dst);
|
|
586
|
+
break;
|
|
587
|
+
default:
|
|
588
|
+
GGML_ABORT("fatal error");
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
} else {
|
|
592
|
+
constexpr int cols_per_block = 32;
|
|
593
|
+
switch (Q->ne[0]) {
|
|
594
|
+
case 64:
|
|
595
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 64, cols_per_block, float>(ctx, dst);
|
|
596
|
+
break;
|
|
597
|
+
case 80:
|
|
598
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 80, cols_per_block, float>(ctx, dst);
|
|
599
|
+
break;
|
|
600
|
+
case 96:
|
|
601
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 96, cols_per_block, float>(ctx, dst);
|
|
602
|
+
break;
|
|
603
|
+
case 112:
|
|
604
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<112, cols_per_block, float>(ctx, dst);
|
|
605
|
+
break;
|
|
606
|
+
case 128:
|
|
607
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<128, cols_per_block, float>(ctx, dst);
|
|
608
|
+
break;
|
|
609
|
+
// case 256:
|
|
610
|
+
// ggml_cuda_flash_attn_ext_wmma_f16_case<256, cols_per_block, float>(ctx, dst);
|
|
611
|
+
// break;
|
|
612
|
+
default:
|
|
613
|
+
GGML_ABORT("fatal error");
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
#if !defined(GGML_USE_HIP)
|
|
621
|
+
if (Q->ne[1] <= 8 && Q->ne[0] % warp_size == 0) {
|
|
622
|
+
constexpr int cols_per_block = 8;
|
|
623
|
+
switch (Q->ne[0]) {
|
|
624
|
+
case 64:
|
|
625
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 64, cols_per_block, half>(ctx, dst);
|
|
626
|
+
break;
|
|
627
|
+
case 96:
|
|
628
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 96, cols_per_block, half>(ctx, dst);
|
|
629
|
+
break;
|
|
630
|
+
case 128:
|
|
631
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<128, cols_per_block, half>(ctx, dst);
|
|
632
|
+
break;
|
|
633
|
+
case 256:
|
|
634
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<256, cols_per_block, half>(ctx, dst);
|
|
635
|
+
break;
|
|
636
|
+
default:
|
|
637
|
+
GGML_ABORT("fatal error");
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
#endif // !defined(GGML_USE_HIP)
|
|
643
|
+
|
|
644
|
+
if (Q->ne[1] <= 32) {
|
|
645
|
+
constexpr int cols_per_block = 16;
|
|
646
|
+
switch (Q->ne[0]) {
|
|
647
|
+
case 64:
|
|
648
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 64, cols_per_block, half>(ctx, dst);
|
|
649
|
+
break;
|
|
650
|
+
case 80:
|
|
651
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 80, cols_per_block, half>(ctx, dst);
|
|
652
|
+
break;
|
|
653
|
+
case 96:
|
|
654
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 96, cols_per_block, half>(ctx, dst);
|
|
655
|
+
break;
|
|
656
|
+
case 112:
|
|
657
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<112, cols_per_block, half>(ctx, dst);
|
|
658
|
+
break;
|
|
659
|
+
case 128:
|
|
660
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<128, cols_per_block, half>(ctx, dst);
|
|
661
|
+
break;
|
|
662
|
+
case 256:
|
|
663
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<256, cols_per_block, half>(ctx, dst);
|
|
664
|
+
break;
|
|
665
|
+
default:
|
|
666
|
+
GGML_ABORT("fatal error");
|
|
667
|
+
break;
|
|
668
|
+
}
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
constexpr int cols_per_block = 32;
|
|
673
|
+
switch (Q->ne[0]) {
|
|
674
|
+
case 64:
|
|
675
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 64, cols_per_block, half>(ctx, dst);
|
|
676
|
+
break;
|
|
677
|
+
case 80:
|
|
678
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 80, cols_per_block, half>(ctx, dst);
|
|
679
|
+
break;
|
|
680
|
+
case 96:
|
|
681
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case< 96, cols_per_block, half>(ctx, dst);
|
|
682
|
+
break;
|
|
683
|
+
case 112:
|
|
684
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<112, cols_per_block, half>(ctx, dst);
|
|
685
|
+
break;
|
|
686
|
+
case 128:
|
|
687
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<128, cols_per_block, half>(ctx, dst);
|
|
688
|
+
break;
|
|
689
|
+
case 256:
|
|
690
|
+
ggml_cuda_flash_attn_ext_wmma_f16_case<256, cols_per_block, half>(ctx, dst);
|
|
691
|
+
break;
|
|
692
|
+
default:
|
|
693
|
+
GGML_ABORT("fatal error");
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
}
|