Skip to content

Commit 3f308df

Browse files
fix skip in test_core when no GPU available (#752)
* fix skip test when no GPU available * add conditional import in __init__ and update files * change import style for gpu device functions * Handle importing gpu device func when there is no GPU * replace gpu dummy docstring with actual one when no GPU * Avoid replacing docstrings for private functions * minor changes * Remove unnecessary import of function * Removed hardcoded value for number of threads per block in GPU
1 parent 73622f2 commit 3f308df

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

stumpy/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
from .core import _gpu_aampdist_driver_not_found as gpu_aampdist # noqa: F401
5050
from .core import _gpu_stimp_driver_not_found as gpu_stimp # noqa: F401
5151
from .core import _gpu_aamp_stimp_driver_not_found as gpu_aamp_stimp # noqa: F401
52+
53+
from . import core
54+
55+
core._gpu_searchsorted_left = core._gpu_searchsorted_left_driver_not_found
56+
core._gpu_searchsorted_right = core._gpu_searchsorted_right_driver_not_found
57+
5258
import ast
5359
import pathlib
5460

tests/test_core.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
import naive
1313

1414
if cuda.is_available():
15-
from stumpy.core import _gpu_searchsorted_left, _gpu_searchsorted_right
16-
else: # pragma: no cover
17-
from stumpy.core import (
18-
_gpu_searchsorted_left_driver_not_found as _gpu_searchsorted_left,
19-
)
20-
from stumpy.core import (
21-
_gpu_searchsorted_right_driver_not_found as _gpu_searchsorted_right,
22-
)
15+
16+
@cuda.jit("(f8[:, :], f8[:], i8[:], i8, b1, i8[:])")
17+
def _gpu_searchsorted_kernel(a, v, bfs, nlevel, is_left, idx):
18+
# A wrapper kernel for calling device function _gpu_searchsorted_left/right.
19+
i = cuda.grid(1)
20+
if i < a.shape[0]:
21+
if is_left:
22+
idx[i] = core._gpu_searchsorted_left(a[i], v[i], bfs, nlevel)
23+
else:
24+
idx[i] = core._gpu_searchsorted_right(a[i], v[i], bfs, nlevel)
25+
2326

2427
try:
2528
from numba.errors import NumbaPerformanceWarning
@@ -28,20 +31,6 @@
2831

2932
TEST_THREADS_PER_BLOCK = 10
3033

31-
if not cuda.is_available(): # pragma: no cover
32-
pytest.skip("Skipping Tests No GPUs Available", allow_module_level=True)
33-
34-
35-
@cuda.jit("(f8[:, :], f8[:], i8[:], i8, b1, i8[:])")
36-
def _gpu_searchsorted_kernel(a, v, bfs, nlevel, is_left, idx):
37-
# A wrapper kernel for calling device function _gpu_searchsorted_left/right.
38-
i = cuda.grid(1)
39-
if i < a.shape[0]:
40-
if is_left:
41-
idx[i] = _gpu_searchsorted_left(a[i], v[i], bfs, nlevel)
42-
else:
43-
idx[i] = _gpu_searchsorted_right(a[i], v[i], bfs, nlevel)
44-
4534

4635
def naive_rolling_window_dot_product(Q, T):
4736
window = len(Q)
@@ -1403,7 +1392,7 @@ def test_find_matches_maxmatch():
14031392
@patch("stumpy.config.STUMPY_THREADS_PER_BLOCK", TEST_THREADS_PER_BLOCK)
14041393
def test_gpu_searchsorted():
14051394
if not cuda.is_available(): # pragma: no cover
1406-
pytest.skip("Skipping Tests No GPUs Available", allow_module_level=True)
1395+
pytest.skip("Skipping Tests No GPUs Available")
14071396

14081397
n = 3 * config.STUMPY_THREADS_PER_BLOCK + 1
14091398
V = np.empty(n, dtype=np.float64)

0 commit comments

Comments
 (0)