tvm_tirx.backend.cuda.ptx#

Table-driven PTX dialect (T.ptx).

One table (table), one generic engine (engine), thin generators (gen_helpers, gen_stubs, and gen_coverage). Importing this package registers every table entry as a TVM Op with a generic codegen; the T.ptx namespace itself is installed by the CUDA backend’s register_backend() via script_namespaces().

Classes#

PTXNamespace([table])

T.ptx — table-driven PTX instruction namespace.

Functions#

instruction_forms(instruction)

Return table entries and resolved modifiers for a fully spelled opcode.

instruction_name(instruction)

Return validated PTX text in table slot order, without binding operands.

Instruction entries#

python/tvm_tirx/backend/cuda/ptx/table.py defines TABLE and its InstructionEntry records. Each entry describes one operand shape; multiple entries may share a user-facing instruction mnemonic.

Field

Meaning

operands

Operand order, register or address kind, read/write direction, dtype, and register-group size.

slots

Modifier positions, legal tokens, and optional positions.

check, imm_check

Checks for modifier combinations and concrete immediate values.

asm_volatile, orders_memory

Inline-assembly retention and compiler memory-ordering requirements.

cert_arch

Architecture used by instruction certification tests.

Predication and special operands#

PTX call destinations are leading operands, and the call itself returns no value. Inside TVMScript, the keyword-only pred gates an instruction. For example, a predicated load can preserve the destination’s existing value when the predicate is false:

T.ptx.ld.global_.b32(value, pointer, pred=predicate, preserve_dst=True)

Here value must be an initialized writable destination, and pointer selects the memory to read. Special operand helpers include:

Helper

Meaning

T.ptx.pred(value)

Mark an operand as a PTX .pred register.

T.ptx.addr(base, byte_offset)

Form an immediate-offset address for an instruction that accepts it.

T.ptx.SINK

Supply PTX’s _ sink in a table-marked operand position.

Developer generators#

Run these commands from the repository root with the Python package available:

python -m tvm_tirx.backend.cuda.ptx.gen_helpers add -o /tmp/ptx_add.cuh
python -m tvm_tirx.backend.cuda.ptx.gen_stubs -o /tmp/ptx_stubs.pyi
python -m tvm_tirx.backend.cuda.ptx.gen_coverage > /tmp/ptx_coverage.txt

gen_helpers renders the selected family’s supported instruction forms. gen_stubs generates signatures for editor tooling, and gen_coverage reports instruction families and variants. These files support inspection; runtime code generation reads the instruction table directly. Each command’s --help describes its available options. The PTX TableGen guide follows an instruction through the implementation.