Repository: numba/numba
Pull request: CUDA: Skip managed alloc tests on ARM
Managed allocation does work on AArch64, but the tests cause some problems on various different Tegra devices. Given the lack of AArch64 testing capability, for now we'll skip the tests on ARM and note that the support is considered "experimental".

Fixes #7180.

Problem statement:
CUDA: Managed alloc test fail on Jetson AGX Xavier
Message from test suite:

```
======================================================================
ERROR: test_managed_alloc_driver_host_attach (numba.cuda.tests.cudadrv.test_managed_alloc.TestManagedAlloc)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gmarkall/numbadev/numba/numba/cuda/tests/cudadrv/test_managed_alloc.py", line 67, in test_managed_alloc_driver_host_attach
    self._test_managed_alloc_driver(0.01, attach_global=False)
  File "/home/gmarkall/numbadev/numba/numba/cuda/tests/cudadrv/test_managed_alloc.py", line 84, in _test_managed_alloc_driver
    device_memset(mem, magic, n_bytes)
  File "/home/gmarkall/numbadev/numba/numba/cuda/cudadrv/driver.py", line 2469, in device_memset
    fn(device_pointer(dst), val, size, *varargs)
  File "/home/gmarkall/numbadev/numba/numba/cuda/cudadrv/driver.py", line 302, in safe_cuda_api_call
    self._check_error(fname, retcode)
  File "/home/gmarkall/numbadev/numba/numba/cuda/cudadrv/driver.py", line 342, in _check_error
    raise CudaAPIError(retcode, msg)
numba.cuda.cudadrv.driver.CudaAPIError: [1] Call to cuMemsetD8 results in CUDA_ERROR_INVALID_VALUE
```

During the test run, the following is also emitted:

```
test_managed_alloc_driver_host_attach (numba.cuda.tests.cudadrv.test_managed_alloc.TestManagedAlloc) ... ERROR
test_managed_alloc_driver_oversubscribe (numba.cuda.tests.cudadrv.test_managed_alloc.TestManagedAlloc) ... skipped ''
test_managed_alloc_driver_undersubscribe (numba.cuda.tests.cudadrv.test_managed_alloc.TestManagedAlloc) ... NvMapReserveOp 0x80000001 failed [22]
NvMapReserveOp 0x80000000 failed [22]
```

Hints from issue discussion:

Commit message: CUDA: Skip managed alloc tests on ARM

Managed allocation does work on AArch64, but the tests cause some
problems on various different Tegra devices. Given the lack of AArch64
testing capability, for now we'll skip the tests on ARM and note that
the support is considered "experimental".

Fixes #7180.

Patch to review:
diff --git a/numba/cuda/api.py b/numba/cuda/api.py
index 6275a96f748..4788558a21f 100644
--- a/numba/cuda/api.py
+++ b/numba/cuda/api.py
@@ -146,8 +146,8 @@ def managed_array(shape, dtype=np.float_, strides=None, order='C', stream=0,
     Allocate a np.ndarray with a buffer that is managed.
     Similar to np.empty().
 
-    Managed memory is supported on Linux, and is considered experimental on
-    Windows.
+    Managed memory is supported on Linux / x86 and PowerPC, and is considered
+    experimental on Windows and Linux / AArch64.
 
     :param attach_global: A flag indicating whether to attach globally. Global
                           attachment implies that the memory is accessible from
diff --git a/numba/cuda/testing.py b/numba/cuda/testing.py
index 49bc83dd86e..95294c2060b 100644
--- a/numba/cuda/testing.py
+++ b/numba/cuda/testing.py
@@ -1,5 +1,6 @@
 import contextlib
 import os
+import platform
 import shutil
 import sys
 
@@ -99,6 +100,12 @@ def skip_with_nvdisasm(reason):
     return unittest.skipIf(nvdisasm_path is not None, reason)
 
 
+def skip_on_arm(reason):
+    cpu = platform.processor()
+    is_arm = cpu.startswith('arm') or cpu.startswith('aarch')
+    return unittest.skipIf(is_arm, reason)
+
+
 def cc_X_or_above(major, minor):
     if not config.ENABLE_CUDASIM:
         cc = devices.get_context().device.compute_capability
diff --git a/numba/cuda/tests/cudadrv/test_managed_alloc.py b/numba/cuda/tests/cudadrv/test_managed_alloc.py
index 03b996216fc..624f0210c11 100644
--- a/numba/cuda/tests/cudadrv/test_managed_alloc.py
+++ b/numba/cuda/tests/cudadrv/test_managed_alloc.py
@@ -3,12 +3,13 @@
 from numba.cuda.cudadrv.driver import device_memset, driver
 from numba import cuda
 from numba.cuda.testing import unittest, ContextResettingTestCase
-from numba.cuda.testing import skip_on_cudasim
+from numba.cuda.testing import skip_on_cudasim, skip_on_arm
 from numba.tests.support import linux_only
 
 
 @skip_on_cudasim('CUDA Driver API unsupported in the simulator')
 @linux_only
+@skip_on_arm
 class TestManagedAlloc(ContextResettingTestCase):
 
     def get_total_gpu_memory(self):


Code review comments:
diff_hunk: @@ -3,12 +3,13 @@
 from numba.cuda.cudadrv.driver import device_memset, driver
 from numba import cuda
 from numba.cuda.testing import unittest, ContextResettingTestCase
-from numba.cuda.testing import skip_on_cudasim
+from numba.cuda.testing import skip_on_cudasim, skip_on_arm
 from numba.tests.support import linux_only
 
 
 @skip_on_cudasim('CUDA Driver API unsupported in the simulator')
 @linux_only
+@skip_on_arm
path: numba/cuda/tests/cudadrv/test_managed_alloc.py
text: @user1:
Incorrect use. Missing reason.

@author:
Whoops!