Skip to content

Commit c22d5b3

Browse files
[NFC][SYCL] Prefer context_impl & as locals/temporaries (#19148)
Subsequently, use `getContextImpl` instead of `getContextImplPtr` when possible. Continuation of the refactoring in #18795 #18877 #18966 #18979 #18980 #18981 #19007 #19030 #19123 #19126
1 parent 683782e commit c22d5b3

File tree

13 files changed

+43
-41
lines changed

13 files changed

+43
-41
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/source/detail/async_alloc.cpp

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

71-
auto &Adapter = h.getContextImplPtr()->getAdapter();
71+
auto &Adapter = h.getContextImpl().getAdapter();
7272

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

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

124124
// 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/device_image_impl.hpp

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

574574
ur_native_handle_t getNative() const {
575575
assert(MProgram);
576-
const auto &ContextImplPtr = detail::getSyclObjImpl(MContext);
577-
const AdapterPtr &Adapter = ContextImplPtr->getAdapter();
576+
context_impl &ContextImpl = *detail::getSyclObjImpl(MContext);
577+
const AdapterPtr &Adapter = ContextImpl.getAdapter();
578578

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

585585
return NativeProgram;

sycl/source/detail/event_impl.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,6 @@ class event_impl {
312312

313313
bool isDefaultConstructed() const noexcept { return MIsDefaultConstructed; }
314314

315-
ContextImplPtr getContextImplPtr() {
316-
if (MIsDefaultConstructed)
317-
initContextIfNeeded();
318-
return MContext;
319-
}
320-
321315
// Sets a sync point which is used when this event represents an enqueue to a
322316
// Command Buffer.
323317
void setSyncPoint(ur_exp_command_buffer_sync_point_t SyncPoint) {

sycl/source/detail/graph/graph_impl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,16 @@ class graph_impl : public std::enable_shared_from_this<graph_impl> {
268268
/// @return Context associated with graph.
269269
sycl::context getContext() const { return MContext; }
270270

271+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
271272
/// Query for the context impl tied to this graph.
272273
/// @return shared_ptr ref for the context impl associated with graph.
273274
const std::shared_ptr<sycl::detail::context_impl> &getContextImplPtr() const {
274275
return sycl::detail::getSyclObjImpl(MContext);
275276
}
277+
#endif
278+
sycl::detail::context_impl &getContextImpl() const {
279+
return *sycl::detail::getSyclObjImpl(MContext);
280+
}
276281

277282
/// Query for the device_impl tied to this graph.
278283
/// @return device_impl shared ptr reference associated with graph.

sycl/source/detail/handler_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ class handler_impl {
199199
template <typename Self = handler_impl> context_impl &get_context() {
200200
Self *self = this;
201201
if (auto *Queue = self->get_queue_or_null())
202-
return *Queue->getContextImplPtr();
202+
return Queue->getContextImpl();
203203
else
204-
return *self->get_graph().getContextImplPtr();
204+
return self->get_graph().getContextImpl();
205205
}
206206

207207
/// If we are submitting a graph using ext_oneapi_graph this will be the graph

sycl/source/detail/helpers.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
namespace sycl {
2626
inline namespace _V1 {
27-
using ContextImplPtr = std::shared_ptr<sycl::detail::context_impl>;
2827
namespace detail {
2928
void waitEvents(std::vector<sycl::event> DepEvents) {
3029
for (auto SyclEvent : DepEvents) {
@@ -59,10 +58,10 @@ retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
5958
if (DeviceImage == DeviceImages.end()) {
6059
return {nullptr, nullptr};
6160
}
62-
auto ContextImpl = Queue.getContextImplPtr();
61+
context_impl &ContextImpl = Queue.getContextImpl();
6362
ur_program_handle_t Program =
6463
detail::ProgramManager::getInstance().createURProgram(
65-
**DeviceImage, *ContextImpl, {createSyclObjFromImpl<device>(Dev)});
64+
**DeviceImage, ContextImpl, {createSyclObjFromImpl<device>(Dev)});
6665
return {*DeviceImage, Program};
6766
}
6867

@@ -79,11 +78,11 @@ retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
7978
DeviceImage = SyclKernelImpl->getDeviceImage()->get_bin_image_ref();
8079
Program = SyclKernelImpl->getDeviceImage()->get_ur_program_ref();
8180
} else {
82-
auto ContextImpl = Queue.getContextImplPtr();
81+
context_impl &ContextImpl = Queue.getContextImpl();
8382
DeviceImage = &detail::ProgramManager::getInstance().getDeviceImage(
84-
KernelName, *ContextImpl, Dev);
83+
KernelName, ContextImpl, Dev);
8584
Program = detail::ProgramManager::getInstance().createURProgram(
86-
*DeviceImage, *ContextImpl, {createSyclObjFromImpl<device>(Dev)});
85+
*DeviceImage, ContextImpl, {createSyclObjFromImpl<device>(Dev)});
8786
}
8887
return {DeviceImage, Program};
8988
}

sycl/source/detail/kernel_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class kernel_impl {
232232
bool isInterop() const { return MIsInterop; }
233233

234234
ur_program_handle_t getProgramRef() const { return MProgram; }
235-
ContextImplPtr getContextImplPtr() const { return MContext; }
235+
context_impl &getContextImpl() const { return *MContext; }
236236

237237
std::mutex &getNoncacheableEnqueueMutex() const {
238238
return MNoncacheableEnqueueMutex;

sycl/source/detail/queue_impl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ template <> device queue_impl::get_info<info::queue::device>() const {
8080
template <>
8181
typename info::platform::version::return_type
8282
queue_impl::get_backend_info<info::platform::version>() const {
83-
if (getContextImplPtr()->getBackend() != backend::opencl) {
83+
if (getContextImpl().getBackend() != backend::opencl) {
8484
throw sycl::exception(errc::backend_mismatch,
8585
"the info::platform::version info descriptor can "
8686
"only be queried with an OpenCL backend");
@@ -93,7 +93,7 @@ queue_impl::get_backend_info<info::platform::version>() const {
9393
template <>
9494
typename info::device::version::return_type
9595
queue_impl::get_backend_info<info::device::version>() const {
96-
if (getContextImplPtr()->getBackend() != backend::opencl) {
96+
if (getContextImpl().getBackend() != backend::opencl) {
9797
throw sycl::exception(errc::backend_mismatch,
9898
"the info::device::version info descriptor can only "
9999
"be queried with an OpenCL backend");
@@ -106,7 +106,7 @@ queue_impl::get_backend_info<info::device::version>() const {
106106
template <>
107107
typename info::device::backend_version::return_type
108108
queue_impl::get_backend_info<info::device::backend_version>() const {
109-
if (getContextImplPtr()->getBackend() != backend::ext_oneapi_level_zero) {
109+
if (getContextImpl().getBackend() != backend::ext_oneapi_level_zero) {
110110
throw sycl::exception(errc::backend_mismatch,
111111
"the info::device::backend_version info descriptor "
112112
"can only be queried with a Level Zero backend");
@@ -734,7 +734,7 @@ ur_native_handle_t queue_impl::getNative(int32_t &NativeHandleDesc) const {
734734

735735
Adapter->call<UrApiKind::urQueueGetNativeHandle>(MQueue, &UrNativeDesc,
736736
&Handle);
737-
if (getContextImplPtr()->getBackend() == backend::opencl)
737+
if (getContextImpl().getBackend() == backend::opencl)
738738
__SYCL_OCL_CALL(clRetainCommandQueue, ur::cast<cl_command_queue>(Handle));
739739

740740
return Handle;

sycl/source/detail/scheduler/commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@ void instrumentationAddExtraKernelMetadata(
20182018
// by graph API, when a modifiable graph is finalized.
20192019
FastKernelCacheValPtr FastKernelCacheVal =
20202020
detail::ProgramManager::getInstance().getOrCreateKernel(
2021-
*Queue->getContextImplPtr(), Queue->getDeviceImpl(), KernelName,
2021+
Queue->getContextImpl(), Queue->getDeviceImpl(), KernelName,
20222022
KernelNameBasedCachePtr);
20232023
EliminatedArgMask = FastKernelCacheVal->MKernelArgMask;
20242024
}

sycl/source/handler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ void handler::depends_on(const detail::EventImplPtr &EventImpl) {
19951995
if (Queue && EventGraph) {
19961996
auto QueueGraph = Queue->getCommandGraph();
19971997

1998-
if (EventGraph->getContextImplPtr().get() != &impl->get_context()) {
1998+
if (&EventGraph->getContextImpl() != &impl->get_context()) {
19991999
throw sycl::exception(
20002000
make_error_code(errc::invalid),
20012001
"Cannot submit to a queue with a dependency from a graph that is "
@@ -2213,17 +2213,19 @@ void handler::memcpyFromHostOnlyDeviceGlobal(void *Dest,
22132213
});
22142214
}
22152215

2216+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
22162217
const std::shared_ptr<detail::context_impl> &
22172218
handler::getContextImplPtr() const {
22182219
if (auto *Graph = impl->get_graph_or_null()) {
22192220
return Graph->getContextImplPtr();
22202221
}
22212222
return impl->get_queue().getContextImplPtr();
22222223
}
2224+
#endif
22232225

22242226
detail::context_impl &handler::getContextImpl() const {
22252227
if (auto *Graph = impl->get_graph_or_null()) {
2226-
return *Graph->getContextImplPtr();
2228+
return Graph->getContextImpl();
22272229
}
22282230
return impl->get_queue().getContextImpl();
22292231
}

0 commit comments

Comments
 (0)