Skip to content

Commit 7c15075

Browse files
committed
clear L2 cache
1 parent cf7371e commit 7c15075

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

problems/bioml/trimul/eval.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import torch.cuda
1313

14-
from utils import set_seed
14+
from utils import set_seed, clear_l2_cache
1515
try:
1616
from task import TestSpec
1717
except ImportError:
@@ -232,6 +232,7 @@ def _run_single_benchmark(test: TestCase, recheck: bool, max_repeats: int, max_t
232232
start_event = torch.cuda.Event(enable_timing=True)
233233
end_event = torch.cuda.Event(enable_timing=True)
234234
start_event.record()
235+
clear_l2_cache()
235236
output = custom_kernel(data)
236237
end_event.record()
237238
torch.cuda.synchronize()

problems/bioml/trimul/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Tuple
33

44
import numpy as np
5+
import cupy as cp
56
import torch
67

78

@@ -156,4 +157,13 @@ def __enter__(self):
156157

157158
def __exit__(self, exc_type, exc_value, traceback):
158159
torch.backends.cudnn.allow_tf32 = self.allow_tf32
159-
torch.backends.cudnn.deterministic = self.deterministic
160+
torch.backends.cudnn.deterministic = self.deterministic
161+
162+
163+
def clear_l2_cache():
164+
cp.cuda.runtime.cudaDeviceSetLimit(cp.cuda.runtime.cudaLimitPersistingL2CacheSize, 0)
165+
# create a large dummy tensor
166+
dummy = torch.empty((32, 1024, 1024), dtype=torch.int64, device="cuda")
167+
# write stuff to
168+
dummy.fill_(42)
169+
del dummy

0 commit comments

Comments
 (0)