Nvrtc include pathes

I started from the examples and created my optix application that is built into to a library (.so) because i am using it with ctypes from python scripts. Locally everything works fine.

So i tried moving everything to another computer without rerunning cmake and make and as expected i got some missing dependencies that i am now trying to fix. The first few i could fix by setting env variables like the OPTIX_SAMPLES_SDK_DIR.

But now i ran into the problem of nvrtc compilation failing because it can’t find the optix.h file. It seems to me that my library got built with a local path to find the includes so nvrtc naturally can’t find them on another machine.
Can anyone point me to the parts in the cmake files where i provide a dynamic path for this?
In the FindOptix.cmake file the Optix_INCLUDE variable is set from the OptiX_INSTALL_DIR which is set using the CMAKE_SOURCE_DIR. Could a change here solve my problem?

Does the second machine have an OptiX SDK and a CUDA Toolkit installed, because if not, you do not have the required headers for OptiX device code runtime compilation at all.

If runtime compilation is actually not required, you can disable the NVRTC usage inside the CMake build and use NVCC to compile all OptiX device *.cu source to *.ptx (or OptiX IR when you’re using OptiX SDK 7.5.0 and CUDA 11.7) and put that into a relative folder and load from there and not use sutil for that at all.

If you want to see which search paths are used during the NVRTC compilation, you could simply debug into the sutil functions getInputData and the getCuStringFromFile and getPtxFromCuString in there which do the compilation with NVRTC.
If you also search for SAMPLES_DIR and getEnv inside the sutil code, you’ll find where it builds the search paths.

Inside getPtxFromCuString look at what is added as include "-I" paths to the nvrtc options.
That code will obviously know the OptiX include directory because that assumes it’s working inside the OptiX SDK folder structure itself.

Especially these are your paths which get set by the top-most CMakeLists.txt.
You could have also searched for NVRTC in all files of the OptiX SDK 7.x.0

    const char*              abs_dirs[] = {SAMPLES_ABSOLUTE_INCLUDE_DIRS};
    const char*              rel_dirs[] = {SAMPLES_RELATIVE_INCLUDE_DIRS};

All that said, I would not recommend using that part of the OptiX SDK example framework for own applications simply because of those hardcoded sample directory paths inside the executables.
That would need to be set dynamically if the application should do runtime compilation on any target machine with the OptiX SDK and CUDA Toolkit possibly installed in non-default locations.
Well, at least the CUDA Toolkit installer sets a CUDA_PATH environment variable. I do that for OptiX SDK versions manually.

Please read this post from an older OptiX version for possible solutions:
https://forums.developer.nvidia.com/t/sdk-samples-sutil-getptxstring-file-path/70963/2

For an OptiX application framework which is not using sutil and only the OptiX 7 headers, have a look at these examples: https://forums.developer.nvidia.com/t/optix-advanced-samples-on-github/48410/7
(Not using NVRTC though. but that would be simple to add where the readData calls are done to create the OptixModule objects.)

Thanks once more for the detailed info on the problem!

Yes i copied the complete OptiX SDK and installed the CUDA toolkit. I could fix my problem by modifying the top-most CmakeLists.txt includes and setting the needed environment variables. Using precompiled .ptx files is a great hint though! I definitely would like to built a project “from scratch” to get rid of all the stuff from the examples i don’t need, but sutil provides some great functionality(especially the code for creating acceleration structures from gltf data) that i would spend a lot of time recreating.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.