Browse Source

Added run script, fix for cpu kmeans benchmark

Fixed the platform harvesting in order to collect all of them, and
changed the hardcoded variable to initialize a CPU device
Andrea Gussoni 8 years ago
parent
commit
10378d41f5
2 changed files with 11 additions and 4 deletions
  1. 10 4
      opencl/kmeans/kmeans.cpp
  2. 1 0
      opencl/kmeans/run-cpu

+ 10 - 4
opencl/kmeans/kmeans.cpp

@@ -63,10 +63,16 @@ static int initialize(int use_gpu)
 	cl_int result;
 	size_t size;
 
+	// modify a bit the initialization of the platforms in order to handle more than one platform (since on the odroid we have the GPU and the CPU platform).
+	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);
+    	clGetPlatformIDs(platformCount, platforms_ids, NULL);
+
+	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; }
@@ -135,7 +141,7 @@ int allocate(int n_points, int n_features, int n_clusters, float **feature)
 	fclose(fp);
 		
 	// OpenCL initialization
-	int use_gpu = 1;
+	int use_gpu = 0;
 	if(initialize(use_gpu)) return -1;
 
 	// compile kernel

+ 1 - 0
opencl/kmeans/run-cpu

@@ -0,0 +1 @@
+./kmeans -o -i ../../data/kmeans/kdd_cup