Skip to content

Commit b6f2cce

Browse files
committed
Unify getOrMakeSubDeviceImpl with getOrMakeDeviceImpl
1 parent 1344429 commit b6f2cce

File tree

4 files changed

+11
-35
lines changed

4 files changed

+11
-35
lines changed

sycl/source/detail/device_impl.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,13 @@ std::vector<device> device_impl::create_sub_devices(
163163
// times with the same arguments?
164164
//
165165
std::vector<device> res;
166-
std::for_each(SubDevices.begin(), SubDevices.end(),
167-
[&res, this](const ur_device_handle_t &a_ur_device) {
168-
device sycl_device = detail::createSyclObjFromImpl<device>(
169-
MPlatform.getOrMakeSubDeviceImpl(a_ur_device));
170-
res.push_back(sycl_device);
171-
});
166+
std::for_each(
167+
SubDevices.begin(), SubDevices.end(),
168+
[&res, this](const ur_device_handle_t &a_ur_device) {
169+
device sycl_device = detail::createSyclObjFromImpl<device>(
170+
MPlatform.getOrMakeDeviceImpl(a_ur_device, true /*IsSubDevice*/));
171+
res.push_back(sycl_device);
172+
});
172173
return res;
173174
}
174175

sycl/source/detail/device_impl.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
429429
/// Constructs a SYCL device instance using the provided
430430
/// UR device instance.
431431
//
432-
// Must be called through `platform_impl::getOrMakeDeviceImpl` or
433-
// `platform_impl::getOrMakeSubDeviceImpl` only.
432+
// Must be called through `platform_impl::getOrMakeDeviceImpl` only.
434433
// `private_tag` ensures that is true.
435434
explicit device_impl(ur_device_handle_t Device, platform_impl &Platform,
436435
private_tag, bool IsSubDevice);

sycl/source/detail/platform_impl.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -298,29 +298,16 @@ device_impl *platform_impl::getDeviceImpl(ur_device_handle_t UrDevice) {
298298
return getDeviceImplHelper(UrDevice);
299299
}
300300

301-
device_impl &platform_impl::getOrMakeDeviceImpl(ur_device_handle_t UrDevice) {
301+
device_impl &platform_impl::getOrMakeDeviceImpl(ur_device_handle_t UrDevice,
302+
bool IsSubDevice = false) {
302303
const std::lock_guard<std::mutex> Guard(MDeviceMapMutex);
303304
// If we've already seen this device, return the impl
304305
if (device_impl *Result = getDeviceImplHelper(UrDevice))
305306
return *Result;
306307

307308
// Otherwise make the impl
308309
MDevices.emplace_back(std::make_shared<device_impl>(
309-
UrDevice, *this, device_impl::private_tag{}, false /*IsSubDevice*/));
310-
311-
return *MDevices.back();
312-
}
313-
314-
device_impl &
315-
platform_impl::getOrMakeSubDeviceImpl(ur_device_handle_t UrSubDevice) {
316-
const std::lock_guard<std::mutex> Guard(MDeviceMapMutex);
317-
// If we've already seen this device, return the impl
318-
if (device_impl *Result = getDeviceImplHelper(UrSubDevice))
319-
return *Result;
320-
321-
// Otherwise make the impl
322-
MDevices.emplace_back(std::make_shared<device_impl>(
323-
UrSubDevice, *this, device_impl::private_tag{}, true /*IsSubDevice*/));
310+
UrDevice, *this, device_impl::private_tag{}, IsSubDevice));
324311

325312
return *MDevices.back();
326313
}

sycl/source/detail/platform_impl.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,6 @@ class platform_impl : public std::enable_shared_from_this<platform_impl> {
172172
/// \return a device_impl* corresponding to the device
173173
device_impl &getOrMakeDeviceImpl(ur_device_handle_t UrDevice);
174174

175-
/// Queries the device_impl cache to either return a shared_ptr
176-
/// for the device_impl corresponding to the UrSubDevice or add
177-
/// a new entry to the cache
178-
///
179-
/// \param UrSubDevice is the UrSubDevice whose impl is requested
180-
///
181-
/// \param PlatormImpl is the Platform for that Device
182-
///
183-
/// \return a device_impl* corresponding to the subdevice
184-
device_impl &getOrMakeSubDeviceImpl(ur_device_handle_t UrSubDevice);
185-
186175
/// Queries the cache to see if the specified UR platform has been seen
187176
/// before. If so, return the cached platform_impl, otherwise create a new
188177
/// one and cache it.

0 commit comments

Comments
 (0)