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/accessor_image.hpp>
14 #include <sycl/detail/export.hpp>
15 #include <sycl/id.hpp>
16 #include <sycl/property_list.hpp>
17 #include <sycl/range.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
The file contains implementations of accessor class.
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={})
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={})
AccessorImplHost & operator=(const AccessorImplHost &Other)
AccessorImplHost(const AccessorImplHost &Other)
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={})
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={})
The Command class represents some action that needs to be performed on one or more memory objects.
Definition: commands.hpp:107
LocalAccessorImplHost(sycl::range< 3 > Size, int Dims, int ElemSize, const property_list &PropertyList)
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)
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)
Objects of the property_list class are containers for the SYCL properties.
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.
std::shared_ptr< UnsampledImageAccessorImplHost > UnsampledImageAccessorImplPtr
std::shared_ptr< SampledImageAccessorImplHost > SampledImageAccessorImplPtr
std::shared_ptr< LocalAccessorImplHost > LocalAccessorImplPtr
Definition: accessor.hpp:583
std::shared_ptr< AccessorImplHost > AccessorImplPtr
Definition: accessor.hpp:514
image_channel_order
Definition: image.hpp:56
class __SYCL_EBO __SYCL_SPECIAL_CLASS AccessMode
image_channel_type
Definition: image.hpp:74
Definition: access.hpp:18
sycl::range< 3 > MMemoryRange
Definition: accessor.hpp:252
sycl::range< 3 > MAccessRange
Definition: accessor.hpp:251