diff --git a/example/main.cpp b/example/main.cpp index 5217fbb68f7c3e8c0fc0e4f7e6c9d7bf689d4ac7..026a2ea5730ab5d038c951117c5f7ed670e20b3c 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -740,51 +740,73 @@ int main (int argc, char * const argv[]) { } device_id = NULL; + unsigned int i = 0; - unsigned int i; - for(i = 0; i < num_devices; i++) - { + if (argc == 3) { cl_bool available; - err = clGetDeviceInfo(device_ids[i], CL_DEVICE_AVAILABLE, sizeof(cl_bool), &available, NULL); - if(err) - { - log_error("Cannot check device availability of device # %d\n", i); + err = clGetDeviceInfo(device_ids[atoi(argv[2])], CL_DEVICE_AVAILABLE, sizeof(cl_bool), &available, NULL); + if(err) { + printf("ERROR: Cannot check device availability of device # %d\n", atoi(argv[2])); + return -1; } - - if(available) - { - device_id = device_ids[i]; + + if(available) { + device_id = device_ids[atoi(argv[2])]; + } + else { 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); + printf("ERROR: Device %s not available for compute\n", name); } else { - printf("INFO: Using device # %d...\n", i); + printf("ERROR: Device # %d not available for compute\n", atoi(argv[2])); } - break; - } - else + return -1; + } + } + else { + for(i = 0; i < num_devices; i++) { - char name[200]; - err = clGetDeviceInfo(device_ids[i], CL_DEVICE_NAME, sizeof(name), name, NULL); - if(err == CL_SUCCESS) - { - log_info("Device %s not available for compute\n", name); + cl_bool available; + err = clGetDeviceInfo(device_ids[i], CL_DEVICE_AVAILABLE, sizeof(cl_bool), &available, NULL); + if(err) { + log_error("Cannot check device availability of device # %d. Continuing with next available device...\n", i); + continue; } - else - { - log_info("Device # %d not available for compute\n", i); + + if(available) { + device_id = device_ids[i]; + break; + } + else { + char name[200]; + err = clGetDeviceInfo(device_ids[i], CL_DEVICE_NAME, sizeof(name), name, NULL); + if(err == CL_SUCCESS) { + log_info("Device %s not available for compute\n", name); + } + else { + log_info("Device # %d not available for compute\n", i); + } } } } - if(!device_id) - { + if(!device_id) { log_error("None of the devices available for compute ... aborting test\n"); test_finish(); return -1; } + else { + 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); if(!context || err) @@ -826,7 +848,7 @@ int main (int argc, char * const argv[]) { 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"); if(!paramFile) { log_error("Cannot open the parameter file\n");