Multidimensional __constant__ arrays

Hello,

I was wondering if multidimensional __constant__ arrays (similar like below) would be possible in CUDA and OptiX:

__constant__ float3 samples[][] =
{
	{ {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
	{ {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
	{ {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
	{ {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
	{ {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} }
};

So basically an array containing 5 arrays of 3 float3 vectors. That mentioned syntax however, fails with

error : an array may not have elements of this type

So, I’m not sure if it’s a matter of syntax or if it’s not possible in general.

Thank you and kind regards,

Markus

This doesn’t look like valid C++ code to me:

float3 samples[][] =
{
	{ {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
	{ {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
	{ {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
	{ {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
	{ {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} }
};

Even if I provide a sensible definition for float3, I’m unable to get that to compile with g++. And the error returned by g++ seems instructive to me.

If it were me, I would first attempt to get such a thing to work with an ordinary C++ compiler. This compiles cleanly for me with nvcc (CUDA 12.0, g++ 7.3.1):

__constant__ float3 csamples[][3] =
{
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} }
};

float3 samples[][3] =
{
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} }
};

int main(){

}

I don’t know much about Optix. But there is a forum where you can ask Optix questions.

Hello,

this:

__constant__ float3 csamples[][3] =
{
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} },
        { {-1.f, -1.f, -1.f}, {0.f, 0.f, 0.f}, {1.f, 1.f, 1.f} }
};

actually solved my problem, thank you. I actually tried to fill the brackets before but ended up with errors. It’s working now, though, so I guess I might have been hunting ghosts.

Thank you!

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