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.
Files changed (480) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +21 -0
  3. data/LICENSE.txt +201 -0
  4. data/NOTICE +5 -0
  5. data/README.md +265 -0
  6. data/THIRD_PARTY_NOTICES.md +67 -0
  7. data/exe/cohere-transcribe +8 -0
  8. data/exe/cohere-transcribe-doctor +8 -0
  9. data/ext/cohere_transcribe_native/CMakeLists.txt +262 -0
  10. data/ext/cohere_transcribe_native/README.md +26 -0
  11. data/ext/cohere_transcribe_native/audio_abi.cpp +1416 -0
  12. data/ext/cohere_transcribe_native/audio_exports.macos +5 -0
  13. data/ext/cohere_transcribe_native/audio_exports.map +10 -0
  14. data/ext/cohere_transcribe_native/cohere_abi.cpp +1209 -0
  15. data/ext/cohere_transcribe_native/exports.macos +40 -0
  16. data/ext/cohere_transcribe_native/exports.map +45 -0
  17. data/ext/cohere_transcribe_native/extconf.rb +89 -0
  18. data/ext/cohere_transcribe_native/test/abi_smoke.rb +232 -0
  19. data/ext/cohere_transcribe_native/test/audio_matrix_smoke.cpp +121 -0
  20. data/ext/cohere_transcribe_native/test/audio_reliability_smoke.cpp +198 -0
  21. data/ext/cohere_transcribe_native/test/native_abi_reliability_smoke.cpp +186 -0
  22. data/ext/cohere_transcribe_native/test/native_batch_projection_probe.rb +81 -0
  23. data/ext/cohere_transcribe_native/test/native_cancellation_smoke.cpp +194 -0
  24. data/lib/cohere/transcribe/alignment/ATTRIBUTION.md +23 -0
  25. data/lib/cohere/transcribe/alignment/LICENSE.ctc-forced-aligner +407 -0
  26. data/lib/cohere/transcribe/alignment/LICENSE.torchaudio +25 -0
  27. data/lib/cohere/transcribe/alignment/LICENSE.uroman +26 -0
  28. data/lib/cohere/transcribe/alignment/aligner.rb +476 -0
  29. data/lib/cohere/transcribe/alignment/ctc.rb +224 -0
  30. data/lib/cohere/transcribe/alignment/text.rb +237 -0
  31. data/lib/cohere/transcribe/alignment/uroman_data.rb +4950 -0
  32. data/lib/cohere/transcribe/api.rb +173 -0
  33. data/lib/cohere/transcribe/asr/batching.rb +472 -0
  34. data/lib/cohere/transcribe/asr/failure_policy.rb +112 -0
  35. data/lib/cohere/transcribe/asr/native.rb +676 -0
  36. data/lib/cohere/transcribe/audio/ATTRIBUTION.md +8 -0
  37. data/lib/cohere/transcribe/audio/LICENSE.auditok +21 -0
  38. data/lib/cohere/transcribe/audio/decoder.rb +315 -0
  39. data/lib/cohere/transcribe/audio/ffmpeg_native.rb +248 -0
  40. data/lib/cohere/transcribe/audio/segmentation.rb +260 -0
  41. data/lib/cohere/transcribe/cli.rb +727 -0
  42. data/lib/cohere/transcribe/configuration.rb +282 -0
  43. data/lib/cohere/transcribe/constants.rb +14 -0
  44. data/lib/cohere/transcribe/dense_converter.rb +548 -0
  45. data/lib/cohere/transcribe/doctor.rb +576 -0
  46. data/lib/cohere/transcribe/errors.rb +57 -0
  47. data/lib/cohere/transcribe/gguf_writer.rb +268 -0
  48. data/lib/cohere/transcribe/hub.rb +436 -0
  49. data/lib/cohere/transcribe/input.rb +110 -0
  50. data/lib/cohere/transcribe/licenses/crispasr.txt +21 -0
  51. data/lib/cohere/transcribe/loader.rb +128 -0
  52. data/lib/cohere/transcribe/model_identity.rb +440 -0
  53. data/lib/cohere/transcribe/output/publication.rb +1118 -0
  54. data/lib/cohere/transcribe/output/rendering.rb +105 -0
  55. data/lib/cohere/transcribe/output/timing.rb +86 -0
  56. data/lib/cohere/transcribe/python_text.rb +70 -0
  57. data/lib/cohere/transcribe/pytorch_checkpoint.rb +1180 -0
  58. data/lib/cohere/transcribe/runtime/engine.rb +1676 -0
  59. data/lib/cohere/transcribe/runtime/model_provider.rb +390 -0
  60. data/lib/cohere/transcribe/runtime/precision.rb +57 -0
  61. data/lib/cohere/transcribe/runtime/preparation.rb +215 -0
  62. data/lib/cohere/transcribe/runtime/resources.rb +165 -0
  63. data/lib/cohere/transcribe/runtime/word_pipeline.rb +364 -0
  64. data/lib/cohere/transcribe/safetensors.rb +579 -0
  65. data/lib/cohere/transcribe/state/checkpoint.rb +224 -0
  66. data/lib/cohere/transcribe/state/contracts.rb +141 -0
  67. data/lib/cohere/transcribe/state/io.rb +727 -0
  68. data/lib/cohere/transcribe/state/locking.rb +211 -0
  69. data/lib/cohere/transcribe/state/manifest.rb +155 -0
  70. data/lib/cohere/transcribe/state.rb +7 -0
  71. data/lib/cohere/transcribe/types.rb +535 -0
  72. data/lib/cohere/transcribe/vad/ATTRIBUTION.md +14 -0
  73. data/lib/cohere/transcribe/vad/LICENSE.faster-whisper +21 -0
  74. data/lib/cohere/transcribe/vad/LICENSE.silero-vad +21 -0
  75. data/lib/cohere/transcribe/vad/silero.rb +344 -0
  76. data/lib/cohere/transcribe/vad/silero_vad_v6.onnx +0 -0
  77. data/lib/cohere/transcribe/vad/timestamps.rb +219 -0
  78. data/lib/cohere/transcribe/version.rb +7 -0
  79. data/lib/cohere/transcribe.rb +26 -0
  80. data/sig/cohere/transcribe.rbs +250 -0
  81. data/vendor/crispasr/AUTHORS +510 -0
  82. data/vendor/crispasr/LICENSE +21 -0
  83. data/vendor/crispasr/UPSTREAM.md +9 -0
  84. data/vendor/crispasr/VERSION +1 -0
  85. data/vendor/crispasr/ggml/AUTHORS +335 -0
  86. data/vendor/crispasr/ggml/CMakeLists.txt +512 -0
  87. data/vendor/crispasr/ggml/LICENSE +21 -0
  88. data/vendor/crispasr/ggml/README.md +49 -0
  89. data/vendor/crispasr/ggml/cmake/FindNCCL.cmake +36 -0
  90. data/vendor/crispasr/ggml/cmake/GitVars.cmake +22 -0
  91. data/vendor/crispasr/ggml/cmake/common.cmake +50 -0
  92. data/vendor/crispasr/ggml/cmake/ggml-config.cmake.in +191 -0
  93. data/vendor/crispasr/ggml/ggml.pc.in +10 -0
  94. data/vendor/crispasr/ggml/include/ggml-alloc.h +85 -0
  95. data/vendor/crispasr/ggml/include/ggml-backend.h +431 -0
  96. data/vendor/crispasr/ggml/include/ggml-blas.h +25 -0
  97. data/vendor/crispasr/ggml/include/ggml-cann.h +123 -0
  98. data/vendor/crispasr/ggml/include/ggml-cpp.h +39 -0
  99. data/vendor/crispasr/ggml/include/ggml-cpu.h +151 -0
  100. data/vendor/crispasr/ggml/include/ggml-cuda.h +50 -0
  101. data/vendor/crispasr/ggml/include/ggml-hexagon.h +19 -0
  102. data/vendor/crispasr/ggml/include/ggml-metal.h +61 -0
  103. data/vendor/crispasr/ggml/include/ggml-opencl.h +26 -0
  104. data/vendor/crispasr/ggml/include/ggml-openvino.h +37 -0
  105. data/vendor/crispasr/ggml/include/ggml-opt.h +256 -0
  106. data/vendor/crispasr/ggml/include/ggml-rpc.h +35 -0
  107. data/vendor/crispasr/ggml/include/ggml-sycl.h +49 -0
  108. data/vendor/crispasr/ggml/include/ggml-virtgpu.h +14 -0
  109. data/vendor/crispasr/ggml/include/ggml-vulkan.h +29 -0
  110. data/vendor/crispasr/ggml/include/ggml-webgpu.h +19 -0
  111. data/vendor/crispasr/ggml/include/ggml-zdnn.h +17 -0
  112. data/vendor/crispasr/ggml/include/ggml-zendnn.h +22 -0
  113. data/vendor/crispasr/ggml/include/ggml.h +2887 -0
  114. data/vendor/crispasr/ggml/include/gguf.h +204 -0
  115. data/vendor/crispasr/ggml/src/CMakeLists.txt +493 -0
  116. data/vendor/crispasr/ggml/src/ggml-alloc.c +1323 -0
  117. data/vendor/crispasr/ggml/src/ggml-backend-dl.cpp +48 -0
  118. data/vendor/crispasr/ggml/src/ggml-backend-dl.h +44 -0
  119. data/vendor/crispasr/ggml/src/ggml-backend-impl.h +275 -0
  120. data/vendor/crispasr/ggml/src/ggml-backend-meta.cpp +2145 -0
  121. data/vendor/crispasr/ggml/src/ggml-backend-reg.cpp +586 -0
  122. data/vendor/crispasr/ggml/src/ggml-backend.cpp +2437 -0
  123. data/vendor/crispasr/ggml/src/ggml-common.h +1900 -0
  124. data/vendor/crispasr/ggml/src/ggml-cpu/CMakeLists.txt +718 -0
  125. data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.cpp +249 -0
  126. data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.h +8 -0
  127. data/vendor/crispasr/ggml/src/ggml-cpu/amx/common.h +115 -0
  128. data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.cpp +2512 -0
  129. data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.h +10 -0
  130. data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp +98 -0
  131. data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/quants.c +4244 -0
  132. data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/repack.cpp +5156 -0
  133. data/vendor/crispasr/ggml/src/ggml-cpu/arch/loongarch/quants.c +2158 -0
  134. data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp +82 -0
  135. data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/quants.c +2304 -0
  136. data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/cpu-feats.cpp +38 -0
  137. data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/quants.c +4455 -0
  138. data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/repack.cpp +1703 -0
  139. data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp +50 -0
  140. data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/quants.c +1465 -0
  141. data/vendor/crispasr/ggml/src/ggml-cpu/arch/wasm/quants.c +1220 -0
  142. data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
  143. data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/quants.c +3970 -0
  144. data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/repack.cpp +6407 -0
  145. data/vendor/crispasr/ggml/src/ggml-cpu/arch-fallback.h +349 -0
  146. data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.cpp +154 -0
  147. data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.h +16 -0
  148. data/vendor/crispasr/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
  149. data/vendor/crispasr/ggml/src/ggml-cpu/common.h +95 -0
  150. data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu-impl.h +539 -0
  151. data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.c +3791 -0
  152. data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.cpp +703 -0
  153. data/vendor/crispasr/ggml/src/ggml-cpu/hbm.cpp +55 -0
  154. data/vendor/crispasr/ggml/src/ggml-cpu/hbm.h +8 -0
  155. data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.cpp +939 -0
  156. data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.h +90 -0
  157. data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +1513 -0
  158. data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
  159. data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.cpp +4051 -0
  160. data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.h +25 -0
  161. data/vendor/crispasr/ggml/src/ggml-cpu/ops.cpp +11662 -0
  162. data/vendor/crispasr/ggml/src/ggml-cpu/ops.h +121 -0
  163. data/vendor/crispasr/ggml/src/ggml-cpu/quants.c +1288 -0
  164. data/vendor/crispasr/ggml/src/ggml-cpu/quants.h +103 -0
  165. data/vendor/crispasr/ggml/src/ggml-cpu/repack.cpp +4836 -0
  166. data/vendor/crispasr/ggml/src/ggml-cpu/repack.h +245 -0
  167. data/vendor/crispasr/ggml/src/ggml-cpu/simd-gemm.h +226 -0
  168. data/vendor/crispasr/ggml/src/ggml-cpu/simd-mappings.h +1329 -0
  169. data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.cpp +1025 -0
  170. data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.h +13 -0
  171. data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime1_kernels.cpp +3196 -0
  172. data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime_kernels.h +26 -0
  173. data/vendor/crispasr/ggml/src/ggml-cpu/traits.cpp +36 -0
  174. data/vendor/crispasr/ggml/src/ggml-cpu/traits.h +38 -0
  175. data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.cpp +336 -0
  176. data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.h +35 -0
  177. data/vendor/crispasr/ggml/src/ggml-cpu/vec.cpp +681 -0
  178. data/vendor/crispasr/ggml/src/ggml-cpu/vec.h +1606 -0
  179. data/vendor/crispasr/ggml/src/ggml-cuda/CMakeLists.txt +272 -0
  180. data/vendor/crispasr/ggml/src/ggml-cuda/acc.cu +61 -0
  181. data/vendor/crispasr/ggml/src/ggml-cuda/acc.cuh +5 -0
  182. data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cu +58 -0
  183. data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cuh +3 -0
  184. data/vendor/crispasr/ggml/src/ggml-cuda/arange.cu +34 -0
  185. data/vendor/crispasr/ggml/src/ggml-cuda/arange.cuh +5 -0
  186. data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cu +91 -0
  187. data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cuh +3 -0
  188. data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cu +265 -0
  189. data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cuh +19 -0
  190. data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cu +534 -0
  191. data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cuh +12 -0
  192. data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cu +45 -0
  193. data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cuh +5 -0
  194. data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cu +81 -0
  195. data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cuh +3 -0
  196. data/vendor/crispasr/ggml/src/ggml-cuda/common.cuh +1489 -0
  197. data/vendor/crispasr/ggml/src/ggml-cuda/concat.cu +204 -0
  198. data/vendor/crispasr/ggml/src/ggml-cuda/concat.cuh +5 -0
  199. data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cu +97 -0
  200. data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
  201. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cu +161 -0
  202. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cuh +5 -0
  203. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cu +115 -0
  204. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cuh +5 -0
  205. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cu +166 -0
  206. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cuh +5 -0
  207. data/vendor/crispasr/ggml/src/ggml-cuda/convert.cu +892 -0
  208. data/vendor/crispasr/ggml/src/ggml-cuda/convert.cuh +66 -0
  209. data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cu +64 -0
  210. data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cuh +5 -0
  211. data/vendor/crispasr/ggml/src/ggml-cuda/cp-async.cuh +57 -0
  212. data/vendor/crispasr/ggml/src/ggml-cuda/cpy-utils.cuh +217 -0
  213. data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cu +581 -0
  214. data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cuh +7 -0
  215. data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cu +177 -0
  216. data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
  217. data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cu +307 -0
  218. data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cuh +5 -0
  219. data/vendor/crispasr/ggml/src/ggml-cuda/dequantize.cuh +99 -0
  220. data/vendor/crispasr/ggml/src/ggml-cuda/diag.cu +77 -0
  221. data/vendor/crispasr/ggml/src/ggml-cuda/diag.cuh +5 -0
  222. data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cu +40 -0
  223. data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cuh +5 -0
  224. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-common.cuh +1212 -0
  225. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-mma-f16.cuh +1860 -0
  226. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cu +57 -0
  227. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cuh +1309 -0
  228. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-vec.cuh +600 -0
  229. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cu +696 -0
  230. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +51 -0
  231. data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cu +620 -0
  232. data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cuh +5 -0
  233. data/vendor/crispasr/ggml/src/ggml-cuda/fill.cu +37 -0
  234. data/vendor/crispasr/ggml/src/ggml-cuda/fill.cuh +3 -0
  235. data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cu +273 -0
  236. data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cuh +4 -0
  237. data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cu +332 -0
  238. data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cuh +15 -0
  239. data/vendor/crispasr/ggml/src/ggml-cuda/ggml-cuda.cu +5580 -0
  240. data/vendor/crispasr/ggml/src/ggml-cuda/gla.cu +93 -0
  241. data/vendor/crispasr/ggml/src/ggml-cuda/gla.cuh +3 -0
  242. data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cu +274 -0
  243. data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cuh +6 -0
  244. data/vendor/crispasr/ggml/src/ggml-cuda/mean.cu +75 -0
  245. data/vendor/crispasr/ggml/src/ggml-cuda/mean.cuh +3 -0
  246. data/vendor/crispasr/ggml/src/ggml-cuda/mma.cuh +1333 -0
  247. data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cu +191 -0
  248. data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cuh +908 -0
  249. data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cu +164 -0
  250. data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cuh +5 -0
  251. data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cu +372 -0
  252. data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cuh +4175 -0
  253. data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cu +862 -0
  254. data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cuh +14 -0
  255. data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cu +1161 -0
  256. data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cuh +16 -0
  257. data/vendor/crispasr/ggml/src/ggml-cuda/norm.cu +756 -0
  258. data/vendor/crispasr/ggml/src/ggml-cuda/norm.cuh +20 -0
  259. data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
  260. data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
  261. data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cu +49 -0
  262. data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cuh +5 -0
  263. data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cu +68 -0
  264. data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cuh +3 -0
  265. data/vendor/crispasr/ggml/src/ggml-cuda/pad.cu +106 -0
  266. data/vendor/crispasr/ggml/src/ggml-cuda/pad.cuh +5 -0
  267. data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cu +91 -0
  268. data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cuh +5 -0
  269. data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cu +94 -0
  270. data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cuh +5 -0
  271. data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cu +443 -0
  272. data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cuh +41 -0
  273. data/vendor/crispasr/ggml/src/ggml-cuda/reduce_rows.cuh +39 -0
  274. data/vendor/crispasr/ggml/src/ggml-cuda/roll.cu +67 -0
  275. data/vendor/crispasr/ggml/src/ggml-cuda/roll.cuh +5 -0
  276. data/vendor/crispasr/ggml/src/ggml-cuda/rope.cu +665 -0
  277. data/vendor/crispasr/ggml/src/ggml-cuda/rope.cuh +9 -0
  278. data/vendor/crispasr/ggml/src/ggml-cuda/scale.cu +34 -0
  279. data/vendor/crispasr/ggml/src/ggml-cuda/scale.cuh +5 -0
  280. data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cu +330 -0
  281. data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cuh +7 -0
  282. data/vendor/crispasr/ggml/src/ggml-cuda/set.cu +39 -0
  283. data/vendor/crispasr/ggml/src/ggml-cuda/set.cuh +7 -0
  284. data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cu +34 -0
  285. data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cuh +5 -0
  286. data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cu +472 -0
  287. data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cuh +7 -0
  288. data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cu +275 -0
  289. data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cuh +3 -0
  290. data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cu +197 -0
  291. data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
  292. data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cu +342 -0
  293. data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
  294. data/vendor/crispasr/ggml/src/ggml-cuda/sum.cu +41 -0
  295. data/vendor/crispasr/ggml/src/ggml-cuda/sum.cuh +5 -0
  296. data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cu +43 -0
  297. data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cuh +4 -0
  298. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +5 -0
  299. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_32.cu +6 -0
  300. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +11 -0
  301. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
  302. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
  303. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +12 -0
  304. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +5 -0
  305. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_32.cu +6 -0
  306. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +12 -0
  307. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +11 -0
  308. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
  309. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
  310. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +5 -0
  311. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
  312. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +12 -0
  313. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +11 -0
  314. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
  315. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
  316. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
  317. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +12 -0
  318. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +11 -0
  319. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq112-dv112.cu +5 -0
  320. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq128-dv128.cu +5 -0
  321. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq256-dv256.cu +5 -0
  322. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq320-dv256.cu +5 -0
  323. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq40-dv40.cu +5 -0
  324. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq512-dv512.cu +5 -0
  325. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq576-dv512.cu +5 -0
  326. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq64-dv64.cu +5 -0
  327. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq72-dv72.cu +5 -0
  328. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq80-dv80.cu +5 -0
  329. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq96-dv96.cu +5 -0
  330. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-bf16.cu +7 -0
  331. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-f16.cu +7 -0
  332. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_0.cu +7 -0
  333. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_1.cu +7 -0
  334. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_0.cu +7 -0
  335. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_1.cu +7 -0
  336. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q8_0.cu +7 -0
  337. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-bf16.cu +7 -0
  338. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-f16.cu +7 -0
  339. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_0.cu +7 -0
  340. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_1.cu +7 -0
  341. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_0.cu +7 -0
  342. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_1.cu +7 -0
  343. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q8_0.cu +7 -0
  344. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-bf16.cu +7 -0
  345. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-f16.cu +7 -0
  346. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_0.cu +7 -0
  347. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_1.cu +7 -0
  348. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_0.cu +7 -0
  349. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_1.cu +7 -0
  350. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q8_0.cu +7 -0
  351. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-bf16.cu +7 -0
  352. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-f16.cu +7 -0
  353. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_0.cu +7 -0
  354. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_1.cu +7 -0
  355. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_0.cu +7 -0
  356. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_1.cu +7 -0
  357. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q8_0.cu +7 -0
  358. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-bf16.cu +7 -0
  359. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-f16.cu +7 -0
  360. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_0.cu +7 -0
  361. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_1.cu +7 -0
  362. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_0.cu +7 -0
  363. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_1.cu +7 -0
  364. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q8_0.cu +7 -0
  365. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-bf16.cu +7 -0
  366. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-f16.cu +7 -0
  367. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_0.cu +7 -0
  368. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_1.cu +7 -0
  369. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_0.cu +7 -0
  370. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_1.cu +7 -0
  371. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q8_0.cu +7 -0
  372. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-bf16.cu +7 -0
  373. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-f16.cu +7 -0
  374. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_0.cu +7 -0
  375. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_1.cu +7 -0
  376. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_0.cu +7 -0
  377. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_1.cu +7 -0
  378. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q8_0.cu +7 -0
  379. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_1.cu +5 -0
  380. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_10.cu +5 -0
  381. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_11.cu +5 -0
  382. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_12.cu +5 -0
  383. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_13.cu +5 -0
  384. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_14.cu +5 -0
  385. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_15.cu +5 -0
  386. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_16.cu +5 -0
  387. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_2.cu +5 -0
  388. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_3.cu +5 -0
  389. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_4.cu +5 -0
  390. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_5.cu +5 -0
  391. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_6.cu +5 -0
  392. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_7.cu +5 -0
  393. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_8.cu +5 -0
  394. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_9.cu +5 -0
  395. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
  396. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
  397. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
  398. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
  399. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
  400. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
  401. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
  402. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
  403. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-mxfp4.cu +5 -0
  404. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-nvfp4.cu +5 -0
  405. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q1_0.cu +5 -0
  406. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
  407. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
  408. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
  409. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
  410. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
  411. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
  412. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
  413. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
  414. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
  415. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
  416. data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cu +95 -0
  417. data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cuh +3 -0
  418. data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cu +415 -0
  419. data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cuh +27 -0
  420. data/vendor/crispasr/ggml/src/ggml-cuda/tri.cu +136 -0
  421. data/vendor/crispasr/ggml/src/ggml-cuda/tri.cuh +5 -0
  422. data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cu +47 -0
  423. data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cuh +5 -0
  424. data/vendor/crispasr/ggml/src/ggml-cuda/unary.cu +644 -0
  425. data/vendor/crispasr/ggml/src/ggml-cuda/unary.cuh +116 -0
  426. data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cu +293 -0
  427. data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cuh +5 -0
  428. data/vendor/crispasr/ggml/src/ggml-cuda/vecdotq.cuh +1317 -0
  429. data/vendor/crispasr/ggml/src/ggml-cuda/vendors/cuda.h +28 -0
  430. data/vendor/crispasr/ggml/src/ggml-cuda/vendors/hip.h +306 -0
  431. data/vendor/crispasr/ggml/src/ggml-cuda/vendors/musa.h +148 -0
  432. data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cu +199 -0
  433. data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cuh +7 -0
  434. data/vendor/crispasr/ggml/src/ggml-impl.h +783 -0
  435. data/vendor/crispasr/ggml/src/ggml-metal/CMakeLists.txt +124 -0
  436. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.cpp +457 -0
  437. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.h +52 -0
  438. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.h +41 -0
  439. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.m +778 -0
  440. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.cpp +2117 -0
  441. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.h +299 -0
  442. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.m +2093 -0
  443. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-impl.h +1267 -0
  444. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.cpp +5023 -0
  445. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.h +111 -0
  446. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.cpp +954 -0
  447. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.metal +11756 -0
  448. data/vendor/crispasr/ggml/src/ggml-opt.cpp +1094 -0
  449. data/vendor/crispasr/ggml/src/ggml-quants.c +5491 -0
  450. data/vendor/crispasr/ggml/src/ggml-quants.h +112 -0
  451. data/vendor/crispasr/ggml/src/ggml-threading.cpp +12 -0
  452. data/vendor/crispasr/ggml/src/ggml-threading.h +14 -0
  453. data/vendor/crispasr/ggml/src/ggml.c +7925 -0
  454. data/vendor/crispasr/ggml/src/ggml.cpp +26 -0
  455. data/vendor/crispasr/ggml/src/gguf.cpp +1556 -0
  456. data/vendor/crispasr/src/cohere-arch.h +137 -0
  457. data/vendor/crispasr/src/cohere.cpp +5642 -0
  458. data/vendor/crispasr/src/cohere.h +327 -0
  459. data/vendor/crispasr/src/cohere_batch_planner.h +82 -0
  460. data/vendor/crispasr/src/cohere_chunking.h +64 -0
  461. data/vendor/crispasr/src/cohere_decoder_batch_layout.h +60 -0
  462. data/vendor/crispasr/src/cohere_encoder_padded_layout.h +27 -0
  463. data/vendor/crispasr/src/cohere_frontend.cpp +189 -0
  464. data/vendor/crispasr/src/cohere_frontend.h +31 -0
  465. data/vendor/crispasr/src/cohere_ragged_controller.h +149 -0
  466. data/vendor/crispasr/src/cohere_token_renderer.h +181 -0
  467. data/vendor/crispasr/src/core/attention.h +924 -0
  468. data/vendor/crispasr/src/core/audio_chunking.h +97 -0
  469. data/vendor/crispasr/src/core/beam_decode.h +486 -0
  470. data/vendor/crispasr/src/core/cpu_ops.h +135 -0
  471. data/vendor/crispasr/src/core/gguf_loader.cpp +1021 -0
  472. data/vendor/crispasr/src/core/gguf_loader.h +216 -0
  473. data/vendor/crispasr/src/core/gpu_backend_pref.h +119 -0
  474. data/vendor/crispasr/src/core/mel.cpp +519 -0
  475. data/vendor/crispasr/src/core/mel.h +265 -0
  476. data/vendor/crispasr/src/core/ngram_loop_fix.h +173 -0
  477. data/vendor/crispasr/src/core/repetition_loop_guard.h +54 -0
  478. data/vendor/crispasr/src/crispasr_imatrix.cpp +255 -0
  479. data/vendor/crispasr/src/crispasr_imatrix.h +38 -0
  480. metadata +596 -0
@@ -0,0 +1,1333 @@
1
+ #pragma once
2
+ // This file contains primitives that expose the tensor core PTX instructions for CUDA code.
3
+ // The primitives can be used in a similar way as the nvcuda::wmma interface but with a well-defined memory layout.
4
+ // The documentation for the PTX instructions can be found under:
5
+ // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#matrix-multiply-accumulate-operation-using-mma-instruction
6
+ //
7
+ // Like with nvcuda::wmma there are three types of matrix tiles: A, B, and C with A @ B = C.
8
+ // A is a row-major matrix with shape M x K.
9
+ // B is a column-major matrix with shape K x N.
10
+ // C is a column-major matrix with shape M x N.
11
+ // A, B, and C are represented using the same fundamental data type: a row-major matrix with I rows and J columns.
12
+ // Note that J is measured in physical 32 bit elements instead of logical elements.
13
+ // The methods get_i and get_j can be used to get the physical 32 bit index of the lth element of a thread within a tile.
14
+ // All matrix tiles have ne physical 32 bit elements per warp.
15
+ //
16
+ // As described in the PTX documentation, all pointers for load_ldmatrix must be to shared memory and aligned to 16 bytes.
17
+ // The API in this file also assumes that the pointers for load_generic are aligned to 16 bytes, unaligned pointers are considered undefined behavior.
18
+
19
+ #include "common.cuh"
20
+
21
+ // On Volta each warp is doing 4 8x8 mma operations in parallel.
22
+ // The basic memory layout for a 32x8 output tile is to stack 4 input tiles in I direction and to mirror the B tile.
23
+ // However, the i indices in this file are by default permuted to simplify the index calculations.
24
+ // #define GGML_CUDA_MMA_NO_VOLTA_PERM
25
+
26
+ #if CUDART_VERSION >= 11080
27
+
28
+ static __device__ __forceinline__ int ggml_cuda_movmatrix(const int x) {
29
+ int ret = 0;
30
+
31
+ #ifdef TURING_MMA_AVAILABLE
32
+ asm("movmatrix.sync.aligned.m8n8.trans.b16 %0, %1;"
33
+ : "=r"(ret) : "r"(x));
34
+ #else
35
+ GGML_UNUSED(x);
36
+ NO_DEVICE_CODE;
37
+ #endif // defined(TURING_MMA_AVAILABLE)
38
+ return ret;
39
+ }
40
+
41
+ #else
42
+
43
+ static __device__ __forceinline__ int ggml_cuda_movmatrix(const int x) {
44
+ // Imagine transposing row-major matrix to column-major matrix.
45
+ const int src_i_low = 2 * (threadIdx.x % 4);
46
+ const int src_i_high = src_i_low + 1;
47
+ const int src_j = threadIdx.x / 4;
48
+
49
+ const int src_laneid_low = src_i_low * 4 + src_j / 2;
50
+ const int src_laneid_high = src_i_high * 4 + src_j / 2;
51
+
52
+ const int shift_low = ((src_j + 0) % 2) * 16;
53
+ const int shift_high = ((src_j + 1) % 2) * 16;
54
+
55
+ const int ret_low = (__shfl_sync(0xFFFFFFFF, x, src_laneid_low, WARP_SIZE) >> shift_low) & 0x0000FFFF;
56
+ const int ret_high = (__shfl_sync(0xFFFFFFFF, x, src_laneid_high, WARP_SIZE) << shift_high) & 0xFFFF0000;
57
+
58
+ return ret_low | ret_high;
59
+ }
60
+
61
+ #endif // CUDART_VERSION >= 11080
62
+
63
+ static __device__ __forceinline__ half2 ggml_cuda_movmatrix(const half2 x) {
64
+ half2 ret;
65
+ *((int *) &ret) = ggml_cuda_movmatrix(*((const int *) &x));
66
+ return ret;
67
+ }
68
+
69
+ namespace ggml_cuda_mma {
70
+
71
+ // Some architectures like Volta or CDNA3 perform multiple matrix multiplications per warp in parallel,
72
+ // effectively the warp is being split into subgroups of threads that each perform a single mma instruction.
73
+ // In those cases the data can be split in different ways across the warp.
74
+ enum data_layout {
75
+ // By default the data uses the I direction as its major dimension and the J direction as its minor dimension.
76
+ // For the A/C matrices this means I major == row major, J major == column major.
77
+ // For the B matrix this means I major == column major, J major == row major.
78
+ // MIRRORED == Each data value is held exactly once per thread subgroup.
79
+ DATA_LAYOUT_I_MAJOR = 0, // Always used for Turing, Ampere, Ada Lovelace, consumer Blackwell, matrix A&B for RDNA4 and CDNA.
80
+ DATA_LAYOUT_J_MAJOR = 10, // Matrix C for CDNA and RDNA4, int and float matrix C for RDNA3.
81
+ DATA_LAYOUT_I_MAJOR_MIRRORED = 20, // Volta, matrix A&B for RDNA3.
82
+ DATA_LAYOUT_J_MAJOR_MIRRORED = 30,
83
+ };
84
+ // Implemented mma combinations are:
85
+ // - (I_MAJOR, I_MAJOR) -> I_MAJOR
86
+ // - (I_MAJOR, I_MAJOR_MIRRORED) -> I_MAJOR
87
+ // - (I_MAJOR, J_MAJOR_MIRRORED) -> I_MAJOR
88
+
89
+ static constexpr __device__ data_layout get_input_data_layout() {
90
+ #if defined(RDNA3) || defined(VOLTA_MMA_AVAILABLE)
91
+ return DATA_LAYOUT_I_MAJOR_MIRRORED;
92
+ #else
93
+ return DATA_LAYOUT_I_MAJOR;
94
+ #endif // defined(RDNA3) || defined(VOLTA_MMA_AVAILABLE)
95
+ }
96
+
97
+ template <int I_, int J_, typename T, data_layout ds_=DATA_LAYOUT_I_MAJOR>
98
+ struct tile {};
99
+
100
+ template <int I_, int J_, typename T>
101
+ struct tile<I_, J_, T, DATA_LAYOUT_I_MAJOR> {
102
+ static constexpr int I = I_;
103
+ static constexpr int J = J_;
104
+ static constexpr data_layout dl = DATA_LAYOUT_I_MAJOR;
105
+
106
+ #if defined(AMD_MFMA_AVAILABLE)
107
+ static constexpr int ne = I * J / 64;
108
+ T x[ne] = {0};
109
+
110
+ static constexpr __device__ bool supported() {
111
+ if (I == 16 && J == 8) return true;
112
+ if (I == 32 && J == 4) return true;
113
+ if (I == 16 && J == 16) return true;
114
+ if (I == 32 && J == 32) return true;
115
+ return false;
116
+ }
117
+
118
+ static __device__ __forceinline__ int get_i(const int l) {
119
+ if constexpr (I == 16 && J == 4) {
120
+ return threadIdx.x % 16;
121
+ } else if constexpr (I == 16 && J == 8) {
122
+ return threadIdx.x % 16;
123
+ } else if constexpr (I == 32 && J == 4) {
124
+ return threadIdx.x % 32;
125
+ } else if constexpr (I == 16 && J == 16) {
126
+ return threadIdx.x % 16;
127
+ } else if constexpr (I == 32 && J == 32) {
128
+ return threadIdx.x % 32;
129
+ } else {
130
+ NO_DEVICE_CODE;
131
+ return -1;
132
+ }
133
+ }
134
+
135
+ static __device__ __forceinline__ int get_j(const int l) {
136
+ if constexpr (I == 16 && J == 4) {
137
+ return threadIdx.x / 16;
138
+ } else if constexpr (I == 16 && J == 8) {
139
+ return 2 * (threadIdx.x / 16) + l;
140
+ } else if constexpr (I == 32 && J == 4) {
141
+ return 2 * (threadIdx.x / 32) + l;
142
+ } else if constexpr (I == 16 && J == 16) {
143
+ return 4 * (threadIdx.x / 16) + l;
144
+ } else if constexpr (I == 32 && J == 32) {
145
+ return 4 * (threadIdx.x / 32) + 8 * (l / 4) + (l % 4);
146
+ } else {
147
+ NO_DEVICE_CODE;
148
+ return -1;
149
+ }
150
+ }
151
+ #elif defined(VOLTA_MMA_AVAILABLE)
152
+ static constexpr int ne = I * J / 32;
153
+ T x[ne] = {0};
154
+
155
+ static constexpr __device__ bool supported() {
156
+ if (I == 32 && J == 8) return true;
157
+ return false;
158
+ }
159
+
160
+ static __device__ __forceinline__ int get_i(const int l) {
161
+ if constexpr (I == 32 && J == 8) {
162
+ #ifdef GGML_CUDA_MMA_NO_VOLTA_PERM
163
+ return (((threadIdx.x % 16) / 4) * 8) + ((threadIdx.x / 16) * 4) + (l & 2) + (threadIdx.x % 2);
164
+ #else
165
+ return (l & 2) + (threadIdx.x & ~2);
166
+ #endif // GGML_CUDA_MMA_NO_VOLTA_PERM
167
+ } else {
168
+ NO_DEVICE_CODE;
169
+ return -1;
170
+ }
171
+ }
172
+
173
+ static __device__ __forceinline__ int get_j(const int l) {
174
+ if constexpr (I == 32 && J == 8) {
175
+ return (threadIdx.x & 2) + (l & (4 + 1));
176
+ } else {
177
+ NO_DEVICE_CODE;
178
+ return -1;
179
+ }
180
+ }
181
+ #elif defined(AMD_WMMA_AVAILABLE)
182
+ static constexpr int ne = I * J / 32;
183
+ T x[ne] = {0};
184
+
185
+ static constexpr __device__ bool supported() {
186
+ if (I == 16 && J == 16) return true;
187
+ if (I == 16 && J == 8) return true;
188
+ if (I == 16 && J == 4) return true;
189
+ return false;
190
+ }
191
+
192
+ static __device__ __forceinline__ int get_i(const int l) {
193
+ if constexpr (supported()) {
194
+ return threadIdx.x % 16;
195
+ } else {
196
+ NO_DEVICE_CODE;
197
+ return -1;
198
+ }
199
+ }
200
+
201
+ static __device__ __forceinline__ int get_j(const int l) {
202
+ if constexpr (I == 16 && J == 16) {
203
+ #if defined(RDNA3)
204
+ if constexpr (std::is_same_v<T, float> || std::is_same_v<T, int>) {
205
+ // matrix C
206
+ return 2 * l + (threadIdx.x / 16);
207
+ } else {
208
+ // matrix A&B
209
+ return l;
210
+ }
211
+ #else
212
+ // matrix C is the transposed matrix A&B on RDNA4
213
+ return ne * (threadIdx.x / 16) + l;
214
+ #endif // defined(RDNA3)
215
+ } else if constexpr (I == 16 && J == 8) {
216
+ // mmq input for RDNA4
217
+ return ne * (threadIdx.x / 16) + l;
218
+ } else if constexpr (I == 16 && J == 4) {
219
+ return ne * (threadIdx.x / 16) + l;
220
+ } else {
221
+ NO_DEVICE_CODE;
222
+ return -1;
223
+ }
224
+ }
225
+ #else
226
+ static constexpr int ne = I * J / 32;
227
+ T x[ne] = {0};
228
+
229
+ static constexpr __device__ bool supported() {
230
+ if (I == 8 && J == 4) return true;
231
+ if (I == 8 && J == 8) return true;
232
+ if (I == 16 && J == 8) return true;
233
+ if (I == 16 && J == 16) return true;
234
+ if (I == 32 && J == 8) return true;
235
+ return false;
236
+ }
237
+
238
+ static __device__ __forceinline__ int get_i(const int l) {
239
+ if constexpr (I == 8 && J == 4) {
240
+ return threadIdx.x / 4;
241
+ } else if constexpr (I == 8 && J == 8) {
242
+ return threadIdx.x / 4;
243
+ } else if constexpr (I == 16 && J == 8) {
244
+ return ((l / 2) * 8) + (threadIdx.x / 4);
245
+ } else if constexpr (I == 16 && J == 16) {
246
+ return (((l / 2) % 2) * 8) + (threadIdx.x / 4);
247
+ } else if constexpr (I == 32 && J == 8) {
248
+ return tile<16, 8, T>::get_i(l); // Memory layout simply repeated with same pattern in i direction.
249
+ } else {
250
+ NO_DEVICE_CODE;
251
+ return -1;
252
+ }
253
+ }
254
+
255
+ static __device__ __forceinline__ int get_j(const int l) {
256
+ if constexpr (I == 8 && J == 4) {
257
+ return threadIdx.x % 4;
258
+ } else if constexpr (I == 8 && J == 8) {
259
+ return (l * 4) + (threadIdx.x % 4);
260
+ } else if constexpr (I == 16 && J == 8) {
261
+ return ((threadIdx.x % 4) * 2) + (l % 2);
262
+ } else if constexpr (I == 16 && J == 16) {
263
+ return ((l / 4) * 8) + ((threadIdx.x % 4) * 2) + (l % 2);
264
+ } else if constexpr (I == 32 && J == 8) {
265
+ return tile<16, 8, T>::get_j(l); // Memory layout simply repeated with same pattern in i direction.
266
+ } else {
267
+ NO_DEVICE_CODE;
268
+ return -1;
269
+ }
270
+ }
271
+ #endif // defined(GGML_USE_HIP)
272
+ };
273
+
274
+ template <int I_, int J_>
275
+ struct tile<I_, J_, half2, DATA_LAYOUT_I_MAJOR> {
276
+ static constexpr int I = I_;
277
+ static constexpr int J = J_;
278
+ static constexpr data_layout dl = DATA_LAYOUT_I_MAJOR;
279
+
280
+ #if defined(VOLTA_MMA_AVAILABLE)
281
+ static constexpr int ne = I * J / WARP_SIZE;
282
+ half2 x[ne] = {{0.0f, 0.0f}};
283
+
284
+ static constexpr __device__ bool supported() {
285
+ if (I == 32 && J == 4) return true;
286
+ return false;
287
+ }
288
+
289
+ static __device__ __forceinline__ int get_i(const int l) {
290
+ if constexpr (I == 32 && J == 4) {
291
+ #ifdef GGML_CUDA_MMA_NO_VOLTA_PERM
292
+ return (((threadIdx.x % 16) / 4) * 8) + ((threadIdx.x / 16) * 4) + (threadIdx.x % 4);
293
+ #else
294
+ return threadIdx.x;
295
+ #endif // GGML_CUDA_MMA_NO_VOLTA_PERM
296
+ } else {
297
+ NO_DEVICE_CODE;
298
+ return -1;
299
+ }
300
+ }
301
+
302
+ static __device__ __forceinline__ int get_j(const int l) {
303
+ if constexpr (I == 32 && J == 4) {
304
+ return l;
305
+ } else {
306
+ NO_DEVICE_CODE;
307
+ return -1;
308
+ }
309
+ }
310
+ #elif defined(AMD_WMMA_AVAILABLE)
311
+ static constexpr int ne = I * J / 32;
312
+ half2 x[ne] = {{0.0f, 0.0f}};
313
+
314
+ static constexpr __device__ bool supported() {
315
+ if (I == 16 && J == 8) return true;
316
+ return false;
317
+ }
318
+
319
+ static __device__ __forceinline__ int get_i(const int l) {
320
+ if constexpr (I == 16 && J == 8) {
321
+ return threadIdx.x % 16;
322
+ } else {
323
+ NO_DEVICE_CODE;
324
+ return -1;
325
+ }
326
+ }
327
+
328
+ static __device__ __forceinline__ int get_j(const int l) {
329
+ if constexpr (I == 16 && J == 8) {
330
+ return ne * (threadIdx.x / 16) + l;
331
+ } else {
332
+ NO_DEVICE_CODE;
333
+ return -1;
334
+ }
335
+ }
336
+ #elif defined(AMD_MFMA_AVAILABLE)
337
+ static constexpr int ne = I * J / 64;
338
+ half2 x[ne] = {{0.0f, 0.0f}};
339
+
340
+ static constexpr __device__ bool supported() {
341
+ if (I == 16 && J == 8) return true;
342
+ return false;
343
+ }
344
+
345
+ static __device__ __forceinline__ int get_i(const int l) {
346
+ if constexpr (I == 16 && J == 8) {
347
+ return threadIdx.x % 16;
348
+ } else {
349
+ NO_DEVICE_CODE;
350
+ return -1;
351
+ }
352
+ }
353
+
354
+ static __device__ __forceinline__ int get_j(const int l) {
355
+ if constexpr (I == 16 && J == 8) {
356
+ return ne * (threadIdx.x / 16) + l;
357
+ } else {
358
+ NO_DEVICE_CODE;
359
+ return -1;
360
+ }
361
+ }
362
+ #else
363
+ static constexpr int ne = I * J / WARP_SIZE;
364
+ half2 x[ne] = {{0.0f, 0.0f}};
365
+
366
+ static constexpr __device__ bool supported() {
367
+ if (I == 8 && J == 4) return true;
368
+ if (I == 8 && J == 8) return true;
369
+ if (I == 16 && J == 8) return true;
370
+ if (I == 16 && J == 16) return true;
371
+ if (I == 32 && J == 8) return true;
372
+ return false;
373
+ }
374
+
375
+ static __device__ __forceinline__ int get_i(const int l) {
376
+ if constexpr (I == 8 && J == 8) {
377
+ return threadIdx.x / 4;
378
+ } else if constexpr (I == 16 && J == 4) {
379
+ return (l * 8) + (threadIdx.x / 4);
380
+ } else if constexpr (I == 16 && J == 8) {
381
+ return ((l % 2) * 8) + (threadIdx.x / 4);
382
+ } else if constexpr (I == 32 && J == 8) {
383
+ return ((l / 4) * 16) + ((l % 2) * 8) + (threadIdx.x / 4);
384
+ } else {
385
+ NO_DEVICE_CODE;
386
+ return -1;
387
+ }
388
+ }
389
+
390
+ static __device__ __forceinline__ int get_j(const int l) {
391
+ if constexpr (I == 8 && J == 8) {
392
+ return (l * 4) + (threadIdx.x % 4);
393
+ } else if constexpr (I == 16 && J == 4) {
394
+ return threadIdx.x % 4;
395
+ } else if constexpr (I == 16 && J == 8) {
396
+ return ((l / 2) * 4) + (threadIdx.x % 4);
397
+ } else if constexpr (I == 32 && J == 8) {
398
+ return ((l & 2) * 2) + (threadIdx.x % 4);
399
+ } else {
400
+ NO_DEVICE_CODE;
401
+ return -1;
402
+ }
403
+ }
404
+ #endif // defined(VOLTA_MMA_AVAILABLE)
405
+ };
406
+
407
+ template <int I_, int J_>
408
+ struct tile<I_, J_, nv_bfloat162, DATA_LAYOUT_I_MAJOR> {
409
+ static constexpr int I = I_;
410
+ static constexpr int J = J_;
411
+ static constexpr data_layout dl = DATA_LAYOUT_I_MAJOR;
412
+
413
+ #if defined(AMD_WMMA_AVAILABLE)
414
+ static constexpr int ne = tile<I_, J_, half2, DATA_LAYOUT_I_MAJOR>::ne;
415
+ nv_bfloat162 x[ne] = {{0.0f, 0.0f}};
416
+
417
+ static constexpr __device__ bool supported() {
418
+ return tile<I_, J_, half2, DATA_LAYOUT_I_MAJOR>::supported();
419
+ }
420
+
421
+ static __device__ __forceinline__ int get_i(const int l) {
422
+ return tile<I_, J_, half2, DATA_LAYOUT_I_MAJOR>::get_i(l);
423
+ }
424
+
425
+ static __device__ __forceinline__ int get_j(const int l) {
426
+ return tile<I_, J_, half2, DATA_LAYOUT_I_MAJOR>::get_j(l);
427
+ }
428
+ #elif defined(AMD_MFMA_AVAILABLE)
429
+ static constexpr int ne = tile<I_, J_, half2, DATA_LAYOUT_I_MAJOR>::ne;
430
+ nv_bfloat162 x[ne] = {{0.0f, 0.0f}};
431
+
432
+ static constexpr __device__ bool supported() {
433
+ return tile<I_, J_, half2, DATA_LAYOUT_I_MAJOR>::supported();
434
+ }
435
+
436
+ static __device__ __forceinline__ int get_i(const int l) {
437
+ return tile<I_, J_, half2, DATA_LAYOUT_I_MAJOR>::get_i(l);
438
+ }
439
+
440
+ static __device__ __forceinline__ int get_j(const int l) {
441
+ return tile<I_, J_, half2, DATA_LAYOUT_I_MAJOR>::get_j(l);
442
+ }
443
+ #else
444
+ static constexpr int ne = I * J / WARP_SIZE;
445
+ nv_bfloat162 x[ne] = {{0.0f, 0.0f}};
446
+
447
+ static constexpr __device__ bool supported() {
448
+ if (I == 8 && J == 8) return true;
449
+ if (I == 16 && J == 4) return true;
450
+ if (I == 16 && J == 8) return true;
451
+ return false;
452
+ }
453
+
454
+ static __device__ __forceinline__ int get_i(const int l) {
455
+ if constexpr (I == 8 && J == 8) {
456
+ return threadIdx.x / 4;
457
+ } else if constexpr (I == 16 && J == 4) {
458
+ return (l * 8) + (threadIdx.x / 4);
459
+ } else if constexpr (I == 16 && J == 8) {
460
+ return ((l % 2) * 8) + (threadIdx.x / 4);
461
+ } else {
462
+ NO_DEVICE_CODE;
463
+ return -1;
464
+ }
465
+ }
466
+
467
+ static __device__ __forceinline__ int get_j(const int l) {
468
+ if constexpr (I == 8 && J == 8) {
469
+ return (l * 4) + (threadIdx.x % 4);
470
+ } else if constexpr (I == 16 && J == 4) {
471
+ return threadIdx.x % 4;
472
+ } else if constexpr (I == 16 && J == 8) {
473
+ return ((l / 2) * 4) + (threadIdx.x % 4);
474
+ } else {
475
+ NO_DEVICE_CODE;
476
+ return -1;
477
+ }
478
+ }
479
+ #endif // defined(AMD_WMMA_AVAILABLE)
480
+ };
481
+
482
+ template <int I_, int J_, typename T>
483
+ struct tile<I_, J_, T, DATA_LAYOUT_J_MAJOR> {
484
+ static constexpr int I = I_;
485
+ static constexpr int J = J_;
486
+ static constexpr data_layout dl = DATA_LAYOUT_J_MAJOR;
487
+
488
+ static constexpr int ne = tile<I_, J_, T, DATA_LAYOUT_I_MAJOR>::ne;
489
+ T x[ne] = {0};
490
+
491
+ static constexpr __device__ bool supported() {
492
+ return tile<I_, J_, T, DATA_LAYOUT_I_MAJOR>::supported();
493
+ }
494
+
495
+ static __device__ __forceinline__ int get_i(const int l) {
496
+ return tile<I_, J_, T, DATA_LAYOUT_I_MAJOR>::get_j(l);
497
+ }
498
+
499
+ static __device__ __forceinline__ int get_j(const int l) {
500
+ return tile<I_, J_, T, DATA_LAYOUT_I_MAJOR>::get_i(l);
501
+ }
502
+ };
503
+
504
+ template <int I_, int J_, typename T>
505
+ struct tile<I_, J_, T, DATA_LAYOUT_I_MAJOR_MIRRORED> {
506
+ static constexpr int I = I_;
507
+ static constexpr int J = J_;
508
+ static constexpr data_layout dl = DATA_LAYOUT_I_MAJOR_MIRRORED;
509
+
510
+ // RDNA3
511
+ static constexpr int ne = I * J / 32 * 2;
512
+
513
+ T x[ne] = {0};
514
+
515
+ static constexpr __device__ bool supported() {
516
+ if (I == 16 && J == 16) return true;
517
+ if (I == 16 && J == 8) return true;
518
+ if (I == 16 && J == 4) return true;
519
+ return false;
520
+ }
521
+
522
+ static __device__ __forceinline__ int get_i(const int /*l*/) {
523
+ if constexpr (supported()) {
524
+ return threadIdx.x % 16;
525
+ } else {
526
+ NO_DEVICE_CODE;
527
+ return -1;
528
+ }
529
+ }
530
+
531
+ static __device__ __forceinline__ int get_j(const int l) {
532
+ if constexpr (supported()) {
533
+ return l;
534
+ } else {
535
+ NO_DEVICE_CODE;
536
+ return -1;
537
+ }
538
+ }
539
+ };
540
+
541
+ template <int I_, int J_>
542
+ struct tile<I_, J_, half2, DATA_LAYOUT_I_MAJOR_MIRRORED> {
543
+ static constexpr int I = I_;
544
+ static constexpr int J = J_;
545
+ static constexpr data_layout dl = DATA_LAYOUT_I_MAJOR_MIRRORED;
546
+ #if defined(RDNA3)
547
+ static constexpr int ne = tile<I_, J_, float, DATA_LAYOUT_I_MAJOR_MIRRORED>::ne;
548
+
549
+ half2 x[ne] = {{0.0f, 0.0f}};
550
+
551
+ static constexpr __device__ bool supported() {
552
+ return tile<I_, J_, float, DATA_LAYOUT_I_MAJOR_MIRRORED>::supported();
553
+ }
554
+
555
+ static __device__ __forceinline__ int get_i(const int l) {
556
+ return tile<I_, J_, float, DATA_LAYOUT_I_MAJOR_MIRRORED>::get_i(l);
557
+ }
558
+
559
+ static __device__ __forceinline__ int get_j(const int l) {
560
+ return tile<I_, J_, float, DATA_LAYOUT_I_MAJOR_MIRRORED>::get_j(l);
561
+ }
562
+ #else // Volta
563
+ static constexpr int ne = I * J / (WARP_SIZE/4);
564
+
565
+ half2 x[ne] = {{0.0f, 0.0f}};
566
+
567
+ static constexpr __device__ bool supported() {
568
+ if (I == 8 && J == 4) return true;
569
+ return false;
570
+ }
571
+
572
+ static __device__ __forceinline__ int get_i(const int /*l*/) {
573
+ if constexpr (I == 8 && J == 4) {
574
+ return ((threadIdx.x / 16) * 4) + (threadIdx.x % 4);
575
+ } else {
576
+ NO_DEVICE_CODE;
577
+ return -1;
578
+ }
579
+ }
580
+
581
+ static __device__ __forceinline__ int get_j(const int l) {
582
+ if constexpr (I == 8 && J == 4) {
583
+ return l;
584
+ } else {
585
+ NO_DEVICE_CODE;
586
+ return -1;
587
+ }
588
+ }
589
+ #endif // defined(RDNA3)
590
+ };
591
+
592
+ template <int I_, int J_>
593
+ struct tile<I_, J_, nv_bfloat162, DATA_LAYOUT_I_MAJOR_MIRRORED> {
594
+ static constexpr int I = I_;
595
+ static constexpr int J = J_;
596
+ static constexpr data_layout dl = DATA_LAYOUT_I_MAJOR_MIRRORED;
597
+ static constexpr int ne = tile<I_, J_, float, DATA_LAYOUT_I_MAJOR_MIRRORED>::ne;
598
+
599
+ nv_bfloat162 x[ne] = {{0.0f, 0.0f}};
600
+
601
+ static constexpr __device__ bool supported() {
602
+ return tile<I_, J_, float, DATA_LAYOUT_I_MAJOR_MIRRORED>::supported();
603
+ }
604
+
605
+ static __device__ __forceinline__ int get_i(const int l) {
606
+ return tile<I_, J_, float, DATA_LAYOUT_I_MAJOR_MIRRORED>::get_i(l);
607
+ }
608
+
609
+ static __device__ __forceinline__ int get_j(const int l) {
610
+ return tile<I_, J_, float, DATA_LAYOUT_I_MAJOR_MIRRORED>::get_j(l);
611
+ }
612
+ };
613
+
614
+ template <int I_, int J_>
615
+ struct tile<I_, J_, half2, DATA_LAYOUT_J_MAJOR_MIRRORED> {
616
+ static constexpr int I = I_;
617
+ static constexpr int J = J_;
618
+ static constexpr data_layout dl = DATA_LAYOUT_J_MAJOR_MIRRORED;
619
+ static constexpr int ne = I * J / (WARP_SIZE/4);
620
+
621
+ half2 x[ne] = {{0.0f, 0.0f}};
622
+
623
+ static constexpr __device__ bool supported() {
624
+ if (I == 8 && J == 4) return true;
625
+ return false;
626
+ }
627
+
628
+ static __device__ __forceinline__ int get_i(const int l) {
629
+ if constexpr (I == 8 && J == 4) {
630
+ return ((l / 2) * 4) + (threadIdx.x % 4);
631
+ } else {
632
+ NO_DEVICE_CODE;
633
+ return -1;
634
+ }
635
+ }
636
+
637
+ static __device__ __forceinline__ int get_j(const int l) {
638
+ if constexpr (I == 8 && J == 4) {
639
+ return ((threadIdx.x / 16) * 2) + (l % 2);
640
+ } else {
641
+ NO_DEVICE_CODE;
642
+ return -1;
643
+ }
644
+ }
645
+ };
646
+
647
+ #if defined(TURING_MMA_AVAILABLE)
648
+ template <int I, int J>
649
+ static __device__ __forceinline__ tile<I, J/2, half2> get_half2(const tile<I, J, float> & tile_float) {
650
+ tile<I, J/2, half2> ret;
651
+ #pragma unroll
652
+ for (int l0 = 0; l0 < tile_float.ne; l0 += 2) {
653
+ ret.x[l0/2] = make_half2(tile_float.x[l0 + 0], tile_float.x[l0 + 1]);
654
+ }
655
+ return ret;
656
+ }
657
+
658
+ static __device__ __forceinline__ tile<8, 8, half2> get_transposed(const tile<16, 4, half2> & t) {
659
+ tile<8, 8, half2> ret;
660
+ ret.x[0] = ggml_cuda_movmatrix(t.x[0]);
661
+ ret.x[1] = ggml_cuda_movmatrix(t.x[1]);
662
+
663
+ return ret;
664
+ }
665
+ #elif defined(AMD_WMMA_AVAILABLE) || defined(AMD_MFMA_AVAILABLE)
666
+ template <int I, int J>
667
+ static __device__ __forceinline__ tile<I, J/2, half2> get_half2(const tile<I, J, float> & tile_float) {
668
+ tile<I, J/2, half2> ret;
669
+ #pragma unroll
670
+ for (int l0 = 0; l0 < tile_float.ne; l0 += 2) {
671
+ ret.x[l0/2] = make_half2(tile_float.x[l0 + 0], tile_float.x[l0 + 1]);
672
+ }
673
+ return ret;
674
+ }
675
+
676
+ static __device__ __forceinline__ tile<8, 8, half2> get_transposed(const tile<16, 4, half2> & t) {
677
+ NO_DEVICE_CODE;
678
+ return tile<8, 8, half2>{};
679
+ }
680
+ #else // Volta
681
+ template <int I, int J>
682
+ static __device__ __forceinline__ tile<I, J/2, half2> get_half2(const tile<I, J, float> & tile_float) {
683
+ tile<I, J/2, half2> ret;
684
+ #pragma unroll
685
+ for (int l0 = 0; l0 < tile_float.ne; l0 += 4) {
686
+ ret.x[l0/2 + 0] = make_half2(tile_float.x[l0 + 0], tile_float.x[l0 + 1]);
687
+ ret.x[l0/2 + 1] = make_half2(tile_float.x[l0 + 2], tile_float.x[l0 + 3]);
688
+
689
+ // On Volta FP16 and FP32 tiles have a different memory layout,
690
+ // for the conversion threads with an offset of 2 need to exchange half their values:
691
+ ret.x[l0/2 + (((threadIdx.x % 4) / 2) ^ 1)] = __shfl_xor_sync(
692
+ 0xFFFFFFFF, ret.x[l0/2 + (((threadIdx.x % 4) / 2) ^ 1)], 2, WARP_SIZE);
693
+ }
694
+ return ret;
695
+ }
696
+ #endif // defined(TURING_MMA_AVAILABLE)
697
+
698
+ template <int I, int J, typename T, data_layout dl>
699
+ static __device__ __forceinline__ void load_generic(tile<I, J, T, dl> & t, const T * __restrict__ xs0, const int stride) {
700
+ #pragma unroll
701
+ for (int l = 0; l < t.ne; ++l) {
702
+ t.x[l] = xs0[t.get_i(l)*stride + t.get_j(l)];
703
+ }
704
+ }
705
+
706
+ template <typename T>
707
+ static __device__ __forceinline__ void load_ldmatrix(
708
+ tile<8, 8, T> & t, const T * __restrict__ xs0, const int stride) {
709
+ #ifdef TURING_MMA_AVAILABLE
710
+ int * xi = (int *) t.x;
711
+ const int * xs = (const int *) xs0 + (threadIdx.x % t.I) * stride + ((threadIdx.x / t.I) * (t.J / 2)) % t.J;
712
+ asm volatile("ldmatrix.sync.aligned.m8n8.x2.b16 {%0, %1}, [%2];"
713
+ : "=r"(xi[0]), "=r"(xi[1])
714
+ : "l"(xs));
715
+ #else
716
+ GGML_UNUSED_VARS(t, xs0, stride);
717
+ NO_DEVICE_CODE;
718
+ #endif // TURING_MMA_AVAILABLE
719
+ }
720
+
721
+ template <typename T, data_layout dl>
722
+ static __device__ __forceinline__ void load_ldmatrix(
723
+ tile<16, 4, T, dl> & t, const T * __restrict__ xs0, const int stride) {
724
+ #ifdef TURING_MMA_AVAILABLE
725
+ int * xi = (int *) t.x;
726
+ const int * xs = (const int *) xs0 + (threadIdx.x % t.I) * stride;
727
+ asm volatile("ldmatrix.sync.aligned.m8n8.x2.b16 {%0, %1}, [%2];"
728
+ : "=r"(xi[0]), "=r"(xi[1])
729
+ : "l"(xs));
730
+ #elif defined(AMD_WMMA_AVAILABLE)
731
+ #ifdef RDNA3
732
+ static_assert(dl == DATA_LAYOUT_I_MAJOR_MIRRORED, "bad data layout");
733
+ static_assert(sizeof(t.x) == 16, "bad ne");
734
+ ggml_cuda_memcpy_1<8>(t.x + 0, xs0 + t.get_i(0)*stride + 0);
735
+ ggml_cuda_memcpy_1<8>(t.x + 2, xs0 + t.get_i(0)*stride + 2);
736
+ #else
737
+ static_assert(dl == DATA_LAYOUT_I_MAJOR, "bad data layout");
738
+ static_assert(sizeof(t.x) == 8, "bad ne");
739
+ ggml_cuda_memcpy_1<8>(t.x, xs0 + t.get_i(0)*stride + t.get_j(0));
740
+ #endif // RDNA3
741
+ #elif defined(AMD_MFMA_AVAILABLE)
742
+ static_assert(sizeof(t.x) == 4, "bad ne");
743
+ ggml_cuda_memcpy_1<4>(t.x, xs0 + t.get_i(0)*stride + t.get_j(0));
744
+ #else
745
+ GGML_UNUSED_VARS(t, xs0, stride);
746
+ NO_DEVICE_CODE;
747
+ #endif // TURING_MMA_AVAILABLE
748
+ }
749
+
750
+ template <typename T, data_layout dl>
751
+ static __device__ __forceinline__ void load_ldmatrix(
752
+ tile<16, 8, T, dl> & t, const T * __restrict__ xs0, const int stride) {
753
+ #if defined(TURING_MMA_AVAILABLE)
754
+ int * xi = (int * ) t.x;
755
+ const int * xs = (const int *) xs0 + (threadIdx.x % t.I) * stride + (threadIdx.x / t.I) * (t.J / 2);
756
+ asm volatile("ldmatrix.sync.aligned.m8n8.x4.b16 {%0, %1, %2, %3}, [%4];"
757
+ : "=r"(xi[0]), "=r"(xi[1]), "=r"(xi[2]), "=r"(xi[3])
758
+ : "l"(xs));
759
+ #elif defined(VOLTA_MMA_AVAILABLE)
760
+ ggml_cuda_memcpy_1<4*sizeof(T)>(t.x + 0, xs0 + t.get_i(0)*stride + 0);
761
+ ggml_cuda_memcpy_1<4*sizeof(T)>(t.x + 4, xs0 + t.get_i(4)*stride + 4);
762
+ #elif defined(AMD_WMMA_AVAILABLE)
763
+ #ifdef RDNA3
764
+ static_assert(dl == DATA_LAYOUT_I_MAJOR_MIRRORED, "bad data layout");
765
+ static_assert(sizeof(t.x) == 32, "bad ne");
766
+ ggml_cuda_memcpy_1<16>(t.x + 0, xs0 + t.get_i(0)*stride + 0);
767
+ ggml_cuda_memcpy_1<16>(t.x + 4, xs0 + t.get_i(0)*stride + 4);
768
+ #else
769
+ static_assert(dl == DATA_LAYOUT_I_MAJOR, "bad data layout");
770
+ static_assert(sizeof(t.x) == 16, "bad ne");
771
+ ggml_cuda_memcpy_1<16>(t.x, xs0 + t.get_i(0)*stride + t.get_j(0));
772
+ #endif // RDNA3
773
+ #elif defined(AMD_MFMA_AVAILABLE)
774
+ static_assert(sizeof(t.x) == 8, "bad ne");
775
+ ggml_cuda_memcpy_1<8>(t.x, xs0 + t.get_i(0)*stride + t.get_j(0));
776
+ #else
777
+ GGML_UNUSED_VARS(t, xs0, stride);
778
+ NO_DEVICE_CODE;
779
+ #endif // TURING_MMA_AVAILABLE
780
+ }
781
+
782
+ static __device__ __forceinline__ void load_ldmatrix(
783
+ tile<8, 4, half2, DATA_LAYOUT_I_MAJOR_MIRRORED> & t, const half2 * __restrict__ xs0, const int stride) {
784
+ ggml_cuda_memcpy_1<4*sizeof(half2)>(t.x, xs0 + t.get_i(0)*stride);
785
+ }
786
+
787
+ static __device__ __forceinline__ void load_ldmatrix(
788
+ tile<8, 4, half2, DATA_LAYOUT_J_MAJOR_MIRRORED> & t, const half2 * __restrict__ xs0, const int stride) {
789
+ #pragma unroll
790
+ for (int l0 = 0; l0 < t.ne; l0 += 2) {
791
+ ggml_cuda_memcpy_1<2*sizeof(half2)>(t.x + l0, xs0 + t.get_i(l0)*stride + t.get_j(l0));
792
+ }
793
+ }
794
+
795
+ static __device__ __forceinline__ void load_ldmatrix(
796
+ tile<32, 4, half2> & t, const half2 * __restrict__ xs0, const int stride) {
797
+ #if defined(VOLTA_MMA_AVAILABLE)
798
+ ggml_cuda_memcpy_1<4*sizeof(half2)>(t.x, xs0 + t.get_i(0)*stride);
799
+ #else
800
+ GGML_UNUSED_VARS(t, xs0, stride);
801
+ NO_DEVICE_CODE;
802
+ #endif // defined(VOLTA_MMA_AVAILABLE)
803
+ }
804
+
805
+ template <typename T>
806
+ static __device__ __forceinline__ void load_ldmatrix_trans(
807
+ tile<16, 8, T> & t, const T * __restrict__ xs0, const int stride) {
808
+ #ifdef TURING_MMA_AVAILABLE
809
+ int * xi = (int *) t.x;
810
+ const int * xs = (const int *) xs0 + (threadIdx.x % t.I) * stride + (threadIdx.x / t.I) * (t.J / 2);
811
+ asm volatile("ldmatrix.sync.aligned.m8n8.x4.trans.b16 {%0, %1, %2, %3}, [%4];"
812
+ : "=r"(xi[0]), "=r"(xi[2]), "=r"(xi[1]), "=r"(xi[3])
813
+ : "l"(xs));
814
+ #elif defined(AMD_MFMA_AVAILABLE) || defined(AMD_WMMA_AVAILABLE)
815
+ half * xh = (half *) t.x;
816
+ #pragma unroll
817
+ for (int l = 0; l < t.ne; ++l) {
818
+ xh[2*l + 0] = ((const half *) xs0)[(2*t.get_j(l) + 0)*(2*stride) + t.get_i(l)];
819
+ xh[2*l + 1] = ((const half *) xs0)[(2*t.get_j(l) + 1)*(2*stride) + t.get_i(l)];
820
+ }
821
+ #else
822
+ GGML_UNUSED_VARS(t, xs0, stride);
823
+ NO_DEVICE_CODE;
824
+ #endif // TURING_MMA_AVAILABLE
825
+ }
826
+
827
+ static __device__ __forceinline__ void mma(
828
+ tile<16, 8, int> & D, const tile<16, 4, int> & A, const tile<8, 4, int> & B) {
829
+ #ifdef TURING_MMA_AVAILABLE
830
+ #if __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
831
+ asm("mma.sync.aligned.m16n8k16.row.col.s32.s8.s8.s32 {%0, %1, %2, %3}, {%4, %5}, {%6}, {%0, %1, %2, %3};"
832
+ : "+r"(D.x[0]), "+r"(D.x[1]), "+r"(D.x[2]), "+r"(D.x[3])
833
+ : "r"(A.x[0]), "r"(A.x[1]), "r"(B.x[0]));
834
+ #else
835
+ // On Turing m16n8k16 mma is not available, use 2x m8n8k16 mma instead:
836
+ asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};"
837
+ : "+r"(D.x[0]), "+r"(D.x[1])
838
+ : "r"(A.x[0]), "r"(B.x[0]));
839
+ asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};"
840
+ : "+r"(D.x[2]), "+r"(D.x[3])
841
+ : "r"(A.x[1]), "r"(B.x[0]));
842
+ #endif // __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
843
+ #else
844
+ GGML_UNUSED_VARS(D, A, B);
845
+ NO_DEVICE_CODE;
846
+ #endif // TURING_MMA_AVAILABLE
847
+ }
848
+
849
+ static __device__ __forceinline__ void mma(
850
+ tile<16, 8, int> & D, const tile<16, 8, int> & A, const tile<8, 8, int> & B) {
851
+ #ifdef TURING_MMA_AVAILABLE
852
+ #if __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
853
+ asm("mma.sync.aligned.m16n8k32.row.col.s32.s8.s8.s32 {%0, %1, %2, %3}, {%4, %5, %6, %7}, {%8, %9}, {%0, %1, %2, %3};"
854
+ : "+r"(D.x[0]), "+r"(D.x[1]), "+r"(D.x[2]), "+r"(D.x[3])
855
+ : "r"(A.x[0]), "r"(A.x[1]), "r"(A.x[2]), "r"(A.x[3]), "r"(B.x[0]), "r"(B.x[1]));
856
+ #else
857
+ // On Turing m16n8k32 mma is not available, use 4x m8n8k16 mma instead:
858
+ asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};"
859
+ : "+r"(D.x[0]), "+r"(D.x[1])
860
+ : "r"(A.x[0]), "r"(B.x[0]));
861
+ asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};"
862
+ : "+r"(D.x[2]), "+r"(D.x[3])
863
+ : "r"(A.x[1]), "r"(B.x[0]));
864
+ asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};"
865
+ : "+r"(D.x[0]), "+r"(D.x[1])
866
+ : "r"(A.x[2]), "r"(B.x[1]));
867
+ asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};"
868
+ : "+r"(D.x[2]), "+r"(D.x[3])
869
+ : "r"(A.x[3]), "r"(B.x[1]));
870
+ #endif // __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
871
+ #else
872
+ GGML_UNUSED_VARS(D, A, B);
873
+ NO_DEVICE_CODE;
874
+ #endif // TURING_MMA_AVAILABLE
875
+ }
876
+
877
+ static __device__ __forceinline__ void mma(
878
+ tile<16, 4, half2> & D, const tile<16, 8, half2> & A, const tile<8, 8, half2> & B) {
879
+ #ifdef TURING_MMA_AVAILABLE
880
+ const int * Axi = (const int *) A.x;
881
+ const int * Bxi = (const int *) B.x;
882
+ int * Dxi = (int *) D.x;
883
+ #if __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
884
+ asm("mma.sync.aligned.m16n8k16.row.col.f16.f16.f16.f16 {%0, %1}, {%2, %3, %4, %5}, {%6, %7}, {%0, %1};"
885
+ : "+r"(Dxi[0]), "+r"(Dxi[1])
886
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[0]), "r"(Bxi[1]));
887
+ #else
888
+ // On Turing m16n8k16 mma is not available, use 2x m8n8k8 mma instead:
889
+ asm("mma.sync.aligned.m16n8k8.row.col.f16.f16.f16.f16 {%0, %1}, {%2, %3}, {%4}, {%0, %1};"
890
+ : "+r"(Dxi[0]), "+r"(Dxi[1])
891
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Bxi[0]));
892
+ asm("mma.sync.aligned.m16n8k8.row.col.f16.f16.f16.f16 {%0, %1}, {%2, %3}, {%4}, {%0, %1};"
893
+ : "+r"(Dxi[0]), "+r"(Dxi[1])
894
+ : "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[1]));
895
+ #endif // __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
896
+ #else
897
+ GGML_UNUSED_VARS(D, A, B);
898
+ NO_DEVICE_CODE;
899
+ #endif // TURING_MMA_AVAILABLE
900
+ }
901
+
902
+ static __device__ __forceinline__ void mma(
903
+ tile<16, 8, half2> & D, const tile<16, 8, half2> & A, const tile<16, 8, half2> & B) {
904
+ #ifdef TURING_MMA_AVAILABLE
905
+ const int * Axi = (const int *) A.x;
906
+ const int * Bxi = (const int *) B.x;
907
+ int * Dxi = (int *) D.x;
908
+ #if __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
909
+ asm("mma.sync.aligned.m16n8k16.row.col.f16.f16.f16.f16 {%0, %1}, {%2, %3, %4, %5}, {%6, %7}, {%0, %1};"
910
+ : "+r"(Dxi[0]), "+r"(Dxi[1])
911
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[0]), "r"(Bxi[2]));
912
+ asm("mma.sync.aligned.m16n8k16.row.col.f16.f16.f16.f16 {%0, %1}, {%2, %3, %4, %5}, {%6, %7}, {%0, %1};"
913
+ : "+r"(Dxi[2]), "+r"(Dxi[3])
914
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[1]), "r"(Bxi[3]));
915
+ #else
916
+ // On Turing m16n8k16 mma is not available, use 4x m8n8k8 mma instead:
917
+ asm("mma.sync.aligned.m16n8k8.row.col.f16.f16.f16.f16 {%0, %1}, {%2, %3}, {%4}, {%0, %1};"
918
+ : "+r"(Dxi[0]), "+r"(Dxi[1])
919
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Bxi[0]));
920
+ asm("mma.sync.aligned.m16n8k8.row.col.f16.f16.f16.f16 {%0, %1}, {%2, %3}, {%4}, {%0, %1};"
921
+ : "+r"(Dxi[0]), "+r"(Dxi[1])
922
+ : "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[2]));
923
+ asm("mma.sync.aligned.m16n8k8.row.col.f16.f16.f16.f16 {%0, %1}, {%2, %3}, {%4}, {%0, %1};"
924
+ : "+r"(Dxi[2]), "+r"(Dxi[3])
925
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Bxi[1]));
926
+ asm("mma.sync.aligned.m16n8k8.row.col.f16.f16.f16.f16 {%0, %1}, {%2, %3}, {%4}, {%0, %1};"
927
+ : "+r"(Dxi[2]), "+r"(Dxi[3])
928
+ : "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[3]));
929
+ #endif // __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
930
+ #elif defined(AMD_WMMA_AVAILABLE)
931
+ #if defined(RDNA4)
932
+ using halfx8_t = __attribute__((ext_vector_type(8))) _Float16;
933
+ halfx8_t& acc_frag = reinterpret_cast<halfx8_t&>(D.x[0]);
934
+ const halfx8_t& a_frag = reinterpret_cast<const halfx8_t&>(A.x[0]);
935
+ const halfx8_t& b_frag = reinterpret_cast<const halfx8_t&>(B.x[0]);
936
+ acc_frag = __builtin_amdgcn_wmma_f16_16x16x16_f16_w32_gfx12(a_frag, b_frag, acc_frag);
937
+ #else
938
+ GGML_UNUSED_VARS(D, A, B);
939
+ NO_DEVICE_CODE;
940
+ #endif // defined(RDNA4)
941
+ #elif defined(AMD_MFMA_AVAILABLE)
942
+ // MFMA: FP16 input, FP32 accumulate, convert back to half2.
943
+ using halfx4_t = __attribute__((ext_vector_type(4))) _Float16;
944
+ using floatx4_t = __attribute__((ext_vector_type(4))) float;
945
+
946
+ // Convert existing half2 accumulator to float for MFMA:
947
+ floatx4_t acc_f32;
948
+ {
949
+ const halfx4_t acc_h = reinterpret_cast<const halfx4_t&>(D.x[0]);
950
+ #pragma unroll
951
+ for (int i = 0; i < 4; ++i) {
952
+ acc_f32[i] = (float)acc_h[i];
953
+ }
954
+ }
955
+
956
+ const halfx4_t& a_frag = reinterpret_cast<const halfx4_t&>(A.x[0]);
957
+ const halfx4_t& b_frag = reinterpret_cast<const halfx4_t&>(B.x[0]);
958
+ acc_f32 = __builtin_amdgcn_mfma_f32_16x16x16f16(a_frag, b_frag, acc_f32, 0, 0, 0);
959
+
960
+ // Convert back to half2:
961
+ {
962
+ halfx4_t result_h;
963
+ #pragma unroll
964
+ for (int i = 0; i < 4; ++i) {
965
+ result_h[i] = (_Float16)acc_f32[i];
966
+ }
967
+ reinterpret_cast<halfx4_t&>(D.x[0]) = result_h;
968
+ }
969
+ #else
970
+ GGML_UNUSED_VARS(D, A, B);
971
+ NO_DEVICE_CODE;
972
+ #endif // TURING_MMA_AVAILABLE
973
+ }
974
+
975
+ template <data_layout dl_ab, data_layout dl_d>
976
+ static __device__ __forceinline__ void mma(
977
+ tile<16, 8, float, dl_d> & D, const tile<16, 8, float, dl_ab> & A, const tile<8, 8, float, dl_ab> & B) {
978
+ #ifdef AMPERE_MMA_AVAILABLE
979
+ const int * Axi = (const int *) A.x;
980
+ const int * Bxi = (const int *) B.x;
981
+ int * Dxi = (int *) D.x;
982
+ asm("mma.sync.aligned.m16n8k8.row.col.f32.tf32.tf32.f32 {%0, %1, %2, %3}, {%4, %5, %6, %7}, {%8, %9}, {%0, %1, %2, %3};"
983
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3])
984
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[0]), "r"(Bxi[1]));
985
+ #else
986
+ GGML_UNUSED_VARS(D, A, B);
987
+ NO_DEVICE_CODE;
988
+ #endif // AMPERE_MMA_AVAILABLE
989
+ }
990
+
991
+ template <data_layout dl_ab, data_layout dl_d>
992
+ static __device__ __forceinline__ void mma(
993
+ tile<16, 16, float, dl_d> & D, const tile<16, 8, float, dl_ab> & A, const tile<16, 8, float, dl_ab> & B) {
994
+ #ifdef AMD_MFMA_AVAILABLE
995
+ using floatx4_t = __attribute__((ext_vector_type(4))) float;
996
+ floatx4_t& acc_frag = reinterpret_cast<floatx4_t&>(D.x[0]);
997
+ #if defined(CDNA3)
998
+ using floatx2_t = __attribute__((ext_vector_type(2))) float;
999
+ const floatx2_t& a_frag = reinterpret_cast<const floatx2_t&>(A.x[0]);
1000
+ const floatx2_t& b_frag = reinterpret_cast<const floatx2_t&>(B.x[0]);
1001
+ acc_frag = __builtin_amdgcn_mfma_f32_16x16x8_xf32(a_frag, b_frag, acc_frag, 0, 0, 0);
1002
+ #elif defined(CDNA4) || defined(CDNA2) || defined(CDNA1)
1003
+ // CDNA4 (gfx950) does not support xf32 MFMA, use f32 path like CDNA2/CDNA1
1004
+ #pragma unroll
1005
+ for (int i = 0; i < 2; ++i) {
1006
+ acc_frag = __builtin_amdgcn_mfma_f32_16x16x4f32(A.x[i], B.x[i], acc_frag, 0, 0, 0);
1007
+ }
1008
+ #else
1009
+ GGML_UNUSED_VARS(D, A, B);
1010
+ NO_DEVICE_CODE;
1011
+ #endif // defined(CDNA3)
1012
+ #else
1013
+ GGML_UNUSED_VARS(D, A, B);
1014
+ NO_DEVICE_CODE;
1015
+ #endif // AMD_MFMA_AVAILABLE
1016
+ }
1017
+
1018
+ template <ggml_type type>
1019
+ static __device__ __forceinline__ void mma_block_scaled_fp4(tile<16, 8, float> & D,
1020
+ const tile<16, 8, int> & A,
1021
+ const tile<8, 8, int> & B,
1022
+ uint32_t a_scale,
1023
+ uint32_t b_scale) {
1024
+ #ifdef BLACKWELL_MMA_AVAILABLE
1025
+ const int * Axi = (const int *) A.x;
1026
+ const int * Bxi = (const int *) B.x;
1027
+ float * Dxi = (float *) D.x;
1028
+
1029
+ if constexpr (type == GGML_TYPE_MXFP4) {
1030
+ asm volatile(
1031
+ "mma.sync.aligned.kind::mxf4.block_scale.scale_vec::2X.m16n8k64.row.col.f32.e2m1.e2m1.f32.ue8m0 "
1032
+ "{%0, %1, %2, %3}, {%4, %5, %6, %7}, {%8, %9}, {%0, %1, %2, %3}, "
1033
+ "%10, {0, 0}, %11, {0, 0};"
1034
+ : "+f"(Dxi[0]), "+f"(Dxi[1]), "+f"(Dxi[2]), "+f"(Dxi[3])
1035
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[0]), "r"(Bxi[1]), "r"(a_scale), "r"(b_scale));
1036
+ } else {
1037
+ asm volatile(
1038
+ "mma.sync.aligned.kind::mxf4nvf4.block_scale.scale_vec::4X.m16n8k64.row.col.f32.e2m1.e2m1.f32.ue4m3 "
1039
+ "{%0, %1, %2, %3}, {%4, %5, %6, %7}, {%8, %9}, {%0, %1, %2, %3}, "
1040
+ "%10, {0, 0}, %11, {0, 0};"
1041
+ : "+f"(Dxi[0]), "+f"(Dxi[1]), "+f"(Dxi[2]), "+f"(Dxi[3])
1042
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[0]), "r"(Bxi[1]), "r"(a_scale), "r"(b_scale));
1043
+ }
1044
+ #else
1045
+ GGML_UNUSED_VARS(D, A, B, a_scale, b_scale);
1046
+ #endif // BLACKWELL_MMA_AVAILABLE
1047
+ }
1048
+
1049
+ static __device__ __forceinline__ void mma(
1050
+ tile<16, 8, float> & D, const tile<16, 8, half2> & A, const tile<8, 8, half2> & B) {
1051
+ #ifdef TURING_MMA_AVAILABLE
1052
+ const int * Axi = (const int *) A.x;
1053
+ const int * Bxi = (const int *) B.x;
1054
+ int * Dxi = (int *) D.x;
1055
+ #if __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
1056
+ asm("mma.sync.aligned.m16n8k16.row.col.f32.f16.f16.f32 {%0, %1, %2, %3}, {%4, %5, %6, %7}, {%8, %9}, {%0, %1, %2, %3};"
1057
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3])
1058
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[0]), "r"(Bxi[1]));
1059
+ #else
1060
+ // On Turing m16n8k16 mma is not available, use 2x m8n8k8 mma instead:
1061
+ asm("mma.sync.aligned.m16n8k8.row.col.f32.f16.f16.f32 {%0, %1, %2, %3}, {%4, %5}, {%6}, {%0, %1, %2, %3};"
1062
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3])
1063
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Bxi[0]));
1064
+ asm("mma.sync.aligned.m16n8k8.row.col.f32.f16.f16.f32 {%0, %1, %2, %3}, {%4, %5}, {%6}, {%0, %1, %2, %3};"
1065
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3])
1066
+ : "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[1]));
1067
+ #endif // __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
1068
+ #else
1069
+ GGML_UNUSED_VARS(D, A, B);
1070
+ NO_DEVICE_CODE;
1071
+ #endif // TURING_MMA_AVAILABLE
1072
+ }
1073
+
1074
+ static __device__ __forceinline__ void mma(
1075
+ tile<16, 8, float> & D, const tile<16, 8, nv_bfloat162> & A, const tile<8, 8, nv_bfloat162> & B) {
1076
+ #ifdef AMPERE_MMA_AVAILABLE
1077
+ const int * Axi = (const int *) A.x;
1078
+ const int * Bxi = (const int *) B.x;
1079
+ int * Dxi = (int *) D.x;
1080
+ asm("mma.sync.aligned.m16n8k16.row.col.f32.bf16.bf16.f32 {%0, %1, %2, %3}, {%4, %5, %6, %7}, {%8, %9}, {%0, %1, %2, %3};"
1081
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3])
1082
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[0]), "r"(Bxi[1]));
1083
+ #else
1084
+ GGML_UNUSED_VARS(D, A, B);
1085
+ NO_DEVICE_CODE;
1086
+ #endif // AMPERE_MMA_AVAILABLE
1087
+ }
1088
+
1089
+ template <data_layout dl_ab, data_layout dl_d>
1090
+ static __device__ __forceinline__ void mma(
1091
+ tile<16, 16, float, dl_d> & D, const tile<16, 8, half2, dl_ab> & A, const tile<16, 8, half2, dl_ab> & B) {
1092
+ #ifdef TURING_MMA_AVAILABLE
1093
+ const int * Axi = (const int *) A.x;
1094
+ const int * Bxi = (const int *) B.x;
1095
+ int * Dxi = (int *) D.x;
1096
+ #if __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
1097
+ asm("mma.sync.aligned.m16n8k16.row.col.f32.f16.f16.f32 {%0, %1, %2, %3}, {%4, %5, %6, %7}, {%8, %9}, {%0, %1, %2, %3};"
1098
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3])
1099
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[0]), "r"(Bxi[2]));
1100
+ asm("mma.sync.aligned.m16n8k16.row.col.f32.f16.f16.f32 {%0, %1, %2, %3}, {%4, %5, %6, %7}, {%8, %9}, {%0, %1, %2, %3};"
1101
+ : "+r"(Dxi[4]), "+r"(Dxi[5]), "+r"(Dxi[6]), "+r"(Dxi[7])
1102
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[1]), "r"(Bxi[3]));
1103
+ #else
1104
+ // On Turing m16n8k16 mma is not available, use 4x m8n8k8 mma instead:
1105
+ asm("mma.sync.aligned.m16n8k8.row.col.f32.f16.f16.f32 {%0, %1, %2, %3}, {%4, %5}, {%6}, {%0, %1, %2, %3};"
1106
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3])
1107
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Bxi[0]));
1108
+ asm("mma.sync.aligned.m16n8k8.row.col.f32.f16.f16.f32 {%0, %1, %2, %3}, {%4, %5}, {%6}, {%0, %1, %2, %3};"
1109
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3])
1110
+ : "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[2]));
1111
+ asm("mma.sync.aligned.m16n8k8.row.col.f32.f16.f16.f32 {%0, %1, %2, %3}, {%4, %5}, {%6}, {%0, %1, %2, %3};"
1112
+ : "+r"(Dxi[4]), "+r"(Dxi[5]), "+r"(Dxi[6]), "+r"(Dxi[7])
1113
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Bxi[1]));
1114
+ asm("mma.sync.aligned.m16n8k8.row.col.f32.f16.f16.f32 {%0, %1, %2, %3}, {%4, %5}, {%6}, {%0, %1, %2, %3};"
1115
+ : "+r"(Dxi[4]), "+r"(Dxi[5]), "+r"(Dxi[6]), "+r"(Dxi[7])
1116
+ : "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[3]));
1117
+ #endif // __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
1118
+ #elif defined(AMD_WMMA_AVAILABLE)
1119
+ #if defined(RDNA4)
1120
+ using halfx8_t = __attribute__((ext_vector_type(8))) _Float16;
1121
+ using floatx8_t = __attribute__((ext_vector_type(8))) float;
1122
+ floatx8_t& acc_frag = reinterpret_cast<floatx8_t&>(D.x[0]);
1123
+ const halfx8_t& a_frag = reinterpret_cast<const halfx8_t&>(A.x[0]);
1124
+ const halfx8_t& b_frag = reinterpret_cast<const halfx8_t&>(B.x[0]);
1125
+ acc_frag = __builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12(a_frag, b_frag, acc_frag);
1126
+ #elif defined(RDNA3)
1127
+ using halfx16_t = __attribute__((ext_vector_type(16))) _Float16;
1128
+ using floatx8_t = __attribute__((ext_vector_type(8))) float;
1129
+ floatx8_t& acc_frag = reinterpret_cast<floatx8_t&>(D.x[0]);
1130
+ const halfx16_t& a_frag = reinterpret_cast<const halfx16_t&>(A.x[0]);
1131
+ const halfx16_t& b_frag = reinterpret_cast<const halfx16_t&>(B.x[0]);
1132
+ acc_frag = __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(a_frag, b_frag, acc_frag);
1133
+ #else
1134
+ GGML_UNUSED_VARS(D, A, B);
1135
+ NO_DEVICE_CODE;
1136
+ #endif // RDNA4
1137
+ #elif defined(AMD_MFMA_AVAILABLE)
1138
+ using halfx4_t = __attribute__((ext_vector_type(4))) _Float16;
1139
+ using floatx4_t = __attribute__((ext_vector_type(4))) float;
1140
+ floatx4_t& acc_frag = reinterpret_cast<floatx4_t&>(D.x[0]);
1141
+ const halfx4_t& a_frag = reinterpret_cast<const halfx4_t&>(A.x[0]);
1142
+ const halfx4_t& b_frag = reinterpret_cast<const halfx4_t&>(B.x[0]);
1143
+ acc_frag = __builtin_amdgcn_mfma_f32_16x16x16f16(a_frag, b_frag, acc_frag, 0, 0, 0);
1144
+ #else
1145
+ GGML_UNUSED_VARS(D, A, B);
1146
+ NO_DEVICE_CODE;
1147
+ #endif // TURING_MMA_AVAILABLE
1148
+ }
1149
+
1150
+ template <data_layout dl_ab, data_layout dl_d>
1151
+ static __device__ __forceinline__ void mma(
1152
+ tile<16, 16, float, dl_d> & D, const tile<16, 8, nv_bfloat162, dl_ab> & A, const tile<16, 8, nv_bfloat162, dl_ab> & B) {
1153
+ #if defined(AMD_WMMA_AVAILABLE)
1154
+ #if defined(RDNA4)
1155
+ using bf16x8_t = __attribute__((ext_vector_type(8))) __bf16;
1156
+ using floatx8_t = __attribute__((ext_vector_type(8))) float;
1157
+ floatx8_t& acc_frag = reinterpret_cast<floatx8_t&>(D.x[0]);
1158
+ const bf16x8_t& a_frag = reinterpret_cast<const bf16x8_t&>(A.x[0]);
1159
+ const bf16x8_t& b_frag = reinterpret_cast<const bf16x8_t&>(B.x[0]);
1160
+ acc_frag = __builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12(a_frag, b_frag, acc_frag);
1161
+ #elif defined(RDNA3)
1162
+ using bf16x16_t = __attribute__((ext_vector_type(16))) __bf16;
1163
+ using floatx8_t = __attribute__((ext_vector_type(8))) float;
1164
+ floatx8_t& acc_frag = reinterpret_cast<floatx8_t&>(D.x[0]);
1165
+ const bf16x16_t& a_frag = reinterpret_cast<const bf16x16_t&>(A.x[0]);
1166
+ const bf16x16_t& b_frag = reinterpret_cast<const bf16x16_t&>(B.x[0]);
1167
+ acc_frag = __builtin_amdgcn_wmma_f32_16x16x16_bf16_w32(a_frag, b_frag, acc_frag);
1168
+ #else
1169
+ GGML_UNUSED_VARS(D, A, B);
1170
+ NO_DEVICE_CODE;
1171
+ #endif // defined(RDNA4)
1172
+ #elif defined(AMD_MFMA_AVAILABLE)
1173
+ using floatx4_t = __attribute__((ext_vector_type(4))) float;
1174
+ floatx4_t& acc_frag = reinterpret_cast<floatx4_t&>(D.x[0]);
1175
+ #if defined(CDNA4) || defined(CDNA3) || defined(CDNA2)
1176
+ using bf16x4_t = __attribute__((ext_vector_type(4))) __bf16;
1177
+ const bf16x4_t& a_frag = reinterpret_cast<const bf16x4_t&>(A.x[0]);
1178
+ const bf16x4_t& b_frag = reinterpret_cast<const bf16x4_t&>(B.x[0]);
1179
+ acc_frag = __builtin_amdgcn_mfma_f32_16x16x16bf16_1k(a_frag, b_frag, acc_frag, 0, 0, 0);
1180
+ #elif defined(CDNA1)
1181
+ #pragma unroll
1182
+ for (int i = 0; i < 2; ++i) {
1183
+ using bf16x2_t = __attribute__((ext_vector_type(2))) __bf16;
1184
+ const bf16x2_t& a_frag = reinterpret_cast<const bf16x2_t&>(A.x[i]);
1185
+ const bf16x2_t& b_frag = reinterpret_cast<const bf16x2_t&>(B.x[i]);
1186
+ acc_frag = __builtin_amdgcn_mfma_f32_16x16x8bf16(a_frag, b_frag, acc_frag, 0, 0, 0);
1187
+ }
1188
+ #else
1189
+ GGML_UNUSED_VARS(D, A, B);
1190
+ NO_DEVICE_CODE;
1191
+ #endif // defined(CDNA3) || defined(CDNA2)
1192
+ #else
1193
+ GGML_UNUSED_VARS(D, A, B);
1194
+ NO_DEVICE_CODE;
1195
+ #endif // defined(AMD_WMMA_AVAILABLE)
1196
+ }
1197
+
1198
+ template <data_layout dl_d, data_layout dl_ab>
1199
+ static __device__ __forceinline__ void mma(
1200
+ tile<16, 16, int, dl_d> & D, const tile<16, 8, int, dl_ab> & A, const tile<16, 8, int, dl_ab> & B) {
1201
+ #if defined(AMD_MFMA_AVAILABLE)
1202
+ using int32x4_t = __attribute__((__vector_size__(4 * sizeof(int)))) int;
1203
+ int32x4_t * acc = (int32x4_t *) D.x;
1204
+ #if defined(CDNA4) || defined(CDNA3)
1205
+ acc[0] = __builtin_amdgcn_mfma_i32_16x16x32_i8(((int64_t *) A.x)[0], ((int64_t *) B.x)[0], acc[0], 0, 0, 0);
1206
+ #elif defined(CDNA2) || defined(CDNA1)
1207
+ acc[0] = __builtin_amdgcn_mfma_i32_16x16x16i8(A.x[0], B.x[0], acc[0], 0, 0, 0);
1208
+ acc[0] = __builtin_amdgcn_mfma_i32_16x16x16i8(A.x[1], B.x[1], acc[0], 0, 0, 0);
1209
+ #endif // defined(CDNA4) || defined(CDNA3)
1210
+ #elif defined(AMD_WMMA_AVAILABLE)
1211
+ using int32x8_t = __attribute__((__vector_size__(8 * sizeof(int)))) int;
1212
+ int32x8_t * acc = (int32x8_t *) D.x;
1213
+ #if defined(RDNA4)
1214
+ using int32x2_t = __attribute__((__vector_size__(2 * sizeof(int)))) int;
1215
+ int32x2_t * a_vec = (int32x2_t *) A.x;
1216
+ int32x2_t * b_vec = (int32x2_t *) B.x;
1217
+ acc[0] = __builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12(true, a_vec[0], true, b_vec[0], acc[0], true);
1218
+ acc[0] = __builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12(true, a_vec[1], true, b_vec[1], acc[0], true);
1219
+ #elif defined(RDNA3)
1220
+ using int32x4_t = __attribute__((__vector_size__(4 * sizeof(int)))) int;
1221
+ int32x4_t * a_vec = (int32x4_t *) A.x;
1222
+ int32x4_t * b_vec = (int32x4_t *) B.x;
1223
+ acc[0] = __builtin_amdgcn_wmma_i32_16x16x16_iu8_w32(true, a_vec[0], true, b_vec[0], acc[0], true);
1224
+ acc[0] = __builtin_amdgcn_wmma_i32_16x16x16_iu8_w32(true, a_vec[1], true, b_vec[1], acc[0], true);
1225
+ #endif // RDNA4
1226
+ #else
1227
+ GGML_UNUSED_VARS(D, A, B);
1228
+ NO_DEVICE_CODE;
1229
+ #endif // AMD_MFMA_AVAILABLE
1230
+ }
1231
+
1232
+ static __device__ __forceinline__ void mma(
1233
+ tile<32, 32, int> & D, const tile<32, 4, int> & A, const tile<32, 4, int> & B) {
1234
+ #if defined(AMD_MFMA_AVAILABLE)
1235
+ using int32x16_t = __attribute__((__vector_size__(16 * sizeof(int)))) int;
1236
+ int32x16_t * acc = (int32x16_t *) D.x;
1237
+ #if defined(CDNA4) || defined(CDNA3)
1238
+ acc[0] = __builtin_amdgcn_mfma_i32_32x32x16_i8(((int64_t *) A.x)[0], ((int64_t *) B.x)[0], acc[0], 0, 0, 0);
1239
+ #elif defined(CDNA2) || defined(CDNA1)
1240
+ acc[0] = __builtin_amdgcn_mfma_i32_32x32x8i8(A.x[0], B.x[0], acc[0], 0, 0, 0);
1241
+ acc[0] = __builtin_amdgcn_mfma_i32_32x32x8i8(A.x[1], B.x[1], acc[0], 0, 0, 0);
1242
+ #endif // defined(CDNA4) || defined(CDNA3)
1243
+
1244
+ #else
1245
+ GGML_UNUSED_VARS(D, A, B);
1246
+ NO_DEVICE_CODE;
1247
+ #endif // AMD_MFMA_AVAILABLE
1248
+ }
1249
+
1250
+ template <typename T1, typename T2, int J, int K>
1251
+ static __device__ __forceinline__ void mma(
1252
+ tile<32, J, T1> & D, const tile<32, K, T2> & A, const tile<J, K, T2> & B) {
1253
+ tile <16, J, T1> * D16 = reinterpret_cast< tile<16, J, T1> *>(&D);
1254
+ const tile<16, K, T2> * A16 = reinterpret_cast<const tile<16, K, T2> *>(&A);
1255
+ mma(D16[0], A16[0], B);
1256
+ mma(D16[1], A16[1], B);
1257
+ }
1258
+
1259
+ static __device__ __forceinline__ void mma(
1260
+ tile<32, 8, float> & D, const tile<32, 4, half2> & A, const tile<8, 4, half2, DATA_LAYOUT_I_MAJOR_MIRRORED> & B) {
1261
+ #if defined(VOLTA_MMA_AVAILABLE)
1262
+ const int * Axi = (const int *) A.x;
1263
+ const int * Bxi = (const int *) B.x;
1264
+ int * Dxi = (int *) D.x;
1265
+ asm("mma.sync.aligned.m8n8k4.row.col.f32.f16.f16.f32 "
1266
+ "{%0, %1, %2, %3, %4, %5, %6, %7}, {%8, %9}, {%10, %11}, {%0, %1, %2, %3, %4, %5, %6, %7};"
1267
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3]), "+r"(Dxi[4]), "+r"(Dxi[5]), "+r"(Dxi[6]), "+r"(Dxi[7])
1268
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Bxi[0]), "r"(Bxi[1]));
1269
+ asm("mma.sync.aligned.m8n8k4.row.col.f32.f16.f16.f32 "
1270
+ "{%0, %1, %2, %3, %4, %5, %6, %7}, {%8, %9}, {%10, %11}, {%0, %1, %2, %3, %4, %5, %6, %7};"
1271
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3]), "+r"(Dxi[4]), "+r"(Dxi[5]), "+r"(Dxi[6]), "+r"(Dxi[7])
1272
+ : "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[2]), "r"(Bxi[3]));
1273
+ #else
1274
+ GGML_UNUSED_VARS(D, A, B);
1275
+ NO_DEVICE_CODE;
1276
+ #endif // defined(VOLTA_MMA_AVAILABLE)
1277
+ }
1278
+
1279
+ static __device__ __forceinline__ void mma(
1280
+ tile<32, 4, half2> & D, const tile<32, 4, half2> & A, const tile<8, 4, half2, DATA_LAYOUT_J_MAJOR_MIRRORED> & B) {
1281
+ #if defined(VOLTA_MMA_AVAILABLE)
1282
+ const int * Axi = (const int *) A.x;
1283
+ const int * Bxi = (const int *) B.x;
1284
+ int * Dxi = (int *) D.x;
1285
+ asm("mma.sync.aligned.m8n8k4.row.row.f16.f16.f16.f16 "
1286
+ "{%0, %1, %2, %3}, {%4, %5}, {%6, %7}, {%0, %1, %2, %3};"
1287
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3])
1288
+ : "r"(Axi[0]), "r"(Axi[1]), "r"(Bxi[0]), "r"(Bxi[1]));
1289
+ asm("mma.sync.aligned.m8n8k4.row.row.f16.f16.f16.f16 "
1290
+ "{%0, %1, %2, %3}, {%4, %5}, {%6, %7}, {%0, %1, %2, %3};"
1291
+ : "+r"(Dxi[0]), "+r"(Dxi[1]), "+r"(Dxi[2]), "+r"(Dxi[3])
1292
+ : "r"(Axi[2]), "r"(Axi[3]), "r"(Bxi[2]), "r"(Bxi[3]));
1293
+ #else
1294
+ GGML_UNUSED_VARS(D, A, B);
1295
+ NO_DEVICE_CODE;
1296
+ #endif // defined(VOLTA_MMA_AVAILABLE)
1297
+ }
1298
+
1299
+ template <data_layout dl_d, data_layout dl_ab>
1300
+ static __device__ __forceinline__ void mma(
1301
+ tile<16, 16, int, dl_d> & D, const tile<16, 4, int, dl_ab> & A, const tile<16, 4, int, dl_ab> & B) {
1302
+ #if defined(AMD_MFMA_AVAILABLE)
1303
+ using int32x4_t = __attribute__((__vector_size__(4 * sizeof(int)))) int;
1304
+ int32x4_t * acc = (int32x4_t *) D.x;
1305
+ #if defined(CDNA4) || defined(CDNA3)
1306
+ const int64_t xA = uint32_t(A.x[0]);
1307
+ const int64_t xB = uint32_t(B.x[0]);
1308
+ acc[0] = __builtin_amdgcn_mfma_i32_16x16x32_i8(xA, xB, acc[0], 0, 0, 0);
1309
+ #elif defined(CDNA2) || defined(CDNA1)
1310
+ acc[0] = __builtin_amdgcn_mfma_i32_16x16x16i8(A.x[0], B.x[0], acc[0], 0, 0, 0);
1311
+ #endif // defined(CDNA4) || defined(CDNA3)
1312
+ #elif defined(AMD_WMMA_AVAILABLE)
1313
+ using int32x8_t = __attribute__((__vector_size__(8 * sizeof(int)))) int;
1314
+ int32x8_t * acc = (int32x8_t *) D.x;
1315
+ #if defined(RDNA4)
1316
+ using int32x2_t = __attribute__((__vector_size__(2 * sizeof(int)))) int;
1317
+ int32x2_t * a_vec = (int32x2_t *) A.x;
1318
+ int32x2_t * b_vec = (int32x2_t *) B.x;
1319
+ acc[0] = __builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12(true, a_vec[0], true, b_vec[0], acc[0], false);
1320
+ #elif defined(RDNA3)
1321
+ using int32x4_t = __attribute__((__vector_size__(4 * sizeof(int)))) int;
1322
+ int32x4_t * a_vec = (int32x4_t *) A.x;
1323
+ int32x4_t * b_vec = (int32x4_t *) B.x;
1324
+ acc[0] = __builtin_amdgcn_wmma_i32_16x16x16_iu8_w32(true, a_vec[0], true, b_vec[0], acc[0], false);
1325
+ #endif // RDNA4
1326
+ #else
1327
+ GGML_UNUSED(D);
1328
+ GGML_UNUSED(A);
1329
+ GGML_UNUSED(B);
1330
+ NO_DEVICE_CODE;
1331
+ #endif // AMD_WMMA_AVAILABLE
1332
+ }
1333
+ }