Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion numba_cuda/numba/cuda/cudadrv/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
c_void_p,
c_float,
c_uint,
c_uint8,
)
import contextlib
import importlib
Expand Down Expand Up @@ -3439,6 +3440,8 @@ def device_memset(dst, val, size, stream=0):
size: number of byte to be written
stream: a CUDA stream
"""
ptr = device_pointer(dst)

varargs = []

if stream:
Expand All @@ -3452,7 +3455,24 @@ def device_memset(dst, val, size, stream=0):
else:
fn = driver.cuMemsetD8

fn(device_pointer(dst), val, size, *varargs)
try:
fn(ptr, val, size, *varargs)
except CudaAPIError as e:
invalid = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you create a situation which this code is intended to handle? Is there an example that could be turned into a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite was already catching it. I'm was running into unit test failures running on WSL. One was lack of support for IPC and the other was memset throwing errors when attempting to access memory accessible by host and device. This fallback enables the test suite to complete successfully.

binding.CUresult.CUDA_ERROR_INVALID_VALUE
if USE_NV_BINDING
else enums.CUDA_ERROR_INVALID_VALUE
)
if (
e.code == invalid
and getattr(dst, "__cuda_memory__", False)
and getattr(dst, "is_managed", False)
):
buf = (c_uint8 * size).from_address(host_pointer(dst))
byte = val & 0xFF
buf[:] = [byte] * size
return
raise


def profile_start():
Expand Down
11 changes: 11 additions & 0 deletions numba_cuda/numba/cuda/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ def skip_on_arm(reason):
return unittest.skipIf(is_arm, reason)


def skip_on_wsl2(reason):
"""Skip test when running under WSL2.

Detection is based on the kernel release string, which typically contains
"microsoft-standard-WSL2" on WSL2 systems.
"""
rel = platform.release().lower()
is_wsl2 = ("microsoft-standard-wsl2" in rel) or ("wsl2" in rel)
return unittest.skipIf(is_wsl2, reason)


def skip_if_cuda_includes_missing(fn):
# Skip when cuda.h is not available - generally this should indicate
# whether the CUDA includes are available or not
Expand Down
3 changes: 3 additions & 0 deletions numba_cuda/numba/cuda/tests/cudapy/test_ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
skip_on_arm,
skip_on_cudasim,
skip_under_cuda_memcheck,
skip_on_wsl2,
ContextResettingTestCase,
ForeignArray,
)
Expand Down Expand Up @@ -93,6 +94,7 @@ def ipc_array_test(ipcarr, result_queue):
@skip_under_cuda_memcheck("Hangs cuda-memcheck")
@skip_on_cudasim("Ipc not available in CUDASIM")
@skip_on_arm("CUDA IPC not supported on ARM in Numba")
@skip_on_wsl2("CUDA IPC unreliable on WSL2; skipping IPC tests")
class TestIpcMemory(ContextResettingTestCase):
def test_ipc_handle(self):
# prepare data for IPC
Expand Down Expand Up @@ -261,6 +263,7 @@ def staged_ipc_array_test(ipcarr, device_num, result_queue):
@skip_under_cuda_memcheck("Hangs cuda-memcheck")
@skip_on_cudasim("Ipc not available in CUDASIM")
@skip_on_arm("CUDA IPC not supported on ARM in Numba")
@skip_on_wsl2("CUDA IPC unreliable on WSL2; skipping IPC tests")
class TestIpcStaged(ContextResettingTestCase):
def test_staged(self):
# prepare data for IPC
Expand Down