@@ -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
710710explained in following section [Code the program for a specific
711711GPU](#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
761761int 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
786782there 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
0 commit comments