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 {
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  AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
57  access::mode AccessMode, void *SYCLMemObject, int Dims,
58  int ElemSize, bool IsPlaceH, int OffsetInBytes = 0,
59  bool IsSubBuffer = false,
60  const property_list &PropertyList = {})
61  : MAccData(Offset, AccessRange, MemoryRange), MAccessMode(AccessMode),
62  MSYCLMemObj((detail::SYCLMemObjI *)SYCLMemObject), MDims(Dims),
63  MElemSize(ElemSize), MOffsetInBytes(OffsetInBytes),
64  MIsSubBuffer(IsSubBuffer), MPropertyList(PropertyList),
65  MIsPlaceH(IsPlaceH) {}
66 
67  ~AccessorImplHost();
68 
70  : MAccData(Other.MAccData), MAccessMode(Other.MAccessMode),
71  MSYCLMemObj(Other.MSYCLMemObj), MDims(Other.MDims),
72  MElemSize(Other.MElemSize), MOffsetInBytes(Other.MOffsetInBytes),
73  MIsSubBuffer(Other.MIsSubBuffer), MPropertyList(Other.MPropertyList),
74  MIsPlaceH(Other.MIsPlaceH) {}
75 
77  MAccData = Other.MAccData;
78  MAccessMode = Other.MAccessMode;
79  MSYCLMemObj = Other.MSYCLMemObj;
80  MDims = Other.MDims;
81  MElemSize = Other.MElemSize;
82  MOffsetInBytes = Other.MOffsetInBytes;
83  MIsSubBuffer = Other.MIsSubBuffer;
84  MPropertyList = Other.MPropertyList;
85  MIsPlaceH = Other.MIsPlaceH;
86  return *this;
87  }
88 
89  // The resize method provides a way to change the size of the
90  // allocated memory and corresponding properties for the accessor.
91  // These are normally fixed for the accessor, but this capability
92  // is needed to support the stream class.
93  // Stream implementation creates an accessor with initial size for
94  // work item. But the number of work items is not available during
95  // stream construction. The resize method allows to update the accessor
96  // as the information becomes available to the handler.
97 
98  void resize(size_t GlobalSize);
99 
101 
102  id<3> &MOffset = MAccData.MOffset;
103  // The size of accessing region.
104  range<3> &MAccessRange = MAccData.MAccessRange;
105  // The size of memory object this requirement is created for.
106  range<3> &MMemoryRange = MAccData.MMemoryRange;
108 
110 
111  unsigned int MDims;
112  unsigned int MElemSize;
113  unsigned int MOffsetInBytes;
115 
116  void *&MData = MAccData.MData;
117 
118  Command *MBlockedCmd = nullptr;
119 
120  bool PerWI = false;
121 
122  // To preserve runtime properties
124 
125  // Placeholder flag
126  bool MIsPlaceH;
127 };
128 
129 using AccessorImplPtr = std::shared_ptr<AccessorImplHost>;
130 
131 class __SYCL_EXPORT LocalAccessorImplHost {
132 public:
133  // Allocate ElemSize more data to have sufficient padding to enforce
134  // alignment.
135  LocalAccessorImplHost(sycl::range<3> Size, int Dims, int ElemSize,
136  const property_list &PropertyList)
137  : MSize(Size), MDims(Dims), MElemSize(ElemSize),
138  MMem(Size[0] * Size[1] * Size[2] * ElemSize + ElemSize),
139  MPropertyList(PropertyList) {}
140 
141  sycl::range<3> MSize;
142  int MDims;
144  std::vector<char> MMem;
146 };
147 
148 using LocalAccessorImplPtr = std::shared_ptr<LocalAccessorImplHost>;
149 
151 
152 } // namespace detail
153 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
154 } // namespace sycl
sycl::_V1::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:24
sycl::_V1::detail::AccessorImplPtr
std::shared_ptr< AccessorImplHost > AccessorImplPtr
Definition: accessor.hpp:464
sycl::_V1::detail::Command
The Command class represents some action that needs to be performed on one or more memory objects.
Definition: commands.hpp:99
sycl::_V1::detail::LocalAccessorImplHost
Definition: accessor_impl.hpp:131
property_list.hpp
sycl::_V1::access::mode
mode
Definition: access.hpp:30
sycl::_V1::detail::AccessorImplHost::operator=
AccessorImplHost & operator=(const AccessorImplHost &Other)
Definition: accessor_impl.hpp:76
sycl::_V1::detail::AccessorImplHost::MIsSubBuffer
bool MIsSubBuffer
Definition: accessor_impl.hpp:114
stl.hpp
sycl::_V1::detail::AccessorImplHost
Definition: accessor_impl.hpp:42
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::detail::AccessorImplHost::MAccessMode
access::mode MAccessMode
Definition: accessor_impl.hpp:107
sycl::_V1::detail::AccessorImplHost::MElemSize
unsigned int MElemSize
Definition: accessor_impl.hpp:112
sycl::_V1::detail::AccHostDataT::MOffset
sycl::id< 3 > MOffset
Definition: accessor.hpp:237
sycl::_V1::detail::AccessorImplHost::AccessorImplHost
AccessorImplHost(const AccessorImplHost &Other)
Definition: accessor_impl.hpp:69
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::detail::AccessorImplHost::MOffsetInBytes
unsigned int MOffsetInBytes
Definition: accessor_impl.hpp:113
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::range< 3 >
export.hpp
sycl::_V1::access::placeholder
placeholder
Definition: access.hpp:45
sycl::_V1::detail::AccessorImplHost::MIsPlaceH
bool MIsPlaceH
Definition: accessor_impl.hpp:126
sycl::_V1::detail::AccessorImplHost::MSYCLMemObj
detail::SYCLMemObjI * MSYCLMemObj
Definition: accessor_impl.hpp:109
range.hpp
sycl::_V1::detail::LocalAccessorImplHost::LocalAccessorImplHost
LocalAccessorImplHost(sycl::range< 3 > Size, int Dims, int ElemSize, const property_list &PropertyList)
Definition: accessor_impl.hpp:135
sycl::_V1::detail::AccHostDataT::MData
void * MData
Definition: accessor.hpp:240
sycl::_V1::access::target
target
Definition: access.hpp:18
sycl::_V1::detail::AccessorImplHost::MPropertyList
property_list MPropertyList
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, bool IsPlaceH, int OffsetInBytes=0, bool IsSubBuffer=false, const property_list &PropertyList={})
Definition: accessor_impl.hpp:56
sycl::_V1::detail::LocalAccessorImplPtr
std::shared_ptr< LocalAccessorImplHost > LocalAccessorImplPtr
Definition: accessor.hpp:519
accessor.hpp
sycl::_V1::detail::LocalAccessorImplHost::MElemSize
int MElemSize
Definition: accessor_impl.hpp:143
sycl::_V1::detail::AccHostDataT
Definition: accessor.hpp:231
sycl::_V1::detail::LocalAccessorImplHost::MSize
sycl::range< 3 > MSize
Definition: accessor_impl.hpp:141
sycl::_V1::detail::AccHostDataT::MAccessRange
sycl::range< 3 > MAccessRange
Definition: accessor.hpp:238
sycl::_V1::detail::AccHostDataT::MMemoryRange
sycl::range< 3 > MMemoryRange
Definition: accessor.hpp:239
sycl::_V1::detail::LocalAccessorImplHost::MMem
std::vector< char > MMem
Definition: accessor_impl.hpp:144
sycl::_V1::detail::LocalAccessorImplHost::MPropertyList
property_list MPropertyList
Definition: accessor_impl.hpp:145
sycl::_V1::detail::SYCLMemObjI
Definition: sycl_mem_obj_i.hpp:28
sycl::_V1::detail::LocalAccessorImplHost::MDims
int MDims
Definition: accessor_impl.hpp:142
sycl::_V1::detail::AccessorImplHost::MDims
unsigned int MDims
Definition: accessor_impl.hpp:111
sycl::_V1::detail::AccessorImplHost::MAccData
detail::AccHostDataT MAccData
Definition: accessor_impl.hpp:100
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::AccessMode
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS AccessMode
Definition: accessor.hpp:2854