Skip to content

Commit

Permalink
Merge pull request #175 from kylelutz/fix-platform-empty-devices
Browse files Browse the repository at this point in the history
Fix errors when using platforms with no devices
  • Loading branch information
kylelutz committed Jul 8, 2014
2 parents 5d6921f + 73443e0 commit bd164a2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion include/boost/compute/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class platform
std::vector<device> devices(cl_device_type type = CL_DEVICE_TYPE_ALL) const
{
size_t count = device_count(type);
if(count == 0){
// no devices for this platform
return std::vector<device>();
}

std::vector<cl_device_id> device_ids(count);
cl_int ret = clGetDeviceIDs(m_platform,
Expand All @@ -143,7 +147,14 @@ class platform
cl_uint count = 0;
cl_int ret = clGetDeviceIDs(m_platform, type, 0, 0, &count);
if(ret != CL_SUCCESS){
BOOST_THROW_EXCEPTION(opencl_error(ret));
if(ret == CL_DEVICE_NOT_FOUND){
// no devices for this platform
return 0;
}
else {
// something else went wrong
BOOST_THROW_EXCEPTION(opencl_error(ret));
}
}

return count;
Expand Down

0 comments on commit bd164a2

Please sign in to comment.