Files
tilelang/testing/python/language/test_tilelang_language_chain_equal.py
T
5f202fe5c1 [Language] Initial version of tilelang frontend v2 (#1120)
* tilelang frontend v2

* syntax sugar: defining a local var by annotation

* [Refactor] fix type linting warning like `T.float32`

* Add tl.local_var_init for new tl.float32

* allow passing default argument as function annotation

* allow default arguments as annotation

* fix lint error

* minor fix

* [Refactor] refactor tilelang.jit and tilelang.autotune

* minor fix

* minor fix

* minor fix

* fix metal get function name

* add par_compile impl and tests

* Type consistency on tvm datatype
1. isinstance(tl.float32, tvm.DataType) == True
2. Allow `tl.float32` as function annotations
3. Allow `tl.float32` as argument to be passed to `tl.alloc` or other functions

* fix lint error

* add more warning in frontend

* update tvm version

* Minor fix on tvm_ffi annotations

* add document and examples

* fix lint error

* Simplify index calculations in example_chunk_o_bwd.py

Refactor index calculations for dg_last_fragment assignment.

* minor fix

* lint fix

---------

Co-authored-by: Lei Wang <leiwang1999@outlook.com>
Co-authored-by: Lei Wang <34334180+LeiWang1999@users.noreply.github.com>
2025-11-03 18:15:56 +08:00

47 lines
1.3 KiB
Python

import tilelang
import tilelang.testing
import tilelang.language as T
import torch
@tilelang.jit(
pass_configs={
tilelang.PassConfigKey.TL_DISABLE_TMA_LOWER: True,
tilelang.PassConfigKey.TL_DISABLE_WARP_SPECIALIZED: True,
},)
def chain_equal(N, block_size, dtype="float32"):
@T.prim_func
def main(
A: T.Tensor((N,), dtype),
B: T.Tensor((N,), dtype),
C: T.Tensor((N,), dtype),
):
with T.Kernel(T.ceildiv(N, block_size), threads=block_size) as bx:
for lane in T.Parallel(block_size):
idx = bx * block_size + lane
A[idx] = B[idx] = C[idx] = 1
return main
def run_chain_equal(N=128, block_size=64, dtype="float32"):
kernel = chain_equal(N, block_size, dtype)
A = torch.zeros((N,), dtype=torch.float32, device="cuda")
B = torch.zeros((N,), dtype=torch.float32, device="cuda")
C = torch.zeros((N,), dtype=torch.float32, device="cuda")
kernel(A, B, C)
ref = torch.ones_like(A)
torch.testing.assert_close(A, ref)
torch.testing.assert_close(B, ref)
torch.testing.assert_close(C, ref)
@tilelang.testing.requires_cuda
def test_chain_equal():
run_chain_equal()
if __name__ == "__main__":
tilelang.testing.main()