Skip to content
Draft
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
10 changes: 10 additions & 0 deletions sycl/include/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,23 @@ class __SYCL_STANDALONE_DEBUG __SYCL_EXPORT device {
explicit device(cl_device_id DeviceId);
#endif

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
/// Constructs a SYCL device instance using the device selected
/// by the DeviceSelector provided.
///
/// \param DeviceSelector SYCL 1.2.1 device_selector to be used (see 4.6.1.1).
__SYCL2020_DEPRECATED("SYCL 1.2.1 device selectors are deprecated. Please "
"use SYCL 2020 device selectors instead.")
explicit device(const device_selector &DeviceSelector);
#else
// TODO: consider rewriting the filter_selector class to be used with the new
// device(const DeviceSelector &deviceSelector) constructor.
/// Constructs a SYCL device instance using the device selected
/// by the DeviceSelector provided.
///
/// \param DeviceSelector filter_selector to be used (see sycl_ext_oneapi_filter_selector).
explicit device(const ext::oneapi::filter_selector &DeviceSelector);
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

/// Constructs a SYCL device instance using the device
/// identified by the device selector provided.
Expand Down
77 changes: 60 additions & 17 deletions sycl/include/sycl/device_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ namespace ext::oneapi {
class filter_selector;
} // namespace ext::oneapi

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
/// The SYCL 1.2.1 device_selector class provides ability to choose the
/// best SYCL device based on heuristics specified by the user.
///
/// \sa device
///
/// \ingroup sycl_api_dev_sel
class __SYCL_EXPORT __SYCL2020_DEPRECATED(
"Use SYCL 2020 callable device selectors instead.") device_selector {
class __SYCL_EXPORT
__SYCL2020_DEPRECATED("Use SYCL 2020 callable device selectors instead.")
device_selector {

public:
virtual ~device_selector() = default;
Expand All @@ -45,41 +47,66 @@ class __SYCL_EXPORT __SYCL2020_DEPRECATED(

virtual int operator()(const device &device) const = 0;
};
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

/// The default selector chooses the first available SYCL device.
///
/// \sa device
///
/// \ingroup sycl_api_dev_sel
class __SYCL_EXPORT __SYCL2020_DEPRECATED(
"Use the callable sycl::default_selector_v instead.") default_selector
: public device_selector {
class __SYCL_EXPORT
__SYCL2020_DEPRECATED("Use the callable sycl::default_selector_v instead.")
default_selector
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
: public device_selector
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
{
public:
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
int operator()(const device &dev) const override;
#else
int operator()(const device &dev) const;
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
};

/// Selects any SYCL GPU device.
///
/// \sa device
///
/// \ingroup sycl_api_dev_sel
class __SYCL_EXPORT __SYCL2020_DEPRECATED(
"Use the callable sycl::gpu_selector_v instead.") gpu_selector
: public device_selector {
class __SYCL_EXPORT
__SYCL2020_DEPRECATED("Use the callable sycl::gpu_selector_v instead.")
gpu_selector
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
: public device_selector
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
{
public:
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
int operator()(const device &dev) const override;
#else
int operator()(const device &dev) const;
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
};

/// Selects any SYCL CPU device.
///
/// \sa device
///
/// \ingroup sycl_api_dev_sel
class __SYCL_EXPORT __SYCL2020_DEPRECATED(
"Use the callable sycl::cpu_selector_v instead.") cpu_selector
: public device_selector {
class __SYCL_EXPORT
__SYCL2020_DEPRECATED("Use the callable sycl::cpu_selector_v instead.")
cpu_selector
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
: public device_selector
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
{
public:
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
int operator()(const device &dev) const override;
#else
int operator()(const device &dev) const;
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
};

/// Selects any SYCL accelerator device.
Expand All @@ -89,9 +116,17 @@ class __SYCL_EXPORT __SYCL2020_DEPRECATED(
/// \ingroup sycl_api_dev_sel
class __SYCL_EXPORT
__SYCL2020_DEPRECATED("Use the callable sycl::accelerator_selector_v instead.")
accelerator_selector : public device_selector {
accelerator_selector
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
: public device_selector
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
{
public:
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
int operator()(const device &dev) const override;
#else
int operator()(const device &dev) const;
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
};

// -------------- SYCL 2020
Expand Down Expand Up @@ -122,13 +157,21 @@ void fill_aspect_vector(std::vector<aspect> &V, FirstT F, OtherTs... O) {

// Enable if DeviceSelector callable has matching signature, but
// exclude if descended from filter_selector which is not purely callable or
// if descended from it is descended from SYCL 1.2.1 device_selector.
// if descended from SYCL 1.2.1 device_selector (deprecated & will be removed
// soon).
// See [FilterSelector not Callable] in device_selector.cpp
template <typename DeviceSelector>
using EnableIfSYCL2020DeviceSelectorInvocable = std::enable_if_t<
std::is_invocable_r_v<int, DeviceSelector &, const device &> &&
!std::is_base_of_v<ext::oneapi::filter_selector, DeviceSelector> &&
!std::is_base_of_v<device_selector, DeviceSelector>>;
using EnableIfSYCL2020DeviceSelectorInvocable =
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
std::enable_if_t<
std::is_invocable_r_v<int, DeviceSelector &, const device &> &&
!std::is_base_of_v<ext::oneapi::filter_selector, DeviceSelector> &&
!std::is_base_of_v<device_selector, DeviceSelector>>;
#else
std::enable_if_t<
std::is_invocable_r_v<int, DeviceSelector &, const device &> &&
!std::is_base_of_v<ext::oneapi::filter_selector, DeviceSelector>>;
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

__SYCL_EXPORT device
select_device(const DSelectorInvocableType &DeviceSelectorInvocable);
Expand Down
18 changes: 16 additions & 2 deletions sycl/include/sycl/ext/oneapi/filter_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
#include <sycl/device.hpp> // for device
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
#include <sycl/device_selector.hpp> // for device_selector
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

#include <memory> // for shared_ptr
#include <string> // for string
Expand All @@ -22,7 +24,6 @@ inline namespace _V1 {

// Forward declarations
class device;
class device_selector;
#ifdef __SYCL_INTERNAL_API
namespace ONEAPI {
class filter_selector;
Expand All @@ -34,13 +35,26 @@ namespace detail {
class filter_selector_impl;
} // namespace detail

class __SYCL_EXPORT filter_selector : public device_selector {
class __SYCL_EXPORT filter_selector
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
: public device_selector
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
{
public:
virtual ~filter_selector() = default;
filter_selector(const std::string &filter)
: filter_selector(sycl::detail::string_view{filter}) {}
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
int operator()(const device &dev) const override;
#else
virtual int operator()(const device &dev) const;
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
void reset() const;
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
device select_device() const override;
#else
virtual device select_device() const;
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
#ifdef __SYCL_INTERNAL_API
friend class sycl::ONEAPI::filter_selector;
#endif
Expand Down
2 changes: 2 additions & 0 deletions sycl/include/sycl/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
explicit platform(cl_platform_id PlatformId);
#endif

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
/// Constructs a SYCL platform instance using a device_selector.
///
/// One of the SYCL devices that is associated with the constructed SYCL
Expand All @@ -95,6 +96,7 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
__SYCL2020_DEPRECATED("SYCL 1.2.1 device selectors are deprecated. Please "
"use SYCL 2020 device selectors instead.")
explicit platform(const device_selector &DeviceSelector);
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

/// Constructs a SYCL platform instance using the platform of the device
/// identified by the device selector provided.
Expand Down
4 changes: 4 additions & 0 deletions sycl/include/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
: queue(syclContext, detail::select_device(deviceSelector, syclContext),
AsyncHandler, propList) {}

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
/// Constructs a SYCL queue instance using the device returned by the
/// DeviceSelector provided.
///
Expand All @@ -296,6 +297,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
queue(const device_selector &DeviceSelector,
const async_handler &AsyncHandler, const property_list &PropList = {})
: queue(DeviceSelector.select_device(), AsyncHandler, PropList) {}
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

/// Constructs a SYCL queue instance using the device provided.
///
Expand All @@ -313,6 +315,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
explicit queue(const device &SyclDevice, const async_handler &AsyncHandler,
const property_list &PropList = {});

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
/// Constructs a SYCL queue instance that is associated with the context
/// provided, using the device returned by the device selector.
///
Expand All @@ -336,6 +339,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
"use SYCL 2020 device selectors instead.")
queue(const context &SyclContext, const device_selector &DeviceSelector,
const async_handler &AsyncHandler, const property_list &PropList = {});
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

/// Constructs a SYCL queue associated with the given context, device
/// and optional properties list.
Expand Down
7 changes: 7 additions & 0 deletions sycl/source/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <sycl/ext/oneapi/experimental/device_architecture.hpp>
#include <sycl/ext/oneapi/experimental/forward_progress.hpp>
#include <sycl/ext/oneapi/experimental/max_work_groups.hpp>
#include <sycl/ext/oneapi/filter_selector.hpp>
#include <sycl/ext/oneapi/info/device.hpp>
#include <sycl/ext/oneapi/matrix/query-types.hpp>

Expand Down Expand Up @@ -61,9 +62,15 @@ device::device(cl_device_id DeviceId) {
__SYCL_OCL_CALL(clRetainDevice, DeviceId);
}

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
device::device(const device_selector &deviceSelector) {
*this = deviceSelector.select_device();
}
#else
device::device(const ext::oneapi::filter_selector &deviceSelector) {
*this = deviceSelector.select_device();
}
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

std::vector<device> device::get_devices(info::device_type deviceType) {
std::vector<device> devices;
Expand Down
5 changes: 4 additions & 1 deletion sycl/source/device_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,11 @@ aspect_selector(const std::vector<aspect> &RequireList,

// SYCL 1.2.1 device_selector class and sub-classes

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
device device_selector::select_device() const {
return detail::select_device([&](const device &dev) { return (*this)(dev); });
}
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

int default_selector::operator()(const device &dev) const {
return default_selector_v(dev);
Expand Down Expand Up @@ -294,7 +296,8 @@ device filter_selector::select_device() const {
std::lock_guard<std::mutex> Guard(
sycl::detail::GlobalHandler::instance().getFilterMutex());

device Result = device_selector::select_device();
device Result = sycl::detail::select_device(
[&](const device &dev) { return (*this)(dev); });

reset();

Expand Down
2 changes: 2 additions & 0 deletions sycl/source/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ platform::platform(cl_platform_id PlatformId) {
// protected constructor for internal use
platform::platform(const device &Device) { *this = Device.get_platform(); }

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
platform::platform(const device_selector &dev_selector) {
*this = dev_selector.select_device().get_platform();
}
#endif

cl_platform_id platform::get() const { return impl->get(); }

Expand Down
4 changes: 4 additions & 0 deletions sycl/source/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace sycl {
inline namespace _V1 {

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
queue::queue(const context &SyclContext, const device_selector &DeviceSelector,
const async_handler &AsyncHandler, const property_list &PropList) {
const std::vector<device> Devs = SyclContext.get_devices();
Expand All @@ -34,6 +35,7 @@ queue::queue(const context &SyclContext, const device_selector &DeviceSelector,
*detail::getSyclObjImpl(SyclContext),
AsyncHandler, PropList);
}
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

queue::queue(const context &SyclContext, const device &SyclDevice,
const async_handler &AsyncHandler, const property_list &PropList) {
Expand All @@ -48,11 +50,13 @@ queue::queue(const device &SyclDevice, const async_handler &AsyncHandler,
AsyncHandler, PropList);
}

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
queue::queue(const context &SyclContext, const device_selector &deviceSelector,
const property_list &PropList)
: queue(SyclContext, deviceSelector,
detail::getSyclObjImpl(SyclContext)->get_async_handler(),
PropList) {}
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

queue::queue(const context &SyclContext, const device &SyclDevice,
const property_list &PropList)
Expand Down
4 changes: 2 additions & 2 deletions sycl/test-e2e/Adapters/level_zero/interop-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

using namespace sycl;

class DiscreteSelector : public sycl::device_selector {
class DiscreteSelector {
public:
int operator()(const sycl::device &Device) const final {
int operator()(const sycl::device &Device) const {
if (!Device.is_gpu() ||
Device.get_backend() != backend::ext_oneapi_level_zero)
return -1;
Expand Down
2 changes: 2 additions & 0 deletions sycl/test/abi/abi_crossing_type_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ int main() {
check_type_traits<vec<int, 4>, true, true, true>();
check_type_traits<detail::PropertyWithDataBase, false, false, false>();
check_type_traits<detail::SYCLMemObjAllocator, false, false, false>();
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
check_type_traits<device_selector, false, false, false>();
#endif

return 0;
}
2 changes: 2 additions & 0 deletions sycl/test/abi/symbol_size_alignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ int main() {
check<cpu_selector, 8, 8>();
check<device, 8, 8>();
check<device_event, 8, 8>();
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
check<device_selector, 8, 8>();
#endif
check<event, 16, 8>();
check<gpu_selector, 8, 8>();
check<handler, 176, 8>();
Expand Down
2 changes: 2 additions & 0 deletions sycl/test/abi/vtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void foo(sycl::detail::SYCLMemObjAllocator &Allocator) {
// CHECK-NEXT: 7 | std::size_t sycl::detail::SYCLMemObjAllocator::getValueSize() const [pure]
// CHECK-NEXT: 8 | void sycl::detail::SYCLMemObjAllocator::setAlignment(std::size_t) [pure]

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
void foo(sycl::device_selector &DeviceSelector) {
(void)DeviceSelector.select_device();
}
Expand All @@ -42,3 +43,4 @@ void foo(sycl::device_selector &DeviceSelector) {
// CHECK-NEXT: 3 | sycl::device_selector::~device_selector() [deleting]
// CHECK-NEXT: 4 | device sycl::device_selector::select_device() const
// CHECK-NEXT: 5 | int sycl::device_selector::operator()(const device &) const [pure]
#endif
Loading
Loading