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 (Union[tvm.tir.PrimFunc, tilelang.tvm.IRModule])

  • host_mod (Optional[tilelang.tvm.IRModule])

  • device_mod (Optional[tilelang.tvm.IRModule])

  • kernel_global_source (Optional[str])

  • verbose (bool)

  • pass_configs (Optional[Dict[str, Any]])

  • compile_flags (Optional[List[str]])

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 (Union[tvm.tir.PrimFunc, tilelang.tvm.IRModule])

  • kernel_global_source (str)

  • kernel_lib_path (str)

  • verbose (bool)

  • pass_configs (Optional[Dict[str, Any]])

  • compile_flags (Optional[List[str]])

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)