[Backend] Add unified backend resolution policy (#2318)

* Refactor backend module registration

* Define backends with explicit specs

* Require explicit backend for codegen

* Rename backend spec to backend module

* Keep host codegen on selected backend

* Introduce backend context for compilation

* Remove legacy backend compatibility APIs

* Restore backend API docstrings
This commit is contained in:
Chaofan Lin
2026-08-06 02:41:57 +08:00
committed by GitHub
parent 752043ec1a
commit fef9f76092
51 changed files with 1142 additions and 1001 deletions
@@ -7,6 +7,7 @@ import cloudpickle
import pytest
import tilelang.cache.kernel_cache as kernel_cache_mod
from tilelang.backend import create_backend_context
from tilelang.cache.kernel_cache import KernelCache
from tilelang.env import env
from tilelang.jit.adapter.base import CachedTextSource
@@ -87,12 +88,11 @@ def test_kernel_cache_disk_hit_defers_source_loading(cache_dirs, monkeypatch):
monkeypatch.setattr(cache, "_load_kernel_source", fail_source_load)
monkeypatch.setattr(kernel_cache_mod.JITKernel, "from_database", classmethod(fake_from_database))
backend_context = create_backend_context("cuda", execution_backend="tvm_ffi")
loaded = cache._load_kernel_from_disk(
key,
target="cuda",
target_host=None,
backend_context=backend_context,
out_idx=[0],
execution_backend="tvm_ffi",
pass_configs=None,
compile_flags=None,
func=None,
@@ -103,6 +103,7 @@ def test_kernel_cache_disk_hit_defers_source_loading(cache_dirs, monkeypatch):
assert captured["device_kernel_source"] == CachedTextSource(path=str(cache_path / cache.device_kernel_path))
assert captured["kernel_lib_path"] == str(cache_path / cache.kernel_lib_path)
assert captured["params"] == ["param"]
assert captured["backend_context"] is backend_context
def test_kernel_cache_disk_hit_perf_skips_large_source_file_reads(cache_dirs, monkeypatch):
@@ -144,10 +145,8 @@ def test_kernel_cache_disk_hit_perf_skips_large_source_file_reads(cache_dirs, mo
loaded = cache._load_kernel_from_disk(
key,
target="cuda",
target_host=None,
backend_context=create_backend_context("cuda", execution_backend="tvm_ffi"),
out_idx=[0],
execution_backend="tvm_ffi",
pass_configs=None,
compile_flags=None,
func=None,
@@ -214,10 +213,8 @@ def test_kernel_cache_disk_hit_rejects_entries_missing_sources(cache_dirs, monke
loaded = cache._load_kernel_from_disk(
key,
target="cuda",
target_host=None,
backend_context=create_backend_context("cuda", execution_backend="tvm_ffi"),
out_idx=[0],
execution_backend="tvm_ffi",
pass_configs=None,
compile_flags=None,
func=None,