In order to build my .cu file inside my solution, do I need to create any new file or can I do it only by configuring the project properties tab?
To setup a standalone OptiX application, you should put all files which belong to your application into your own application folder(s).
That is, you do not reference any *.cpp
or *.cu
source files directly from the OptiX SDK, except for the things inside OptiX SDK <version>/include
which defines the OptiX 7 or 8 API and some helper functions.
Instead you copy everything you need to your local application folders and then build your project from those.
Everything the OptiX SDK examples do to setup their own application framework is not strictly necessary inside your own OptiX applications.
The only thing you really need, are the OptiX API headers inside the include folder.
Just look at my examples. I’m only using the headers from the OptiX SDK include folder, nothing else.
If you insist on using the OptiX SDK sutil library, which I would highly discourage, then you should also copy the necessary files locally and use them inside your code directly instead of building a library. The basic headers in there are useful but if you want your own OptiX application framework, you should only learn from the things done inside sutil.cpp.
Should I add in Build Dependencies->Build Customizations the CUDA 12.1 (targets, props)?
How you configure your own application MSVS solution is your choice!
If you want to use CMake to easily build solutions for various platforms and compilers, look at how my standalone CMake scripts do it.
If you want to build your own solution and projects manually inside the MSVS IDE and use the CUDA Visual Studio Integration to control the translation rules for each *.cu file individually, that is also possible, but that is tedious and you must meticulously set every NVCC options exactly as required for the OptiX device code.
The default CUDA compilation settings won’t work for OptiX device code!
Read all comments I added to the nvcc.exe command line options here again.
Could I simply run a pre build event and run the proper nvcc command? I tried this with no success:
Because you are still doing exactly the same error as in the thread I linked above.
That command line compiles a *.cu
file to a native CUDA object module because of the --compile
option inside that. That is simply wrong for OptiX device code *.cu files.
Instead you must use only either --ptx
to translate to PTX intermediate source code or --optixir
to translate to OptiX-IR intermediate binary code. Either is what optixCreateModule requires.
Let’s do the same analysis like in the above links:
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin\nvcc.exe"
--optix-ir // You cannot have --optixir and --compile inside the same nvcc command line!
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\Hostx86\x64" // This looks wrong. Is there a --ccbin missing before this?
-x cu // This lets nvcc handle all given input files as *.cu files. Not necessary when the only input file is *.cu anyway.
-I"C:\Program Files\Rhino 8 SDK\inc"
-I"C:\ProgramData\NVIDIA Corporation\OptiX SDK 8.0.0\include" // Yes, required.
// I do not recommend referencing any other files inside the OptiX SDK directly when building own applications.
// They can change with any OptiX SDK version. Copy them locally and include them from your own application folders.
-I"C:\ProgramData\NVIDIA Corporation\OptiX SDK 8.0.0\SDK\cuda"
-I"C:\ProgramData\NVIDIA Corporation\OptiX SDK 8.0.0\SDK"
-I"C:\ProgramData\NVIDIA Corporation\OptiX SDK 8.0.0\SDK\build\include" // No. Anything in build is just a copy of the original SDK sources.
-I"C:\ProgramData\NVIDIA Corporation\OptiX SDK 8.0.0\SDK\build" // No
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\include" // Yes, required.
-I"C:\ProgramData\NVIDIA Corporation\OptiX SDK 8.0.0\SDK\support\imgui\.."
-I"C:\ProgramData\NVIDIA Corporation\OptiX SDK 8.0.0\SDK\support\."
-I"C:\ProgramData\NVIDIA Corporation\OptiX SDK 8.0.0\SDK\sutil\\"
-I"C:\Program Files\Rhino 8 SDK\inc" // Duplicate.
-I"C:\Users\tgf\source\repos\vcpkg\vcpkg\installed\x64-windows\include"
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\include" // Duplicate
-G // Avoid this. Debug device code will be really slow.
--keep-dir x64\Debug // Unnecessary when not using --keep, which is also not necessary other than for CUDA compiler bugs.
-maxrregcount=0 // OK
--machine 64 // Yes, required.
-g // Debug host code is not needed when only building OptiX device code
-DWIN32
-DWIN64
-D_DEBUG
-D_CONSOLE
-D_MBCS
-Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd "
--compile--use_fast_math // The --compile is wrong when it's used. There is a space missing here. --use_fast_math is recommended for performance
File.cu \ -o File.optixir // Not sure why there is a backslash, it's single line. Rest is OK, File.cu is the input, File.optixir is the output
Is there a guide like this for integrating Optix .cu files to VS solution?:
You need to set all CUDA compilation options exactly as described here:
https://raytracing-docs.nvidia.com/optix8/guide/index.html#program_pipeline_creation#program-input
I would still recommend using CMake and following the process described here. That will save a lot of time in the long run.
https://forums.developer.nvidia.com/t/converting-vs-property-sheet-into-cmake-settings/287159/5