View Full Version : clGetDeviceIDs returns error if no devices found
03-02-2010, 10:57 PM
Is it just me, or is it strange that clGetDeviceIDs returns an error code if no devices of the desired type are found? After all, the call is successful, it just happens to return 0 devices. This is not an error in my book, it's just no devices.
That sounds like a bug. Whose driver are you using?
(I've never run into this on a Mac, but they always have a CPU device.)
03-03-2010, 08:01 AM
It's in the spec.
clGetDeviceIDs returns CL_INVALID_PLATFORM_if platform is not a valid platform, returns
CL_INVALID_DEVICE_TYPE if device_type is not a valid value, returns CL_INVALID_VALUE
if num_entries is equal to zero and devices is not NULL or if both num_devices and devices are
NULL, returns CL_DEVICE_NOT_FOUND if no OpenCL devices that matched device_type were
found, and returns CL_SUCCESS if the function is executed successfully.
03-03-2010, 01:53 PM
Both approaches i.e. either return a 0 in num_devices or return an error seem fine. However, in the case where an app just wants one device it may decide to call clGetDeviceIDs with num_entries = 1, deviceIDs set to a valid location and num_entries set to NULL. In this case, there is no way to report that no devices were found except for returning an error CL_DEVICE_NOT_FOUND. Returning the CL_DEVICE_NOT_FOUND error turns out to provide a slightly more robust approach as outlined by the example I gave above and was therefore the approach the WG decided to take.
Hope this helps answer your question.
03-03-2010, 04:47 PM
Yes, that helps. Looking closely at the spec raises the hypothetical question, what if I want two devices and issue the call with num_entries = 2, devices points to a valid address, and num_devices = NULL. If only one device is found, what is returned? As I read it, CL_DEVICE_NOT_FOUND is returned only if no devices are found. But one was found, it's just not enough for the request. The only other possible valid return is SUCCESS, which would be very odd.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.