Iska91

OpenCL inaccurate

Discussion created by Iska91 on Jan 12, 2010
Latest reply on Jan 14, 2010 by Iska91

Hey everyone,

I finally got OpenCL up and running so I started my first tests. I calculated Pi using the taylorserie of arctan(1) (= 1/4 Pi) but I got an error in the number calculated by the GPU while they are using the same code!
int main:
[code]
cout << setprecision(10) << setiosflags(ios::fixed) << setiosflags(ios::showpoint);

cout << "Calculating Pi using GPU (1024 serie)\n\n";

// Initialize Host application
if(initializeHost()==1)
return 1;

// Initialize OpenCL resources
if(initializeCL()==1)
return 1;

int iTime = 0;

iTime = runCLKernels();
// Run the CL program
if(iTime==1)
return 1;

float fPi = 0.0f;
for(cl_uint i = 0; i < width; i++)
{
 fPi += output[ i ];
}

cout << "Pi is :" << fPi*4.0f << "\n";
cout << "Time total :" << iTime << "\n\n\n";
system("pause");

// Releases OpenCL resources
if(cleanupCL()==1)
return 1;

// Release host resources
cleanupHost();

cout << "Calculating Pi using CPU (1024 serie)\n\n";

iStart = GetTickCount();

fPi = 0.0f;
int iCount = 0;
int iTotal = 256 * 10000;
while (iCount < iTotal)
{
fPi += pow(-1.0, iCount) / (2 * iCount + 1);

iCount++;
}

iEnd = GetTickCount();

cout << "Pi is :" << fPi*4.0f << "\n";
cout << "Time total :" << iEnd - iStart << "\n";

system("pause");

return 0;
[/code]

Kernel
[code]
 __kernel void MainKernel(__global float * output)
{
uint xid = get_global_id(0);

uint iCount = xid * 10000;
float fTemp = 0.0f;
while (iCount < (xid * 10000 + 10000))
{
fTemp += pow((-1), iCount) / (2 * iCount + 1);

iCount++;
}
output[xid] = fTemp;
}
[/code]

Output:
[code]
Calculating Pi using GPU (1024 serie)

Pi is: 3.1415958405
Time total: 62

 

Calculating Pi using CPU (1024 serie)

Pi is: 3.1415963173
Time total: 406
[/code]

Does anyone know what causes this error? It becomes bigger using when I make the serie longer.

 

Regards,
Iska



Outcomes