cupy

Cupy `RawKernel` CUDA_ERROR_NOT_FOUND: named symbol not found [cupy]


I am trying to write a custom cuda kernel in python using cupy's RawKernel, however I keep getting the following error

Traceback (most recent call last):
  File "/nfs/users/xxxxxxxxx/git/raw_kernel.py", line 32, in <module>
    null.compile()
  File "cupy/_core/raw.pyx", line 291, in cupy._core.raw.RawKernel.compile
  File "cupy/_core/raw.pyx", line 117, in cupy._core.raw.RawKernel._kernel
  File "cupy/cuda/function.pyx", line 275, in cupy.cuda.function.Module.get_function
  File "cupy/cuda/function.pyx", line 216, in cupy.cuda.function.Function.__init__
  File "cupy_backends/cuda/api/driver.pyx", line 226, in cupy_backends.cuda.api.driver.moduleGetFunction
  File "cupy_backends/cuda/api/driver.pyx", line 60, in cupy_backends.cuda.api.driver.check_status
cupy_backends.cuda.api.driver.CUDADriverError: CUDA_ERROR_NOT_FOUND: named symbol not found

Even when I define an empty function that does nothing, I am not able to get past compilation

none = """
__global__ void none() {
};
"""
null = cp.RawKernel(none, "null")
null.compile()

I am using python 3.10.12 with cupy 12.2.0. The cupyx's jit.Rawernel decorator works instead.


Solution

  • You need to pass the function's symbol name as the RawKernel argument. Use extern "C" to avoid symbol name being mangled.

    none = """
    extern "C" __global__ void none() {
    };
    """
    null = cp.RawKernel(none, "none")
    null.compile()
    

    See https://docs.cupy.dev/en/latest/user_guide/kernel.html#raw-kernels for more details.