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 
43 public:
44  AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
45  access::mode AccessMode, void *SYCLMemObject, int Dims,
46  int ElemSize, size_t OffsetInBytes = 0,
47  bool IsSubBuffer = false,
48  const property_list &PropertyList = {})
49  : MAccData(Offset, AccessRange, MemoryRange), MAccessMode(AccessMode),
50  MSYCLMemObj((detail::SYCLMemObjI *)SYCLMemObject), MDims(Dims),
51  MElemSize(ElemSize), MOffsetInBytes(OffsetInBytes),
52  MIsSubBuffer(IsSubBuffer), MPropertyList(PropertyList),
53  MIsPlaceH(false) {}
54 
55  AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
56  access::mode AccessMode, void *SYCLMemObject, int Dims,
57  int ElemSize, bool IsPlaceH, size_t OffsetInBytes = 0,
58  bool IsSubBuffer = false,
59  const property_list &PropertyList = {})
60  : MAccData(Offset, AccessRange, MemoryRange), MAccessMode(AccessMode),
61  MSYCLMemObj((detail::SYCLMemObjI *)SYCLMemObject), MDims(Dims),
62  MElemSize(ElemSize), MOffsetInBytes(OffsetInBytes),
63  MIsSubBuffer(IsSubBuffer), MPropertyList(PropertyList),
64  MIsPlaceH(IsPlaceH) {}
65 
67 
69  : MAccData(Other.MAccData), MAccessMode(Other.MAccessMode),
70  MSYCLMemObj(Other.MSYCLMemObj), MDims(Other.MDims),
73  MIsPlaceH(Other.MIsPlaceH) {}
74 
76  MAccData = Other.MAccData;
77  MAccessMode = Other.MAccessMode;
78  MSYCLMemObj = Other.MSYCLMemObj;
79  MDims = Other.MDims;
80  MElemSize = Other.MElemSize;
82  MIsSubBuffer = Other.MIsSubBuffer;
84  MIsPlaceH = Other.MIsPlaceH;
85  return *this;
86  }
87 
88  // The resize method provides a way to change the size of the
89  // allocated memory and corresponding properties for the accessor.
90  // These are normally fixed for the accessor, but this capability
91  // is needed to support the stream class.
92  // Stream implementation creates an accessor with initial size for
93  // work item. But the number of work items is not available during
94  // stream construction. The resize method allows to update the accessor
95  // as the information becomes available to the handler.
96 
97  void resize(size_t GlobalSize);
98 
100 
102  // The size of accessing region.
104  // The size of memory object this requirement is created for.
107 
109 
110  unsigned int MDims;
111  unsigned int MElemSize;
114 
115  void *&MData = MAccData.MData;
116 
117  Command *MBlockedCmd = nullptr;
118 
119  bool PerWI = false;
120 
121  // To preserve runtime properties
123 
124  // Placeholder flag
125  bool MIsPlaceH;
126 };
127 
128 using AccessorImplPtr = std::shared_ptr<AccessorImplHost>;
129 
131 public:
132  // Allocate ElemSize more data to have sufficient padding to enforce
133  // alignment.
134  LocalAccessorImplHost(sycl::range<3> Size, int Dims, int ElemSize,
135  const property_list &PropertyList)
136  : MSize(Size), MDims(Dims), MElemSize(ElemSize),
137  MMem(Size[0] * Size[1] * Size[2] * ElemSize + ElemSize),
138  MPropertyList(PropertyList) {}
139 
141  int MDims;
143  std::vector<char> MMem;
145 };
146 
147 using LocalAccessorImplPtr = std::shared_ptr<LocalAccessorImplHost>;
148 
150 public:
152  void *SYCLMemObject, int Dims, int ElemSize,
153  id<3> Pitch, image_channel_type ChannelType,
154  image_channel_order ChannelOrder,
155  const property_list &PropertyList)
156  : AccessorImplHost(id<3>{0, 0, 0}, Size, Size, AccessMode, SYCLMemObject,
157  Dims, ElemSize, 0, false, PropertyList),
158  MPitch{Pitch}, MChannelType{ChannelType}, MChannelOrder{ChannelOrder} {}
159 
163 };
164 
166 public:
167  SampledImageAccessorImplHost(range<3> Size, void *SYCLMemObject, int Dims,
168  int ElemSize, id<3> Pitch,
169  image_channel_type ChannelType,
170  image_channel_order ChannelOrder,
171  image_sampler Sampler,
172  const property_list &PropertyList)
173  : UnsampledImageAccessorImplHost(Size, access_mode::read, SYCLMemObject,
174  Dims, ElemSize, Pitch, ChannelType,
175  ChannelOrder, PropertyList),
176  MSampler{Sampler} {}
177 
179 };
180 
182  std::shared_ptr<UnsampledImageAccessorImplHost>;
184  std::shared_ptr<SampledImageAccessorImplHost>;
185 
187 
188 } // namespace detail
189 } // namespace _V1
190 } // 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, size_t OffsetInBytes=0, bool IsSubBuffer=false, const property_list &PropertyList={})
AccessorImplHost & operator=(const AccessorImplHost &Other)
AccessorImplHost(const AccessorImplHost &Other)
void resize(size_t GlobalSize)
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:109
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:570
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