Python Compatibility¶
TileLang is a Python-embedded DSL, but not all Python syntax is supported inside
TileLang DSL. This guide clarifies what works, what doesn’t, and how
to translate common Python patterns into TileLang equivalents. Specially, we focus on
the kernel part (scripts inside with T.Kernel) semantics. For host-side semantics when
using eager-style JIT, please stay tuned for our upcoming documentation.
The following codes use the conventional aliases:
import tilelang
import tilelang.language as T
from tilelang import jit
Control Flow & Loops¶
Python Feature |
Supported |
Notes / Alternative |
|---|---|---|
|
✅ |
Maps to |
|
✅ |
Maps to |
|
❌ |
Use index-based loop |
|
✅ |
|
|
✅ |
|
|
✅ |
Ternary expression |
|
✅ |
|
|
❌ |
Data Access¶
Python Feature |
Supported |
Notes / Alternative |
|---|---|---|
|
✅ |
Multi-dim indexing supported: |
|
✅ |
Creates |
|
✅ |
Assignment & Arithmetic Operations¶
Python Feature |
Supported |
Notes / Alternative |
|---|---|---|
|
✅ |
|
|
✅ |
Maps to device-side arithmetic operations |
|
✅ |
Augmented assignment |
|
❌ |
Use separate assignments |
Functions & Classes¶
As a kernel script language, TileLang doesn’t support functions or classes. You can use @T.macro to define reusable code blocks, which will be inlined at compile time like __device__ function.
Statements & Built-in Functions¶
Python Feature |
Supported |
Notes / Alternative |
|---|---|---|
|
⚠️ |
Only |
|
⚠️ |
Use |
|
⚠️ |
Use |
|
❌ |
Use |
|
❌ |