Skip to content

Commit c058380

Browse files
[SYCL] Deprecate SYCL 1.2.1 device selectors (#6599)
Now that we have added the SYCL 2020 callable device selectors, we need to prepare for the removal of the older SYCL 1.2.1 `device_selector` class. The first step is to add the deprecation message to the 1.2.1 style device selectors, which this PR does. It also removes the usage of those from our own codebase so as to not trip on our own messages in the future. Signed-off-by: Chris Perkins <[email protected]> Signed-off-by: Larsen, Steffen <[email protected]> Co-authored-by: Larsen, Steffen <[email protected]>
1 parent 84de9d6 commit c058380

File tree

14 files changed

+88
-60
lines changed

14 files changed

+88
-60
lines changed

sycl/doc/GetStartedGuide.md

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ SYCL_BE=PI_CUDA ./simple-sycl-app-cuda.exe
705705
```
706706
707707
**NOTE**: DPC++/SYCL developers can specify SYCL device for execution using
708-
device selectors (e.g. `sycl::cpu_selector`, `sycl::gpu_selector`,
708+
device selectors (e.g. `sycl::cpu_selector_v`, `sycl::gpu_selector_v`,
709709
[Intel FPGA selector(s)](extensions/supported/sycl_ext_intel_fpga_device_selector.md)) as
710710
explained in following section [Code the program for a specific
711711
GPU](#code-the-program-for-a-specific-gpu).
@@ -740,42 +740,38 @@ the CMake.
740740
741741
### Code the program for a specific GPU
742742
743-
To specify OpenCL device SYCL provides the abstract `sycl::device_selector`
744-
class which the can be used to define how the runtime should select the best
745-
device.
746-
747-
The method `sycl::device_selector::operator()` of the SYCL
748-
`sycl::device_selector` is an abstract member function which takes a
749-
reference to a SYCL device and returns an integer score. This abstract member
750-
function can be implemented in a derived class to provide a logic for selecting
751-
a SYCL device. SYCL runtime uses the device for with the highest score is
752-
returned. Such object can be passed to `sycl::queue` and `sycl::device`
753-
constructors.
754-
755-
The example below illustrates how to use `sycl::device_selector` to create
756-
device and queue objects bound to Intel GPU device:
743+
To assist in finding a specific SYCL compatible device out of all that may be
744+
available, a "device selector" may be used. A "device selector" is a ranking
745+
function (C++ Callable) that will give an integer ranking value to all the
746+
devices on the system. It can be passed to `sycl::queue`, `sycl::device` and
747+
`sycl::platform` constructors. The highest ranking device is then selected. SYCL
748+
has built-in device selectors for selecting a generic GPU, CPU, or accelerator
749+
device, as well as one for a default device. Additionally, a user can define
750+
their own as function, lambda, or functor class. Device selectors returning
751+
negative values will "reject" a device ensuring it is not selected, but values 0
752+
or higher will be selected by the highest score with ties resolved by an
753+
internal algorithm (see Section 4.6.1 of the SYCL 2020 specification)
754+
755+
The example below illustrates how to use a device selector to create device and
756+
queue objects bound to Intel GPU device:
757757
758758
```c++
759759
#include <sycl/sycl.hpp>
760760
761761
int main() {
762-
class NEOGPUDeviceSelector : public sycl::device_selector {
763-
public:
764-
int operator()(const sycl::device &Device) const override {
765-
using namespace sycl::info;
766762
767-
const std::string DeviceName = Device.get_info<device::name>();
768-
const std::string DeviceVendor = Device.get_info<device::vendor>();
763+
auto NEOGPUDeviceSelector = [](const sycl::device &Device){
764+
using namespace sycl::info;
769765
770-
return Device.is_gpu() && (DeviceName.find("HD Graphics NEO") != std::string::npos);
771-
}
766+
const std::string DeviceName = Device.get_info<device::name>();
767+
bool match = Device.is_gpu() && (DeviceName.find("HD Graphics NEO") != std::string::npos);
768+
return match ? 1 : -1;
772769
};
773770
774-
NEOGPUDeviceSelector Selector;
775771
try {
776-
sycl::queue Queue(Selector);
777-
sycl::device Device(Selector);
778-
} catch (sycl::invalid_parameter_error &E) {
772+
sycl::queue Queue(NEOGPUDeviceSelector);
773+
sycl::device Device(NEOGPUDeviceSelector);
774+
} catch (sycl::exception &E) {
779775
std::cout << E.what() << std::endl;
780776
}
781777
}
@@ -786,19 +782,18 @@ The device selector below selects an NVIDIA device only, and won't execute if
786782
there is none.
787783
788784
```c++
789-
class CUDASelector : public sycl::device_selector {
790-
public:
791-
int operator()(const sycl::device &Device) const override {
792-
using namespace sycl::info;
793-
const std::string DriverVersion = Device.get_info<device::driver_version>();
794-
795-
if (Device.is_gpu() && (DriverVersion.find("CUDA") != std::string::npos)) {
796-
std::cout << " CUDA device found " << std::endl;
797-
return 1;
798-
};
799-
return -1;
800-
}
801-
};
785+
786+
int CUDASelector(const sycl::device &Device) {
787+
using namespace sycl::info;
788+
const std::string DriverVersion = Device.get_info<device::driver_version>();
789+
790+
if (Device.is_gpu() && (DriverVersion.find("CUDA") != std::string::npos)) {
791+
std::cout << " CUDA device found " << std::endl;
792+
return 1;
793+
};
794+
return -1;
795+
}
796+
802797
```
803798
804799
### Using the DPC++ toolchain on CUDA platforms

sycl/doc/MultiTileCardWithLevelZero.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ try {
143143
``` C++
144144
try {
145145
// The queue is attached to the root-device, driver distributes to sub-devices, if any.
146-
auto D = device(gpu_selector{});
147-
auto Q = queue(D);
146+
auto Q = queue(gpu_selector_v);
148147
Q.submit([&](handler& cgh) {...});
149148
}
150149
```
@@ -155,7 +154,7 @@ try {
155154
- Example:
156155
``` C++
157156
try {
158-
auto P = platform(gpu_selector{});
157+
auto P = platform(gpu_selector_v);
159158
auto RootDevices = P.get_devices();
160159
auto C = context(RootDevices);
161160
for (auto &D : RootDevices) {

sycl/doc/design/GlobalObjectsInRuntime.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ like in example below:
2222
sycl::queue Queue;
2323
2424
int main() {
25-
Queue = sycl::queue{sycl::default_selector{}.select_device()};
25+
Queue = sycl::queue{sycl::default_selector_v};
2626
2727
return 0;
2828
}

sycl/doc/extensions/experimental/sycl_ext_intel_esimd/sycl_ext_intel_esimd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ int main(void) {
660660
int err_cnt = 0;
661661
662662
try {
663-
queue q(gpu_selector{}, createExceptionHandler());
663+
queue q(gpu_selector_v, createExceptionHandler());
664664
auto dev = q.get_device();
665665
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
666666

sycl/doc/extensions/experimental/sycl_ext_oneapi_max_work_group_query.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ As encouraged by the SYCL specification, a feature-test macro, `SYCL_EXT_ONEAPI_
3434
## Examples
3535

3636
```c++
37-
sycl::device gpu = sycl::device{sycl::gpu_selector{}};
37+
sycl::device gpu = sycl::device{sycl::gpu_selector_v};
3838
std::cout << gpu.get_info<sycl::info::device::name>() << '\n';
3939

4040
#ifdef SYCL_EXT_ONEAPI_MAX_WORK_GROUP_QUERY

sycl/include/sycl/device.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class __SYCL_EXPORT device {
6161
/// by the DeviceSelector provided.
6262
///
6363
/// \param DeviceSelector SYCL 1.2.1 device_selector to be used (see 4.6.1.1).
64+
__SYCL2020_DEPRECATED("Use Callable device selectors instead of deprecated "
65+
"device_selector subclasses.")
6466
explicit device(const device_selector &DeviceSelector);
6567

6668
#if __cplusplus >= 201703L

sycl/include/sycl/device_selector.hpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class filter_selector;
3131
/// \sa device
3232
///
3333
/// \ingroup sycl_api_dev_sel
34-
class __SYCL_EXPORT device_selector {
34+
class __SYCL_EXPORT __SYCL2020_DEPRECATED(
35+
"Use Callable instead to select device.") device_selector {
3536

3637
public:
3738
virtual ~device_selector() = default;
@@ -46,7 +47,9 @@ class __SYCL_EXPORT device_selector {
4647
/// \sa device
4748
///
4849
/// \ingroup sycl_api_dev_sel
49-
class __SYCL_EXPORT default_selector : public device_selector {
50+
class __SYCL_EXPORT __SYCL2020_DEPRECATED(
51+
"Use the callable sycl::default_selector_v instead.") default_selector
52+
: public device_selector {
5053
public:
5154
int operator()(const device &dev) const override;
5255
};
@@ -56,7 +59,9 @@ class __SYCL_EXPORT default_selector : public device_selector {
5659
/// \sa device
5760
///
5861
/// \ingroup sycl_api_dev_sel
59-
class __SYCL_EXPORT gpu_selector : public device_selector {
62+
class __SYCL_EXPORT __SYCL2020_DEPRECATED(
63+
"Use the callable sycl::gpu_selector_v instead.") gpu_selector
64+
: public device_selector {
6065
public:
6166
int operator()(const device &dev) const override;
6267
};
@@ -66,7 +71,9 @@ class __SYCL_EXPORT gpu_selector : public device_selector {
6671
/// \sa device
6772
///
6873
/// \ingroup sycl_api_dev_sel
69-
class __SYCL_EXPORT cpu_selector : public device_selector {
74+
class __SYCL_EXPORT __SYCL2020_DEPRECATED(
75+
"Use the callable sycl::cpu_selector_v instead.") cpu_selector
76+
: public device_selector {
7077
public:
7178
int operator()(const device &dev) const override;
7279
};
@@ -76,7 +83,9 @@ class __SYCL_EXPORT cpu_selector : public device_selector {
7683
/// \sa device
7784
///
7885
/// \ingroup sycl_api_dev_sel
79-
class __SYCL_EXPORT accelerator_selector : public device_selector {
86+
class __SYCL_EXPORT
87+
__SYCL2020_DEPRECATED("Use the callable sycl::accelerator_selector_v instead.")
88+
accelerator_selector : public device_selector {
8089
public:
8190
int operator()(const device &dev) const override;
8291
};
@@ -86,7 +95,9 @@ class __SYCL_EXPORT accelerator_selector : public device_selector {
8695
/// \sa device
8796
///
8897
/// \ingroup sycl_api_dev_sel
89-
class __SYCL_EXPORT host_selector : public device_selector {
98+
class __SYCL_EXPORT
99+
__SYCL2020_DEPRECATED("Use a callable function instead.") host_selector
100+
: public device_selector {
90101
public:
91102
int operator()(const device &dev) const override;
92103
};

sycl/include/sycl/platform.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class __SYCL_EXPORT platform {
6464
/// provided device selector.
6565
///
6666
/// \param DeviceSelector is an instance of a SYCL 1.2.1 device_selector
67+
__SYCL2020_DEPRECATED("Use Callable device selectors instead of deprecated "
68+
"device_selector subclasses.")
6769
explicit platform(const device_selector &DeviceSelector);
6870

6971
#if __cplusplus >= 201703L

sycl/include/sycl/queue.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class __SYCL_EXPORT queue {
163163
///
164164
/// \param DeviceSelector is an instance of a SYCL 1.2.1 device_selector.
165165
/// \param PropList is a list of properties for queue construction.
166+
__SYCL2020_DEPRECATED("Use Callable device selectors instead of deprecated "
167+
"device_selector subclasses.")
166168
queue(const device_selector &DeviceSelector,
167169
const property_list &PropList = {})
168170
: queue(DeviceSelector.select_device(), async_handler{}, PropList) {}
@@ -173,6 +175,8 @@ class __SYCL_EXPORT queue {
173175
/// \param DeviceSelector is an instance of SYCL 1.2.1 device_selector.
174176
/// \param AsyncHandler is a SYCL asynchronous exception handler.
175177
/// \param PropList is a list of properties for queue construction.
178+
__SYCL2020_DEPRECATED("Use Callable device selectors instead of deprecated "
179+
"device_selector subclasses.")
176180
queue(const device_selector &DeviceSelector,
177181
const async_handler &AsyncHandler, const property_list &PropList = {})
178182
: queue(DeviceSelector.select_device(), AsyncHandler, PropList) {}
@@ -199,6 +203,8 @@ class __SYCL_EXPORT queue {
199203
/// \param SyclContext is an instance of SYCL context.
200204
/// \param DeviceSelector is an instance of SYCL device selector.
201205
/// \param PropList is a list of properties for queue construction.
206+
__SYCL2020_DEPRECATED("Use Callable device selectors instead of deprecated "
207+
"device_selector subclasses.")
202208
queue(const context &SyclContext, const device_selector &DeviceSelector,
203209
const property_list &PropList = {});
204210

@@ -210,6 +216,8 @@ class __SYCL_EXPORT queue {
210216
/// \param DeviceSelector is an instance of SYCL device selector.
211217
/// \param AsyncHandler is a SYCL asynchronous exception handler.
212218
/// \param PropList is a list of properties for queue construction.
219+
__SYCL2020_DEPRECATED("Use Callable device selectors instead of deprecated "
220+
"device_selector subclasses.")
213221
queue(const context &SyclContext, const device_selector &DeviceSelector,
214222
const async_handler &AsyncHandler, const property_list &PropList = {});
215223

sycl/test/basic_tests/accessor/atomic_zero_dimension_accessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void store(atomic_t foo, int value) { foo.store(value); }
1919

2020
int main(int argc, char *argv[]) {
2121

22-
queue q(default_selector{});
22+
queue q(default_selector_v);
2323

2424
// Accessor with dimensionality 0.
2525
{

sycl/test/extensions/inline_asm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main() {
3131
sycl::buffer<DataType, 1> BufB(DataB, DEFAULT_PROBLEM_SIZE);
3232
sycl::buffer<DataType, 1> BufC(DataC, DEFAULT_PROBLEM_SIZE);
3333

34-
sycl::queue deviceQueue(sycl::gpu_selector{}, AsyncHandler);
34+
sycl::queue deviceQueue(sycl::gpu_selector_v, AsyncHandler);
3535

3636
deviceQueue.submit([&](sycl::handler &cgh) {
3737
auto A = BufA.get_access<sycl::access::mode::read>(cgh);

sycl/test/warnings/sycl_2020_deprecations.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx %fsycl-host-only -fsyntax-only -sycl-std=2020 -Xclang -verify -Xclang -verify-ignore-unexpected=note %s -o %t.out
1+
// RUN: %clangxx %fsycl-host-only -fsyntax-only -ferror-limit=100 -sycl-std=2020 -Xclang -verify -Xclang -verify-ignore-unexpected=note %s -o %t.out
22

33
#include <CL/sycl.hpp>
44
#include <sycl/ext/intel/online_compiler.hpp>
@@ -194,6 +194,17 @@ int main() {
194194
// expected-warning@+1{{'get_linear_id' is deprecated: use sycl::group::get_group_linear_id() instead}}
195195
group.get_linear_id();
196196

197+
// expected-warning@+1{{'default_selector' is deprecated: Use the callable sycl::default_selector_v instead.}}
198+
sycl::default_selector ds;
199+
// expected-warning@+1{{'cpu_selector' is deprecated: Use the callable sycl::cpu_selector_v instead.}}
200+
sycl::cpu_selector cs;
201+
// expected-warning@+1{{'gpu_selector' is deprecated: Use the callable sycl::gpu_selector_v instead.}}
202+
sycl::gpu_selector gs;
203+
// expected-warning@+1{{'accelerator_selector' is deprecated: Use the callable sycl::accelerator_selector_v instead.}}
204+
sycl::accelerator_selector as;
205+
// expected-warning@+1{{'host_selector' is deprecated: Use a callable function instead.}}
206+
sycl::host_selector hs;
207+
197208
// expected-warning@+2{{'local' is deprecated: use `local_accessor` instead}}
198209
Queue.submit([&](sycl::handler &CGH) {
199210
sycl::accessor<int, 1, sycl::access::mode::read_write, sycl::target::local>

sycl/unittests/assert/assert.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void ChildProcess(int StdErrFD) {
438438
exit(1);
439439
}
440440

441-
sycl::platform Plt{sycl::default_selector()};
441+
sycl::platform Plt;
442442

443443
sycl::unittest::PiMock Mock{Plt};
444444

@@ -516,7 +516,7 @@ void ParentProcess(int ChildPID, int ChildStdErrFD) {
516516
TEST(Assert, TestPositive) {
517517
// Preliminary checks
518518
{
519-
sycl::platform Plt{sycl::default_selector()};
519+
sycl::platform Plt;
520520
if (Plt.is_host()) {
521521
printf("Test is not supported on host, skipping\n");
522522
return;
@@ -572,7 +572,7 @@ TEST(Assert, TestAssertServiceKernelHidden) {
572572
}
573573

574574
TEST(Assert, TestInteropKernelNegative) {
575-
sycl::platform Plt{sycl::default_selector()};
575+
sycl::platform Plt;
576576

577577
if (Plt.is_host()) {
578578
printf("Test is not supported on host, skipping\n");
@@ -610,7 +610,7 @@ TEST(Assert, TestInteropKernelNegative) {
610610
}
611611

612612
TEST(Assert, TestInteropKernelFromProgramNegative) {
613-
sycl::platform Plt{sycl::default_selector()};
613+
sycl::platform Plt;
614614

615615
if (Plt.is_host()) {
616616
printf("Test is not supported on host, skipping\n");

sycl/unittests/buffer/BufferLocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static pi_result redefinedDeviceGetInfo(pi_device device,
7171

7272
class BufferTest : public ::testing::Test {
7373
public:
74-
BufferTest() : Plt{sycl::default_selector()} {}
74+
BufferTest() {}
7575

7676
protected:
7777
void SetUp() override {

0 commit comments

Comments
 (0)