Skip to content
Snippets Groups Projects
Commit 3987009c authored by Oliver Bock's avatar Oliver Bock
Browse files

Added crude feature to pass device ID as second command line argument (using...

Added crude feature to pass device ID as second command line argument (using lots of redundant code)
parent dcf5e08e
No related branches found
No related tags found
No related merge requests found
...@@ -369,31 +369,39 @@ int main (int argc, char * const argv[]) { ...@@ -369,31 +369,39 @@ int main (int argc, char * const argv[]) {
} }
device_id = NULL; device_id = NULL;
unsigned int i = 0;
unsigned int i; if (argc == 3) {
for(i = 0; i < num_devices; i++)
{
cl_bool available; cl_bool available;
err = clGetDeviceInfo(device_ids[i], CL_DEVICE_AVAILABLE, sizeof(cl_bool), &available, NULL); err = clGetDeviceInfo(device_ids[atoi(argv[2])], CL_DEVICE_AVAILABLE, sizeof(cl_bool), &available, NULL);
if(err) if(err)
{ {
printf("ERROR: Cannot check device availability of device # %d\n", i); printf("ERROR: Cannot check device availability of device # %d\n", atoi(argv[2]));
} }
if(available) if(available)
{ {
device_id = device_ids[i]; device_id = device_ids[atoi(argv[2])];
char name[200];
err = clGetDeviceInfo(device_ids[i], CL_DEVICE_NAME, sizeof(name), name, NULL);
if(err == CL_SUCCESS)
{
printf("INFO: Using device %s...\n", name);
} }
else else
{ {
printf("INFO: Using device # %d...\n", i); printf("INFO: Device # %d not available for compute\n", atoi(argv[2]));
return -1;
}
}
else {
for(i = 0; i < num_devices; i++)
{
cl_bool available;
err = clGetDeviceInfo(device_ids[i], CL_DEVICE_AVAILABLE, sizeof(cl_bool), &available, NULL);
if(err)
{
printf("ERROR: Cannot check device availability of device # %d\n", i);
} }
if(available)
{
device_id = device_ids[i];
break; break;
} }
else else
...@@ -417,6 +425,18 @@ int main (int argc, char * const argv[]) { ...@@ -417,6 +425,18 @@ int main (int argc, char * const argv[]) {
//test_finish(); //test_finish();
return -1; return -1;
} }
}
char name[200];
err = clGetDeviceInfo(device_id, CL_DEVICE_NAME, sizeof(name), name, NULL);
if(err == CL_SUCCESS)
{
printf("INFO: Using device %s...\n", name);
}
else
{
printf("INFO: Using device # %d...\n", i);
}
context = clCreateContext(0, 1, &device_id, NULL, NULL, &err); context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
if(!context || err) if(!context || err)
...@@ -458,7 +478,7 @@ int main (int argc, char * const argv[]) { ...@@ -458,7 +478,7 @@ int main (int argc, char * const argv[]) {
return -1; return -1;
} }
if(argc == 2) { // arguments are supplied in a file with arguments for a single run are all on the same line if(argc >= 2) { // arguments are supplied in a file with arguments for a single run are all on the same line
paramFile = fopen(argv[1], "r"); paramFile = fopen(argv[1], "r");
if(!paramFile) { if(!paramFile) {
log_error((char*)"Cannot open the parameter file\n"); log_error((char*)"Cannot open the parameter file\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment