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,37 @@
|
|
|
1
|
+
#include "fill.cuh"
|
|
2
|
+
#include "convert.cuh"
|
|
3
|
+
|
|
4
|
+
#define CUDA_FILL_BLOCK_SIZE 256
|
|
5
|
+
|
|
6
|
+
template <typename T>
|
|
7
|
+
static __global__ void fill_kernel(T * dst, const int64_t k, const T value) {
|
|
8
|
+
const int64_t i = (int64_t)blockDim.x * blockIdx.x + threadIdx.x;
|
|
9
|
+
if (i >= k) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
dst[i] = value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
void ggml_cuda_op_fill(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
16
|
+
void * dst_d = dst->data;
|
|
17
|
+
cudaStream_t stream = ctx.stream();
|
|
18
|
+
|
|
19
|
+
GGML_ASSERT(ggml_is_contiguous(dst));
|
|
20
|
+
|
|
21
|
+
float value;
|
|
22
|
+
memcpy(&value, dst->op_params, sizeof(float));
|
|
23
|
+
|
|
24
|
+
const int64_t k = ggml_nelements(dst);
|
|
25
|
+
const int64_t num_blocks = (k + CUDA_FILL_BLOCK_SIZE - 1) / CUDA_FILL_BLOCK_SIZE;
|
|
26
|
+
|
|
27
|
+
switch (dst->type) {
|
|
28
|
+
case GGML_TYPE_F32:
|
|
29
|
+
fill_kernel<<<num_blocks, CUDA_FILL_BLOCK_SIZE, 0, stream>>>((float *)dst_d, k, value);
|
|
30
|
+
break;
|
|
31
|
+
case GGML_TYPE_F16:
|
|
32
|
+
fill_kernel<<<num_blocks, CUDA_FILL_BLOCK_SIZE, 0, stream>>>((half *)dst_d, k, ggml_cuda_cast<half>(value));
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
GGML_ABORT("unsupported type");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
#include "gated_delta_net.cuh"
|
|
2
|
+
|
|
3
|
+
template <int S_v, bool KDA>
|
|
4
|
+
__global__ void __launch_bounds__((ggml_cuda_get_physical_warp_size() < S_v ? ggml_cuda_get_physical_warp_size() : S_v) * 4, 2)
|
|
5
|
+
gated_delta_net_cuda(const float * q,
|
|
6
|
+
const float * k,
|
|
7
|
+
const float * v,
|
|
8
|
+
const float * g,
|
|
9
|
+
const float * beta,
|
|
10
|
+
const float * curr_state,
|
|
11
|
+
float * dst,
|
|
12
|
+
int64_t H,
|
|
13
|
+
int64_t n_tokens,
|
|
14
|
+
int64_t n_seqs,
|
|
15
|
+
int64_t sq1,
|
|
16
|
+
int64_t sq2,
|
|
17
|
+
int64_t sq3,
|
|
18
|
+
int64_t sv1,
|
|
19
|
+
int64_t sv2,
|
|
20
|
+
int64_t sv3,
|
|
21
|
+
int64_t sb1,
|
|
22
|
+
int64_t sb2,
|
|
23
|
+
int64_t sb3,
|
|
24
|
+
const uint3 neqk1_magic,
|
|
25
|
+
const uint3 rq3_magic,
|
|
26
|
+
float scale) {
|
|
27
|
+
const uint32_t h_idx = blockIdx.x;
|
|
28
|
+
const uint32_t sequence = blockIdx.y;
|
|
29
|
+
// each warp owns one column, using warp-level primitives to reduce across rows
|
|
30
|
+
const int lane = threadIdx.x;
|
|
31
|
+
const int col = blockIdx.z * blockDim.y + threadIdx.y;
|
|
32
|
+
|
|
33
|
+
const uint32_t iq1 = fastmodulo(h_idx, neqk1_magic);
|
|
34
|
+
const uint32_t iq3 = fastdiv(sequence, rq3_magic);
|
|
35
|
+
|
|
36
|
+
const int64_t attn_score_elems = S_v * H * n_tokens * n_seqs;
|
|
37
|
+
float * attn_data = dst;
|
|
38
|
+
float * state = dst + attn_score_elems;
|
|
39
|
+
|
|
40
|
+
const int64_t state_offset = (sequence * H + h_idx) * S_v * S_v;
|
|
41
|
+
state += state_offset;
|
|
42
|
+
curr_state += state_offset + col * S_v;
|
|
43
|
+
attn_data += (sequence * n_tokens * H + h_idx) * S_v;
|
|
44
|
+
|
|
45
|
+
constexpr int warp_size = ggml_cuda_get_physical_warp_size() < S_v ? ggml_cuda_get_physical_warp_size() : S_v;
|
|
46
|
+
static_assert(S_v % warp_size == 0, "S_v must be a multiple of warp_size");
|
|
47
|
+
constexpr int rows_per_lane = (S_v + warp_size - 1) / warp_size;
|
|
48
|
+
float s_shard[rows_per_lane];
|
|
49
|
+
// state is stored transposed: M[col][i] = S[i][col], row col is contiguous
|
|
50
|
+
|
|
51
|
+
#pragma unroll
|
|
52
|
+
for (int r = 0; r < rows_per_lane; r++) {
|
|
53
|
+
const int i = r * warp_size + lane;
|
|
54
|
+
s_shard[r] = curr_state[i];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (int t = 0; t < n_tokens; t++) {
|
|
58
|
+
const float * q_t = q + iq3 * sq3 + t * sq2 + iq1 * sq1;
|
|
59
|
+
const float * k_t = k + iq3 * sq3 + t * sq2 + iq1 * sq1;
|
|
60
|
+
const float * v_t = v + sequence * sv3 + t * sv2 + h_idx * sv1;
|
|
61
|
+
|
|
62
|
+
const int64_t gb_offset = sequence * sb3 + t * sb2 + h_idx * sb1;
|
|
63
|
+
const float * beta_t = beta + gb_offset;
|
|
64
|
+
const float * g_t = g + gb_offset * (KDA ? S_v : 1);
|
|
65
|
+
|
|
66
|
+
const float beta_val = *beta_t;
|
|
67
|
+
|
|
68
|
+
// Cache k and q in registers
|
|
69
|
+
float k_reg[rows_per_lane];
|
|
70
|
+
float q_reg[rows_per_lane];
|
|
71
|
+
#pragma unroll
|
|
72
|
+
for (int r = 0; r < rows_per_lane; r++) {
|
|
73
|
+
const int i = r * warp_size + lane;
|
|
74
|
+
k_reg[r] = k_t[i];
|
|
75
|
+
q_reg[r] = q_t[i];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if constexpr (!KDA) {
|
|
79
|
+
const float g_val = expf(*g_t);
|
|
80
|
+
|
|
81
|
+
// kv[col] = (S^T @ k)[col] = sum_i S[i][col] * k[i]
|
|
82
|
+
float kv_shard = 0.0f;
|
|
83
|
+
#pragma unroll
|
|
84
|
+
for (int r = 0; r < rows_per_lane; r++) {
|
|
85
|
+
kv_shard += s_shard[r] * k_reg[r];
|
|
86
|
+
}
|
|
87
|
+
float kv_col = warp_reduce_sum<warp_size>(kv_shard);
|
|
88
|
+
|
|
89
|
+
// delta[col] = (v[col] - g * kv[col]) * beta
|
|
90
|
+
float delta_col = (v_t[col] - g_val * kv_col) * beta_val;
|
|
91
|
+
|
|
92
|
+
// fused: S[i][col] = g * S[i][col] + k[i] * delta[col]
|
|
93
|
+
// attn[col] = (S^T @ q)[col] = sum_i S[i][col] * q[i]
|
|
94
|
+
float attn_partial = 0.0f;
|
|
95
|
+
#pragma unroll
|
|
96
|
+
for (int r = 0; r < rows_per_lane; r++) {
|
|
97
|
+
s_shard[r] = g_val * s_shard[r] + k_reg[r] * delta_col;
|
|
98
|
+
attn_partial += s_shard[r] * q_reg[r];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
float attn_col = warp_reduce_sum<warp_size>(attn_partial);
|
|
102
|
+
|
|
103
|
+
if (lane == 0) {
|
|
104
|
+
attn_data[col] = attn_col * scale;
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
// kv[col] = sum_i g[i] * S[i][col] * k[i]
|
|
108
|
+
float kv_shard = 0.0f;
|
|
109
|
+
#pragma unroll
|
|
110
|
+
for (int r = 0; r < rows_per_lane; r++) {
|
|
111
|
+
const int i = r * warp_size + lane;
|
|
112
|
+
kv_shard += expf(g_t[i]) * s_shard[r] * k_reg[r];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
float kv_col = warp_reduce_sum<warp_size>(kv_shard);
|
|
116
|
+
|
|
117
|
+
// delta[col] = (v[col] - kv[col]) * beta
|
|
118
|
+
float delta_col = (v_t[col] - kv_col) * beta_val;
|
|
119
|
+
|
|
120
|
+
// fused: S[i][col] = g[i] * S[i][col] + k[i] * delta[col]
|
|
121
|
+
// attn[col] = (S^T @ q)[col] = sum_i S[i][col] * q[i]
|
|
122
|
+
float attn_partial = 0.0f;
|
|
123
|
+
#pragma unroll
|
|
124
|
+
for (int r = 0; r < rows_per_lane; r++) {
|
|
125
|
+
const int i = r * warp_size + lane;
|
|
126
|
+
s_shard[r] = expf(g_t[i]) * s_shard[r] + k_reg[r] * delta_col;
|
|
127
|
+
attn_partial += s_shard[r] * q_reg[r];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
float attn_col = warp_reduce_sum<warp_size>(attn_partial);
|
|
131
|
+
|
|
132
|
+
if (lane == 0) {
|
|
133
|
+
attn_data[col] = attn_col * scale;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
attn_data += S_v * H;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Write state back to global memory (transposed layout)
|
|
141
|
+
#pragma unroll
|
|
142
|
+
for (int r = 0; r < rows_per_lane; r++) {
|
|
143
|
+
const int i = r * warp_size + lane;
|
|
144
|
+
state[col * S_v + i] = s_shard[r];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
template <bool KDA>
|
|
149
|
+
static void launch_gated_delta_net(
|
|
150
|
+
const float * q_d, const float * k_d, const float * v_d,
|
|
151
|
+
const float * g_d, const float * b_d, const float * s_d,
|
|
152
|
+
float * dst_d,
|
|
153
|
+
int64_t S_v, int64_t H, int64_t n_tokens, int64_t n_seqs,
|
|
154
|
+
int64_t sq1, int64_t sq2, int64_t sq3,
|
|
155
|
+
int64_t sv1, int64_t sv2, int64_t sv3,
|
|
156
|
+
int64_t sb1, int64_t sb2, int64_t sb3,
|
|
157
|
+
int64_t neqk1, int64_t rq3,
|
|
158
|
+
float scale, cudaStream_t stream) {
|
|
159
|
+
//TODO: Add chunked kernel for even faster pre-fill
|
|
160
|
+
const int warp_size = ggml_cuda_info().devices[ggml_cuda_get_device()].warp_size;
|
|
161
|
+
const int num_warps = 4;
|
|
162
|
+
dim3 grid_dims(H, n_seqs, (S_v + num_warps - 1) / num_warps);
|
|
163
|
+
dim3 block_dims(warp_size <= S_v ? warp_size : S_v, num_warps, 1);
|
|
164
|
+
|
|
165
|
+
const uint3 neqk1_magic = init_fastdiv_values(neqk1);
|
|
166
|
+
const uint3 rq3_magic = init_fastdiv_values(rq3);
|
|
167
|
+
|
|
168
|
+
int cc = ggml_cuda_info().devices[ggml_cuda_get_device()].cc;
|
|
169
|
+
|
|
170
|
+
switch (S_v) {
|
|
171
|
+
case 16:
|
|
172
|
+
gated_delta_net_cuda<16, KDA><<<grid_dims, block_dims, 0, stream>>>(
|
|
173
|
+
q_d, k_d, v_d, g_d, b_d, s_d, dst_d, H,
|
|
174
|
+
n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
|
|
175
|
+
sb1, sb2, sb3, neqk1_magic, rq3_magic, scale);
|
|
176
|
+
break;
|
|
177
|
+
case 32:
|
|
178
|
+
gated_delta_net_cuda<32, KDA><<<grid_dims, block_dims, 0, stream>>>(
|
|
179
|
+
q_d, k_d, v_d, g_d, b_d, s_d, dst_d, H,
|
|
180
|
+
n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
|
|
181
|
+
sb1, sb2, sb3, neqk1_magic, rq3_magic, scale);
|
|
182
|
+
break;
|
|
183
|
+
case 64: {
|
|
184
|
+
gated_delta_net_cuda<64, KDA><<<grid_dims, block_dims, 0, stream>>>(
|
|
185
|
+
q_d, k_d, v_d, g_d, b_d, s_d, dst_d, H,
|
|
186
|
+
n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
|
|
187
|
+
sb1, sb2, sb3, neqk1_magic, rq3_magic, scale);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case 128: {
|
|
191
|
+
gated_delta_net_cuda<128, KDA><<<grid_dims, block_dims, 0, stream>>>(
|
|
192
|
+
q_d, k_d, v_d, g_d, b_d, s_d, dst_d, H,
|
|
193
|
+
n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
|
|
194
|
+
sb1, sb2, sb3, neqk1_magic, rq3_magic, scale);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
default:
|
|
198
|
+
GGML_ABORT("fatal error");
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
void ggml_cuda_op_gated_delta_net(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
204
|
+
ggml_tensor * src_q = dst->src[0];
|
|
205
|
+
ggml_tensor * src_k = dst->src[1];
|
|
206
|
+
ggml_tensor * src_v = dst->src[2];
|
|
207
|
+
ggml_tensor * src_g = dst->src[3];
|
|
208
|
+
ggml_tensor * src_beta = dst->src[4];
|
|
209
|
+
ggml_tensor * src_state = dst->src[5];
|
|
210
|
+
|
|
211
|
+
GGML_TENSOR_LOCALS(int64_t, neq, src_q, ne);
|
|
212
|
+
GGML_TENSOR_LOCALS(size_t , nbq, src_q, nb);
|
|
213
|
+
GGML_TENSOR_LOCALS(int64_t, nek, src_k, ne);
|
|
214
|
+
GGML_TENSOR_LOCALS(size_t , nbk, src_k, nb);
|
|
215
|
+
GGML_TENSOR_LOCALS(int64_t, nev, src_v, ne);
|
|
216
|
+
GGML_TENSOR_LOCALS(size_t, nbv, src_v, nb);
|
|
217
|
+
GGML_TENSOR_LOCALS(size_t, nbb, src_beta, nb);
|
|
218
|
+
|
|
219
|
+
const int64_t S_v = nev0;
|
|
220
|
+
const int64_t H = nev1;
|
|
221
|
+
const int64_t n_tokens = nev2;
|
|
222
|
+
const int64_t n_seqs = nev3;
|
|
223
|
+
|
|
224
|
+
const bool kda = (src_g->ne[0] == S_v);
|
|
225
|
+
|
|
226
|
+
GGML_ASSERT(neq1 == nek1);
|
|
227
|
+
const int64_t neqk1 = neq1;
|
|
228
|
+
|
|
229
|
+
const int64_t rq3 = nev3 / neq3;
|
|
230
|
+
|
|
231
|
+
const float * q_d = (const float *) src_q->data;
|
|
232
|
+
const float * k_d = (const float *) src_k->data;
|
|
233
|
+
const float * v_d = (const float *) src_v->data;
|
|
234
|
+
const float * g_d = (const float *) src_g->data;
|
|
235
|
+
const float * b_d = (const float *) src_beta->data;
|
|
236
|
+
|
|
237
|
+
const float * s_d = (const float *) src_state->data;
|
|
238
|
+
float * dst_d = (float *) dst->data;
|
|
239
|
+
|
|
240
|
+
GGML_ASSERT(ggml_is_contiguous_rows(src_q));
|
|
241
|
+
GGML_ASSERT(ggml_is_contiguous_rows(src_k));
|
|
242
|
+
GGML_ASSERT(ggml_is_contiguous_rows(src_v));
|
|
243
|
+
GGML_ASSERT(ggml_are_same_stride(src_q, src_k));
|
|
244
|
+
GGML_ASSERT(src_g->ne[0] == 1 || kda);
|
|
245
|
+
GGML_ASSERT(ggml_is_contiguous(src_g));
|
|
246
|
+
GGML_ASSERT(ggml_is_contiguous(src_beta));
|
|
247
|
+
GGML_ASSERT(ggml_is_contiguous(src_state));
|
|
248
|
+
|
|
249
|
+
// strides in floats (beta strides used for both g and beta offset computation)
|
|
250
|
+
const int64_t sq1 = nbq1 / sizeof(float);
|
|
251
|
+
const int64_t sq2 = nbq2 / sizeof(float);
|
|
252
|
+
const int64_t sq3 = nbq3 / sizeof(float);
|
|
253
|
+
const int64_t sv1 = nbv1 / sizeof(float);
|
|
254
|
+
const int64_t sv2 = nbv2 / sizeof(float);
|
|
255
|
+
const int64_t sv3 = nbv3 / sizeof(float);
|
|
256
|
+
const int64_t sb1 = nbb1 / sizeof(float);
|
|
257
|
+
const int64_t sb2 = nbb2 / sizeof(float);
|
|
258
|
+
const int64_t sb3 = nbb3 / sizeof(float);
|
|
259
|
+
|
|
260
|
+
const float scale = 1.0f / sqrtf((float) S_v);
|
|
261
|
+
|
|
262
|
+
cudaStream_t stream = ctx.stream();
|
|
263
|
+
|
|
264
|
+
if (kda) {
|
|
265
|
+
launch_gated_delta_net<true>(q_d, k_d, v_d, g_d, b_d, s_d, dst_d,
|
|
266
|
+
S_v, H, n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
|
|
267
|
+
sb1, sb2, sb3, neqk1, rq3, scale, stream);
|
|
268
|
+
} else {
|
|
269
|
+
launch_gated_delta_net<false>(q_d, k_d, v_d, g_d, b_d, s_d, dst_d,
|
|
270
|
+
S_v, H, n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
|
|
271
|
+
sb1, sb2, sb3, neqk1, rq3, scale, stream);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
#include "getrows.cuh"
|
|
2
|
+
#include "dequantize.cuh"
|
|
3
|
+
#include "convert.cuh"
|
|
4
|
+
|
|
5
|
+
// ── k-quant GET_ROWS ────────────────────────────────────────────────
|
|
6
|
+
// The legacy quants (Q4_0 etc.) use a per-element dequantize_kernel_t
|
|
7
|
+
// that outputs float2. K-quants (Q4_K, Q5_K, Q6_K) have a more complex
|
|
8
|
+
// block structure incompatible with that interface. Instead, we use the
|
|
9
|
+
// row-level dequantize functions from convert.cu via ggml_get_to_fp32_cuda.
|
|
10
|
+
//
|
|
11
|
+
// Strategy: copy indices to host, then launch one dequantize kernel per
|
|
12
|
+
// selected row. For typical embedding lookups (1-4 rows of 4096 elements),
|
|
13
|
+
// sequential kernel launches are negligible vs the LM forward pass.
|
|
14
|
+
template<typename dst_t>
|
|
15
|
+
static void get_rows_cuda_kquant(
|
|
16
|
+
const void * src0_d, const ggml_type src0_type, const int32_t * src1_d, dst_t * dst_d,
|
|
17
|
+
const int64_t ne00, const size_t nb01, const size_t nb02, const size_t nb03,
|
|
18
|
+
const int64_t ne10, const int64_t ne11, const int64_t ne12, const size_t nb10, const size_t nb11, const size_t nb12,
|
|
19
|
+
const size_t nb1, const size_t nb2, const size_t nb3,
|
|
20
|
+
cudaStream_t stream) {
|
|
21
|
+
to_fp32_cuda_t dequant = ggml_get_to_fp32_cuda(src0_type);
|
|
22
|
+
GGML_ASSERT(dequant != nullptr);
|
|
23
|
+
|
|
24
|
+
// Copy index tensor to host (typically 1-4 indices for embed lookups).
|
|
25
|
+
const int64_t n_ids = ne10 * ne11 * ne12;
|
|
26
|
+
std::vector<int32_t> ids_host(n_ids);
|
|
27
|
+
CUDA_CHECK(cudaMemcpyAsync(ids_host.data(), src1_d, n_ids * sizeof(int32_t),
|
|
28
|
+
cudaMemcpyDeviceToHost, stream));
|
|
29
|
+
CUDA_CHECK(cudaStreamSynchronize(stream));
|
|
30
|
+
|
|
31
|
+
for (int64_t idx = 0; idx < n_ids; idx++) {
|
|
32
|
+
const int32_t row = ids_host[idx];
|
|
33
|
+
const void * src_row = (const char *)src0_d + (size_t)row * nb01;
|
|
34
|
+
float * dst_row = (float *)((char *)dst_d + idx * nb1);
|
|
35
|
+
dequant(src_row, dst_row, ne00, stream);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
template<int qk, int qr, dequantize_kernel_t dequantize_kernel, typename dst_t>
|
|
40
|
+
static __global__ void k_get_rows(
|
|
41
|
+
const void * __restrict__ src0, const int32_t * __restrict__ src1, dst_t * __restrict__ dst,
|
|
42
|
+
const int64_t ne00, /*const int64_t ne01, const int64_t ne02, const int64_t ne03,*/
|
|
43
|
+
/*const int64_t ne10,*/ const int64_t ne11, const int64_t ne12, /*const int64_t ne13,*/
|
|
44
|
+
/*const size_t s0,*/ const size_t s1, const size_t s2, const size_t s3,
|
|
45
|
+
/*const size_t nb00,*/ const size_t nb01, const size_t nb02, const size_t nb03,
|
|
46
|
+
const size_t s10, const size_t s11, const size_t s12/*, const size_t s13*/) {
|
|
47
|
+
|
|
48
|
+
for (int64_t z = blockIdx.z; z < ne11*ne12; z += gridDim.z) {
|
|
49
|
+
for (int64_t i00 = 2*(blockIdx.y*blockDim.x + threadIdx.x); i00 < ne00; i00 += gridDim.y*blockDim.x) {
|
|
50
|
+
// The x and y dimensions of the grid are swapped because the maximum allowed grid size for x is higher.
|
|
51
|
+
const int i10 = blockIdx.x;
|
|
52
|
+
const int i11 = z / ne12; // TODO fastdiv
|
|
53
|
+
const int i12 = z % ne12;
|
|
54
|
+
|
|
55
|
+
const int i01 = src1[i10*s10 + i11*s11 + i12*s12];
|
|
56
|
+
|
|
57
|
+
dst_t * dst_row = dst + i10*s1 + i11*s2 + i12*s3;
|
|
58
|
+
const void * src0_row = (const char *) src0 + i01*nb01 + i11*nb02 + i12*nb03;
|
|
59
|
+
|
|
60
|
+
const int ib = i00/qk; // block index
|
|
61
|
+
const int iqs = (i00%qk)/qr; // quant index
|
|
62
|
+
const int iybs = i00 - i00%qk; // dst block start index
|
|
63
|
+
const int y_offset = qr == 1 ? 1 : qk/2;
|
|
64
|
+
|
|
65
|
+
// dequantize
|
|
66
|
+
float2 v;
|
|
67
|
+
dequantize_kernel(src0_row, ib, iqs, v);
|
|
68
|
+
|
|
69
|
+
dst_row[iybs + iqs + 0] = ggml_cuda_cast<dst_t>(v.x);
|
|
70
|
+
dst_row[iybs + iqs + y_offset] = ggml_cuda_cast<dst_t>(v.y);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
template<typename src0_t, typename dst_t>
|
|
76
|
+
static __global__ void k_get_rows_float(
|
|
77
|
+
const src0_t * __restrict__ src0, const int32_t * __restrict__ src1, dst_t * __restrict__ dst,
|
|
78
|
+
const int64_t ne00, /*const int64_t ne01, const int64_t ne02, const int64_t ne03,*/
|
|
79
|
+
/*const int64_t ne10,*/ const int64_t ne11, const int64_t ne12, /*const int64_t ne13,*/
|
|
80
|
+
/*const size_t s0,*/ const size_t s1, const size_t s2, const size_t s3,
|
|
81
|
+
/*const size_t nb00,*/ const size_t nb01, const size_t nb02, const size_t nb03,
|
|
82
|
+
const size_t s10, const size_t s11, const size_t s12/*, const size_t s13*/) {
|
|
83
|
+
|
|
84
|
+
for (int64_t z = blockIdx.z; z < ne11*ne12; z += gridDim.z) {
|
|
85
|
+
for (int64_t i00 = blockIdx.y*blockDim.x + threadIdx.x; i00 < ne00; i00 += gridDim.y*blockDim.x) {
|
|
86
|
+
// The x and y dimensions of the grid are swapped because the maximum allowed grid size for x is higher.
|
|
87
|
+
const int i10 = blockIdx.x;
|
|
88
|
+
const int i11 = z / ne12; // TODO fastdiv
|
|
89
|
+
const int i12 = z % ne12;
|
|
90
|
+
|
|
91
|
+
if (i00 >= ne00) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const int i01 = src1[i10*s10 + i11*s11 + i12*s12];
|
|
96
|
+
|
|
97
|
+
dst_t * dst_row = dst + i10*s1 + i11*s2 + i12*s3;
|
|
98
|
+
const src0_t * src0_row = (const src0_t *)((const char *) src0 + i01*nb01 + i11*nb02 + i12*nb03);
|
|
99
|
+
|
|
100
|
+
dst_row[i00] = ggml_cuda_cast<dst_t>(src0_row[i00]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
template<typename grad_t, typename dst_t>
|
|
106
|
+
static __global__ void k_get_rows_back_float(
|
|
107
|
+
const grad_t * __restrict__ grad, const int32_t * __restrict__ rows, dst_t * __restrict__ dst, const int64_t ncols, const int64_t nrows_grad) {
|
|
108
|
+
const int col = blockIdx.x*blockDim.x + threadIdx.x;
|
|
109
|
+
|
|
110
|
+
if (col >= ncols) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const int dst_row = blockIdx.y*blockDim.y + threadIdx.y;
|
|
115
|
+
|
|
116
|
+
float sum = 0.0f;
|
|
117
|
+
|
|
118
|
+
for (int64_t i = 0; i < nrows_grad; ++i) {
|
|
119
|
+
if (rows[i] != dst_row) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
sum += grad[i*ncols + col];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
dst[dst_row*ncols + col] = sum;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
template<int qk, int qr, dequantize_kernel_t dq, typename dst_t>
|
|
129
|
+
static void get_rows_cuda_q(
|
|
130
|
+
const void * src0_d, const int32_t * src1_d, dst_t * dst_d,
|
|
131
|
+
const int64_t ne00, const size_t nb01, const size_t nb02, const size_t nb03,
|
|
132
|
+
const int64_t ne10, const int64_t ne11, const int64_t ne12, const size_t nb10, const size_t nb11, const size_t nb12,
|
|
133
|
+
const size_t nb1, const size_t nb2, const size_t nb3,
|
|
134
|
+
cudaStream_t stream) {
|
|
135
|
+
const dim3 block_dims(CUDA_GET_ROWS_BLOCK_SIZE, 1, 1);
|
|
136
|
+
const int block_num_y = (ne00 + 2*CUDA_GET_ROWS_BLOCK_SIZE - 1) / (2*CUDA_GET_ROWS_BLOCK_SIZE);
|
|
137
|
+
const dim3 block_nums(ne10, MIN(block_num_y, UINT16_MAX), MIN(ne11*ne12, UINT16_MAX));
|
|
138
|
+
|
|
139
|
+
// strides in elements
|
|
140
|
+
// const size_t s0 = nb0 / sizeof(dst_t);
|
|
141
|
+
const size_t s1 = nb1 / sizeof(dst_t);
|
|
142
|
+
const size_t s2 = nb2 / sizeof(dst_t);
|
|
143
|
+
const size_t s3 = nb3 / sizeof(dst_t);
|
|
144
|
+
|
|
145
|
+
const size_t s10 = nb10 / sizeof(int32_t);
|
|
146
|
+
const size_t s11 = nb11 / sizeof(int32_t);
|
|
147
|
+
const size_t s12 = nb12 / sizeof(int32_t);
|
|
148
|
+
// const size_t s13 = nb13 / sizeof(int32_t);
|
|
149
|
+
|
|
150
|
+
GGML_ASSERT(ne00 % 2 == 0);
|
|
151
|
+
|
|
152
|
+
k_get_rows<qk, qr, dq><<<block_nums, block_dims, 0, stream>>>(
|
|
153
|
+
src0_d, src1_d, dst_d,
|
|
154
|
+
ne00, /*ne01, ne02, ne03,*/
|
|
155
|
+
/*ne10,*/ ne11, ne12, /*ne13,*/
|
|
156
|
+
/* s0,*/ s1, s2, s3,
|
|
157
|
+
/* nb00,*/ nb01, nb02, nb03,
|
|
158
|
+
s10, s11, s12/*, s13*/);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
template<typename src0_t, typename dst_t>
|
|
162
|
+
static void get_rows_cuda_float(
|
|
163
|
+
const src0_t * src0_d, const int32_t * src1_d, dst_t * dst_d,
|
|
164
|
+
const int64_t ne00, const size_t nb01, const size_t nb02, const size_t nb03,
|
|
165
|
+
const int64_t ne10, const int64_t ne11, const int64_t ne12, const size_t nb10, const size_t nb11, const size_t nb12,
|
|
166
|
+
const size_t nb1, const size_t nb2, const size_t nb3,
|
|
167
|
+
cudaStream_t stream) {
|
|
168
|
+
const dim3 block_dims(CUDA_GET_ROWS_BLOCK_SIZE, 1, 1);
|
|
169
|
+
const int block_num_y = (ne00 + CUDA_GET_ROWS_BLOCK_SIZE - 1) / CUDA_GET_ROWS_BLOCK_SIZE;
|
|
170
|
+
const dim3 block_nums(ne10, MIN(block_num_y, UINT16_MAX), MIN(ne11*ne12, UINT16_MAX));
|
|
171
|
+
|
|
172
|
+
// strides in elements
|
|
173
|
+
// const size_t s0 = nb0 / sizeof(dst_t);
|
|
174
|
+
const size_t s1 = nb1 / sizeof(dst_t);
|
|
175
|
+
const size_t s2 = nb2 / sizeof(dst_t);
|
|
176
|
+
const size_t s3 = nb3 / sizeof(dst_t);
|
|
177
|
+
|
|
178
|
+
const size_t s10 = nb10 / sizeof(int32_t);
|
|
179
|
+
const size_t s11 = nb11 / sizeof(int32_t);
|
|
180
|
+
const size_t s12 = nb12 / sizeof(int32_t);
|
|
181
|
+
// const size_t s13 = nb13 / sizeof(int32_t);
|
|
182
|
+
|
|
183
|
+
k_get_rows_float<<<block_nums, block_dims, 0, stream>>>(
|
|
184
|
+
src0_d, src1_d, dst_d,
|
|
185
|
+
ne00, /*ne01, ne02, ne03,*/
|
|
186
|
+
/*ne10,*/ ne11, ne12, /*ne13,*/
|
|
187
|
+
/* s0,*/ s1, s2, s3,
|
|
188
|
+
/* nb00,*/ nb01, nb02, nb03,
|
|
189
|
+
s10, s11, s12/*, s13*/);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
template <typename dst_t>
|
|
193
|
+
static void ggml_cuda_get_rows_switch_src0_type(
|
|
194
|
+
const void * src0_d, const ggml_type src0_type, const int32_t * src1_d, dst_t * dst_d,
|
|
195
|
+
const int64_t ne00, const size_t nb01, const size_t nb02, const size_t nb03,
|
|
196
|
+
const int64_t ne10, const int64_t ne11, const int64_t ne12, const size_t nb10, const size_t nb11, const size_t nb12,
|
|
197
|
+
const size_t nb1, const size_t nb2, const size_t nb3,
|
|
198
|
+
cudaStream_t stream) {
|
|
199
|
+
switch (src0_type) {
|
|
200
|
+
case GGML_TYPE_F16:
|
|
201
|
+
get_rows_cuda_float((const half *) src0_d, src1_d, dst_d,
|
|
202
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
203
|
+
break;
|
|
204
|
+
case GGML_TYPE_F32:
|
|
205
|
+
get_rows_cuda_float((const float *) src0_d, src1_d, dst_d,
|
|
206
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
207
|
+
break;
|
|
208
|
+
case GGML_TYPE_I32:
|
|
209
|
+
get_rows_cuda_float((const int32_t *) src0_d, src1_d, dst_d,
|
|
210
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
211
|
+
break;
|
|
212
|
+
case GGML_TYPE_BF16:
|
|
213
|
+
get_rows_cuda_float((const nv_bfloat16 *) src0_d, src1_d, dst_d,
|
|
214
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
215
|
+
break;
|
|
216
|
+
case GGML_TYPE_Q1_0:
|
|
217
|
+
get_rows_cuda_q<QK1_0, QR1_0, dequantize_q1_0>(src0_d, src1_d, dst_d,
|
|
218
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
219
|
+
break;
|
|
220
|
+
case GGML_TYPE_Q4_0:
|
|
221
|
+
get_rows_cuda_q<QK4_0, QR4_0, dequantize_q4_0>(src0_d, src1_d, dst_d,
|
|
222
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
223
|
+
break;
|
|
224
|
+
case GGML_TYPE_Q4_1:
|
|
225
|
+
get_rows_cuda_q<QK4_1, QR4_1, dequantize_q4_1>(src0_d, src1_d, dst_d,
|
|
226
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
227
|
+
break;
|
|
228
|
+
case GGML_TYPE_Q5_0:
|
|
229
|
+
get_rows_cuda_q<QK5_0, QR5_0, dequantize_q5_0>(src0_d, src1_d, dst_d,
|
|
230
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
231
|
+
break;
|
|
232
|
+
case GGML_TYPE_Q5_1:
|
|
233
|
+
get_rows_cuda_q<QK5_1, QR5_1, dequantize_q5_1>(src0_d, src1_d, dst_d,
|
|
234
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
235
|
+
break;
|
|
236
|
+
case GGML_TYPE_Q8_0:
|
|
237
|
+
get_rows_cuda_q<QK8_0, QR8_0, dequantize_q8_0>(src0_d, src1_d, dst_d,
|
|
238
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
239
|
+
break;
|
|
240
|
+
default:
|
|
241
|
+
// k-quants and any other type with a to_fp32 dequantize path.
|
|
242
|
+
// Only available when dst_t is float (k-quant dequant always outputs F32).
|
|
243
|
+
if constexpr (std::is_same_v<dst_t, float>) {
|
|
244
|
+
if (ggml_get_to_fp32_cuda(src0_type) != nullptr) {
|
|
245
|
+
get_rows_cuda_kquant(src0_d, src0_type, src1_d, dst_d,
|
|
246
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
GGML_ABORT("%s: unsupported src0 type: %s\n", __func__, ggml_type_name(src0_type));
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
void get_rows_cuda(
|
|
256
|
+
const void * src0_d, ggml_type src0_type, const int32_t * src1_d, void * dst_d, ggml_type dst_type,
|
|
257
|
+
int64_t ne00, size_t nb01, size_t nb02, size_t nb03,
|
|
258
|
+
int64_t ne10, int64_t ne11, int64_t ne12, size_t nb10, size_t nb11, size_t nb12,
|
|
259
|
+
size_t nb1, size_t nb2, size_t nb3,
|
|
260
|
+
cudaStream_t stream) {
|
|
261
|
+
switch (dst_type) {
|
|
262
|
+
case GGML_TYPE_F32:
|
|
263
|
+
ggml_cuda_get_rows_switch_src0_type(src0_d, src0_type, src1_d, (float *) dst_d,
|
|
264
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
265
|
+
break;
|
|
266
|
+
case GGML_TYPE_I32:
|
|
267
|
+
ggml_cuda_get_rows_switch_src0_type(src0_d, src0_type, src1_d, (int32_t *) dst_d,
|
|
268
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
269
|
+
break;
|
|
270
|
+
case GGML_TYPE_F16:
|
|
271
|
+
ggml_cuda_get_rows_switch_src0_type(src0_d, src0_type, src1_d, (half *) dst_d,
|
|
272
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
273
|
+
break;
|
|
274
|
+
case GGML_TYPE_BF16:
|
|
275
|
+
ggml_cuda_get_rows_switch_src0_type(src0_d, src0_type, src1_d, (nv_bfloat16 *) dst_d,
|
|
276
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
277
|
+
break;
|
|
278
|
+
default:
|
|
279
|
+
GGML_ABORT("%s: unsupported dst type: %s\n", __func__, ggml_type_name(dst_type));
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
void ggml_cuda_op_get_rows(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
285
|
+
const ggml_tensor * src0 = dst->src[0];
|
|
286
|
+
const ggml_tensor * src1 = dst->src[1];
|
|
287
|
+
|
|
288
|
+
cudaStream_t stream = ctx.stream();
|
|
289
|
+
|
|
290
|
+
GGML_TENSOR_BINARY_OP_LOCALS
|
|
291
|
+
|
|
292
|
+
GGML_ASSERT(src1->type == GGML_TYPE_I32);
|
|
293
|
+
GGML_ASSERT(ne13 == 1);
|
|
294
|
+
|
|
295
|
+
GGML_ASSERT(src0->nb[0] == ggml_type_size(src0->type));
|
|
296
|
+
GGML_ASSERT(src1->nb[0] == ggml_type_size(src1->type));
|
|
297
|
+
GGML_ASSERT(dst->nb[0] == ggml_type_size(dst->type));
|
|
298
|
+
|
|
299
|
+
get_rows_cuda(src0->data, src0->type, (const int32_t *) src1->data, dst->data, dst->type,
|
|
300
|
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
void ggml_cuda_op_get_rows_back(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
304
|
+
const ggml_tensor * src0 = dst->src[0]; // gradients of forward pass output
|
|
305
|
+
const ggml_tensor * src1 = dst->src[1]; // src1 in forward pass
|
|
306
|
+
|
|
307
|
+
GGML_TENSOR_BINARY_OP_LOCALS
|
|
308
|
+
|
|
309
|
+
const float * src0_d = (const float *) src0->data;
|
|
310
|
+
const int32_t * src1_d = (const int32_t *) src1->data;
|
|
311
|
+
float * dst_d = (float *) dst->data;
|
|
312
|
+
|
|
313
|
+
cudaStream_t stream = ctx.stream();
|
|
314
|
+
|
|
315
|
+
GGML_ASSERT(src0->type == GGML_TYPE_F32);
|
|
316
|
+
GGML_ASSERT(src1->type == GGML_TYPE_I32);
|
|
317
|
+
GGML_ASSERT(dst->type == GGML_TYPE_F32);
|
|
318
|
+
|
|
319
|
+
GGML_ASSERT(ggml_is_contiguous(src0));
|
|
320
|
+
GGML_ASSERT(ggml_is_contiguous(src1));
|
|
321
|
+
GGML_ASSERT(ggml_is_contiguous(dst));
|
|
322
|
+
|
|
323
|
+
GGML_ASSERT(ne02*ne03 == 1);
|
|
324
|
+
GGML_ASSERT(ne12*ne13 == 1);
|
|
325
|
+
GGML_ASSERT(ne2*ne3 == 1);
|
|
326
|
+
|
|
327
|
+
const dim3 block_dims(CUDA_GET_ROWS_BACK_BLOCK_SIZE, 1, 1);
|
|
328
|
+
const int block_num_x = (ne00 + CUDA_GET_ROWS_BACK_BLOCK_SIZE - 1) / CUDA_GET_ROWS_BACK_BLOCK_SIZE;
|
|
329
|
+
const dim3 block_nums(block_num_x, ne1, 1);
|
|
330
|
+
|
|
331
|
+
k_get_rows_back_float<<<block_nums, block_dims, 0, stream>>>(src0_d, src1_d, dst_d, ne00, ne10);
|
|
332
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#include "common.cuh"
|
|
2
|
+
|
|
3
|
+
#define CUDA_GET_ROWS_BLOCK_SIZE 256
|
|
4
|
+
#define CUDA_GET_ROWS_BACK_BLOCK_SIZE 256
|
|
5
|
+
|
|
6
|
+
void get_rows_cuda(
|
|
7
|
+
const void * src0_d, ggml_type src0_type, const int32_t * src1_d, void * dst_d, ggml_type dst_type,
|
|
8
|
+
int64_t ne00, size_t nb01, size_t nb02, size_t nb03,
|
|
9
|
+
int64_t ne10, int64_t ne11, int64_t ne12, size_t nb10, size_t nb11, size_t nb12,
|
|
10
|
+
size_t nb1, size_t nb2, size_t nb3,
|
|
11
|
+
cudaStream_t stream);
|
|
12
|
+
|
|
13
|
+
void ggml_cuda_op_get_rows(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
14
|
+
|
|
15
|
+
void ggml_cuda_op_get_rows_back(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|