Skip to content

Commit a2d44f7

Browse files
[NFCI][SYCL] Make sure platform_impl could only be owned by GlobalHandler (#18141)
This is a pre-requisite to eliminate `PlatformImplPtr` and use `platform_impl` by raw pointer/reference throught the SYCL RT library.
1 parent 2726476 commit a2d44f7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

sycl/source/detail/platform_impl.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ platform_impl::getOrMakePlatformImpl(ur_platform_handle_t UrPlatform,
5050
return PlatImpl;
5151
}
5252

53-
// Otherwise make the impl
54-
Result = std::make_shared<platform_impl>(UrPlatform, Adapter);
53+
// Otherwise make the impl. Our ctor/dtor are private, so std::make_shared
54+
// needs a bit of help...
55+
struct creator : platform_impl {
56+
creator(ur_platform_handle_t APlatform, const AdapterPtr &AAdapter)
57+
: platform_impl(APlatform, AAdapter) {}
58+
};
59+
Result = std::make_shared<creator>(UrPlatform, Adapter);
5560
PlatformCache.emplace_back(Result);
5661
}
5762

sycl/source/detail/platform_impl.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ class device_impl;
3232
// TODO: implement extension management for host device
3333
// TODO: implement parameters treatment for host device
3434
class platform_impl {
35-
public:
3635
/// Constructs platform_impl from a UR platform handle.
3736
///
3837
/// \param APlatform is a raw plug-in platform handle.
3938
/// \param AAdapter is a plug-in handle.
39+
//
40+
// Platforms can only be created under `GlobalHandler`'s ownership via
41+
// `platform_impl::getOrMakePlatformImpl` method.
4042
explicit platform_impl(ur_platform_handle_t APlatform,
4143
const std::shared_ptr<Adapter> &AAdapter)
4244
: MPlatform(APlatform), MAdapter(AAdapter) {
@@ -50,6 +52,7 @@ class platform_impl {
5052

5153
~platform_impl() = default;
5254

55+
public:
5356
/// Checks if this platform supports extension.
5457
///
5558
/// \param ExtensionName is a string containing extension name.

0 commit comments

Comments
 (0)