Skip to content

Conversation

@kurisu6912
Copy link
Collaborator

@kurisu6912 kurisu6912 commented Nov 21, 2025

This pr adds missing support for uint32x2 and some other details:

  1. allow expressions like T.uint32x2(1.0)
  2. allow T.uint64(0xffffffffffffffff)
  3. allow casting to uint in bitwise operation
a = T.uint32()
a & 0xffffffff
  1. add T.Ref in macro annotation to pass reference:
@T.macro
def swap(a: T.Ref, b: T.Ref):
    a, b = b, a
@T.prim_func
def foo():
    a = T.alloc_var(T.int32)
    b = T.alloc_var(T.int32)
    swap(a, b)

Summary by CodeRabbit

  • New Features

    • Added support for 2-element vector integer dtypes (int8x2, int16x2, int32x2, int64x2 and unsigned variants).
    • Introduced Ref as a new public API for variable references.
  • Improvements

    • Macro argument handling now accepts Ref annotations; Var usage emits a deprecation warning.
  • Tests

    • Added tests for integer immediates and Ref-based macro behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 21, 2025

Walkthrough

Updated TVM submodule pointer; added 2-element vector integer dtypes; exported a new Ref symbol and typing support; macro_arg now accepts Ref annotations (with Var deprecated); and added tests for integer immediates and macro Ref/Var behavior.

Changes

Cohort / File(s) Summary
Submodule Update
3rdparty/tvm
Updated tracked submodule commit pointer from 713e6ade56e... to ead90f669c39....
Vector Dtype Aliases
tilelang/language/v2/dtypes.py
Added 2-element vector dtype aliases (int8x2,int16x2,int32x2,int64x2,uint8x2,uint16x2,uint32x2,uint64x2); exposed them at runtime as dtype('...'); added TYPE_CHECKING stub classes; extended _all_dtypes/__all__; updated string↔dtype mappings; enhanced __dtype_call__ to accept integer literals via int_.
Public API: Ref export
tilelang/language/__init__.py
Exported Ref from tilelang.language public API (added to the from .proxy import (...) block).
Ref typing/runtime proxy
tilelang/language/proxy.py
Added TypeVar _T; introduced Ref(Generic[_T], tir.Var) under TYPE_CHECKING and a runtime class Ref placeholder; exposes Ref as a public symbol.
Macro arg validation
tilelang/language/v2/builder.py
macro_arg now accepts Ref annotations in addition to Var (emits deprecation warning for Var), validates local variable buffers for both, imports Ref locally to avoid top-level dependency, and raises ValueError for invalid args.
Tests: integer immediates
testing/python/language/test_tilelang_intimm.py
Added tests exercising TileLang integer immediates and bitwise masking across signed/unsigned widths and masks.
Tests: frontend Ref vs Var
testing/python/language/test_tilelang_language_frontend_v2.py
Added tests verifying macro behavior when passing T.Ref (paralleling existing T.Var tests) and asserting expected script content or error reporting.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Frontend as User/Frontend
  participant Builder as v2.builder.macro_arg
  participant Proxy as proxy.Ref/Var
  participant Validator as LocalVarValidator

  Frontend->>Builder: call macro with annotated arg (Ref or Var)
  note right of Builder `#f6f8ff`: Ref imported locally to avoid top-level deps
  Builder->>Proxy: inspect annotation type
  alt annotation is Ref
    Builder->>Validator: validate Ref path as local var buffer
    Validator-->>Builder: buffer / valid
  else annotation is Var
    Builder->>Validator: validate Var path (emit deprecation warning)
    Validator-->>Builder: buffer / valid
  else invalid
    Validator-->>Builder: raise ValueError
  end
  Builder-->>Frontend: return buffer or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Attention points:
    • dtype mapping and __dtype_call__ integer-literal handling in tilelang/language/v2/dtypes.py
    • correctness of TYPE_CHECKING vs runtime Ref definitions in tilelang/language/proxy.py
    • macro_arg branching, deprecation message, and local import in tilelang/language/v2/builder.py
    • new tests: ensure they exercise both success and error paths for Ref/Var

Possibly related PRs

Suggested reviewers

  • LeiWang1999
  • tzj-fxz

Poem

🐰 New refs and vectors hop in line,
Two-element dtypes snug and fine.
Macros now welcome Ref with care,
Tests ensure the rules are fair.
TVM pointer nudged—code springs to shine.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding uint32x2 support, unsigned implicit casting in bitwise operations, and T.Ref as a macro annotation—all confirmed by the file changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46b9cdb and 32184fc.

📒 Files selected for processing (1)
  • tilelang/language/v2/builder.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tilelang/language/v2/builder.py (1)
tilelang/language/proxy.py (2)
  • Ref (269-270)
  • Ref (278-279)
⏰ 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). (3)
  • GitHub Check: Test for Python 3.12 with Metal (on macos-latest)
  • GitHub Check: Test for Python 3.12 with CUDA-12.8 (on self-hosted-nvidia)
  • GitHub Check: Test for Python 3.12 with ROCm-6.3 (on self-hosted-amd)
🔇 Additional comments (2)
tilelang/language/v2/builder.py (2)

336-342: LGTM! Improved warning message.

The updated warning message is more explicit about the double declaration issue and provides a helpful suggestion to use T.alloc_var, making it more actionable for users.


477-492: Code implementation is correct; local import pattern verified as consistent with codebase conventions.

Verification confirms that the Ref import from tilelang.language.proxy is properly defined and the local import at line 478 is not necessary for circular dependency avoidance. No circular dependency exists between proxy.py and builder.py. The local import pattern is consistent with other imports in the same file (e.g., line 510), indicating this is an established code convention rather than a necessity.

The implementation correctly extends macro argument handling to support both Var and Ref annotations with appropriate backward compatibility via deprecation warning.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kurisu6912 kurisu6912 changed the title [Feat] Add missing support for uint32x2, add unsigned implicit cast in bitwise op [Feat] Add missing support for uint32x2, add unsigned implicit cast in bitwise op, add T.Ref as macro annotation Nov 21, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (2)
tilelang/language/__init__.py (1)

25-25: Consider removing the unused noqa directive.

Static analysis indicates the noqa: F401 directive is not needed. If Ref is properly used or exported, the directive can be removed for cleaner code.

Apply this diff:

-    Ref,  # noqa: F401
+    Ref,
testing/python/language/test_tilelang_intimm.py (1)

23-23: Inconsistent mask wrapping in bitwise operations.

Line 23 wraps the mask in T.uint64(0xffffffffffffffff), but earlier bitwise operations (lines 14, 17, 20) use bare hex literals. Consider making this consistent across all operations.

Either use type constructors consistently:

     a = T.int32()
-    a & 0x7fffffff
+    a & T.int32(0x7fffffff)

     a = T.uint32()
-    a & 0xffffffff
+    a & T.uint32(0xffffffff)

     a = T.int64()
-    a & 0x7fffffffffffffff
+    a & T.int64(0x7fffffffffffffff)

Or omit them consistently if implicit casting is the intended behavior being tested.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82d6e0b and d7bd28a.

📒 Files selected for processing (5)
  • testing/python/language/test_tilelang_intimm.py (1 hunks)
  • testing/python/language/test_tilelang_language_frontend_v2.py (1 hunks)
  • tilelang/language/__init__.py (1 hunks)
  • tilelang/language/proxy.py (2 hunks)
  • tilelang/language/v2/builder.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
testing/python/language/test_tilelang_intimm.py (1)
tilelang/language/v2/dtypes.py (4)
  • int32 (156-156)
  • uint32 (184-184)
  • int64 (157-157)
  • uint64 (185-185)
tilelang/language/v2/builder.py (1)
tilelang/language/proxy.py (2)
  • Ref (269-270)
  • Ref (278-279)
testing/python/language/test_tilelang_language_frontend_v2.py (2)
tilelang/language/v2/builder.py (4)
  • macro (159-169)
  • macro (553-590)
  • prim_func (152-156)
  • prim_func (659-752)
tilelang/language/proxy.py (2)
  • Ref (269-270)
  • Ref (278-279)
tilelang/language/__init__.py (1)
tilelang/language/proxy.py (2)
  • Ref (269-270)
  • Ref (278-279)
🪛 Ruff (0.14.5)
testing/python/language/test_tilelang_language_frontend_v2.py

425-425: Avoid specifying long messages outside the exception class

(TRY003)

tilelang/language/__init__.py

25-25: Unused noqa directive (non-enabled: F401)

Remove unused noqa directive

(RUF100)

🔇 Additional comments (3)
tilelang/language/v2/builder.py (1)

477-492: LGTM!

The macro argument handling correctly supports both Var and Ref annotations with appropriate deprecation warnings. The local import pattern avoids circular dependencies, and the validation logic properly ensures that only local.var buffers are accepted.

tilelang/language/proxy.py (1)

4-4: LGTM!

The Ref class implementation properly uses the TYPE_CHECKING pattern to provide generic typing support for type checkers while maintaining a lightweight runtime placeholder. This is a clean approach for adding typing-time reference semantics.

Also applies to: 267-270, 278-280

testing/python/language/test_tilelang_language_frontend_v2.py (1)

397-427: LGTM!

The new T.Ref tests properly validate macro behavior for reference annotations, mirroring the existing T.Var tests. The tests cover both successful usage and error cases appropriately.

Note: Static analysis suggests the error message on line 425 could be shorter or moved to the exception class definition, but this is a minor style consideration that matches the existing pattern in this file.

Comment on lines 5 to 23
def test_tilelang_intimm():
T.int32(0x7fffffff)
T.int32(-0x7fffffff-1)
T.uint32(0xffffffff)
T.int64(0x7fffffffffffffff)
T.int64(-0x7fffffffffffffff-1)
T.uint64(0xffffffffffffffff)

a = T.int32()
a & 0x7fffffff

a = T.uint32()
a & 0xffffffff

a = T.int64()
a & 0x7fffffffffffffff

a = T.uint64()
a & T.uint64(0xffffffffffffffff)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Add assertions to validate the test behavior.

The test creates integer immediates and bitwise expressions but doesn't validate that they work correctly. Without assertions, this test cannot detect regressions or verify the intended behavior.

Consider adding assertions to verify:

  • Integer immediate values are constructed correctly
  • Bitwise operations produce expected results
  • Type boundaries are respected

For example:

def test_tilelang_intimm():
    # Test integer immediate construction
    val = T.int32(0x7fffffff)
    assert isinstance(val, T.PrimExpr)
    
    # Test bitwise operations
    a = T.uint32()
    result = a & 0xffffffff
    assert isinstance(result, T.PrimExpr)
    # Add more specific validation...

@kurisu6912 kurisu6912 linked an issue Nov 21, 2025 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 0xFFFFFFFF recogized as -1

2 participants