Skip to content

[Refactor] add support for numpy dtype conversion#1255

Merged
LeiWang1999 merged 11 commits intotile-ai:mainfrom
kurisu6912:dtype-rev
Nov 17, 2025
Merged

[Refactor] add support for numpy dtype conversion#1255
LeiWang1999 merged 11 commits intotile-ai:mainfrom
kurisu6912:dtype-rev

Conversation

@kurisu6912
Copy link
Collaborator

@kurisu6912 kurisu6912 commented Nov 14, 2025

This pr introduces conversion from numpy data types into T.dtype

Summary by CodeRabbit

  • New Features

    • Added comprehensive public type declarations for TIR/IR operations to improve editor/type support.
    • Added a new time-recurrent example module with public utilities and a JIT kernel factory.
  • Refactor

    • Consolidated dtype handling into unified registries and a single dispatch path for Python, NumPy, and PyTorch types.
  • Chores

    • Added a stub-generation utility to produce typed stubs automatically.
  • Tests

    • Removed a deprecated PyTorch dtype equivalence test (now commented out).

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

Walkthrough

Adds a large TIR type-stub tilelang/language/tir/ir.pyi, refactors dtype mapping/dispatch in tilelang/language/v2/dtypes.py, and introduces tools and examples (stubgen.py, triteo_linear.py, small snippet a.py) plus a test comment-out change.

Changes

Cohort / File(s) Change Summary
TIR type-stub
tilelang/language/tir/ir.pyi
New stub file declaring 80+ TIR helper signatures (math, bitwise, comparisons, numeric constructors, memory/TVM intrinsics, PTX/barrier helpers, thread/reduction/matrix/MMA primitives). No implementations — only static type declarations.
Dtype registry & dispatch
tilelang/language/v2/dtypes.py
Replaced fragmented per-source dtype maps with consolidated registries: _PYTHON_DTYPE_TO_STR, _NUMPY_DTYPE_TO_STR, _TORCH_DTYPE_TO_STR, merged _DTYPE_TO_STR; added _STR_TO_TVM_DTYPE_CALL, get_tvm_dtype, and adapted __dtype_call__/__dtype_new__. Added import numpy as np.
Stub generator
stubgen.py
New script that parses tilelang/language/tir/op.py, extracts pseudo-type-docstrings, synthesizes typed FunctionDef stubs, and writes tilelang/language/tir/ir.pyi.
Recurrent kernel example
triteo_linear.py
New module implementing shift/pad utilities, a first-recurrence builder, block processing, and a JIT-wrapped kernel factory plus profiling/validation harness.
Small snippet
a.py
New snippet importing tilelang.tvm and torch, converting a torch dtype via tvm.runtime.convert and creating tvm.DataType('float32').
Tests
testing/python/language/test_tilelang_language_frontend_v2.py
Removed/disabled test_torch_eq() by commenting it out and leaving a "not supported now" placeholder.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant User
    participant Stubgen as stubgen.py
    participant OpModule as tilelang/language/tir/op.py
    participant IRStub as tilelang/language/tir/ir.pyi

    User->>Stubgen: run
    Stubgen->>OpModule: read & parse AST
    Stubgen->>Stubgen: extract pseudo-docstring types\nmap to PrimExpr/_T/etc.
    Stubgen->>IRStub: generate typed FunctionDef stubs
    Stubgen-->>User: write ir.pyi
    note right of IRStub `#DDEBF7`: New static type declarations\n(no runtime code)
Loading
sequenceDiagram
    autonumber
    participant Caller
    participant dtypes as dtypes.py
    participant Mappings as _DTYPE_TO_STR/_STR_TO_TVM_DTYPE_CALL
    participant tvm as TVM FFI

    Caller->>dtypes: __dtype_new__(value)
    dtypes->>Mappings: lookup value -> dtype_str
    Mappings-->>dtypes: dtype_str
    dtypes-->>Caller: dtype object

    Caller->>dtypes: __dtype_call__(dtype_str)
    dtypes->>Mappings: lookup dtype_str -> ffi_entry
    Mappings->>tvm: call ffi_entry
    tvm-->>dtypes: TVM dtype result
    dtypes-->>Caller: TVM dtype
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas needing extra attention:
    • Completeness and correctness of the many signatures in ir.pyi (types, optional Span, generics).
    • Correctness and coverage of _DTYPE_TO_STR / _STR_TO_TVM_DTYPE_CALL mappings (Python, NumPy, Torch edge cases).
    • Behavior of get_tvm_dtype and its interaction with existing dtype construction code.
    • stubgen.py parsing heuristics and robustness (error handling, assumptions about op.py format).
    • Correctness and numerical equivalence of triteo_linear.py kernel and JIT interfacing.

Possibly related PRs

Suggested reviewers

  • LeiWang1999
  • XuehaiPan

Poem

🐰
I hopped in code, a tiny stub,
Catalogued each TIR and rub.
Dtypes joined from far and near,
Kernels hum — the burrow cheers!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.80% 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 PR title '[Refactor] add support for numpy dtype conversion' directly aligns with the main objective: introducing conversion from numpy data types into T.dtype. The title clearly identifies the primary change as adding numpy dtype conversion support.
✨ 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.

LeiWang1999
LeiWang1999 previously approved these changes Nov 14, 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 (3)
tilelang/language/v2/dtypes.py (2)

77-96: Harden __dtype_call__ for missing FFI symbols

The new fast path via _STR_TO_TVM_DTYPE_CALL looks good, but unlike the fallback logic below, it does not guard against the case where the mapped FFI symbol doesn’t exist on tb_ffi. In that scenario you’d get a NoneType is not callable instead of the clearer TypeError you emit later.

You can align the behaviors like this:

 def __dtype_call__(self: dtype, expr=None, is_size_var: bool = False) -> tir.Var:
-    if self in _STR_TO_TVM_DTYPE_CALL:
-        attr = _STR_TO_TVM_DTYPE_CALL[self]
-        call = getattr(tb_ffi, attr, None)
-        return call(expr, is_size_var)
+    if self in _STR_TO_TVM_DTYPE_CALL:
+        attr = _STR_TO_TVM_DTYPE_CALL[self]
+        call = getattr(tb_ffi, attr, None)
+        if call is None:
+            raise TypeError(
+                f"Convert to datatype `{self}` is not supported by tvm\n"
+                f"calling failed on `tvm.script.ir_builder.tir._ffi_api.{attr}`"
+            )
+        return call(expr, is_size_var)

This keeps error reporting consistent regardless of whether you hit the explicit map or the derived-name path.

Consider running the existing TIR builder tests across the TVM versions you support to ensure all _STR_TO_TVM_DTYPE_CALL entries have corresponding FFI functions.

Also applies to: 100-103


128-135: Make dtype.__new__ idempotent and friendlier to more inputs

The revamped __dtype_new__ nicely centralizes Python/NumPy/Torch mappings, but:

  • Passing an existing dtype instance (or potentially an ir.Type) into dtype(...) now falls into the error branch, even though such calls are often expected to be idempotent.
  • The expected set mixes type objects and strings, which is fine, but can be noisy in error messages.

You can make this more robust and backwards-friendly with a small tweak:

 def __dtype_new__(cls, value: AnyDType) -> dtype:
-    if isinstance(value, str):
-        return __orig_dtype_new(cls, value)
-    elif value in _DTYPE_TO_STR:
-        return __orig_dtype_new(cls, _DTYPE_TO_STR[value])
-    else:
-        expected = set(list(_DTYPE_TO_STR.keys()) + list(_DTYPE_TO_STR.values()))
-        raise TypeError(f"Invalid DataType {value}({type(value)}), expect one of {expected}")
+    # Already a dtype: keep it idempotent.
+    if isinstance(value, dtype):
+        return value
+    if isinstance(value, str):
+        return __orig_dtype_new(cls, value)
+    if value in _DTYPE_TO_STR:
+        return __orig_dtype_new(cls, _DTYPE_TO_STR[value])
+    expected = set(_DTYPE_TO_STR.keys()) | set(_DTYPE_TO_STR.values())
+    raise TypeError(
+        f"Invalid DataType {value}({type(value)}), expect one of {expected}"
+    )

This should reduce surprising TypeErrors for callers that pass an existing dtype while keeping the new NumPy/Torch conversion semantics.

Please scan for call sites doing dtype(existing_dtype_or_type) to confirm this change matches their expectations and doesn’t mask any intentional validation.

tilelang/language/tir/ir.pyi (1)

58-59: Align span parameter typing for consistency in the stub

Most intrinsics here use span: Span | None = None, but a few keep span=None untyped (shift_left, shift_right, call_packed*, call_cpacked*). This is harmless at runtime (it’s a stub), but slightly degrades type-checking quality and consistency.

You could align these signatures as follows:

-def shift_left(x: _T, y: _T, span=None) -> _T: ...
-def shift_right(x: _T, y: _T, span=None) -> _T: ...
+def shift_left(x: _T, y: _T, span: Span | None = None) -> _T: ...
+def shift_right(x: _T, y: _T, span: Span | None = None) -> _T: ...
@@
-def call_packed(*args, span=None) -> _T: ...
-def call_cpacked(*args, span=None) -> _T: ...
-def call_packed_lowered(*args, span=None) -> _T: ...
-def call_cpacked_lowered(*args, span=None) -> _T: ...
+def call_packed(*args, span: Span | None = None) -> _T: ...
+def call_cpacked(*args, span: Span | None = None) -> _T: ...
+def call_packed_lowered(*args, span: Span | None = None) -> _T: ...
+def call_cpacked_lowered(*args, span: Span | None = None) -> _T: ...

This keeps the stub self-consistent and makes it easier for type checkers to track span usage.

Please confirm against the actual TVM TIR Python API signatures you’re targeting to ensure the annotated types and parameter names (especially span) are accurate.

Also applies to: 75-78

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c0072a and 34f6a4b.

📒 Files selected for processing (2)
  • tilelang/language/tir/ir.pyi (1 hunks)
  • tilelang/language/v2/dtypes.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tilelang/language/tir/ir.pyi (1)
tilelang/language/ast/ir.py (1)
  • func_name (206-214)
⏰ 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 (1)
tilelang/language/v2/dtypes.py (1)

44-65: ****

PyTorch exposes torch.uint16, torch.uint32, and torch.uint64 dtypes, so this module will not raise AttributeError at import time. The code snippet in lines 44–65 is valid as written, and the proposed conditional registration workaround is unnecessary.

Likely an incorrect or invalid review comment.

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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tilelang/language/v2/dtypes.py (1)

135-138: Return type annotation doesn't match implementation.

Line 136 returns value if it's an ir.Type, but the function signature declares -> dtype. This creates a type annotation mismatch.

If ir.Type is compatible with dtype, update the return annotation:

-def get_tvm_dtype(value: AnyDType) -> dtype:
+def get_tvm_dtype(value: AnyDType) -> Union[dtype, ir.Type]:

Otherwise, convert ir.Type to dtype:

 def get_tvm_dtype(value: AnyDType) -> dtype:
-    if isinstance(value, (dtype, ir.Type)):
-        return value
+    if isinstance(value, dtype):
+        return value
+    elif isinstance(value, ir.Type):
+        return dtype(str(value))  # or appropriate conversion
     return dtype(value)
♻️ Duplicate comments (1)
tilelang/language/v2/dtypes.py (1)

11-11: AnyDType annotation still missing NumPy types despite previous review feedback.

The type annotation remains incomplete even though this was flagged in the previous review. Runtime now accepts NumPy dtypes (via _NUMPY_DTYPE_TO_STR at lines 19-40), but the type hint does not reflect this.

Apply this fix as suggested in the previous review:

-AnyDType = Union[ir.Type, str, type, torch.dtype, dtype]
+AnyDType = Union[ir.Type, str, type, torch.dtype, dtype, "np.dtype", "np.generic"]
🧹 Nitpick comments (3)
tilelang/language/v2/dtypes.py (3)

92-115: Implicit dtype-to-string comparison may be fragile.

Line 93 checks if self in _STR_TO_TVM_DTYPE_CALL: where self is a dtype object but the dict has string keys. This relies on TVM's dtype.__eq__ implementation to compare with strings, which is an implicit dependency on internal TVM behavior.

Make the string conversion explicit for clarity and robustness:

 def __dtype_call__(self: dtype, expr=None, is_size_var: bool = False) -> tir.Var:
-    if self in _STR_TO_TVM_DTYPE_CALL:
-        attr = _STR_TO_TVM_DTYPE_CALL[self]
+    dtype_str = str(self)
+    if dtype_str in _STR_TO_TVM_DTYPE_CALL:
+        attr = _STR_TO_TVM_DTYPE_CALL[dtype_str]
         call = getattr(tb_ffi, attr, None)
         return call(expr, is_size_var)
     # try to construct the ffi call
-    if self.startswith('uint'):
-        val = 'UInt' + self[4:]
-    elif self.startswith('int'):
-        val = 'Int' + self[3:]
-    elif self.startswith('float'):
-        val = 'Float' + self[5:]
-    elif self.startswith('bfloat'):
-        val = 'BFloat' + self[6:]
+    if dtype_str.startswith('uint'):
+        val = 'UInt' + dtype_str[4:]
+    elif dtype_str.startswith('int'):
+        val = 'Int' + dtype_str[3:]
+    elif dtype_str.startswith('float'):
+        val = 'Float' + dtype_str[5:]
+    elif dtype_str.startswith('bfloat'):
+        val = 'BFloat' + dtype_str[6:]
     else:
-        raise TypeError(f'Invalid type {self}')
+        raise TypeError(f'Invalid type {dtype_str}')
     if '_' in val:
         first, second = val.split('_', maxsplit=1)
         val = first + second.upper()
     call = getattr(tb_ffi, val, None)
     if call is None:
-        raise TypeError(f"Convert to datatype `{self}` is not supported by tvm\n"
+        raise TypeError(f"Convert to datatype `{dtype_str}` is not supported by tvm\n"
                         f"calling failed on `tvm.script.ir_builder.tir._ffi_api.{val}`")
     return call(expr, is_size_var)

121-128: Minor: Simplify error message construction.

The logic is correct, but the error message construction can be slightly cleaner.

     else:
-        expected = set(list(_DTYPE_TO_STR.keys()) + list(_DTYPE_TO_STR.values()))
+        expected = set(_DTYPE_TO_STR.keys()) | set(_DTYPE_TO_STR.values())
         raise TypeError(f"Invalid DataType {value}({type(value)}), expect one of {expected}")

64-66: Consider removing or documenting commented code.

The reverse mappings are commented out. If these are not needed, remove them to keep the codebase clean. If they're planned for future use, add a TODO comment explaining the intent.

-# _STR_TO_TORCH_DTYPE = {v: k for k, v in _TORCH_DTYPE_TO_STR.items()}
-
-# _STR_TO_NUMPY_DTYPE = {v: k for k, v in _NUMPY_DTYPE_TO_STR.items()}
+# TODO: Add reverse mappings if needed for future dtype conversion utilities
+# _STR_TO_TORCH_DTYPE = {v: k for k, v in _TORCH_DTYPE_TO_STR.items()}
+# _STR_TO_NUMPY_DTYPE = {v: k for k, v in _NUMPY_DTYPE_TO_STR.items()}

Or simply remove them if not planned.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34f6a4b and da1a38a.

📒 Files selected for processing (1)
  • tilelang/language/v2/dtypes.py (2 hunks)
⏰ 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 (3)
tilelang/language/v2/dtypes.py (3)

13-17: LGTM! Python bool support restored.

The bool mapping has been correctly added, addressing the previous review concern about the behavior regression.


42-62: LGTM! Comprehensive Torch dtype mappings.

The Torch dtype mappings are thorough and correctly normalize aliases (e.g., torch.half'float16') to canonical names present in _STR_TO_TVM_DTYPE_CALL.


68-68: LGTM! Clean consolidation of dtype mappings.

The merge strategy correctly combines all three mapping dictionaries without key collisions, since Python, NumPy, and Torch types are distinct objects.

Comment on lines 19 to 40
_NUMPY_DTYPE_TO_STR = {
np.bool_: 'bool',
np.short: 'short',
np.int_: 'int32',
np.longlong: 'int64',
np.half: 'float16',
np.float_: 'float32',
np.double: 'float64',
np.int8: 'int8',
np.int16: 'int16',
np.int32: 'int32',
np.int64: 'int64',
np.uint8: 'uint8',
np.uint16: 'uint16',
np.uint32: 'uint32',
np.uint64: 'uint64',
np.float16: 'float16',
np.float32: 'float32',
np.float64: 'float64',
}

_NUMPY_DTYPE_TO_STR.update({np.dtype(k): v for k, v in _NUMPY_DTYPE_TO_STR.items()})
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 | 🔴 Critical

🧩 Analysis chain

Verify 'short' mapping and np.dtype() conversion pattern.

Two concerns:

  1. Missing FFI mapping: Line 21 maps np.short to 'short', but 'short' is absent from _STR_TO_TVM_DTYPE_CALL (lines 70-89). When dtype(np.short) is called, it will hit the fallback path in __dtype_call__ attempting to construct tvm.script.ir_builder.tir._ffi_api.Short, which may not exist.

  2. Unconventional pattern: Line 40's np.dtype(k) pattern (e.g., np.dtype(np.int32)) creates dtype objects from type objects. While this should work, it's an unusual approach that warrants testing.

Run this script to verify both concerns:


🏁 Script executed:

#!/bin/bash
# Verify 'short' and other missing type mappings work correctly

cat << 'PYEOF' > /tmp/test_dtype.py
import sys
sys.path.insert(0, '.')

from tilelang.language.v2 import dtypes
import numpy as np

# Test 1: Check if np.short works
try:
    result = dtypes.dtype(np.short)
    print(f"✓ np.short works: {result}")
except Exception as e:
    print(f"✗ np.short failed: {e}")

# Test 2: Check if np.dtype(np.int32) works
try:
    result = dtypes.dtype(np.dtype(np.int32))
    print(f"✓ np.dtype(np.int32) works: {result}")
except Exception as e:
    print(f"✗ np.dtype(np.int32) failed: {e}")

# Test 3: Check various numpy dtypes
test_types = [np.int8, np.int32, np.float32, np.bool_]
for t in test_types:
    try:
        result = dtypes.dtype(t)
        print(f"✓ {t.__name__} -> {result}")
    except Exception as e:
        print(f"✗ {t.__name__} failed: {e}")
PYEOF

python /tmp/test_dtype.py

Length of output: 666


I'll verify the code structure directly and check NumPy documentation on the np.dtype() pattern.


🏁 Script executed:

#!/bin/bash
# Verify the code structure and mappings

echo "=== Checking line 21 for np.short mapping ==="
sed -n '19,25p' tilelang/language/v2/dtypes.py

echo -e "\n=== Checking _STR_TO_TVM_DTYPE_CALL (lines 70-89) ==="
sed -n '70,89p' tilelang/language/v2/dtypes.py

echo -e "\n=== Checking line 40 and surrounding context ==="
sed -n '38,42p' tilelang/language/v2/dtypes.py

echo -e "\n=== Checking __dtype_call__ implementation ==="
rg -n -A 10 "def __dtype_call__" tilelang/language/v2/dtypes.py

Length of output: 1499


🌐 Web query:

Does numpy.dtype() work with numpy type objects like np.int32?

💡 Result:

Yes — np.dtype accepts NumPy scalar type objects like np.int32. Example: np.dtype(np.int32) returns a dtype('int32'). See the NumPy documentation. [1][2]

Sources

  • NumPy — Data type objects (dtype) (reference manual). [1]
  • NumPy — Specifying and constructing data types (1.25 docs). [2]

I need to see the complete __dtype_call__ implementation to understand what happens when 'short' doesn't match any pattern.


🏁 Script executed:

#!/bin/bash
# Get full __dtype_call__ implementation
rg -n -A 20 "def __dtype_call__" tilelang/language/v2/dtypes.py

Length of output: 848


Add 'short' to _STR_TO_TVM_DTYPE_CALL mapping.

The code maps np.short to the string 'short' (line 21), but 'short' is missing from _STR_TO_TVM_DTYPE_CALL (lines 70-89). When dtype(np.short) is called, it passes through __dtype_call__ (line 92), which:

  1. Checks if 'short' exists in the dictionary (line 93) — it doesn't
  2. Falls through to pattern matching (lines 98-105) — 'short' doesn't start with 'uint', 'int', 'float', or 'bfloat'
  3. Raises TypeError (line 107)

This also affects calls using np.dtype(np.short) due to the .update() on line 40.

Add 'short': 'Short' to _STR_TO_TVM_DTYPE_CALL. The np.dtype() pattern on line 40 is valid NumPy usage and requires no changes.

🤖 Prompt for AI Agents
tilelang/language/v2/dtypes.py lines ~19-40 and mapping usage around lines
70-107: the mapping contains np.short -> 'short' but '_STR_TO_TVM_DTYPE_CALL'
lacks a 'short' entry causing dtype(np.short) or dtype(np.dtype(np.short)) to
fall through and raise; add the missing mapping entry 'short': 'Short' to the
_STR_TO_TVM_DTYPE_CALL dictionary so __dtype_call__ can resolve 'short' directly
(no other changes to the np.dtype() update required).

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: 4

♻️ Duplicate comments (1)
tilelang/language/v2/dtypes.py (1)

11-17: Align AnyDType typing with the new NumPy support (optional typing polish)

Runtime-wise, the new registries _NUMPY_DTYPE_TO_STR and _DTYPE_TO_STR correctly support np.bool_, np.int32, np.dtype("float32"), etc. However, the AnyDType annotation hasn’t been updated and still reads:

AnyDType = Union[ir.Type, str, type, torch.dtype, dtype]

For type checkers, that means NumPy dtypes are seen as “wrong” even though they’re accepted at runtime.

If you want the typing story to match behavior, you could extend it to cover NumPy explicitly, for example:

-from typing import TYPE_CHECKING, Union
+from typing import TYPE_CHECKING, Union
+import numpy as np  # already imported above

-AnyDType = Union[ir.Type, str, type, torch.dtype, dtype]
+AnyDType = Union[ir.Type, str, type, torch.dtype, dtype, np.dtype, np.generic]

(or use np.typing.DTypeLike if that fits your typing conventions).

Not mandatory for correctness, but it keeps annotations honest with respect to the new NumPy integration.

What is the recommended static typing alias in NumPy (>=1.26) for “dtype-like” inputs that include `np.dtype`, scalar types (`np.float32`), and strings?

Also applies to: 19-39, 41-68, 134-137

🧹 Nitpick comments (4)
a.py (1)

1-6: Treat this as an example/benchmark, not import-time code

This looks like a quick local dtype-conversion experiment rather than production logic. Having it as a top-level module means it runs on import and adds noise to the repo.

Consider either deleting a.py or turning it into a proper example/test (with an if __name__ == "__main__": guard) so it doesn’t affect normal imports.

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

148-204: Avoid permanently commenting out test_torch_eq; update or replace it and add NumPy tests

Turning test_torch_eq into a commented block with “not supported now” silently drops coverage for a critical path (torch↔T dtype equality and T.dtype(torch_dtype) conversion), right when this PR is refactoring dtype handling.

Prefer to:

  • Either fix the expectations in test_torch_eq to match the new semantics, or mark it as xfail with a clear reason; and
  • Add a dedicated test that exercises the new NumPy dtype conversions (dtype(np.int32), dtype(np.dtype("float32")), etc.), similar to how this test covered torch dtypes.

That keeps the behavior explicit and protects against future regressions in dtype dispatch.

stubgen.py (1)

28-32: Tighten exception handling and clean up unused imports in the stub generator

For a one-off tool this is not blocking, but a couple of small improvements would make stubgen.py more robust:

  • Lines 76–79 and 83–86: except Exception only prints and continues. Narrowing to SyntaxError / ValueError, or at least documenting why a broad catch is needed, will quiet static analysis and make failures more intentional.
  • from logging.config import valid_ident and from argparse import ArgumentParser appear unused and can be dropped.

None of this affects runtime behavior of TileLang, but it simplifies future maintenance of the stub generator.

Also applies to: 76-86

triteo_linear.py (1)

12-33: Document or guard the allowed shift range in shift_with_zeros

shift_with_zeros assumes abs(shift) <= x.shape[dim]:

zeros_shape[dim] = abs(shift)
...
x.narrow(dim, 0, x.shape[dim] - shift)

If someone accidentally calls it with abs(shift) > x.shape[dim], x.shape[dim] - shift becomes negative and narrow will raise. In this file you only use shift as ±1, so it’s safe, but it would be good to either:

  • Explicitly document that precondition in the docstring, or
  • Clamp/early-return zeros when abs(shift) >= x.shape[dim].

That makes the helper safer to reuse elsewhere.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da1a38a and fc29eea.

📒 Files selected for processing (5)
  • a.py (1 hunks)
  • stubgen.py (1 hunks)
  • testing/python/language/test_tilelang_language_frontend_v2.py (1 hunks)
  • tilelang/language/v2/dtypes.py (2 hunks)
  • triteo_linear.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
a.py (1)
tilelang/language/v2/dtypes.py (1)
  • float32 (199-199)
triteo_linear.py (3)
tilelang/jit/kernel.py (1)
  • JITKernel (31-727)
tilelang/language/allocate.py (1)
  • alloc_fragment (59-70)
tilelang/language/loop.py (1)
  • Parallel (12-32)
🪛 Ruff (0.14.4)
stubgen.py

78-78: Do not catch blind exception: Exception

(BLE001)


85-85: Do not catch blind exception: Exception

(BLE001)

triteo_linear.py

14-14: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF002)


16-16: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean ( (LEFT PARENTHESIS)?

(RUF002)


16-16: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean ) (RIGHT PARENTHESIS)?

(RUF002)


16-16: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF002)


16-16: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean ( (LEFT PARENTHESIS)?

(RUF002)


16-16: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean ) (RIGHT PARENTHESIS)?

(RUF002)


38-38: Docstring contains ambiguous (FULLWIDTH COLON). Did you mean : (COLON)?

(RUF002)


43-43: Comment contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean ( (LEFT PARENTHESIS)?

(RUF003)


43-43: Comment contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean ) (RIGHT PARENTHESIS)?

(RUF003)


47-47: Comment contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean ( (LEFT PARENTHESIS)?

(RUF003)


47-47: Comment contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean ) (RIGHT PARENTHESIS)?

(RUF003)


49-49: Comment contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean ( (LEFT PARENTHESIS)?

(RUF003)


49-49: Comment contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean ) (RIGHT PARENTHESIS)?

(RUF003)


90-90: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)


92-92: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)

⏰ 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

stubgen.py Outdated
Comment on lines 94 to 97
fdef.body = [ast.parse('...')]
# funcs.append(fdef)
funcs[fdef.name] = fdef

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

Use a statement node for the stub body instead of an entire Module

fdef.body = [ast.parse('...')] assigns a Module node into a function body, where the AST normally expects stmt nodes (e.g., an Expr).

Safer and more conventional is:

-    fdef.body = [ast.parse('...')]
+    fdef.body = [ast.parse('...').body[0]]

This keeps the generated stubs structurally valid across CPython versions and tools that walk the AST.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fdef.body = [ast.parse('...')]
# funcs.append(fdef)
funcs[fdef.name] = fdef
fdef.body = [ast.parse('...').body[0]]
# funcs.append(fdef)
funcs[fdef.name] = fdef
🤖 Prompt for AI Agents
In stubgen.py around lines 94 to 97, fdef.body currently gets a Module node via
ast.parse('...'), which places a Module into a function body; replace that with
a statement node instead (for example assign fdef.body =
[ast.parse('...').body[0]] or construct an ast.Expr(ast.Constant('...')) with
appropriate lineno/col_offset) so the function body contains a proper stmt node
and the generated stubs remain valid for AST walkers and different CPython
versions.

Comment on lines +69 to +88
_STR_TO_TVM_DTYPE_CALL = {
'bool': 'Boolean',
'int8': 'Int8',
'int32': 'Int32',
'int64': 'Int64',
'uint8': 'UInt8',
'uint16': 'UInt16',
'uint32': 'UInt32',
'uint64': 'UInt64',
'float16': 'Float16',
'float32': 'Float32',
'float64': 'Float64',
'bfloat16': 'BFloat16',
'float8_e4m3': 'Float8E4M3',
'float8_e4m3fn': 'Float8E4M3FN',
'float8_e4m3fnuz': 'Float8E4M3FNUZ',
'float8_e5m2': 'Float8E5M2',
'float8_e5m2fnuz': 'Float8E5M2FNUZ',
'float8_e8m0fnu': 'Float8E8M0FNU'
}
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 | 🔴 Critical

🧩 Analysis chain

Use str(self) for dispatch in __dtype_call__ so the FFI mapping actually applies

Right now __dtype_call__ does:

def __dtype_call__(self: dtype, expr=None, is_size_var: bool = False) -> tir.Var:
    if self in _STR_TO_TVM_DTYPE_CALL:
        attr = _STR_TO_TVM_DTYPE_CALL[self]
        call = getattr(tb_ffi, attr, None)
        return call(expr, is_size_var)
    # try to construct the ffi call
    if self.startswith('uint'):
        ...

Two problems:

  • _STR_TO_TVM_DTYPE_CALL is keyed by strings like 'bool', 'float32', etc., but self is a tvm.DataType instance. The membership test therefore never succeeds, so special cases such as 'bool' -> 'Boolean' are effectively dead code.
  • The subsequent self.startswith(...) calls assume tvm.DataType behaves like a string. It’s much safer (and clearer) to normalize to a string once and operate on that.

A minimal, robust fix is:

 def __dtype_call__(self: dtype, expr=None, is_size_var: bool = False) -> tir.Var:
-    if self in _STR_TO_TVM_DTYPE_CALL:
-        attr = _STR_TO_TVM_DTYPE_CALL[self]
-        call = getattr(tb_ffi, attr, None)
-        return call(expr, is_size_var)
-    # try to construct the ffi call
-    if self.startswith('uint'):
-        val = 'UInt' + self[4:]
-    elif self.startswith('int'):
-        val = 'Int' + self[3:]
-    elif self.startswith('float'):
-        val = 'Float' + self[5:]
-    elif self.startswith('bfloat'):
-        val = 'BFloat' + self[6:]
+    key = str(self)
+    if key in _STR_TO_TVM_DTYPE_CALL:
+        attr = _STR_TO_TVM_DTYPE_CALL[key]
+        call = getattr(tb_ffi, attr, None)
+        return call(expr, is_size_var)
+    # try to construct the ffi call
+    if key.startswith('uint'):
+        val = 'UInt' + key[4:]
+    elif key.startswith('int'):
+        val = 'Int' + key[3:]
+    elif key.startswith('float'):
+        val = 'Float' + key[5:]
+    elif key.startswith('bfloat'):
+        val = 'BFloat' + key[6:]
     else:
-        raise TypeError(f'Invalid type {self}')
+        raise TypeError(f'Invalid type {key}')

That makes the explicit mapping actually used (e.g., boolBoolean) and decouples the logic from the internal representation of tvm.DataType.

Also applies to: 91-115


🏁 Script executed:

#!/bin/bash
# Quick verification: show how dtype objects stringify and confirm mapping keys
python - << 'EOF'
from tilelang import tvm
from tilelang.language.v2 import dtypes

x = tvm.DataType("bool")
print("repr:", repr(x), "str:", str(x))
print("key in _STR_TO_TVM_DTYPE_CALL:", str(x) in dtypes._STR_TO_TVM_DTYPE_CALL)
EOF

Length of output: 611


I need to examine the code directly since the sandbox build is incomplete. Let me inspect the actual implementation of __dtype_call__ and the dtype class structure.


🏁 Script executed:

#!/bin/bash
# Locate and show __dtype_call__ implementation
rg -n "__dtype_call__" --type=py tilelang/language/v2/dtypes.py -A 30

Length of output: 2088


🏁 Script executed:

#!/bin/bash
# Show dtype class definition
rg -n "class dtype" --type=py tilelang/language/v2/dtypes.py -A 5

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Check if dtype inherits from tvm.DataType
rg -n "dtype.*tvm\.DataType" --type=py -i tilelang/language/v2/dtypes.py -B 2 -A 2

Length of output: 169


🏁 Script executed:

#!/bin/bash
# Verify _STR_TO_TVM_DTYPE_CALL structure and confirm keys are strings
sed -n '69,88p' tilelang/language/v2/dtypes.py

Length of output: 538


🏁 Script executed:

#!/bin/bash
# Check tvm module or other imports to understand tvm.DataType
rg -n "from.*tvm|import.*tvm" --type=py tilelang/language/v2/dtypes.py -B 1 -A 1 | head -30

Length of output: 201


🏁 Script executed:

#!/bin/bash
# Look for any isinstance or type checks involving dtype or DataType
rg -n "isinstance.*dtype|isinstance.*DataType" --type=py tilelang/language/v2/dtypes.py -B 1 -A 1

Length of output: 121


🏁 Script executed:

#!/bin/bash
# Search for startswith usage on self or dtype in dtypes.py
rg -n "startswith" --type=py tilelang/language/v2/dtypes.py -B 2 -A 2

Length of output: 389


🏁 Script executed:

#!/bin/bash
# Check for __str__ or __repr__ method on dtype class
rg -n "def __str__|def __repr__" --type=py tilelang/language/v2/dtypes.py -A 3

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Show lines 91-115 mentioned as "also applies to"
sed -n '91,115p' tilelang/language/v2/dtypes.py

Length of output: 979


🏁 Script executed:

#!/bin/bash
# Check if tvm.DataType is aliased or wrapped somewhere
rg -n "^dtype\s*=|^DataType\s*=" --type=py tilelang/language/v2/dtypes.py

Length of output: 22


🏁 Script executed:

#!/bin/bash
# Look at dtype usage within the file to understand its nature
rg -nP ":\s*dtype" --type=py tilelang/language/v2/dtypes.py | head -20

Length of output: 84


🏁 Script executed:

#!/bin/bash
# Check if dict membership checking works on DataType by looking for similar patterns
rg -n " in _STR_TO" --type=py tilelang/language/v2/dtypes.py -B 2 -A 2

Length of output: 223


🏁 Script executed:

#!/bin/bash
# Find any definitions or aliases of dtype at module level
rg -n "^dtype" --type=py tilelang/language/v2/dtypes.py -A 1

Length of output: 163


🏁 Script executed:

#!/bin/bash
# Examine the entire dtypes.py file to understand structure
wc -l tilelang/language/v2/dtypes.py && head -50 tilelang/language/v2/dtypes.py

Length of output: 1230


🏁 Script executed:

#!/bin/bash
# Check TypeAlias or type annotation for dtype
rg -n "dtype.*=|dtype.*:" --type=py tilelang/language/v2/dtypes.py | grep -E "^[0-9]+:(dtype\s*=|dtype.*:)" | head -10

Length of output: 22


🏁 Script executed:

#!/bin/bash
# Look at imports more comprehensively
head -30 tilelang/language/v2/dtypes.py

Length of output: 693


🏁 Script executed:

#!/bin/bash
# Check type annotations and see what dtype refers to
ast-grep --pattern 'def __dtype_call__(self: $_, $_) { $$$ }'

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Look for class or TypeVar definitions
grep -n "class\|TypeVar\|dtype\s*=" tilelang/language/v2/dtypes.py | head -30

Length of output: 986


🏁 Script executed:

#!/bin/bash
# Simpler approach: show full context around __dtype_call__
sed -n '80,120p' tilelang/language/v2/dtypes.py

Length of output: 1346


🏁 Script executed:

#!/bin/bash
# Show all lines mentioning "__dtype_call__" and surrounding context
grep -n "__dtype_call__" tilelang/language/v2/dtypes.py && sed -n '80,120p' tilelang/language/v2/dtypes.py

Length of output: 1467


🏁 Script executed:

#!/bin/bash
# Get context: what is dtype?
python3 << 'PYEOF'
import ast
with open('tilelang/language/v2/dtypes.py', 'r') as f:
    content = f.read()
    tree = ast.parse(content)
    
# Find dtype definition
for node in ast.walk(tree):
    if isinstance(node, (ast.ClassDef, ast.TypeAlias)) and 'dtype' in str(getattr(node, 'name', '')):
        print(f"Found: {type(node).__name__} - {getattr(node, 'name', 'unknown')}")
        if hasattr(node, 'lineno'):
            print(f"  Line: {node.lineno}")
    if isinstance(node, ast.Assign):
        for target in node.targets:
            if isinstance(target, ast.Name) and target.id == 'dtype':
                print(f"Assignment to 'dtype' at line {node.lineno}")
PYEOF

Length of output: 130


🏁 Script executed:

#!/bin/bash
# Direct inspection of the file to find dtype and __dtype_call__
cat tilelang/language/v2/dtypes.py | grep -n "dtype\|__dtype_call__" | head -40

Length of output: 1547


🏁 Script executed:

#!/bin/bash
# Just show the whole file
cat tilelang/language/v2/dtypes.py

Length of output: 18570


🏁 Script executed:

#!/bin/bash
# Final check: find method decorated or defined that handles dtype calls
rg -n "def.*dtype" --type=py tilelang/language/v2/dtypes.py

Length of output: 187


🏁 Script executed:

#!/bin/bash
# Look for where 'key' or string conversion happens with self
rg -n "str(self)" --type=py tilelang/language/v2/dtypes.py

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for int membership checks on dicts
rg -n " in _" --type=py tilelang/language/v2/dtypes.py -B 1 -A 1

Length of output: 586


Now I need to verify that this code path is actually reachable and understand how tvm.DataType stringifies. Let me check for actual usage patterns:Excellent. From the web search, I found that tvm.DataType (in tvm-ffi) behaves like a Python string and carries an internal FFI representation. This means tvm.DataType can be used with string operations, but the key insight is still that it's a different type than a plain string.

Now let me verify one more thing: check if there are any callers of dtype_call to understand the code path:Perfect. Now I have all the information I need. The code inspection is conclusive. Let me verify one more critical detail - whether the code path is even reachable:


🏁 Script executed:

#!/bin/bash
# Check if there are any calls to the dtype object's __call__ method
# Look for patterns like dtype(...)(expr)
rg -n "dtype\(" --type=py tilelang/language/v2/ | grep -v "test" | head -30

Length of output: 2002


🏁 Script executed:

#!/bin/bash
# Look for places where __dtype_call__ would be invoked via dtype(...)(expr) pattern
rg -n "\)(\s*\(" --type=py tilelang/language/v2/dtypes.py -A 1

Length of output: 61


Use str(self) for dispatch in __dtype_call__ so the FFI mapping actually applies

The __dtype_call__ method at lines 91–114 has a critical bug:

  • Line 92 checks if self in _STR_TO_TVM_DTYPE_CALL:, but self is a tvm.DataType instance while the dict keys (lines 69–88) are strings like 'bool', 'int8', 'int32', etc. This membership test will never succeed, making the explicit mapping (lines 92–95) dead code.
  • Lines 97–104 then use self.startswith(...), which assumes tvm.DataType behaves like a string. This coupling is fragile and error-prone.

The fix is to normalize to a string once at the start and use that for all subsequent operations:

 def __dtype_call__(self: dtype, expr=None, is_size_var: bool = False) -> tir.Var:
-    if self in _STR_TO_TVM_DTYPE_CALL:
-        attr = _STR_TO_TVM_DTYPE_CALL[self]
-        call = getattr(tb_ffi, attr, None)
-        return call(expr, is_size_var)
-    # try to construct the ffi call
-    if self.startswith('uint'):
-        val = 'UInt' + self[4:]
-    elif self.startswith('int'):
-        val = 'Int' + self[3:]
-    elif self.startswith('float'):
-        val = 'Float' + self[5:]
-    elif self.startswith('bfloat'):
-        val = 'BFloat' + self[6:]
+    key = str(self)
+    if key in _STR_TO_TVM_DTYPE_CALL:
+        attr = _STR_TO_TVM_DTYPE_CALL[key]
+        call = getattr(tb_ffi, attr, None)
+        return call(expr, is_size_var)
+    # try to construct the ffi call
+    if key.startswith('uint'):
+        val = 'UInt' + key[4:]
+    elif key.startswith('int'):
+        val = 'Int' + key[3:]
+    elif key.startswith('float'):
+        val = 'Float' + key[5:]
+    elif key.startswith('bfloat'):
+        val = 'BFloat' + key[6:]
     else:
-        raise TypeError(f'Invalid type {self}')
+        raise TypeError(f'Invalid type {key}')

This ensures the explicit mappings (e.g., boolBoolean) are actually used and decouples the logic from the internal representation of tvm.DataType.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
tilelang/language/v2/dtypes.py lines 69-114: The explicit FFI mapping keys are
strings but the method checks and string operations use self (a tvm.DataType),
so the mapping branch never triggers and string methods are fragile; fix by
converting self to a single string once (e.g., s = str(self)) at the start of
__dtype_call__ and then use s for the membership test against
_STR_TO_TVM_DTYPE_CALL and for any startswith checks, returning the mapped value
or falling back to the existing logic using that normalized string.

triteo_linear.py Outdated
Comment on lines 5 to 11
# n = 2 ** 25
B = 8
t = 2**11
D = 128
k = torch.randn(B,t,D, dtype=torch.float32, device='cuda')
s = torch.softmax(torch.randn(B,t,3, dtype=torch.float32, device='cuda'),dim=-1)

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

🧩 Analysis chain

Move heavy tensor allocation, kernel runs, and profiling under a __main__ guard

This module currently executes quite a bit of work on import:

  • Allocates large CUDA tensors k and s.
  • Constructs kernels for multiple blk_t values.
  • Runs a correctness assertion and a profiling loop with torch.profiler.

That’s appropriate for a standalone benchmark script, but surprising if this file is ever imported as a library module.

Consider wrapping all of this in an entrypoint block, or moving it into an examples/ or benchmarks/ script:

if __name__ == "__main__":
    # set up B, t, D, k, s
    # run reference + TileLang kernels
    # assert correctness and profile

This keeps imports cheap and side-effect free while preserving the benchmark.

Also applies to: 115-128


🏁 Script executed:

#!/bin/bash
# Quick check: confirm that importing triteo_linear today would execute the profiling path
python - << 'EOF'
import inspect
import triteo_linear
print("Top-level names:", [n for n in dir(triteo_linear) if not n.startswith("_")])
print("Has __name__ guard:", "__main__" in inspect.getsource(triteo_linear))
EOF

Length of output: 697


I'll inspect the file directly since importing failed due to build dependencies. Let me read the triteo_linear.py file to check for the __main__ guard and identify what code executes at the module level.



🏁 Script executed:

#!/bin/bash
# Read the triteo_linear.py file to check __main__ guard and module-level code
cat triteo_linear.py | head -150

Length of output: 4501


🏁 Script executed:

#!/bin/bash
# Check for __main__ guard presence
grep -n "if __name__" triteo_linear.py || echo "No __main__ guard found"

Length of output: 23


🏁 Script executed:

#!/bin/bash
# Count total lines to understand file size
wc -l triteo_linear.py

Length of output: 20


🏁 Script executed:

#!/bin/bash
# Show lines 100-150 to see the mentioned section (115-128)
sed -n '100,150p' triteo_linear.py

Length of output: 1137


Wrap heavy tensor allocation, kernel construction, and profiling in a __main__ guard

Verified: This module executes expensive operations at import time:

  • Lines 5–11 allocate large CUDA tensors (k, s)
  • Line ~85 computes o_torch via make_first_recurrent() loop
  • Lines 115–127 construct kernels for each blk_t value, run a correctness assertion, and profile 10 iterations with torch.profiler.profile()

No if __name__ guard exists in the file. This means importing triteo_linear immediately triggers all compute, which is inappropriate for a library module.

Move this section into an entrypoint:

if __name__ == "__main__":
    # set up B, t, D, k, s
    # compute o_torch reference
    # run kernels, assert correctness, profile
🤖 Prompt for AI Agents
In triteo_linear.py around lines 5-11 (and also the compute at ~line 85 and the
kernel construction/profiling/assertions at ~lines 115-127), heavy CUDA tensor
allocation, kernel construction and profiling run at import time; move all
runtime work into an entrypoint by wrapping the B, t, D, k, s setup, the call
that computes o_torch (make_first_recurrent loop), the per-blk_t kernel
construction, correctness assertion and torch.profiler.profile runs inside an if
__name__ == "__main__": block so importing the module no longer triggers
expensive computation; keep module-level imports and function/class definitions
at top-level, only relocate the runtime/test code into that guard.

triteo_linear.py Outdated
Comment on lines 88 to 113
for i0_t in T.serial(blk_t):
t_local = i0_t*blk_t + i0_t
#先存第一行也就是栈顶,到输出的o里面
o[i_b,t_local,i_d] = S_temp[0]
#再做三对角,实际上也就是相邻行的加权求和
down = s[i_b,t_local,0]
mid = s[i_b,t_local,1]
up = s[i_b,t_local,2]
for i0_d in T.Parallel(d-1):
S_down[i0_d + 1] = S_temp[i0_d] * down
for i0_d in T.Parallel(d-1):
S_up[i0_d] = S_temp[i0_d + 1] * up
for i0_d in T.Parallel(d):
S_mid[i0_d] = S_temp[i0_d] * mid
S_down[0] = 0
S_up[d-1] = 0
for i0_d in T.Parallel(d):
S_temp[i0_d] += S_mid[i0_d]
S_temp[i0_d] += S_down[i0_d]
S_temp[i0_d] += S_up[i0_d]
#往栈顶写入当前的k
S_temp[0] += down * k[i_b,t_local,i_d]
# 存储当前block最终的状态S,留作未来计算
for i0_d in T.Parallel(d):
S[i_b,i_t,i0_d,i_d] = S_temp[i0_d]
return inner_chunk_recurrent_fwd_init0_
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 | 🔴 Critical

🧩 Analysis chain

Fix t_local computation and explicitly handle/guard non-multiple-of-blk_t lengths

Inside inner_chunk_recurrent_fwd_init0_:

for i0_t in T.serial(blk_t):
    t_local = i0_t*blk_t + i0_t
    ...
    o[i_b, t_local, i_d] = S_temp[0]
    ...
    down = s[i_b, t_local, 0]
    ...
    S_temp[0] += down * k[i_b, t_local, i_d]

Issues:

  • t_local doesn’t depend on i_t (the block index from with T.Kernel(b * d, T.ceildiv(t, blk_t)) as (i_bd, i_t)), so every block iterates over the same subset of time steps. That both duplicates work and leaves part of the [0, t) range untouched.
  • For general t, this also assumes t % blk_t == 0; otherwise t_local can exceed t - 1 and index out of bounds on k, s, and o. Similarly, S is shaped (b, t//blk_t, d, d) while i_t ranges up to T.ceildiv(t, blk_t) - 1, so i_t can overrun the second dimension when t is not an exact multiple.

You probably want something along the lines of:

-        with T.Kernel(b * d, T.ceildiv(t, blk_t)) as (i_bd, i_t):
+        with T.Kernel(b * d, T.ceildiv(t, blk_t)) as (i_bd, i_t):
             i_b = i_bd // d
             i_d = i_bd % d
             ...
-            for i0_t in T.serial(blk_t):
-                t_local = i0_t*blk_t + i0_t
+            for i0_t in T.serial(blk_t):
+                t_local = i_t * blk_t + i0_t
+                if t_local >= t:
+                    break  # or equivalently clamp the loop extent for the last block

(Adjust the guard to whatever control flow TileLang’s T.serial supports—e.g., by computing an effective block length instead of using break.)

Additionally, if the kernel is only intended for t % blk_t == 0, it would be good to document that precondition or assert on it at the Python wrapper level.


🏁 Script executed:

#!/bin/bash
# Minimal sanity check: scan for t_local and block usage in this kernel
rg -n "inner_chunk_recurrent_fwd_init0_" -n triteo_linear.py -n -A15 -B5 || cat triteo_linear.py

Length of output: 1691


I can see the critical issues from the partial output. The key observations are:

  1. Shape mismatch confirmed: Line 70 shows S: T.Tensor((b, t//blk_t, d, d)) uses integer division, but line 76 shows the kernel grid is T.ceildiv(t, blk_t) (ceiling division). When t % blk_t ≠ 0, the last block's i_t index exceeds the valid range.

  2. Top-level side effects confirmed: Lines 116–127 show that kernel compilation, tensor allocation, and profiling loops execute on module import—this should not happen at import time.

  3. t_local formula unconfirmed: The output was truncated (lines 83–107 hidden), so I can't yet see the exact t_local computation. Let me retrieve it.


🏁 Script executed:

#!/bin/bash
# Get the full inner_chunk_recurrent_fwd_init0_ function with no truncation
sed -n '69,113p' triteo_linear.py

Length of output: 1890


Fix critical t_local computation and S tensor shape mismatch

The kernel has two critical bugs:

  1. Line 89: t_local formula is wrong. It should be t_local = i_t * blk_t + i0_t, not i0_t*blk_t + i0_t. As currently written, every block processes the same (wrong) time indices, duplicating work and missing parts of the input.

  2. Line 70 vs. line 76 shape mismatch. S is allocated as (b, t//blk_t, d, d) using integer division, but the kernel grid dimension is T.ceildiv(t, blk_t). When t % blk_t ≠ 0, the last block's i_t index exceeds the valid S dimension, causing out-of-bounds writes at line 112.

  3. Lines 116–127: Remove top-level kernel execution and profiling. Kernel compilation, tensor allocation, and profiling should not execute on module import; move this code to an example script or guarded test.

Suggested fix:

  • Change line 89 to: t_local = i_t * blk_t + i0_t
  • Either change S allocation to (b, T.ceildiv(t, blk_t), d, d) or add a bounds check to skip iterations when t_local >= t.
  • Move lines 116–127 to a separate example or guard them behind if __name__ == "__main__":.
🧰 Tools
🪛 Ruff (0.14.4)

90-90: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)


92-92: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)

🤖 Prompt for AI Agents
In triteo_linear.py around lines 88–113: the local time index calculation uses
the wrong variables so blocks compute incorrect time indices — replace the
current t_local expression so it uses the block index i_t combined with the
inner loop index i0_t (i.e., compute t_local from i_t and i0_t, not from i0_t
twice); fix the S tensor allocation vs. kernel grid mismatch by either
allocating S with ceildiv over t (so its second dim equals the number of blocks)
or add a bounds check that skips iterations when the computed t_local is >= t to
avoid out-of-bounds writes; and remove or guard the top-level kernel
compilation/allocation/profiling code (lines ~116–127) so it only runs under an
example/test entrypoint (for example inside an if __name__ == "__main__" or
moved to a separate script).

@LeiWang1999 LeiWang1999 merged commit 041d4a0 into tile-ai:main Nov 17, 2025
6 checks passed
RubiaCx pushed a commit to RubiaCx/tilelang that referenced this pull request Nov 24, 2025
* add typing stub for tir.ir

* remove idents

* minor update

* [Refactor] add numpy conversion for dtype

* fix lint error

* remove unused np.float_ in dtype conversion

* fix type in np.int_

* fix typo

* minor fix

* remove debug files
chengyupku added a commit to tile-ai/tilescale that referenced this pull request Feb 6, 2026
* [Example] Add GQA decoding kernel with varlen page table (#1265)

* [Example] Add page table for gqa decode

* [Example] Page table for varlen decoding

* [Lint]

* [Refactor] Remove redundant code

* [Lint]

* [Lint]

* [Lint]

* [Refactor] add support for numpy dtype conversion (#1255)

* add typing stub for tir.ir

* remove idents

* minor update

* [Refactor] add numpy conversion for dtype

* fix lint error

* remove unused np.float_ in dtype conversion

* fix type in np.int_

* fix typo

* minor fix

* remove debug files

* [EXAMPLE] In the flash attention example keep the max of all blocks seen in scores_max numerical stability (#1148)

* Keep the max of all blocks seen in scores_max for stability

* ruff formatting

* [Docs] Improve Installation Guide (#1270)

* [Docs] Improve installation guide

* address comments

* [Enhancement] Keep max score attention across blocks in FlashAttention for better numerical stablity (#1269)

* Implement max score retention across blocks in FlashAttention for improved stability

* fix manual pipeline parameters

* Update examples/flash_attention/example_gqa_fwd_varlen.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix typo

* more

* fix a previous typo

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* [Bugfix] Fix multiple cg defination when using T.sync_grid (#1272)

* [Minor] Remove from __future__ import annotations for python 3.8 (#1273)

* [BugFix] Adding extra parameters into autotune hashkey (#1274)

* [BugFix] Adding extra parameters into autotune hashkey

* lint

* None check

* check serializable

* Fix various issues under `int64_t` static and dynamic shape. (#1218)

* Fix various issues under int64_t static and dynamic shape.

* Resolve reviewed issues.

* Add unit test.

* fix

---------

Co-authored-by: LeiWang1999 <leiwang1999@outlook.com>

* Bug fix for Gated Delta Net benchmark script (#1267)

* fix argument order for fla chunk_gated_delta_rule_fwd_h

* explicit import assert_similar from utils

* rename utils module to avoid name clash

* set store_final_state and save_new_value to True

* fix

---------

Co-authored-by: LeiWang1999 <leiwang1999@outlook.com>

* [Bugfix] Minor fix for some cases (#1278)

* [Language] Add shape check in `T.view/reshape` (#1277)

* [Language] Add shape check in T.view/reshape

* address comments

* [FFI] Use tvm ffi as the default execution backend (#1259)

* [Refactor] Update FFI type handling and simplify argument management

* Refactored FFI type definitions in runtime and code generation files to use `TVMFFIAny` instead of `TVMValue`, enhancing type clarity.
* Updated function registration in `runtime.cc` to utilize canonical names for better consistency.
* Simplified argument handling in the `simplify` transformation, ensuring unused buffer parameters are removed only when simplification is enabled.
* Adjusted autotuner and profiler parameters to standardize the execution backend to `tvm_ffi`, improving clarity in backend selection.
* Removed obsolete `adapt_torch2tvm` function from tensor utilities to streamline the codebase and reduce complexity.

* [Update] Sync TVM submodule and enhance kernel source handling

* Updated the TVM submodule to commit cdc2aced, ensuring compatibility with recent changes.
* Added functionality to print kernel source in `example_blocksparse_gemm.py` for better debugging.
* Commented out the main execution call in test files to prevent unintended execution during testing.
* Introduced `tilelang.disable_cache()` in various test files to streamline testing and avoid cache-related issues.
* Refactored kernel source retrieval methods to improve clarity and consistency across different execution backends.

* [Refactor] Clean up imports and improve code formatting

* Removed unused import of `tilelang.testing` in `test_example_blocksparse_gemm.py` to streamline the code.
* Reformatted several lines in `arg_binder.cc`, `make_packed_api.cc`, `tvm_ffi.py`, and `adapter.py` for improved readability and consistency.
* Updated comments and spacing in `tvm_ffi.py` to enhance clarity without altering functionality.

* Update execution backend options and improve resolution logic

- Changed default execution backend from "cython" to "auto" in multiple locations to allow automatic selection based on the target.
- Expanded the list of supported execution backends to include "torch" and "nvrtc" across various classes and functions.
- Enhanced backend resolution logic in `KernelCache` and `AutoTuner` to ensure appropriate backend selection based on the target.
- Updated documentation to reflect changes in execution backend options and their defaults.

* lint fix

* fix

* Enhance argument handling in CUDA and HIP runtime modules

- Updated `ExtractFuncInfo` in `rt_mod_cuda.cc` and `rt_mod_hip.cc` to map boolean argument types to int32, ensuring compatibility with device runtime.
- Refactored `BindDLTensor` in `arg_binder.cc` to improve null handling and validation checks for DLTensor parameters, utilizing expression-level guards to prevent dereferencing null pointers.
- Enhanced error checking for buffer shape, strides, and data fields, ensuring robust handling of optional inputs and maintaining consistency across various checks.

* lint fix

* lint fix

* lint fix

* lint fix

* minor fix

* fix

* recover check

* Refactor argument binding and validation in `arg_binder.cc`

- Improved null handling and validation checks in `BindDLTensor`, ensuring safe dereferencing of pointers.
- Enhanced consistency checks for buffer shape, strides, and data fields, utilizing expression-level guards.
- Updated `MakePackedAPI` to maintain code clarity and consistency in argument handling.
- Minor adjustments in test files to streamline kernel execution and improve readability.

* lint fix

* stride fix

* minor fix

* fix

* lint fix

* lint fix

* Add CUDA stream access policy window helpers and integrate with L2 persistent cache management

- Introduced functions to set and reset the CUDA stream access policy window, allowing for better control over L2 cache usage.
- Updated runtime files to include new FFI packed functions for managing stream attributes.
- Modified lower_hopper_intrin to incorporate prologue and epilogue statements for L2 cache setup and teardown.
- Enhanced tests to verify the inclusion of new FFI calls in the generated kernel source.

* check with symbolic

* support null ptr

* Update CMakeLists and lower.py for code generation and subproject status

- Added `codegen_c_host.cc` to the list of source files in CMakeLists.txt for improved code generation support.
- Updated the function call in `lower.py` to use `target.build.tilelang_c` for C target host code generation, enhancing compatibility.
- Marked the TVM subproject as dirty to indicate local modifications.

* lint fix

* Update comments for clarity in quickstart.py

* [Bugfix] Supply missing `T.print` for bool type (#1279)

* fix for bool dtype

* lint fix

* fix

* ci fix

* [Fix] Fix memory leak bug (#1281)

* add typing stub for tir.ir

* remove idents

* minor update

* [Refactor] add numpy conversion for dtype

* fix lint error

* remove unused np.float_ in dtype conversion

* fix type in np.int_

* fix typo

* minor fix

* remove debug files

* fix memory leak bug

* fix lint error

* add comments

* fix lint error

* remove duplicated, because tilelang doesn't dependent deprecated

* [Enhancement] Enhance CUDA compilation by integrating pass context configuration (#1283)

- Updated the `tilelang_callback_cuda_compile` function to accept a `pass_config` parameter, allowing for more flexible compilation options.
- Introduced handling for fast math and PTXAS options based on the provided pass configuration.
- Modified the CUDA build process in `rt_mod_cuda.cc` to utilize the current pass context, improving the integration of compilation settings.
- Refactored NVCC command construction to use a dedicated function for better clarity and maintainability.

* Fix the bug in issue #1266 (#1284)

Co-authored-by: cheeryBloosm <liu_yu_hao@126.com>

* [Language][UX] Nested loop checker in pre-lowering stage (#1288)

* [Language][UX] Nested loop checker in pre-lowering stage

* rename

* comment

* address comments

* [Compatibility] Support CUDA 11.3 (#1290)

* [Feat] Add support for using `T.Tensor(n * 2 + 1)` in function annotation (#1285)

* [Feature] Add support for A: T.Tensor(n + 1) and A: T.Tensor(2*n)

* issue fix

* fix

* fix

* decreate nproc for debugging

---------

Co-authored-by: Lei Wang <leiwang1999@outlook.com>

* [Feat] add support for passing reference in T.Var annotation (#1291)

* [Enhancement] Shared Memory Size Can be Dynamic (#1294)

* bugfix

* lint fix

* test

* lint fix

* increate procs

* recover

* [Fix] Remove unused let_bindings_ in CodeGenC to fix #1300 (#1305)

* [Feat] add missing support of uint32x2

* [Feat] Add `T.Ref` annotation and tests

* fix lint error

* minor update for error message on twice decl

* Remove unused let_bindings_ in CodeGenC to fix #1300

* [Bugfix] Fallback to the old AtomicAdd implementation for legacy architectures (#1306)

* [Fix] Fix frame scope error in T.macro (#1308)

* [Fix] Fix #1307 by adding macro inside function

* fix lint error

* add comments and fix lint error

* Remove debug print from enter_frame method

Removed debug print statement from enter_frame method.

---------

Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>

* [WIP] support more dtypes for tcgen05 (#1229)

support ld with pack for fp32 dtype

add dump

add tempalte expand

remove unused dtype and change to rebased apis

* Improve memory access safety and `T.assume` handling (#1292)

* Improve memory access safety and T.assume handling

* Improve memory access safety and T.assume handling

* bugfix

* lint fix

* bugfix

* bugfix

* refactor legalize safe memory access pass

---------

Co-authored-by: Lei Wang <leiwang1999@outlook.com>

* [Bugfix] Fix autotune cache (#1315)

* [Refactor] Backup Analyzer to get the appropriate arith informations (#1311)

* [Refactor] Update Vectorization Functions to Accept Analyzer Parameter

- Modified `VectorizeLoop` and related functions to accept an `arith::Analyzer` parameter, enhancing their capability to perform analysis during vectorization.
- Updated multiple instances in `copy.cc`, `fill.cc`, `parallel.cc`, and layout inference files to utilize the new analyzer parameter for improved performance and correctness.
- Ensured consistency across vectorization logic by integrating the analyzer into existing workflows, facilitating better optimization opportunities.

* [Fix] Corrected PostOrderVisit call in loop_vectorize.cc

- Updated the PostOrderVisit function to analyze the body of the loop node instead of the node itself, ensuring proper handling of nested loops during vectorization analysis.

* fix

* lint fix

* fix

* Revert "[WIP] support more dtypes for tcgen05 (#1229)" (#1323)

This reverts commit 0d101c110f74ebf2ef8c11a5ece9dfb314b48baa.

Co-authored-by: Zhiwen Mo <zm125@ic.ac.uk>

* [CI]: Bump actions/checkout from 5 to 6 (#1319)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [CI]: Bump pypa/cibuildwheel from 3.2 to 3.3 (#1318)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [Installation] Fix building using customized TVM path (#1326)

* [Release] Allow developer with write permission to trigger wheel release (#1322)

* [Feat] Support warp reduce (#1316)

* [Feat] Support warp reduce

* lint

* add test

* lint

* [Enhancement] Support more dtype in `T.print` (#1329)

* [Enhancement] Support more dtype in `T.print`

* upd

* upd

* [BugFix] Use BufferRegion in tl.cumsum to infer buffer shape (#1321)

* [BugFix] Use BufferRegion in tl.cumsum to infer buffer shape

* remove debug lines

* remove rubbish

* Fix decorator syntax for atomic_different_memory_orders_program

---------

Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>

* [Fix] fix wrong uint narrowing bug in tvm in #1310 (#1320)

* [Refactor] Disable strided buffer load inside tvm (#1301) (#1332)

* [Refactor] Moving `NormalizeToBufferRegion` and `MakeAccessPtrFromRegion` to utils (#1333)

* Refactor GEMM and Reduce operations by moving NormalizeToBufferRegion and MakeAccessPtrFromRegion to utils.{h,cc} for better code organization and reuse.

* lint fix

* [Fix] Fix bug copying from or to local buffer (#1304) (#1324)

* [Fix] fix copy from or to local buffer (#1304)

* fix lint error

* minor fix testing script

* [Language][UX] Semantic check for parallel fragment access (#1338)

* Add unit tests for T.assume (#1341)

* Add test for T.assume

* Add unit test for T.assume

* Add unit test for T.assume

* Add unit tests for T.assume

* Remove debug print for kernel source

Remove print statement for kernel source in tests.

* Update test_tilelang_language_assume.py

---------

Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>

* [Feat] Extend LegalizeNegativeIndex to support buffer store stmts (#1339)

This commit enhances the LegalizeNegativeIndex transformation pass to handle
both buffer load and store operations with negative indices and adds some
test cases.

* [Refactor] Phaseout vmap for Tile Operators (#1334)

* Refactor GEMM and Reduce operations by moving NormalizeToBufferRegion and MakeAccessPtrFromRegion to utils.{h,cc} for better code organization and reuse.

* lint fix

* Refactor region handling by removing the RegionOp and updating NormalizeToBufferRegion to only accept BufferLoad and BufferRegion. This change improves code organization and simplifies the handling of memory regions across various operations.

* fix

* Refactor memory region handling by introducing `tl.region` calls across various operations, including GEMM and fill functions. This change enhances the consistency of region management and improves code organization by utilizing utility functions for buffer region conversions.

* fix

* fix

* test fix

* lint fix

* Refactor GEMM operations to improve memory region handling by replacing `mbarPtr_` with `mbarRegion_` and updating related logic in both C++ and Python implementations. This change enhances the clarity and consistency of buffer region management.

* fix

* lint fix

* fix

* fix

* test fix

* lint fix

* lint fix

* minor fix

* fix

---------

Co-authored-by: Zhiwen Mo <zm125@ic.ac.uk>

* [Enhancement] add more dtype and fix mma.ws for fp16 for tcgen05 (#1327)

* feat: add fp8 variants; add placeholder for fp6/fp4 in meta

support ld with pack for fp32 dtype

add dump

add tempalte expand

remove unused dtype and change to rebased apis

* fix: when atom-m!=128, enable_ws

* fix: typo in tcgen05 meta; dispatch in gemm sm100

* [Refactor] Enhance CopyNode's IterVar Creation and Range Handling (#1346)

* [Refactor] Enhance CopyNode's IterVar Creation and Range Handling

This commit refines the `MakeIterVars` method in `CopyNode` to select base ranges based on memory scope levels, ensuring that the chosen ranges are not smaller than the original source ranges. Additionally, it updates the Python `copy` function to clarify range handling, including broadcasting logic and extent alignment. These changes improve the robustness and clarity of the copy operation's implementation.

* test fix

* [Fix] Fix missing `not` rewrite in frontend (#1348)

* [Enhancement] Add support for k_pack in gemm_mfma (#1344)

* add support for k_pack

* support benchmark on ROCm

* fix format

* Add sparse fine-tuning kernel for deepseek sparse attention to example (#1296)

* [EXAMPLE] add example for dsa sparse finetuning

* [Refactor]

* [Refactor] Improve assertion handling in CodeGenCHost and ArgBinder (#1352)

* [Refactor] Improve assertion handling in CodeGenCHost and ArgBinder

This commit refines the assertion message generation in CodeGenCHost by optimizing the handling of equality checks and reducing buffer size for error messages. Additionally, it enhances the ArgBinder by introducing a nullable guard mechanism for assertions, allowing for more precise error handling when binding arguments. The changes improve the clarity and efficiency of assertion handling across the codebase.

* [Enhancement] Update matmul kernel and optimize argument binding

This commit enhances the matmul kernel by introducing additional tensor parameters and refining the pipeline stages for improved performance. It also updates the argument binding mechanism to include a flag indicating whether buffers are used, enhancing the efficiency of buffer management. Furthermore, the optimization phase in the engine is improved by adding a simplification step, ensuring better performance and clarity in the generated code.

* lint fix

* [Enhancement] Add tensor checks documentation and improve argument binding assertions

This commit introduces a new documentation page for host-side tensor checks, detailing the automatic validations performed by TileLang on kernel arguments. It enhances the ArgBinder by adding assertions for non-null pointers when arguments are used, improving error handling. Additionally, the optimization phase in the engine is updated to include a simplification step, ensuring better performance and clarity in the generated code.

* [Enhancement] Update .gitignore and refine matmul kernel for improved performance

This commit adds host checks logs to the .gitignore file to prevent unnecessary log files from being tracked. Additionally, it refines the matmul kernel by adjusting pipeline stages, updating tensor parameters, and enhancing argument handling for better performance. The changes also include improved error messages in the argument binding process, ensuring clearer diagnostics for users.

* lint fix

* lint fix

* [Refactor] Simplify tensor_null_test function and remove ptr_null_test

This commit refactors the tensor_null_test function by adding a with_bias parameter and removing the ptr_null_test function, which was previously unused. The run_test function is updated to reflect these changes, streamlining the testing process for tensor operations.

* lint fix

* fix

* [Refactor] Simplify index sign state handling in LegalizeNegativeIndex (#1354)

This commit refines the logic for determining the sign state of indices in the LegalizeNegativeIndex transformation. It prioritizes vector patterns, specifically Ramp and Broadcast nodes, to avoid compile-time lane queries. The handling of scalar indices is also streamlined, ensuring clearer diagnostics when non-negativity cannot be proven. These changes enhance the robustness and clarity of index handling in the transformation pass.

* [Enhancement] Improve error handling and assertion messages across runtime and argument binding (#1356)

This commit enhances the error handling mechanisms in the runtime by introducing CPU-safe runtime helpers and refining assertion messages in the CodeGenCHost and ArgBinder. It includes structured packed error messages for various conditions, improving clarity in diagnostics. Additionally, the CMake configuration is updated to always include necessary runtime helpers, ensuring consistent error reporting. The changes aim to provide clearer feedback during runtime errors and improve the overall robustness of the argument binding process.

* [Bugfix] Disable floordiv optimization due to integer overflow risk (#1355)

* disable overflow-prone floordiv optimization in lower_intrin.cc

* disable overflow-prone floordiv optimization in lower_intrin.cc

* [Bugfix] Fix the jit_kernel issue (#1357)

* [Bugfix] Fix the jit_kernel issue

* Update README.md

---------

Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>

* [Refactor] Update Fragment Indexing in ParallelOpNode's InferLayout Method (#1359)

This commit refines the Fragment creation process in the InferLayout method of ParallelOpNode. It removes the unnecessary forward_index array and utilizes default fragment indexing for consistency with other operations. Additionally, it binds the thread range to enhance comparability across different operations.

* [Analysis] Enhance NestedLoopChecker with tile op cases (#1358)

* [Analysis] Enhance NestedLoopChecker with tile op cases

* fix tileop issue

* [Language] support `T.gemm_sp_v2` on sm80 and sm89 (#1056)

* [misc] add a cpp side wrapper for gemm_sp_py

* [misc] typing

* [IR] bind GemmSPWarpPolicy

* [chore] add wrapper code

* [IR] fix GemmSPWarpPolicy

* [codegen] apply ptxas instructions

* [intrinsic] add typical (unused) mma layout

* [template] add uint16 debug func

* [intrinsic] add b matrix layout

* [gemm_sp] enable fp16/bf16 on sm8x

* [layout] refactor fp16/bf16 layout

* [gemm_sp] enable int8

* [chore] update test case dtype

* [gemm_sp] enable fp32

* [layout] refactor layouts

* [intrinsic] enable ldmatrix for mat A

* [layout] enable ldsm for matrix b

* [layout] add ldmatrix for fp32 and fp8

* [chore] refine

* [chore] refactor

* [chore] add fp8 efactor

* [chore] refactor

* [chore] add remove negative zero util

* [example] add a custom compress kernel

* [chore] minor update

* [test] refactor gemm_sp test

* [refactor] make metadata layout func

* [example] add option for using cutlass layout

* [doc] add a gemm_sp doc

* [doc] minor polish

* [chore] remove unused

* [bugfix] fix non replicate b case

* [test] refactor

* [chore] add a check

* [bugfix] fix util bug

* [wip] init a new test case for v2

* [chore] minor refactor

* [chore] minor update

* [bugfix] enable 16bit rs

* [language] enable rs

* [language] enable gemm_sp_sr

* [language] enable gemm_sp_rr

* [test] enable more tests

* [tvm] update ffi binding

* [chore] remove print

* [chore] fix benchmark script

* [lint] precommit lint

* [chore] apply feedback

* [test] use arch 8.0

* [chore] rollback ::ordered_metadata for backward compatibility

* [bugfix] fix captialized

* [example] keep gemm_sp on hopper

* [test] fix no fp8 normal kernel

* [test] reduce matmul size to satisfy accum error

* [test] use cal_diff for assertion

* [bugfix] expand float8 type

* [lib] add make_int4 for short type

* [language] add transpose E

* [bugfix] fix wrong var

* [format] format

* [chore] refactor binding

* [chore] fix wrong passing var

* [Bugfix] Update TIR registration for GemmSPPy to use tile operation (#1361)

* [Enhancement] Implement dynamic unroll factor in CUDA code generation (#1360)

* [Enhancement] Implement dynamic unroll factor in CUDA code generation

This commit introduces support for specifying a dynamic unroll factor in the CUDA code generation. The `unroll_factor` map is added to store unroll factors for loop variables, allowing for more flexible and optimized loop unrolling. Additionally, the `unroll` function is integrated into the loop language, enabling users to define unroll factors directly in their code. This enhancement improves performance by allowing tailored unrolling strategies based on specific loop characteristics.

* lint fix

* [Bugfix] Correct initialization of non-zero counters in custom compress kernel and update TIR registration for gemm_sp_py to use the correct tile operation

* [CI] [pre-commit.ci] autoupdate (#1362)

updates:
- [github.com/pre-commit/mirrors-clang-format: v21.1.2 → v21.1.6](https://github.com/pre-commit/mirrors-clang-format/compare/v21.1.2...v21.1.6)
- [github.com/astral-sh/ruff-pre-commit: v0.14.3 → v0.14.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.14.3...v0.14.7)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [Bugfix] Remove debug print in PyStmtFunctionVisitor  (#1363)

* [Debug] Always include line info in NVCC command for improved profiling and mapping (#1364)

* [Refactor] Update condition for benchmarking in example_gemv.py and simplify cached library path handling in sparse.py (#1365)

* [Enhancement] Add DISABLE_CACHE environment variables (#1368)

* [Refactor]: Remove useless include in atomicadd_vectorize.h (#1371)

* [Refactor] Generalize fp8 process (#1372)

* [Refactor] Update condition for benchmarking in example_gemv.py and simplify cached library path handling in sparse.py

* [Enhancement] Extend support for float8 data types in GEMM operations

- Updated GEMM operations to recognize additional float8 data types: `float8_e4m3fn` and `float8_e5m2fnuz`.
- Refactored condition checks in `checkWgmma` methods to simplify float8 type handling.
- Adjusted test cases to ensure compatibility with the new float8 types in tile language examples.

* lint fix

* [Layout] Enhance Free Layout Inference (#1375)

* [Refactor] Update condition for benchmarking in example_gemv.py and simplify cached library path handling in sparse.py

* [Enhancement] Extend support for float8 data types in GEMM operations

- Updated GEMM operations to recognize additional float8 data types: `float8_e4m3fn` and `float8_e5m2fnuz`.
- Refactored condition checks in `checkWgmma` methods to simplify float8 type handling.
- Adjusted test cases to ensure compatibility with the new float8 types in tile language examples.

* lint fix

* [Enhancement] Add injective layout detection and exception handling

- Introduced `DetectInjective` method in `FragmentNode` to check for injective layouts.
- Added `LoopLayoutInjectiveException` to handle errors related to non-injective layouts.
- Updated `InferLayout` methods in `ParallelOpNode` to utilize injective checks and log relevant information.
- Refactored layout inference queue management to use `std::deque` for improved performance and added prioritization logic for buffer layouts.

* remove debug print

* remove debug print

* remove debug print

* minor layout fix

* fix for T.view

* [Enhancement] Improve injective layout detection in FragmentNode

- Updated the `DetectInjective` method to handle symbolic dimensions more effectively by introducing a mechanism to collect symbolic shapes and adjust the detection level accordingly.
- Added logging for cases where the layout detection falls back to NoCheck due to symbolic dimensions.
- Minor update to the test file to include the tilelang testing module.

* [Refactor] Simplify layout inference for bulk copy operations

- Removed unnecessary conditions for bulk load/store operations in the layout inference logic.
- Streamlined the handling of layout application for bulk copy instances to enhance clarity and maintainability.

* remove debug print

* [Enhancement] Introduce layout-related exceptions and improve error handling

- Added `LayoutConflictException` and `LoopLayoutInjectiveException` classes for better exception management in layout operations.
- Updated `InferLayout` method in `ParallelOpNode` to throw `LoopLayoutInjectiveException` with detailed error information when injective layout checks fail.
- Removed redundant exception class definitions from `parallel.h` to streamline code organization.

* [Enhancement] Introduce buffer var lca analysis for pass plan buffer allocations (#1376)

* Update submodule TVM to latest commit and add PlanAndUpdateBufferAllocationLocation function to transform module

- Updated the TVM submodule to commit 3a32b763.
- Added a new function `PlanAndUpdateBufferAllocationLocation` in the transform module to facilitate buffer allocation planning within PrimFuncs.

* Refactor buffer allocation code for improved readability and consistency

- Updated formatting and spacing in `plan_update_buffer_allocation_location.cc` for better code clarity.
- Standardized the use of pointer and reference syntax across various class methods.
- Enhanced comments for better understanding of buffer allocation logic.
- Removed unnecessary lines and improved overall code structure.

* Refactor buffer allocation checks for improved clarity

- Replaced size checks with empty checks for `ffi::Array<Buffer>` in `plan_update_buffer_allocation_location.cc` to enhance code readability.
- Updated conditions in multiple methods to use `empty()` instead of comparing size to zero, streamlining the logic.

* [Tool] Provide layout visualization tool (#1353)

* Provide layout visualization tool

Adds a layout visualization tool to TileLang, which helps users understand and debug the layout transformations applied during compilation.

This tool visualizes the memory layout of tensors at different stages of the compilation process, allowing developers to identify potential inefficiencies and optimize their code for better performance.

The visualization can be enabled via a pass config option.

* format

* add layout visual example

* Adds vis extra with matplotlib dependency

* rafactor pass config name

* fix lint

* Enables configurable layout visualization formats

Allows users to specify the output formats (png, pdf, svg) for layout visualization through a pass config option.

This change provides more flexibility in how layout visualizations are generated, allowing users to choose the formats that best suit their needs.

It also fixes a bug where layout visualization was not correctly disabled when the config option was set to "false".

* Adds visual layout inference tool docs

* fix lint

* fix lint

* Rafactor configurable layout visualization formats

* fix lint

* fix typo

* add some comments

* fix lints

* add some warnings for user

* Moves layout visualization

* Refactors layout visualization pass configuration

Updates the layout visualization pass configuration to use boolean flag for enabling and a string for specifying formats.

* Enables multiple layout visualization formats

* Updates layout visualization docs

* Moves layout visualization to analysis

* [Release] Relax constraint of tvm-ffi to compatible version (#1373)

Co-authored-by: LeiWang1999 <leiwang1999@outlook.com>

* [Language] Tilelang LazyJIT Experimental Version (#1337)

* initial step

* modify builder

* scratch version of new frontend

* write some tests

* add many tests

* add typing stub for tir.ir

* remove idents

* minor update

* minor update

* First version of jitv2 (renamed to LazyJIT)

* fix pre-commit error

* minor fix

* fix lint error

* fix lint error

* Fix conditional check for PrimFunc instance

---------

Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>

* [Builder] Enhance variable name binding and scope management (#1378)

- Improved handling of TVM Var/Buffer names to prevent out-of-scope errors when reusing Python names across different for-frames.
- Added assertions to ensure variables are defined within the correct control flow frame, enhancing error checking and code reliability.

* [Bugfix] make cuda driver api compat with cuda12/13, along with tests (#1379)

* [Fix] typo in cuda attr (#1380)

* [Bugfix] make cuda driver api compat with cuda12/13, along with tests

* fix typo in cudaDevAttr

* [Language V2] Minor fix for complex annotations (#1381)

* [Release] Bump Version into 0.1.7 (#1377)

* Update VERSION to 0.1.7

* Update Python version in distribution scripts to support CPython 3.9 and log output

* [Typing] Enhance compatibility for advanced typing features in Python (#1382)

- Updated `allocate.py` and `annot.py` to improve compatibility with Python 3.9 and later by conditionally importing advanced typing features such as `TypeVarTuple`, `Unpack`, and `ParamSpec`.
- Added fallback imports from `typing_extensions` for environments using earlier Python versions.
- Improved handling of generic alias detection to ensure consistent behavior across different Python versions.

* [Bugfix][Build] Update CMake configuration to remove project root injection for sys.path (#1385)

* [Build] Update CMake configuration for tilelang_cython_wrapper installation

- Adjusted output directories for the tilelang_cython_wrapper to ensure that development builds place the extension in build/lib.
- Updated installation paths to place the extension in tilelang/lib within the wheel, improving organization and avoiding potential conflicts with other modules.
- Modified the internal library path exposure in env.py to prevent shadowing of common module names, enhancing compatibility and usability in user projects.

* [Build] Standardize output directories for tilelang libraries

- Set output directories for both tilelang and tilelang_module libraries to "${CMAKE_BINARY_DIR}/lib" for consistency in development builds.
- This change enhances organization and ensures that all build artifacts are located in a unified directory structure.

* [BugFix] Fix split kernel layout bug of GQA decode (#1386)

* [BugFix] Fix split kernel layout bug of GQA decode

* [BugFix] Avoid local with Parallel; use robust fragment instead

* [Enhancement] Add debug output methods for Layout and Fragment classes (#1392)

* [Doc] Update logging docs (#1395)

* [Enhancement] Refactor inflight computing to support dynamic pipeline extents (#1399)

* [Build] Update CMake configuration for tilelang_cython_wrapper installation

- Adjusted output directories for the tilelang_cython_wrapper to ensure that development builds place the extension in build/lib.
- Updated installation paths to place the extension in tilelang/lib within the wheel, improving organization and avoiding potential conflicts with other modules.
- Modified the internal library path exposure in env.py to prevent shadowing of common module names, enhancing compatibility and usability in user projects.

* [Build] Standardize output directories for tilelang libraries

- Set output directories for both tilelang and tilelang_module libraries to "${CMAKE_BINARY_DIR}/lib" for consistency in development builds.
- This change enhances organization and ensures that all build artifacts are located in a unified directory structure.

* [Refactor] Update TVM subproject and enhance pipeline loop handling

- Updated the TVM subproject to commit 90581fe9e5287bbcf1844ad14255a1e1e8cdf7f0.
- Added new fields to `PipelineAnnotation` and `RewrittenBlockInfo` structures to track original statement indices and improve async state management.
- Refactored `EmitImpl` and `PopulateWaitCounts` methods to enhance clarity and functionality, including better handling of commit groups and wait counts.
- Simplified access index calculations and strengthened analyzer constraints for loop bounds.

* [Cleanup] Remove license block and unused includes from inject_pipeline.cc

- Eliminated the Apache license block from the top of the file to streamline the code.
- Removed unused include directives for memory and stringstream to enhance code clarity and reduce unnecessary dependencies.

* [Refactor] Enhance transformation pipeline and test execution

- Added an additional Simplify transformation in the InjectSoftwarePipeline to improve optimization.
- Updated the test file to call `test_trival_pipeline()` directly, commenting out the previous main execution for better test isolation.

* [AMD] Fix 3 bugs when build docker on amd mi3x gpu (#1401)

* [Typo] Fix tilelang link in README.md (#1402)

* [Dependency] Update apache-tvm-ffi version to >=0.1.2 (#1400)

* [Dependency] Update apache-tvm-ffi version to >=0.1.2 in project files

* [Dependency] Update subproject commit for TVM to latest version afc07935

* [Enhancement] Add support for optional step parameter in loop constructs

- Updated loop creation functions to accept an optional step parameter, enhancing flexibility in loop definitions.
- Modified ForFrame implementations to utilize the new step parameter across various loop types including serial, parallel, and pipelined loops.
- Adjusted related vectorization transformations to accommodate the step parameter, ensuring consistent behavior in loop vectorization processes.

* lint fix

* [AMD] Enable FA2 fwd on AMD MI300X (#1406)

* enable FA2 on AMD MI300X

* make lint happy

* [TypoFix] fix typo for SM120 (#1408)

* [Doc] Minor documentation update (#1410)

* [Dependency] Add torch-c-dlpack-ext to project requirements (#1403)

* [Dependency] Add torch-c-dlpack-ext to project requirements

* Added torch-c-dlpack-ext to both pyproject.toml and requirements.txt to provide prebuilt torch extensions, which may prevent JIT compilation on first import of TVM FFI.

* [Build] Update manylinux images in project configuration

* Changed the manylinux image for x86_64 from "manylinux2014" to "manylinux_2_28" in both pyproject.toml and the Dockerfile to align with updated standards for compatibility and performance.

* [Build] Update CUDA repository configuration in pyproject.toml

* Changed the package manager command from `yum-config-manager` to `dnf config-manager` for adding the CUDA repository, ensuring compatibility with newer systems.

* fix

* [Build] Update CUDA repository to RHEL 8

* Changed the CUDA repository configuration in both pyproject.toml and the manylinux Dockerfile from RHEL 7 to RHEL 8, ensuring compatibility with newer systems.

* test: run out of space

* use cu130 to reduce size

* upd

* upd comment

* upd

---------

Co-authored-by: Your Name <wenji.yyc@alibaba-inc.com>

* [Dependency] Update TVM subproject to latest commit 2b1ead1a (#1412)

* [Enhancement] Introduce `T.__ldg` (#1414)

* [Enhancement] Add __ldg intrinsic for CUDA read-only cache loads

* Introduced the __ldg intrinsic to enable explicit read-only cached loads from global memory in CUDA.
* Updated the corresponding documentation and added support in both CUDA and HIP code generation.
* Enhanced the Python interface for __ldg to accept BufferLoad and Buffer types, improving usability.

* [Enhancement] Update formatting and linting rules in pyproject.toml; minor test adjustment

* Added new formatting rules in pyproject.toml to enforce consistent code style, including hanging indents and argument splitting.
* Updated test_tilelang_language_intrinsics_codegen.py to improve readability by adding a blank line before the main execution block.
* Refactored error messages in builtin.py for better clarity and consistency, ensuring proper formatting in function definitions and raising ValueErrors.

* lint fix

* [Enhancement] Improve vectorization invariant check (#1398)

* Improve loop vectorize

* Improve loop vectorize

* Improve loop vectorize

* Improve loop vectorize

* Improve loop vectorize

* Add some vectorize tests and comments

* [Lint] Phaseout Yapf format and embrace ruff format (#1417)

* [Atomic] Use ptr for atomicAdd dst instead of reference (#1425)

* [Enhancement] Update AtomicAdd function signature to accept pointer to destination

* Modified AtomicAdd in CUDA to take a pointer instead of a reference for the destination argument.
* Updated related code in atomicadd_vectorize.cc to ensure compatibility with the new signature.
* Adjusted Python interface in atomic.py to pass the destination by pointer, aligning with device function requirements.

* [Enhancement] Refactor AtomicAddRet function signature to accept pointer

* Updated AtomicAddRet in both CUDA and HIP to take a pointer instead of a reference for the address argument, improving consistency with the AtomicAdd function.
* Adjusted the implementation to ensure proper reinterpretation of the address type for atomic operations.

* lint fix

* [Enhancement] Refactor AtomicAddNode::MakeSIMTLoop to use destination pointer

* Updated the MakeSIMTLoop function to build a pointer to the destination element using tvm_access_ptr instead of loading the destination value directly.
* Simplified the handling of source and destination predicates, improving clarity and maintainability of the code.
* Ensured compatibility with the new pointer-based approach for atomic operations.

* lint fix

* test fix

* lint fix

* [CUDA] Add read-only parameter annotation for CUDA codegen (#1416)

* [Enhancement] Add read-only parameter annotation for CUDA codegen

* Introduced the `AnnotateReadOnlyParams` transformation to annotate read-only handle parameters in PrimFuncs, enabling the generation of `const` qualifiers in CUDA codegen.
* Updated `PrintFunctionSignature` and `AddFunction` methods to utilize the new attribute `tl.readonly_param_indices`, enhancing performance by allowing read-only cache loads.
* Modified the optimization pipeline to include the new annotation step, improving the overall efficiency of the code generation process.

* lint fix

* [Dependency] Update apache-tvm-ffi version to >=0.1.3

* Updated the version of apache-tvm-ffi in pyproject.toml, requirements.txt, and requirements-dev.txt to ensure compatibility with the latest features and fixes.
* Made adjustments in CUDA and HIP template files to use `const` qualifiers for global pointer parameters, enhancing code safety and clarity.

* lint fix

* [Enhancement] Refactor ReadWriteMarker for improved parameter handling

* Updated the ReadWriteMarker class to accept a set of parameter or data variables, enhancing its ability to track written variables.
* Introduced a new method, ResolveDataVarFromPtrArg, to resolve underlying buffer data from pointer-like arguments, improving accuracy in identifying written variables.
* Modified the MarkReadOnlyParams function to gather handle parameters and their corresponding buffer data variables, streamlining the process of determining read-only parameters.
* Enhanced the logic for identifying written variables to account for aliased data variables, ensuring comprehensive tracking of modifications.

* lint fix

* Update tma_load function to use const qualifier for global memory pointer

* Changed the parameter type of gmem_ptr in the tma_load function from void* to void const* to enhance type safety and clarity in memory operations.
* This modification ensures that the function correctly handles read-only global memory pointers, aligning with best practices in CUDA programming.

* Remove commented-out code and reorder transformations in OptimizeForTarget function for clarity

* Refactor buffer marking logic in annotate_read_only_params.cc to improve accuracy in identifying written variables. Update OptimizeForTarget function to reorder transformations for better clarity.

* [Refactor] Phase out the primitives folder since its design has been merged into tileop (#1429)

* Phase out primitives

* revert changes

* Refactor GemmWarpPolicy method signature for clarity

Updated the `from_warp_partition` method in the `GemmWarpPolicy` class to return the type `GemmWarpPolicy` instead of a string, enhancing type safety and clarity in the codebase. Removed an unnecessary blank line for improved readability.

* fix

* [CI]: Bump actions/upload-artifact from 5 to 6 (#1431)

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5 to 6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [CI]: Bump actions/download-artifact from 6 to 7 (#1432)

Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [Bugfix] Convey  `compile_flags` to ffi compilation path with pass_configs (#1434)

* [Enhancement] Add device compile flags support in pass configuration

* Introduced `kDeviceCompileFlags` option in the pass configuration to allow additional device compiler flags for CUDA compilation.
* Updated the `tilelang_callback_cuda_compile` function to merge extra flags from the pass configuration, enhancing flexibility in compiler options.
* Modified the `JITKernel` class to handle device compile flags appropriately, ensuring they are included during compilation.
* Documented the new pass configuration key for clarity on usage and expected input formats.

* lint fix

* [Refactor] Simplify compile_flags handling in JIT functions

* Removed redundant string check for compile_flags in the compile, jit, and lazy_jit functions, ensuring compile_flags is consistently treated as a list.
* Updated the JITKernel class to handle compile_flags as a list when a string is provided, enhancing code clarity and maintainability.

* lint fix

* fix

* [Enhancement] Improve buffer usage tracking in MakePackedAPI (#1435)

* Added detailed logging for data and shape variable parameters during buffer usage detection in the MakePackedAPI function.
* Refactored the UsedBufferDetector to differentiate between used parameters by data and shape variables, enhancing clarity in buffer management.
* Updated logic to ensure minimal carrier buffers are selected for shape symbols, improving the efficiency of parameter handling.

* [Enhancement] Improve InjectAssumes logic and make assumes work after SplitHostDevice (#1405)

* [Refactor] Refactor InjectAssumes logic and make assumes work after SplitHostDevice

* address comments

* fix

* fix submodule

* fix

* fix 3rdparty

* [Enhancement] Include PrimFunc name in memory cache logs for better debugging (#1437)

* Added the `get_prim_func_name` utility to extract human-readable function names from TVM PrimFuncs.
* Updated memory cache logging in `AutoTuner` and `KernelCache` classes to include the kernel name, improving clarity during cache hits.
* Enhanced debug logging to provide more informative messages when checking disk cache for kernels.

* [CI] Update lint dependencies and fix lint on trunk (#1433)

* [CI] Update pre-commit hooks

* [Lint] Pass correct `exclude-header-filter` to `clang-tidy`

* [Lint] Download latest `run-clang-tidy` script

* [CI] Show compile commands

* [CI] Add output grouping to GHA

* [Lint] Re-order pre-commit hooks

* [Enhancement] Refactor vectorization checks in loop_vectorize (#1440)

* Introduced a new function, IsExprInvariantInVectorBoundary, to encapsulate the logic for checking if an expression is invariant within vector boundaries, improving code clarity and reusability.
* Updated the existing vectorization logic to utilize this new function, streamlining the process of determining vectorization feasibility based on boundary conditions.
* Enhanced comments for better understanding of the vectorization criteria and mathematical rationale behind the checks.

* Enhance vectorized conversion support (#1438)

* [Feature] Support region as input of T.cumsum (#1426)

* [Feature] Support region as input of T.cumsum

- Extend T.cumsum to accept BufferRegion and BufferLoad inputs in addition to Buffer
- This enables operations on buffer slices/regions like:
  T.cumsum(InputG_fragment[i * chunk_size:(i + 1) * chunk_size], dim=0)
- Update cumsum_fragment to handle region inputs properly
- Add comprehensive tests for 1D and 2D region inputs including normal and reverse modes

Fixes #879

* Fix formatting and add docstring for cumsum_fragment

- Add comprehensive docstring for cumsum_fragment function
- Format code according to ruff style guidelines

* Fix CodeRabbit review issues

- Fix negative dimension bounds check (dim < -len(shape) instead of dim <= -len(shape))
- Add src/dst shape compatibility validation for out-of-place cumsum
- Update copy() type annotation to accept BufferRegion as dst parameter
- Fix test in-place mutation issues by using out-of-place cumsum operations
- Add non-divisible size test cases for tail region coverage

* Fix out-of-bounds access in region tests

- Add bounds clamping using T.min() for chunk_end calculations
- Prevents accessing beyond tensor bounds for non-divisible sizes
- Matches reference implementation behavior
- Fixes both 1D and 2D region test cases

* Fix region test: use simple slice expressions instead of T.min()

- Remove T.min() which cannot be used directly in slice indices
- Use chunk_start + chunk_size form instead
- Rely on system's automatic bounds checking for non-divisible sizes
- Update comments to reflect this approach

* Fix cumsum region: use region extents in lowering and update tests for shared memory

* Simplify fragment scope check using is_fragment()

---------

Co-authored-by: LeiWang1999 <leiwang1999@outlook.com>

* [Fix] Fix analyzer bind conflicting (#1446)

* [Refactor] Reduce direct dependency on PyTorch due to its limited type support (#1444)

* [Enhancement] Update KernelParam to use tvm.DataType directly and add torch_dtype conversion method

- Changed dtype in KernelParam from torch.dtype to tvm.DataType to support a wider range of data types and prevent information loss during conversions.
- Added a new method, torch_dtype, to convert tvm.DataType back to torch.dtype for tensor creation.
- Updated various adapters to utilize the new torch_dtype method for parameter type conversion during initialization.

* [Enhancement] Refactor CUDA type handling and add support for FP4 and FP8 types

- Renamed functions for clarity: GetFP8Type, GetFP6Type, and GetFP4Type are now GetTileLangFP8Type, GetTileLangFP6Type, and GetTileLangFP4Type respectively.
- Enhanced FP4 type handling to support additional lane sizes (2, 4, 8, 16, 32, 64).
- Updated CUDA code generation to include new FP8 and FP4 types, ensuring proper type handling in PrintType and related functions.
- Introduced new structures for FP8 types in cuda_fp8.h to facilitate better memory management and type packing.
- Added methods in KernelParam and tensor utilities to recognize and handle float4 types, improving compatibility with PyTorch.
- Enhanced logging for debugging purposes in various CUDA functions to track type handling and memory operations more effectively.

* lint fix

* Remove unnecessary logging statements from CUDA code generation and delete obsolete matrix multiplication test file.

* [Enhancement] Add support for FP4 and FP8 types in CUDA code generation

- Enhanced PrintVecElemLoad and PrintVecElemStore functions to handle new FP4 types.
- Updated arg_binder to allow float4 to match int8 at runtime, improving compatibility with PyTorch.
- Modified loop_vectorize to account for buffer dtype lanes in vectorization calculations.
- Refactored tensor type mapping to support new float4 and float8 types, ensuring correct type handling in tensor operations.
- Added tests for FP4 and FP8 copy operations to validate functionality and integration with existing workflows.

---------

Co-authored-by: Zhiwen Mo <zm125@ic.ac.uk>

* [Refactor] Use `pytest.mark.parameterize` to speedup parallel testing (#1447)

* Refactor GEMM tests to use parameterized pytest fixtures

- Converted multiple test cases for GEMM operations in `test_tilelang_tilelibrary_gemm_sp.py` to use `pytest.mark.parametrize` for better maintainability and readability.
- Similar refactoring applied to `test_tilelang_tilelibrary_gemm_sp_v2.py`, consolidating test cases for `run_gemm_ss`, `run_gemm_rs`, `run_gemm_sr`, and `run_gemm_rr` into parameterized tests.
- This change reduces code duplication and enhances the clarity of test configurations.

* Update testing/python/amd/test_tilelang_gemm_mfma_preshuffle.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* [Docs] Improve installation instructions for developers (#1450)

* [Feat] Integrate Z3 in TVM Arith Analyzer (#1367)

* [Bugfix] Improve autotune from elementwise_add function in examples (#1445)

* Remove JIT decorator from elementwise_add function in examples

* fix kernel compilation without autotune

* Refactor main function to accept parameters and update tests for autotune option

* Refactor autotune test function for morden style

* [Language] Introduce `T.annotate_restrict_buffers` (#1428)

* [Enhancement] Introduce non-restrict parameter support in code generation

- Added a new PrimFunc-level attribute `tl.non_restrict_params` to specify handle Vars that should not be marked with the restrict qualifier during code generation.
- Updated `CodeGenTileLangCPP`, `CodeGenTileLangCUDA`, and `CodeGenTileLangHIP` to handle non-restrict parameters, ensuring proper treatment of overlapping buffer aliases.
- Implemented a new annotation function `annotate_restrict_buffers` to facilitate the marking of buffer parameters as non-restrict.
- Enhanced the `SplitHostDevice` transformation to propagate non-restrict parameters from host to device functions.
- Added a new transform function `HoistNonRestrictParams` to manage non-restrict parameters effectively.

* [Enhancement] Improve HoistNonRestrictParams transformation

- Updated the HoistNonRestrictParams function to recursively collect all `tl.non_restrict_params` annotations from nested blocks, enhancing flexibility in annotation placement.
- Introduced a new NonRestrictCollector class to manage the collection and deduplication of non-restrict parameters.
- Modified the SplitHostDevice transformation to remove the non-restrict attribute from the host-side PrimFunc after propagation to device kernels.
- Adjusted the LowerAndLegalize function to directly apply the HoistNonRestrictParams transformation without exception handling, streamlining the process.

* [Refactor] Simplify non-restrict parameter handling in code generation

- Removed unnecessary normalization logic and associated data structures from `CodeGenTileLangCPP`, `CodeGenTileLangCUDA`, and `CodeGenTileLangHIP`.
- Streamlined the handling of non-restrict parameters by directly inserting them into the `non_restrict` set, improving code clarity and maintainability.
- Updated conditional checks to eliminate redundant checks against normalized names, enhancing performance and readability.

* [Dependency] Update TVM subproject to latest commit 68aa8461

- Updated the TVM subproject to the latest commit, ensuring compatibility with recent changes and improvements.
- Refactored non-restrict parameter handling in `CodeGenTileLangCPP`, `CodeGenTileLangCUDA`, and `CodeGenTileLangHIP` to enhance code clarity and maintainability.
- Adjusted the `SplitHostDevice` transformation to streamline the propagation of non-restrict parameters.

* fix

* [Analyzer] Require loop extent > 0 when entering loop (#1451)

* Updat ROCm CI to Nightly-ROCm-7.1 (#1449)

* [Enhancement] Update examples and tests for improved type handling functionality (#1448)

* [Enhancement] Update examples and tests for improved type handling and functionality

- Enhanced various example scripts to support new data types and improve compatibility with PyTorch.
- Updated tests across multiple modules to ensure correct functionality with the latest changes in type handling.
- Refactored code in examples to streamline operations and improve clarity, particularly in tensor operations and memory management.
- Added comprehensive tests for new features and fixed existing issues related to type conversions and buffer handling.

* [Refactor] Update accumulation data type to float32 across examples

- Changed accumulation data type from "float" to T.float32 in multiple example scripts to ensure consistency and improve numerical stability.
- This update affects various modules including flash attention, GEMM analysis, convolution, and deepseek MLA examples, enhancing type handling across the board.

* [Refactor] Standardize data type usage across benchmark scripts

- Updated data type definitions in benchmark scripts to use T.float16 and T.float32 consistently, enhancing clarity and type handling.
- Adjusted dtype assignments in matmul functions and configuration setups to align with the new standard.
- Improved overall code consistency and maintainability by ensuring uniform data type usage across various modules.

* [Refactor] Standardize data type usage in templates and scripts

- Updated data type definitions in various templates and scripts to use string representations (e.g., "float16", "int32") instead of T.float16 and T.int32 for improved consistency and clarity.
- Enhanced overall code maintainability by ensuring uniform data type usage across multiple modules, including convolution, elementwise operations, and matrix multiplication templates.
- This change aims to streamline type handling and improve compatibility with existing workflows.

* [Refactor] Standardize data type usage in examples and benchmarks

- Updated data type definitions in various example and benchmark scripts to use T.float16 and T.int32 consistently, enhancing clarity and maintainability.
- Adjusted dtype assignments in kernel functions and configuration setups to align with the new standard.
- Improved overall code consistency by ensuring uniform data type usage across multiple modules, including attention mechanisms, matrix multiplication, and GEMM examples.

* [Refactor] Import dtypes from language.v2 module

- Added import statement for dtypes from the language.v2 module to enhance type handling and maintain consistency across the codebase.
- This change aims to streamline data type management and improve overall code clarity.

* fix

* [Refactor] Standardize data type usage across scripts

- Updated data type definitions in various scripts to use string representations (e.g., "float16", "int8") instead of T.float16 and T.int8 for improved consistency and clarity.
- Adjusted dtype assignments in functions and configuration setups to align with the new standard, enhancing overall code maintainability.
- This change affects multiple modules, including benchmark and attention mechanisms, ensuring uniform data type usage throughout the codebase.

* [Refactor] Update data type handling for consistency and clarity

- Changed string representations of data types in the Hint class to use T.float32 and T.int32 for improved consistency.
- Added new data types "int4" and "int16" to the dtypes module, enhancing type support across the codebase.
- Updated function signatures and assertions in the lop3 and mxfp modules to utilize the new data types, ensuring uniformity in type handling.
- This refactor aims to streamline data type management and improve overall code clarity and maintainability.

* [Enhancement] Improve data type handling and error messaging

- Introduced a mapping for canonical data types to their display strings, enhancing clarity in type representation.
- Updated the dtype creation logic to utilize the new mapping, ensuring more intuitive handling of string inputs.
- Refined error messages in the lop3 module to provide clearer feedback on invalid source formats, improving debugging and user experience.

* [Fix] Correct boolean flag in GEMM SP test case

- Updated the boolean flag in the test_gemm_sp_sm90 function to ensure proper functionality in the test case.
- This change enhances the accuracy of the test and aligns it with expected behavior for the GEMM SP implementation.

* [Refactor] Standardize data type usage across scripts

- Updated data type definitions in various scripts to use T.float16 and T.bfloat16 consistently, enhancing clarity and maintainability.
- Adjusted dtype assignments in function signatures and argument parsing to align with the new standard, ensuring uniform data type usage throughout the codebase.
- This change affects multiple modules, including benchmarks and examples, improving overall code consistency and readability.

* [Refactor] Standardize data type usage in various modules

- Updated data type assignments in multiple scripts to utilize T.float32, T.int8, and T.int32 consistently, enhancing clarity and maintainability.
- Adjusted function signatures and parameter types across benchmarks, examples, and tests to align with the new standard, ensuring uniform data type usage throughout the codebase.
- This change improves overall code consistency and readability, impacting modules related to matrix multiplication, GEMM, and tensor operations.

* [Refactor] Update argument parsing for data types in benchmarks

- Changed argument parsing for data types in benchmark_matmul_intrinsic.py and benchmark_matmul_sp.py to use string representations ("float16", "int8", "float") instead of T.float16 and T.float.
- This update enhances consistency in data type handling across benchmark scripts, improving clarity and maintainability.

* [Refactor] Update data type handling in benchmark and example scripts

- Changed data type arguments in benchmark and example scripts to use string representations ("float16") instead of T.float16 for improved consistency.
- Updated function signatures and argument parsing to align with the new standard, enhancing clarity and maintainability across the codebase.
- This change affects multiple modules related to attention mechanisms and tensor operations, ensuring uniform data type usage throughout the examples.

* [Refactor] Fix data type conversion in multiple scripts

- Corrected the usage of the data type conversion method from dtype..as_torch() to dtype.as_torch() across various benchmark and example scripts.
- This change enhances consistency in data type handling and improves code readability, impacting modules related to attention mechanisms and tensor operations.

* [Refactor] Update float8 data type usage across multiple scripts

- Changed instances of T.float8_e4m3 to T.float8_e4m3fn in various benchmark, example, and test scripts to ensure consistency in data type handling.
- This update enhances clarity and maintainability across the codebase, particularly in modules related to matrix multiplication and tensor operations.

* [Refactor] Enhance float8 data type handling in CUDA code generation

- Updated the handling of float8 data types in the CUDA code generation to include additional float8 variants, improving type conversion logic.
- Adjusted conditions to ensure proper type checks for float8 conversions, enhancing clarity and maintainability in the codebase.
- Modified layout inference to streamline float8 type checks, ensuring consistency across the implementation.
- This change impacts modules related to matrix operations and CUDA code generation, improving overall type handling and conversion accuracy.

* [Refactor] Streamline float8 data type handling in CUDA and related modules

- Enhanced float8 data type handling in CUDA code generation by refining type conversion logic and ensuring consistent type checks.
- Updated layout inference for float8 types to improve clarity and maintainability across the implementation.
- This change impacts modules related to matrix operations and CUDA code generation, improving overall type handling and conversion accuracy.

* [Refactor] Remove unnecessary cache disabling in float8 example script

- Eliminated the call to tilelang.disable_cache() in example_group_per_split_token_cast_to_fp8.py to streamline the code.
- This change enhances clarity and maintainability of the example script without affecting its functionality.

* [Refactor] Update data type usage in debug print tests

- Changed the argument for dtype in the test_debug_print_buffer function from a string representation to the corresponding T.bool type.
- This update enhances consistency in data type handling within the test suite, improving clarity and maintainability.

* lint fix

* Update function parameter types from `str` to `T.dtype` for improved type safety in attention sink and related examples

* Refactor `gemv_alloc_reducer` function signature for improved readability by formatting parameters across multiple lines.

* [Issue Template] Enable blank issues in GitHub issue template(#1453)

* [CI] Moved the clang-tidy step to after pip install (#1456)

* [Bug] Fix tvm build script when patchelf is not found #1459)

* [Analyzer] Fix floordiv & floormod bug in z3 prover (#1458)

* fix floordiv & floormod in z3 prover

* fix lint error

* [Cache] Rename sparse compress cache directory (#1460)

* Enhance cache directory structure by including version information in sparse.py to ensure separate caches for different versions.

* Fix formatting in sparse.py by adding a newline for improved readability and consistency.

* [Language]Adds a random number generation capability through curand_kernel (#1461)

* add curand.{curand_init, curand}

* run format.sh

* add default value for curand_init & add test for curand

* Update testing/python/language/test_rand.py

Remove unused thread binding

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* remove unused library

* enable tilelang cache for testing

* run format.sh

* Revert "run format.sh"

This reverts commit 5afaff782f31cdf653e2c45b469da8dead228b8a.

* Revert "enable tilelang cache for testing"

This reverts commit c277a43e77938bd88d47a108dd1bd65734d4a1ae.

* Revert "remove unused library"

This reverts commit 568ad20611f039380113937fd131151a2bffd801.

* run format.sh

* ensure FreshName for __philox_state

* ensure FreshName for __philox_state
…
chengyupku added a commit to tile-ai/tilescale that referenced this pull request Feb 6, 2026
* Enhance threadblock swizzle templates with default offset parameter and streamline parser.py for better readability

* [Cache] Rename sparse compress cache directory

* Temporarily exclude sink tests from non-distributed example tests in CI to address timeout issues

* [DeepEP] Move deepep benchmark to example and allow compatible with new version DeepEP

* [Feat] Enhance `T.st` to support intra-node store to peer's symm memory

* use strided loop to simplify get_dispatch a bit

* [Feat] Support warp reduce operators

* draft notify dispatch

* rename and refactor `T.barrier/sync_blocks`

* fix prev typo

* [Feat] Add `get_device_tensor` function and related test

* support elect_one_sync() and add test

* draft dispatch

* suupport ld, st, warp_sync, continue and add test

* support warp vote and add test

* support device-side wait_ne

* refactor T.wait_* and refine dispatch test logic

* intra-node dispatch test passed

* draft combine

* support massage-only debug print

* intra-node combine test passed

* unify dispatch, migrate topk_idx to u64, support cached dispatch

* Refactor to pre-alloc buffers and expose interface, add benchmark

* remove redundant test

* update doc

* use int4 vectorization for dispatch

* use comm_stream for comm kernels

* optimze dispatch perf via skipping tensor validation

* add dispatch benchmark result

* make rank as an argument of the kernel

* use cuda postproc for vectorization in combine

* support int4 ld/st ptx in cuda template

* [Feat] Support auto vectorization for ld/st to optimize combine to surpass deepep

* lint

* upd doc

* make ci happy

* fix review issues

* fix import error

* Add DeepEP submodule and installation script for CI

* fix ci bug

* [Sync] Merge mainstream TileLang TVM-FFI features into TileScale (#47)

* [Example] Add GQA decoding kernel with varlen page table (#1265)

* [Example] Add page table for gqa decode

* [Example] Page table for varlen decoding

* [Lint]

* [Refactor] Remove redundant code

* [Lint]

* [Lint]

* [Lint]

* [Refactor] add support for numpy dtype conversion (#1255)

* add typing stub for tir.ir

* remove idents

* minor update

* [Refactor] add numpy conversion for dtype

* fix lint error

* remove unused np.float_ in dtype conversion

* fix type in np.int_

* fix typo

* minor fix

* remove debug files

* [EXAMPLE] In the flash attention example keep the max of all blocks seen in scores_max numerical stability (#1148)

* Keep the max of all blocks seen in scores_max for stability

* ruff formatting

* [Docs] Improve Installation Guide (#1270)

* [Docs] Improve installation guide

* address comments

* [Enhancement] Keep max score attention across blocks in FlashAttention for better numerical stablity (#1269)

* Implement max score retention across blocks in FlashAttention for improved stability

* fix manual pipeline parameters

* Update examples/flash_attention/example_gqa_fwd_varlen.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix typo

* more

* fix a previous typo

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* [Bugfix] Fix multiple cg defination when using T.sync_grid (#1272)

* [Minor] Remove from __future__ import annotations for python 3.8 (#1273)

* [BugFix] Adding extra parameters into autotune hashkey (#1274)

* [BugFix] Adding extra parameters into autotune hashkey

* lint

* None check

* check serializable

* Fix various issues under `int64_t` static and dynamic shape. (#1218)

* Fix various issues under int64_t static and dynamic shape.

* Resolve reviewed issues.

* Add unit test.

* fix

---------

Co-authored-by: LeiWang1999 <leiwang1999@outlook.com>

* Bug fix for Gated Delta Net benchmark script (#1267)

* fix argument order for fla chunk_gated_delta_rule_fwd_h

* explicit import assert_similar from utils

* rename utils module to avoid name clash

* set store_final_state and save_new_value to True

* fix

---------

Co-authored-by: LeiWang1999 <leiwang1999@outlook.com>

* [Bugfix] Minor fix for some cases (#1278)

* [Language] Add shape check in `T.view/reshape` (#1277)

* [Language] Add shape check in T.view/reshape

* address comments

* [FFI] Use tvm ffi as the default execution backend (#1259)

* [Refactor] Update FFI type handling and simplify argument management

* Refactored FFI type definitions in runtime and code generation files to use `TVMFFIAny` instead of `TVMValue`, enhancing type clarity.
* Updated function registration in `runtime.cc` to utilize canonical names for better consistency.
* Simplified argument handling in the `simplify` transformation, ensuring unused buffer parameters are removed only when simplification is enabled.
* Adjusted autotuner and profiler parameters to standardize the execution backend to `tvm_ffi`, improving clarity in backend selection.
* Removed obsolete `adapt_torch2tvm` function from tensor utilities to streamline the codebase and reduce complexity.

* [Update] Sync TVM submodule and enhance kernel source handling

* Updated the TVM submodule to commit cdc2aced, ensuring compatibility with recent changes.
* Added functionality to print kernel source in `example_blocksparse_gemm.py` for better debugging.
* Commented out the main execution call in test files to prevent unintended execution during testing.
* Introduced `tilelang.disable_cache()` in various test files to streamline testing and avoid cache-related issues.
* Refactored kernel source retrieval methods to improve clarity and consistency across different execution backends.

* [Refactor] Clean up imports and improve code formatting

* Removed unused import of `tilelang.testing` in `test_example_blocksparse_gemm.py` to streamline the code.
* Reformatted several lines in `arg_binder.cc`, `make_packed_api.cc`, `tvm_ffi.py`, and `adapter.py` for improved readability and consistency.
* Updated comments and spacing in `tvm_ffi.py` to enhance clarity without altering functionality.

* Update execution backend options and improve resolution logic

- Changed default execution backend from "cython" to "auto" in multiple locations to allow automatic selection based on the target.
- Expanded the list of supported execution backends to include "torch" and "nvrtc" across various classes and functions.
- Enhanced backend resolution logic in `KernelCache` and `AutoTuner` to ensure appropriate backend selection based on the target.
- Updated documentation to reflect changes in execution backend options and their defaults.

* lint fix

* fix

* Enhance argument handling in CUDA and HIP runtime modules

- Updated `ExtractFuncInfo` in `rt_mod_cuda.cc` and `rt_mod_hip.cc` to map boolean argument types to int32, ensuring compatibility with device runtime.
- Refactored `BindDLTensor` in `arg_binder.cc` to improve null handling and validation checks for DLTensor parameters, utilizing expression-level guards to prevent dereferencing null pointers.
- Enhanced error checking for buffer shape, strides, and data fields, ensuring robust handling of optional inputs and maintaining consistency across various checks.

* lint fix

* lint fix

* lint fix

* lint fix

* minor fix

* fix

* recover check

* Refactor argument binding and validation in `arg_binder.cc`

- Improved null handling and validation checks in `BindDLTensor`, ensuring safe dereferencing of pointers.
- Enhanced consistency checks for buffer shape, strides, and data fields, utilizing expression-level guards.
- Updated `MakePackedAPI` to maintain code clarity and consistency in argument handling.
- Minor adjustments in test files to streamline kernel execution and improve readability.

* lint fix

* stride fix

* minor fix

* fix

* lint fix

* lint fix

* Add CUDA stream access policy window helpers and integrate with L2 persistent cache management

- Introduced functions to set and reset the CUDA stream access policy window, allowing for better control over L2 cache usage.
- Updated runtime files to include new FFI packed functions for managing stream attributes.
- Modified lower_hopper_intrin to incorporate prologue and epilogue statements for L2 cache setup and teardown.
- Enhanced tests to verify the inclusion of new FFI calls in the generated kernel source.

* check with symbolic

* support null ptr

* Update CMakeLists and lower.py for code generation and subproject status

- Added `codegen_c_host.cc` to the list of source files in CMakeLists.txt for improved code generation support.
- Updated the function call in `lower.py` to use `target.build.tilelang_c` for C target host code generation, enhancing compatibility.
- Marked the TVM subproject as dirty to indicate local modifications.

* lint fix

* Update comments for clarity in quickstart.py

* [Bugfix] Supply missing `T.print` for bool type (#1279)

* fix for bool dtype

* lint fix

* fix

* ci fix

* [Fix] Fix memory leak bug (#1281)

* add typing stub for tir.ir

* remove idents

* minor update

* [Refactor] add numpy conversion for dtype

* fix lint error

* remove unused np.float_ in dtype conversion

* fix type in np.int_

* fix typo

* minor fix

* remove debug files

* fix memory leak bug

* fix lint error

* add comments

* fix lint error

* remove duplicated, because tilelang doesn't dependent deprecated

* [Enhancement] Enhance CUDA compilation by integrating pass context configuration (#1283)

- Updated the `tilelang_callback_cuda_compile` function to accept a `pass_config` parameter, allowing for more flexible compilation options.
- Introduced handling for fast math and PTXAS options based on the provided pass configuration.
- Modified the CUDA build process in `rt_mod_cuda.cc` to utilize the current pass context, improving the integration of compilation settings.
- Refactored NVCC command construction to use a dedicated function for better clarity and maintainability.

* Fix the bug in issue #1266 (#1284)

Co-authored-by: cheeryBloosm <liu_yu_hao@126.com>

* [Language][UX] Nested loop checker in pre-lowering stage (#1288)

* [Language][UX] Nested loop checker in pre-lowering stage

* rename

* comment

* address comments

* [Compatibility] Support CUDA 11.3 (#1290)

* [Feat] Add support for using `T.Tensor(n * 2 + 1)` in function annotation (#1285)

* [Feature] Add support for A: T.Tensor(n + 1) and A: T.Tensor(2*n)

* issue fix

* fix

* fix

* decreate nproc for debugging

---------

Co-authored-by: Lei Wang <leiwang1999@outlook.com>

* [Feat] add support for passing reference in T.Var annotation (#1291)

* [Enhancement] Shared Memory Size Can be Dynamic (#1294)

* bugfix

* lint fix

* test

* lint fix

* increate procs

* recover

* [Fix] Remove unused let_bindings_ in CodeGenC to fix #1300 (#1305)

* [Feat] add missing support of uint32x2

* [Feat] Add `T.Ref` annotation and tests

* fix lint error

* minor update for error message on twice decl

* Remove unused let_bindings_ in CodeGenC to fix #1300

* [Bugfix] Fallback to the old AtomicAdd implementation for legacy architectures (#1306)

* [Fix] Fix frame scope error in T.macro (#1308)

* [Fix] Fix #1307 by adding macro inside function

* fix lint error

* add comments and fix lint error

* Remove debug print from enter_frame method

Removed debug print statement from enter_frame method.

---------

Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>

* [WIP] support more dtypes for tcgen05 (#1229)

support ld with pack for fp32 dtype

add dump

add tempalte expand

remove unused dtype and change to rebased apis

* Improve memory access safety and `T.assume` handling (#1292)

* Improve memory access safety and T.assume handling

* Improve memory access safety and T.assume handling

* bugfix

* lint fix

* bugfix

* bugfix

* refactor legalize safe memory access pass

---------

Co-authored-by: Lei Wang <leiwang1999@outlook.com>

* [Bugfix] Fix autotune cache (#1315)

* [Refactor] Backup Analyzer to get the appropriate arith informations (#1311)

* [Refactor] Update Vectorization Functions to Accept Analyzer Parameter

- Modified `VectorizeLoop` and related functions to accept an `arith::Analyzer` parameter, enhancing their capability to perform analysis during vectorization.
- Updated multiple instances in `copy.cc`, `fill.cc`, `parallel.cc`, and layout inference files to utilize the new analyzer parameter for improved performance and correctness.
- Ensured consistency across vectorization logic by integrating the analyzer into existing workflows, facilitating better optimization opportunities.

* [Fix] Corrected PostOrderVisit call in loop_vectorize.cc

- Updated the PostOrderVisit function to analyze the body of the loop node instead of the node itself, ensuring proper handling of nested loops during vectorization analysis.

* fix

* lint fix

* fix

* Revert "[WIP] support more dtypes for tcgen05 (#1229)" (#1323)

This reverts commit 0d101c110f74ebf2ef8c11a5ece9dfb314b48baa.

Co-authored-by: Zhiwen Mo <zm125@ic.ac.uk>

* [CI]: Bump actions/checkout from 5 to 6 (#1319)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [CI]: Bump pypa/cibuildwheel from 3.2 to 3.3 (#1318)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [Installation] Fix building using customized TVM path (#1326)

* [Release] Allow developer with write permission to trigger wheel release (#1322)

* [Feat] Support warp reduce (#1316)

* [Feat] Support warp reduce

* lint

* add test

* lint

* [Enhancement] Support more dtype in `T.print` (#1329)

* [Enhancement] Support more dtype in `T.print`

* upd

* upd

* [BugFix] Use BufferRegion in tl.cumsum to infer buffer shape (#1321)

* [BugFix] Use BufferRegion in tl.cumsum to infer buffer shape

* remove debug lines

* remove rubbish

* Fix decorator syntax for atomic_different_memory_orders_program

---------

Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>

* [Fix] fix wrong uint narrowing bug in tvm in #1310 (#1320)

* [Refactor] Disable strided buffer load inside tvm (#1301) (#1332)

* [Refactor] Moving `NormalizeToBufferRegion` and `MakeAccessPtrFromRegion` to utils (#1333)

* Refactor GEMM and Reduce operations by moving NormalizeToBufferRegion and MakeAccessPtrFromRegion to utils.{h,cc} for better code organization and reuse.

* lint fix

* [Fix] Fix bug copying from or to local buffer (#1304) (#1324)

* [Fix] fix copy from or to local buffer (#1304)

* fix lint error

* minor fix testing script

* [Language][UX] Semantic check for parallel fragment access (#1338)

* Add unit tests for T.assume (#1341)

* Add test for T.assume

* Add unit test for T.assume

* Add unit test for T.assume

* Add unit tests for T.assume

* Remove debug print for kernel source

Remove print statement for kernel source in tests.

* Update test_tilelang_language_assume.py

---------

Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>

* [Feat] Extend LegalizeNegativeIndex to support buffer store stmts (#1339)

This commit enhances the LegalizeNegativeIndex transformation pass to handle
both buffer load and store operations with negative indices and adds some
test cases.

* [Refactor] Phaseout vmap for Tile Operators (#1334)

* Refactor GEMM and Reduce operations by moving NormalizeToBufferRegion and MakeAccessPtrFromRegion to utils.{h,cc} for better code organization and reuse.

* lint fix

* Refactor region handling by removing the RegionOp and updating NormalizeToBufferRegion to only accept BufferLoad and BufferRegion. This change improves code organization and simplifies the handling of memory regions across various operations.

* fix

* Refactor memory region handling by introducing `tl.region` calls across various operations, including GEMM and fill functions. This change enhances the consistency of region management and improves code organization by utilizing utility functions for buffer region conversions.

* fix

* fix

* test fix

* lint fix

* Refactor GEMM operations to improve memory region handling by replacing `mbarPtr_` with `mbarRegion_` and updating related logic in both C++ and Python implementations. This change enhances the clarity and consistency of buffer region management.

* fix

* lint fix

* fix

* fix

* test fix

* lint fix

* lint fix

* minor fix

* fix

---------

Co-authored-by: Zhiwen Mo <zm125@ic.ac.uk>

* [Enhancement] add more dtype and fix mma.ws for fp16 for tcgen05 (#1327)

* feat: add fp8 variants; add placeholder for fp6/fp4 in meta

support ld with pack for fp32 dtype

add dump

add tempalte expand

remove unused dtype and change to rebased apis

* fix: when atom-m!=128, enable_ws

* fix: typo in tcgen05 meta; dispatch in gemm sm100

* [Refactor] Enhance CopyNode's IterVar Creation and Range Handling (#1346)

* [Refactor] Enhance CopyNode's IterVar Creation and Range Handling

This commit refines the `MakeIterVars` method in `CopyNode` to select base ranges based on memory scope levels, ensuring that the chosen ranges are not smaller than the original source ranges. Additionally, it updates the Python `copy` function to clarify range handling, including broadcasting logic and extent alignment. These changes improve the robustness and clarity of the copy operation's implementation.

* test fix

* [Fix] Fix missing `not` rewrite in frontend (#1348)

* [Enhancement] Add support for k_pack in gemm_mfma (#1344)

* add support for k_pack

* support benchmark on ROCm

* fix format

* Add sparse fine-tuning kernel for deepseek sparse attention to example (#1296)

* [EXAMPLE] add example for dsa sparse finetuning

* [Refactor]

* [Refactor] Improve assertion handling in CodeGenCHost and ArgBinder (#1352)

* [Refactor] Improve assertion handling in CodeGenCHost and ArgBinder

This commit refines the assertion message generation in CodeGenCHost by optimizing the handling of equality checks and reducing buffer size for error messages. Additionally, it enhances the ArgBinder by introducing a nullable guard mechanism for assertions, allowing for more precise error handling when binding arguments. The changes improve the clarity and efficiency of assertion handling across the codebase.

* [Enhancement] Update matmul kernel and optimize argument binding

This commit enhances the matmul kernel by introducing additional tensor parameters and refining the pipeline stages for improved performance. It also updates the argument binding mechanism to include a flag indicating whether buffers are used, enhancing the efficiency of buffer management. Furthermore, the optimization phase in the engine is improved by adding a simplification step, ensuring better performance and clarity in the generated code.

* lint fix

* [Enhancement] Add tensor checks documentation and improve argument binding assertions

This commit introduces a new documentation page for host-side tensor checks, detailing the automatic validations performed by TileLang on kernel arguments. It enhances the ArgBinder by adding assertions for non-null pointers when arguments are used, improving error handling. Additionally, the optimization phase in the engine is updated to include a simplification step, ensuring better performance and clarity in the generated code.

* [Enhancement] Update .gitignore and refine matmul kernel for improved performance

This commit adds host checks logs to the .gitignore file to prevent unnecessary log files from being tracked. Additionally, it refines the matmul kernel by adjusting pipeline stages, updating tensor parameters, and enhancing argument handling for better performance. The changes also include improved error messages in the argument binding process, ensuring clearer diagnostics for users.

* lint fix

* lint fix

* [Refactor] Simplify tensor_null_test function and remove ptr_null_test

This commit refactors the tensor_null_test function by adding a with_bias parameter and removing the ptr_null_test function, which was previously unused. The run_test function is updated to reflect these changes, streamlining the testing process for tensor operations.

* lint fix

* fix

* [Refactor] Simplify index sign state handling in LegalizeNegativeIndex (#1354)

This commit refines the logic for determining the sign state of indices in the LegalizeNegativeIndex transformation. It prioritizes vector patterns, specifically Ramp and Broadcast nodes, to avoid compile-time lane queries. The handling of scalar indices is also streamlined, ensuring clearer diagnostics when non-negativity cannot be proven. These changes enhance the robustness and clarity of index handling in the transformation pass.

* [Enhancement] Improve error handling and assertion messages across runtime and argument binding (#1356)

This commit enhances the error handling mechanisms in the runtime by introducing CPU-safe runtime helpers and refining assertion messages in the CodeGenCHost and ArgBinder. It includes structured packed error messages for various conditions, improving clarity in diagnostics. Additionally, the CMake configuration is updated to always include necessary runtime helpers, ensuring consistent error reporting. The changes aim to provide clearer feedback during runtime errors and improve the overall robustness of the argument binding process.

* [Bugfix] Disable floordiv optimization due to integer overflow risk (#1355)

* disable overflow-prone floordiv optimization in lower_intrin.cc

* disable overflow-prone floordiv optimization in lower_intrin.cc

* [Bugfix] Fix the jit_kernel issue (#1357)

* [Bugfix] Fix the jit_kernel issue

* Update README.md

---------

Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>

* [Refactor] Update Fragment Indexing in ParallelOpNode's InferLayout Method (#1359)

This commit refines the Fragment creation process in the InferLayout method of ParallelOpNode. It removes the unnecessary forward_index array and utilizes default fragment indexing for consistency with other operations. Additionally, it binds the thread range to enhance comparability across different operations.

* [Analysis] Enhance NestedLoopChecker with tile op cases (#1358)

* [Analysis] Enhance NestedLoopChecker with tile op cases

* fix tileop issue

* [Language] support `T.gemm_sp_v2` on sm80 and sm89 (#1056)

* [misc] add a cpp side wrapper for gemm_sp_py

* [misc] typing

* [IR] bind GemmSPWarpPolicy

* [chore] add wrapper code

* [IR] fix GemmSPWarpPolicy

* [codegen] apply ptxas instructions

* [intrinsic] add typical (unused) mma layout

* [template] add uint16 debug func

* [intrinsic] add b matrix layout

* [gemm_sp] enable fp16/bf16 on sm8x

* [layout] refactor fp16/bf16 layout

* [gemm_sp] enable int8

* [chore] update test case dtype

* [gemm_sp] enable fp32

* [layout] refactor layouts

* [intrinsic] enable ldmatrix for mat A

* [layout] enable ldsm for matrix b

* [layout] add ldmatrix for fp32 and fp8

* [chore] refine

* [chore] refactor

* [chore] add fp8 efactor

* [chore] refactor

* [chore] add remove negative zero util

* [example] add a custom compress kernel

* [chore] minor update

* [test] refactor gemm_sp test

* [refactor] make metadata layout func

* [example] add option for using cutlass layout

* [doc] add a gemm_sp doc

* [doc] minor polish

* [chore] remove unused

* [bugfix] fix non replicate b case

* [test] refactor

* [chore] add a check

* [bugfix] fix util bug

* [wip] init a new test case for v2

* [chore] minor refactor

* [chore] minor update

* [bugfix] enable 16bit rs

* [language] enable rs

* [language] enable gemm_sp_sr

* [language] enable gemm_sp_rr

* [test] enable more tests

* [tvm] update ffi binding

* [chore] remove print

* [chore] fix benchmark script

* [lint] precommit lint

* [chore] apply feedback

* [test] use arch 8.0

* [chore] rollback ::ordered_metadata for backward compatibility

* [bugfix] fix captialized

* [example] keep gemm_sp on hopper

* [test] fix no fp8 normal kernel

* [test] reduce matmul size to satisfy accum error

* [test] use cal_diff for assertion

* [bugfix] expand float8 type

* [lib] add make_int4 for short type

* [language] add transpose E

* [bugfix] fix wrong var

* [format] format

* [chore] refactor binding

* [chore] fix wrong passing var

* [Bugfix] Update TIR registration for GemmSPPy to use tile operation (#1361)

* [Enhancement] Implement dynamic unroll factor in CUDA code generation (#1360)

* [Enhancement] Implement dynamic unroll factor in CUDA code generation

This commit introduces support for specifying a dynamic unroll factor in the CUDA code generation. The `unroll_factor` map is added to store unroll factors for loop variables, allowing for more flexible and optimized loop unrolling. Additionally, the `unroll` function is integrated into the loop language, enabling users to define unroll factors directly in their code. This enhancement improves performance by allowing tailored unrolling strategies based on specific loop characteristics.

* lint fix

* [Bugfix] Correct initialization of non-zero counters in custom compress kernel and update TIR registration for gemm_sp_py to use the correct tile operation

* [CI] [pre-commit.ci] autoupdate (#1362)

updates:
- [github.com/pre-commit/mirrors-clang-format: v21.1.2 → v21.1.6](https://github.com/pre-commit/mirrors-clang-format/compare/v21.1.2...v21.1.6)
- [github.com/astral-sh/ruff-pre-commit: v0.14.3 → v0.14.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.14.3...v0.14.7)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [Bugfix] Remove debug print in PyStmtFunctionVisitor  (#1363)

* [Debug] Always include line info in NVCC command for improved profiling and mapping (#1364)

* [Refactor] Update condition for benchmarking in example_gemv.py and simplify cached library path handling in sparse.py (#1365)

* [Enhancement] Add DISABLE_CACHE environment variables (#1368)

* [Refactor]: Remove useless include in atomicadd_vectorize.h (#1371)

* [Refactor] Generalize fp8 process (#1372)

* [Refactor] Update condition for benchmarking in example_gemv.py and simplify cached library path handling in sparse.py

* [Enhancement] Extend support for float8 data types in GEMM operations

- Updated GEMM operations to recognize additional float8 data types: `float8_e4m3fn` and `float8_e5m2fnuz`.
- Refactored condition checks in `checkWgmma` methods to simplify float8 type handling.
- Adjusted test cases to ensure compatibility with the new float8 types in tile language examples.

* lint fix

* [Layout] Enhance Free Layout Inference (#1375)

* [Refactor] Update condition for benchmarking in example_gemv.py and simplify cached library path handling in sparse.py

* [Enhancement] Extend support for float8 data types in GEMM operations

- Updated GEMM operations to recognize additional float8 data types: `float8_e4m3fn` and `float8_e5m2fnuz`.
- Refactored condition checks in `checkWgmma` methods to simplify float8 type handling.
- Adjusted test cases to ensure compatibility with the new float8 types in tile language examples.

* lint fix

* [Enhancement] Add injective layout detection and exception handling

- Introduced `DetectInjective` method in `FragmentNode` to check for injective layouts.
- Added `LoopLayoutInjectiveException` to handle errors related to non-injective layouts.
- Updated `InferLayout` methods in `ParallelOpNode` to utilize injective checks and log relevant information.
- Refactored layout inference queue management to use `std::deque` for improved performance and added prioritization logic for buffer layouts.

* remove debug print

* remove debug print

* remove debug print

* minor layout fix

* fix for T.view

* [Enhancement] Improve injective layout detection in FragmentNode

- Updated the `DetectInjective` method to handle symbolic dimensions more effectively by introducing a mechanism to collect symbolic shapes and adjust the detection level accordingly.
- Added logging for cases where the layout detection falls back to NoCheck due to symbolic dimensions.
- Minor update to the test file to include the tilelang testing module.

* [Refactor] Simplify layout inference for bulk copy operations

- Removed unnecessary conditions for bulk load/store operations in the layout inference logic.
- Streamlined the handling of layout application for bulk copy instances to enhance clarity and maintainability.

* remove debug print

* [Enhancement] Introduce layout-related exceptions and improve error handling

- Added `LayoutConflictException` and `LoopLayoutInjectiveException` classes for better exception management in layout operations.
- Updated `InferLayout` method in `ParallelOpNode` to throw `LoopLayoutInjectiveException` with detailed error information when injective layout checks fail.
- Removed redundant exception class definitions from `parallel.h` to streamline code organization.

* [Enhancement] Introduce buffer var lca analysis for pass plan buffer allocations (#1376)

* Update submodule TVM to latest commit and add PlanAndUpdateBufferAllocationLocation function to transform module

- Updated the TVM submodule to commit 3a32b763.
- Added a new function `PlanAndUpdateBufferAllocationLocation` in the transform module to facilitate buffer allocation planning within PrimFuncs.

* Refactor buffer allocation code for improved readability and consistency

- Updated formatting and spacing in `plan_update_buffer_allocation_location.cc` for better code clarity.
- Standardized the use of pointer and reference syntax across various class methods.
- Enhanced comments for better understanding of buffer allocation logic.
- Removed unnecessary lines and improved overall code structure.

* Refactor buffer allocation checks for improved clarity

- Replaced size checks with empty checks for `ffi::Array<Buffer>` in `plan_update_buffer_allocation_location.cc` to enhance code readability.
- Updated conditions in multiple methods to use `empty()` instead of comparing size to zero, streamlining the logic.

* [Tool] Provide layout visualization tool (#1353)

* Provide layout visualization tool

Adds a layout visualization tool to TileLang, which helps users understand and debug the layout transformations applied during compilation.

This tool visualizes the memory layout of tensors at different stages of the compilation process, allowing developers to identify potential inefficiencies and optimize their code for better performance.

The visualization can be enabled via a pass config option.

* format

* add layout visual example

* Adds vis extra with matplotlib dependency

* rafactor pass config name

* fix lint

* Enables configurable layout visualization formats

Allows users to specify the output formats (png, pdf, svg) for layout visualization through a pass config option.

This change provides more flexibility in how layout visualizations are generated, allowing users to choose the formats that best suit their needs.

It also fixes a bug where layout visualization was not correctly disabled when the config option was set to "false".

* Adds visual layout inference tool docs

* fix lint

* fix lint

* Rafactor configurable layout visualization formats

* fix lint

* fix typo

* add some comments

* fix lints

* add some warnings for user

* Moves layout visualization

* Refactors layout visualization pass configuration

Updates the layout visualization pass configuration to use boolean flag for enabling and a string for specifying formats.

* Enables multiple layout visualization formats

* Updates layout visualization docs

* Moves layout visualization to analysis

* [Release] Relax constraint of tvm-ffi to compatible version (#1373)

Co-authored-by: LeiWang1999 <leiwang1999@outlook.com>

* [Language] Tilelang LazyJIT Experimental Version (#1337)

* initial step

* modify builder

* scratch version of new frontend

* write some tests

* add many tests

* add typing stub for tir.ir

* remove idents

* minor update

* minor update

* First version of jitv2 (renamed to LazyJIT)

* fix pre-commit error

* minor fix

* fix lint error

* fix lint error

* Fix conditional check for PrimFunc instance

---------

Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>

* [Builder] Enhance variable name binding and scope management (#1378)

- Improved handling of TVM Var/Buffer names to prevent out-of-scope errors when reusing Python names across different for-frames.
- Added assertions to ensure variables are defined within the correct control flow frame, enhancing error checking and code reliability.

* [Bugfix] make cuda driver api compat with cuda12/13, along with tests (#1379)

* [Fix] typo in cuda attr (#1380)

* [Bugfix] make cuda driver api compat with cuda12/13, along with tests

* fix typo in cudaDevAttr

* [Language V2] Minor fix for complex annotations (#1381)

* [Release] Bump Version into 0.1.7 (#1377)

* Update VERSION to 0.1.7

* Update Python version in distribution scripts to support CPython 3.9 and log output

* [Typing] Enhance compatibility for advanced typing features in Python (#1382)

- Updated `allocate.py` and `annot.py` to improve compatibility with Python 3.9 and later by conditionally importing advanced typing features such as `TypeVarTuple`, `Unpack`, and `ParamSpec`.
- Added fallback imports from `typing_extensions` for environments using earlier Python versions.
- Improved handling of generic alias detection to ensure consistent behavior across different Python versions.

* [Bugfix][Build] Update CMake configuration to remove project root injection for sys.path (#1385)

* [Build] Update CMake configuration for tilelang_cython_wrapper installation

- Adjusted output directories for the tilelang_cython_wrapper to ensure that development builds place the extension in build/lib.
- Updated installation paths to place the extension in tilelang/lib within the wheel, improving organization and avoiding potential conflicts with other modules.
- Modified the internal library path exposure in env.py to prevent shadowing of common module names, enhancing compatibility and usability in user projects.

* [Build] Standardize output directories for tilelang libraries

- Set output directories for both tilelang and tilelang_module libraries to "${CMAKE_BINARY_DIR}/lib" for consistency in development builds.
- This change enhances organization and ensures that all build artifacts are located in a unified directory structure.

* [BugFix] Fix split kernel layout bug of GQA decode (#1386)

* [BugFix] Fix split kernel layout bug of GQA decode

* [BugFix] Avoid local with Parallel; use robust fragment instead

* [Enhancement] Add debug output methods for Layout and Fragment classes (#1392)

* [Doc] Update logging docs (#1395)

* [Enhancement] Refactor inflight computing to support dynamic pipeline extents (#1399)

* [Build] Update CMake configuration for tilelang_cython_wrapper installation

- Adjusted output directories for the tilelang_cython_wrapper to ensure that development builds place the extension in build/lib.
- Updated installation paths to place the extension in tilelang/lib within the wheel, improving organization and avoiding potential conflicts with other modules.
- Modified the internal library path exposure in env.py to prevent shadowing of common module names, enhancing compatibility and usability in user projects.

* [Build] Standardize output directories for tilelang libraries

- Set output directories for both tilelang and tilelang_module libraries to "${CMAKE_BINARY_DIR}/lib" for consistency in development builds.
- This change enhances organization and ensures that all build artifacts are located in a unified directory structure.

* [Refactor] Update TVM subproject and enhance pipeline loop handling

- Updated the TVM subproject to commit 90581fe9e5287bbcf1844ad14255a1e1e8cdf7f0.
- Added new fields to `PipelineAnnotation` and `RewrittenBlockInfo` structures to track original statement indices and improve async state management.
- Refactored `EmitImpl` and `PopulateWaitCounts` methods to enhance clarity and functionality, including better handling of commit groups and wait counts.
- Simplified access index calculations and strengthened analyzer constraints for loop bounds.

* [Cleanup] Remove license block and unused includes from inject_pipeline.cc

- Eliminated the Apache license block from the top of the file to streamline the code.
- Removed unused include directives for memory and stringstream to enhance code clarity and reduce unnecessary dependencies.

* [Refactor] Enhance transformation pipeline and test execution

- Added an additional Simplify transformation in the InjectSoftwarePipeline to improve optimization.
- Updated the test file to call `test_trival_pipeline()` directly, commenting out the previous main execution for better test isolation.

* [AMD] Fix 3 bugs when build docker on amd mi3x gpu (#1401)

* [Typo] Fix tilelang link in README.md (#1402)

* [Dependency] Update apache-tvm-ffi version to >=0.1.2 (#1400)

* [Dependency] Update apache-tvm-ffi version to >=0.1.2 in project files

* [Dependency] Update subproject commit for TVM to latest version afc07935

* [Enhancement] Add support for optional step parameter in loop constructs

- Updated loop creation functions to accept an optional step parameter, enhancing flexibility in loop definitions.
- Modified ForFrame implementations to utilize the new step parameter across various loop types including serial, parallel, and pipelined loops.
- Adjusted related vectorization transformations to accommodate the step parameter, ensuring consistent behavior in loop vectorization processes.

* lint fix

* [AMD] Enable FA2 fwd on AMD MI300X (#1406)

* enable FA2 on AMD MI300X

* make lint happy

* [TypoFix] fix typo for SM120 (#1408)

* [Doc] Minor documentation update (#1410)

* [Dependency] Add torch-c-dlpack-ext to project requirements (#1403)

* [Dependency] Add torch-c-dlpack-ext to project requirements

* Added torch-c-dlpack-ext to both pyproject.toml and requirements.txt to provide prebuilt torch extensions, which may prevent JIT compilation on first import of TVM FFI.

* [Build] Update manylinux images in project configuration

* Changed the manylinux image for x86_64 from "manylinux2014" to "manylinux_2_28" in both pyproject.toml and the Dockerfile to align with updated standards for compatibility and performance.

* [Build] Update CUDA repository configuration in pyproject.toml

* Changed the package manager command from `yum-config-manager` to `dnf config-manager` for adding the CUDA repository, ensuring compatibility with newer systems.

* fix

* [Build] Update CUDA repository to RHEL 8

* Changed the CUDA repository configuration in both pyproject.toml and the manylinux Dockerfile from RHEL 7 to RHEL 8, ensuring compatibility with newer systems.

* test: run out of space

* use cu130 to reduce size

* upd

* upd comment

* upd

---------

Co-authored-by: Your Name <wenji.yyc@alibaba-inc.com>

* [Dependency] Update TVM subproject to latest commit 2b1ead1a (#1412)

* [Enhancement] Introduce `T.__ldg` (#1414)

* [Enhancement] Add __ldg intrinsic for CUDA read-only cache loads

* Introduced the __ldg intrinsic to enable explicit read-only cached loads from global memory in CUDA.
* Updated the corresponding documentation and added support in both CUDA and HIP code generation.
* Enhanced the Python interface for __ldg to accept BufferLoad and Buffer types, improving usability.

* [Enhancement] Update formatting and linting rules in pyproject.toml; minor test adjustment

* Added new formatting rules in pyproject.toml to enforce consistent code style, including hanging indents and argument splitting.
* Updated test_tilelang_language_intrinsics_codegen.py to improve readability by adding a blank line before the main execution block.
* Refactored error messages in builtin.py for better clarity and consistency, ensuring proper formatting in function definitions and raising ValueErrors.

* lint fix

* [Enhancement] Improve vectorization invariant check (#1398)

* Improve loop vectorize

* Improve loop vectorize

* Improve loop vectorize

* Improve loop vectorize

* Improve loop vectorize

* Add some vectorize tests and comments

* [Lint] Phaseout Yapf format and embrace ruff format (#1417)

* [Atomic] Use ptr for atomicAdd dst instead of reference (#1425)

* [Enhancement] Update AtomicAdd function signature to accept pointer to destination

* Modified AtomicAdd in CUDA to take a pointer instead of a reference for the destination argument.
* Updated related code in atomicadd_vectorize.cc to ensure compatibility with the new signature.
* Adjusted Python interface in atomic.py to pass the destination by pointer, aligning with device function requirements.

* [Enhancement] Refactor AtomicAddRet function signature to accept pointer

* Updated AtomicAddRet in both CUDA and HIP to take a pointer instead of a reference for the address argument, improving consistency with the AtomicAdd function.
* Adjusted the implementation to ensure proper reinterpretation of the address type for atomic operations.

* lint fix

* [Enhancement] Refactor AtomicAddNode::MakeSIMTLoop to use destination pointer

* Updated the MakeSIMTLoop function to build a pointer to the destination element using tvm_access_ptr instead of loading the destination value directly.
* Simplified the handling of source and destination predicates, improving clarity and maintainability of the code.
* Ensured compatibility with the new pointer-based approach for atomic operations.

* lint fix

* test fix

* lint fix

* [CUDA] Add read-only parameter annotation for CUDA codegen (#1416)

* [Enhancement] Add read-only parameter annotation for CUDA codegen

* Introduced the `AnnotateReadOnlyParams` transformation to annotate read-only handle parameters in PrimFuncs, enabling the generation of `const` qualifiers in CUDA codegen.
* Updated `PrintFunctionSignature` and `AddFunction` methods to utilize the new attribute `tl.readonly_param_indices`, enhancing performance by allowing read-only cache loads.
* Modified the optimization pipeline to include the new annotation step, improving the overall efficiency of the code generation process.

* lint fix

* [Dependency] Update apache-tvm-ffi version to >=0.1.3

* Updated the version of apache-tvm-ffi in pyproject.toml, requirements.txt, and requirements-dev.txt to ensure compatibility with the latest features and fixes.
* Made adjustments in CUDA and HIP template files to use `const` qualifiers for global pointer parameters, enhancing code safety and clarity.

* lint fix

* [Enhancement] Refactor ReadWriteMarker for improved parameter handling

* Updated the ReadWriteMarker class to accept a set of parameter or data variables, enhancing its ability to track written variables.
* Introduced a new method, ResolveDataVarFromPtrArg, to resolve underlying buffer data from pointer-like arguments, improving accuracy in identifying written variables.
* Modified the MarkReadOnlyParams function to gather handle parameters and their corresponding buffer data variables, streamlining the process of determining read-only parameters.
* Enhanced the logic for identifying written variables to account for aliased data variables, ensuring comprehensive tracking of modifications.

* lint fix

* Update tma_load function to use const qualifier for global memory pointer

* Changed the parameter type of gmem_ptr in the tma_load function from void* to void const* to enhance type safety and clarity in memory operations.
* This modification ensures that the function correctly handles read-only global memory pointers, aligning with best practices in CUDA programming.

* Remove commented-out code and reorder transformations in OptimizeForTarget function for clarity

* Refactor buffer marking logic in annotate_read_only_params.cc to improve accuracy in identifying written variables. Update OptimizeForTarget function to reorder transformations for better clarity.

* [Refactor] Phase out the primitives folder since its design has been merged into tileop (#1429)

* Phase out primitives

* revert changes

* Refactor GemmWarpPolicy method signature for clarity

Updated the `from_warp_partition` method in the `GemmWarpPolicy` class to return the type `GemmWarpPolicy` instead of a string, enhancing type safety and clarity in the codebase. Removed an unnecessary blank line for improved readability.

* fix

* [CI]: Bump actions/upload-artifact from 5 to 6 (#1431)

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5 to 6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [CI]: Bump actions/download-artifact from 6 to 7 (#1432)

Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [Bugfix] Convey  `compile_flags` to ffi compilation path with pass_configs (#1434)

* [Enhancement] Add device compile flags support in pass configuration

* Introduced `kDeviceCompileFlags` option in the pass configuration to allow additional device compiler flags for CUDA compilation.
* Updated the `tilelang_callback_cuda_compile` function to merge extra flags from the pass configuration, enhancing flexibility in compiler options.
* Modified the `JITKernel` class to handle device compile flags appropriately, ensuring they are included during compilation.
* Documented the new pass configuration key for clarity on usage and expected input formats.

* lint fix

* [Refactor] Simplify compile_flags handling in JIT functions

* Removed redundant string check for compile_flags in the compile, jit, and lazy_jit functions, ensuring compile_flags is consistently treated as a list.
* Updated the JITKernel class to handle compile_flags as a list when a string is provided, enhancing code clarity and maintainability.

* lint fix

* fix

* [Enhancement] Improve buffer usage tracking in MakePackedAPI (#1435)

* Added detailed logging for data and shape variable parameters during buffer usage detection in the MakePackedAPI function.
* Refactored the UsedBufferDetector to differentiate between used parameters by data and shape variables, enhancing clarity in buffer management.
* Updated logic to ensure minimal carrier buffers are selected for shape symbols, improving the efficiency of parameter handling.

* [Enhancement] Improve InjectAssumes logic and make assumes work after SplitHostDevice (#1405)

* [Refactor] Refactor InjectAssumes logic and make assumes work after SplitHostDevice

* address comments

* fix

* fix submodule

* fix

* fix 3rdparty

* [Enhancement] Include PrimFunc name in memory cache logs for better debugging (#1437)

* Added the `get_prim_func_name` utility to extract human-readable function names from TVM PrimFuncs.
* Updated memory cache logging in `AutoTuner` and `KernelCache` classes to include the kernel name, improving clarity during cache hits.
* Enhanced debug logging to provide more informative messages when checking disk cache for kernels.

* [CI] Update lint dependencies and fix lint on trunk (#1433)

* [CI] Update pre-commit hooks

* [Lint] Pass correct `exclude-header-filter` to `clang-tidy`

* [Lint] Download latest `run-clang-tidy` script

* [CI] Show compile commands

* [CI] Add output grouping to GHA

* [Lint] Re-order pre-commit hooks

* [Enhancement] Refactor vectorization checks in loop_vectorize (#1440)

* Introduced a new function, IsExprInvariantInVectorBoundary, to encapsulate the logic for checking if an expression is invariant within vector boundaries, improving code clarity and reusability.
* Updated the existing vectorization logic to utilize this new function, streamlining the process of determining vectorization feasibility based on boundary conditions.
* Enhanced comments for better understanding of the vectorization criteria and mathematical rationale behind the checks.

* Enhance vectorized conversion support (#1438)

* [Feature] Support region as input of T.cumsum (#1426)

* [Feature] Support region as input of T.cumsum

- Extend T.cumsum to accept BufferRegion and BufferLoad inputs in addition to Buffer
- This enables operations on buffer slices/regions like:
  T.cumsum(InputG_fragment[i * chunk_size:(i + 1) * chunk_size], dim=0)
- Update cumsum_fragment to handle region inputs properly
- Add comprehensive tests for 1D and 2D region inputs including normal and reverse modes

Fixes #879

* Fix formatting and add docstring for cumsum_fragment

- Add comprehensive docstring for cumsum_fragment function
- Format code according to ruff style guidelines

* Fix CodeRabbit review issues

- Fix negative dimension bounds check (dim < -len(shape) instead of dim <= -len(shape))
- Add src/dst shape compatibility validation for out-of-place cumsum
- Update copy() type annotation to accept BufferRegion as dst parameter
- Fix test in-place mutation issues by using out-of-place cumsum operations
- Add non-divisible size test cases for tail region coverage

* Fix out-of-bounds access in region tests

- Add bounds clamping using T.min() for chunk_end calculations
- Prevents accessing beyond tensor bounds for non-divisible sizes
- Matches reference implementation behavior
- Fixes both 1D and 2D region test cases

* Fix region test: use simple slice expressions instead of T.min()

- Remove T.min() which cannot be used directly in slice indices
- Use chunk_start + chunk_size form instead
- Rely on system's automatic bounds checking for non-divisible sizes
- Update comments to reflect this approach

* Fix cumsum region: use region extents in lowering and update tests for shared memory

* Simplify fragment scope check using is_fragment()

---------

Co-authored-by: LeiWang1999 <leiwang1999@outlook.com>

* [Fix] Fix analyzer bind conflicting (#1446)

* [Refactor] Reduce direct dependency on PyTorch due to its limited type support (#1444)

* [Enhancement] Update KernelParam to use tvm.DataType directly and add torch_dtype conversion method

- Changed dtype in KernelParam from torch.dtype to tvm.DataType to support a wider range of data types and prevent information loss during conversions.
- Added a new method, torch_dtype, to convert tvm.DataType back to torch.dtype for tensor creation.
- Updated various adapters to utilize the new torch_dtype method for parameter type conversion during initialization.

* [Enhancement] Refactor CUDA type handling and add support for FP4 and FP8 types

- Renamed functions for clarity: GetFP8Type, GetFP6Type, and GetFP4Type are now GetTileLangFP8Type, GetTileLangFP6Type, and GetTileLangFP4Type respectively.
- Enhanced FP4 type handling to support additional lane sizes (2, 4, 8, 16, 32, 64).
- Updated CUDA code generation to include new FP8 and FP4 types, ensuring proper type handling in PrintType and related functions.
- Introduced new structures for FP8 types in cuda_fp8.h to facilitate better memory management and type packing.
- Added methods in KernelParam and tensor utilities to recognize and handle float4 types, improving compatibility with PyTorch.
- Enhanced logging for debugging purposes in various CUDA functions to track type handling and memory operations more effectively.

* lint fix

* Remove unnecessary logging statements from CUDA code generation and delete obsolete matrix multiplication test file.

* [Enhancement] Add support for FP4 and FP8 types in CUDA code generation

- Enhanced PrintVecElemLoad and PrintVecElemStore functions to handle new FP4 types.
- Updated arg_binder to allow float4 to match int8 at runtime, improving compatibility with PyTorch.
- Modified loop_vectorize to account for buffer dtype lanes in vectorization calculations.
- Refactored tensor type mapping to support new float4 and float8 types, ensuring correct type handling in tensor operations.
- Added tests for FP4 and FP8 copy operations to validate functionality and integration with existing workflows.

---------

Co-authored-by: Zhiwen Mo <zm125@ic.ac.uk>

* [Refactor] Use `pytest.mark.parameterize` to speedup parallel testing (#1447)

* Refactor GEMM tests to use parameterized pytest fixtures

- Converted multiple test cases for GEMM operations in `test_tilelang_tilelibrary_gemm_sp.py` to use `pytest.mark.parametrize` for better maintainability and readability.
- Similar refactoring applied to `test_tilelang_tilelibrary_gemm_sp_v2.py`, consolidating test cases for `run_gemm_ss`, `run_gemm_rs`, `run_gemm_sr`, and `run_gemm_rr` into parameterized tests.
- This change reduces code duplication and enhances the clarity of test configurations.

* Update testing/python/amd/test_tilelang_gemm_mfma_preshuffle.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* [Docs] Improve installation instructions for developers (#1450)

* [Feat] Integrate Z3 in TVM Arith Analyzer (#1367)

* [Bugfix] Improve autotune from elementwise_add function in examples (#1445)

* Remove JIT decorator from elementwise_add function in examples

* fix kernel compilation without autotune

* Refactor main function to accept parameters and update tests for autotune option

* Refactor autotune test function for morden style

* [Language] Introduce `T.annotate_restrict_buffers` (#1428)

* [Enhancement] Introduce non-restrict parameter support in code generation

- Added a new PrimFunc-level attribute `tl.non_restrict_params` to specify handle Vars that should not be marked with the restrict qualifier during code generation.
- Updated `CodeGenTileLangCPP`, `CodeGenTileLangCUDA`, and `CodeGenTileLangHIP` to handle non-restrict parameters, ensuring proper treatment of overlapping buffer aliases.
- Implemented a new annotation function `annotate_restrict_buffers` to facilitate the marking of buffer parameters as non-restrict.
- Enhanced the `SplitHostDevice` transformation to propagate non-restrict parameters from host to device functions.
- Added a new transform function `HoistNonRestrictParams` to manage non-restrict parameters effectively.

* [Enhancement] Improve HoistNonRestrictParams transformation

- Updated the HoistNonRestrictParams function to recursively collect all `tl.non_restrict_params` annotations from nested blocks, enhancing flexibility in annotation placement.
- Introduced a new NonRestrictCollector class to manage the collection and deduplication of non-restrict parameters.
- Modified the SplitHostDevice transformation to remove the non-restrict attribute from the host-side PrimFunc after propagation to device kernels.
- Adjusted the LowerAndLegalize function to directly apply the HoistNonRestrictParams transformation without exception handling, streamlining the process.

* [Refactor] Simplify non-restrict parameter handling in code generation

- Removed unnecessary normalization logic and associated data structures from `CodeGenTileLangCPP`, `CodeGenTileLangCUDA`, and `CodeGenTileLangHIP`.
- Streamlined the handling of non-restrict parameters by directly inserting them into the `non_restrict` set, improving code clarity and maintainability.
- Updated conditional checks to eliminate redundant checks against normalized names, enhancing performance and readability.

* [Dependency] Update TVM subproject to latest commit 68aa8461

- Updated the TVM subproject to the latest commit, ensuring compatibility with recent changes and improvements.
- Refactored non-restrict parameter handling in `CodeGenTileLangCPP`, `CodeGenTileLangCUDA`, and `CodeGenTileLangHIP` to enhance code clarity and maintainability.
- Adjusted the `SplitHostDevice` transformation to streamline the propagation of non-restrict parameters.

* fix

* [Analyzer] Require loop extent > 0 when entering loop (#1451)

* Updat ROCm CI to Nightly-ROCm-7.1 (#1449)

* [Enhancement] Update examples and tests for improved type handling functionality (#1448)

* [Enhancement] Update examples and tests for improved type handling and functionality

- Enhanced various example scripts to support new data types and improve compatibility with PyTorch.
- Updated tests across multiple modules to ensure correct functionality with the latest changes in type handling.
- Refactored code in examples to streamline operations and improve clarity, particularly in tensor operations and memory management.
- Added comprehensive tests for new features and fixed existing issues related to type conversions and buffer handling.

* [Refactor] Update accumulation data type to float32 across examples

- Changed accumulation data type from "float" to T.float32 in multiple example scripts to ensure consistency and improve numerical stability.
- This update affects various modules including flash attention, GEMM analysis, convolution, and deepseek MLA examples, enhancing type handling across the board.

* [Refactor] Standardize data type usage across benchmark scripts

- Updated data type definitions in benchmark scripts to use T.float16 and T.float32 consistently, enhancing clarity and type handling.
- Adjusted dtype assignments in matmul functions and configuration setups to align with the new standard.
- Improved overall code consistency and maintainability by ensuring uniform data type usage across various modules.

* [Refactor] Standardize data type usage in templates and scripts

- Updated data type definitions in various templates and scripts to use string representations (e.g., "float16", "int32") instead of T.float16 and T.int32 for improved consistency and clarity.
- Enhanced overall code maintainability by ensuring uniform data type usage across multiple modules, including convolution, elementwise operations, and matrix multiplication templates.
- This change aims to streamline type handling and improve compatibility with existing workflows.

* [Refactor] Standardize data type usage in examples and benchmarks

- Updated data type definitions in various example and benchmark scripts to use T.float16 and T.int32 consistently, enhancing clarity and maintainability.
- Adjusted dtype assignments in kernel functions and configuration setups to align with the new standard.
- Improved overall code consistency by ensuring uniform data type usage across multiple modules, including attention mechanisms, matrix multiplication, and GEMM examples.

* [Refactor] Import dtypes from language.v2 module

- Added import statement for dtypes from the language.v2 module to enhance type handling and maintain consistency across the codebase.
- This change aims to streamline data type management and improve overall code clarity.

* fix

* [Refactor] Standardize data type usage across scripts

- Updated data type definitions in various scripts to use string representations (e.g., "float16", "int8") instead of T.float16 and T.int8 for improved consistency and clarity.
- Adjusted dtype assignments in functions and configuration setups to align with the new standard, enhancing overall code maintainability.
- This change affects multiple modules, including benchmark and attention mechanisms, ensuring uniform data type usage throughout the codebase.

* [Refactor] Update data type handling for consistency and clarity

- Changed string representations of data types in the Hint class to use T.float32 and T.int32 for improved consistency.
- Added new data types "int4" and "int16" to the dtypes module, enhancing type support across the codebase.
- Updated function signatures and assertions in the lop3 and mxfp modules to utilize the new data types, ensuring uniformity in type handling.
- This refactor aims to streamline data type management and improve overall code clarity and maintainability.

* [Enhancement] Improve data type handling and error messaging

- Introduced a mapping for canonical data types to their display strings, enhancing clarity in type representation.
- Updated the dtype creation logic to utilize the new mapping, ensuring more intuitive handling of string inputs.
- Refined error messages in the lop3 module to provide clearer feedback on invalid source formats, improving debugging and user experience.

* [Fix] Correct boolean flag in GEMM SP test case

- Updated the boolean flag in the test_gemm_sp_sm90 function to ensure proper functionality in the test case.
- This change enhances the accuracy of the test and aligns it with expected behavior for the GEMM SP implementation.

* [Refactor] Standardize data type usage across scripts

- Updated data type definitions in various scripts to use T.float16 and T.bfloat16 consistently, enhancing clarity and maintainability.
- Adjusted dtype assignments in function signatures and argument parsing to align with the new standard, ensuring uniform data type usage throughout the codebase.
- This change affects multiple modules, including benchmarks and examples, improving overall code consistency and readability.

* [Refactor] Standardize data type usage in various modules

- Updated data type assignments in multiple scripts to utilize T.float32, T.int8, and T.int32 consistently, enhancing clarity and maintainability.
- Adjusted function signatures and parameter types across benchmarks, examples, and tests to align with the new standard, ensuring uniform data type usage throughout the codebase.
- This change improves overall code consistency and readability, impacting modules related to matrix multiplication, GEMM, and tensor operations.

* [Refactor] Update argument parsing for data types in benchmarks

- Changed argument parsing for data types in benchmark_matmul_intrinsic.py and benchmark_matmul_sp.py to use string representations ("float16", "int8", "float") instead of T.float16 and T.float.
- This update enhances consistency in data type handling across benchmark scripts, improving clarity and maintainability.

* [Refactor] Update data type handling in benchmark and example scripts

- Changed data type arguments in benchmark and example scripts to use string representations ("float16") instead of T.float16 for improved consistency.
- Updated function signatures and argument parsing to align with the new standard, enhancing clarity and maintainability across the codebase.
- This change affects multiple modules related to attention mechanisms and tensor operations, ensuring uniform data type usage throughout the examples.

* [Refactor] Fix data type conversion in multiple scripts

- Corrected the usage of the data type conversion method from dtype..as_torch() to dtype.as_torch() across various benchmark and example scripts.
- This change enhances consistency in data type handling and improves code readability, impacting modules related to attention mechanisms and tensor operations.

* [Refactor] Update float8 data type usage across multiple scripts

- Changed instances of T.float8_e4m3 to T.float8_e4m3fn in various benchmark, example, and test scripts to ensure consistency in data type handling.
- This update enhances clarity and maintainability across the codebase, particularly in modules related to matrix multiplication and tensor operations.

* [Refactor] Enhance float8 data type handling in CUDA code generation

- Updated the handling of float8 data types in the CUDA code generation to include additional float8 variants, improving type conversion logic.
- Adjusted conditions to ensure proper type checks for float8 conversions, enhancing clarity and maintainability in the codebase.
- Modified layout inference to streamline float8 type checks, ensuring consistency across the implementation.
- This change impacts modules related to matrix operations and CUDA code generation, improving overall type handling and conversion accuracy.

* [Refactor] Streamline float8 data type handling in CUDA and related modules

- Enhanced float8 data type handling in CUDA code generation by refining type conversion logic and ensuring consistent type checks.
- Updated layout inference for float8 types to improve clarity and maintainability across the implementation.
- This change impacts modules related to matrix operations and CUDA code generation, improving overall type handling and conversion accuracy.

* [Refactor] Remove unnecessary cache disabling in float8 example script

- Eliminated the call to tilelang.disable_cache() in example_group_per_split_token_cast_to_fp8.py to streamline the code.
- This change enhances clarity and maintainability of the example script without affecting its functionality.

* [Refactor] Update data type usage in debug print tests

- Changed the argument for dtype in the test_debug_print_buffer function from a string representation to the corresponding T.bool type.
- This update…
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.

2 participants