RT_CALLABLE_PROGRAM not found in PTX

Using the cmake files attached to Ingo Wald’s Raytracing In a Weekend repo,
I’ve been on to later chapters in the series.

When attempting textures, I have them represented as calling ProgramIDs in the materials

typedef rtCallableProgramId<float3(float, float, float3, int)> TextureFunction;

When compiling against sm_30. The Texture functions are not found in the ptx (there is no visible function).

terminate called after throwing an instance of ‘optix::Exception’
what(): Parse error (Details: Function “RTresult _rtProgramCreateFromPTXString(RTcontext, const char*, const char*, RTprogram_api**)” caught exception: Function ‘sampleTexture’ not found in PTX)
Aborted (core dumped)

Any documentation printed claims that an RT_CALLABLE_PROGRAM in a stand-alone cuda file should not be compiled away in >sm_20. So, I wouldn’t have expected a problem in sm_30.

Well, the other solution is to create a dummy global function that calls the RT_CALLABLE_FUNCTION in the body of the cu file.

#include <optix.h>

rtDeclareVariable(float3, color, , );

RT_CALLABLE_PROGRAM float3 sampleTexture(float u, float v, float3 p, int i)
{
    return color;
}

rtDeclareVariable(float3, stub_constant_texture_return, , );
__global__ void stub_constant_texture_sample_texture()
{
    stub_constant_texture_return = sampleTexture(0.0f, 0.0f, make_float3(0.0f, 0.0f, 0.0f), 0);
}

Which, it no longer throws an error because the RT_CALLABLE_PROGRAM is maintained.

However, on further inspection, the code is behaving as if the inputs are always zeros.
And on even further inspection, the code is behaving as if the inputs are constants set by the dummy global function.

My educated opinion is that the compiler is optimizing with the assumption that all inputs are constants set by the dummy global function.
This is not what I want. I just want any RT_CALLABLE_FUNCTIONs in stand alone cu files to exist post compilation.
I don’t even WANT the dummy global, but I’m out of ideas at this point.

Please have a look at this thread and check your nvcc compiler options.
https://devtalk.nvidia.com/default/topic/1000376/optix/loading-callable-program-from-file-fails-with-rt_invalid_source/post/5111537/#5111537

Here is a related thread with compiler options for NVRTC instead of NVCC.
https://devtalk.nvidia.com/default/topic/1047572/optix/optix-compile-error-in-ptxstring/post/5316118/#5316118

Needed RDC

"--relocatable-device-code=true"

Thank you. But, I’m afraid I figured it out just before seeing this.