Files
2026-10-20 12:09:42 +08:00

33 lines
1.2 KiB
Python

"""Kernel dispatcher: interface modules do
``from deepinfer.model_executor.layers.tilelang_ops import ops`` and call
``ops.xxx_tl``; backend selection happens only in this file.
Re-exports all ``xxx_tl`` factories of the selected backend.
"""
import importlib
import pkgutil
from types import ModuleType
from typing import Any
from deepinfer import PLATFORM
_pkg = importlib.import_module(f"{__package__}.{PLATFORM.tilelang_ops_backend}")
for _info in pkgutil.iter_modules(_pkg.__path__):
_mod = importlib.import_module(f"{_pkg.__name__}.{_info.name}")
for _name, _obj in vars(_mod).items():
if _name.startswith("_") or isinstance(_obj, ModuleType) or not _name.endswith("_tl"):
continue
assert globals().get(_name, _obj) is _obj, f"backend symbol collision: {_name}"
globals()[_name] = _obj
class KernelUnavailableError(AttributeError):
"""Selected backend lacks this kernel factory; conftest.py turns it into
a test skip on non-cuda backends. Subclasses AttributeError to keep the
module ``__getattr__`` / ``hasattr`` protocol intact."""
def __getattr__(name: str) -> Any: # for static analyzers
raise KernelUnavailableError(f"tilelang_ops backend {PLATFORM.tilelang_ops_backend!r} has no kernel {name!r}")