Skip to content

Commit 74736d6

Browse files
committed
[SYCL] Move buffer_impl and image_impl to the source directory
The patch moves impl parts of buffer and image classes to the library to give more freedom to modify their contents without breaking ABI. To achieve this the patch: 1. Introduces buffer_plain and image_plain as a base classes for buffer and image respectively in order to introduce non-template proxy which can access impl parts. 2. Introduces initialization and finalization callbacks which are passed from headers to the library for the cases when source or destination heavily depends on the template parameters. 3. Adds several private methods which are accessed by "friend" classes.
1 parent 54655a2 commit 74736d6

33 files changed

+1239
-864
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
#include <sycl/detail/handler_proxy.hpp>
2020
#include <sycl/detail/image_accessor_util.hpp>
2121
#include <sycl/detail/image_ocl_types.hpp>
22+
#include <sycl/device.hpp>
2223
#include <sycl/exception.hpp>
2324
#include <sycl/ext/oneapi/accessor_property_list.hpp>
2425
#include <sycl/id.hpp>
2526
#include <sycl/image.hpp>
2627
#include <sycl/pointers.hpp>
2728
#include <sycl/properties/accessor_properties.hpp>
29+
#include <sycl/properties/buffer_properties.hpp>
2830
#include <sycl/property_list.hpp>
2931
#include <sycl/property_list_conversion.hpp>
3032
#include <sycl/sampler.hpp>
@@ -248,20 +250,6 @@ template <> struct IsCxPropertyList<ext::oneapi::accessor_property_list<>> {
248250
constexpr static bool value = false;
249251
};
250252

251-
// The function extends or truncates number of dimensions of objects of id
252-
// or ranges classes. When extending the new values are filled with
253-
// DefaultValue, truncation just removes extra values.
254-
template <int NewDim, int DefaultValue, template <int> class T, int OldDim>
255-
static T<NewDim> convertToArrayOfN(T<OldDim> OldObj) {
256-
T<NewDim> NewObj = InitializedVal<NewDim, T>::template get<0>();
257-
const int CopyDims = NewDim > OldDim ? OldDim : NewDim;
258-
for (int I = 0; I < CopyDims; ++I)
259-
NewObj[I] = OldObj[I];
260-
for (int I = CopyDims; I < NewDim; ++I)
261-
NewObj[I] = DefaultValue;
262-
return NewObj;
263-
}
264-
265253
__SYCL_EXPORT device getDeviceFromHandler(handler &CommandGroupHandlerRef);
266254

267255
template <typename DataT, int Dimensions, access::mode AccessMode,
@@ -510,15 +498,14 @@ class image_accessor
510498
// host.
511499
}
512500
#else
513-
: AccessorBaseHost({detail::getSyclObjImpl(ImageRef)->getRowPitch(),
514-
detail::getSyclObjImpl(ImageRef)->getSlicePitch(), 0},
501+
: AccessorBaseHost({ImageRef.getRowPitch(), ImageRef.getSlicePitch(), 0},
515502
detail::convertToArrayOfN<3, 1>(ImageRef.get_range()),
516503
detail::convertToArrayOfN<3, 1>(ImageRef.get_range()),
517504
AccessMode, detail::getSyclObjImpl(ImageRef).get(),
518505
Dimensions, ImageElementSize),
519506
MImageCount(ImageRef.size()),
520-
MImgChannelOrder(detail::getSyclObjImpl(ImageRef)->getChannelOrder()),
521-
MImgChannelType(detail::getSyclObjImpl(ImageRef)->getChannelType()) {
507+
MImgChannelOrder(ImageRef.getChannelOrder()),
508+
MImgChannelType(ImageRef.getChannelType()) {
522509
addHostAccessorAndWait(AccessorBaseHost::impl.get());
523510
}
524511
#endif
@@ -541,15 +528,14 @@ class image_accessor
541528
// host.
542529
}
543530
#else
544-
: AccessorBaseHost({detail::getSyclObjImpl(ImageRef)->getRowPitch(),
545-
detail::getSyclObjImpl(ImageRef)->getSlicePitch(), 0},
531+
: AccessorBaseHost({ImageRef.getRowPitch(), ImageRef.getSlicePitch(), 0},
546532
detail::convertToArrayOfN<3, 1>(ImageRef.get_range()),
547533
detail::convertToArrayOfN<3, 1>(ImageRef.get_range()),
548534
AccessMode, detail::getSyclObjImpl(ImageRef).get(),
549535
Dimensions, ImageElementSize),
550536
MImageCount(ImageRef.size()),
551-
MImgChannelOrder(detail::getSyclObjImpl(ImageRef)->getChannelOrder()),
552-
MImgChannelType(detail::getSyclObjImpl(ImageRef)->getChannelType()) {
537+
MImgChannelOrder(ImageRef.getChannelOrder()),
538+
MImgChannelType(ImageRef.getChannelType()) {
553539
checkDeviceFeatureSupported<info::device::image_support>(
554540
getDeviceFromHandler(CommandGroupHandlerRef));
555541
}
@@ -1197,7 +1183,7 @@ class __SYCL_SPECIAL_CLASS accessor :
11971183
const property_list &PropertyList = {},
11981184
const detail::code_location CodeLoc = detail::code_location::current())
11991185
: accessor(BufferRef, PropertyList, CodeLoc) {
1200-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1186+
adjustAccPropsInBuf(BufferRef);
12011187
}
12021188

12031189
template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
@@ -1212,7 +1198,7 @@ class __SYCL_SPECIAL_CLASS accessor :
12121198
{},
12131199
const detail::code_location CodeLoc = detail::code_location::current())
12141200
: accessor(BufferRef, PropertyList, CodeLoc) {
1215-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1201+
adjustAccPropsInBuf(BufferRef);
12161202
}
12171203
#endif
12181204

@@ -1291,7 +1277,7 @@ class __SYCL_SPECIAL_CLASS accessor :
12911277
TagT, const property_list &PropertyList = {},
12921278
const detail::code_location CodeLoc = detail::code_location::current())
12931279
: accessor(BufferRef, CommandGroupHandler, PropertyList, CodeLoc) {
1294-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1280+
adjustAccPropsInBuf(BufferRef);
12951281
}
12961282

12971283
template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
@@ -1307,7 +1293,7 @@ class __SYCL_SPECIAL_CLASS accessor :
13071293
{},
13081294
const detail::code_location CodeLoc = detail::code_location::current())
13091295
: accessor(BufferRef, CommandGroupHandler, PropertyList, CodeLoc) {
1310-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1296+
adjustAccPropsInBuf(BufferRef);
13111297
}
13121298

13131299
#endif
@@ -1351,7 +1337,7 @@ class __SYCL_SPECIAL_CLASS accessor :
13511337
TagT, const property_list &PropertyList = {},
13521338
const detail::code_location CodeLoc = detail::code_location::current())
13531339
: accessor(BufferRef, AccessRange, {}, PropertyList, CodeLoc) {
1354-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1340+
adjustAccPropsInBuf(BufferRef);
13551341
}
13561342

13571343
template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
@@ -1367,7 +1353,7 @@ class __SYCL_SPECIAL_CLASS accessor :
13671353
{},
13681354
const detail::code_location CodeLoc = detail::code_location::current())
13691355
: accessor(BufferRef, AccessRange, {}, PropertyList, CodeLoc) {
1370-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1356+
adjustAccPropsInBuf(BufferRef);
13711357
}
13721358
#endif
13731359

@@ -1413,7 +1399,7 @@ class __SYCL_SPECIAL_CLASS accessor :
14131399
const detail::code_location CodeLoc = detail::code_location::current())
14141400
: accessor(BufferRef, CommandGroupHandler, AccessRange, {}, PropertyList,
14151401
CodeLoc) {
1416-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1402+
adjustAccPropsInBuf(BufferRef);
14171403
}
14181404

14191405
template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
@@ -1430,7 +1416,7 @@ class __SYCL_SPECIAL_CLASS accessor :
14301416
const detail::code_location CodeLoc = detail::code_location::current())
14311417
: accessor(BufferRef, CommandGroupHandler, AccessRange, {}, PropertyList,
14321418
CodeLoc) {
1433-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1419+
adjustAccPropsInBuf(BufferRef);
14341420
}
14351421
#endif
14361422

@@ -1526,7 +1512,7 @@ class __SYCL_SPECIAL_CLASS accessor :
15261512
id<Dimensions> AccessOffset, TagT, const property_list &PropertyList = {},
15271513
const detail::code_location CodeLoc = detail::code_location::current())
15281514
: accessor(BufferRef, AccessRange, AccessOffset, PropertyList, CodeLoc) {
1529-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1515+
adjustAccPropsInBuf(BufferRef);
15301516
}
15311517

15321518
template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
@@ -1542,7 +1528,7 @@ class __SYCL_SPECIAL_CLASS accessor :
15421528
{},
15431529
const detail::code_location CodeLoc = detail::code_location::current())
15441530
: accessor(BufferRef, AccessRange, AccessOffset, PropertyList, CodeLoc) {
1545-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1531+
adjustAccPropsInBuf(BufferRef);
15461532
}
15471533
#endif
15481534

@@ -1639,7 +1625,7 @@ class __SYCL_SPECIAL_CLASS accessor :
16391625
const detail::code_location CodeLoc = detail::code_location::current())
16401626
: accessor(BufferRef, CommandGroupHandler, AccessRange, AccessOffset,
16411627
PropertyList, CodeLoc) {
1642-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1628+
adjustAccPropsInBuf(BufferRef);
16431629
}
16441630

16451631
template <typename T = DataT, int Dims = Dimensions, typename AllocatorT,
@@ -1656,7 +1642,7 @@ class __SYCL_SPECIAL_CLASS accessor :
16561642
const detail::code_location CodeLoc = detail::code_location::current())
16571643
: accessor(BufferRef, CommandGroupHandler, AccessRange, AccessOffset,
16581644
PropertyList, CodeLoc) {
1659-
adjustAccPropsInBuf(detail::getSyclObjImpl(BufferRef).get());
1645+
adjustAccPropsInBuf(BufferRef);
16601646
}
16611647
#endif
16621648

@@ -1829,27 +1815,23 @@ class __SYCL_SPECIAL_CLASS accessor :
18291815
}
18301816

18311817
#if __cplusplus >= 201703L
1832-
template <typename... PropTypes>
1833-
void adjustAccPropsInBuf(detail::SYCLMemObjI *SYCLMemObject) {
1818+
template <typename BufT, typename... PropTypes>
1819+
void adjustAccPropsInBuf(BufT &Buffer) {
18341820
if constexpr (PropertyListT::template has_property<
18351821
sycl::ext::intel::property::buffer_location>()) {
18361822
auto location = (PropertyListT::template get_property<
18371823
sycl::ext::intel::property::buffer_location>())
18381824
.get_location();
18391825
property_list PropList{
18401826
sycl::property::buffer::detail::buffer_location(location)};
1841-
detail::SYCLMemObjT *SYCLMemObjectT =
1842-
dynamic_cast<detail::SYCLMemObjT *>(SYCLMemObject);
1843-
SYCLMemObjectT->addOrReplaceAccessorProperties(PropList);
1827+
Buffer.addOrReplaceAccessorProperties(PropList);
18441828
} else {
1845-
deleteAccPropsFromBuf(SYCLMemObject);
1829+
deleteAccPropsFromBuf(Buffer);
18461830
}
18471831
}
18481832

1849-
void deleteAccPropsFromBuf(detail::SYCLMemObjI *SYCLMemObject) {
1850-
detail::SYCLMemObjT *SYCLMemObjectT =
1851-
dynamic_cast<detail::SYCLMemObjT *>(SYCLMemObject);
1852-
SYCLMemObjectT->deleteAccessorProperty(
1833+
template <typename BufT> void deleteAccPropsFromBuf(BufT &Buffer) {
1834+
Buffer.deleteAccProps(
18531835
sycl::detail::PropWithDataKind::AccPropBufferLocation);
18541836
}
18551837
#endif
@@ -2236,8 +2218,7 @@ class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
22362218
handler &CommandGroupHandler)
22372219
: detail::image_accessor<DataT, Dimensions, AccessMode,
22382220
access::target::image, IsPlaceholder>(
2239-
Image, CommandGroupHandler,
2240-
(detail::getSyclObjImpl(Image))->getElementSize()) {
2221+
Image, CommandGroupHandler, Image.getElementSize()) {
22412222
#ifndef __SYCL_DEVICE_ONLY__
22422223
detail::associateWithHandler(CommandGroupHandler, this,
22432224
access::target::image);
@@ -2249,8 +2230,7 @@ class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
22492230
handler &CommandGroupHandler, const property_list &propList)
22502231
: detail::image_accessor<DataT, Dimensions, AccessMode,
22512232
access::target::image, IsPlaceholder>(
2252-
Image, CommandGroupHandler,
2253-
(detail::getSyclObjImpl(Image))->getElementSize()) {
2233+
Image, CommandGroupHandler, Image.getElementSize()) {
22542234
(void)propList;
22552235
#ifndef __SYCL_DEVICE_ONLY__
22562236
detail::associateWithHandler(CommandGroupHandler, this,
@@ -2294,14 +2274,14 @@ class accessor<DataT, Dimensions, AccessMode, access::target::host_image,
22942274
accessor(sycl::image<Dimensions, AllocatorT> &Image)
22952275
: detail::image_accessor<DataT, Dimensions, AccessMode,
22962276
access::target::host_image, IsPlaceholder>(
2297-
Image, (detail::getSyclObjImpl(Image))->getElementSize()) {}
2277+
Image, Image.getElementSize()) {}
22982278

22992279
template <typename AllocatorT>
23002280
accessor(sycl::image<Dimensions, AllocatorT> &Image,
23012281
const property_list &propList)
23022282
: detail::image_accessor<DataT, Dimensions, AccessMode,
23032283
access::target::host_image, IsPlaceholder>(
2304-
Image, (detail::getSyclObjImpl(Image))->getElementSize()) {
2284+
Image, Image.getElementSize()) {
23052285
(void)propList;
23062286
}
23072287
};
@@ -2343,8 +2323,7 @@ class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
23432323
handler &CommandGroupHandler)
23442324
: detail::image_accessor<DataT, Dimensions + 1, AccessMode,
23452325
access::target::image, IsPlaceholder>(
2346-
Image, CommandGroupHandler,
2347-
(detail::getSyclObjImpl(Image))->getElementSize()) {
2326+
Image, CommandGroupHandler, Image.getElementSize()) {
23482327
#ifndef __SYCL_DEVICE_ONLY__
23492328
detail::associateWithHandler(CommandGroupHandler, this,
23502329
access::target::image_array);
@@ -2356,8 +2335,7 @@ class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
23562335
handler &CommandGroupHandler, const property_list &propList)
23572336
: detail::image_accessor<DataT, Dimensions + 1, AccessMode,
23582337
access::target::image, IsPlaceholder>(
2359-
Image, CommandGroupHandler,
2360-
(detail::getSyclObjImpl(Image))->getElementSize()) {
2338+
Image, CommandGroupHandler, Image.getElementSize()) {
23612339
(void)propList;
23622340
#ifndef __SYCL_DEVICE_ONLY__
23632341
detail::associateWithHandler(CommandGroupHandler, this,

0 commit comments

Comments
 (0)