Skip to content

Commit 34913f9

Browse files
[SYCL] Make sycl::platform use raw platform_impl * for its impl
Similar to intel#20821.
1 parent f2abf71 commit 34913f9

File tree

10 files changed

+29
-38
lines changed

10 files changed

+29
-38
lines changed

sycl/gdb/libsycl.so-gdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class SYCLDevice(SYCLValue):
375375
"""Provides information about a sycl::device from a gdb.Value."""
376376

377377
IMPL_OFFSET_TO_PLATFORM = 0x8
378-
PLATFORM_OFFSET_TO_BACKEND = 0x20
378+
PLATFORM_OFFSET_TO_BACKEND = 0x10
379379

380380
def __init__(self, gdb_value):
381381
super().__init__(gdb_value)

sycl/include/sycl/platform.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
207207
private:
208208
ur_native_handle_t getNative() const;
209209

210-
std::shared_ptr<detail::platform_impl> impl;
211-
platform(std::shared_ptr<detail::platform_impl> impl) : impl(impl) {}
210+
detail::platform_impl *impl = nullptr;
211+
platform(detail::platform_impl &impl) : impl(&impl) {}
212212

213213
platform(const device &Device);
214214

sycl/source/detail/global_handler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ Sync &GlobalHandler::getSync() {
179179
return sync;
180180
}
181181

182-
std::vector<std::shared_ptr<platform_impl>> &GlobalHandler::getPlatformCache() {
183-
static std::vector<std::shared_ptr<platform_impl>> &PlatformCache =
182+
std::vector<std::unique_ptr<platform_impl>> &GlobalHandler::getPlatformCache() {
183+
static std::vector<std::unique_ptr<platform_impl>> &PlatformCache =
184184
getOrCreate(MPlatformCache);
185185
return PlatformCache;
186186
}

sycl/source/detail/global_handler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class GlobalHandler {
6363
bool isSchedulerAlive() const;
6464
ProgramManager &getProgramManager();
6565
Sync &getSync();
66-
std::vector<std::shared_ptr<platform_impl>> &getPlatformCache();
66+
std::vector<std::unique_ptr<platform_impl>> &getPlatformCache();
6767

6868
std::unordered_map<platform_impl *, std::shared_ptr<context_impl>> &
6969
getPlatformToDefaultContextCache();
@@ -118,7 +118,7 @@ class GlobalHandler {
118118
InstWithLock<Scheduler> MScheduler;
119119
InstWithLock<ProgramManager> MProgramManager;
120120
InstWithLock<Sync> MSync;
121-
InstWithLock<std::vector<std::shared_ptr<platform_impl>>> MPlatformCache;
121+
InstWithLock<std::vector<std::unique_ptr<platform_impl>>> MPlatformCache;
122122
InstWithLock<
123123
std::unordered_map<platform_impl *, std::shared_ptr<context_impl>>>
124124
MPlatformToDefaultContextCache;

sycl/source/detail/platform_impl.cpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,26 @@ platform_impl::~platform_impl() = default;
4747
platform_impl &
4848
platform_impl::getOrMakePlatformImpl(ur_platform_handle_t UrPlatform,
4949
adapter_impl &Adapter) {
50-
std::shared_ptr<platform_impl> Result;
51-
{
52-
const std::lock_guard<std::mutex> Guard(
53-
GlobalHandler::instance().getPlatformMapMutex());
54-
55-
std::vector<std::shared_ptr<platform_impl>> &PlatformCache =
56-
GlobalHandler::instance().getPlatformCache();
57-
58-
// If we've already seen this platform, return the impl
59-
for (const auto &PlatImpl : PlatformCache) {
60-
if (PlatImpl->getHandleRef() == UrPlatform)
61-
return *PlatImpl;
62-
}
50+
const std::lock_guard<std::mutex> Guard(
51+
GlobalHandler::instance().getPlatformMapMutex());
52+
53+
std::vector<std::unique_ptr<platform_impl>> &PlatformCache =
54+
GlobalHandler::instance().getPlatformCache();
6355

64-
// Otherwise make the impl. Our ctor/dtor are private, so std::make_shared
65-
// needs a bit of help...
66-
struct creator : platform_impl {
67-
creator(ur_platform_handle_t APlatform, adapter_impl &AAdapter)
68-
: platform_impl(APlatform, AAdapter) {}
69-
};
70-
Result = std::make_shared<creator>(UrPlatform, Adapter);
71-
PlatformCache.emplace_back(Result);
56+
// If we've already seen this platform, return the impl
57+
for (const auto &PlatImpl : PlatformCache) {
58+
if (PlatImpl->getHandleRef() == UrPlatform)
59+
return *PlatImpl;
7260
}
7361

74-
return *Result;
62+
// Otherwise make the impl. Our ctor/dtor are private, so std::make_unique
63+
// needs a bit of help...
64+
struct creator : platform_impl {
65+
creator(ur_platform_handle_t APlatform, adapter_impl &AAdapter)
66+
: platform_impl(APlatform, AAdapter) {}
67+
};
68+
return *PlatformCache.emplace_back(
69+
std::make_unique<creator>(UrPlatform, Adapter));
7570
}
7671

7772
platform_impl &

sycl/source/detail/platform_impl.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ enum class aspect;
2929
namespace detail {
3030
class device_impl;
3131

32-
// TODO: implement extension management for host device
33-
// TODO: implement parameters treatment for host device
34-
class platform_impl : public std::enable_shared_from_this<platform_impl> {
32+
class platform_impl {
3533
/// Constructs platform_impl from a UR platform handle.
3634
///
3735
/// \param APlatform is a raw plug-in platform handle.
@@ -41,9 +39,9 @@ class platform_impl : public std::enable_shared_from_this<platform_impl> {
4139
// `platform_impl::getOrMakePlatformImpl` method.
4240
explicit platform_impl(ur_platform_handle_t APlatform, adapter_impl &Adapter);
4341

42+
public:
4443
~platform_impl();
4544

46-
public:
4745
/// Checks if this platform supports extension.
4846
///
4947
/// \param ExtensionName is a string containing extension name.

sycl/source/platform.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ platform::platform(cl_platform_id PlatformId) {
3131
Adapter.call<detail::UrApiKind::urPlatformCreateWithNativeHandle>(
3232
detail::ur::cast<ur_native_handle_t>(PlatformId), Adapter.getUrAdapter(),
3333
/* pProperties = */ nullptr, &UrPlatform);
34-
impl = detail::platform_impl::getOrMakePlatformImpl(UrPlatform, Adapter)
35-
.shared_from_this();
34+
impl = &detail::platform_impl::getOrMakePlatformImpl(UrPlatform, Adapter);
3635
}
3736

3837
// protected constructor for internal use

sycl/test/abi/symbol_size_alignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main() {
6060
check<image<1>, 16, 8>();
6161
check<kernel, 16, 8>();
6262
check<detail::nd_range_view, 32, 8>();
63-
check<platform, 16, 8>();
63+
check<platform, 8, 8>();
6464
#ifdef __SYCL_DEVICE_ONLY__
6565
check<private_memory<int, 1>, 4, 4>();
6666
check<detail::sampler_impl, 8, 8>();

sycl/test/gdb/printers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ sycl::item<2, false> item_wo_offset =
6767
// CHECK: 120 | void * MUserPtr
6868

6969
// CHECK: 0 | class sycl::detail::platform_impl
70-
// CHECK: 32 | backend MBackend
70+
// CHECK: 16 | backend MBackend
7171

7272
// CHECK: 0 | class sycl::detail::device_impl
7373
// CHECK: 8 | platform_impl & MPlatform

sycl/unittests/Extensions/CommandGraph/InOrderQueue.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ TEST_F(CommandGraphTest, InOrderQueueEventlessWithDependency) {
642642
return UR_RESULT_SUCCESS;
643643
};
644644

645-
sycl::unittest::UrMock<> Mock;
646645
mock::getCallbacks().set_before_callback("urEnqueueCommandBufferExp",
647646
beforeUrEnqueueCommandBufferExp);
648647

0 commit comments

Comments
 (0)