From c42457f30559596f83ef110c8a45745bbaafa5d1 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Thu, 1 May 2014 02:16:28 -0700 Subject: [PATCH] API: return CL_INVALID_DEVICE from boinc_get_opencl_ids() if init_data.xml passes a value for gpu_opencl_dev_index which does not correspond to an OpenCL capable device. --- api/boinc_opencl.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/api/boinc_opencl.cpp b/api/boinc_opencl.cpp index 288577a954..396d4662a3 100644 --- a/api/boinc_opencl.cpp +++ b/api/boinc_opencl.cpp @@ -110,24 +110,28 @@ int boinc_get_opencl_ids_aux( // Use gpu_opencl_dev_index if available if (opencl_device_index >= 0) { - if (opencl_device_index < (int)num_devices) { - device_id = devices[opencl_device_index]; - retval = get_vendor(device_id, vendor, sizeof(vendor)); - if (retval != CL_SUCCESS) continue; - - if (!strcmp(vendor, type)) { - *device = device_id; - *platform = platforms[platform_index]; - return 0; - } + if (opencl_device_index >= (int)num_devices) { + fprintf(stderr, "Invalid OpenCL GPU index: %d \n", opencl_device_index); + return CL_INVALID_DEVICE; } + device_id = devices[opencl_device_index]; + retval = get_vendor(device_id, vendor, sizeof(vendor)); + if (retval != CL_SUCCESS) continue; + + if (!strcmp(vendor, type)) { + *device = device_id; + *platform = platforms[platform_index]; + return 0; + } + } + continue; } // Older versions of init_data.xml don't have gpu_opencl_dev_index field // NOTE: This may return the wrong device on older versions of BOINC if - // OpenCL does not recognize all GPU models detected by CUDA + // OpenCL does not recognize all GPU models detected by CUDA or CAL for (device_index=0; device_index<(int)num_devices; ++device_index) { device_id = devices[device_index];