SQRT problem? I guess...


I’m runing the GeForce 8700M GT on an ASUS G2 machine and I’ve got the following code, wich has to calculate a distance between two points (please ignore the sphere thing):

global void calculate(int numvertices, Vertex *vertex, Sphere *vectSpheres){

int i = blockIdx.x * blockDim.x + threadIdx.x;

	vectSpheres[i].position = vertiex[i].position;//ignore this
	vectSpheres[i].radius = distance(vertex[i].faces[0].position1, vertex[i].faces[0].position2);


AND the function “distance” goes like this:

device float distance(float3 ponit1, float3 point2){

float xtemp,ytemp,ztemp,dist;

xtemp=(point1.x - point2.x);
ytemp=(point1.y - point2.y);
ztemp=(point1.z - ponit2.z);


dist = sqrtf((xtemp+ytemp+ztemp)); --> THE PROBLEM IS HERE!!!

return dist; --> I CAN'T DO THIS ?


this code gives me that advisory thing… and if i run it, gives me the driver problem with flashing screen…

I’ve tested by comenting the “return dist” and replaced it by “return 7”; and all worked fine; So I think the problem will be at the sqrt call…

Please can someone help me, I’ll be very greatful.

Thanks in advance.

What do you mean by “advisory thing”?

If I leave the “return dist” call when I rebuild it I get this line “Advisory: Cannot tell what pointer points to, assuming global memory space” 6 times in the compiler…

Not really an answer to your specific problem but the file cutil_math.h already has defined many vector operations, such a inline host device float length(float2,3,4 v).

Thanks for your reply!!!

But the problem is that I realy need this function!I need to calculate the distance between two points in order to calculate the circum center of a triangle; But I got stuck in this function, the problem, I think is in return call or on the sqrtf call; But with warnings displayed on the compiler, I fear the problem is the memory on the device…

I’m out of ideas.Please Someone Help.

I dont’ think the advisory has anything to do with calling sqrtf. If you comment out “return dist” the dead code optimizer will optimize out the entire call to distance and the pointers in “vertex[i].faces[0].position1, vertex[i].faces[0].position2” will not be dereferenced. I’m guessing that the problem comes in the faces[0] part of the data structure. You could test this by putting “float3 pos1 = vertex[i].faces[0].position1” and then passing pos1 to distance: you should then get the advisory on a different line.

If the faces pointer does indeed point to global memory, then you should be fine and can ignore the advisory. However, I would suggest rearranging your data structures. Instead of an array of structures, use a structure of arrays containing float4’s. 1) This alleviates pointer headaches such as you are encountering and 2) You get memory coalescing which will boost memory performance by a factor of 10 or more.