Skip to content

Commit

Permalink
device_selector: implement select_device.
Browse files Browse the repository at this point in the history
This allows the CTS test_device_selector test to compile, run
and pass in some circumstances.
  • Loading branch information
airlied committed Jun 28, 2018
1 parent 6e496a7 commit b62de8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
9 changes: 2 additions & 7 deletions include/CL/sycl/device_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
License. See LICENSE.TXT for details.
*/

#include "CL/sycl/detail/unimplemented.hpp"
#include "CL/sycl/device.hpp"

namespace cl {
namespace sycl {

Expand All @@ -25,17 +22,15 @@ namespace sycl {
*/
class device_selector {

device select_device(vector_class<platform> platforms) const;
public:

/** Returns a selected device using the functor operator defined in
sub-classes operator()(const device &dev)
\todo Remove this from specification
*/
void /* device */ select_device() const {
// return {};
}

device select_device() const;

/** This pure virtual operator allows the customization of device
selection.
Expand Down
25 changes: 25 additions & 0 deletions include/CL/sycl/device_selector/detail/device_selector_tail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,32 @@ namespace sycl {
/** \addtogroup execution Platforms, contexts, devices and queues
@{
*/
inline device device_selector::select_device(vector_class<platform> platforms) const {
int best_id = -1;
int best_score = -1;
int i = 0;
device best_device;

for (auto &platform : platforms) {
for (auto &dev : platform.get_devices()) {
int score = operator()(dev);
if (score > best_score) {
best_id = 1;
best_device = dev;
best_score = score;
}
++i;
}
}
if (best_id == -1)
throw cl::sycl::runtime_error("Could not find device");

return best_device;
}

inline device device_selector::select_device() const {
return select_device(platform::get_platforms());
}

/** A device selector by device_type
Expand Down

0 comments on commit b62de8a

Please sign in to comment.