Repository navigation
[Backend] Dispatch host CodeGen through backend registry - #2446
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! 🚀 |
📝 WalkthroughWalkthroughA new ChangesHost Codegen Registry System
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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/backend/README.md (1)
185-188: 🧹 Nitpick | 🔵 Trivial | 💤 Low valueVary "Keep" sentence starters to improve readability.
Lines 185–188 have three consecutive bullet points opening with "Keep," which creates repetitive phrasing. Reword one or two to improve variety while maintaining clarity.
- Keep `tilelang/language` and `tilelang/tileop` backend-neutral. - Keep backend-specific pass ordering in the backend package. -- Keep backend-specific host-codegen dispatch and host preparation hooks in the - backend package. +- Backend-specific host-codegen dispatch and host preparation hooks should stay + in the backend package. - Keep backend-specific device-codegen dispatch in the backend package.🤖 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/backend/README.md` around lines 185 - 188, The three consecutive bullet points in the backend package architecture section (covering pass ordering, host-codegen dispatch and hooks, and device-codegen dispatch) all begin with "Keep," creating repetitive phrasing that reduces readability. Reword one or two of these bullet points to use alternative sentence starters or phrasings that convey the same information while maintaining clarity and variety, such as restructuring around the component names or using action-oriented language instead of "Keep."Source: Linters/SAST tools
🤖 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/backend/README.md`:
- Around line 185-188: The three consecutive bullet points in the backend
package architecture section (covering pass ordering, host-codegen dispatch and
hooks, and device-codegen dispatch) all begin with "Keep," creating repetitive
phrasing that reduces readability. Reword one or two of these bullet points to
use alternative sentence starters or phrasings that convey the same information
while maintaining clarity and variety, such as restructuring around the
component names or using action-oriented language instead of "Keep."
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: eabaf237-b57d-44a8-8ef6-dd155f93f839
📒 Files selected for processing (6)
tilelang/backend/README.mdtilelang/backend/__init__.pytilelang/backend/host_codegen.pytilelang/cpu/codegen.pytilelang/engine/lower.pytilelang/metal/codegen.py
Summary
Overview
This PR refactors the backend architecture by introducing a centralized host codegen registry system that decentralizes host code generation dispatch logic. The changes move backend-specific host build logic out of the engine's lowering layer and into their respective backend packages, improving separation of concerns and maintainability.
Key Changes
New Infrastructure: Host Codegen Registry
tilelang/backend/host_codegen.pyintroduces a new registry system with:HostCodegenFunc,HostCodegenHookFunc,TargetPredicate)HostCodegendataclass to register host code generators with optional target predicatesHostCodegenHookdataclass to register backend-owned host preparation hooksregister_host_codegen()andregister_lazy_host_codegen()for host code generatorsregister_host_codegen_hook()andregister_lazy_host_codegen_hooks()for host hooksallowed_host_codegens_for_target()to query available host codegensresolve_host_codegen()to select the matching host codegenapply_host_codegen_hooks()to apply all matching hooks sequentiallyglobal_func_host_codegen()to wrap TVM global functionsBackend Integration
tilelang/backend/__init__.pyexposes the new host codegen infrastructure and registers lazy entries for"c"and"llvm"host codegens and"metal"host codegen hooks.tilelang/cpu/codegen.pynow registers host code generators for both"c"and"llvm"target kinds, wiring them to their respective TVM build functions (target.build.tilelang_c_hostandtarget.build.llvm).tilelang/metal/codegen.pyintroduces_mark_host_metal_context()hook function and registers it via the new host codegen hook system for Metal-specific host context preparation, keeping host-side Metal logic self-contained within the Metal backend.Simplified Engine Lowering
tilelang/engine/lower.pyrefactors thehost_codegenfunction to use the new registry system instead of inline dispatch logic. It now:apply_host_codegen_hooks()resolve_host_codegen(target_host).lower()This eliminates hardcoded conditionals and centralizes host build dispatch logic in backend packages.
Documentation
tilelang/backend/README.mdupdated to clarify backend ownership boundaries, distinguishingtilelang/backend/as shared infrastructure fromtilelang/<backend>/as backend-owned implementations. Added documentation for the host-codegen resolution flow, including the newapply_host_codegen_hooksstep and how backends register host build entries and hooks.