To profile a kernel, wrap the compilation process in an iket.session(...). This ensures the session is active when tilelang.compile(...) generates CUDA source. You can use iket.range as a context manager and iket.mark for instant events within your T.prim_func.
import tilelang
import tilelang.language as T
from tilelang.tools.cuda import iket
def instrumented_add(n: int, threads: int = 128):
@T.prim_func
def main(
A: T.Tensor((n,), T.float32),
B: T.Tensor((n,), T.float32),
C: T.Tensor((n,), T.float32),
):
with T.Kernel(T.ceildiv(n, threads), threads=threads) as bx:
with iket.range("block_total"):
for tx in T.Parallel(threads):
i = bx * threads + tx
if i < n:
iket.mark("before_store")
C[i] = A[i] + B[i]
iket.mark("after_store")
return main
with iket.session(output_dir="/tmp/tilelang_iket"):
program = instrumented_add(1024)
kernel = tilelang.compile(
program,
out_idx=-1,
target="cuda",
execution_backend="cython",
)