Unable to debug my code

From now i cannot run my code and it’s debugging don’t give me enough information to contiune my development.

Can you reproduce that printf(“ok”) don’t show anithing when uncomment access to sphereColor data?

global void RayTracing_Image(long countPerThread, long long count, double t0, long* pixels, long width, long height, long sphereCount, double* xSphere, double* ySphere, double* zSphere, double* sphereRadius, long* sphereColor, double lx, double ly, double lz, double PI)
{
long threadIdx_ = threadIdx.x;
for (long i = 0; i < countPerThread; i++)
{
long long idx = threadIdx_ * countPerThread + i;
if (idx >= count) break;
double
x = ((long)idx % width - width / 2) / ((double)height / 2),
y = -((long)idx / width - height / 2) / ((double)height / 2),
z = 1;

	double ox = 0, oy = 0, oz = 0;
	double nx = 0, ny = 0, nz = 0;
	long r = 0, g = 0, b = 0;
	long reflectionCount = 0;
	while (true)
	{
		double _distance = (double)(1 << 20);
		long sphereIndex = -1;
		for (long j = 0; j < sphereCount; j++)
		{
			double distance = intersect(ox, oy, oz, x, y, z, xSphere[j], ySphere[j], zSphere[j], sphereRadius[j], PI);
			if (distance != -1 && distance < _distance)
			{
				sphereIndex = j;
				_distance = distance;
			}
		}
		if (sphereIndex != -1)
		{
			normalize(x, y, z, &x, &y, &z);
			ox += x * _distance;
			oy += y * _distance;
			oz += z * _distance;
			printf("ok");
			/*r += (sphereColor[sphereIndex] & (255 << 16)) >> 16;
			g += (sphereColor[sphereIndex] & (255 << 8)) >> 8;
			b += (sphereColor[sphereIndex] & 255);*/

			intersectionNormalDirection(ox, oy, oz, xSphere[sphereIndex], ySphere[sphereIndex], zSphere[sphereIndex], &nx, &ny, &nz);
			reflectRay(x, y, z, nx, ny, nz, &x, &y, &z);
			reflectionCount++;
		}
		else
		{
			if (reflectionCount > 0)
			{
				double luminosity = luminosityFactor(nx, ny, nz, lx, ly, lz, PI);
				/*	r = (long)(r * luminosity / reflectionCount);
					g = (long)(g * luminosity / reflectionCount);
					b = (long)(b * luminosity / reflectionCount);*/
				pixels[idx] = 255 << 24 | (long)r << 16 | (long)g << 8 | (long)b;
			}
			else pixels[idx] = 255 << 24;
			break;
		}
	}
}

}

However, that run correctly :

global void RayTracing_Image(long countPerThread, long long count, double t0, long* pixels, long width, long height, long sphereCount, double* xSphere, double* ySphere, double* zSphere, double* sphereRadius, long* sphereColor, double lx, double ly, double lz, double PI)
{
long threadIdx_ = threadIdx.x;
for (long i = 0; i < countPerThread; i++)
{
long long idx = threadIdx_ * countPerThread + i;
if (idx >= count) break;
double
x = ((long)idx % width - width / 2) / ((double)height / 2),
y = -((long)idx / width - height / 2) / ((double)height / 2),
z = 1;

	double ox = 0, oy = 0, oz = 0;
	double nx = 0, ny = 0, nz = 0;
	long r = 0, g = 0, b = 0;
	double _distance = (double)(1 << 20);
	long sphereIndex = -1;
	for (long j = 0; j < sphereCount; j++)
	{
		double distance = intersect(ox, oy, oz, x, y, z, xSphere[j], ySphere[j], zSphere[j], sphereRadius[j], PI);
		if (distance != -1 && distance < _distance)
		{
			sphereIndex = j;
			_distance = distance;
		}
	}
	if (sphereIndex != -1)
	{
		normalize(x, y, z, &x, &y, &z);
		ox += x * _distance;
		oy += y * _distance;
		oz += z * _distance;

		r += (sphereColor[sphereIndex] & (255 << 16)) >> 16;
		g += (sphereColor[sphereIndex] & (255 << 8)) >> 8;
		b += (sphereColor[sphereIndex] & 255);

		intersectionNormalDirection(ox, oy, oz, xSphere[sphereIndex], ySphere[sphereIndex], zSphere[sphereIndex], &nx, &ny, &nz);
		reflectRay(x, y, z, nx, ny, nz, &x, &y, &z);

		double luminosity = luminosityFactor(nx, ny, nz, lx, ly, lz, PI);
		r = (long)(r * luminosity);
		g = (long)(g * luminosity);
		b = (long)(b * luminosity);
		pixels[idx] = 255 << 24 | (long)r << 16 | (long)g << 8 | (long)b;
	}
	else pixels[idx] = 255 << 24;
}

}

Here it’s don’t work when uncommenting ‘else’ on the middle. From C# on GPU it can run. Do i commit a C++/Cuda error ? Can’t we use Cuda like that?

global void RayTracing_Image(long countPerThread, long long count, double t0, long* pixels, long width, long height, long sphereCount, double* xSphere, double* ySphere, double* zSphere, double* sphereRadius, long* sphereColor, double lx, double ly, double lz, double PI)
{
printf(“ok”);
for (long i = 0; i < countPerThread; i++)
{
long long idx = threadIdx.x * countPerThread + i;
if (idx >= count) break;
double
x = ((long)idx % width - width / 2) / ((double)height / 2),
y = -((long)idx / width - height / 2) / ((double)height / 2),
z = 12;

	double ox = 0, oy = 0, oz = 0;
	double px = 0, py = 0, pz = 0;
	double nx = 0, ny = 0, nz = 0;
	long r = 0, g = 0, b = 0;
	long reflectionCount = 10;
	bool shadowed = false;
	long lastSphereIndex = -1;
	while (true)
	{
		RayTracing_Normalize(x, y, z, &x, &y, &z);
		double _distance = (double)(1 << 20);
		long sphereIndex = -1;
		for (long j = 0; j < sphereCount; j++)
		{
			if (j == lastSphereIndex)
				continue;
			double distance = RayTracing_Intersect(ox, oy, oz, x, y, z, xSphere[j], ySphere[j], zSphere[j], sphereRadius[j]);
			if (distance != -1 && distance < _distance)
			{
				sphereIndex = j;
				_distance = distance;
			}
		}
		lastSphereIndex = sphereIndex;

		if (sphereIndex != -1)
		{
			ox += x * _distance;
			oy += y * _distance;
			oz += z * _distance;

			r += (sphereColor[sphereIndex] & (255 << 16)) >> 16;
			g += (sphereColor[sphereIndex] & (255 << 8)) >> 8;
			b += (sphereColor[sphereIndex] & 255);

			RayTracing_RayTracing_IntersectionNormal(ox, oy, oz, xSphere[sphereIndex], ySphere[sphereIndex], zSphere[sphereIndex], &nx, &ny, &nz);

			if (reflectionCount == 0)
			{
				px = ox;
				py = oy;
				pz = oz;
			}
			RayTracing_ReflectRay(x, y, z, nx, ny, nz, &x, &y, &z);
			reflectionCount++;
		}
		//else
		{
			if (reflectionCount > 0)
			{
				for (long j = 0; j < sphereCount; j++)
				{
					if (RayTracing_Intersect(px, py, pz, -lx, -ly, -lz, xSphere[j], ySphere[j], zSphere[j], sphereRadius[j]) != -1)
					{
						shadowed = true;
						break;
					}
				}
				if (shadowed)
					reflectionCount *= 2;

				double luminosity = RayTracing_LuminosityFactor(nx, ny, nz, lx, ly, lz, PI);
				r = (long)(r * luminosity / reflectionCount);
				g = (long)(g * luminosity / reflectionCount);
				b = (long)(b * luminosity / reflectionCount);
				pixels[idx] = 255 << 24 | (long)r << 16 | (long)g << 8 | (long)b;
			}
			else
				pixels[idx] = 255 << 24;
			break;
		}
	}
}

}

For this i can not use my usual 768 threads.

Using these following functions in some device functions, with 512 thread it’s slower than with 8 CPU cores: abs, sqrt, atan2, sin, asin, cos, max.

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