MCPcopy Create free account
hub / github.com/tile-ai/tilelang / clean_cache_env

Function clean_cache_env

testing/python/cache/test_tilelang_kernel_cache.py:100–131  ·  view source on GitHub ↗

Provide isolated cache environment for each test. Creates isolated cache/tmp directories to ensure: - No interference from previous test runs - No interference between parallel tests - Clean slate for testing cache miss/hit behavior - No "Invalid cross-device link" errors (os.re

(tmp_path, request)

Source from the content-addressed store, hash-verified

98
99@pytest.fixture(scope="function")
100def clean_cache_env(tmp_path, request):
101 """Provide isolated cache environment for each test.
102
103 Creates isolated cache/tmp directories to ensure:
104 - No interference from previous test runs
105 - No interference between parallel tests
106 - Clean slate for testing cache miss/hit behavior
107 - No "Invalid cross-device link" errors (os.replace requires same filesystem)
108
109 Technical notes:
110 - TILELANG_TMP_DIR MUST be on same filesystem as TILELANG_CACHE_DIR because
111 cache implementation uses os.replace() for atomic writes
112 - Env restoration is handled by setup_module_env at module scope
113 """
114 # This fixture should ONLY be used with @pytest.mark.parametrize("backend", ...)
115 backend = request.node.callspec.params["backend"] # Will raise KeyError if missing
116 _require_backend_available(backend)
117
118 cache_dir = tmp_path / "tilelang_cache"
119 cache_dir.mkdir()
120
121 tmp_dir = tmp_path / "tilelang_tmp"
122 tmp_dir.mkdir()
123
124 # Patch env variables to point to isolated directories
125 env.TILELANG_CACHE_DIR = str(cache_dir)
126 env.TILELANG_TMP_DIR = str(tmp_dir)
127
128 # Clear memory caches to force disk I/O
129 _dispatch_map[backend]._memory_cache.clear()
130
131 return cache_dir
132
133
134@tilelang.testing.requires_cuda

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…