Skip to content

Commit 96e10e6

Browse files
authored
test: enable fail-on-warn and clean up resulting failures (#529)
1 parent b04dd44 commit 96e10e6

31 files changed

+242
-222
lines changed

numba_cuda/numba/cuda/core/typed_passes.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,9 @@ def fallback_context(state, msg):
7070
# this emits a warning containing the error message body in the
7171
# case of fallback from npm to objmode
7272
loop_lift = "" if state.flags.enable_looplift else "OUT"
73-
msg_rewrite = (
74-
"\nCompilation is falling back to object mode "
75-
"WITH%s looplifting enabled because %s" % (loop_lift, msg)
76-
)
7773
warnings.warn_explicit(
78-
"%s due to: %s" % (msg_rewrite, e),
74+
"Compilation is falling back to object mode "
75+
f"WITH{loop_lift} looplifting enabled because {msg} due to: {e}",
7976
errors.NumbaWarning,
8077
state.func_id.filename,
8178
state.func_id.firstlineno,

numba_cuda/numba/cuda/core/untyped_passes.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,9 @@ def fallback_context(state, msg):
6666
# this emits a warning containing the error message body in the
6767
# case of fallback from npm to objmode
6868
loop_lift = "" if state.flags.enable_looplift else "OUT"
69-
msg_rewrite = (
70-
"\nCompilation is falling back to object mode "
71-
"WITH%s looplifting enabled because %s" % (loop_lift, msg)
72-
)
7369
warnings.warn_explicit(
74-
"%s due to: %s" % (msg_rewrite, e),
70+
"Compilation is falling back to object mode "
71+
f"WITH{loop_lift} looplifting enabled because {msg} due to: {e}",
7572
errors.NumbaWarning,
7673
state.func_id.filename,
7774
state.func_id.firstlineno,

numba_cuda/numba/cuda/cudadrv/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ def _alloc_finalizer(memory_manager, ptr, alloc_key, size):
14951495

14961496
def core():
14971497
if allocations:
1498-
del allocations[alloc_key]
1498+
allocations.pop(alloc_key, None)
14991499
deallocations.add_item(driver.cuMemFree, ptr, size)
15001500

15011501
return core

numba_cuda/numba/cuda/memory_management/memsys.cu

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ extern "C" __global__ void NRT_MemSys_print(void)
8989
if (TheMSys != nullptr)
9090
{
9191
printf("TheMSys->stats.enabled %d\n", TheMSys->stats.enabled);
92-
printf("TheMSys->stats.alloc %lu\n", TheMSys->stats.alloc.load());
93-
printf("TheMSys->stats.free %lu\n", TheMSys->stats.free.load());
94-
printf("TheMSys->stats.mi_alloc %lu\n", TheMSys->stats.mi_alloc.load());
95-
printf("TheMSys->stats.mi_free %lu\n", TheMSys->stats.mi_free.load());
92+
printf("TheMSys->stats.alloc %zu\n", TheMSys->stats.alloc.load());
93+
printf("TheMSys->stats.free %zu\n", TheMSys->stats.free.load());
94+
printf("TheMSys->stats.mi_alloc %zu\n", TheMSys->stats.mi_alloc.load());
95+
printf("TheMSys->stats.mi_free %zu\n", TheMSys->stats.mi_free.load());
9696
} else {
9797
printf("TheMsys is null.\n");
9898
}

numba_cuda/numba/cuda/simulator/api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from .kernel import FakeCUDAKernel
2323
from numba.cuda.core import config
2424
from numba.cuda.core.sigutils import is_signature
25-
from warnings import warn
2625
from ..args import In, Out, InOut # noqa: F401
2726

2827

@@ -111,8 +110,8 @@ def synchronize(self):
111110
pass
112111

113112
def elapsed_time(self, event):
114-
warn("Simulator timings are bogus")
115-
return 0.0
113+
"""This is here to preserve the API; the output is meaningless."""
114+
return -1.0
116115

117116

118117
event = Event

numba_cuda/numba/cuda/simulator/cudadrv/devicearray.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from contextlib import contextmanager
1010
from numba.cuda.np.numpy_support import numpy_version
11+
from numba.cuda.np import numpy_support
12+
from numba.cuda import types
1113

1214
import numpy as np
1315

@@ -57,8 +59,8 @@ def __wrap_if_fake(self, item):
5759
return item
5860

5961
def __getattr__(self, attrname):
60-
if attrname in dir(self._item._ary): # For e.g. array size.
61-
return self.__wrap_if_fake(getattr(self._item._ary, attrname))
62+
if (value := getattr(self._item, attrname, None)) is not None:
63+
return self.__wrap_if_fake(value)
6264
else:
6365
return self.__wrap_if_fake(self._item.__getitem__(attrname))
6466

@@ -109,6 +111,23 @@ def __init__(self, ary, stream=0):
109111
self._ary = ary
110112
self.stream = stream
111113

114+
@property
115+
def _numba_type_(self):
116+
"""
117+
Magic attribute expected by Numba to get the numba type that
118+
represents this object.
119+
"""
120+
broadcast = 0 in self.strides
121+
if self.is_c_contiguous() and not broadcast:
122+
layout = "C"
123+
elif self.is_f_contiguous() and not broadcast:
124+
layout = "F"
125+
else:
126+
layout = "A"
127+
128+
dtype = numpy_support.from_dtype(self._ary.dtype)
129+
return types.Array(dtype, self._ary.ndim, layout)
130+
112131
@property
113132
def alloc_size(self):
114133
return self._ary.nbytes

numba_cuda/numba/cuda/testing.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,44 +187,52 @@ def assertFileCheckMatches(
187187

188188
def skip_on_cudasim(reason):
189189
"""Skip this test if running on the CUDA simulator"""
190+
assert isinstance(reason, str)
190191
return unittest.skipIf(config.ENABLE_CUDASIM, reason)
191192

192193

193-
def skip_on_standalone_numba_cuda(reason):
194-
"""Skip this test if running on standalone numba_cuda"""
195-
return unittest.skipIf(not HAS_NUMBA, reason)
194+
skip_on_standalone_numba_cuda = unittest.skipUnless(
195+
HAS_NUMBA, "requires base numba install"
196+
)
196197

197198

198199
def skip_unless_cudasim(reason):
199200
"""Skip this test if running on CUDA hardware"""
201+
assert isinstance(reason, str)
200202
return unittest.skipUnless(config.ENABLE_CUDASIM, reason)
201203

202204

203205
def skip_unless_conda_cudatoolkit(reason):
204206
"""Skip test if the CUDA toolkit was not installed by Conda"""
207+
assert isinstance(reason, str)
205208
return unittest.skipUnless(get_conda_ctk_libdir() is not None, reason)
206209

207210

208211
def skip_if_external_memmgr(reason):
209212
"""Skip test if an EMM Plugin is in use"""
213+
assert isinstance(reason, str)
210214
return unittest.skipIf(config.CUDA_MEMORY_MANAGER != "default", reason)
211215

212216

213217
def skip_under_cuda_memcheck(reason):
218+
assert isinstance(reason, str)
214219
return unittest.skipIf(os.environ.get("CUDA_MEMCHECK") is not None, reason)
215220

216221

217222
def skip_without_nvdisasm(reason):
223+
assert isinstance(reason, str)
218224
nvdisasm_path = shutil.which("nvdisasm")
219225
return unittest.skipIf(nvdisasm_path is None, reason)
220226

221227

222228
def skip_with_nvdisasm(reason):
229+
assert isinstance(reason, str)
223230
nvdisasm_path = shutil.which("nvdisasm")
224231
return unittest.skipIf(nvdisasm_path is not None, reason)
225232

226233

227234
def skip_on_arm(reason):
235+
assert isinstance(reason, str)
228236
cpu = platform.processor()
229237
is_arm = cpu.startswith("arm") or cpu.startswith("aarch")
230238
return unittest.skipIf(is_arm, reason)
@@ -236,6 +244,7 @@ def skip_on_wsl2(reason):
236244
Detection is based on the kernel release string, which typically contains
237245
"microsoft-standard-WSL2" on WSL2 systems.
238246
"""
247+
assert isinstance(reason, str)
239248
rel = platform.release().lower()
240249
is_wsl2 = ("microsoft-standard-wsl2" in rel) or ("wsl2" in rel)
241250
return unittest.skipIf(is_wsl2, reason)
@@ -269,6 +278,7 @@ def skip_if_curand_kernel_missing(fn):
269278

270279
def skip_if_mvc_enabled(reason):
271280
"""Skip a test if Minor Version Compatibility is enabled"""
281+
assert isinstance(reason, str)
272282
return unittest.skipIf(
273283
config.CUDA_ENABLE_MINOR_VERSION_COMPATIBILITY, reason
274284
)
@@ -321,6 +331,7 @@ def skip_if_cudadevrt_missing(fn):
321331

322332

323333
def skip_if_nvjitlink_missing(reason):
334+
assert isinstance(reason, str)
324335
return unittest.skipIf(not driver._have_nvjitlink(), reason)
325336

326337

numba_cuda/numba/cuda/tests/cudadrv/test_cuda_libraries.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

numba_cuda/numba/cuda/tests/cudadrv/test_is_fp16.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TestIsFP16Supported(CUDATestCase):
99
def test_is_fp16_supported(self):
1010
self.assertTrue(cuda.is_float16_supported())
1111

12-
@skip_on_cudasim
12+
@skip_on_cudasim("fp16 not available in sim")
1313
@skip_unless_cc_53
1414
def test_device_supports_float16(self):
1515
self.assertTrue(cuda.get_current_device().supports_float16)

numba_cuda/numba/cuda/tests/cudadrv/test_linker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: BSD-2-Clause
33

44
import numpy as np
5-
import warnings
5+
import pytest
66
from numba.cuda.testing import unittest
77
from numba.cuda.testing import (
88
skip_on_cudasim,
@@ -12,7 +12,6 @@
1212
from numba.cuda.testing import CUDATestCase, test_data_dir
1313
from numba.cuda.cudadrv.driver import CudaAPIError, _Linker, LinkerError
1414
from numba.cuda import require_context
15-
from numba.cuda.tests.support import ignore_internal_warnings
1615
from numba import cuda
1716
from numba.cuda import void, float64, int64, int32, float32
1817
from numba.cuda.typing.typeof import typeof
@@ -172,8 +171,7 @@ def test_linking_cu_log_warning(self):
172171

173172
link = str(test_data_dir / "warn.cu")
174173

175-
with warnings.catch_warnings(record=True) as w:
176-
ignore_internal_warnings()
174+
with pytest.warns(UserWarning) as w:
177175

178176
@cuda.jit("void(int32)", link=[link])
179177
def kernel(x):

0 commit comments

Comments
 (0)