tilelang.jit.adapter.tvm_ffi¶

Utilities to adapt TVM-FFI kernels to Torch tensors.

TVM-FFI obtains the active work stream through Torch’s DLPack Exchange API. The Ascend adapter installs TileLang’s Torch NPU callback before the first tensor reaches an executable.

Attributes¶

Classes¶

TVMFFIKernelAdapter

Adapter that runs a TVM runtime.Executable with Torch tensors.

Module Contents¶

tilelang.jit.adapter.tvm_ffi.COMPILE_ARGS¶
class tilelang.jit.adapter.tvm_ffi.TVMFFIKernelAdapter(params, result_idx, target, func_or_mod, host_mod=None, device_mod=None, rt_mod=None, host_kernel_source=None, device_kernel_source=None, verbose=False, pass_configs=None, compile_flags=None)¶

Bases: tilelang.jit.adapter.base.BaseKernelAdapter

Adapter that runs a TVM runtime.Executable with Torch tensors.

Notes - Torch tensors use TVM-FFI’s zero-copy DLPack Exchange API conversion. - Ascend execution installs a Cython callback that reads Torch’s current

NPU stream for every invocation.

Parameters:
  • params (list[tilelang.engine.param.KernelParam])

  • result_idx (list[int])

  • target (str | tvm.target.Target)

  • func_or_mod (tvm.tirx.PrimFunc | tilelang.tvm.IRModule)

  • host_mod (tilelang.tvm.IRModule | None)

  • device_mod (tilelang.tvm.IRModule | None)

  • rt_mod (tilelang.tvm.runtime.Module | None)

  • host_kernel_source (str | None)

  • device_kernel_source (str | None)

  • verbose (bool)

  • pass_configs (dict[str, Any] | None)

  • compile_flags (list[str] | None)

target: str | tvm.target.Target = 'cuda'¶
ir_module: tilelang.tvm.IRModule | None = None¶
host_kernel_source: str | None = None¶
device_kernel_source: str | None = None¶
executable: tilelang.tvm.runtime.Executable | tilelang.tvm.runtime.Module | None = None¶
pass_configs: dict[str, Any] | None = None¶
host_mod: tilelang.tvm.IRModule | None = None¶
device_mod: tilelang.tvm.IRModule | None = None¶
rt_mod: tilelang.tvm.runtime.Module | None = None¶
dynamic_symbolic_map: dict[tvm.tirx.Var, tuple[int, int, int, int]] | None = None¶
params¶
result_idx¶
verbose = False¶
compile_flags = None¶
kernel_global_source = None¶
get_exportable_executable()¶

Return the lazy executable, or the runnable module loaded from disk cache.

Return type:

tilelang.tvm.runtime.Executable | tilelang.tvm.runtime.Module

classmethod from_database(params, result_idx, target, func_or_mod, host_kernel_source, device_kernel_source, kernel_lib_path, verbose=False, pass_configs=None, compile_flags=None)¶
Parameters:
get_host_source()¶

Returns the source code of the host module.

Return type:

str | None

get_device_source()¶

Returns the source code of the device module.

Return type:

str | None

get_kernel_source(kernel_only=False)¶

Returns the source code of the compiled kernel.

Parameters:

kernel_only (bool)

property prim_func: tvm.tirx.PrimFunc¶

Returns the primary TIR function from the IR module.

Return type:

tvm.tirx.PrimFunc