DPC++ Runtime
Runtime libraries for oneAPI DPC++
accessor.cpp
Go to the documentation of this file.
1 //==------------ accessor.cpp - SYCL standard source 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 #include <detail/queue_impl.hpp>
11 #include <sycl/accessor.hpp>
12 
13 namespace sycl {
14 inline namespace _V1 {
15 namespace detail {
17  assert((cgh.MQueue || cgh.MGraph) &&
18  "One of MQueue or MGraph should be nonnull!");
19  if (cgh.MQueue)
20  return cgh.MQueue->get_device();
21 
22  return cgh.MGraph->getDevice();
23 }
24 
25 // TODO: the following function to be removed during next ABI break window
27  range<3> MemoryRange,
28  access::mode AccessMode, void *SYCLMemObject,
29  int Dims, int ElemSize, int OffsetInBytes,
30  bool IsSubBuffer,
31  const property_list &PropertyList) {
32  impl = std::shared_ptr<AccessorImplHost>(
33  new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
34  (detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
35  false, OffsetInBytes, IsSubBuffer, PropertyList));
36 }
37 
38 // TODO: the following function to be removed during next ABI break window
40  range<3> MemoryRange,
41  access::mode AccessMode, void *SYCLMemObject,
42  int Dims, int ElemSize, bool IsPlaceH,
43  int OffsetInBytes, bool IsSubBuffer,
44  const property_list &PropertyList) {
45  impl = std::shared_ptr<AccessorImplHost>(
46  new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
47  (detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
48  IsPlaceH, OffsetInBytes, IsSubBuffer, PropertyList));
49 }
50 
52  range<3> MemoryRange,
53  access::mode AccessMode, void *SYCLMemObject,
54  int Dims, int ElemSize, size_t OffsetInBytes,
55  bool IsSubBuffer,
56  const property_list &PropertyList) {
57  impl = std::shared_ptr<AccessorImplHost>(
58  new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
59  (detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
60  false, OffsetInBytes, IsSubBuffer, PropertyList));
61 }
62 
64  range<3> MemoryRange,
65  access::mode AccessMode, void *SYCLMemObject,
66  int Dims, int ElemSize, bool IsPlaceH,
67  size_t OffsetInBytes, bool IsSubBuffer,
68  const property_list &PropertyList) {
69  impl = std::shared_ptr<AccessorImplHost>(
70  new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
71  (detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
72  IsPlaceH, OffsetInBytes, IsSubBuffer, PropertyList));
73 }
74 
75 id<3> &AccessorBaseHost::getOffset() { return impl->MOffset; }
76 range<3> &AccessorBaseHost::getAccessRange() { return impl->MAccessRange; }
77 range<3> &AccessorBaseHost::getMemoryRange() { return impl->MMemoryRange; }
78 void *AccessorBaseHost::getPtr() noexcept { return impl->MData; }
79 
81 
83  return impl->MPropertyList;
84 }
85 
86 unsigned int AccessorBaseHost::getElemSize() const { return impl->MElemSize; }
87 
88 const id<3> &AccessorBaseHost::getOffset() const { return impl->MOffset; }
90  return impl->MAccessRange;
91 }
93  return impl->MMemoryRange;
94 }
96  return const_cast<void *>(impl->MData);
97 }
98 
99 void *AccessorBaseHost::getMemoryObject() const { return impl->MSYCLMemObj; }
100 
101 bool AccessorBaseHost::isPlaceholder() const { return impl->MIsPlaceH; }
102 
104  return static_cast<detail::SYCLMemObjT *>(impl->MSYCLMemObj)->isUsedInGraph();
105 }
106 
108  sycl::range<3> Size, int Dims, int ElemSize,
109  const property_list &PropertyList) {
110  impl = std::shared_ptr<LocalAccessorImplHost>(
111  new LocalAccessorImplHost(Size, Dims, ElemSize, PropertyList));
112 }
115  return impl->MSize;
116 }
118  // Const cast this in order to call the const getPtr.
119  return const_cast<const LocalAccessorBaseHost *>(this)->getPtr();
120 }
122  char *ptr = impl->MMem.data();
123 
124  // Align the pointer to MElemSize.
125  size_t val = reinterpret_cast<size_t>(ptr);
126  if (val % impl->MElemSize != 0) {
127  ptr += impl->MElemSize - val % impl->MElemSize;
128  }
129 
130  return ptr;
131 }
133  return impl->MPropertyList;
134 }
135 
137 int LocalAccessorBaseHost::getElementSize() { return impl->MElemSize; }
138 
140  sycl::range<3> Size, access_mode AccessMode, void *SYCLMemObject, int Dims,
141  int ElemSize, id<3> Pitch, image_channel_type ChannelType,
142  image_channel_order ChannelOrder, const property_list &PropertyList) {
143  impl = std::make_shared<UnsampledImageAccessorImplHost>(
144  Size, AccessMode, (detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
145  Pitch, ChannelType, ChannelOrder, PropertyList);
146 }
148  return impl->MAccessRange;
149 }
151  return impl->MPropertyList;
152 }
154  return impl->MSYCLMemObj;
155 }
157  return impl->MAccData;
158 }
161  return const_cast<void *>(impl->MData);
162 }
165  return impl->MElemSize;
166 }
169  return impl->MChannelType;
170 }
172  return impl->MChannelOrder;
173 }
174 
176  sycl::range<3> Size, void *SYCLMemObject, int Dims, int ElemSize,
177  id<3> Pitch, image_channel_type ChannelType,
178  image_channel_order ChannelOrder, image_sampler Sampler,
179  const property_list &PropertyList) {
180  impl = std::make_shared<SampledImageAccessorImplHost>(
181  Size, (detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize, Pitch,
182  ChannelType, ChannelOrder, Sampler, PropertyList);
183 }
185  return impl->MAccessRange;
186 }
188  return impl->MPropertyList;
189 }
191  return impl->MSYCLMemObj;
192 }
194  return impl->MAccData;
195 }
196 void *SampledImageAccessorBaseHost::getPtr() { return impl->MData; }
198  return const_cast<void *>(impl->MData);
199 }
200 int SampledImageAccessorBaseHost::getNumOfDims() const { return impl->MDims; }
202  return impl->MElemSize;
203 }
206  return impl->MChannelType;
207 }
209  return impl->MChannelOrder;
210 }
212  return impl->MSampler;
213 }
214 
215 } // namespace detail
216 } // namespace _V1
217 } // namespace sycl
The file contains implementations of accessor class.
unsigned int getElemSize() const
Definition: accessor.cpp:86
const property_list & getPropList() const
Definition: accessor.cpp:82
detail::AccHostDataT & getAccData()
Definition: accessor.cpp:80
AccessorBaseHost(const AccessorImplPtr &Impl)
Definition: accessor.hpp:536
const property_list & getPropList() const
Definition: accessor.cpp:132
LocalAccessorBaseHost(const LocalAccessorImplPtr &Impl)
Definition: accessor.hpp:605
image_channel_type getChannelType() const
Definition: accessor.cpp:205
const sycl::range< 3 > & getSize() const
Definition: accessor.cpp:184
const property_list & getPropList() const
Definition: accessor.cpp:187
image_channel_order getChannelOrder() const
Definition: accessor.cpp:208
SampledImageAccessorBaseHost(const SampledImageAccessorImplPtr &Impl)
Definition: accessor.hpp:710
UnsampledImageAccessorBaseHost(const UnsampledImageAccessorImplPtr &Impl)
Definition: accessor.hpp:642
const sycl::range< 3 > & getSize() const
Definition: accessor.cpp:147
const property_list & getPropList() const
Definition: accessor.cpp:150
image_channel_order getChannelOrder() const
Definition: accessor.cpp:171
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
Command group handler class.
Definition: handler.hpp:458
Objects of the property_list class are containers for the SYCL properties.
device getDeviceFromHandler(handler &CommandGroupHandlerRef)
Definition: accessor.cpp:16
image_channel_order
Definition: image.hpp:56
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS AccessMode
Definition: accessor.hpp:3233
image_channel_type
Definition: image.hpp:74
Definition: access.hpp:18
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324