-
Couldn't load subscription status.
- Fork 286
[BugFix] alloc_var init failed to handle complex expression #1144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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! 🚀 |
WalkthroughAdds a new test for TileLang variable allocation and updates Changes
Sequence DiagramsequenceDiagram
participant User
participant alloc_var
participant BlockAttr as block_attr\n(tl.local_var_init)
participant BufferStore as T.buffer_store
participant Buffer as Buffer (returned)
User->>alloc_var: call alloc_var(dtype, init, scope)
alt init is primitive (int/float/IntImm/FloatImm)
alloc_var->>BlockAttr: emit tl.local_var_init attribute
BlockAttr->>Buffer: allocation with init metadata
else init is non-primitive
alloc_var->>BufferStore: emit T.buffer_store to write init
BufferStore->>Buffer: allocation with stored init
end
Buffer->>User: Buffer handle
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
testing/python/language/test_tilelang_language_var_init.py(1 hunks)tilelang/language/allocate.py(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tilelang/language/allocate.py (3)
src/op/builtin.h (1)
tvm(13-517)tilelang/language/ast/ir.py (3)
block_attr(430-438)init(361-369)buffer_store(1263-1300)testing/python/language/test_tilelang_language_alloc.py (1)
alloc_var(4-23)
testing/python/language/test_tilelang_language_var_init.py (1)
tilelang/language/allocate.py (3)
alloc_var(74-75)alloc_var(79-83)alloc_var(86-141)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Quick Lint
🔇 Additional comments (6)
testing/python/language/test_tilelang_language_var_init.py (2)
1-10: LGTM! Test structure is well-formed.The test setup correctly uses tilelang.jit and T.prim_func to create a kernel that exercises variable initialization behavior.
17-27: LGTM! Assertions validate the aliasing semantics.The test correctly verifies that
bcaptures the initial value ofa(1) anddcaptures the reassigned value (2), confirming that variable initialization semantics work as expected for both primitive and complex expressions.tilelang/language/allocate.py (4)
18-18: LGTM! Imports support the new type overloads and init logic.The
overloadimport enables proper type hints, whileBuffer,IntImm, andFloatImmare used for return type annotations and runtime type checking of initializers.Also applies to: 23-24
73-83: LGTM! Overload signatures correctly model the two main usage patterns.The overloads provide precise type information for type checkers:
- First overload: positional init parameter
- Second overload: keyword-only init parameter
This matches the flexible argument parsing in the implementation (lines 113-130).
101-106: LGTM! Documentation examples are clear and comprehensive.The examples cover all supported usage patterns and align with the overload signatures, making the API easy to understand.
137-140: LGTM! Conditional init logic correctly handles complex expressions.This is the core fix:
- Primitives (
int,float,IntImm,FloatImm) use the optimizedblock_attrpath withtl.local_var_init- Complex expressions (e.g., Buffer references, arithmetic expressions) use
T.buffer_storeto properly evaluate and store the resultThis enables initializing variables with expressions like
T.alloc_var('int32', init=some_buffer), which previously failed. The attribute name matches the constant defined insrc/op/builtin.h.
When init value of
T.alloc_varis not const, tilelang generates wrong code. This pr fix this by fallback to assignment.Summary by CodeRabbit
New Features
Tests