Module Sarek_execute.Coopmat_variant

Launch-time variant of a cooperative-matrix kernel on the CUDA backends.

wmma needs a 32-byte aligned address and a stride that is a multiple of 16 bytes, which the IR does not promise. The generators emit the bare instruction for an access they can prove aligned, and for every other access a run-time test with a staging path through a per-warp shared buffer (Sarek_ir_coopmat_align). A kernel whose accesses depend on scalar arguments (a GEMM's k and n) would pay that buffer on every launch, so the host decides instead: Sarek_ir_coopmat_align.derive reduces "every access is aligned" to a predicate on the kernel's int32 parameters, and at launch the actual arguments either satisfy it (the kernel marked with Sarek_ir_coopmat_align.mark_aligned: bare wmma, no check, no buffer) or not (the kernel as given: the staged variant). The marked kernel is a distinct IR value, built once per kernel, so Execute's source memo, which keys on the IR's physical identity, holds one source per variant (and per block) and each is compiled once.

Only the CUDA frameworks are concerned; every other backend, and a kernel with no cooperative-matrix statement, gets the kernel it was given. The base pointers are assumed 32-byte aligned (device allocations).

type outcome =
  1. | Aligned
    (*

    the marked variant: no check, no staging buffer

    *)
  2. | Staged
    (*

    the kernel as given: static proofs where they hold, run-time check and staging for the rest

    *)
  3. | Checked
    (*

    every access tested at run time: a launch argument's base pointer is not 32-byte aligned, which the static proofs assume

    *)
  4. | Not_applicable
    (*

    not a CUDA framework, or no cooperative matrix

    *)

What a launch runs.

val outcome_name : outcome -> string
val frameworks : string list
type entry = {
  1. applicable : bool;
  2. predicate : A.predicate option;
  3. aligned : Sarek_ir_types.kernel option;
    (*

    None: the kernel itself

    *)
  4. checked : Sarek_ir_types.kernel option;
  5. arrays : string list;
    (*

    the array parameters its accesses touch

    *)
}
val entry_key : entry Ir_memo.key
val entry_of : Sarek_ir_types.kernel -> entry
val required_alignment : int

The alignment, in bytes, wmma needs of an address.

val alignment_of_pointer : nativeint -> int

The largest power of two (at most 4096) dividing a device pointer; 0 is taken as maximally aligned.

val is_param : Sarek_ir_types.kernel -> Stdlib.String.t -> bool
val bases_aligned : Sarek_ir_types.kernel -> (Stdlib.String.t * int) list option -> Stdlib.String.t list -> bool
val relevant : framework:string -> Sarek_ir_types.kernel -> bool

Whether choose has anything to decide for k on framework: a CUDA framework and a kernel with cooperative-matrix statements. The launch path asks this first: for every other launch it is a string comparison against two names (a kernel on a CUDA framework: one physical comparison with the last kernel seen), and nothing is allocated.

val aligned_launches : int Stdlib.Atomic.t
val checked_launches : int Stdlib.Atomic.t
val staged_launches : int Stdlib.Atomic.t
val counts : unit -> int * int

(aligned, staged) launches counted so far.

val checked_count : unit -> int

Launches that ran the checked variant (a misaligned base pointer).

val choose_lazy : ?count:bool -> framework:string -> Sarek_ir_types.kernel -> scalars:(unit -> (string * int) list) -> bases:(unit -> (string * int) list option) -> Sarek_ir_types.kernel * outcome

choose ~framework k scalars is the kernel to generate and run for the scalar int32 arguments scalars (parameter name, value); ~count:false leaves the launch counters alone (introspection).

val choose : ?count:bool -> ?bases:(string * int) list -> framework:string -> Sarek_ir_types.kernel -> (string * int) list -> Sarek_ir_types.kernel * outcome

choose_lazy with the arguments in hand.