You have to send the "filename" and the source of each header separately.
When the preprocessor does its thing, it'll use any #include
filenames as a key to find the source for the header, based on the collection that you provide.
I suspect that, in this case, the compiler (driver) doesn't have file system access, so you have to give it the source in much the same way that you would for shader includes in OpenGL.
So:
Include your header's name when calling nvrtcCreateProgram
. The compiler will, internally, generate the equivalent of a std::map<string,string>
containing the source of each header indexed by the given name.
In your kernel source, use #include "foo.cuh"
as usual.
The compiler will use foo.cuh
as an index or key into its internal map (created when you called nvrtcCreateProgram
), and will retrieve the header source from that collection
Compilation proceeds as normal.
One of the reasons that nvrtc provides only a "subset" of features is that the compiler plays in a somewhat sandboxed environment, without necessarily having all of the supporting tools and utilities lying around that you have with offline compilation. So, you have to manually handle a lot of the stuff that the normal nvcc + (gcc | MSVC| clang)
combination provides.
A possible, but non-ideal, solution would be to preprocess the file that you need in your IDE, save the result and then #include
that. However, I bet there is a better way to do that. if you just want curand
, consider diving into the library and extracting the part you need (blech) or using another GPU-friendly rand
implementation. On older CUDA versions, I just generated a big array of random floats on the host, uploaded it to the GPU, and sampled it in the kernels.
This related link may be helpful.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…