Browse Source

Added run script, fix for cpu lud benchmark

Fixed selection and harvesting of the OCL platform and changed the
hardcoded variable to select the CPU device
Andrea Gussoni 8 years ago
parent
commit
d3c46b7617
2 changed files with 12 additions and 5 deletions
  1. 10 5
      opencl/lud/ocl/lud.cpp
  2. 2 0
      opencl/lud/ocl/run-cpu

+ 10 - 5
opencl/lud/ocl/lud.cpp

@@ -54,11 +54,16 @@ static int initialize(int use_gpu)
 {
 	cl_int result;
 	size_t size;
-
+	
+	// modify a little bit the initialization of the platforms to handle also the case in which we have more than one platform on our system.
+	cl_uint platformCount;
+	cl_platform_id *platforms_ids;
+	
 	// 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);
+	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; }
@@ -197,7 +202,7 @@ main ( int argc, char *argv[] )
 	fclose(fp);
 
 	// Use 1: GPU  0: CPU
-	int use_gpu = 1;
+	int use_gpu = 0;
 	// OpenCL initialization
 	if(initialize(use_gpu)) return -1;
 	// compile kernel

+ 2 - 0
opencl/lud/ocl/run-cpu

@@ -0,0 +1,2 @@
+#./lud -i ../../../data/lud/2048.dat -v
+./lud -s 2048