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  AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
45  access::mode AccessMode, void *SYCLMemObject, int Dims,
46  int ElemSize, int 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 
54  ~AccessorImplHost();
55 
57  : MAccData(Other.MAccData), MAccessMode(Other.MAccessMode),
58  MSYCLMemObj(Other.MSYCLMemObj), MDims(Other.MDims),
59  MElemSize(Other.MElemSize), MOffsetInBytes(Other.MOffsetInBytes),
60  MIsSubBuffer(Other.MIsSubBuffer), MPropertyList(Other.MPropertyList) {}
61 
63  MAccData = Other.MAccData;
64  MAccessMode = Other.MAccessMode;
65  MSYCLMemObj = Other.MSYCLMemObj;
66  MDims = Other.MDims;
67  MElemSize = Other.MElemSize;
68  MOffsetInBytes = Other.MOffsetInBytes;
69  MIsSubBuffer = Other.MIsSubBuffer;
70  MPropertyList = Other.MPropertyList;
71  return *this;
72  }
73 
74  // The resize method provides a way to change the size of the
75  // allocated memory and corresponding properties for the accessor.
76  // These are normally fixed for the accessor, but this capability
77  // is needed to support the stream class.
78  // Stream implementation creates an accessor with initial size for
79  // work item. But the number of work items is not available during
80  // stream construction. The resize method allows to update the accessor
81  // as the information becomes available to the handler.
82 
83  void resize(size_t GlobalSize);
84 
86 
87  id<3> &MOffset = MAccData.MOffset;
88  // The size of accessing region.
89  range<3> &MAccessRange = MAccData.MAccessRange;
90  // The size of memory object this requirement is created for.
91  range<3> &MMemoryRange = MAccData.MMemoryRange;
93 
95 
96  unsigned int MDims;
97  unsigned int MElemSize;
98  unsigned int MOffsetInBytes;
100 
101  void *&MData = MAccData.MData;
102 
103  Command *MBlockedCmd = nullptr;
104 
105  bool PerWI = false;
106 
107  // To preserve runtime properties
109 };
110 
111 using AccessorImplPtr = std::shared_ptr<AccessorImplHost>;
112 
113 class __SYCL_EXPORT LocalAccessorImplHost {
114 public:
115  // Allocate ElemSize more data to have sufficient padding to enforce
116  // alignment.
117  LocalAccessorImplHost(sycl::range<3> Size, int Dims, int ElemSize,
118  const property_list &PropertyList)
119  : MSize(Size), MDims(Dims), MElemSize(ElemSize),
120  MMem(Size[0] * Size[1] * Size[2] * ElemSize + ElemSize),
121  MPropertyList(PropertyList) {}
122 
123  sycl::range<3> MSize;
124  int MDims;
126  std::vector<char> MMem;
128 };
129 
130 using LocalAccessorImplPtr = std::shared_ptr<LocalAccessorImplHost>;
131 
133 
134 } // namespace detail
135 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
136 } // namespace sycl
The file contains implementations of accessor class.
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={})
The Command class represents some action that needs to be performed on one or more memory objects.
Definition: commands.hpp:95
LocalAccessorImplHost(sycl::range< 3 > Size, int Dims, int ElemSize, const property_list &PropertyList)
Objects of the property_list class are containers for the SYCL properties.
#define __SYCL_INLINE_VER_NAMESPACE(X)
std::shared_ptr< LocalAccessorImplHost > LocalAccessorImplPtr
Definition: accessor.hpp:515
std::shared_ptr< AccessorImplHost > AccessorImplPtr
Definition: accessor.hpp:473
class __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_SPECIAL_CLASS AccessMode
Definition: accessor.hpp:2747
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::range< 3 > MMemoryRange
Definition: accessor.hpp:243
sycl::range< 3 > MAccessRange
Definition: accessor.hpp:242