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 #include <sycl/accessor_image.hpp>
13 
14 namespace sycl {
15 inline namespace _V1 {
16 namespace detail {
18  assert((cgh.MQueue || getSyclObjImpl(cgh)->MGraph) &&
19  "One of MQueue or MGraph should be nonnull!");
20  if (cgh.MQueue)
21  return cgh.MQueue->get_device();
22 
23  return getSyclObjImpl(cgh)->MGraph->getDevice();
24 }
25 
27  range<3> MemoryRange,
28  access::mode AccessMode, void *SYCLMemObject,
29  int Dims, int ElemSize, size_t 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 
39  range<3> MemoryRange,
40  access::mode AccessMode, void *SYCLMemObject,
41  int Dims, int ElemSize, bool IsPlaceH,
42  size_t OffsetInBytes, bool IsSubBuffer,
43  const property_list &PropertyList) {
44  impl = std::shared_ptr<AccessorImplHost>(
45  new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
46  (detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
47  IsPlaceH, OffsetInBytes, IsSubBuffer, PropertyList));
48 }
49 
50 id<3> &AccessorBaseHost::getOffset() { return impl->MOffset; }
51 range<3> &AccessorBaseHost::getAccessRange() { return impl->MAccessRange; }
52 range<3> &AccessorBaseHost::getMemoryRange() { return impl->MMemoryRange; }
53 void *AccessorBaseHost::getPtr() noexcept { return impl->MData; }
54 
56 
58  return impl->MPropertyList;
59 }
60 
61 unsigned int AccessorBaseHost::getElemSize() const { return impl->MElemSize; }
62 
63 const id<3> &AccessorBaseHost::getOffset() const { return impl->MOffset; }
65  return impl->MAccessRange;
66 }
68  return impl->MMemoryRange;
69 }
71  return const_cast<void *>(impl->MData);
72 }
73 
74 void *AccessorBaseHost::getMemoryObject() const { return impl->MSYCLMemObj; }
75 
76 bool AccessorBaseHost::isPlaceholder() const { return impl->MIsPlaceH; }
77 
79  return static_cast<detail::SYCLMemObjT *>(impl->MSYCLMemObj)->isUsedInGraph();
80 }
81 
83  sycl::range<3> Size, int Dims, int ElemSize,
84  const property_list &PropertyList) {
85  impl = std::shared_ptr<LocalAccessorImplHost>(
86  new LocalAccessorImplHost(Size, Dims, ElemSize, PropertyList));
87 }
90  return impl->MSize;
91 }
93  // Const cast this in order to call the const getPtr.
94  return const_cast<const LocalAccessorBaseHost *>(this)->getPtr();
95 }
97  char *ptr = impl->MMem.data();
98 
99  // Align the pointer to MElemSize.
100  size_t val = reinterpret_cast<size_t>(ptr);
101  if (val % impl->MElemSize != 0) {
102  ptr += impl->MElemSize - val % impl->MElemSize;
103  }
104 
105  return ptr;
106 }
108  return impl->MPropertyList;
109 }
110 
112 int LocalAccessorBaseHost::getElementSize() { return impl->MElemSize; }
113 
115  sycl::range<3> Size, access_mode AccessMode, void *SYCLMemObject, int Dims,
116  int ElemSize, id<3> Pitch, image_channel_type ChannelType,
117  image_channel_order ChannelOrder, const property_list &PropertyList) {
118  impl = std::make_shared<UnsampledImageAccessorImplHost>(
119  Size, AccessMode, (detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
120  Pitch, ChannelType, ChannelOrder, PropertyList);
121 }
123  return impl->MAccessRange;
124 }
126  return impl->MPropertyList;
127 }
129  return impl->MSYCLMemObj;
130 }
132  return impl->MAccData;
133 }
136  return const_cast<void *>(impl->MData);
137 }
140  return impl->MElemSize;
141 }
144  return impl->MChannelType;
145 }
147  return impl->MChannelOrder;
148 }
149 
151  sycl::range<3> Size, void *SYCLMemObject, int Dims, int ElemSize,
152  id<3> Pitch, image_channel_type ChannelType,
153  image_channel_order ChannelOrder, image_sampler Sampler,
154  const property_list &PropertyList) {
155  impl = std::make_shared<SampledImageAccessorImplHost>(
156  Size, (detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize, Pitch,
157  ChannelType, ChannelOrder, Sampler, PropertyList);
158 }
160  return impl->MAccessRange;
161 }
163  return impl->MPropertyList;
164 }
166  return impl->MSYCLMemObj;
167 }
169  return impl->MAccData;
170 }
171 void *SampledImageAccessorBaseHost::getPtr() { return impl->MData; }
173  return const_cast<void *>(impl->MData);
174 }
175 int SampledImageAccessorBaseHost::getNumOfDims() const { return impl->MDims; }
177  return impl->MElemSize;
178 }
181  return impl->MChannelType;
182 }
184  return impl->MChannelOrder;
185 }
187  return impl->MSampler;
188 }
189 
190 } // namespace detail
191 } // namespace _V1
192 } // namespace sycl
The file contains implementations of accessor class.
unsigned int getElemSize() const
Definition: accessor.cpp:61
const property_list & getPropList() const
Definition: accessor.cpp:57
detail::AccHostDataT & getAccData()
Definition: accessor.cpp:55
AccessorBaseHost(const AccessorImplPtr &Impl)
Definition: accessor.hpp:518
const property_list & getPropList() const
Definition: accessor.cpp:107
LocalAccessorBaseHost(const LocalAccessorImplPtr &Impl)
Definition: accessor.hpp:574
image_channel_type getChannelType() const
Definition: accessor.cpp:180
const sycl::range< 3 > & getSize() const
Definition: accessor.cpp:159
const property_list & getPropList() const
Definition: accessor.cpp:162
image_channel_order getChannelOrder() const
Definition: accessor.cpp:183
SampledImageAccessorBaseHost(const SampledImageAccessorImplPtr &Impl)
UnsampledImageAccessorBaseHost(const UnsampledImageAccessorImplPtr &Impl)
const sycl::range< 3 > & getSize() const
Definition: accessor.cpp:122
const property_list & getPropList() const
Definition: accessor.cpp:125
image_channel_order getChannelOrder() const
Definition: accessor.cpp:146
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:467
Objects of the property_list class are containers for the SYCL properties.
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:31
device getDeviceFromHandler(handler &CommandGroupHandlerRef)
Definition: accessor.cpp:17
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
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324