1- = sycl_ext_oneapi_device_index
1+ = sycl_ext_oneapi_platform_device_index
22
33:source-highlighter: coderay
44:coderay-linenums-mode: table
@@ -37,7 +37,7 @@ https://github.com/intel/llvm/issues
3737
3838== Dependencies
3939
40- This extension is written against the SYCL 2020 revision 10 specification.
40+ This extension is written against the SYCL 2020 revision 11 specification.
4141All references below to the "core SYCL specification" or to section numbers in
4242the SYCL specification refer to that revision.
4343
@@ -57,10 +57,11 @@ specification.*
5757== Overview
5858
5959Some SYCL applications find it more convenient to represent a device as an
60- integer value rather than using the `device` class.
60+ integer value rather than using the `device` class, where the integer value
61+ represents the index of the device within its platform.
6162The core SYCL specification already allows an application to do this by using
6263the `device` object's index in the list of all devices returned by
63- `device ::get_devices`.
64+ `platform ::get_devices`.
6465However, converting between a `device` object and its index could be expensive
6566because the conversion requires a search through all of the devices returned by
6667`get_devices`.
@@ -75,7 +76,8 @@ conversion.
7576This extension provides a feature-test macro as described in the core SYCL
7677specification.
7778An implementation supporting this extension must predefine the macro
78- `SYCL_EXT_ONEAPI_DEVICE_INDEX` to one of the values defined in the table below.
79+ `SYCL_EXT_ONEAPI_PLATFORM_DEVICE_INDEX` to one of the values defined in the
80+ table below.
7981Applications can test for the existence of this macro to determine if the
8082implementation supports this feature, or applications can test the macro's value
8183to determine which of the extension's features the implementation supports.
@@ -89,9 +91,9 @@ to determine which of the extension's features the implementation supports.
8991|Initial version of this extension.
9092|===
9193
92- === New member functions in the device class
94+ === New member function in the device class
9395
94- This extension adds the following new member functions to the `device` class.
96+ This extension adds the following new member function to the `device` class.
9597
9698[frame=all,grid=none,separator="@"]
9799|====
100102----
101103class device {
102104 // ...
103- size_t ext_oneapi_to_index() const;
104- static device ext_oneapi_from_index(size_t index);
105+ size_t ext_oneapi_index_within_platform() const;
105106};
106107----
107108|====
@@ -113,30 +114,49 @@ class device {
113114a@
114115[source,c++]
115116----
116- size_t ext_oneapi_to_index () const;
117+ size_t ext_oneapi_index_within_platform () const;
117118----
118119|====
119120
120121_Returns:_ If this device is a root device as defined by the core SYCL
121122specification, returns the index that it has in the `std::vector` that is
122- returned when calling `device::get_devices()`.
123+ returned when calling `platform::get_devices()` on the platform that contains
124+ this device.
123125
124126_Throws:_ An `exception` with the `errc::invalid` error code if this device is
125127not a root device.
126128
127129'''
128130
131+ === New member function in the platform class
132+
133+ This extension adds the following new member function to the `platform` class.
134+
129135[frame=all,grid=none,separator="@"]
130136|====
131137a@
132138[source,c++]
133139----
134- static device ext_oneapi_from_index(size_t index);
140+ class platform {
141+ // ...
142+ device ext_oneapi_device_at_index(size_t index) const;
143+ };
144+ ----
145+ |====
146+
147+ '''
148+
149+ [frame=all,grid=none,separator="@"]
150+ |====
151+ a@
152+ [source,c++]
153+ ----
154+ device ext_oneapi_device_at_index(size_t index) const;
135155----
136156|====
137157
138158_Returns:_ If the `index` is within range of the `std::vector` that is returned
139- when calling `device ::get_devices()`, returns a copy of the `device` object
159+ when calling `platform ::get_devices()`, returns a copy of the `device` object
140160which has that index.
141161
142162_Throws:_ An `exception` with the `errc::invalid` error code if the `index` is
@@ -145,6 +165,28 @@ out of range.
145165'''
146166
147167
168+ == {dpcpp} guaranteed compatibility with Level Zero and OpenCL backends
169+
170+ The contents of this section are non-normative and apply only to the {dpcpp}
171+ implementation.
172+ The device index returned from `device::ext_oneapi_index_within_platform` is
173+ compatible with the index of the underlying backend device when the
174+ `ONEAPI_DEVICE_SELECTOR` environment variable is not set.
175+ Specifically, the following guarantees are provided.
176+
177+ * When the platform's backend is `backend::ext_oneapi_level_zero`, the index
178+ returned from `device::ext_oneapi_index_within_platform` matches the index of
179+ the device's underlying `ze_device_handle_t` within the list of handles
180+ returned from `zeDeviceGet`.
181+ As a result, the SYCL device index is equivalent to the Level Zero index
182+ returned from `zerTranslateDeviceHandleToIdentifier`.
183+
184+ * When the platform's backend is `backend::opencl`, the index returned from
185+ `device::ext_oneapi_index_within_platform` matches the index of the device's
186+ underlying `cl_device_id` within the list of IDs returned from
187+ `clGetDeviceIDs`.
188+
189+
148190== Example
149191
150192[source,c++]
@@ -154,9 +196,10 @@ out of range.
154196int main() {
155197 sycl::device d1; // Get the default device.
156198 // There is no guarantee this has index 0.
199+ sycl::platform p; // Get the platform containing the default device.
157200
158- size_t index = d1.ext_oneapi_to_index ();
159- sycl::device d2 = sycl::device::ext_oneapi_from_index (index);
201+ size_t index = d1.ext_oneapi_index_within_platform ();
202+ sycl::device d2 = p.ext_oneapi_device_at_index (index);
160203 assert(d1 == d2);
161204}
162205----
0 commit comments