fix crash in Test_BitonicSort

This commit is contained in:
erwincoumans 2013-04-30 12:40:55 -07:00
parent 86a3cb5d2e
commit bf7a779562

View File

@ -69,82 +69,85 @@ int main(int argc, char* argv[])
cl_context context = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum); cl_context context = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
int numDevices = b3OpenCLUtils::getNumDevices(context); if (context)
printf("Num Devices = %d\n", numDevices);
for (int j=0;j<numDevices;j++)
{ {
cl_device_id dev = b3OpenCLUtils::getDevice(context,j); int numDevices = b3OpenCLUtils::getNumDevices(context);
b3OpenCLDeviceInfo devInfo; printf("Num Devices = %d\n", numDevices);
b3OpenCLUtils::getDeviceInfo(dev,&devInfo); for (int j=0;j<numDevices;j++)
printf("m_deviceName = %s\n",devInfo.m_deviceName);
//b3OpenCLUtils::printDeviceInfo(dev);
g_cqCommandQue = clCreateCommandQueue(context, dev, 0, &ciErrNum);
oclCHECKERROR(ciErrNum, CL_SUCCESS);
b3BitonicSortInfo info;
info.bitonicSortLocal = b3OpenCLUtils::compileCLKernelFromString(context,dev,kernelSource,"kBitonicSortCellIdLocal",&ciErrNum,0,"");
oclCHECKERROR(ciErrNum, CL_SUCCESS);
info.bitonicSortLocal1 = b3OpenCLUtils::compileCLKernelFromString(context,dev,kernelSource,"kBitonicSortCellIdLocal1",&ciErrNum,0,"");
oclCHECKERROR(ciErrNum, CL_SUCCESS);
info.bitonicSortMergeGlobal = b3OpenCLUtils::compileCLKernelFromString(context,dev,kernelSource,"kBitonicSortCellIdMergeGlobal",&ciErrNum,0,"");
oclCHECKERROR(ciErrNum, CL_SUCCESS);
info.bitonicSortMergeLocal = b3OpenCLUtils::compileCLKernelFromString(context,dev,kernelSource,"kBitonicSortCellIdMergeLocal",&ciErrNum,0,"");
oclCHECKERROR(ciErrNum, CL_SUCCESS);
info.m_cqCommandQue = g_cqCommandQue;
b3OpenCLArray<b3Int2> keyValuesGPU(context,g_cqCommandQue);
b3AlignedObjectArray<b3Int2> keyValuesCPU;
b3AlignedObjectArray<b3Int2> keyValuesGold;
int numValues = 8*1024*1024;//2048;//1024;
keyValuesCPU.resize(numValues);
for (int i=0;i<numValues;i++)
{ {
b3Int2 v; cl_device_id dev = b3OpenCLUtils::getDevice(context,j);
v.x = numValues+1-i; b3OpenCLDeviceInfo devInfo;
v.y = i*i; b3OpenCLUtils::getDeviceInfo(dev,&devInfo);
keyValuesCPU[i] = v; printf("m_deviceName = %s\n",devInfo.m_deviceName);
} //b3OpenCLUtils::printDeviceInfo(dev);
keyValuesGPU.copyFromHost(keyValuesCPU);
keyValuesGPU.copyToHost(keyValuesGold);
keyValuesGold.quickSort(compareFunc);
unsigned int batch = 1; g_cqCommandQue = clCreateCommandQueue(context, dev, 0, &ciErrNum);
unsigned int arrayLength = keyValuesGPU.size(); oclCHECKERROR(ciErrNum, CL_SUCCESS);
for (int i=0;i<10;i++) b3BitonicSortInfo info;
{
info.bitonicSortLocal = b3OpenCLUtils::compileCLKernelFromString(context,dev,kernelSource,"kBitonicSortCellIdLocal",&ciErrNum,0,"");
oclCHECKERROR(ciErrNum, CL_SUCCESS);
info.bitonicSortLocal1 = b3OpenCLUtils::compileCLKernelFromString(context,dev,kernelSource,"kBitonicSortCellIdLocal1",&ciErrNum,0,"");
oclCHECKERROR(ciErrNum, CL_SUCCESS);
info.bitonicSortMergeGlobal = b3OpenCLUtils::compileCLKernelFromString(context,dev,kernelSource,"kBitonicSortCellIdMergeGlobal",&ciErrNum,0,"");
oclCHECKERROR(ciErrNum, CL_SUCCESS);
info.bitonicSortMergeLocal = b3OpenCLUtils::compileCLKernelFromString(context,dev,kernelSource,"kBitonicSortCellIdMergeLocal",&ciErrNum,0,"");
oclCHECKERROR(ciErrNum, CL_SUCCESS);
info.m_cqCommandQue = g_cqCommandQue;
b3OpenCLArray<b3Int2> keyValuesGPU(context,g_cqCommandQue);
b3AlignedObjectArray<b3Int2> keyValuesCPU;
b3AlignedObjectArray<b3Int2> keyValuesGold;
int numValues = 8*1024*1024;//2048;//1024;
keyValuesCPU.resize(numValues);
for (int i=0;i<numValues;i++)
{
b3Int2 v;
v.x = numValues+1-i;
v.y = i*i;
keyValuesCPU[i] = v;
}
keyValuesGPU.copyFromHost(keyValuesCPU); keyValuesGPU.copyFromHost(keyValuesCPU);
clFinish(info.m_cqCommandQue); keyValuesGPU.copyToHost(keyValuesGold);
unsigned long pre=clock.getTimeMilliseconds(); keyValuesGold.quickSort(compareFunc);
bitonicSortNv(keyValuesGPU.getBufferCL(), arrayLength, info);
clFinish(info.m_cqCommandQue); unsigned int batch = 1;
unsigned long post=clock.getTimeMilliseconds(); unsigned int arrayLength = keyValuesGPU.size();
printf("GPU sort took %d ms\n",post-pre);
} for (int i=0;i<10;i++)
keyValuesGPU.copyToHost(keyValuesCPU); {
int success=1; keyValuesGPU.copyFromHost(keyValuesCPU);
for (int i=0;i<numValues;i++) clFinish(info.m_cqCommandQue);
{ unsigned long pre=clock.getTimeMilliseconds();
if (keyValuesCPU[i].x != keyValuesGold[i].x) bitonicSortNv(keyValuesGPU.getBufferCL(), arrayLength, info);
success = 0; clFinish(info.m_cqCommandQue);
if (keyValuesCPU[i].y != keyValuesGold[i].y) unsigned long post=clock.getTimeMilliseconds();
success = 0; printf("GPU sort took %d ms\n",post-pre);
} }
if (success) keyValuesGPU.copyToHost(keyValuesCPU);
{ int success=1;
printf("Correct\n"); for (int i=0;i<numValues;i++)
numSuccess++; {
} else if (keyValuesCPU[i].x != keyValuesGold[i].x)
{ success = 0;
printf("Sort Failed\n"); if (keyValuesCPU[i].y != keyValuesGold[i].y)
numFailed++; success = 0;
}
if (success)
{
printf("Correct\n");
numSuccess++;
} else
{
printf("Sort Failed\n");
numFailed++;
}
} }
clReleaseContext(context);
} }
clReleaseContext(context);
} }
///Easier method to initialize OpenCL using createContextFromType for a GPU ///Easier method to initialize OpenCL using createContextFromType for a GPU