Module Rig_amd_abi.Code_object
Code objects, the programs AMD GPUs run.
Code objects, the programs AMD GPUs run.
A code object is the ELF object a compiler links for one processor: a GPU, or a generic processor whose code objects every GPU of a generation runs. A device loads its image at an address of its memory, and runs its kernels from there. Each kernel has a kernel descriptor in the image, which a dispatch reads: where the kernel's code starts, the memory it takes, and the registers it sets up for its waves.
The image (image) is size bytes: the object's sections laid out as Rig_elf lays out its image, zeros up to size, then the word each of its relocations computes written over them, in the object's order. It starts at the object's lowest section the image holds, so the headers and tables a linker puts before its code are not loaded. Each relocation writes an R_AMDGPU_REL64 word, S + A - P: its target's offset plus the relocation's addend, less the word's own offset. The image therefore holds wherever it is loaded. A loader writes it into its destination.
Offsets are offsets in the image, in bytes.
type tThe type for code objects: an ELF object for AMD GPUs, and what its relocations write over its image.
of_string obj reads the code object obj. It is Error msg, msg saying why, if:
objis not an ELF object for AMD GPUs (Rig_elf.of_string);- it names no processor LLVM knows, or a generic one in a code object before version 6 or of generic version
0; - a relocation is of a kind other than
R_AMDGPU_REL64, keeps its addend outside its entry, or reaches outside the image; - its image exceeds
2{^48}bytes, or a kernel's descriptor or first instruction lies outside it; - a kernel takes more than a dispatch gives: over 511 * 512 bytes of LDS, or more scratch per lane than a wave's scratch register holds on its generation, 131056 bytes on GFX9 and GFX10, 131068 on GFX11 and 1048572 from GFX12;
- a note runs past its section, or the metadata is malformed, bounds a kernel's workgroups outside [
1;1024] work-items, or places an argument outside the kernel's arguments.
target co is the processor co is compiled for, as LLVM names it: a GPU, such as "gfx1201", or a generic processor, such as "gfx12-generic".
runs_on co g is true iff g runs co: co is compiled for Gpu.processor g, or for a generic processor that LLVM lists it under.
size co is the length of co's image, in bytes: the size of the object's image as Rig_elf lays it out, rounded up to whole 32-bit words.
kernels co is the names of co's kernels, in increasing order: each name such that co defines the symbol name ^ ".kd" in its image.
The type for the implicit arguments a kernel reads, which its dispatcher writes among its arguments. A kernel learns its grid's and its workgroups' sizes from them.
type kernel = {- #
descriptor : int;(*The offset of its kernel descriptor.
*) - #
entry : int;(*The offset of its first instruction.
*) - #
group_segment : int;(*The bytes of LDS a workgroup takes.
*) - #
private_segment : int;(*The bytes of scratch a work-item takes.
*) - #
kernarg_size : int;(*The bytes of its arguments: the descriptor's size if nonzero, otherwise the metadata's
*).kernarg_segment_size, or0if neither gives one. - #
rsrc1 : int;(*Its
*)COMPUTE_PGM_RSRC1, as the compiler set it. - #
rsrc2 : int;(*Its
*)COMPUTE_PGM_RSRC2, as the compiler set it. - #
rsrc3 : int;(*Its
*)COMPUTE_PGM_RSRC3, as the compiler set it. - #
wave32 : bool;(*
*)trueiff its waves are 32 lanes wide, else 64. - #
dispatch_ptr : bool;(*
*)trueiff its waves read the address of their dispatch packet from user SGPRs. - #
private_segment_buffer : bool;(*
*)trueiff its waves read a buffer descriptor of their scratch from their first four user SGPRs. - #
max_threads : int;(*The most work-items its workgroups have: its
*).max_flat_workgroup_sizein the object's metadata, or 1024, the most of any GPU, if the metadata does not bound it. - #
explicit_size : int;(*The bytes of its explicit arguments, which its caller writes: the end of the last argument of its metadata that is not implicit (
*)hidden). It is0if its metadata lists no explicit argument, andkernarg_sizeif the metadata does not describe the kernel.
}The type for kernels, as their code object describes them.