I have a .cu file with these heads:
#include </usr/include/features.h>
#include </usr/include/assert.h>
#include </usr/include/stdio.h>
When I use nvcc
command to compile this file, it passed, but when I use cupy.RawKernel()
to execute code in this .cu file, it crashed with this:
PyDev console: starting.
Traceback (most recent call last):
File "/home/username/.local/share/JetBrains/IntelliJIdea2024.2/python/helpers-pro/pydevd_asyncio/pydevd_asyncio_utils.py", line 117, in _exec_async_code
result = func()
^^^^^^
File "<input>", line 1, in <module>
File "cupy/_core/raw.pyx", line 93, in cupy._core.raw.RawKernel.__call__
File "cupy/_core/raw.pyx", line 100, in cupy._core.raw.RawKernel.kernel.__get__
File "cupy/_core/raw.pyx", line 117, in cupy._core.raw.RawKernel._kernel
File "cupy/_util.pyx", line 64, in cupy._util.memoize.decorator.ret
File "cupy/_core/raw.pyx", line 538, in cupy._core.raw._get_raw_module
File "cupy/_core/core.pyx", line 2265, in cupy._core.core.compile_with_cache
File "cupy/_core/core.pyx", line 2283, in cupy._core.core.compile_with_cache
File "/home/username/.conda/envs/torchhydro1/lib/python3.11/site-packages/cupy/cuda/compiler.py", line 498, in _compile_module_with_cache
return _compile_with_cache_cuda(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/username/.conda/envs/torchhydro1/lib/python3.11/site-packages/cupy/cuda/compiler.py", line 577, in _compile_with_cache_cuda
ptx, mapping = compile_using_nvrtc(
^^^^^^^^^^^^^^^^^^^^
File "/home/username/.conda/envs/torchhydro1/lib/python3.11/site-packages/cupy/cuda/compiler.py", line 333, in compile_using_nvrtc
return _compile(source, options, cu_path,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/username/.conda/envs/torchhydro1/lib/python3.11/site-packages/cupy/cuda/compiler.py", line 317, in _compile
compiled_obj, mapping = prog.compile(options, log_stream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/username/.conda/envs/torchhydro1/lib/python3.11/site-packages/cupy/cuda/compiler.py", line 711, in compile
raise CompileException(log, self.src, self.name, options,
cupy.cuda.compiler.CompileException: /usr/include/features.h(439): catastrophic error: cannot open source file "stdc-predef.h"
1 catastrophic error detected in the compilation of "/tmp/tmpjszp_wuk/239939fff8cdfee531aa36905d9ea0a21ebe8db4.cubin.cu".
Compilation terminated.
So how to quote correct head files rather than put all files in #include
?
change backend
parameter to 'nvcc'
when use cupy.RawKernel()
will solve it.