Skip to content

Conversation

@kurisu6912
Copy link
Collaborator

@kurisu6912 kurisu6912 commented Nov 10, 2025

This is a fix of #1198

Summary by CodeRabbit

  • Tests

  • Refactor

    • Standardized type annotations for buffer handling functions across the codebase
    • Updated internal type validation and checking to properly handle buffer types consistently
    • Refined function signatures for descriptor initialization and manipulation operations
    • Improved overall type safety and consistency in buffer-related utilities

@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 10, 2025

Walkthrough

A new test file for issue 1198 is added, and type annotations in builtin.py are updated to consistently use tir.Buffer instead of Buffer for descriptor and buffer-related function parameters across multiple functions.

Changes

Cohort / File(s) Summary
New test file for issue 1198
testing/python/issue/test_tilelang_issue_1198.py
Adds test module with test_issue_1198() test function and a @T.prim_func decorated foo() function accepting a 32-element int32 buffer. Includes standard entry point.
Type annotation updates to buffer parameters
tilelang/language/builtin.py
Updates function signatures to use tir.Buffer instead of Buffer: warpgroup_fence_operand(), initialize_wgmma_descriptor(), initialize_tcgen05_descriptor(), and increase_descriptor_offset(). Adjusts internal type checks and shape validations to align with explicit tir.Buffer typing. Import surface updated to reference BufferLoad.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Review the new test structure and logic for issue 1198
  • Verify type annotation changes are consistently applied across all affected functions in builtin.py and that internal type guards reflect the new tir.Buffer references

🐰 Types now gleam with clarity bright,
tir.Buffer replaces old with might,
Tests spring forth to verify the way,
Descriptors march in new array!
A cleaner code awaits the day! ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title references fixing a 'buffer re-import typo in tilelang.languge,' but the actual changes show significant updates to buffer type annotations (Buffer → tir.Buffer) across multiple function signatures and a new test file, which goes beyond a simple typo fix. Revise the title to accurately reflect the scope of changes, such as 'Update buffer type annotations to use tir.Buffer across builtin functions' or provide clarification on what specific typo was fixed.
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 linked an issue Nov 10, 2025 that may be closed by this pull request
2 tasks
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 (1)
testing/python/issue/test_tilelang_issue_1198.py (1)

1-10: Test implementation looks good.

The test correctly validates that T.Buffer is accessible from the tilelang.language module. The implementation is straightforward and appropriate for a regression test.

Optional style note: Line 6 has a trailing comma in the list [32,]. While syntactically correct, it's typically used for multi-element lists. Consider [32] for consistency with single-element list conventions.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85218bd and ca8e74d.

📒 Files selected for processing (2)
  • testing/python/issue/test_tilelang_issue_1198.py (1 hunks)
  • tilelang/language/__init__.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.14.3)
tilelang/language/__init__.py

85-85: Redefinition of unused Buffer from line 19

Remove definition: Buffer

(F811)


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

Remove unused noqa directive

(RUF100)

⏰ 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

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 (3)
tilelang/language/builtin.py (2)

601-630: LGTM - Type annotations updated correctly

The function signature and type checks have been properly updated to use tir.Buffer. The logic correctly validates the descriptor shape and converts it to a BufferLoad when needed.

Consider extracting the long error message to improve code style:

-    if not isinstance(descriptor, (BufferLoad, tir.Buffer)):
-        raise TypeError("Descriptor must be a tvm.tir.Buffer or tvm.tir.BufferLoad.")
+    DESCRIPTOR_TYPE_ERROR = "Descriptor must be a tvm.tir.Buffer or tvm.tir.BufferLoad."
+    if not isinstance(descriptor, (BufferLoad, tir.Buffer)):
+        raise TypeError(DESCRIPTOR_TYPE_ERROR)

632-664: LGTM - Consistent type annotation updates

The function follows the same pattern as initialize_wgmma_descriptor with proper type checks and validation.

Consider extracting the long error message for consistency:

-    if not isinstance(descriptor, (BufferLoad, tir.Buffer)):
-        raise TypeError("Descriptor must be a tvm.tir.Buffer or tvm.tir.BufferLoad.")
+    DESCRIPTOR_TYPE_ERROR = "Descriptor must be a tvm.tir.Buffer or tvm.tir.BufferLoad."
+    if not isinstance(descriptor, (BufferLoad, tir.Buffer)):
+        raise TypeError(DESCRIPTOR_TYPE_ERROR)
testing/python/issue/test_tilelang_issue_1198.py (1)

5-11: Consider enhancing the test to verify the fix

The test successfully validates that the syntax is correct, but it doesn't actually exercise any of the changed functions (e.g., warpgroup_fence_operand, initialize_wgmma_descriptor) that now use tir.Buffer.

Consider adding a test that actually uses one of the updated functions to ensure the buffer type handling works correctly:

def test_issue_1198():
    @T.prim_func
    def foo(x: T.Buffer([32], "int32")):
        # Test that buffer can be used with updated function signatures
        T.evaluate(T.tir.call_intrin("handle", "dummy", x))

Or test one of the descriptor functions if applicable to your testing environment.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca8e74d and 32bdb07.

📒 Files selected for processing (2)
  • testing/python/issue/test_tilelang_issue_1198.py (1 hunks)
  • tilelang/language/builtin.py (7 hunks)
🧰 Additional context used
🪛 Ruff (0.14.3)
tilelang/language/builtin.py

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

(TRY003)


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

(TRY003)


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

(TRY003)


681-682: Parenthesize a and b expressions when chaining and and or together, to make the precedence clear

Parenthesize the and subexpression

(RUF021)

⏰ 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 (2)
tilelang/language/builtin.py (2)

11-11: LGTM - Consistent import pattern

The removal of Buffer from the direct import is correct, as the code now consistently uses tir.Buffer throughout the file.


433-490: LGTM - Correct type annotation update

The function signature and isinstance check at line 459 have been correctly updated to use tir.Buffer, maintaining consistency with the import changes.

Comment on lines +678 to 683
if not isinstance(descriptor, (BufferLoad, tir.Buffer)):
raise TypeError("Descriptor must be a tvm.tir.Buffer or tvm.tir.BufferLoad.")

if isinstance(descriptor, Buffer) and len(descriptor.shape) != 1 or descriptor.shape[0] != 1:
if isinstance(descriptor, tir.Buffer) and len(
descriptor.shape) != 1 or descriptor.shape[0] != 1:
raise ValueError("Descriptor must be a 1D buffer of size 1.")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix operator precedence issue in condition

Lines 681-682 have a logic error due to operator precedence. The condition:

if isinstance(descriptor, tir.Buffer) and len(descriptor.shape) != 1 or descriptor.shape[0] != 1:

Evaluates as: (isinstance(descriptor, tir.Buffer) and len(descriptor.shape) != 1) or (descriptor.shape[0] != 1)

This could cause an AttributeError when descriptor is a BufferLoad, as the second part of the or evaluates without the isinstance guard.

Apply this diff to fix the precedence:

-    if isinstance(descriptor, tir.Buffer) and len(
-            descriptor.shape) != 1 or descriptor.shape[0] != 1:
+    if isinstance(descriptor, tir.Buffer) and (len(descriptor.shape) != 1 or descriptor.shape[0] != 1):

Additionally, consider extracting the error message:

-    if not isinstance(descriptor, (BufferLoad, tir.Buffer)):
-        raise TypeError("Descriptor must be a tvm.tir.Buffer or tvm.tir.BufferLoad.")
+    DESCRIPTOR_TYPE_ERROR = "Descriptor must be a tvm.tir.Buffer or tvm.tir.BufferLoad."
+    if not isinstance(descriptor, (BufferLoad, tir.Buffer)):
+        raise TypeError(DESCRIPTOR_TYPE_ERROR)
🧰 Tools
🪛 Ruff (0.14.3)

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

(TRY003)


681-682: Parenthesize a and b expressions when chaining and and or together, to make the precedence clear

Parenthesize the and subexpression

(RUF021)


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

(TRY003)

🤖 Prompt for AI Agents
In tilelang/language/builtin.py around lines 678 to 683, the conditional has an
operator precedence bug causing the descriptor.shape[0] check to run for
non-Buffer objects; change the condition to guard both shape checks behind the
isinstance test by grouping the shape checks with parentheses (e.g. if
isinstance(descriptor, tir.Buffer) and (len(descriptor.shape) != 1 or
descriptor.shape[0] != 1): raise ValueError(...)), and extract the ValueError
message into a small named variable or constant above the check so the message
is declared once and reused.

@LeiWang1999 LeiWang1999 merged commit d5fda27 into tile-ai:main Nov 10, 2025
6 checks passed
RubiaCx pushed a commit to RubiaCx/tilelang that referenced this pull request Nov 24, 2025
* Fix Buffer re-import typo in tilelang.langugage

* fix lint error
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] TVM FFI encountered a Segfault in 0.1.6.post2

2 participants