Skip to content

Commit e5b7a0d

Browse files
committed
fix tests
1 parent 6746526 commit e5b7a0d

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

examples/eval.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def run_single_test(pool: multiprocessing.Pool, test: TestCase):
211211
"""
212212
world_size = test.args.get("world_size", None)
213213
if world_size is None:
214-
return pool.apply(_run_single_test, (test, 0, 0))
214+
return pool.apply(_run_single_test, (test,))
215215
else:
216216
return run_multi_gpu_test(pool, test, world_size)
217217

@@ -255,7 +255,7 @@ def _run_single_benchmark(test: TestCase, recheck: bool, max_repeats: int, max_t
255255
durations = []
256256
# generate input data once
257257
data = generate_input(**test.args)
258-
check_copy = _clone_data(data)
258+
check_copy = _clone_data(data, 0)
259259
# first, one obligatory correctness check
260260
output = custom_kernel(data)
261261
good, message = wrap_check_implementation(check_copy, output)
@@ -275,7 +275,7 @@ def _run_single_benchmark(test: TestCase, recheck: bool, max_repeats: int, max_t
275275
test.args["seed"] += 13
276276

277277
data = generate_input(**test.args)
278-
check_copy = _clone_data(data)
278+
check_copy = _clone_data(data, 0)
279279
torch.cuda.synchronize()
280280
start_event = torch.cuda.Event(enable_timing=True)
281281
end_event = torch.cuda.Event(enable_timing=True)
@@ -509,7 +509,7 @@ def run_single_profile(test: TestCase) -> str:
509509
torch.cuda.synchronize()
510510

511511
with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA]) as prof:
512-
submission_output = custom_kernel(_clone_data(data))
512+
submission_output = custom_kernel(_clone_data(data, 0))
513513
torch.cuda.synchronize()
514514
return prof.key_averages().table(sort_by="self_cuda_time_total", row_limit=20)
515515

tests/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,32 @@ def bot(docker_compose, database):
106106
CUDA: "template.cu"
107107
"""
108108

109+
MULTi_GPU_TASK_YAML = """
110+
lang: py
111+
description: "Test task description"
112+
ranking_by: geom
113+
multi_gpu: true
114+
test_timeout: 120
115+
files:
116+
- name: "kernel.py"
117+
source: "kernel.py"
118+
- name: "submission.py"
119+
source: "@SUBMISSION@"
120+
config:
121+
main: "kernel.py"
122+
tests:
123+
- input_size: 1000
124+
world_size: 4
125+
dtype: "float32"
126+
benchmarks:
127+
- input_size: 10000
128+
world_size: 4
129+
dtype: "float32"
130+
templates:
131+
Python: "template.py"
132+
CUDA: "template.cu"
133+
"""
134+
109135

110136
@pytest.fixture
111137
def task_directory(tmp_path):
@@ -117,6 +143,7 @@ def task_directory(tmp_path):
117143

118144
# Create task.yml
119145
Path.write_text(tmp_path / "task.yml", TASK_YAML)
146+
Path.write_text(tmp_path / "multi-task.yml", MULTi_GPU_TASK_YAML)
120147
return tmp_path
121148

122149

tests/test_task.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
build_task_config,
1515
make_task_definition,
1616
)
17+
from libkernelbot.utils import KernelBotError
1718

1819

1920
@pytest.fixture()
@@ -148,6 +149,7 @@ def test_build_task_config_python(leaderboard_task):
148149
{"input_size": 5000, "dtype": "float16"},
149150
],
150151
"mode": mode.value,
152+
"multi_gpu": False,
151153
"test_timeout": 120,
152154
"benchmark_timeout": 180,
153155
"ranked_timeout": 180,
@@ -201,6 +203,7 @@ def test_build_task_config_cuda():
201203
{"input_size": 5000, "dtype": "float16"},
202204
],
203205
"mode": mode.value,
206+
"multi_gpu": False,
204207
"test_timeout": 120,
205208
"benchmark_timeout": 180,
206209
"ranked_timeout": 180,
@@ -234,3 +237,16 @@ def test_make_task_definition(task_directory):
234237
assert task.benchmarks == [{"input_size": 10000, "dtype": "float32"}]
235238
assert isinstance(task.config, PythonTaskData)
236239
assert task.config.main == "kernel.py"
240+
241+
242+
def test_multi_gpu_task(task_directory):
243+
"""Test make_task_definition with a multi-GPU task"""
244+
orig = (task_directory / "task.yml").read_text()
245+
(task_directory / "task.yml").write_text(orig + "\nmulti_gpu: true")
246+
247+
# no world size specified => Error
248+
with pytest.raises(KernelBotError, match="does not specify world_size"):
249+
make_task_definition(task_directory / "task.yml")
250+
251+
result = make_task_definition(task_directory / "multi-task.yml")
252+
assert result.task.multi_gpu is True

0 commit comments

Comments
 (0)