JayBeams  0.1
Another project to have fun coding.
device_selector.hpp
Go to the documentation of this file.
1 #ifndef jb_opencl_device_selector_hpp
2 #define jb_opencl_device_selector_hpp
3 
4 #include <boost/compute/device.hpp>
5 #include <boost/compute/system.hpp>
6 
7 namespace jb {
8 namespace opencl {
9 
10 class config;
11 
12 /**
13  * Select an OpenCL device matching the current configuration.
14  */
15 boost::compute::device device_selector(config const& cfg);
16 
17 /**
18  * Return the default OpenCL device.
19  */
20 boost::compute::device device_selector();
21 
22 namespace detail {
23 
24 /// Return the best available device of the given type
25 template <typename Filter>
26 boost::compute::device best_device(Filter filter, char const* filter_name) {
27  boost::compute::device selection;
28  unsigned int count = 0;
29  for (auto const& d : boost::compute::system::devices()) {
30  if (filter(d) and d.compute_units() > count) {
31  count = d.compute_units();
32  selection = d;
33  }
34  }
35  if (count == 0) {
36  std::ostringstream os;
37  os << "Could not find a device using filter " << filter_name;
38  throw std::runtime_error(os.str());
39  }
40  return selection;
41 }
42 
43 } // namespace detail
44 
45 } // namespace opencl
46 } // namespace jb
47 
48 #endif // jb_cl_device_selector_hpp
boost::compute::device device_selector(config const &cfg)
Select an OpenCL device matching the current configuration.
boost::compute::device best_device(Filter filter, char const *filter_name)
Return the best available device of the given type.
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7