Skip to content

[NFC][SYCL] Use plain context_impl & in sycl/ext/oneapi/memcpy2d.hpp #19030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sycl/include/sycl/ext/oneapi/memcpy2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void handler::ext_oneapi_memcpy2d(void *Dest, size_t DestPitch, const void *Src,
#endif

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

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

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

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

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

// If the backends supports 2D fill we use that. Otherwise we use a fallback
Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3546,6 +3546,7 @@ class __SYCL_EXPORT handler {
}

const std::shared_ptr<detail::context_impl> &getContextImplPtr() const;
detail::context_impl &getContextImpl() const;

// Checks if 2D memory operations are supported by the underlying platform.
bool supportsUSMMemcpy2D();
Expand Down
11 changes: 11 additions & 0 deletions sycl/include/sycl/usm/usm_pointer_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ inline namespace _V1 {
class device;
class context;

namespace detail {
class context_impl;
__SYCL_EXPORT usm::alloc get_pointer_type(const void *ptr, context_impl &ctxt);
} // namespace detail

// Pointer queries
/// Query the allocation type from a USM pointer
///
/// \param ptr is the USM pointer to query
/// \param ctxt is the sycl context the ptr was allocated in
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
inline usm::alloc get_pointer_type(const void *ptr, const context &ctxt) {
return get_pointer_type(ptr, *getSyclObjImpl(ctxt));
}
#else
__SYCL_EXPORT usm::alloc get_pointer_type(const void *ptr, const context &ctxt);
#endif

/// Queries the device against which the pointer was allocated
/// Throws an exception with errc::invalid error code if ptr is a host
Expand Down
6 changes: 4 additions & 2 deletions sycl/source/detail/context_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,14 @@ void GetCapabilitiesIntersectionSet(const std::vector<sycl::device> &Devices,

// We're under sycl/source and these won't be exported but it's way more
// convenient to be able to reference them without extra `detail::`.
inline auto get_ur_handles(const sycl::context &syclContext) {
sycl::detail::context_impl &Ctx = *sycl::detail::getSyclObjImpl(syclContext);
inline auto get_ur_handles(sycl::detail::context_impl &Ctx) {
ur_context_handle_t urCtx = Ctx.getHandleRef();
const sycl::detail::Adapter *Adapter = Ctx.getAdapter().get();
return std::tuple{urCtx, Adapter};
}
inline auto get_ur_handles(const sycl::context &syclContext) {
return get_ur_handles(*sycl::detail::getSyclObjImpl(syclContext));
}
inline auto get_ur_handles(const sycl::device &syclDevice,
const sycl::context &syclContext) {
auto [urCtx, Adapter] = get_ur_handles(syclContext);
Expand Down
9 changes: 8 additions & 1 deletion sycl/source/detail/usm/usm_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ void *aligned_alloc(size_t Alignment, size_t Size, const queue &Q, alloc Kind,
///
/// \param Ptr is the USM pointer to query
/// \param Ctxt is the sycl context the ptr was allocated in
alloc get_pointer_type(const void *Ptr, const context &Ctxt) {
namespace detail {
alloc get_pointer_type(const void *Ptr, context_impl &Ctxt) {
if (!Ptr)
return alloc::unknown;

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

return ResultAlloc;
}
} // namespace detail
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
__SYCL_EXPORT alloc get_pointer_type(const void *Ptr, const context &Ctxt) {
return get_pointer_type(Ptr, *getSyclObjImpl(Ctxt));
}
#endif

/// Queries the device against which the pointer was allocated
///
Expand Down
7 changes: 7 additions & 0 deletions sycl/source/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,13 @@ handler::getContextImplPtr() const {
return impl->get_queue().getContextImplPtr();
}

detail::context_impl &handler::getContextImpl() const {
if (auto *Graph = impl->get_graph_or_null()) {
return *Graph->getContextImplPtr();
}
return impl->get_queue().getContextImpl();
}

void handler::setKernelCacheConfig(handler::StableKernelCacheConfig Config) {
switch (Config) {
case handler::StableKernelCacheConfig::Default:
Expand Down
2 changes: 2 additions & 0 deletions sycl/test/abi/sycl_symbols_linux.dump
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,7 @@ _ZN4sycl3_V16detail16AccessorBaseHostC1ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6a
_ZN4sycl3_V16detail16AccessorBaseHostC1ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6access4modeEPviimbRKNS0_13property_listE
_ZN4sycl3_V16detail16AccessorBaseHostC2ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6access4modeEPviibmbRKNS0_13property_listE
_ZN4sycl3_V16detail16AccessorBaseHostC2ENS0_2idILi3EEENS0_5rangeILi3EEES6_NS0_6access4modeEPviimbRKNS0_13property_listE
_ZN4sycl3_V16detail16get_pointer_typeEPKvRNS1_12context_implE
_ZN4sycl3_V16detail16reduGetMaxWGSizeERNS0_7handlerEm
_ZN4sycl3_V16detail16reduGetMaxWGSizeESt10shared_ptrINS1_10queue_implEEm
_ZN4sycl3_V16detail17HostProfilingInfo3endEv
Expand Down Expand Up @@ -4082,6 +4083,7 @@ _ZNK4sycl3_V17context8get_infoINS0_4info7context7devicesEEENS0_6detail20is_conte
_ZNK4sycl3_V17context8get_infoINS0_4info7context8platformEEENS0_6detail20is_context_info_descIT_E11return_typeEv
_ZNK4sycl3_V17context9getNativeEv
_ZNK4sycl3_V17handler11eventNeededEv
_ZNK4sycl3_V17handler14getContextImplEv
_ZNK4sycl3_V17handler15getCommandGraphEv
_ZNK4sycl3_V17handler15getKernelBundleEv
_ZNK4sycl3_V17handler16getDeviceBackendEv
Expand Down
2 changes: 2 additions & 0 deletions sycl/test/abi/sycl_symbols_windows.dump
Original file line number Diff line number Diff line change
Expand Up @@ -4054,6 +4054,7 @@
?getChannelType@UnsampledImageAccessorBaseHost@detail@_V1@sycl@@QEBA?AW4image_channel_type@34@XZ
?getChannelType@image_plain@detail@_V1@sycl@@IEBA?AW4image_channel_type@34@XZ
?getCommandGraph@handler@_V1@sycl@@AEBA?AV?$shared_ptr@Vgraph_impl@detail@experimental@oneapi@ext@_V1@sycl@@@std@@XZ
?getContextImpl@handler@_V1@sycl@@AEBAAEAVcontext_impl@detail@23@XZ
?getContextImplPtr@handler@_V1@sycl@@AEBAAEBV?$shared_ptr@Vcontext_impl@detail@_V1@sycl@@@std@@XZ
?getCurrentDSODir@OSUtil@detail@_V1@sycl@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ
?getDeviceBackend@handler@_V1@sycl@@AEBA?AW4backend@23@XZ
Expand Down Expand Up @@ -4207,6 +4208,7 @@
?get_platforms@platform@_V1@sycl@@SA?AV?$vector@Vplatform@_V1@sycl@@V?$allocator@Vplatform@_V1@sycl@@@std@@@std@@XZ
?get_pointer_device@_V1@sycl@@YA?AVdevice@12@PEBXAEBVcontext@12@@Z
?get_pointer_type@_V1@sycl@@YA?AW4alloc@usm@12@PEBXAEBVcontext@12@@Z
?get_pointer_type@detail@_V1@sycl@@YA?AW4alloc@usm@23@PEBXAEAVcontext_impl@123@@Z
?get_precision@stream@_V1@sycl@@QEBA_KXZ
?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
?get_queue@fusion_wrapper@experimental@codeplay@ext@_V1@sycl@@QEBA?AVqueue@56@XZ
Expand Down