Module Sarek_codegen.Sarek_ir_cuda_coopmat_preamble

The CUDA/HIP cooperative-matrix helpers, emitted before extern "C" when the kernel has a cooperative-matrix statement (Sarek_ir_cuda_coopmat).

The AMD helpers have C++ linkage and one pointer type each, so a buffer of the wrong element type is a compile error rather than a reinterpretation.

Each operand helper names an access pattern, not an operand: load_a_* reads 16 contiguous elements per lane starting at p + i + l16 * s, which is an A fragment row-major and a B fragment column-major; load_b_* reads 16 elements s apart starting at p + i + l16, a B fragment row-major and an A fragment column-major. The contiguous form is the one the compiler turns into vector loads.

The stride is long long, so every offset product (l16 * s, e * s, 2 * j * s) is computed in 64 bits: an int product overflows once the stride passes 2^31 / 15 elements, although every element the fragment touches is addressable.

val amd : string
val scale_add : string

The CM_scale_add helper (docs/design/coopmat-scaled-accumulate.md), emitted only in a kernel that has the statement, so every other cooperative-matrix kernel keeps its source byte for byte.

val cuda : string
val text : scale_add:bool -> string

text ~scale_add is the whole preamble, with the CM_scale_add helper when scale_add.