From db95f76bfd5b75be7278f2f8359c1ba193214b45 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Fri, 27 Sep 2013 15:00:58 -0500 Subject: [PATCH] Return empty list if no devices found in get_devices() --- doc/runtime.rst | 6 ++++++ src/wrapper/wrap_cl.hpp | 2 ++ 2 files changed, 8 insertions(+) diff --git a/doc/runtime.rst b/doc/runtime.rst index d6999f0d..b809211b 100644 --- a/doc/runtime.rst +++ b/doc/runtime.rst @@ -78,6 +78,12 @@ Platforms, Devices and Contexts Return a list of devices matching *device_type*. See :class:`device_type` for values of *device_type*. + .. versionchanged:: 2013.2 + + This used to raise an exception if no matching + devices were found. Now, it will simply return + an empty list. + .. automethod:: from_int_ptr .. autoattribute:: int_ptr diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp index dbdced1a..ea1cea82 100644 --- a/src/wrapper/wrap_cl.hpp +++ b/src/wrapper/wrap_cl.hpp @@ -850,6 +850,8 @@ namespace pyopencl cl_uint num_devices = 0; PYOPENCL_CALL_GUARDED(clGetDeviceIDs, (m_platform, devtype, 0, 0, &num_devices)); + if (num_devices == 0) + return py::list(); std::vector<cl_device_id> devices(num_devices); PYOPENCL_CALL_GUARDED(clGetDeviceIDs, -- GitLab