Skip to content

Commit a95c342

Browse files
[NFC][SYCL] Use plain context_impl & in sycl/ext/oneapi/memcpy2d.hpp (#19030)
Continuation of the refactoring in #18795 #18877 #18966 #18979 #18980 #18981 #19007
1 parent 4ee45df commit a95c342

File tree

8 files changed

+39
-7
lines changed

8 files changed

+39
-7
lines changed

sycl/include/sycl/ext/oneapi/memcpy2d.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void handler::ext_oneapi_memcpy2d(void *Dest, size_t DestPitch, const void *Src,
3434
#endif
3535

3636
// Get the type of the pointers.
37-
context Ctx = detail::createSyclObjFromImpl<context>(getContextImplPtr());
37+
detail::context_impl &Ctx = getContextImpl();
3838
usm::alloc SrcAllocType = get_pointer_type(Src, Ctx);
3939
usm::alloc DestAllocType = get_pointer_type(Dest, Ctx);
4040
bool SrcIsHost =
@@ -71,7 +71,7 @@ void handler::ext_oneapi_copy2d(const T *Src, size_t SrcPitch, T *Dest,
7171
"to the width specified in 'ext_oneapi_copy2d'");
7272

7373
// Get the type of the pointers.
74-
context Ctx = detail::createSyclObjFromImpl<context>(getContextImplPtr());
74+
detail::context_impl &Ctx = getContextImpl();
7575
usm::alloc SrcAllocType = get_pointer_type(Src, Ctx);
7676
usm::alloc DestAllocType = get_pointer_type(Dest, Ctx);
7777
bool SrcIsHost =
@@ -106,7 +106,7 @@ void handler::ext_oneapi_memset2d(void *Dest, size_t DestPitch, int Value,
106106
"to the width specified in 'ext_oneapi_memset2d'");
107107
T CharVal = static_cast<T>(Value);
108108

109-
context Ctx = detail::createSyclObjFromImpl<context>(getContextImplPtr());
109+
detail::context_impl &Ctx = getContextImpl();
110110
usm::alloc DestAllocType = get_pointer_type(Dest, Ctx);
111111

112112
// If the backends supports 2D fill we use that. Otherwise we use a fallback
@@ -130,7 +130,7 @@ void handler::ext_oneapi_fill2d(void *Dest, size_t DestPitch, const T &Pattern,
130130
"Destination pitch must be greater than or equal "
131131
"to the width specified in 'ext_oneapi_fill2d'");
132132

133-
context Ctx = detail::createSyclObjFromImpl<context>(getContextImplPtr());
133+
detail::context_impl &Ctx = getContextImpl();
134134
usm::alloc DestAllocType = get_pointer_type(Dest, Ctx);
135135

136136
// If the backends supports 2D fill we use that. Otherwise we use a fallback

sycl/include/sycl/handler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3546,6 +3546,7 @@ class __SYCL_EXPORT handler {
35463546
}
35473547

35483548
const std::shared_ptr<detail::context_impl> &getContextImplPtr() const;
3549+
detail::context_impl &getContextImpl() const;
35493550

35503551
// Checks if 2D memory operations are supported by the underlying platform.
35513552
bool supportsUSMMemcpy2D();

sycl/include/sycl/usm/usm_pointer_info.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,23 @@ inline namespace _V1 {
1616
class device;
1717
class context;
1818

19+
namespace detail {
20+
class context_impl;
21+
__SYCL_EXPORT usm::alloc get_pointer_type(const void *ptr, context_impl &ctxt);
22+
} // namespace detail
23+
1924
// Pointer queries
2025
/// Query the allocation type from a USM pointer
2126
///
2227
/// \param ptr is the USM pointer to query
2328
/// \param ctxt is the sycl context the ptr was allocated in
29+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
30+
inline usm::alloc get_pointer_type(const void *ptr, const context &ctxt) {
31+
return get_pointer_type(ptr, *getSyclObjImpl(ctxt));
32+
}
33+
#else
2434
__SYCL_EXPORT usm::alloc get_pointer_type(const void *ptr, const context &ctxt);
35+
#endif
2536

2637
/// Queries the device against which the pointer was allocated
2738
/// Throws an exception with errc::invalid error code if ptr is a host

sycl/source/detail/context_impl.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,14 @@ void GetCapabilitiesIntersectionSet(const std::vector<sycl::device> &Devices,
364364

365365
// We're under sycl/source and these won't be exported but it's way more
366366
// convenient to be able to reference them without extra `detail::`.
367-
inline auto get_ur_handles(const sycl::context &syclContext) {
368-
sycl::detail::context_impl &Ctx = *sycl::detail::getSyclObjImpl(syclContext);
367+
inline auto get_ur_handles(sycl::detail::context_impl &Ctx) {
369368
ur_context_handle_t urCtx = Ctx.getHandleRef();
370369
const sycl::detail::Adapter *Adapter = Ctx.getAdapter().get();
371370
return std::tuple{urCtx, Adapter};
372371
}
372+
inline auto get_ur_handles(const sycl::context &syclContext) {
373+
return get_ur_handles(*sycl::detail::getSyclObjImpl(syclContext));
374+
}
373375
inline auto get_ur_handles(const sycl::device &syclDevice,
374376
const sycl::context &syclContext) {
375377
auto [urCtx, Adapter] = get_ur_handles(syclContext);

sycl/source/detail/usm/usm_impl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ void *aligned_alloc(size_t Alignment, size_t Size, const queue &Q, alloc Kind,
518518
///
519519
/// \param Ptr is the USM pointer to query
520520
/// \param Ctxt is the sycl context the ptr was allocated in
521-
alloc get_pointer_type(const void *Ptr, const context &Ctxt) {
521+
namespace detail {
522+
alloc get_pointer_type(const void *Ptr, context_impl &Ctxt) {
522523
if (!Ptr)
523524
return alloc::unknown;
524525

@@ -559,6 +560,12 @@ alloc get_pointer_type(const void *Ptr, const context &Ctxt) {
559560

560561
return ResultAlloc;
561562
}
563+
} // namespace detail
564+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
565+
__SYCL_EXPORT alloc get_pointer_type(const void *Ptr, const context &Ctxt) {
566+
return get_pointer_type(Ptr, *getSyclObjImpl(Ctxt));
567+
}
568+
#endif
562569

563570
/// Queries the device against which the pointer was allocated
564571
///

sycl/source/handler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,6 +2219,13 @@ handler::getContextImplPtr() const {
22192219
return impl->get_queue().getContextImplPtr();
22202220
}
22212221

2222+
detail::context_impl &handler::getContextImpl() const {
2223+
if (auto *Graph = impl->get_graph_or_null()) {
2224+
return *Graph->getContextImplPtr();
2225+
}
2226+
return impl->get_queue().getContextImpl();
2227+
}
2228+
22222229
void handler::setKernelCacheConfig(handler::StableKernelCacheConfig Config) {
22232230
switch (Config) {
22242231
case handler::StableKernelCacheConfig::Default:

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,6 +3298,7 @@ _ZN4sycl3_V16detail16AccessorBaseHostC1ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6a
32983298
_ZN4sycl3_V16detail16AccessorBaseHostC1ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6access4modeEPviimbRKNS0_13property_listE
32993299
_ZN4sycl3_V16detail16AccessorBaseHostC2ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6access4modeEPviibmbRKNS0_13property_listE
33003300
_ZN4sycl3_V16detail16AccessorBaseHostC2ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6access4modeEPviimbRKNS0_13property_listE
3301+
_ZN4sycl3_V16detail16get_pointer_typeEPKvRNS1_12context_implE
33013302
_ZN4sycl3_V16detail16reduGetMaxWGSizeERNS0_7handlerEm
33023303
_ZN4sycl3_V16detail16reduGetMaxWGSizeESt10shared_ptrINS1_10queue_implEEm
33033304
_ZN4sycl3_V16detail17HostProfilingInfo3endEv
@@ -4080,6 +4081,7 @@ _ZNK4sycl3_V17context8get_infoINS0_4info7context7devicesEEENS0_6detail20is_conte
40804081
_ZNK4sycl3_V17context8get_infoINS0_4info7context8platformEEENS0_6detail20is_context_info_descIT_E11return_typeEv
40814082
_ZNK4sycl3_V17context9getNativeEv
40824083
_ZNK4sycl3_V17handler11eventNeededEv
4084+
_ZNK4sycl3_V17handler14getContextImplEv
40834085
_ZNK4sycl3_V17handler15getCommandGraphEv
40844086
_ZNK4sycl3_V17handler15getKernelBundleEv
40854087
_ZNK4sycl3_V17handler16getDeviceBackendEv

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,6 +4050,7 @@
40504050
?getChannelType@UnsampledImageAccessorBaseHost@detail@_V1@sycl@@QEBA?AW4image_channel_type@34@XZ
40514051
?getChannelType@image_plain@detail@_V1@sycl@@IEBA?AW4image_channel_type@34@XZ
40524052
?getCommandGraph@handler@_V1@sycl@@AEBA?AV?$shared_ptr@Vgraph_impl@detail@experimental@oneapi@ext@_V1@sycl@@@std@@XZ
4053+
?getContextImpl@handler@_V1@sycl@@AEBAAEAVcontext_impl@detail@23@XZ
40534054
?getContextImplPtr@handler@_V1@sycl@@AEBAAEBV?$shared_ptr@Vcontext_impl@detail@_V1@sycl@@@std@@XZ
40544055
?getCurrentDSODir@OSUtil@detail@_V1@sycl@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ
40554056
?getDeviceBackend@handler@_V1@sycl@@AEBA?AW4backend@23@XZ
@@ -4202,6 +4203,7 @@
42024203
?get_platforms@platform@_V1@sycl@@SA?AV?$vector@Vplatform@_V1@sycl@@V?$allocator@Vplatform@_V1@sycl@@@std@@@std@@XZ
42034204
?get_pointer_device@_V1@sycl@@YA?AVdevice@12@PEBXAEBVcontext@12@@Z
42044205
?get_pointer_type@_V1@sycl@@YA?AW4alloc@usm@12@PEBXAEBVcontext@12@@Z
4206+
?get_pointer_type@detail@_V1@sycl@@YA?AW4alloc@usm@23@PEBXAEAVcontext_impl@123@@Z
42054207
?get_precision@stream@_V1@sycl@@QEBA_KXZ
42064208
?get_predecessors@node@experimental@oneapi@ext@_V1@sycl@@QEBA?AV?$vector@Vnode@experimental@oneapi@ext@_V1@sycl@@V?$allocator@Vnode@experimental@oneapi@ext@_V1@sycl@@@std@@@std@@XZ
42074209
?get_queue@fusion_wrapper@experimental@codeplay@ext@_V1@sycl@@QEBA?AVqueue@56@XZ

0 commit comments

Comments
 (0)