소스 검색

Implemented device selection for heartwall

We now use parameters as the way to select OpenCL platform, device and
type instead of having the hardcoded in the code. In this way we can
easily change the type of the benchmark without recompiling it.

The parsing is done using the pre-existing structure of command line
arguments parsing, that is quite artisanal.
Andrea Gussoni 8 년 전
부모
커밋
856e362147

+ 16 - 12
opencl/heartwall/kernel/kernel_gpu_opencl_wrapper.c

@@ -50,7 +50,10 @@ kernel_gpu_opencl_wrapper(	params_common common,
 							int* epiCol,
 							int* tEpiRowLoc,
 							int* tEpiColLoc,
-							avi_t* frames)
+							avi_t* frames,
+              int platform_id,
+              int device_id,
+              int use_gpu)
 {
 
 	//======================================================================================================================================================150
@@ -111,10 +114,9 @@ kernel_gpu_opencl_wrapper(	params_common common,
 
 	}
 
-	// Select platform
-	int plat = 1;
-	platform = platforms[plat];
-	printf("Selecting platform %d\n", plat);
+	// Select platform on the basis of the passed as function argument
+	platform = platforms[platform_id];
+	printf("Selecting platform %d\n", platform_id);
 
 	//====================================================================================================100
 	//	CREATE CONTEXT FOR THE PLATFORM
@@ -124,11 +126,14 @@ kernel_gpu_opencl_wrapper(	params_common common,
 	cl_context_properties context_properties[3] = {	CL_CONTEXT_PLATFORM, 
 													(cl_context_properties) platform, 
 													0};
-
-	// Create context for selected platform being GPU
+                          
+  // Create the device_type selector in the basis of the argument passed (use_gpu)                        
+  cl_device_type device_type = use_gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU;
+  
+	// Create context for selected platform being GPU or CPU
 	cl_context context;
 	context = clCreateContextFromType(	context_properties, 
-										CL_DEVICE_TYPE_CPU, 
+										device_type, 
 										NULL, 
 										NULL, 
 										&error);
@@ -180,10 +185,9 @@ kernel_gpu_opencl_wrapper(	params_common common,
 
 	}
 
-	// Select device (previousely selected for the context) (if there are multiple devices, choose the first one)
-	int devi = 0;
-	device = devices[devi];
-	printf("Selecting device %d\n", devi);
+	// Select device on the basis of the argument passed as function argument
+	device = devices[device_id];
+	printf("Selecting device %d\n", device_id);
 
 	//====================================================================================================100
 	//	CREATE COMMAND QUEUE FOR THE DEVICE

+ 4 - 1
opencl/heartwall/kernel/kernel_gpu_opencl_wrapper.h

@@ -16,7 +16,10 @@ kernel_gpu_opencl_wrapper(params_common common,
 							int* epiCol,
 							int* tEpiRowLoc,
 							int* tEpiColLoc,
-							avi_t* frames);
+							avi_t* frames,
+              int platform_id,
+              int device_id,
+              int use_gpu);
 
 //========================================================================================================================================================================================================200
 //	END

+ 15 - 3
opencl/heartwall/main.c

@@ -63,6 +63,11 @@ main(	int argc,
 	// other
 	int i;
 	avi_t* frames;
+  
+  // OpenCL platform and device selection
+  int platform_id = 0;
+  int device_id = 0;
+  int use_gpu = 0;
 
 	time0 = get_time();
 
@@ -101,8 +106,9 @@ main(	int argc,
 	// 	CHECK INPUT ARGUMENTS
 	//======================================================================================================================================================150
 
-	if(argc!=2){
-		printf("ERROR: missing argument (number of frames to processed) or too many arguments\n");
+	if(argc!=5){
+		printf("ERROR: missing argument (number of frames to processed) or too many arguments\n\
+    Usage <number of frames> <platform_id> <device_id> <use_gpu>");
 		return 0;
 	}
 	else{
@@ -111,6 +117,9 @@ main(	int argc,
 			printf("ERROR: %d is an incorrect number of frames specified, select in the range of 0-%d\n", common.frames_processed, common.no_frames);
 			return 0;
 		}
+    platform_id = atoi(argv[2]);
+    device_id = atoi(argv[3]);
+    use_gpu = atoi(argv[4]);
 	}
 
 	time2 = get_time();
@@ -208,7 +217,10 @@ main(	int argc,
 								epiCol,
 								tEpiRowLoc,
 								tEpiColLoc,
-								frames);
+								frames,
+                platform_id,
+                device_id,
+                use_gpu);
 
 	time4 = get_time();
 

+ 1 - 1
opencl/heartwall/run-cpu

@@ -1 +1 @@
-./heartwall 20
+./heartwall 20 1 0 0

+ 1 - 0
opencl/heartwall/run-gpu

@@ -0,0 +1 @@
+./heartwall 20 0 0 1