|
@@ -64,10 +64,17 @@ static int initialize(int use_gpu)
|
|
|
cl_int result;
|
|
|
size_t size;
|
|
|
|
|
|
+ // modification to handle the case in which we have more than one OpenCL platform available on the system.
|
|
|
+ cl_uint platformCount;
|
|
|
+
|
|
|
+
|
|
|
// create OpenCL context
|
|
|
- cl_platform_id platform_id;
|
|
|
- if (clGetPlatformIDs(1, &platform_id, NULL) != CL_SUCCESS) { printf("ERROR: clGetPlatformIDs(1,*,0) failed\n"); return -1; }
|
|
|
- cl_context_properties ctxprop[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform_id, 0};
|
|
|
+ clGetPlatformIDs(0, NULL, &platformCount);
|
|
|
+
|
|
|
+ cl_platform_id *platforms_ids;
|
|
|
+ platforms_ids = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount);
|
|
|
+ if (clGetPlatformIDs(platformCount, platforms_ids, NULL) != CL_SUCCESS) { printf("ERROR: clGetPlatformIDs(1,*,0) failed\n"); return -1; }
|
|
|
+ cl_context_properties ctxprop[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platforms_ids[1], 0};
|
|
|
device_type = use_gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU;
|
|
|
context = clCreateContextFromType( ctxprop, device_type, NULL, NULL, NULL );
|
|
|
if( !context ) { printf("ERROR: clCreateContextFromType(%s) failed\n", use_gpu ? "GPU" : "CPU"); return -1; }
|
|
@@ -223,7 +230,7 @@ int main(int argc, char **argv){
|
|
|
size_t local_work[3] = { (workgroupsize>0)?workgroupsize:1, 1, 1 };
|
|
|
size_t global_work[3] = { nworkitems, 1, 1 }; //nworkitems = no. of GPU threads
|
|
|
|
|
|
- int use_gpu = 1;
|
|
|
+ int use_gpu = 0;
|
|
|
// OpenCL initialization
|
|
|
if(initialize(use_gpu)) return -1;
|
|
|
|