[Feature] Add compiler pass timing profiling - #2622
Conversation
|
👋 Hi! Thank you for contributing to the TileLang project. Please remember to run We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀 |
📝 WalkthroughWalkthroughTileLang adds pass profiling configuration, threshold validation, nested pass timing records, formatted reports, and timing instrumentation to JIT and grouped compilation phases. Profiling can be enabled through pass configuration or environment variables. ChangesPass profiling
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Configuration
participant JITKernel
participant PassContext
participant TileLangPassTimingInstrument
participant TimingReport
Configuration->>JITKernel: provide profiling flag and threshold
JITKernel->>PassContext: install pass instruments
PassContext->>TileLangPassTimingInstrument: record pass callbacks
TileLangPassTimingInstrument->>TimingReport: produce timing report on exit
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tilelang/jit/kernel.py (1)
239-255: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract shared instrument-setup helper to eliminate duplication.
The base-instrument construction (lines 239–242) and threshold-resolution logic (lines 244–251) are duplicated in
tilelang/autotuner/grouped_compile.py(lines 44–56). A shared factory would keep both call sites in sync if the setup logic evolves.♻️ Proposed shared helper in
tilelang/utils/pass_timing.pydef make_pass_instrument_factory(pass_configs: Mapping[str, Any]) -> Callable[[], tuple[list, object | None]]: """Return a zero-arg factory that produces fresh (instruments, timing_instrument) tuples.""" from tilelang import env from tilelang.transform import PassConfigKey base_pass_instruments: list = [] if pass_configs.get(PassConfigKey.TL_ENABLE_DUMP_IR): dump_ir_path = pass_configs.get(PassConfigKey.TL_DUMP_IR_DIR, "./dump_ir") base_pass_instruments.append(tvm.ir.instrument.DumpIR(dump_dir=dump_ir_path)) profile_threshold_ms: float | None = None if pass_configs.get(PassConfigKey.TL_PASS_PROFILE) or env.is_pass_profile_enabled(): profile_threshold_ms = resolve_pass_profile_threshold_ms( pass_configs, PassConfigKey.TL_PASS_PROFILE_THRESHOLD_MS, env.get_pass_profile_threshold_ms, ) def create_pass_instruments(): return build_pass_instruments(base_pass_instruments, profile_threshold_ms) return create_pass_instrumentsUsage in
kernel.py:- base_pass_instruments = [] - if pass_configs.get(PassConfigKey.TL_ENABLE_DUMP_IR): - dump_ir_path = pass_configs.get(PassConfigKey.TL_DUMP_IR_DIR, "./dump_ir") - base_pass_instruments.append(tvm.ir.instrument.DumpIR(dump_dir=dump_ir_path)) - - # Pass timing instrument - profile_threshold_ms = None - if pass_configs.get(PassConfigKey.TL_PASS_PROFILE) or env.is_pass_profile_enabled(): - profile_threshold_ms = resolve_pass_profile_threshold_ms( - pass_configs, - PassConfigKey.TL_PASS_PROFILE_THRESHOLD_MS, - env.get_pass_profile_threshold_ms, - ) - pass_instruments, timing_instrument = build_pass_instruments( - base_pass_instruments, - profile_threshold_ms, - ) + create_pass_instruments = make_pass_instrument_factory(pass_configs) + pass_instruments, timing_instrument = create_pass_instruments()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tilelang/jit/kernel.py` around lines 239 - 255, Extract the duplicated dump-IR and pass-profile setup from the kernel pass-instrument flow and grouped compilation into a shared make_pass_instrument_factory helper in pass_timing.py. Have the factory resolve configuration once and return a zero-argument creator that produces fresh instrument/timing tuples via build_pass_instruments, then update the affected call sites to use it while preserving existing configuration behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tilelang/jit/kernel.py`:
- Around line 239-255: Extract the duplicated dump-IR and pass-profile setup
from the kernel pass-instrument flow and grouped compilation into a shared
make_pass_instrument_factory helper in pass_timing.py. Have the factory resolve
configuration once and return a zero-argument creator that produces fresh
instrument/timing tuples via build_pass_instruments, then update the affected
call sites to use it while preserving existing configuration behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e490ab81-6db4-4cdc-8b95-30facf493cf5
📒 Files selected for processing (10)
src/op/builtin.ccsrc/op/builtin.htesting/python/components/test_tilelang_env.pytesting/python/debug/test_pass_timing.pytilelang/autotuner/grouped_compile.pytilelang/env.pytilelang/jit/kernel.pytilelang/transform/pass_config.pytilelang/utils/__init__.pytilelang/utils/pass_timing.py
Summary
Why not reuse TVM's PassTimingInstrument?
ExitPassContext, sorender()must be calledinside the
with PassContextblock.grouping.
Example
Summary
Adds configurable compiler pass-timing profiling for regular JIT and grouped compilation.
Highlights
PassConfig.tilelang.utils.C++ style / lint notes
src/op/builtin.ccandsrc/op/builtin.h.docs/developer_guide/cpp_style.md.