@@ -29,17 +29,15 @@ namespace sycl {
29
29
inline namespace _V1 {
30
30
namespace detail {
31
31
32
- context_impl::context_impl (const std::vector<sycl::device> Devices,
33
- async_handler AsyncHandler,
32
+ context_impl::context_impl (devices_range Devices, async_handler AsyncHandler,
34
33
const property_list &PropList, private_tag)
35
34
: MOwnedByRuntime(true ), MAsyncHandler(std::move(AsyncHandler)),
36
- MDevices (std::move(Devices)), MContext(nullptr ),
37
- MPlatform(detail::getSyclObjImpl(MDevices[0 ].get_platform())),
38
- MPropList(PropList), MKernelProgramCache(*this ),
39
- MSupportBufferLocationByDevices(NotChecked) {
35
+ MDevices (Devices.to<std::vector<device_impl *>>()), MContext(nullptr ),
36
+ MPlatform(MDevices[0 ]->getPlatformImpl ()), MPropList(PropList),
37
+ MKernelProgramCache(*this ), MSupportBufferLocationByDevices(NotChecked) {
40
38
verifyProps (PropList);
41
39
std::vector<ur_device_handle_t > DeviceIds;
42
- for (const auto &D : MDevices) {
40
+ for (device_impl &D : devices_range{ MDevices} ) {
43
41
if (D.has (aspect::ext_oneapi_is_composite)) {
44
42
// Component devices are considered to be descendent devices from a
45
43
// composite device and therefore context created for a composite
@@ -52,7 +50,7 @@ context_impl::context_impl(const std::vector<sycl::device> Devices,
52
50
DeviceIds.push_back (getSyclObjImpl (CD)->getHandleRef ());
53
51
}
54
52
55
- DeviceIds.push_back (getSyclObjImpl (D)-> getHandleRef ());
53
+ DeviceIds.push_back (D. getHandleRef ());
56
54
}
57
55
58
56
getAdapter ().call <UrApiKind::urContextCreate>(
@@ -61,39 +59,42 @@ context_impl::context_impl(const std::vector<sycl::device> Devices,
61
59
62
60
context_impl::context_impl (ur_context_handle_t UrContext,
63
61
async_handler AsyncHandler, adapter_impl &Adapter,
64
- const std::vector<sycl::device> & DeviceList,
65
- bool OwnedByRuntime, private_tag)
62
+ devices_range DeviceList, bool OwnedByRuntime ,
63
+ private_tag)
66
64
: MOwnedByRuntime(OwnedByRuntime), MAsyncHandler(std::move(AsyncHandler)),
67
- MDevices(DeviceList), MContext(UrContext), MPlatform(),
65
+ MDevices([&]() {
66
+ if (!DeviceList.empty ())
67
+ return DeviceList.to <std::vector<device_impl *>>();
68
+
69
+ std::vector<ur_device_handle_t > DeviceIds;
70
+ uint32_t DevicesNum = 0 ;
71
+ // TODO catch an exception and put it to list of asynchronous
72
+ // exceptions.
73
+ Adapter.call <UrApiKind::urContextGetInfo>(
74
+ UrContext, UR_CONTEXT_INFO_NUM_DEVICES, sizeof (DevicesNum),
75
+ &DevicesNum, nullptr );
76
+ DeviceIds.resize (DevicesNum);
77
+ // TODO catch an exception and put it to list of asynchronous
78
+ // exceptions.
79
+ Adapter.call <UrApiKind::urContextGetInfo>(
80
+ UrContext, UR_CONTEXT_INFO_DEVICES,
81
+ sizeof (ur_device_handle_t ) * DevicesNum, &DeviceIds[0 ], nullptr );
82
+
83
+ if (DeviceIds.empty ())
84
+ throw exception (
85
+ make_error_code (errc::invalid),
86
+ " No devices in the provided device list and native context." );
87
+
88
+ platform_impl &Platform =
89
+ platform_impl::getPlatformFromUrDevice (DeviceIds[0 ], Adapter);
90
+ std::vector<device_impl *> Devices;
91
+ for (ur_device_handle_t Dev : DeviceIds)
92
+ Devices.emplace_back (&Platform.getOrMakeDeviceImpl (Dev));
93
+
94
+ return Devices;
95
+ }()),
96
+ MContext(UrContext), MPlatform(MDevices[0 ]->getPlatformImpl ()),
68
97
MKernelProgramCache(*this ), MSupportBufferLocationByDevices(NotChecked) {
69
- if (!MDevices.empty ()) {
70
- MPlatform = detail::getSyclObjImpl (MDevices[0 ].get_platform ());
71
- } else {
72
- std::vector<ur_device_handle_t > DeviceIds;
73
- uint32_t DevicesNum = 0 ;
74
- // TODO catch an exception and put it to list of asynchronous exceptions
75
- Adapter.call <UrApiKind::urContextGetInfo>(
76
- MContext, UR_CONTEXT_INFO_NUM_DEVICES, sizeof (DevicesNum), &DevicesNum,
77
- nullptr );
78
- DeviceIds.resize (DevicesNum);
79
- // TODO catch an exception and put it to list of asynchronous exceptions
80
- Adapter.call <UrApiKind::urContextGetInfo>(
81
- MContext, UR_CONTEXT_INFO_DEVICES,
82
- sizeof (ur_device_handle_t ) * DevicesNum, &DeviceIds[0 ], nullptr );
83
-
84
- if (DeviceIds.empty ())
85
- throw exception (
86
- make_error_code (errc::invalid),
87
- " No devices in the provided device list and native context." );
88
-
89
- platform_impl &Platform =
90
- platform_impl::getPlatformFromUrDevice (DeviceIds[0 ], Adapter);
91
- for (ur_device_handle_t Dev : DeviceIds) {
92
- MDevices.emplace_back (
93
- createSyclObjFromImpl<device>(Platform.getOrMakeDeviceImpl (Dev)));
94
- }
95
- MPlatform = Platform.shared_from_this ();
96
- }
97
98
// TODO catch an exception and put it to list of asynchronous exceptions
98
99
// getAdapter() will be the same as the Adapter passed. This should be taken
99
100
// care of when creating device object.
@@ -144,12 +145,12 @@ uint32_t context_impl::get_info<info::context::reference_count>() const {
144
145
this ->getAdapter ());
145
146
}
146
147
template <> platform context_impl::get_info<info::context::platform>() const {
147
- return createSyclObjFromImpl<platform>(* MPlatform);
148
+ return createSyclObjFromImpl<platform>(MPlatform);
148
149
}
149
150
template <>
150
151
std::vector<sycl::device>
151
152
context_impl::get_info<info::context::devices>() const {
152
- return MDevices;
153
+ return devices_range{ MDevices}. to <std::vector<sycl::device>>() ;
153
154
}
154
155
template <>
155
156
std::vector<sycl::memory_order>
@@ -219,7 +220,7 @@ context_impl::get_backend_info<info::platform::version>() const {
219
220
" the info::platform::version info descriptor can "
220
221
" only be queried with an OpenCL backend" );
221
222
}
222
- return MDevices[0 ]. get_platform ().get_info <info::platform::version>();
223
+ return MDevices[0 ]-> get_platform ().get_info <info::platform::version>();
223
224
}
224
225
#endif
225
226
@@ -271,17 +272,17 @@ KernelProgramCache &context_impl::getKernelProgramCache() const {
271
272
}
272
273
273
274
bool context_impl::hasDevice (const detail::device_impl &Device) const {
274
- for (auto D : MDevices)
275
- if (getSyclObjImpl (D). get () == &Device)
275
+ for (device_impl * D : MDevices)
276
+ if (D == &Device)
276
277
return true ;
277
278
return false ;
278
279
}
279
280
280
281
device_impl *
281
282
context_impl::findMatchingDeviceImpl (ur_device_handle_t &DeviceUR) const {
282
- for (device D : MDevices)
283
- if (getSyclObjImpl (D) ->getHandleRef () == DeviceUR)
284
- return getSyclObjImpl (D). get () ;
283
+ for (device_impl * D : MDevices)
284
+ if (D ->getHandleRef () == DeviceUR)
285
+ return D ;
285
286
286
287
return nullptr ;
287
288
}
@@ -301,8 +302,8 @@ bool context_impl::isBufferLocationSupported() const {
301
302
return MSupportBufferLocationByDevices == Supported ? true : false ;
302
303
// Check that devices within context have support of buffer location
303
304
MSupportBufferLocationByDevices = Supported;
304
- for (auto & Device : MDevices) {
305
- if (!Device. has_extension (" cl_intel_mem_alloc_buffer_location" )) {
305
+ for (device_impl * Device : MDevices) {
306
+ if (!Device-> has_extension (" cl_intel_mem_alloc_buffer_location" )) {
306
307
MSupportBufferLocationByDevices = NotSupported;
307
308
break ;
308
309
}
0 commit comments