@@ -91,35 +91,91 @@ int queryFromNativeHandle(std::vector<sycl::platform> *platform_list,
91
91
zeDeviceGet (l0_drivers[0 ], &l0_device_count, l0_devices.data ());
92
92
93
93
// Create the platform and device objects using the native handle.
94
- auto plt = level_zero::make<sycl::platform>(l0_drivers[0 ]);
95
- auto dev = level_zero::make<sycl::device>(plt, l0_devices[0 ]);
96
-
97
- // Check to see if this platform is in the platform list.
98
- std::cout << " Platform created with native handle: "
99
- << plt.get_info <sycl::info::platform::name>() << std::endl;
100
- auto plt_result = std::find_if (platform_list->begin (), platform_list->end (),
101
- [&](sycl::platform &p) { return p == plt; });
102
- if (plt_result != platform_list->end ()) {
103
- std::cout << " The platform list contains: "
94
+ {
95
+ // Using deprecated level_zero-specific interface. Intentionally copy-pasted
96
+ // and not outlined into a helper because the deprecated interface will be
97
+ // removed in a few months.
98
+ auto plt = level_zero::make<sycl::platform>(l0_drivers[0 ]);
99
+ auto dev = level_zero::make<sycl::device>(plt, l0_devices[0 ]);
100
+
101
+ // Check to see if this platform is in the platform list.
102
+ std::cout << " Platform created with native handle: "
104
103
<< plt.get_info <sycl::info::platform::name>() << std::endl;
105
- } else {
106
- std::cout << plt.get_info <sycl::info::platform::name>()
107
- << " was not in the platform list.\n " ;
108
- failures++;
104
+ auto plt_result = std::find_if (platform_list->begin (), platform_list->end (),
105
+ [&](sycl::platform &p) { return p == plt; });
106
+ if (plt_result != platform_list->end ()) {
107
+ std::cout << " The platform list contains: "
108
+ << plt.get_info <sycl::info::platform::name>() << std::endl;
109
+ } else {
110
+ std::cout << plt.get_info <sycl::info::platform::name>()
111
+ << " was not in the platform list.\n " ;
112
+ failures++;
113
+ }
114
+
115
+ // Check to see if this device is in the device list.
116
+ std::cout << " Device created with native handle: "
117
+ << dev.get_info <sycl::info::device::name>() << std::endl;
118
+ auto dev_result = std::find_if (device_list->begin (), device_list->end (),
119
+ [&](sycl::device &d) { return d == dev; });
120
+ if (dev_result != device_list->end ()) {
121
+ std::cout << " The device list contains: "
122
+ << dev.get_info <sycl::info::device::name>() << std::endl;
123
+ } else {
124
+ std::cout << dev.get_info <sycl::info::device::name>()
125
+ << " was not in the device list.\n " ;
126
+ failures++;
127
+ }
109
128
}
129
+ {
130
+ // Using SYCL2020 interface.
131
+ auto plt = sycl::make_platform<sycl::backend::ext_oneapi_level_zero>(
132
+ l0_drivers[0 ]);
133
+ auto dev =
134
+ sycl::make_device<sycl::backend::ext_oneapi_level_zero>(l0_devices[0 ]);
135
+
136
+ // Check to see if this platform is in the platform list.
137
+ std::cout << " Platform created with native handle: "
138
+ << plt.get_info <sycl::info::platform::name>() << std::endl;
139
+ auto plt_result = std::find_if (platform_list->begin (), platform_list->end (),
140
+ [&](sycl::platform &p) { return p == plt; });
141
+ if (plt_result != platform_list->end ()) {
142
+ std::cout << " The platform list contains: "
143
+ << plt.get_info <sycl::info::platform::name>() << std::endl;
144
+ } else {
145
+ std::cout << plt.get_info <sycl::info::platform::name>()
146
+ << " was not in the platform list.\n " ;
147
+ failures++;
148
+ }
110
149
111
- // Check to see if this device is in the device list.
112
- std::cout << " Device created with native handle: "
113
- << dev.get_info <sycl::info::device::name>() << std::endl;
114
- auto dev_result = std::find_if (device_list->begin (), device_list->end (),
115
- [&](sycl::device &d) { return d == dev; });
116
- if (dev_result != device_list->end ()) {
117
- std::cout << " The device list contains: "
150
+ // Check to see if this device is in the device list.
151
+ std::cout << " Device created with native handle: "
118
152
<< dev.get_info <sycl::info::device::name>() << std::endl;
119
- } else {
120
- std::cout << dev.get_info <sycl::info::device::name>()
121
- << " was not in the device list.\n " ;
122
- failures++;
153
+ auto dev_result = std::find_if (device_list->begin (), device_list->end (),
154
+ [&](sycl::device &d) { return d == dev; });
155
+ if (dev_result != device_list->end ()) {
156
+ // Level-Zero backend specification for sycl::make_device:
157
+ //
158
+ // > Constructs a SYCL device instance from a Level-Zero
159
+ // > ze_device_handle_t. The SYCL execution environment for the Level
160
+ // > Zero backend contains a fixed number of devices that are enumerated
161
+ // > via sycl::device::get_devices() and a fixed number of sub-devices
162
+ // > that are enumerated via sycl::device::create_sub_devices(...).
163
+ // > Calling this function does not create a new device. Rather it
164
+ // > merely creates a sycl::device object that is a copy of one of the
165
+ // > devices from those enumerations.
166
+ //
167
+ // SYCL 2020's common reference semantics says that such a copy must
168
+ // result in the same hash value.
169
+ auto hash = std::hash<sycl::device>{};
170
+ assert (hash (*dev_result) == hash (dev));
171
+
172
+ std::cout << " The device list contains: "
173
+ << dev.get_info <sycl::info::device::name>() << std::endl;
174
+ } else {
175
+ std::cout << dev.get_info <sycl::info::device::name>()
176
+ << " was not in the device list.\n " ;
177
+ failures++;
178
+ }
123
179
}
124
180
return failures;
125
181
}
0 commit comments