Skip to content

Commit 9825b68

Browse files
WIP
1 parent 321d0a0 commit 9825b68

29 files changed

+157
-149
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,7 +3545,9 @@ class __SYCL_EXPORT handler {
35453545
UserRange, KernelFunc};
35463546
}
35473547

3548+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
35483549
const std::shared_ptr<detail::context_impl> &getContextImplPtr() const;
3550+
#endif
35493551
detail::context_impl &getContextImpl() const;
35503552

35513553
// Checks if 2D memory operations are supported by the underlying platform.

sycl/include/sycl/interop_handle.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ class interop_handle {
205205
friend class detail::DispatchHostTask;
206206
using ReqToMem = std::pair<detail::AccessorImplHost *, ur_mem_handle_t>;
207207

208+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
209+
// Clean this up (no shared pointers). Not doing it right now because I expect
210+
// there will be several iterations of simplifications possible and it would
211+
// be hard to track which of them made their way into a minor public release
212+
// and which didn't. Let's just clean it up once during ABI breaking window.
213+
#endif
208214
interop_handle(std::vector<ReqToMem> MemObjs,
209215
const std::shared_ptr<detail::queue_impl> &Queue,
210216
const std::shared_ptr<detail::device_impl> &Device,

sycl/source/detail/async_alloc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void *async_malloc(sycl::handler &h, sycl::usm::alloc kind, size_t size) {
6767
sycl::make_error_code(sycl::errc::feature_not_supported),
6868
"Only device backed asynchronous allocations are supported!");
6969

70-
auto &Adapter = h.getContextImplPtr()->getAdapter();
70+
auto &Adapter = h.getContextImpl().getAdapter();
7171

7272
// Get CG event dependencies for this allocation.
7373
const auto &DepEvents = h.impl->CGData.MEvents;
@@ -117,7 +117,7 @@ __SYCL_EXPORT void *async_malloc(const sycl::queue &q, sycl::usm::alloc kind,
117117
__SYCL_EXPORT void *async_malloc_from_pool(sycl::handler &h, size_t size,
118118
const memory_pool &pool) {
119119

120-
auto &Adapter = h.getContextImplPtr()->getAdapter();
120+
auto &Adapter = h.getContextImpl().getAdapter();
121121
auto &memPoolImpl = sycl::detail::getSyclObjImpl(pool);
122122

123123
// Get CG event dependencies for this allocation.

sycl/source/detail/backend_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ inline namespace _V1 {
1515
namespace detail {
1616

1717
template <class T> backend getImplBackend(const T &Impl) {
18-
return Impl->getContextImplPtr()->getBackend();
18+
return Impl->getContextImpl().getBackend();
1919
}
2020

2121
} // namespace detail

sycl/source/detail/bindless_images.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,9 @@ get_image_memory_support(const image_descriptor &imageDescriptor,
813813
const sycl::context &syclContext) {
814814
std::shared_ptr<sycl::detail::device_impl> DevImpl =
815815
sycl::detail::getSyclObjImpl(syclDevice);
816-
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
817-
sycl::detail::getSyclObjImpl(syclContext);
818-
const sycl::detail::AdapterPtr &Adapter = CtxImpl->getAdapter();
816+
sycl::detail::context_impl &CtxImpl =
817+
*sycl::detail::getSyclObjImpl(syclContext);
818+
const sycl::detail::AdapterPtr &Adapter = CtxImpl.getAdapter();
819819

820820
ur_image_desc_t urDesc;
821821
ur_image_format_t urFormat;
@@ -825,15 +825,15 @@ get_image_memory_support(const image_descriptor &imageDescriptor,
825825
Adapter->call<sycl::errc::runtime,
826826
sycl::detail::UrApiKind::
827827
urBindlessImagesGetImageMemoryHandleTypeSupportExp>(
828-
CtxImpl->getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
828+
CtxImpl.getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
829829
ur_exp_image_mem_type_t::UR_EXP_IMAGE_MEM_TYPE_USM_POINTER,
830830
&supportsPointerAllocation);
831831

832832
ur_bool_t supportsOpaqueAllocation{0};
833833
Adapter->call<sycl::errc::runtime,
834834
sycl::detail::UrApiKind::
835835
urBindlessImagesGetImageMemoryHandleTypeSupportExp>(
836-
CtxImpl->getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
836+
CtxImpl.getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
837837
ur_exp_image_mem_type_t::UR_EXP_IMAGE_MEM_TYPE_OPAQUE_HANDLE,
838838
&supportsOpaqueAllocation);
839839

@@ -864,9 +864,9 @@ __SYCL_EXPORT bool is_image_handle_supported<unsampled_image_handle>(
864864
const sycl::device &syclDevice, const sycl::context &syclContext) {
865865
std::shared_ptr<sycl::detail::device_impl> DevImpl =
866866
sycl::detail::getSyclObjImpl(syclDevice);
867-
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
868-
sycl::detail::getSyclObjImpl(syclContext);
869-
const sycl::detail::AdapterPtr &Adapter = CtxImpl->getAdapter();
867+
sycl::detail::context_impl &CtxImpl =
868+
*sycl::detail::getSyclObjImpl(syclContext);
869+
const sycl::detail::AdapterPtr &Adapter = CtxImpl.getAdapter();
870870

871871
ur_image_desc_t urDesc;
872872
ur_image_format_t urFormat;
@@ -881,7 +881,7 @@ __SYCL_EXPORT bool is_image_handle_supported<unsampled_image_handle>(
881881
Adapter->call<sycl::errc::runtime,
882882
sycl::detail::UrApiKind::
883883
urBindlessImagesGetImageUnsampledHandleSupportExp>(
884-
CtxImpl->getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
884+
CtxImpl.getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
885885
memHandleType, &supportsUnsampledHandle);
886886

887887
return supportsUnsampledHandle;
@@ -904,9 +904,9 @@ __SYCL_EXPORT bool is_image_handle_supported<sampled_image_handle>(
904904
const sycl::device &syclDevice, const sycl::context &syclContext) {
905905
std::shared_ptr<sycl::detail::device_impl> DevImpl =
906906
sycl::detail::getSyclObjImpl(syclDevice);
907-
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
908-
sycl::detail::getSyclObjImpl(syclContext);
909-
const sycl::detail::AdapterPtr &Adapter = CtxImpl->getAdapter();
907+
sycl::detail::context_impl &CtxImpl =
908+
*sycl::detail::getSyclObjImpl(syclContext);
909+
const sycl::detail::AdapterPtr &Adapter = CtxImpl.getAdapter();
910910

911911
ur_image_desc_t urDesc;
912912
ur_image_format_t urFormat;
@@ -921,7 +921,7 @@ __SYCL_EXPORT bool is_image_handle_supported<sampled_image_handle>(
921921
Adapter->call<
922922
sycl::errc::runtime,
923923
sycl::detail::UrApiKind::urBindlessImagesGetImageSampledHandleSupportExp>(
924-
CtxImpl->getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
924+
CtxImpl.getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
925925
memHandleType, &supportsSampledHandle);
926926

927927
return supportsSampledHandle;

sycl/source/detail/cg.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,9 @@ class CGHostTask : public CG {
726726
std::vector<ArgDesc> MArgs;
727727

728728
CGHostTask(std::shared_ptr<HostTask> HostTask, detail::queue_impl *Queue,
729-
std::shared_ptr<detail::context_impl> Context,
730-
std::vector<ArgDesc> Args, CG::StorageInitHelper CGData,
731-
CGType Type, detail::code_location loc = {});
729+
detail::context_impl *Context, std::vector<ArgDesc> Args,
730+
CG::StorageInitHelper CGData, CGType Type,
731+
detail::code_location loc = {});
732732
};
733733

734734
} // namespace detail

sycl/source/detail/device_image_impl.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,13 @@ class device_image_impl {
570570

571571
ur_native_handle_t getNative() const {
572572
assert(MProgram);
573-
const auto &ContextImplPtr = detail::getSyclObjImpl(MContext);
574-
const AdapterPtr &Adapter = ContextImplPtr->getAdapter();
573+
context_impl &ContextImpl = *detail::getSyclObjImpl(MContext);
574+
const AdapterPtr &Adapter = ContextImpl.getAdapter();
575575

576576
ur_native_handle_t NativeProgram = 0;
577577
Adapter->call<UrApiKind::urProgramGetNativeHandle>(MProgram,
578578
&NativeProgram);
579-
if (ContextImplPtr->getBackend() == backend::opencl)
579+
if (ContextImpl.getBackend() == backend::opencl)
580580
__SYCL_OCL_CALL(clRetainProgram, ur::cast<cl_program>(NativeProgram));
581581

582582
return NativeProgram;

sycl/source/detail/event_impl.hpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class context;
2929
namespace detail {
3030
class Adapter;
3131
class context_impl;
32-
using ContextImplPtr = std::shared_ptr<sycl::detail::context_impl>;
3332
class queue_impl;
3433
class event_impl;
3534
using EventImplPtr = std::shared_ptr<sycl::detail::event_impl>;
@@ -312,12 +311,6 @@ class event_impl {
312311

313312
bool isDefaultConstructed() const noexcept { return MIsDefaultConstructed; }
314313

315-
ContextImplPtr getContextImplPtr() {
316-
if (MIsDefaultConstructed)
317-
initContextIfNeeded();
318-
return MContext;
319-
}
320-
321314
// Sets a sync point which is used when this event represents an enqueue to a
322315
// Command Buffer.
323316
void setSyncPoint(ur_exp_command_buffer_sync_point_t SyncPoint) {
@@ -394,7 +387,7 @@ class event_impl {
394387
std::atomic<ur_event_handle_t> MEvent = nullptr;
395388
// Stores submission time of command associated with event
396389
uint64_t MSubmitTime = 0;
397-
ContextImplPtr MContext;
390+
std::shared_ptr<context_impl> MContext;
398391
std::unique_ptr<HostProfilingInfo> MHostProfilingInfo;
399392
void *MCommand = nullptr;
400393
std::weak_ptr<queue_impl> MQueue;

sycl/source/detail/global_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ ProgramManager &GlobalHandler::getProgramManager() {
185185
return PM;
186186
}
187187

188-
std::unordered_map<platform_impl *, ContextImplPtr> &
188+
std::unordered_map<platform_impl *, std::shared_ptr<context_impl>> &
189189
GlobalHandler::getPlatformToDefaultContextCache() {
190190
// The optimization with static reference is not done because
191191
// there are public methods of the GlobalHandler

sycl/source/detail/global_handler.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class XPTIRegistry;
2929
class ThreadPool;
3030
struct KernelNameBasedCacheT;
3131

32-
using ContextImplPtr = std::shared_ptr<context_impl>;
3332
using AdapterPtr = std::shared_ptr<Adapter>;
3433

3534
/// Wrapper class for global data structures with non-trivial destructors.
@@ -65,7 +64,7 @@ class GlobalHandler {
6564

6665
void clearPlatforms();
6766

68-
std::unordered_map<platform_impl *, ContextImplPtr> &
67+
std::unordered_map<platform_impl *, std::shared_ptr<context_impl>> &
6968
getPlatformToDefaultContextCache();
7069

7170
std::mutex &getPlatformToDefaultContextCacheMutex();
@@ -121,7 +120,8 @@ class GlobalHandler {
121120
InstWithLock<ProgramManager> MProgramManager;
122121
InstWithLock<Sync> MSync;
123122
InstWithLock<std::vector<std::shared_ptr<platform_impl>>> MPlatformCache;
124-
InstWithLock<std::unordered_map<platform_impl *, ContextImplPtr>>
123+
InstWithLock<
124+
std::unordered_map<platform_impl *, std::shared_ptr<context_impl>>>
125125
MPlatformToDefaultContextCache;
126126
InstWithLock<std::mutex> MPlatformToDefaultContextCacheMutex;
127127
InstWithLock<std::mutex> MPlatformMapMutex;

0 commit comments

Comments
 (0)