Hi developers, I’m a newbie in OptiX and have a simple question.
I implemented simple virtual functions in a class, then derive it from another class like codes below.
It perfectly works in pure CUDA code (specifically, the simplePrintf example in official CUDA examples), but does not work in OptiX code (the optixPathTracer example) with the error:
Caught exception: OPTIX_ERROR_INVALID_PTX: Optix call 'optixModuleCreateFromPTX( state.context, &module_compile_options, &state.pipeline_compile_options, ptx.c_str(), ptx.size(), log, &sizeof_log, &state.ptx_module )' failed: /home/hchoi/NVIDIA-OptiX-SDK-7.0.0-linux64/SDK/optixPathTracer/optixPathTracer.cpp:700) Log: COMPILE ERROR: Invalid PTX input: ptx2llvm-module-001: error: Failed to translate PTX input to LLVM Virtual function calls are not supported in class "Base" (vtable symbol name: "_ZTV4Base"). Virtual function calls are not supported in class "Derived" (vtable symbol name: "_ZTV7Derived").
[optixPathTracer.cu]
class Base {
public:
__device__ virtual ~Base() {}
__device__
virtual void func() {
printf("Base: %d\n", a);
}
protected:
int a = 10;
};
class Derived : public Base {
public:
__device__ virtual ~Derived() {}
__device__
void func() {
a = 20;
printf("Derived: %d\n", a);
}
};
extern "C" __global__ void __raygen__rg()
{
Base b;
b.func();
Derived d;
d.func();
Base* b2 = &d;
b2->func();
}
I just wonder whether it is not supported in OptiX because there is no mention of the virtual function in documents.
Thank you