If you’re fine with using CMake to generate a solution with optionally multiple projects independently of the host compiler version and cross platform, then there exist quite some examples doing that.
These sticky posts contain links to multiple examples doing that differently than the OptiX SDK examples.
https://forums.developer.nvidia.com/t/optix-7-1-release/139962
https://forums.developer.nvidia.com/t/optix-advanced-samples-on-github/48410/4
My OptiX application framework is completely standalone. It’s not using anything from the OptiX SDK 7 except for the host and device API headers.
You could easily strip down one of the intro_* examples to just the ray generation program which colors the output buffer without shooting a single ray. That’s effectively the “optixHello” program in all SDKs.
The OptiX 7 SIGGRAPH course examples has that and my OptiX 5/6 introduction samples also have that.
If you mean you want to do that as a MSVS native project using the CUDA toolkit Visual Studio integration, things get a little more manual.
Assuming you know how to handle all other parts of a MSVS solution for the host code, the remaining problem is setting the correct CUDA compiler (NVCC) options on the *.cu files in your project to compile them to *.ptx input files for OptiX 7 with working and fast code. The rules are:
- Use sm_50 and compute_50 architecture targets (e.g. --gpu-architecture=compute_50) to generate PTX code for the minimum supported GPU architecture Maxwell. That will work on any newer GPU as well. Note that this is deprecated in CUDA 11 and will result in warnings, CUDA 10.x won’t. You can use SM 6.0 (Pascal) as well to suppress these. (The OptiX SDK 7.1.0 examples do that.)
- Use --machine=64 (-m64), only 64-bit code is supported in OptiX.
- Do not compile to obj or cubin, the output needs to be --ptx.
- Do not use debug flags -g and -G. That’s the default in the Debug target. OptiX might not handle all debug instrumentation.
- Enable --use_fast_math to get faster code. That means .approx instructions for trigonometric functions and reciprocals and no inadvertent use of slow double precision floats.
- Enable --relocatable-device-code=true (or -rdc) or --keep-device-functions. This is required to keep the CUDA compiler from eliminating direct or continuation callables as dead code because it doesn’t find a call to them in the same module.
- Enable --generate-line-info if you want to profile your code with Nsight Compute in the future.
You can check the exact NVCC command line inside the OptiIX SDK examples for each *.cu file while generating the project inside CMake with an additional message output. Follow the link in this post:
https://forums.developer.nvidia.com/t/cmake-dont-compile-cuda-kernels/140937/6