Skip to content

Commit 3d34c31

Browse files
authored
test: add benchmarks for kernel launch for reproducibility (#528)
This PR establishes a benchmarks directory where pytest-benchmark-based benchmarks can live. This is to serve as a baseline for #510.
1 parent be52e73 commit 3d34c31

File tree

9 files changed

+146
-4
lines changed

9 files changed

+146
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ testing/*.ptx
1919
.pixi/*
2020
!.pixi/config.toml
2121
*.log
22+
.benchmarks

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ cd testing
4040
make -j $(nproc)
4141
export NUMBA_CUDA_TEST_BIN_DIR=`pwd`
4242
# Execute tests
43-
pytest -n auto -v
43+
pytest -n auto -v --dist loadscope
4444
```
4545

4646
Alternatively, you can use [pixi](https://pixi.sh/latest/installation/) to wrap all of that up for you:
4747

4848
```
4949
# run tests against CUDA 13
50-
pixi run -e cu13 test -n auto -v
50+
pixi run -e cu13 test -n auto -v --dist loadscope
5151
```
5252

5353

ci/test_conda.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ DEPENDENCIES=(
3535
"psutil"
3636
"pytest"
3737
"pytest-xdist"
38+
"pytest-benchmark"
3839
"cffi"
3940
"ml_dtypes"
4041
"python=${RAPIDS_PY_VERSION}"

ci/test_simulator.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ DEPENDENCIES=(
1212
"psutil"
1313
"pytest"
1414
"pytest-xdist"
15+
"pytest-benchmark"
1516
"cffi"
1617
"ml_dtypes"
1718
"python=${RAPIDS_PY_VERSION}"

numba_cuda/numba/cuda/tests/benchmarks/__init__.py

Whitespace-only changes.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: BSD-2-Clause
3+
4+
import string
5+
from numba import cuda
6+
import numpy as np
7+
import pytest
8+
9+
10+
@pytest.fixture
11+
def many_arrs():
12+
return [
13+
cuda.device_array(10000, dtype=np.float32)
14+
for _ in range(len(string.ascii_lowercase))
15+
]
16+
17+
18+
@pytest.fixture
19+
def one_arr():
20+
return cuda.device_array(10000, dtype=np.float32)
21+
22+
23+
def test_one_arg(benchmark, one_arr):
24+
@cuda.jit("void(float32[:])")
25+
def one_arg(arr1):
26+
return
27+
28+
benchmark(one_arg[1, 1], one_arr)
29+
30+
31+
def test_many_args(benchmark, many_arrs):
32+
@cuda.jit("void({})".format(", ".join(["float32[:]"] * len(many_arrs))))
33+
def many_args(
34+
a,
35+
b,
36+
c,
37+
d,
38+
e,
39+
f,
40+
g,
41+
h,
42+
i,
43+
j,
44+
k,
45+
l,
46+
m,
47+
n,
48+
o,
49+
p,
50+
q,
51+
r,
52+
s,
53+
t,
54+
u,
55+
v,
56+
w,
57+
x,
58+
y,
59+
z,
60+
):
61+
return
62+
63+
benchmark(many_args[1, 1], *many_arrs)

pixi.lock

Lines changed: 55 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ test = [
5353
"cffi",
5454
"pytest",
5555
"pytest-xdist",
56+
"pytest-benchmark",
5657
"filecheck",
5758
"ml_dtypes",
59+
"statistics",
5860
]
5961
test-cu12 = [
6062
"nvidia-curand-cu12",
@@ -176,6 +178,26 @@ build-tests = { cmd = [
176178
"-C",
177179
"$PIXI_PROJECT_ROOT/testing",
178180
] }
181+
bench = { cmd = [
182+
"pytest",
183+
"$PIXI_PROJECT_ROOT/testing",
184+
"--pyargs",
185+
"numba.cuda.tests.benchmarks",
186+
"--benchmark-only",
187+
"--benchmark-enable",
188+
"--benchmark-autosave",
189+
"--benchmark-group-by=name",
190+
] }
191+
benchcmp = { cmd = [
192+
"pytest",
193+
"$PIXI_PROJECT_ROOT/testing",
194+
"--pyargs",
195+
"numba.cuda.tests.benchmarks",
196+
"--benchmark-only",
197+
"--benchmark-enable",
198+
"--benchmark-group-by=name",
199+
"--benchmark-compare",
200+
] }
179201

180202
[tool.pixi.target.linux.tasks.test]
181203
cmd = ["pytest", "$PIXI_PROJECT_ROOT/testing"]

testing/pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
minversion = 8.0
77
consider_namespace_packages = true
88
# loadscope ensures the grouping required by CUDATestCase
9-
addopts = --dist loadscope --pyargs numba.cuda.tests
9+
addopts = --pyargs numba.cuda.tests

0 commit comments

Comments
 (0)