forked from NVIDIA/cuda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_numba.py
More file actions
52 lines (34 loc) · 1.18 KB
/
Copy pathtest_numba.py
File metadata and controls
52 lines (34 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright 2021-2025 NVIDIA Corporation. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
import numpy as np
import pytest
try:
from numba import cuda
skip_tests = False
except ImportError:
skip_tests = True
def launch_empty(kernel, stream):
kernel[1, 1, stream]()
def launch(kernel, stream, arg):
kernel[1, 1, stream](arg)
# Measure launch latency with no parmaeters
@pytest.mark.skipif(skip_tests, reason="Numba is not installed")
@pytest.mark.benchmark(group="numba", min_rounds=1000)
def test_launch_latency_empty_kernel(benchmark):
stream = cuda.stream()
@cuda.jit
def empty_kernel():
return
benchmark(launch_empty, empty_kernel, stream)
cuda.synchronize()
# Measure launch latency with a single parameter
@pytest.mark.skipif(skip_tests, reason="Numba is not installed")
@pytest.mark.benchmark(group="numba", min_rounds=1000)
def test_launch_latency_small_kernel(benchmark):
stream = cuda.stream()
arg = cuda.device_array(1, dtype=np.float32, stream=stream)
@cuda.jit
def small_kernel(array):
array[0] = 0.0
benchmark(launch, small_kernel, stream, arg)
cuda.synchronize()