DPC++ Runtime
Runtime libraries for oneAPI DPC++
accessor_impl.hpp
Go to the documentation of this file.
1 //==------------ accessor_impl.hpp - SYCL standard header file -------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/access/access.hpp>
12 #include <sycl/accessor.hpp>
13 #include <sycl/detail/export.hpp>
14 #include <sycl/id.hpp>
15 #include <sycl/property_list.hpp>
16 #include <sycl/range.hpp>
17 #include <sycl/stl.hpp>
18 
19 namespace sycl {
20 inline namespace _V1 {
21 template <typename, int, access::mode, access::target, access::placeholder,
22  typename>
23 class accessor;
24 
25 namespace ext {
26 namespace intel {
27 namespace esimd {
28 namespace detail {
29 // Forward declare a "back-door" access class to support ESIMD.
30 class AccessorPrivateProxy;
31 } // namespace detail
32 } // namespace esimd
33 } // namespace intel
34 } // namespace ext
35 
36 namespace detail {
37 
38 class SYCLMemObjI;
39 
40 class Command;
41 
42 class __SYCL_EXPORT AccessorImplHost {
43 public:
44  // TODO: Remove when ABI break is allowed.
45  AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
46  access::mode AccessMode, void *SYCLMemObject, int Dims,
47  int ElemSize, int OffsetInBytes = 0,
48  bool IsSubBuffer = false,
49  const property_list &PropertyList = {})
50  : MAccData(Offset, AccessRange, MemoryRange), MAccessMode(AccessMode),
51  MSYCLMemObj((detail::SYCLMemObjI *)SYCLMemObject), MDims(Dims),
52  MElemSize(ElemSize), MOffsetInBytes(OffsetInBytes),
53  MIsSubBuffer(IsSubBuffer), MPropertyList(PropertyList),
54  MIsPlaceH(false) {}
55 
56  // TODO: Remove when ABI break is allowed.
57  AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
58  access::mode AccessMode, void *SYCLMemObject, int Dims,
59  int ElemSize, bool IsPlaceH, int OffsetInBytes = 0,
60  bool IsSubBuffer = false,
61  const property_list &PropertyList = {})
62  : MAccData(Offset, AccessRange, MemoryRange), MAccessMode(AccessMode),
63  MSYCLMemObj((detail::SYCLMemObjI *)SYCLMemObject), MDims(Dims),
64  MElemSize(ElemSize), MOffsetInBytes(OffsetInBytes),
65  MIsSubBuffer(IsSubBuffer), MPropertyList(PropertyList),
66  MIsPlaceH(IsPlaceH) {}
67 
68  AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
69  access::mode AccessMode, void *SYCLMemObject, int Dims,
70  int ElemSize, size_t OffsetInBytes = 0,
71  bool IsSubBuffer = false,
72  const property_list &PropertyList = {})
73  : MAccData(Offset, AccessRange, MemoryRange), MAccessMode(AccessMode),
74  MSYCLMemObj((detail::SYCLMemObjI *)SYCLMemObject), MDims(Dims),
75  MElemSize(ElemSize), MOffsetInBytes(OffsetInBytes),
76  MIsSubBuffer(IsSubBuffer), MPropertyList(PropertyList),
77  MIsPlaceH(false) {}
78 
79  AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
80  access::mode AccessMode, void *SYCLMemObject, int Dims,
81  int ElemSize, bool IsPlaceH, size_t OffsetInBytes = 0,
82  bool IsSubBuffer = false,
83  const property_list &PropertyList = {})
84  : MAccData(Offset, AccessRange, MemoryRange), MAccessMode(AccessMode),
85  MSYCLMemObj((detail::SYCLMemObjI *)SYCLMemObject), MDims(Dims),
86  MElemSize(ElemSize), MOffsetInBytes(OffsetInBytes),
87  MIsSubBuffer(IsSubBuffer), MPropertyList(PropertyList),
88  MIsPlaceH(IsPlaceH) {}
89 
90  ~AccessorImplHost();
91 
93  : MAccData(Other.MAccData), MAccessMode(Other.MAccessMode),
94  MSYCLMemObj(Other.MSYCLMemObj), MDims(Other.MDims),
95  MElemSize(Other.MElemSize), MOffsetInBytes(Other.MOffsetInBytes),
96  MIsSubBuffer(Other.MIsSubBuffer), MPropertyList(Other.MPropertyList),
97  MIsPlaceH(Other.MIsPlaceH) {}
98 
100  MAccData = Other.MAccData;
101  MAccessMode = Other.MAccessMode;
102  MSYCLMemObj = Other.MSYCLMemObj;
103  MDims = Other.MDims;
104  MElemSize = Other.MElemSize;
105  MOffsetInBytes = Other.MOffsetInBytes;
106  MIsSubBuffer = Other.MIsSubBuffer;
107  MPropertyList = Other.MPropertyList;
108  MIsPlaceH = Other.MIsPlaceH;
109  return *this;
110  }
111 
112  // The resize method provides a way to change the size of the
113  // allocated memory and corresponding properties for the accessor.
114  // These are normally fixed for the accessor, but this capability
115  // is needed to support the stream class.
116  // Stream implementation creates an accessor with initial size for
117  // work item. But the number of work items is not available during
118  // stream construction. The resize method allows to update the accessor
119  // as the information becomes available to the handler.
120 
121  void resize(size_t GlobalSize);
122 
124 
125  id<3> &MOffset = MAccData.MOffset;
126  // The size of accessing region.
127  range<3> &MAccessRange = MAccData.MAccessRange;
128  // The size of memory object this requirement is created for.
129  range<3> &MMemoryRange = MAccData.MMemoryRange;
131 
133 
134  unsigned int MDims;
135  unsigned int MElemSize;
138 
139  void *&MData = MAccData.MData;
140 
141  Command *MBlockedCmd = nullptr;
142 
143  bool PerWI = false;
144 
145  // To preserve runtime properties
147 
148  // Placeholder flag
149  bool MIsPlaceH;
150 };
151 
152 using AccessorImplPtr = std::shared_ptr<AccessorImplHost>;
153 
154 class __SYCL_EXPORT LocalAccessorImplHost {
155 public:
156  // Allocate ElemSize more data to have sufficient padding to enforce
157  // alignment.
158  LocalAccessorImplHost(sycl::range<3> Size, int Dims, int ElemSize,
159  const property_list &PropertyList)
160  : MSize(Size), MDims(Dims), MElemSize(ElemSize),
161  MMem(Size[0] * Size[1] * Size[2] * ElemSize + ElemSize),
162  MPropertyList(PropertyList) {}
163 
165  int MDims;
167  std::vector<char> MMem;
169 };
170 
171 using LocalAccessorImplPtr = std::shared_ptr<LocalAccessorImplHost>;
172 
174 public:
176  void *SYCLMemObject, int Dims, int ElemSize,
177  id<3> Pitch, image_channel_type ChannelType,
178  image_channel_order ChannelOrder,
179  const property_list &PropertyList)
180  : AccessorImplHost(id<3>{0, 0, 0}, Size, Size, AccessMode, SYCLMemObject,
181  Dims, ElemSize, 0, false, PropertyList),
182  MPitch{Pitch}, MChannelType{ChannelType}, MChannelOrder{ChannelOrder} {}
183 
187 };
188 
190 public:
191  SampledImageAccessorImplHost(range<3> Size, void *SYCLMemObject, int Dims,
192  int ElemSize, id<3> Pitch,
193  image_channel_type ChannelType,
194  image_channel_order ChannelOrder,
195  image_sampler Sampler,
196  const property_list &PropertyList)
197  : UnsampledImageAccessorImplHost(Size, access_mode::read, SYCLMemObject,
198  Dims, ElemSize, Pitch, ChannelType,
199  ChannelOrder, PropertyList),
200  MSampler{Sampler} {}
201 
203 };
204 
206  std::shared_ptr<UnsampledImageAccessorImplHost>;
208  std::shared_ptr<SampledImageAccessorImplHost>;
209 
211 
212 } // namespace detail
213 } // namespace _V1
214 } // namespace sycl
sycl::_V1::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:31
sycl::_V1::detail::AccessorImplPtr
std::shared_ptr< AccessorImplHost > AccessorImplPtr
Definition: accessor.hpp:532
sycl::_V1::detail::Command
The Command class represents some action that needs to be performed on one or more memory objects.
Definition: commands.hpp:102
sycl::_V1::detail::LocalAccessorImplHost
Definition: accessor_impl.hpp:154
property_list.hpp
sycl::_V1::access::mode
mode
Definition: access.hpp:34
sycl::_V1::detail::AccessorImplHost::operator=
AccessorImplHost & operator=(const AccessorImplHost &Other)
Definition: accessor_impl.hpp:99
sycl::_V1::image_sampler
Definition: sampler.hpp:132
sycl::_V1::detail::AccessorImplHost::MIsSubBuffer
bool MIsSubBuffer
Definition: accessor_impl.hpp:137
stl.hpp
sycl::_V1::detail::AccessorImplHost
Definition: accessor_impl.hpp:42
sycl::_V1::detail::AccessorImplHost::MAccessMode
access::mode MAccessMode
Definition: accessor_impl.hpp:130
sycl::_V1::detail::AccessorImplHost::MElemSize
unsigned int MElemSize
Definition: accessor_impl.hpp:135
sycl::_V1::detail::AccHostDataT::MOffset
sycl::id< 3 > MOffset
Definition: accessor.hpp:258
sycl::_V1::detail::AccessorImplHost::AccessorImplHost
AccessorImplHost(const AccessorImplHost &Other)
Definition: accessor_impl.hpp:92
sycl
Definition: access.hpp:18
sycl::_V1::accessor
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor accessor(buffer< DataT, Dimensions, AllocatorT >) -> accessor< DataT, Dimensions, access::mode::read_write, target::device, access::placeholder::true_t >
Buffer accessor.
access.hpp
sycl::_V1::id< 3 >
id.hpp
sycl::_V1::detail::SampledImageAccessorImplHost
Definition: accessor_impl.hpp:189
sycl::_V1::detail::UnsampledImageAccessorImplHost::MChannelType
image_channel_type MChannelType
Definition: accessor_impl.hpp:185
sycl::_V1::range< 3 >
export.hpp
sycl::_V1::access::placeholder
placeholder
Definition: access.hpp:49
sycl::_V1::detail::AccessorImplHost::MIsPlaceH
bool MIsPlaceH
Definition: accessor_impl.hpp:149
sycl::_V1::detail::AccessorImplHost::MSYCLMemObj
detail::SYCLMemObjI * MSYCLMemObj
Definition: accessor_impl.hpp:132
sycl::_V1::detail::AccessorImplHost::AccessorImplHost
AccessorImplHost(id< 3 > Offset, range< 3 > AccessRange, range< 3 > MemoryRange, access::mode AccessMode, void *SYCLMemObject, int Dims, int ElemSize, bool IsPlaceH, size_t OffsetInBytes=0, bool IsSubBuffer=false, const property_list &PropertyList={})
Definition: accessor_impl.hpp:79
range.hpp
sycl::_V1::detail::UnsampledImageAccessorImplPtr
std::shared_ptr< UnsampledImageAccessorImplHost > UnsampledImageAccessorImplPtr
Definition: accessor.hpp:631
sycl::_V1::detail::SampledImageAccessorImplPtr
std::shared_ptr< SampledImageAccessorImplHost > SampledImageAccessorImplPtr
Definition: accessor.hpp:633
sycl::_V1::detail::LocalAccessorImplHost::LocalAccessorImplHost
LocalAccessorImplHost(sycl::range< 3 > Size, int Dims, int ElemSize, const property_list &PropertyList)
Definition: accessor_impl.hpp:158
sycl::_V1::detail::AccHostDataT::MData
void * MData
Definition: accessor.hpp:261
sycl::_V1::image_channel_order
image_channel_order
Definition: image.hpp:57
sycl::_V1::detail::SampledImageAccessorImplHost::MSampler
image_sampler MSampler
Definition: accessor_impl.hpp:202
sycl::_V1::detail::UnsampledImageAccessorImplHost::UnsampledImageAccessorImplHost
UnsampledImageAccessorImplHost(range< 3 > Size, access_mode AccessMode, void *SYCLMemObject, int Dims, int ElemSize, id< 3 > Pitch, image_channel_type ChannelType, image_channel_order ChannelOrder, const property_list &PropertyList)
Definition: accessor_impl.hpp:175
sycl::_V1::access::target
target
Definition: access.hpp:22
sycl::_V1::detail::AccessorImplHost::MPropertyList
property_list MPropertyList
Definition: accessor_impl.hpp:146
sycl::_V1::detail::AccessorImplHost::AccessorImplHost
AccessorImplHost(id< 3 > Offset, range< 3 > AccessRange, range< 3 > MemoryRange, access::mode AccessMode, void *SYCLMemObject, int Dims, int ElemSize, bool IsPlaceH, int OffsetInBytes=0, bool IsSubBuffer=false, const property_list &PropertyList={})
Definition: accessor_impl.hpp:57
sycl::_V1::detail::LocalAccessorImplPtr
std::shared_ptr< LocalAccessorImplHost > LocalAccessorImplPtr
Definition: accessor.hpp:601
accessor.hpp
sycl::_V1::detail::LocalAccessorImplHost::MElemSize
int MElemSize
Definition: accessor_impl.hpp:166
sycl::_V1::detail::AccessorImplHost::AccessorImplHost
AccessorImplHost(id< 3 > Offset, range< 3 > AccessRange, range< 3 > MemoryRange, access::mode AccessMode, void *SYCLMemObject, int Dims, int ElemSize, size_t OffsetInBytes=0, bool IsSubBuffer=false, const property_list &PropertyList={})
Definition: accessor_impl.hpp:68
sycl::_V1::detail::UnsampledImageAccessorImplHost
Definition: accessor_impl.hpp:173
sycl::_V1::detail::AccHostDataT
Definition: accessor.hpp:252
sycl::_V1::detail::LocalAccessorImplHost::MSize
sycl::range< 3 > MSize
Definition: accessor_impl.hpp:164
sycl::_V1::detail::AccHostDataT::MAccessRange
sycl::range< 3 > MAccessRange
Definition: accessor.hpp:259
sycl::_V1::detail::AccHostDataT::MMemoryRange
sycl::range< 3 > MMemoryRange
Definition: accessor.hpp:260
sycl::_V1::detail::SampledImageAccessorImplHost::SampledImageAccessorImplHost
SampledImageAccessorImplHost(range< 3 > Size, void *SYCLMemObject, int Dims, int ElemSize, id< 3 > Pitch, image_channel_type ChannelType, image_channel_order ChannelOrder, image_sampler Sampler, const property_list &PropertyList)
Definition: accessor_impl.hpp:191
sycl::_V1::detail::LocalAccessorImplHost::MMem
std::vector< char > MMem
Definition: accessor_impl.hpp:167
sycl::_V1::detail::LocalAccessorImplHost::MPropertyList
property_list MPropertyList
Definition: accessor_impl.hpp:168
sycl::_V1::detail::UnsampledImageAccessorImplHost::MPitch
id< 3 > MPitch
Definition: accessor_impl.hpp:184
sycl::_V1::detail::SYCLMemObjI
Definition: sycl_mem_obj_i.hpp:28
sycl::_V1::detail::AccessorImplHost::MOffsetInBytes
size_t MOffsetInBytes
Definition: accessor_impl.hpp:136
sycl::_V1::detail::LocalAccessorImplHost::MDims
int MDims
Definition: accessor_impl.hpp:165
sycl::_V1::detail::AccessorImplHost::MDims
unsigned int MDims
Definition: accessor_impl.hpp:134
sycl::_V1::detail::AccessorImplHost::MAccData
detail::AccHostDataT MAccData
Definition: accessor_impl.hpp:123
sycl::_V1::detail::AccessorImplHost::AccessorImplHost
AccessorImplHost(id< 3 > Offset, range< 3 > AccessRange, range< 3 > MemoryRange, access::mode AccessMode, void *SYCLMemObject, int Dims, int ElemSize, int OffsetInBytes=0, bool IsSubBuffer=false, const property_list &PropertyList={})
Definition: accessor_impl.hpp:45
sycl::_V1::image_channel_type
image_channel_type
Definition: image.hpp:75
sycl::_V1::AccessMode
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS AccessMode
Definition: accessor.hpp:3235
sycl::_V1::detail::UnsampledImageAccessorImplHost::MChannelOrder
image_channel_order MChannelOrder
Definition: accessor_impl.hpp:186