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,443 @@
|
|
|
1
|
+
#include "quantize.cuh"
|
|
2
|
+
#include <cstdint>
|
|
3
|
+
|
|
4
|
+
__launch_bounds__(CUDA_QUANTIZE_BLOCK_SIZE, 1)
|
|
5
|
+
static __global__ void quantize_q8_1(
|
|
6
|
+
const float * __restrict__ x, void * __restrict__ vy,
|
|
7
|
+
const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
|
8
|
+
const int64_t ne0, const uint32_t ne1, const uint3 ne2) {
|
|
9
|
+
const int64_t i0 = (int64_t)blockDim.x*blockIdx.x + threadIdx.x;
|
|
10
|
+
|
|
11
|
+
if (i0 >= ne0) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const int64_t i3 = fastdiv(blockIdx.z, ne2);
|
|
16
|
+
const int64_t i2 = blockIdx.z - i3*ne2.z;
|
|
17
|
+
const int64_t i1 = blockIdx.y;
|
|
18
|
+
|
|
19
|
+
const int64_t & i00 = i0;
|
|
20
|
+
const int64_t & i01 = i1;
|
|
21
|
+
const int64_t & i02 = i2;
|
|
22
|
+
const int64_t & i03 = i3;
|
|
23
|
+
|
|
24
|
+
const int64_t i_cont = ((i3*ne2.z + i2) * ne1 + i1) * ne0 + i0;
|
|
25
|
+
|
|
26
|
+
block_q8_1 * y = (block_q8_1 *) vy;
|
|
27
|
+
|
|
28
|
+
const int64_t ib = i_cont / QK8_1; // block index
|
|
29
|
+
const int64_t iqs = i_cont % QK8_1; // quant index
|
|
30
|
+
|
|
31
|
+
const float xi = i0 < ne00 ? x[i03*s03 + i02*s02 + i01*s01 + i00] : 0.0f;
|
|
32
|
+
float amax = fabsf(xi);
|
|
33
|
+
float sum = xi;
|
|
34
|
+
|
|
35
|
+
amax = warp_reduce_max<QK8_1>(amax);
|
|
36
|
+
sum = warp_reduce_sum<QK8_1>(sum);
|
|
37
|
+
|
|
38
|
+
const float d = amax / 127.0f;
|
|
39
|
+
const int8_t q = amax == 0.0f ? 0 : roundf(xi / d);
|
|
40
|
+
|
|
41
|
+
y[ib].qs[iqs] = q;
|
|
42
|
+
|
|
43
|
+
if (iqs > 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
y[ib].ds = make_half2(d, sum);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
__device__ __forceinline__ uint8_t compute_e8m0_scale(float amax) {
|
|
51
|
+
if (!(amax > 0.0f)) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// FP4 E2M1: max exponent (unbiased) is 2.
|
|
56
|
+
constexpr int FP4_E2M1_EMAX = 2;
|
|
57
|
+
|
|
58
|
+
const float e = log2f(amax);
|
|
59
|
+
|
|
60
|
+
// "even" -> round-to-nearest integer, ties-to-even
|
|
61
|
+
const int e_int = __float2int_rn(e);
|
|
62
|
+
|
|
63
|
+
const int shared_exp = e_int - FP4_E2M1_EMAX;
|
|
64
|
+
|
|
65
|
+
int biased = shared_exp + 127;
|
|
66
|
+
|
|
67
|
+
biased = max(biased, 0);
|
|
68
|
+
biased = min(biased, 254);
|
|
69
|
+
|
|
70
|
+
return static_cast<uint8_t>(biased);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
static __global__ void quantize_mmq_nvfp4(
|
|
75
|
+
const float * __restrict__ x, const int32_t * __restrict__ ids, void * __restrict__ vy,
|
|
76
|
+
const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
|
77
|
+
const int64_t ne0, const int64_t ne1, const int64_t ne2) {
|
|
78
|
+
#if defined(BLACKWELL_MMA_AVAILABLE)
|
|
79
|
+
|
|
80
|
+
const int64_t i0_base = ((int64_t) blockDim.x * blockIdx.y + threadIdx.x) * QK_NVFP4_SUB;
|
|
81
|
+
if (i0_base >= ne0) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const int64_t i1 = blockIdx.x;
|
|
86
|
+
const int64_t i2 = blockIdx.z % ne2;
|
|
87
|
+
const int64_t i3 = blockIdx.z / ne2;
|
|
88
|
+
const int64_t i01 = ids ? ids[i1] : i1;
|
|
89
|
+
const int64_t k_block = i0_base / QK_K;
|
|
90
|
+
const int64_t blocks_per_col = (ne0 + QK_K - 1) / QK_K;
|
|
91
|
+
if (k_block >= blocks_per_col) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const int64_t ib = blockIdx.z * ((int64_t) blocks_per_col * ne1) + k_block * ne1 + blockIdx.x;
|
|
96
|
+
block_fp4_mmq * y = (block_fp4_mmq *) vy;
|
|
97
|
+
block_fp4_mmq * yb = y + ib;
|
|
98
|
+
|
|
99
|
+
const int sub = (i0_base % QK_K) / QK_NVFP4_SUB;
|
|
100
|
+
|
|
101
|
+
float vals_raw[QK_NVFP4_SUB];
|
|
102
|
+
float amax_raw = 0.0f;
|
|
103
|
+
const int64_t base_idx = i3 * s03 + i2 * s02 + i01 * s01;
|
|
104
|
+
#pragma unroll
|
|
105
|
+
for (int k = 0; k < QK_NVFP4_SUB; k++) {
|
|
106
|
+
const int64_t i00 = i0_base + k;
|
|
107
|
+
if (i00 < ne00) {
|
|
108
|
+
const float v = x[base_idx + i00];
|
|
109
|
+
vals_raw[k] = v;
|
|
110
|
+
amax_raw = fmaxf(amax_raw, fabsf(v));
|
|
111
|
+
} else {
|
|
112
|
+
vals_raw[k] = 0.0f;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static constexpr int test_offsets[5] = { 0, -1, 1, -2, 2};
|
|
117
|
+
const int first_fp8_code = (int) ggml_cuda_fp32_to_ue4m3(amax_raw / 6.0f);
|
|
118
|
+
|
|
119
|
+
float best_err = FLT_MAX;
|
|
120
|
+
uint8_t fp8_code = 0;
|
|
121
|
+
float subblock_scale = 0.0f;
|
|
122
|
+
|
|
123
|
+
#pragma unroll // Check +/- 2 to find best code to reduce NVFP4 activation loss. Negligible overhead on Blackwell.
|
|
124
|
+
for (int i = 0; i < 5; i++) {
|
|
125
|
+
const int test_code = first_fp8_code + test_offsets[i];
|
|
126
|
+
if (test_code < 0 || test_code > 0x7e) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const uint8_t code = (uint8_t) test_code;
|
|
130
|
+
const float test_scale = ggml_cuda_ue4m3_to_fp32(code);
|
|
131
|
+
const float test_inv_scale = test_scale > 0.0f ? 0.5f / test_scale : 0.0f;
|
|
132
|
+
float cur_err = 0.0f;
|
|
133
|
+
#pragma unroll
|
|
134
|
+
for (int k = 0; k < QK_NVFP4_SUB; ++k) {
|
|
135
|
+
const float v = vals_raw[k];
|
|
136
|
+
const uint8_t q = ggml_cuda_float_to_fp4_e2m1(v, test_inv_scale);
|
|
137
|
+
const float err_diff = fabsf(v) - fabsf(kvalues_mxfp4[q & 0x7]) * test_scale;
|
|
138
|
+
cur_err = fmaf(err_diff, err_diff, cur_err);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (cur_err < best_err) {
|
|
142
|
+
best_err = cur_err;
|
|
143
|
+
fp8_code = test_code;
|
|
144
|
+
subblock_scale = test_scale;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const float inv_scale = subblock_scale > 0.0f ? 0.5f / subblock_scale : 0.0f;
|
|
149
|
+
uint32_t q0 = 0;
|
|
150
|
+
uint32_t q1 = 0;
|
|
151
|
+
#pragma unroll // this is faster than the previous __nv_fp4x4_e2m1
|
|
152
|
+
for (int k = 0; k < QK_NVFP4_SUB / 4; ++k) {
|
|
153
|
+
q0 |= (uint32_t) ggml_cuda_float_to_fp4_e2m1(vals_raw[k + 0], inv_scale) << (8 * k);
|
|
154
|
+
q0 |= (uint32_t) ggml_cuda_float_to_fp4_e2m1(vals_raw[k + 8], inv_scale) << (8 * k + 4);
|
|
155
|
+
q1 |= (uint32_t) ggml_cuda_float_to_fp4_e2m1(vals_raw[k + 4], inv_scale) << (8 * k);
|
|
156
|
+
q1 |= (uint32_t) ggml_cuda_float_to_fp4_e2m1(vals_raw[k + 12], inv_scale) << (8 * k + 4);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
uint32_t * yqs = reinterpret_cast<uint32_t *>(yb->qs);
|
|
160
|
+
yqs[2 * sub + 0] = q0;
|
|
161
|
+
yqs[2 * sub + 1] = q1;
|
|
162
|
+
reinterpret_cast<uint8_t *>(yb->d4)[sub] = fp8_code;
|
|
163
|
+
#else
|
|
164
|
+
NO_DEVICE_CODE; // This is for Blackwell NVFP4 activations only.
|
|
165
|
+
#endif // defined(BLACKWELL_MMA_AVAILABLE)
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// quantize values in the format mxfp4 is stored which is interleaved nibbles
|
|
170
|
+
// i.e. a block a0-a31 is represented as a0a16,a1a17 ...a15a31
|
|
171
|
+
static __global__ void quantize_mmq_mxfp4(const float * __restrict__ x,
|
|
172
|
+
const int32_t * __restrict__ ids,
|
|
173
|
+
void * __restrict__ vy,
|
|
174
|
+
const int64_t ne00,
|
|
175
|
+
const int64_t s01,
|
|
176
|
+
const int64_t s02,
|
|
177
|
+
const int64_t s03,
|
|
178
|
+
const int64_t ne0,
|
|
179
|
+
const int ne1,
|
|
180
|
+
const int ne2) {
|
|
181
|
+
constexpr int vals_per_scale = 32;
|
|
182
|
+
constexpr int vals_per_warp = 2 * vals_per_scale; // Each warp processes 2 blocks of 32 = 64 values
|
|
183
|
+
|
|
184
|
+
const int warp_id = threadIdx.y;
|
|
185
|
+
const int lane_id_32 = threadIdx.x;
|
|
186
|
+
|
|
187
|
+
const int nwarps = blockDim.y;
|
|
188
|
+
|
|
189
|
+
const int64_t warp_start_offset = (blockIdx.y * nwarps + warp_id) * vals_per_warp;
|
|
190
|
+
|
|
191
|
+
if (warp_start_offset >= ne0) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const int64_t i1 = blockIdx.x;
|
|
196
|
+
const int64_t i2 = blockIdx.z % ne2;
|
|
197
|
+
const int64_t i3 = blockIdx.z / ne2;
|
|
198
|
+
|
|
199
|
+
const int64_t i01 = ids ? ids[i1] : i1;
|
|
200
|
+
const int64_t i02 = i2;
|
|
201
|
+
const int64_t i03 = i3;
|
|
202
|
+
|
|
203
|
+
block_fp4_mmq * y = (block_fp4_mmq *) vy;
|
|
204
|
+
|
|
205
|
+
const int64_t block_fp4_mmq_size = 8 * QK_MXFP4; // 256 values
|
|
206
|
+
const int64_t ib0 = blockIdx.z * ((int64_t) ne1 * (ne0 / block_fp4_mmq_size));
|
|
207
|
+
const int64_t ib = ib0 + (warp_start_offset / block_fp4_mmq_size) * ne1 + blockIdx.x;
|
|
208
|
+
const int64_t quad_idx_in_block = (warp_start_offset % block_fp4_mmq_size) / vals_per_warp;
|
|
209
|
+
|
|
210
|
+
const int group_id = lane_id_32 / 4;
|
|
211
|
+
const int lane_in_group = lane_id_32 % 4;
|
|
212
|
+
const int base = group_id * 2;
|
|
213
|
+
char2 * yqs2 = (char2 *) y[ib].qs;
|
|
214
|
+
|
|
215
|
+
const int64_t base_pos = i03 * s03 + i02 * s02 + i01 * s01;
|
|
216
|
+
|
|
217
|
+
uint8_t scales[2];
|
|
218
|
+
|
|
219
|
+
#pragma unroll
|
|
220
|
+
for (int b = 0; b < 2; ++b) {
|
|
221
|
+
const int64_t i0 = warp_start_offset + b * vals_per_scale + lane_id_32;
|
|
222
|
+
const float xi = (i0 < ne00) ? x[base_pos + i0] : 0.0f;
|
|
223
|
+
|
|
224
|
+
float amax = fabsf(xi);
|
|
225
|
+
#pragma unroll
|
|
226
|
+
for (int mask = 16; mask > 0; mask >>= 1) {
|
|
227
|
+
amax = fmaxf(amax, __shfl_xor_sync(0xFFFFFFFF, amax, mask, WARP_SIZE));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const uint8_t e = compute_e8m0_scale(amax);
|
|
231
|
+
scales[b] = e;
|
|
232
|
+
const float inv_s = (amax == 0.0f) ? 0.0f : __frcp_rn(ggml_cuda_e8m0_to_fp32(e));
|
|
233
|
+
|
|
234
|
+
#if CUDART_VERSION >= 12080
|
|
235
|
+
const float scaled_val = xi * inv_s;
|
|
236
|
+
|
|
237
|
+
const float val0 = __shfl_sync(0xFFFFFFFF, scaled_val, base, WARP_SIZE);
|
|
238
|
+
const float val1 = __shfl_sync(0xFFFFFFFF, scaled_val, base + 16, WARP_SIZE);
|
|
239
|
+
const float val2 = __shfl_sync(0xFFFFFFFF, scaled_val, base + 1, WARP_SIZE);
|
|
240
|
+
const float val3 = __shfl_sync(0xFFFFFFFF, scaled_val, base + 17, WARP_SIZE);
|
|
241
|
+
|
|
242
|
+
if (lane_in_group == 0) {
|
|
243
|
+
__nv_fp4x4_e2m1 fp4_packed(make_float4(val0, val1, val2, val3));
|
|
244
|
+
|
|
245
|
+
yqs2[quad_idx_in_block * 16 + b * 8 + group_id] = *(char2 *) &fp4_packed;
|
|
246
|
+
}
|
|
247
|
+
#else
|
|
248
|
+
// Fallback: manual FP4 conversion using LUT
|
|
249
|
+
const uint8_t q_val = ggml_cuda_float_to_fp4_e2m1(xi, inv_s);
|
|
250
|
+
|
|
251
|
+
const uint8_t q_lo_0 = __shfl_sync(0xFFFFFFFF, q_val, base, WARP_SIZE);
|
|
252
|
+
const uint8_t q_lo_1 = __shfl_sync(0xFFFFFFFF, q_val, base + 1, WARP_SIZE);
|
|
253
|
+
const uint8_t q_hi_0 = __shfl_sync(0xFFFFFFFF, q_val, base + 16, WARP_SIZE);
|
|
254
|
+
const uint8_t q_hi_1 = __shfl_sync(0xFFFFFFFF, q_val, base + 17, WARP_SIZE);
|
|
255
|
+
|
|
256
|
+
if (lane_in_group == 0) {
|
|
257
|
+
char2 q;
|
|
258
|
+
q.x = (q_hi_0 << 4) | q_lo_0;
|
|
259
|
+
q.y = (q_hi_1 << 4) | q_lo_1;
|
|
260
|
+
yqs2[quad_idx_in_block * 16 + b * 8 + group_id] = q;
|
|
261
|
+
}
|
|
262
|
+
#endif // CUDART_VERSION >= 12080
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (lane_id_32 == 0) {
|
|
266
|
+
// Store 2 scales packed into 1 uint32
|
|
267
|
+
y[ib].d4[quad_idx_in_block] = (scales[1] << 8) | scales[0];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
template <mmq_q8_1_ds_layout ds_layout>
|
|
272
|
+
static __global__ void quantize_mmq_q8_1(
|
|
273
|
+
const float * __restrict__ x, const int32_t * __restrict__ ids, void * __restrict__ vy,
|
|
274
|
+
const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
|
275
|
+
const int64_t ne0, const int ne1, const int ne2) {
|
|
276
|
+
|
|
277
|
+
constexpr int vals_per_scale = ds_layout == MMQ_Q8_1_DS_LAYOUT_D2S6 ? 64 : 32;
|
|
278
|
+
constexpr int vals_per_sum = ds_layout == MMQ_Q8_1_DS_LAYOUT_D2S6 ? 16 : 32;
|
|
279
|
+
|
|
280
|
+
const int64_t i0 = ((int64_t)blockDim.x*blockIdx.y + threadIdx.x)*4;
|
|
281
|
+
|
|
282
|
+
if (i0 >= ne0) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const int64_t i1 = blockIdx.x;
|
|
287
|
+
const int64_t i2 = blockIdx.z % ne2;
|
|
288
|
+
const int64_t i3 = blockIdx.z / ne2;
|
|
289
|
+
|
|
290
|
+
const int64_t i00 = i0;
|
|
291
|
+
const int64_t i01 = ids ? ids[i1] : i1;
|
|
292
|
+
const int64_t i02 = i2;
|
|
293
|
+
const int64_t i03 = i3;
|
|
294
|
+
|
|
295
|
+
const float4 * x4 = (const float4 *) x;
|
|
296
|
+
|
|
297
|
+
block_q8_1_mmq * y = (block_q8_1_mmq *) vy;
|
|
298
|
+
|
|
299
|
+
const int64_t ib0 = blockIdx.z*((int64_t)gridDim.x*gridDim.y*blockDim.x/QK8_1); // first block of channel
|
|
300
|
+
const int64_t ib = ib0 + (i0 / (4*QK8_1))*ne1 + blockIdx.x; // block index in channel
|
|
301
|
+
const int64_t iqs = i0 % (4*QK8_1); // quant index in block
|
|
302
|
+
|
|
303
|
+
// Load 4 floats per thread and calculate max. abs. value between them:
|
|
304
|
+
const float4 xi = i0 < ne00 ? x4[(i03*s03 + i02*s02 + i01*s01 + i00)/4] : make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
305
|
+
float amax = fabsf(xi.x);
|
|
306
|
+
amax = fmaxf(amax, fabsf(xi.y));
|
|
307
|
+
amax = fmaxf(amax, fabsf(xi.z));
|
|
308
|
+
amax = fmaxf(amax, fabsf(xi.w));
|
|
309
|
+
|
|
310
|
+
// Exchange max. abs. value between vals_per_scale/4 threads.
|
|
311
|
+
#pragma unroll
|
|
312
|
+
for (int offset = vals_per_scale/8; offset > 0; offset >>= 1) {
|
|
313
|
+
amax = fmaxf(amax, __shfl_xor_sync(0xFFFFFFFF, amax, offset, WARP_SIZE));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
float sum;
|
|
317
|
+
if (ds_layout != MMQ_Q8_1_DS_LAYOUT_D4) {
|
|
318
|
+
sum = xi.x + xi.y + xi.z + xi.w;
|
|
319
|
+
|
|
320
|
+
// Calculate sums across vals_per_sum/4 threads.
|
|
321
|
+
#pragma unroll
|
|
322
|
+
for (int offset = vals_per_sum/8; offset > 0; offset >>= 1) {
|
|
323
|
+
sum += __shfl_xor_sync(0xFFFFFFFF, sum, offset, WARP_SIZE);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const float d_inv = 127.0f / amax;
|
|
328
|
+
char4 q;
|
|
329
|
+
q.x = roundf(xi.x*d_inv);
|
|
330
|
+
q.y = roundf(xi.y*d_inv);
|
|
331
|
+
q.z = roundf(xi.z*d_inv);
|
|
332
|
+
q.w = roundf(xi.w*d_inv);
|
|
333
|
+
|
|
334
|
+
// Write back 4 int8 values as a single 32 bit value for better memory bandwidth:
|
|
335
|
+
char4 * yqs4 = (char4 *) y[ib].qs;
|
|
336
|
+
yqs4[iqs/4] = q;
|
|
337
|
+
|
|
338
|
+
if (ds_layout == MMQ_Q8_1_DS_LAYOUT_D2S6) {
|
|
339
|
+
if (iqs % 16 != 0 || iqs >= 96) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
y[ib].d2s6[2 + iqs/16] = sum;
|
|
344
|
+
|
|
345
|
+
if (iqs % 64 != 0) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const float d = 1.0f / d_inv;
|
|
350
|
+
|
|
351
|
+
y[ib].d2s6[iqs/64] = d;
|
|
352
|
+
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (iqs % 32 != 0) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const float d = 1.0f / d_inv;
|
|
361
|
+
|
|
362
|
+
if (ds_layout == MMQ_Q8_1_DS_LAYOUT_DS4) {
|
|
363
|
+
y[ib].ds4[iqs/32] = make_half2(d, sum);
|
|
364
|
+
} else {
|
|
365
|
+
y[ib].d4[iqs/32] = d;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
void quantize_row_q8_1_cuda(
|
|
370
|
+
const float * x, const int32_t * ids, void * vy, const ggml_type type_src0,
|
|
371
|
+
const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
|
372
|
+
const int64_t ne0, const int64_t ne1, const int64_t ne2, const int64_t ne3, cudaStream_t stream) {
|
|
373
|
+
GGML_ASSERT(!ids);
|
|
374
|
+
GGML_ASSERT(ne0 % QK8_1 == 0);
|
|
375
|
+
|
|
376
|
+
const uint3 ne2_fastdiv = init_fastdiv_values(ne2);
|
|
377
|
+
|
|
378
|
+
const int64_t block_num_x = (ne0 + CUDA_QUANTIZE_BLOCK_SIZE - 1) / CUDA_QUANTIZE_BLOCK_SIZE;
|
|
379
|
+
const dim3 num_blocks(block_num_x, ne1, ne2*ne3);
|
|
380
|
+
const dim3 block_size(CUDA_QUANTIZE_BLOCK_SIZE, 1, 1);
|
|
381
|
+
quantize_q8_1<<<num_blocks, block_size, 0, stream>>>(x, vy, ne00, s01, s02, s03, ne0, ne1, ne2_fastdiv);
|
|
382
|
+
GGML_UNUSED(type_src0);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
void quantize_mmq_q8_1_cuda(
|
|
386
|
+
const float * x, const int32_t * ids, void * vy, const ggml_type type_src0,
|
|
387
|
+
const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
|
388
|
+
const int64_t ne0, const int64_t ne1, const int64_t ne2, const int64_t ne3, cudaStream_t stream) {
|
|
389
|
+
GGML_ASSERT(ne00 % 4 == 0);
|
|
390
|
+
GGML_ASSERT(ne0 % (4*QK8_1) == 0);
|
|
391
|
+
|
|
392
|
+
// ne1 tends to assume the highest values, therefore use it as the "x" dimension of the CUDA grid:
|
|
393
|
+
const int64_t block_num_y = (ne0 + 4*CUDA_QUANTIZE_BLOCK_SIZE_MMQ - 1) / (4*CUDA_QUANTIZE_BLOCK_SIZE_MMQ);
|
|
394
|
+
const dim3 num_blocks(ne1, block_num_y, ne2*ne3);
|
|
395
|
+
const dim3 block_size(CUDA_QUANTIZE_BLOCK_SIZE_MMQ, 1, 1);
|
|
396
|
+
switch (mmq_get_q8_1_ds_layout(type_src0)) {
|
|
397
|
+
case MMQ_Q8_1_DS_LAYOUT_D4:
|
|
398
|
+
quantize_mmq_q8_1<MMQ_Q8_1_DS_LAYOUT_D4>
|
|
399
|
+
<<<num_blocks, block_size, 0, stream>>>(x, ids, vy, ne00, s01, s02, s03, ne0, ne1, ne2);
|
|
400
|
+
break;
|
|
401
|
+
case MMQ_Q8_1_DS_LAYOUT_DS4:
|
|
402
|
+
quantize_mmq_q8_1<MMQ_Q8_1_DS_LAYOUT_DS4>
|
|
403
|
+
<<<num_blocks, block_size, 0, stream>>>(x, ids, vy, ne00, s01, s02, s03, ne0, ne1, ne2);
|
|
404
|
+
break;
|
|
405
|
+
case MMQ_Q8_1_DS_LAYOUT_D2S6:
|
|
406
|
+
quantize_mmq_q8_1<MMQ_Q8_1_DS_LAYOUT_D2S6>
|
|
407
|
+
<<<num_blocks, block_size, 0, stream>>>(x, ids, vy, ne00, s01, s02, s03, ne0, ne1, ne2);
|
|
408
|
+
break;
|
|
409
|
+
default:
|
|
410
|
+
GGML_ABORT("fatal error");
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
void quantize_mmq_fp4_cuda(
|
|
416
|
+
const float * x, const int32_t * ids, void * vy, const ggml_type type_src0,
|
|
417
|
+
const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
|
418
|
+
const int64_t ne0, const int64_t ne1, const int64_t ne2, const int64_t ne3, cudaStream_t stream) {
|
|
419
|
+
GGML_ASSERT(type_src0 == GGML_TYPE_MXFP4 || type_src0 == GGML_TYPE_NVFP4);
|
|
420
|
+
GGML_ASSERT(ne0 > 0);
|
|
421
|
+
|
|
422
|
+
if (type_src0 == GGML_TYPE_NVFP4) {
|
|
423
|
+
GGML_ASSERT(ne00 % QK_NVFP4 == 0);
|
|
424
|
+
constexpr int nvfp4_block_size = 128;
|
|
425
|
+
const int64_t block_num_y = (ne0 + QK_NVFP4_SUB * nvfp4_block_size - 1) / (QK_NVFP4_SUB * nvfp4_block_size);
|
|
426
|
+
const dim3 block_size(nvfp4_block_size, 1, 1);
|
|
427
|
+
const dim3 num_blocks(ne1, block_num_y, ne2 * ne3);
|
|
428
|
+
quantize_mmq_nvfp4<<<num_blocks, block_size, 0, stream>>>(
|
|
429
|
+
x, ids, vy, ne00, s01, s02, s03, ne0, ne1, ne2);
|
|
430
|
+
} else {
|
|
431
|
+
GGML_ASSERT(ne0 % (2 * QK_MXFP4) == 0);
|
|
432
|
+
|
|
433
|
+
constexpr int nwarps = 8;
|
|
434
|
+
constexpr int vals_per_warp = 2 * QK_MXFP4;
|
|
435
|
+
constexpr int vals_per_block = nwarps * vals_per_warp;
|
|
436
|
+
|
|
437
|
+
const int64_t block_num_y = (ne0 + vals_per_block - 1) / vals_per_block;
|
|
438
|
+
const dim3 num_blocks(ne1, block_num_y, ne2 * ne3);
|
|
439
|
+
const dim3 block_size(WARP_SIZE, nwarps, 1);
|
|
440
|
+
|
|
441
|
+
quantize_mmq_mxfp4<<<num_blocks, block_size, 0, stream>>>(x, ids, vy, ne00, s01, s02, s03, ne0, ne1, ne2);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "common.cuh"
|
|
4
|
+
#include "mmq.cuh"
|
|
5
|
+
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
|
|
8
|
+
#define CUDA_QUANTIZE_BLOCK_SIZE 256
|
|
9
|
+
#define CUDA_QUANTIZE_BLOCK_SIZE_MMQ 128
|
|
10
|
+
|
|
11
|
+
static_assert(MATRIX_ROW_PADDING % CUDA_QUANTIZE_BLOCK_SIZE == 0, "Risk of out-of-bounds access.");
|
|
12
|
+
static_assert(MATRIX_ROW_PADDING % (4*CUDA_QUANTIZE_BLOCK_SIZE_MMQ) == 0, "Risk of out-of-bounds access.");
|
|
13
|
+
|
|
14
|
+
typedef void (*quantize_cuda_t)(
|
|
15
|
+
const float * x, const int32_t * ids, void * vy,
|
|
16
|
+
ggml_type type_src0, int64_t ne00, int64_t s01, int64_t s02, int64_t s03,
|
|
17
|
+
int64_t ne0, int64_t ne1, int64_t ne2, int64_t ne3, cudaStream_t stream);
|
|
18
|
+
|
|
19
|
+
void quantize_row_q8_1_cuda(
|
|
20
|
+
const float * x, const int32_t * ids, void * vy,
|
|
21
|
+
ggml_type type_src0, int64_t ne00, int64_t s01, int64_t s02, int64_t s03,
|
|
22
|
+
int64_t ne0, int64_t ne1, int64_t ne2, int64_t ne3, cudaStream_t stream);
|
|
23
|
+
|
|
24
|
+
void quantize_mmq_q8_1_cuda(
|
|
25
|
+
const float * x, const int32_t * ids, void * vy,
|
|
26
|
+
ggml_type type_src0, int64_t ne00, int64_t s01, int64_t s02, int64_t s03,
|
|
27
|
+
int64_t ne0, int64_t ne1, int64_t ne2, int64_t ne3, cudaStream_t stream);
|
|
28
|
+
|
|
29
|
+
void quantize_mmq_fp4_cuda(const float * x,
|
|
30
|
+
const int32_t * ids,
|
|
31
|
+
void * vy,
|
|
32
|
+
ggml_type type_src0,
|
|
33
|
+
int64_t ne00,
|
|
34
|
+
int64_t s01,
|
|
35
|
+
int64_t s02,
|
|
36
|
+
int64_t s03,
|
|
37
|
+
int64_t ne0,
|
|
38
|
+
int64_t ne1,
|
|
39
|
+
int64_t ne2,
|
|
40
|
+
int64_t ne3,
|
|
41
|
+
cudaStream_t stream);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#include "common.cuh"
|
|
2
|
+
|
|
3
|
+
// Row reduction kernel template - compute sum (norm=false) or mean (norm=true)
|
|
4
|
+
template <bool norm>
|
|
5
|
+
static __global__ void reduce_rows_f32(const float * __restrict__ x, float * __restrict__ dst, const int ncols) {
|
|
6
|
+
const int row = blockIdx.x;
|
|
7
|
+
const int col = threadIdx.x;
|
|
8
|
+
|
|
9
|
+
float sum = 0.0f;
|
|
10
|
+
const int num_unroll = 8;
|
|
11
|
+
float temp[num_unroll];
|
|
12
|
+
float sum_temp[num_unroll] = { 0.0f };
|
|
13
|
+
for (int i = col; i < ncols;) {
|
|
14
|
+
for (int j = 0; j < num_unroll; ++j) {
|
|
15
|
+
if (i < ncols) {
|
|
16
|
+
temp[j] = x[row * ncols + i];
|
|
17
|
+
} else {
|
|
18
|
+
temp[j] = 0;
|
|
19
|
+
}
|
|
20
|
+
i += blockDim.x;
|
|
21
|
+
}
|
|
22
|
+
for (int j = 0; j < num_unroll; ++j) {
|
|
23
|
+
sum_temp[j] += temp[j];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (int j = 0; j < num_unroll; ++j) {
|
|
27
|
+
sum += sum_temp[j];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// sum up partial sums
|
|
31
|
+
__shared__ float shared_vals[32];
|
|
32
|
+
sum = block_reduce<block_reduce_method::SUM>(sum, shared_vals);
|
|
33
|
+
|
|
34
|
+
if (col != 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
dst[row] = norm ? sum / ncols : sum;
|
|
39
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#include "ggml-cuda/common.cuh"
|
|
2
|
+
#include "roll.cuh"
|
|
3
|
+
|
|
4
|
+
static __forceinline__ __device__ int64_t wrap_index(const int64_t idx, const int64_t ne) {
|
|
5
|
+
if (idx < 0) {
|
|
6
|
+
return idx + ne;
|
|
7
|
+
}
|
|
8
|
+
if (idx >= ne) {
|
|
9
|
+
return idx - ne;
|
|
10
|
+
}
|
|
11
|
+
return idx;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static __global__ void roll_f32_cuda(const float * __restrict__ src,
|
|
15
|
+
float * __restrict__ dst,
|
|
16
|
+
const int64_t ne00,
|
|
17
|
+
const int64_t ne01,
|
|
18
|
+
const int64_t ne02,
|
|
19
|
+
const int64_t ne03,
|
|
20
|
+
const int s0,
|
|
21
|
+
const int s1,
|
|
22
|
+
const int s2,
|
|
23
|
+
const int s3) {
|
|
24
|
+
const int64_t idx = int64_t(blockDim.x) * blockIdx.x + threadIdx.x;
|
|
25
|
+
const int64_t n_elements = ne00 * ne01 * ne02 * ne03;
|
|
26
|
+
|
|
27
|
+
if (idx >= n_elements) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const int64_t i0 = idx % ne00;
|
|
32
|
+
const int64_t i1 = (idx / ne00) % ne01;
|
|
33
|
+
const int64_t i2 = (idx / (ne00 * ne01)) % ne02;
|
|
34
|
+
const int64_t i3 = (idx / (ne00 * ne01 * ne02)) % ne03;
|
|
35
|
+
|
|
36
|
+
const int64_t d0 = wrap_index(i0 - s0, ne00);
|
|
37
|
+
const int64_t d1 = wrap_index(i1 - s1, ne01);
|
|
38
|
+
const int64_t d2 = wrap_index(i2 - s2, ne02);
|
|
39
|
+
const int64_t d3 = wrap_index(i3 - s3, ne03);
|
|
40
|
+
|
|
41
|
+
dst[i3 * (ne00 * ne01 * ne02) + i2 * (ne01 * ne00) + i1 * ne00 + i0] =
|
|
42
|
+
src[d3 * (ne00 * ne01 * ne02) + d2 * (ne01 * ne00) + d1 * ne00 + d0];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void ggml_cuda_op_roll(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
46
|
+
int s0 = dst->op_params[0];
|
|
47
|
+
int s1 = dst->op_params[1];
|
|
48
|
+
int s2 = dst->op_params[2];
|
|
49
|
+
int s3 = dst->op_params[3];
|
|
50
|
+
|
|
51
|
+
const ggml_tensor * src0 = dst->src[0];
|
|
52
|
+
const float * src0_d = (const float *) dst->src[0]->data;
|
|
53
|
+
float * dst_d = (float *) dst->data;
|
|
54
|
+
|
|
55
|
+
GGML_TENSOR_UNARY_OP_LOCALS;
|
|
56
|
+
|
|
57
|
+
GGML_ASSERT(dst->src[0]->type == GGML_TYPE_F32);
|
|
58
|
+
GGML_ASSERT(ggml_are_same_shape(dst->src[0], dst));
|
|
59
|
+
|
|
60
|
+
cudaStream_t stream = ctx.stream();
|
|
61
|
+
|
|
62
|
+
int64_t sz = (ne00 * ne01 * ne02 * ne03);
|
|
63
|
+
int64_t num_blocks = (sz + CUDA_ROLL_BLOCK_SIZE - 1) / CUDA_ROLL_BLOCK_SIZE;
|
|
64
|
+
|
|
65
|
+
roll_f32_cuda<<<num_blocks, CUDA_ROLL_BLOCK_SIZE, 0, stream>>>(
|
|
66
|
+
src0_d, dst_d, ne00, ne01, ne02, ne03, s0, s1, s2, s3);
|
|
67
|
+
}
|