Module Ir.Compiled_kernels

What the device compiler made of a routine's kernels, read back from the compiled code (gh-ocannl-1530).

The schedule layer predicts a kernel's static workgroup-shared allocation (Schedule.workgroup_memory_bytes, the charge the seeding floors reproduce); this census holds the device compiler's own figure for the same kernel, so a test can relate the two. It is a domain-local bracket, like Compile_cost.with_census: a backend's link records one entry per kernel it links while a bracket is open on the linking domain, and nothing otherwise. Context.compile opens one around every link and keeps its records as the routine's compiled_kernels field (gh-ocannl-2515), so callers read the field rather than bracketing a compile themselves.

Which backends answer: Metal (staticThreadgroupMemoryLength of the compute pipeline state it creates at link), CUDA (CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES of the linked function) and HIP (HIP_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES), each read from the kernel the link already holds, at no extra load. The C backends declare no workgroup memory and record nothing, so an empty census is "no answer", never "zero bytes". A relink of retained code (Context.relink_outcome) records nothing; its routine carries the census of the compile its code came from.

type record = {
  1. kernel : string;
    (*

    The kernel's name, as the backend links it.

    *)
  2. static_workgroup_bytes : int;
    (*

    The static workgroup-shared (threadgroup / __shared__) bytes the compiled kernel allocates, as the driver reports them — rounded up to the backend's Backend_intf.codegen_capabilities.workgroup_reporting_granule (gh-ocannl-2426: 16 B on Metal, 1 B on CUDA and HIP).

    *)
}
val sexp_of_record : record -> Sexplib0.Sexp.t
val with_census : (unit -> 'a) -> 'a * record list

with_census f runs f with the census armed on this domain and returns its result with the records of the kernels linked meanwhile, in link order. A nested bracket's records are added to the enclosing one's as well when it closes.

val record : kernel:string -> static_workgroup_bytes:int -> unit

Adds a record to the innermost open bracket; a no-op outside any.