Skip to content

Commit a997761

Browse files
authored
[SYCL] Return shared_ptr<platform_impl> by ref (#17750)
Change the return type of getPlatformImpl() to a reference in the context_impl and device_impl classes.
1 parent 172e909 commit a997761

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

sycl/source/detail/buffer_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ buffer_impl::getNativeVector(backend BackendName) const {
7979
// doesn't have context and platform
8080
if (!Ctx)
8181
continue;
82-
PlatformImplPtr Platform = Ctx->getPlatformImpl();
82+
const PlatformImplPtr &Platform = Ctx->getPlatformImpl();
8383
assert(Platform && "Platform must be present for device context");
8484
if (Platform->getBackend() != BackendName)
8585
continue;

sycl/source/detail/context_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class context_impl {
9090
const AdapterPtr &getAdapter() const { return MPlatform->getAdapter(); }
9191

9292
/// \return the PlatformImpl associated with this context.
93-
PlatformImplPtr getPlatformImpl() const { return MPlatform; }
93+
const PlatformImplPtr &getPlatformImpl() const { return MPlatform; }
9494

9595
/// Queries this context for information.
9696
///

sycl/source/detail/device_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class device_impl {
290290

291291
/// @brief Get the platform impl serving this device
292292
/// @return PlatformImplPtr
293-
PlatformImplPtr getPlatformImpl() const { return MPlatform; }
293+
const PlatformImplPtr &getPlatformImpl() const { return MPlatform; }
294294

295295
/// Get device info string
296296
std::string get_device_info_string(ur_device_info_t InfoCode) const;

sycl/source/detail/usm/usm_impl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ device get_pointer_device(const void *Ptr, const context &Ctxt) {
600600

601601
// The device is not necessarily a member of the context, it could be a
602602
// member's descendant instead. Fetch the corresponding device from the cache.
603-
std::shared_ptr<detail::platform_impl> PltImpl = CtxImpl->getPlatformImpl();
603+
const std::shared_ptr<detail::platform_impl> &PltImpl =
604+
CtxImpl->getPlatformImpl();
604605
std::shared_ptr<detail::device_impl> DevImpl =
605606
PltImpl->getDeviceImpl(DeviceId);
606607
if (DevImpl)

0 commit comments

Comments
 (0)