printf is very twitchy in CUDA dll

Hi there,

We have an application which consists of a C# GUI and an unmanaged dll containing the CUDA code. I have been experimenting with the printf statement for compute 2.0 capable cards and it works some of the time, but mostly not.

So I just wanted to know if printf is supported in kernels in dlls when said dll is used by a C# GUI in VS2008 (or something else for that matter)?

As an example, this code works in a kernel:

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

{

   // Calculate distance

   double3 tempCenter2 = (someDataStructure[i].center);

   float diffX2 = (float)(someDataStructure[i].center.x);

if(blockIdx.x == 0 && blockIdx.y == 0 && i > 0)

   {

      printf("Center @ %i (%3.3f, %3.3f, %3.3f)\t", i, tempCenter2.x, tempCenter2.y, tempCenter2.z);

      //printf("diffX2 : %6.2lf\t", diffX2);

      printf("\n");

   }

}

but this does not

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

{

   // Calculate distance

   double3 tempCenter2 = (someDataStructure[i].center);

   float diffX2 = (float)(someDataStructure[i].center.x);

if(blockIdx.x == 0 && blockIdx.y == 0 && i > 0)

   {

      printf("Center @ %i (%3.3f, %3.3f, %3.3f)\t", i, tempCenter2.x, tempCenter2.y, tempCenter2.z);

      printf("diffX2 : %6.2lf\t", diffX2);

      printf("\n");

   }

}

Any advice is welcome.

Thanks,

Claus

[font=“Courier New”]diffX2[/font] is a float, but the format specifies a double, so cast it to that before printing:

printf("diffX2 : %6.2lf\t", (double)diffX2);

That makes no difference what so ever. I have tried %f, %6.2f, and the %6.2lf and none of them worked.
I’ve also tried changing the buffer from 1 to 10 and then to 100 MB just to make sure that there was enough room in it.
But thanks for the suggestion tera.