Optix 6.5 error

I got this error:
{m_message=“Variable not found (Details: Function "_rtContextValidate"
caught exception: Variable "Unresolved reference to variable ExternalTrace from _Z11SceneLaunchv" not found in scope)” …} optix::Exception &

the computational details are:

Cuda compilation tools, release 7.0, V7.0.27
// Based on LLVM 3.4svn
//

.version 4.2
.target sm_30
.address_size 64

I’m using optix 6.5 and cuda 7.0.
how to solve it?
is it possible that something wrong in the ptx definition written in bold ?

Hi asaf.eilam,

hm, the PTX file is basically empty, it only includes the header.
This isn’t output from the MDL SDK, is it?
Where is this file coming from and which variable are you trying to access, where the exception is happening?

Best regards
Moritz

these are only the first few lines from the ptx.
the ptx include more lines of course.
I also found the variable “_Z11SceneLaunchv” in the ptx in the next line :

// .globl	_Z11SceneLaunchv

.visible .entry _Z11SceneLaunchv(

)

according to the error message, it relates to the callable program that I have "ExternalTrace ".

So your CUDA file containing the function SceneLaunch contains an “rtCallableProgram” line for “ExternalTrace”?
So the error message sounds like you didn’t assign an actual “Program” object to variable in your host code.

If you have a look at the “optixCallablePrograms” example in the OptiX SDK 6.5.0, you can find such an assignment of a callable program variable “shade_normal” in the “createScene()” function in optixCallablePrograms.cpp:

  ptx = sutil::getPtxString( SAMPLE_NAME, "optixCallablePrograms.cu" );
  Program closest_hit_prog = context->createProgramFromPTXString( ptx, "closest_hit_radiance" );
  Program shade_prog       = context->createProgramFromPTXString( ptx, "shade_from_normal" );
  Material material = context->createMaterial();
  material->setClosestHitProgram( 0, closest_hit_prog );
  material[ "shade_normal" ]->set( shade_prog );

Hope that helps
Moritz

the script that I’m trying to run, worked well when I compiled it with optix 3.9.1.
it is probably related to this as well.

would be happy to have your opinion.

Did you check, whether you assigned a program to the variable “shade_normal” in your cpp code?
Because the error message implies, you didn’t assign it.

I have never worked with OptiX 3.*, but I would expect, that a lot has changed since then.
As Detlef already did, I would also recommend to have a look at OptiX 6.5 Programming Guide as well as the examples delivered with the SDK.

I compile the solution, however the ptx does not include the callable functions in the *.cu file.
I’m using cuda 9.2 with optix 6.5, sm 30.

what to do ?

Please have a look at the optixCallablePrograms example of OptiX SDK 6.5.0 and try to find out, what the example does differently than you do.
In optixCallablePrograms.cu, the function to be used as callable program is declared as RT_CALLABLE_PROGRAM. With this, the function appears in the .ptx file with a mangled name as _Z17shade_from_normal6float3. Do you also use RT_CALLABLE_PROGRAM for your callable program?

If this doesn’t solve your problem, it might help, if you provided some more concrete source snippets, like the declaration of the function to be used as callable program and the declaration of the callable program variable (rtCallableProgram), as well as the code around assignment of the callable program variable in your .cpp part. Currently, I’m just guessing what could be the cause of the problem ;)

there is something that I missed with the definitions.
every callable program should be declared with :
" rtDeclareVariable(rtCallableProgram<bool (const float3& , const char )>, funcname); " ?
my callable program is :

"RT_CALLABLE_PROGRAM bool funcname( const float3& vCoord, const char cInternalReflectionsCount )
{

if ( m_bResetRequired )	
{
	m_buffRayPath[make_uint3( vLaunchIndex.x, vLaunchIndex.y, 2u * cInternalReflectionsCount )] = make_float4( vCoord.x, vCoord.y, vCoord.z, 1.f );
}
return true;

}
"

this is its only appearance in the code accept the call to it from ptx.

I went over the example in optix 6.5 and didn’t see anything wrong in my definitions

No, you don’t declare the callable programs like that, but the callable program variables, which you want to call. I would also recommend using a different name (e.g. “func_var”) for the variable than for the function you want to assign to the variable. Don’t know, if this may cause problems, if the names clash.

The example uses const float3 without the reference, I don’t know, whether references are allowed. Maybe worth a try providing the vCoord by value instead, if everything else fails.

In your .cpp code, you should assign the program for funcname to the OptiX variable func_var in the scope depending on your requirements (see https://raytracing-docs.nvidia.com/optix6/guide_6_5/index.html#programs#program-variable-scoping). For example, for a closest hit program, you could set the variable in the Material object like shown for the callable program variable “shader_normal” and the callable program “shade_from_normal” above (Optix 6.5 error - #4 by mkroll).

If you are already doing this and still getting the “Variable “Unresolved reference to variable ExternalTrace from _Z11SceneLaunchv” not found in scope” error, please show me the code, where you assign the callable program variable “ExternalTrace” which you declared with rtDeclareVariable.

Moved topic to the OptiX forum.

I compile the solution, however the ptx does not include the callable functions in the *.cu file. I’m using cuda 9.2 with optix 6.5, sm 30.

Please note that since CUDA 8.0 there are more dead code elimination techniques inside the CUDA compiler which required changes to the NVCC command line options to keep OptiX callable programs inside the generated PTX code although there is no call to them in the same module.

You either need to add --keep-device-functions or --relocatable-device-code=true to your NVCC command line to prevent that dead code elimination…
https://forums.developer.nvidia.com/t/module-creation-not-identifying-my-direct-callable-functions/157711/2

when doing this change ( –relocatable-device-code=true) I got a compilation error :
Error 2 error : Label expected for argument 0 of instruction ‘call’
what to do?

what to do?

Provide the input code which fails compilation.

When does that compilation error happen? When translating the *.cu file to *.ptx with NVCC or when loading the *.ptx file into OptiX?

Was that with CUDA 9.2 and OptiX 6.5.0?
Have you tried using a different CUDA version like 9.0 or 10.x? I have skipped CUDA 9.2 completely.

you suggest to use cuda 10.x ?

I would always recommend using the CUDA version which with a specific OptiX version was built.
For OptiX 6.5.0 that would be CUDA 10.1 according to the OptiX 6.5.0 Release Notes.

The CUDA toolkit in turn documents to which Microsoft Visual Studio versions it’s compatible.
Since even CUDA 10.2 lists all MSVS versions from 2012 to 2019, there shouldn’t be a problem.

Of course I cannot say if that helps in any way with the information you provided so far.