Browse Source

Added run script, fix for cpu hybridsort benchmark

Fixed selection of the OCL platform in all the sources of the sorting
algorithms
Andrea Gussoni 8 years ago
parent
commit
bbb99cd6e6

+ 4 - 4
opencl/hybridsort/CLHelper.h

@@ -162,7 +162,7 @@ void _clInit()
         throw (string("InitCL()::Error: Getting platform ids (clGetPlatformIDs)"));
 
     /* Select the target platform. Default: first platform */
-    targetPlatform = allPlatforms[0];
+    targetPlatform = allPlatforms[1];
     for (int i = 0; i < numPlatforms; i++)
     {
         char pbuff[128];
@@ -183,7 +183,7 @@ void _clInit()
     //--cambine-2: create an OpenCL context
     cl_context_properties cprops[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)targetPlatform, 0 };
     oclHandles.context = clCreateContextFromType(cprops, 
-                                                CL_DEVICE_TYPE_GPU, 
+                                                CL_DEVICE_TYPE_CPU, 
                                                 NULL, 
                                                 NULL, 
                                                 &resultCL);
@@ -193,7 +193,7 @@ void _clInit()
     //-----------------------------------------------
     //--cambine-3: detect OpenCL devices	
     /* First, get the size of device list */
-   oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_GPU, 0, NULL, &deviceListSize);
+   oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_CPU, 0, NULL, &deviceListSize);
    if(oclHandles.cl_status!=CL_SUCCESS){
    	throw(string("exception in _clInit -> clGetDeviceIDs"));   	
    }
@@ -209,7 +209,7 @@ void _clInit()
         throw(string("InitCL()::Error: Could not allocate memory."));
 
     /* Next, get the device list data */
-   oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_GPU, deviceListSize, \
+   oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_CPU, deviceListSize, \
 								oclHandles.devices, NULL);
    if(oclHandles.cl_status!=CL_SUCCESS){
    	throw(string("exception in _clInit -> clGetDeviceIDs-2"));   	

+ 6 - 5
opencl/hybridsort/bucketsort.c

@@ -89,10 +89,10 @@ void init_bucketsort(int listsize)
     cl_platform_id platformID[num];
     clGetPlatformIDs(num, platformID, NULL);
     
-    clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_GPU,0,NULL,&num);
+    clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_CPU,0,NULL,&num);
     
     cl_device_id devices[num];
-    err = clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_GPU,num,devices,NULL);
+    err = clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_CPU,num,devices,NULL);
 //    int gpu = 1;
 //    err = clGetDeviceIDs(NULL, gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 2, &device_id, NULL);
     
@@ -199,15 +199,16 @@ void histogramInit(int listsize) {
     cl_platform_id platformID[num];
     clGetPlatformIDs(num, platformID, NULL);
     
-    clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_GPU,0,NULL,&num);
+    clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_CPU,0,NULL,&num);
     
+    num = 2;
     char name[128];
     
     clGetPlatformInfo(platformID[1], CL_PLATFORM_PROFILE,128,name,NULL);
     
     
     cl_device_id devices[num];
-    err = clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_GPU,num,devices,NULL);
+    err = clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_CPU,num,devices,NULL);
     //    int gpu = 1;
     //    err = clGetDeviceIDs(NULL, gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 2, &device_id, NULL);
     
@@ -228,7 +229,7 @@ void histogramInit(int listsize) {
         0
     };
     
-    histoContext = clCreateContext(contextProperties, 1, &devices[0], NULL, NULL, &err);
+    histoContext = clCreateContext(0, 1, &devices[0], NULL, NULL, &err);
     
     histoCommands = clCreateCommandQueue(histoContext, devices[0], CL_QUEUE_PROFILING_ENABLE, &err);
     histoInput = clCreateBuffer(histoContext,  CL_MEM_READ_ONLY,  listsize*(sizeof(float)), NULL, NULL);

+ 2 - 2
opencl/hybridsort/mergesort.c

@@ -53,9 +53,9 @@ void init_mergesort(int listsize){
     clGetPlatformIDs(0,NULL,&num);
     cl_platform_id platformID[num];
     clGetPlatformIDs(num,platformID,NULL);
-    clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_GPU,0,NULL,&num);
+    clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_CPU,0,NULL,&num);
     cl_device_id devices[num];
-    err = clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_GPU,num,devices,NULL);
+    err = clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_CPU,num,devices,NULL);
     
     if (err != CL_SUCCESS)
     {

+ 1 - 0
opencl/hybridsort/run-cpu

@@ -0,0 +1 @@
+./hybridsort r