Loading callable program from file fails with RT_INVALID_SOURCE

Hi there, I’m trying to use callable programs to implement light sources in my renderer. I have a simple dome light implementation in light_infinite_area.cu:

#include "lights.h"
#include "raydata.h"

using namespace optix;

RT_CALLABLE_PROGRAM LightSample light_sample(const float3 p, const Onb onb, 
                                             const float u1, const float u2) {
    LightSample ls;
    float3 omega_l;
    cosine_sample_hemisphere(u1, u2, omega_l);
    ls.omega_i = normalize(omega_l.z * onb.m_normal + 
                           omega_l.x * onb.m_tangent + 
                           omega_l.y * onb.m_binormal);
    ls.L_i = make_float3(1.0f);
    ls.pdf = 1.0f;
    return ls;
}

It all compiles fine, along with the rest of my cuda that also depends on the lights.h and raydata.h headers, but when I try to load it with

RTprogram prg;
RTresult res = rtProgramCreateFromPTXFile(_ctx, "light_infinite_area.ptx", "light_sample", &prg);

the result is RT_INVALID_SOURCE. The API docs don’t mention what this return code means exactly, and I can’t see anything immediately wrong with my code from comparing it to the callable example program.

I’m using OptiX 4.0.2 on OS X 10.11.6

Cheers,
Anders

Which CUDA Toolkit did you use to compile the PTX?

If this was with CUDA 8.0, that behaves more aggressive with respect to dead code elimination on function level than previous CUDA compilers. Callable programs are real functions and if the compiler doesn’t find a call to these in the code, it assumes it’s not used and doesn’t generate code for this function.

To solve that you need to force code generation for callable programs when using CUDA 8.0. Please try adding the command line option “–relocatable-device-code=true” to your nvcc options and compare the PTX results before and after.

For example, this is what my nvcc options look like in a CMakeLists.txt for an OptiX 4.0.2 project using CUDA 8.0:

NVCC_OPTIONS "--gpu-architecture=compute_30" "--use_fast_math" "--relocatable-device-code=true" "-I${OPTIX_INCLUDE_DIR}" "-I${CMAKE_CURRENT_SOURCE_DIR}/shaders"

Hi Detlef, that was indeed the cause, and the solution. Thank you!