OptiX including <curand> results in catastrophic error: cannot include stdlib.h....

Hi

I want to use cuda random generator in my optix code, but when I include the headers,
I get the following compilation error:

Running OpenGL 4.6 on: GeForce GTX 860M/PCIe/SSE2
NVRTC Compilation failed.
C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1/include/cuda.h(53): catastrophic error: cannot open source file "stdlib.h"

1 catastrophic error detected in the compilation of "C:\Users\Ryper\Ryper_Prog\OptiXPathTracer/include//pathTracing.cu".

My friend said to me, that I should not use NVRTC, I should disable it. But when I disable it and I want to compile optix without it, I get the following error:

//CUDA_NVRTC_ENABLED FALSE

2>------ Build started: Project: sutil_sdk, Configuration: Debug x64 ------
2>Building NVCC ptx file lib/ptx/cuda_compile_ptx_generated_phong.cu.ptx
2>CMake Error at cuda_compile_ptx_generated_phong.cu.ptx.cmake:251 (message):
2>  Error generating C:/ProgramData/NVIDIA Corporation/OptiX SDK
2>  5.1.0/BUILD2/lib/ptx/cuda_compile_ptx_generated_phong.cu.ptx
2>
2>
2>C:\Program Files (x86)\Microsoft Visual Studio017\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1.
2>Done building project "sutil_sdk.vcxproj" -- FAILED.

I am using VS2017 64 bit for compilation, without this header everything works fine. Any tips?

NVRTC can only generate device code.
When using NVRTC to compile CUDA code to PTX for your OptiX application, it needs to be told all additional paths the source code includes from. You can specify these paths with the options string table you give to nvrtcCompileProgram().

I have been using NVRTC to generate OptiX programs at runtime. Some information about that can be found this GTC presentation on slides 16 and 17:
GTC 2017 - ID S7185 “Leveraging NVRTC Runtime Compilation for Dynamically Building OptiX Shaders from MDL Materials” you can search for here [url]http://on-demand-gtc.gputechconf.com/gtcnew/on-demand-gtc.php[/url]

I have not used cuRAND but implemented my own random number generators.
Maybe this old OptiX forum post about it could help:
[url]https://devtalk.nvidia.com/default/topic/759883/optix/random-number-streams/[/url]

Thank you very much for your answer.

I am added the include directories for stdlib, after it could include the directories, but because it is not device code i got the following errors:

OptiX Error: 'NVRTC Compilation failed.
C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/sal.h(708): warning: unrecognized #pragma

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/sal.h(1472): warning: unrecognized #pragma

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/vadefs.h(133): error: expected either a definition or a tag name

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/vadefs.h(133): error: type name is not allowed

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/vadefs.h(133): error: expected a ";"

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/vadefs.h(139): error: expected either a definition or a tag name

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/vadefs.h(139): error: type name is not allowed

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/vadefs.h(139): error: expected a ";"

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/vadefs.h(143): error: expected a ">"

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/vcruntime.h(81): error: this declaration has no storage class or type specifier

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.13.26128/include/vcruntime.h(81): error: identifier "push" is undefined.........

How can I solve this?

The link you provided about random number streams also uses curand.

Any tips?