From 50137d3f43518ae52abba3a7baf02f1330b9c239 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 25 Nov 2026 13:27:40 -0500 Subject: [PATCH] test(cuda.core): drop numba from test_occupancy_max_potential_block_size_b2dsize The test used numba only to compile the size_t (*)(int) block-size-to- dynamic-shared-memory callback, and skipped when numba was missing. No CI job that runs test_module.py installs numba, so it never ran. Build the callback with ctypes instead. The driver calls it synchronously on the calling thread while cuOccupancyMaxPotentialBlockSize runs. Record the block sizes the driver queries and assert that the callback was called, so the test fails if the callback is ignored. Closes #3566. Co-Authored-By: Claude Opus 5.5 --- cuda_core/tests/test_module.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/cuda_core/tests/test_module.py b/cuda_core/tests/test_module.py index c6d42e0a14e4..577c7f6a7647 100644 --- a/cuda_core/tests/test_module.py +++ b/cuda_core/tests/test_module.py @@ -18,11 +18,6 @@ from cuda.core._utils.cuda_utils import CUDAError, driver, handle_return from cuda.core._utils.version import driver_version -try: - import numba -except ImportError: - numba = None - SAXPY_KERNEL = r""" template __global__ void saxpy(const T a, @@ -662,22 +657,24 @@ def test_occupancy_max_potential_block_size_constant(get_saxpy_kernel_cubin, blo kernel.occupancy.max_potential_block_size(invalid_dsmem, block_size_limit) -# This test is not currently run in any CI job -@pytest.mark.skipif(numba is None, reason="Test requires numba to be installed") @pytest.mark.parametrize("block_size_limit", [32, 64, 96, 120, 128, 277, 0]) def test_occupancy_max_potential_block_size_b2dsize(get_saxpy_kernel_cubin, block_size_limit): """Tests use case when shared memory needed depends on the block size""" kernel, _ = get_saxpy_kernel_cubin + queried_block_sizes = [] - def shared_memory_needed(block_size: numba.intc) -> numba.size_t: + # The driver calls this synchronously on this thread, so a ctypes callback + # works. It must stay referenced until max_potential_block_size returns. + @ctypes.CFUNCTYPE(ctypes.c_size_t, ctypes.c_int) + def shared_memory_needed(block_size): "Size of dynamic shared memory needed by kernel of this block size" + queried_block_sizes.append(block_size) return 1024 * (block_size // 32) - b2dsize_sig = numba.size_t(numba.intc) - dsmem_needed_cfunc = numba.cfunc(b2dsize_sig)(shared_memory_needed) - fn_ptr = ctypes.cast(dsmem_needed_cfunc.ctypes, ctypes.c_void_p).value + fn_ptr = ctypes.cast(shared_memory_needed, ctypes.c_void_p).value b2dsize_fn = driver.CUoccupancyB2DSize(_ptr=fn_ptr) config_data = kernel.occupancy.max_potential_block_size(b2dsize_fn, block_size_limit) + assert queried_block_sizes, "the driver never called the block-size-to-shared-memory callback" dev_props = Device().properties assert block_size_limit <= dev_props.max_threads_per_block min_grid_size, max_block_size = config_data