Generated-code inspection¶
Import these helpers from tirx_harness.dump_kernel. They accept a compiled
TVM executable or runtime module and expose CUDA source, Parallel Thread
Execution (PTX) assembly, native GPU assembly (SASS), and compiler resource
information. See the compilation example.
Extract code¶
- tirx_harness.dump_kernel.dump_module(mod, *, arch: str | None = None, ptx: bool = False, sass: bool = True, lineinfo: bool = True, function: str | None = None, outdir: str | None = None, name: str = 'kernel', quiet: bool = True) DumpResult¶
Dump CUDA / PTX / SASS from a compiled module (the
tvm_tirx.compileoutput).modis theExecutablereturned bytvm_tirx.compile(or a runtimeModule). CUDA is always returned;ptx/sasstoggle those stages, which shell out to nvcc/ptxas/cuobjdump.archdefaults to the local GPU (B200 ->sm_100a). Withoutdirset, artifacts are written there as<name>.{cu,ptx,cubin,sass,ptxas.log}and their paths returned in.paths; otherwise a temp dir is used and removed before returning.If a requested stage fails (bad arch, unknown
function, etc.) its field staysNoneand a message is appended to.errors(.okis thenFalse); the failure is printed to stderr only whenquiet=False.Example:
ex = tvm_tirx.compile(tvm_tirx.IRModule({"main": pf}), target="cuda", pipeline="tirx") d = dump_module(ex, ptx=True) assert d.ok, d.errors print(d.sass) # SASS text print(d.ptxas["registers"]) # 153
The requested assembly stages require CUDA toolkit executables. Set arch
explicitly when inspecting code for a GPU other than the local device.
sass=True by default; use ptx=False, sass=False to extract only CUDA source,
or call dump_cuda directly.
- tirx_harness.dump_kernel.dump_cuda(mod) str¶
Extract generated CUDA source from a compiled module (the
tvm_tirx.compileoutput).Accepts the
Executablereturned bytvm_tirx.compile(uses its.mod) or a runtimeModuledirectly. The device CUDA lives in an imported submodule (the top-level host module doesn’t carry it), so walk the import tree and return the first source that actually contains a__global__entry.
Results¶
- class tirx_harness.dump_kernel.DumpResult¶
Result of
dump_module()— text of each requested artifact + metadata.cudais always populated;ptx/sassonly when requested and the nvcc/cuobjdump step succeeded — if a requested stage fails, its field staysNoneand a message is appended toerrors(checkd.ok/d.errorsto tell “not requested” from “requested but failed”).ptxasholds the parsed register/spill/smem report andptxas_logits raw text.pathsmaps artifact -> written file, populated only for files actually written (requiresoutdir).- cuda: str¶
- arch: str¶
- symbols: list[str] = []¶
- ptx: str | None = None¶
- sass: str | None = None¶
- ptxas: dict¶
- ptxas_log: str | None = None¶
- paths: dict[str, str]¶
- errors: list[str] = []¶
- property ok: bool¶
True if no requested artifact stage failed.
ptxas is the CUDA assembler’s resource report. Its smem entry describes
static shared memory; an absent entry does not imply zero dynamic shared-memory
use. Check ok and errors before consuming a requested artifact. A failure
to extract the initial CUDA source raises ValueError directly.
Inspect existing text¶
- tirx_harness.dump_kernel.extract_symbols(cuda_src: str) list[str]¶
Return the
__global__kernel symbol names in generated CUDA source.The actual entry symbol comes from the PrimFunc’s
global_symbolattribute (e.g._kernel_kernel), NOT the IRModule key — so read it back from the emitted__global__ void [__launch_bounds__(...)] <name>(signature rather than guessing<key>_kernel.
- tirx_harness.dump_kernel.parse_ptxas(log: str) dict¶
Extract registers / spill / smem / barriers from a
ptxas -vlog.Caveats: only the first entry function’s report is parsed (single-kernel modules are the common case;
DumpResult.symbolslists all kernels). Thesmemkey is present only for static shared memory — kernels usingextern __shared__dynamic SMEM (most TIRx GEMM/attention kernels) don’t report it, so its absence does not mean “0 bytes SMEM”.