Skip to content

[SYCL] Make default device the one selected by default_selector #5587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sycl/include/CL/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ class device_impl;
auto getDeviceComparisonLambda();
}

// A tag to allow for creating a host device
struct host_device {};

/// The SYCL device class encapsulates a single SYCL device on which kernels
/// may be executed.
///
/// \ingroup sycl_api
class __SYCL_EXPORT device {
public:
/// Constructs a SYCL device instance as a host device.
device(host_device);
Comment on lines 40 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this constructor in the specification. Why do you think we should add it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's an approval to remove host device completely. Also, libsycl.so makes use of host device.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not suggesting we move the host device support completely, but we should not add silently add non-standard functionality w/o extending the specification.

You can use aspect_selector with host aspect to select a host device. The host aspect is not in the standard, but it's already supported by DPC++, so no new extensions are needed.


/// Constructs a SYCL device instance as selected by default_selector
device();

/// Constructs a SYCL device instance from an OpenCL cl_device_id
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/platform_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ platform_impl::get_devices(info::device_type DeviceType) const {
// If SYCL_DEVICE_FILTER is set, check if filter contains host.
device_filter_list *FilterList = SYCLConfig<SYCL_DEVICE_FILTER>::get();
if (!FilterList || FilterList->containsHost()) {
Res.push_back(device());
Res.push_back(device(host_device{}));
}
}

Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void Scheduler::deallocateStreamBuffers(stream_impl *Impl) {
}

Scheduler::Scheduler() {
sycl::device HostDevice;
sycl::device HostDevice(sycl::host_device{});
sycl::context HostContext{HostDevice};
DefaultHostQueue = QueueImplPtr(
new queue_impl(detail::getSyclObjImpl(HostDevice),
Expand Down
4 changes: 3 additions & 1 deletion sycl/source/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ void force_type(info::device_type &t, const info::device_type &ft) {
}
} // namespace detail

device::device() : impl(detail::device_impl::getHostDeviceImpl()) {}
device::device() { *this = default_selector{}.select_device(); }

device::device(host_device) : impl(detail::device_impl::getHostDeviceImpl()) {}

device::device(cl_device_id DeviceId) {
// The implementation constructor takes ownership of the native handle so we
Expand Down