Very serious compiler bug

The following code will always return the first item in the colors array

void Func(float3& color)
{
for(int i=0; i<count; i++)
{
if( Foo(…) )
{
color = colors[i];
}
}
}

However this one works.

void Func(float3& color)
{
for(int i=0; i<count; i++)
{
float3 newColor = colors[i];
if( Foo(…) )
{
color = newColor;
}
}
}

How can I trust the cuda compiler with this kinds of errors?

Is it a device function? Otherwise you should blame your host compiler.

Can you provide a complete code example that reproduces this error?

No I can not. When I try to strip away all unnecessary code I get a “unspecified launch error”. Supposedly that happens when you’re writing uninitialized variable to memory (should that be an error?) so I’ve made sure all variables are initialized before use. Unce I get that error the driver seems to be in an incorrect state and every graphics application will get a flickering noise in the screen.

Here is the function causing all the trouble.

device bool Trace(float3 pos, float3 dir, float3& normal, float3& color, float3& hitPoint)

{

bool hitAnything = false;

float dist = 50.0;

float3 hitCenter = make_float3(0.0f, 0.0f, 0.0f);



const int sphereCount = 4;

float4 spheres[sphereCount];

float3 colors[sphereCount];

spheres[0] = make_float4(0.0f, 0.0f, -10.0f, 10.0f);

colors[0] = make_float3(1.0f, 0.0f, 1.0f);

spheres[1] = make_float4(-2.0f, -2.0f, 1.0f, 1.0f);

colors[1] = make_float3(1.0f, 0.0f, 0.0f);

spheres[2] = make_float4(2.0f, -2.0f, 1.0f, 1.0f);

colors[2] = make_float3(0.0f, 1.0f, 0.0f);

spheres[3] = make_float4(-2.0f, 2.0f, 1.0f, 1.0f);

colors[3] = make_float3(0.0f, 0.0f, 1.0f);

color = make_float3(0.5f, 0.5f, 1.0f);

for(int i=0; i<sphereCount; i++)

{

	float4 sphere = spheres[i];

	if( RaySphere( pos, dir, make_float3(sphere.x, sphere.y, sphere.z), sphere.w, dist) )

	{

		//Found hit

		hitCenter = make_float3(sphere.x, sphere.y, sphere.z);

		color = colors[i];

		hitAnything = true;

	}

}

hitPoint = pos + dir*dist;

normal = normalize( hitPoint - hitCenter );

return hitAnything;

}

The calling code should be ok. I’ve used it to call a much more complex trace function without any problem. I just needed a simple and fast Trace function so I could experiment with different MLT strategies when I ran into these problems.

By just adding float3 newColor = colors[i]; before the branch and exchange colors[i] against newColor both problems disapear. Doesn’t feel very stable to me.

declaring the loop variable i as volatile also removes the problems.

bump

Is it possible to get an answer on this? Have you been able to reproduce it?

Can you post a self-contained code sample which reproduces the bug? Your last post indicated you get an “unspecified launch error” when stripping away incidental code. These errors are not due to uninitialized variable access. They usually indicate a write to a bad pointer; that is, a programming error.