Skip to content

Commit 91692c3

Browse files
authored
Revert cleaning cache changes on Windows (#3217)
With unloaded DLL libraries, these changes are no longer necessary. However, two tests that hold a reference to the compiled kernel need to be adjusted - manually clear the cache (inside `JITFunction` object). CI: * https://github.com/intel/intel-xpu-backend-for-triton/actions/runs/12951798922 (passed) * https://github.com/intel/intel-xpu-backend-for-triton/actions/runs/12955820922 (check status) Blocked on #3251 Extra refs: * python/cpython#87319 --------- Signed-off-by: Anatoly Myachev <[email protected]>
1 parent 4042f87 commit 91692c3

File tree

7 files changed

+27
-42
lines changed

7 files changed

+27
-42
lines changed

python/test/regression/conftest.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ def device(request):
1414

1515
@pytest.fixture
1616
def fresh_triton_cache():
17-
try:
18-
with tempfile.TemporaryDirectory() as tmpdir:
19-
try:
20-
os.environ["TRITON_CACHE_DIR"] = tmpdir
21-
yield tmpdir
22-
finally:
23-
os.environ.pop("TRITON_CACHE_DIR", None)
24-
except OSError:
25-
# Ignore errors, such as PermissionError, on Windows
26-
pass
17+
with tempfile.TemporaryDirectory() as tmpdir:
18+
try:
19+
os.environ["TRITON_CACHE_DIR"] = tmpdir
20+
yield tmpdir
21+
finally:
22+
os.environ.pop("TRITON_CACHE_DIR", None)

python/test/unit/conftest.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@ def device(request):
1717

1818
@pytest.fixture
1919
def fresh_triton_cache():
20-
try:
21-
with tempfile.TemporaryDirectory() as tmpdir:
22-
try:
23-
os.environ["TRITON_CACHE_DIR"] = tmpdir
24-
yield tmpdir
25-
finally:
26-
os.environ.pop("TRITON_CACHE_DIR", None)
27-
except OSError:
28-
# Ignore errors, such as PermissionError, on Windows
29-
pass
20+
with tempfile.TemporaryDirectory() as tmpdir:
21+
try:
22+
os.environ["TRITON_CACHE_DIR"] = tmpdir
23+
yield tmpdir
24+
finally:
25+
os.environ.pop("TRITON_CACHE_DIR", None)
3026

3127

3228
def pytest_configure(config):

python/test/unit/runtime/test_cache.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ def inc_counter(*args, **kwargs):
164164
for i in range(10):
165165
kernel[(1, )](x, 1, BLOCK=1024)
166166
assert counter == 1
167+
device = getattr(torch, device).current_device()
168+
kernel.device_caches[device][0].clear()
167169

168170

169171
@pytest.mark.parametrize('mode', ['enable', 'disable', 'disable_on_alignment'])
@@ -181,6 +183,10 @@ def inc_counter(*args, **kwargs):
181183
for i in [1, 2, 4, 8, 16, 32]:
182184
function[(1, )](x, i, BLOCK=512)
183185
assert counter == target
186+
device = getattr(torch, device).current_device()
187+
kernel.device_caches[device][0].clear()
188+
kernel_nospec.device_caches[device][0].clear()
189+
kernel_nospec_on_alignment.device_caches[device][0].clear()
184190

185191

186192
def test_annotation(device):
@@ -489,7 +495,7 @@ def cache_hook(*args, **kwargs):
489495
assert specialization_data is not None
490496

491497
# clear the cache
492-
shutil.rmtree(fresh_triton_cache, ignore_errors=True)
498+
shutil.rmtree(fresh_triton_cache)
493499
kernel_add.device_caches[device][0].clear()
494500

495501
# preload the kernel

python/test/unit/runtime/test_subproc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_compile_in_forked_subproc_with_forced_gc(fresh_triton_cache) -> None:
8787
compile_empty_kernel_with_gc()
8888

8989
# stage 2.p
90-
shutil.rmtree(fresh_triton_cache, ignore_errors=True)
90+
shutil.rmtree(fresh_triton_cache)
9191
mp_ctx = multiprocessing.get_context(start_method)
9292
proc = mp_ctx.Process(target=compile_empty_kernel_with_gc)
9393

python/triton/runtime/cache.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,7 @@ def put(self, data, filename, binary=True) -> str:
131131
f.write(data)
132132
# Replace is guaranteed to be atomic on POSIX systems if it succeeds
133133
# so filepath cannot see a partial write
134-
try:
135-
os.replace(temp_path, filepath)
136-
except PermissionError:
137-
# Ignore PermissionError on Windows because it happens when another process already
138-
# put a file into the cache and locked it by opening it.
139-
if os.name == "nt":
140-
os.remove(temp_path)
141-
else:
142-
raise
134+
os.replace(temp_path, filepath)
143135
os.removedirs(temp_dir)
144136
return filepath
145137

third_party/intel/backend/driver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ class TritonLauncher:
172172

173173
def __init__(self, cache_path: str):
174174
self.shared_library = ctypes.PyDLL(cache_path)
175-
# breakpoint()
176175
self.shared_library.launch.restype = ctypes.py_object
177176
self.shared_library.launch.argtypes = (ctypes.py_object, )
178177

third_party/intel/python/test/conftest.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ def device(request):
1414

1515
@pytest.fixture
1616
def fresh_triton_cache():
17-
try:
18-
with tempfile.TemporaryDirectory() as tmpdir:
19-
try:
20-
os.environ["TRITON_CACHE_DIR"] = tmpdir
21-
yield tmpdir
22-
finally:
23-
os.environ.pop("TRITON_CACHE_DIR", None)
24-
except OSError:
25-
# Ignore errors, such as PermissionError, on Windows
26-
pass
17+
with tempfile.TemporaryDirectory() as tmpdir:
18+
try:
19+
os.environ["TRITON_CACHE_DIR"] = tmpdir
20+
yield tmpdir
21+
finally:
22+
os.environ.pop("TRITON_CACHE_DIR", None)

0 commit comments

Comments
 (0)