Exception when calling createProgramFromPTXString on host

Hi! I recently started learning OptiX and I was trying to use a callable program as a way to sample a simple procedural texture, starting with a constant one, but I’m getting an exception when calling createProgramFromPTXString on host:

optix::Program textProg = g_context->createProgramFromPTXString(embedded_constant_texture_programs, "sample_texture");

My whole .CU file for the callable program is:

#define RT_USE_TEMPLATED_RTCALLABLEPROGRAM 1
#include <optix_world.h>

rtDeclareVariable(float3, color, , );

RT_CALLABLE_PROGRAM float3 sample_texture(float u, float v, float3 p) {
    return color;
}

And according to the debugger:

Exception thrown at 0x00007FFDC8CBA388 in OptiX-Path-Tracer.exe: Microsoft C++ exception: prodlib::InvalidSource at memory location 0x000000BA254FE670.
Exception thrown at 0x00007FFDC8CBA388 in OptiX-Path-Tracer.exe: Microsoft C++ exception: optix::Exception at memory location 0x000000BA254FEBD0.

I’m still a bit confused at how callable programs actually work, even after reading through the documentation and examples, so I don’t know if I’m missing something on that front. I didn’t get any warnings or compiler errors.

Not sure if it’s relevant, but I’m compiling on a Windows 10 machine, with MSVC 2017, CUDA SKD 10 and Optix 5.1. My GPU would be a Geforce 1060 6Gb.

That might actually be the culprit.
Please have a look inside the OptiX release notes for the supported CUDA toolkit versions before setting up a development environment for OptiX.

OptiX 5.1.x versions have been built with CUDA 9.0 and that toolkit and MSVS 2015 are the recommended compilers under Windows.
Which host compiler is supported by which CUDA toolkit version can be found inside the CUDA documentation files named CUDA_Installation_Guide_.pdf.

There are ways to use CUDA 9.2 under MSVS 2017 as well, but there are same intricate version dependencies. Follow the links in this post for more information: https://devtalk.nvidia.com/default/topic/1042255/?comment=5288342

Note that you must set the –relocatable-device-code=true or -rdc NVCC compiler option when compiling OptiX CUDA shaders with RT_CALLABLE_PROGRAMs inside starting with CUDA 8.0 because it does more aggressive dead code elimination and the callable programs are functions with no actual call inside the PTX code and will get removed.
Also do not compile to PTX code with NVCC debug settings (-G, -g). The generated code is not correctly parsed by OptiX.

Thank you! The --relocatable-device-code flag solved my issue. I know it’s more of a Cuda thing rather than OptiX, but wouldn’t it be a good idea to mention that the flag is needed in the callable programs sections of the documentation & programming guide? I went through both but I couldn’t find anything related to said flag.