|
@@ -50,7 +50,7 @@ static cl_device_type device_type;
|
|
|
static cl_device_id * device_list;
|
|
|
static cl_int num_devices;
|
|
|
|
|
|
-static int initialize(int use_gpu)
|
|
|
+static int initialize(int platform_id, int device_id, int use_gpu)
|
|
|
{
|
|
|
cl_int result;
|
|
|
size_t size;
|
|
@@ -63,12 +63,12 @@ static int initialize(int use_gpu)
|
|
|
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};
|
|
|
+ cl_context_properties ctxprop[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platforms_ids[platform_id], 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; }
|
|
|
|
|
|
- // get the list of GPUs
|
|
|
+ // get the list of GPUs/CPUs
|
|
|
result = clGetContextInfo( context, CL_CONTEXT_DEVICES, 0, NULL, &size );
|
|
|
num_devices = (int) (size / sizeof(cl_device_id));
|
|
|
printf("num_devices = %d\n", num_devices);
|
|
@@ -79,8 +79,8 @@ static int initialize(int use_gpu)
|
|
|
result = clGetContextInfo( context, CL_CONTEXT_DEVICES, size, device_list, NULL );
|
|
|
if( result != CL_SUCCESS ) { printf("ERROR: clGetContextInfo() failed\n"); return -1; }
|
|
|
|
|
|
- // create command queue for the first device
|
|
|
- cmd_queue = clCreateCommandQueue( context, device_list[0], 0, NULL );
|
|
|
+ // create command queue for the device passed as parameter
|
|
|
+ cmd_queue = clCreateCommandQueue( context, device_list[device_id], 0, NULL );
|
|
|
if( !cmd_queue ) { printf("ERROR: clCreateCommandQueue() failed\n"); return -1; }
|
|
|
return 0;
|
|
|
}
|
|
@@ -123,33 +123,44 @@ main ( int argc, char *argv[] )
|
|
|
const char *input_file = NULL;
|
|
|
float *m, *mm;
|
|
|
stopwatch sw;
|
|
|
+
|
|
|
+ // Variables to store information on platform and device to use_gpu
|
|
|
+ int platform_id = 0;
|
|
|
+ int device_id = 0;
|
|
|
+ int use_gpu = 0;
|
|
|
|
|
|
- while ((opt = getopt_long(argc, argv, "::vs:i:",
|
|
|
+ while ((opt = getopt_long(argc, argv, "::vs:i:p:d:g:",
|
|
|
long_options, &option_index)) != -1 ) {
|
|
|
switch(opt){
|
|
|
case 'i':
|
|
|
- input_file = optarg;
|
|
|
- break;
|
|
|
+ input_file = optarg;
|
|
|
+ break;
|
|
|
case 'v':
|
|
|
- do_verify = 1;
|
|
|
- break;
|
|
|
- case 's':
|
|
|
- matrix_dim = atoi(optarg);
|
|
|
- printf("Generate input matrix internally, size =%d\n", matrix_dim);
|
|
|
- // fprintf(stderr, "Currently not supported, use -i instead\n");
|
|
|
- // fprintf(stderr, "Usage: %s [-v] [-s matrix_size|-i input_file]\n", argv[0]);
|
|
|
- // exit(EXIT_FAILURE);
|
|
|
- break;
|
|
|
- case '?':
|
|
|
- fprintf(stderr, "invalid option\n");
|
|
|
- break;
|
|
|
- case ':':
|
|
|
- fprintf(stderr, "missing argument\n");
|
|
|
- break;
|
|
|
- default:
|
|
|
- fprintf(stderr, "Usage: %s [-v] [-s matrix_size|-i input_file]\n",
|
|
|
- argv[0]);
|
|
|
- exit(EXIT_FAILURE);
|
|
|
+ do_verify = 1;
|
|
|
+ break;
|
|
|
+ case 's':
|
|
|
+ matrix_dim = atoi(optarg);
|
|
|
+ printf("Generate input matrix internally, size =%d\n", matrix_dim);
|
|
|
+ break;
|
|
|
+ case 'p':
|
|
|
+ platform_id = atoi(optarg);
|
|
|
+ break;
|
|
|
+ case 'd':
|
|
|
+ device_id = atoi(optarg);
|
|
|
+ break;
|
|
|
+ case 'g':
|
|
|
+ use_gpu = atoi(optarg);
|
|
|
+ break;
|
|
|
+ case '?':
|
|
|
+ fprintf(stderr, "invalid option\n");
|
|
|
+ break;
|
|
|
+ case ':':
|
|
|
+ fprintf(stderr, "missing argument\n");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ fprintf(stderr, "Usage: %s [-v] [-s matrix_size|-i input_file] -p platform -d device -g use_gpu\n",
|
|
|
+ argv[0]);
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -201,10 +212,8 @@ main ( int argc, char *argv[] )
|
|
|
fread(source + strlen(source), sourcesize, 1, fp);
|
|
|
fclose(fp);
|
|
|
|
|
|
- // Use 1: GPU 0: CPU
|
|
|
- int use_gpu = 0;
|
|
|
// OpenCL initialization
|
|
|
- if(initialize(use_gpu)) return -1;
|
|
|
+ if(initialize(platform_id, device_id, use_gpu)) return -1;
|
|
|
// compile kernel
|
|
|
cl_int err = 0;
|
|
|
const char * slist[2] = { source, 0 };
|