tilelang.jit.adapter.ctypes.adapter¶

The profiler and convert to torch utils

Classes¶

CtypesKernelAdapter

Adapter class that converts TVM/TIR functions to callable CUDA kernels using ctypes.

Module Contents¶

class tilelang.jit.adapter.ctypes.adapter.CtypesKernelAdapter(params, result_idx, target, func_or_mod, host_mod=None, device_mod=None, kernel_global_source=None, verbose=False, pass_configs=None, compile_flags=None)¶

Bases: tilelang.jit.adapter.base.BaseKernelAdapter

Adapter class that converts TVM/TIR functions to callable CUDA kernels using ctypes.

This adapter handles: 1. Converting TIR functions to compiled CUDA libraries 2. Managing dynamic shapes in tensor operations 3. Wrapping C++ kernels for Python/PyTorch usage

Parameters:
  • params (list[tvm.relax.TensorType])

  • result_idx (list[int])

  • target (str)

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

  • host_mod (tilelang.tvm.IRModule | None)

  • device_mod (tilelang.tvm.IRModule | None)

  • kernel_global_source (str | None)

  • verbose (bool)

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

  • compile_flags (list[str] | None)

target = 'cuda'¶
ir_module: tilelang.tvm.IRModule | None = None¶
kernel_global_source: str | None = None¶
lib: ctypes.CDLL | None = None¶
wrapped_source: str | None = None¶
dynamic_symbolic_map: dict[tvm.tir.Var, tuple[int, int]] | None = None¶
pass_configs: dict[str, Any] | None = None¶
param_dtypes: list[torch.dtype] | None = None¶
param_shapes: list[list] | None = None¶
params¶
result_idx¶
verbose = False¶
wrapper¶
lib_generator¶
classmethod from_database(params, result_idx, target, func_or_mod, kernel_global_source, kernel_lib_path, verbose=False, pass_configs=None, compile_flags=None)¶
Parameters:
  • params (list[tvm.relax.TensorType])

  • result_idx (list[int])

  • target (str)

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

  • kernel_global_source (str)

  • kernel_lib_path (str)

  • verbose (bool)

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

  • compile_flags (list[str] | None)

property prim_func: tvm.tir.PrimFunc¶

Returns the primary TIR function from the IR module.

Return type:

tvm.tir.PrimFunc

property srcpath¶

Returns the source path of the compiled library.

property libpath¶

Returns the path to the compiled library.

property lib_code¶

Returns the code of the compiled library.

property is_dynamic¶

Indicates whether the kernel handles dynamic shapes.

get_kernel_source(kernel_only=False)¶

Returns the source code of the compiled kernel.

Parameters:

kernel_only (bool)