tilus.Class

Contents

tilus.Class

class tilus.Class[source]

A helper class for organizing kernel logic into reusable components.

tilus.Class works like tilus.Script but for helper objects that are not kernels themselves. It can allocate mbarriers, shared tensors, tensor memory, and use all tilus instructions.

Subclass tilus.Class and define an __init__ method to create reusable abstractions. The __init__ is transpiled alongside the kernel that uses it.

Example:

class Pipeline(tilus.Class):
    def __init__(self, num_stages: int):
        self.barriers = self.mbarrier.alloc(counts=[1] * num_stages)
        self.stage: int32 = 0

    def advance(self):
        self.stage = (self.stage + 1) % self.num_stages

Use it inside a tilus.Script:

class MyKernel(tilus.Script):
    def __call__(self, ...):
        pipe = Pipeline(num_stages=4)
        pipe.advance()