Syntax error compiling optixTrace call with arithmetic expression as parameter

I have the following example device code using Optix 7.4 and CUDA 11.5

#define NORMAL RAY 0
#define NORMAL_RAY_MISS 0
#define NUM_RAY_TYPES 2
extern "C" __global__ void __miss_bad() {
    float3 ourRayOrigin;
    float3 reflectionDirection;
    unsigned int newDepth;
    unsigned int p0;
    unsigned int p1;
    unsigned int p2;
    optixTrace(params.handle, ourRayOrigin, reflectionDirection, 0.01, 100.0f, 0.0f, OptixVisibilityMask(255), OPTIX_RAY_FLAG_NONE, NORMAL_RAY, NUM_RAY_TYPES, NORMAL_RAY_MISS, newDepth, p0, p1,
                    p2);
}

This compiles without problems

If I change it to

extern "C" __global__ void __miss_bad() {
    float3 ourRayOrigin;
    float3 reflectionDirection;
    unsigned int newDepth;
    unsigned int p0;
    unsigned int p1;
    unsigned int p2;
    optixTrace(params.handle, ourRayOrigin, reflectionDirection, 0.01, 100.0f, 0.0f, OptixVisibilityMask(255), OPTIX_RAY_FLAG_NONE, NORMAL_RAY, NUM_RAY_TYPES, NORMAL_RAY_MISS, newDepth + 1u, p0, p1,
                    p2);
}

then I get a compilation syntax error from nvcc

nvcc -g -lineinfo --use_fast_math -rdc=true -allow-unsupported-compiler --ptx -O3 --extra-device-vectorization -c --std c++17 -m64 -arch compute_86 -code sm_86 -I/usr/include/optix -I./include -I./sysInclude -I/usr/local/cuda-11.0/targets/x86_64-linux/include -o obj/Optix.ptx src/Optix.cu
src/Optix.cu(625): warning #549-D: variable "newDepth" is used before its value is set

src/Optix.cu(625): error: no instance of overloaded function "optixTrace" matches the argument list
            argument types are: (OptixTraversableHandle, float3, float3, double, float, float, OptixVisibilityMask, OptixRayFlags, int, int, int, unsigned int, unsigned int, unsigned int, unsigned int)

1 error detected in the compilation of "src/Optix.cu".

I realize the compiler has to generate a temporary to evaluate newDepth + 1u, but I think that temporary is also of type unsigned int.

Maybe there’s a problem with passing temporaries as parameters by reference to optixTrace (using & in function definition), but I’m used to seeing the error message indicate the pass by reference by including the ‘&’ in the parameter in the error message, which is not the case here.

If I change the expression to ‘newDepth + 1’, I get the same error.

If it works when actually doing the right thing like
unsigned int newDepth = optixGetPayload_0() + 1u;
and using that newDepth as payload argument, then I wouldn’t waste any thoughts on this.

Also please have a look at the function signature inside the error message. There are no double arguments inside the optixTrace call and the SBT offsets and strides are unsigned int, not int, so the code could be a little more precise.

I have not tried using -g, --extra-device-vectorization or c++17 for the PTX translation and can’t check if that makes a difference until next year.

I tried removing the compiler options myself and the error message did not go away. I brought this up in the case there was a minor bug here.

Maybe this has to do with my use of Fedora’ 35’s supplied gcc 11.2.1 and therefore the -allow-unsupported-compiler option.

So I’ll consider this resolved.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.