Skip to content

Commit

Permalink
platform: move to passing a device selector instead of device_type
Browse files Browse the repository at this point in the history
This uses a device selector instead of device type to construct
the detail platform implementations.

However it creates a cyclic depend, so we have to introduce
a platform_tail to handle it.
  • Loading branch information
airlied committed Jun 28, 2018
1 parent ff31298 commit 288dd40
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions include/CL/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
// Some includes at the end to break some dependencies
#include "CL/sycl/device_selector/detail/device_selector_tail.hpp"
#include "CL/sycl/device/detail/device_tail.hpp"
#include "CL/sycl/platform/detail/platform_tail.hpp"
#include "CL/sycl/platform/detail/host_platform_tail.hpp"
#ifdef TRISYCL_OPENCL
#include "CL/sycl/platform/detail/opencl_platform_tail.hpp"
Expand Down
5 changes: 1 addition & 4 deletions include/CL/sycl/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ class platform
\return the device list
*/
vector_class<device>
get_devices(info::device_type device_type = info::device_type::all) const {
return implementation->get_devices(device_type);
}

get_devices(info::device_type device_type = info::device_type::all) const;
};

/// @} to end the execution Doxygen group
Expand Down
2 changes: 1 addition & 1 deletion include/CL/sycl/platform/detail/host_platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ auto static constexpr platform_extensions = "Xilinx_blocking_pipes";
\return the device list
*/
vector_class<cl::sycl::device>
get_devices(info::device_type device_type) const override;
get_devices(const device_selector &device_selector) const override;

};

Expand Down
4 changes: 2 additions & 2 deletions include/CL/sycl/platform/detail/host_platform_tail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ namespace detail {
\return the device list
*/
vector_class<cl::sycl::device>
inline host_platform::get_devices(info::device_type device_type) const {
inline host_platform::get_devices(const device_selector &device_selector) const {
/** If \c get_devices is called with the host platform
and the right device type, returns the host_device.
*/
if (device_type_selector { device_type }(cl::sycl::device {}) > 0)
if (device_selector(cl::sycl::device {}) > 0)
// Return 1 default device, i.e. the host device
return { {} };
else
Expand Down
2 changes: 1 addition & 1 deletion include/CL/sycl/platform/detail/opencl_platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class opencl_platform : public detail::platform {
\return the device list
*/
vector_class<cl::sycl::device>
get_devices(info::device_type device_type) const override;
get_devices(const device_selector &device_selector) const override;

private:

Expand Down
5 changes: 2 additions & 3 deletions include/CL/sycl/platform/detail/opencl_platform_tail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ namespace detail {
\return the device list
*/
vector_class<cl::sycl::device>
inline opencl_platform::get_devices(info::device_type device_type) const {
inline opencl_platform::get_devices(const device_selector &device_selector) const {
vector_class<cl::sycl::device> devices;
device_type_selector ds { device_type };
// Add the desired OpenCL devices
for (const auto &d : get_boost_compute().devices()) {
// Get the SYCL device from the Boost Compute device
Expand All @@ -40,7 +39,7 @@ inline opencl_platform::get_devices(info::device_type device_type) const {
By calling devices on the \c boost::compute::platform we know that
we iterate only over the device belonging to the current platform,
*/
if (ds(sycl_dev) > 0)
if (device_selector(sycl_dev) > 0)
devices.push_back(sycl_dev);
}

Expand Down
7 changes: 3 additions & 4 deletions include/CL/sycl/platform/detail/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace cl {
namespace sycl {

class device;
class device_selector;

namespace detail {

Expand Down Expand Up @@ -52,14 +53,12 @@ class platform {

/** Get all the available devices for this platform
\param[in] device_type is the device type to filter the selection
or \c info::device_type::all by default to return all the
devices
\param[in] device_selector is used to filter the selection.
\return the device list
*/
virtual vector_class<device>
get_devices(info::device_type device_type) const = 0;
get_devices(const device_selector &device_selector) const = 0;

// Virtual to call the real destructor
virtual ~platform() {}
Expand Down
22 changes: 22 additions & 0 deletions include/CL/sycl/platform/detail/platform_tail.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef TRISYCL_SYCL_PLATFORM_TAIL_HPP
#define TRISYCL_SYCL_PLATFORM_TAIL_HPP

/** \file The ending part of the OpenCL SYCL platform
This is here to break a dependence between platform and device_selector.
This file is distributed under the University of Illinois Open Source
License. See LICENSE.TXT for details.
*/

namespace cl {
namespace sycl {

inline vector_class<device>
platform::get_devices(info::device_type device_type) const {
return implementation->get_devices(device_type_selector { device_type });
}

}
}

#endif

0 comments on commit 288dd40

Please sign in to comment.