Skip to content

[SYCL] Move buffer_impl and image_impl to the source directory #6600

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

Merged
merged 6 commits into from
Aug 23, 2022
Merged
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
86 changes: 32 additions & 54 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
#include <sycl/detail/handler_proxy.hpp>
#include <sycl/detail/image_accessor_util.hpp>
#include <sycl/detail/image_ocl_types.hpp>
#include <sycl/device.hpp>
#include <sycl/exception.hpp>
#include <sycl/ext/oneapi/accessor_property_list.hpp>
#include <sycl/id.hpp>
#include <sycl/image.hpp>
#include <sycl/pointers.hpp>
#include <sycl/properties/accessor_properties.hpp>
#include <sycl/properties/buffer_properties.hpp>
#include <sycl/property_list.hpp>
#include <sycl/property_list_conversion.hpp>
#include <sycl/sampler.hpp>
Expand Down Expand Up @@ -264,20 +266,6 @@ template <> struct IsCxPropertyList<ext::oneapi::accessor_property_list<>> {
constexpr static bool value = false;
};

// The function extends or truncates number of dimensions of objects of id
// or ranges classes. When extending the new values are filled with
// DefaultValue, truncation just removes extra values.
template <int NewDim, int DefaultValue, template <int> class T, int OldDim>
static T<NewDim> convertToArrayOfN(T<OldDim> OldObj) {
T<NewDim> NewObj = InitializedVal<NewDim, T>::template get<0>();
const int CopyDims = NewDim > OldDim ? OldDim : NewDim;
for (int I = 0; I < CopyDims; ++I)
NewObj[I] = OldObj[I];
for (int I = CopyDims; I < NewDim; ++I)
NewObj[I] = DefaultValue;
return NewObj;
}

__SYCL_EXPORT device getDeviceFromHandler(handler &CommandGroupHandlerRef);

template <typename DataT, int Dimensions, access::mode AccessMode,
Expand Down Expand Up @@ -526,15 +514,14 @@ class image_accessor
// host.
}
#else
: AccessorBaseHost({detail::getSyclObjImpl(ImageRef)->getRowPitch(),
detail::getSyclObjImpl(ImageRef)->getSlicePitch(), 0},
: AccessorBaseHost({ImageRef.getRowPitch(), ImageRef.getSlicePitch(), 0},
detail::convertToArrayOfN<3, 1>(ImageRef.get_range()),
detail::convertToArrayOfN<3, 1>(ImageRef.get_range()),
AccessMode, detail::getSyclObjImpl(ImageRef).get(),
Dimensions, ImageElementSize),
MImageCount(ImageRef.size()),
MImgChannelOrder(detail::getSyclObjImpl(ImageRef)->getChannelOrder()),
MImgChannelType(detail::getSyclObjImpl(ImageRef)->getChannelType()) {
MImgChannelOrder(ImageRef.getChannelOrder()),
MImgChannelType(ImageRef.getChannelType()) {
addHostAccessorAndWait(AccessorBaseHost::impl.get());
}
#endif
Expand All @@ -557,15 +544,14 @@ class image_accessor
// host.
}
#else
: AccessorBaseHost({detail::getSyclObjImpl(ImageRef)->getRowPitch(),
detail::getSyclObjImpl(ImageRef)->getSlicePitch(), 0},
: AccessorBaseHost({ImageRef.getRowPitch(), ImageRef.getSlicePitch(), 0},
detail::convertToArrayOfN<3, 1>(ImageRef.get_range()),
detail::convertToArrayOfN<3, 1>(ImageRef.get_range()),
AccessMode, detail::getSyclObjImpl(ImageRef).get(),
Dimensions, ImageElementSize),
MImageCount(ImageRef.size()),
MImgChannelOrder(detail::getSyclObjImpl(ImageRef)->getChannelOrder()),
MImgChannelType(detail::getSyclObjImpl(ImageRef)->getChannelType()) {
MImgChannelOrder(ImageRef.getChannelOrder()),
MImgChannelType(ImageRef.getChannelType()) {
checkDeviceFeatureSupported<info::device::image_support>(
getDeviceFromHandler(CommandGroupHandlerRef));
}
Expand Down Expand Up @@ -1203,7 +1189,7 @@ class __SYCL_SPECIAL_CLASS accessor :
const property_list &PropertyList = {},
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, PropertyList, CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}

template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
Expand All @@ -1218,7 +1204,7 @@ class __SYCL_SPECIAL_CLASS accessor :
{},
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, PropertyList, CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}
#endif

Expand Down Expand Up @@ -1297,7 +1283,7 @@ class __SYCL_SPECIAL_CLASS accessor :
TagT, const property_list &PropertyList = {},
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, CommandGroupHandler, PropertyList, CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}

template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
Expand All @@ -1313,7 +1299,7 @@ class __SYCL_SPECIAL_CLASS accessor :
{},
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, CommandGroupHandler, PropertyList, CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}

#endif
Expand Down Expand Up @@ -1357,7 +1343,7 @@ class __SYCL_SPECIAL_CLASS accessor :
TagT, const property_list &PropertyList = {},
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, AccessRange, {}, PropertyList, CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}

template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
Expand All @@ -1373,7 +1359,7 @@ class __SYCL_SPECIAL_CLASS accessor :
{},
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, AccessRange, {}, PropertyList, CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}
#endif

Expand Down Expand Up @@ -1419,7 +1405,7 @@ class __SYCL_SPECIAL_CLASS accessor :
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, CommandGroupHandler, AccessRange, {}, PropertyList,
CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}

template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
Expand All @@ -1436,7 +1422,7 @@ class __SYCL_SPECIAL_CLASS accessor :
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, CommandGroupHandler, AccessRange, {}, PropertyList,
CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}
#endif

Expand Down Expand Up @@ -1532,7 +1518,7 @@ class __SYCL_SPECIAL_CLASS accessor :
id<Dimensions> AccessOffset, TagT, const property_list &PropertyList = {},
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, AccessRange, AccessOffset, PropertyList, CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}

template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
Expand All @@ -1548,7 +1534,7 @@ class __SYCL_SPECIAL_CLASS accessor :
{},
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, AccessRange, AccessOffset, PropertyList, CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}
#endif

Expand Down Expand Up @@ -1645,7 +1631,7 @@ class __SYCL_SPECIAL_CLASS accessor :
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, CommandGroupHandler, AccessRange, AccessOffset,
PropertyList, CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}

template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
Expand All @@ -1662,7 +1648,7 @@ class __SYCL_SPECIAL_CLASS accessor :
const detail::code_location CodeLoc = detail::code_location::current())
: accessor(BufferRef, CommandGroupHandler, AccessRange, AccessOffset,
PropertyList, CodeLoc) {
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
adjustAccPropsInBuf(BufferRef);
}
#endif

Expand Down Expand Up @@ -1854,27 +1840,23 @@ class __SYCL_SPECIAL_CLASS accessor :
}

#if __cplusplus >= 201703L
template <typename... PropTypes>
void adjustAccPropsInBuf(detail::SYCLMemObjI *SYCLMemObject) {
template <typename BufT, typename... PropTypes>
void adjustAccPropsInBuf(BufT &Buffer) {
if constexpr (PropertyListT::template has_property<
sycl::ext::intel::property::buffer_location>()) {
auto location = (PropertyListT::template get_property<
sycl::ext::intel::property::buffer_location>())
.get_location();
property_list PropList{
sycl::property::buffer::detail::buffer_location(location)};
detail::SYCLMemObjT *SYCLMemObjectT =
dynamic_cast<detail::SYCLMemObjT *>(SYCLMemObject);
SYCLMemObjectT->addOrReplaceAccessorProperties(PropList);
Buffer.addOrReplaceAccessorProperties(PropList);
} else {
deleteAccPropsFromBuf(SYCLMemObject);
deleteAccPropsFromBuf(Buffer);
}
}

void deleteAccPropsFromBuf(detail::SYCLMemObjI *SYCLMemObject) {
detail::SYCLMemObjT *SYCLMemObjectT =
dynamic_cast<detail::SYCLMemObjT *>(SYCLMemObject);
SYCLMemObjectT->deleteAccessorProperty(
template <typename BufT> void deleteAccPropsFromBuf(BufT &Buffer) {
Buffer.deleteAccProps(
sycl::detail::PropWithDataKind::AccPropBufferLocation);
}
#endif
Expand Down Expand Up @@ -2261,8 +2243,7 @@ class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
handler &CommandGroupHandler)
: detail::image_accessor<DataT, Dimensions, AccessMode,
access::target::image, IsPlaceholder>(
Image, CommandGroupHandler,
(detail::getSyclObjImpl(Image))->getElementSize()) {
Image, CommandGroupHandler, Image.getElementSize()) {
#ifndef __SYCL_DEVICE_ONLY__
detail::associateWithHandler(CommandGroupHandler, this,
access::target::image);
Expand All @@ -2274,8 +2255,7 @@ class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
handler &CommandGroupHandler, const property_list &propList)
: detail::image_accessor<DataT, Dimensions, AccessMode,
access::target::image, IsPlaceholder>(
Image, CommandGroupHandler,
(detail::getSyclObjImpl(Image))->getElementSize()) {
Image, CommandGroupHandler, Image.getElementSize()) {
(void)propList;
#ifndef __SYCL_DEVICE_ONLY__
detail::associateWithHandler(CommandGroupHandler, this,
Expand Down Expand Up @@ -2319,14 +2299,14 @@ class accessor<DataT, Dimensions, AccessMode, access::target::host_image,
accessor(sycl::image<Dimensions, AllocatorT> &Image)
: detail::image_accessor<DataT, Dimensions, AccessMode,
access::target::host_image, IsPlaceholder>(
Image, (detail::getSyclObjImpl(Image))->getElementSize()) {}
Image, Image.getElementSize()) {}

template <typename AllocatorT>
accessor(sycl::image<Dimensions, AllocatorT> &Image,
const property_list &propList)
: detail::image_accessor<DataT, Dimensions, AccessMode,
access::target::host_image, IsPlaceholder>(
Image, (detail::getSyclObjImpl(Image))->getElementSize()) {
Image, Image.getElementSize()) {
(void)propList;
}
};
Expand Down Expand Up @@ -2368,8 +2348,7 @@ class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
handler &CommandGroupHandler)
: detail::image_accessor<DataT, Dimensions + 1, AccessMode,
access::target::image, IsPlaceholder>(
Image, CommandGroupHandler,
(detail::getSyclObjImpl(Image))->getElementSize()) {
Image, CommandGroupHandler, Image.getElementSize()) {
#ifndef __SYCL_DEVICE_ONLY__
detail::associateWithHandler(CommandGroupHandler, this,
access::target::image_array);
Expand All @@ -2381,8 +2360,7 @@ class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
handler &CommandGroupHandler, const property_list &propList)
: detail::image_accessor<DataT, Dimensions + 1, AccessMode,
access::target::image, IsPlaceholder>(
Image, CommandGroupHandler,
(detail::getSyclObjImpl(Image))->getElementSize()) {
Image, CommandGroupHandler, Image.getElementSize()) {
(void)propList;
#ifndef __SYCL_DEVICE_ONLY__
detail::associateWithHandler(CommandGroupHandler, this,
Expand Down
Loading