tilelang.tools.lower_trace.core¶
IR lower trace — zero-intrusion debug tool for visualizing compilation passes.
Monkey-patches tvm.ir.transform.Pass.__call__ and PassPipeline.lower
to automatically capture IR before/after every pass and generate diff reports.
This module reads its configuration (TL_LOWER_TRACE / TL_LOWER_TRACE_DIR)
through the centralized tilelang.env environment, or via values passed
programmatically to enable().
Supports two architectures:
- New: PassPipeline.lower (each backend registers a pipeline object)
- Old: phase-based functions called from tilelang.engine.lower
Usage:
TL_LOWER_TRACE=1 python my_kernel.py # HTML report
TL_LOWER_TRACE=terminal python my_kernel.py # terminal diff only
TL_LOWER_TRACE=both python my_kernel.py # both terminal and HTML
Attributes¶
Classes¶
Result of running a single pass. |
Functions¶
Module Contents¶
- tilelang.tools.lower_trace.core.STATUS_COMPLETED = 'completed'¶
- tilelang.tools.lower_trace.core.STATUS_FAILED = 'failed'¶
- tilelang.tools.lower_trace.core.STATUS_SKIPPED = 'skipped'¶
- tilelang.tools.lower_trace.core.STATUS_CODEGEN = 'codegen'¶
- class tilelang.tools.lower_trace.core.LowerRecord¶
Result of running a single pass.
- phase: str¶
- name: str¶
- index: int¶
- before_text: str¶
- after_text: str¶
- add_lines: int = 0¶
- del_lines: int = 0¶
- status: str = 'completed'¶
- error_msg: str = ''¶
- tilelang.tools.lower_trace.core.enable(*, mode=_UNSET, trace_dir=_UNSET, codegen_output=_UNSET)¶
Enable IR pass tracing via monkey-patching.
- Parameters:
mode (str | None, optional) – Force a trace mode (
'terminal','html','both', orNoneto disable). When omitted, the mode is read from theTL_LOWER_TRACEenv var (viatilelang.env) or a priorenableoverride.trace_dir (str | None, optional) – Force the trace output base directory. When omitted, falls back to the
TL_LOWER_TRACE_DIRenv var, then./tmp/lower_trace_dir.codegen_output (str | None, optional) – Path to save the codegen-generated C++/CUDA/etc. source code. When omitted, defaults to
<script_dir>/codegen.cpp(inside the per-script output directory, beside.run_records/). PassNoneexplicitly to suppress all extra saves. See_wrap_codegen_ffifor the three-file (<path>/<path>.original/<path>.latest) patch-and-recompile workflow.
- tilelang.tools.lower_trace.core.disable()¶
Remove the pass tracing hook and restore original behavior.
- tilelang.tools.lower_trace.core.reset()¶
Clear collected records and section cache.
_script_diris preserved (stable across runs, holds codegen files + html symlink)._run_diris also preserved: clearing it here would split a single run into two directories, because pre-pipeline passes (which lazily create it via_ensure_run_dir) run beforePassPipeline.lower/_wrap_phaseinvokesreseton its first run. A fresh_run_dirfor each subsequent run is instead established directly in_traced_pipeline_lower/_wrap_phase(when_run_counter > 1), without callingresetso that records keep accumulating across runs.