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>
10 #include <sycl/accessor.hpp>
11 
12 namespace sycl {
14 namespace detail {
15 device getDeviceFromHandler(handler &CommandGroupHandlerRef) {
16  return CommandGroupHandlerRef.MQueue->get_device();
17 }
18 
19 AccessorBaseHost::AccessorBaseHost(id<3> Offset, range<3> AccessRange,
20  range<3> MemoryRange,
21  access::mode AccessMode, void *SYCLMemObject,
22  int Dims, int ElemSize, int OffsetInBytes,
23  bool IsSubBuffer,
24  const property_list &PropertyList) {
25  impl = std::shared_ptr<AccessorImplHost>(
26  new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
27  (detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
28  OffsetInBytes, IsSubBuffer, PropertyList));
29 }
30 
31 id<3> &AccessorBaseHost::getOffset() { return impl->MOffset; }
32 range<3> &AccessorBaseHost::getAccessRange() { return impl->MAccessRange; }
33 range<3> &AccessorBaseHost::getMemoryRange() { return impl->MMemoryRange; }
34 void *AccessorBaseHost::getPtr() { return impl->MData; }
35 
36 detail::AccHostDataT &AccessorBaseHost::getAccData() { return impl->MAccData; }
37 
38 const property_list &AccessorBaseHost::getPropList() const {
39  return impl->MPropertyList;
40 }
41 
42 unsigned int AccessorBaseHost::getElemSize() const { return impl->MElemSize; }
43 
44 const id<3> &AccessorBaseHost::getOffset() const { return impl->MOffset; }
45 const range<3> &AccessorBaseHost::getAccessRange() const {
46  return impl->MAccessRange;
47 }
48 const range<3> &AccessorBaseHost::getMemoryRange() const {
49  return impl->MMemoryRange;
50 }
51 void *AccessorBaseHost::getPtr() const {
52  return const_cast<void *>(impl->MData);
53 }
54 
55 void *AccessorBaseHost::getMemoryObject() const { return impl->MSYCLMemObj; }
56 
57 LocalAccessorBaseHost::LocalAccessorBaseHost(
58  sycl::range<3> Size, int Dims, int ElemSize,
59  const property_list &PropertyList) {
60  impl = std::shared_ptr<LocalAccessorImplHost>(
61  new LocalAccessorImplHost(Size, Dims, ElemSize, PropertyList));
62 }
63 sycl::range<3> &LocalAccessorBaseHost::getSize() { return impl->MSize; }
64 const sycl::range<3> &LocalAccessorBaseHost::getSize() const {
65  return impl->MSize;
66 }
67 void *LocalAccessorBaseHost::getPtr() {
68  // Const cast this in order to call the const getPtr.
69  return const_cast<const LocalAccessorBaseHost *>(this)->getPtr();
70 }
71 void *LocalAccessorBaseHost::getPtr() const {
72  char *ptr = impl->MMem.data();
73 
74  // Align the pointer to MElemSize.
75  size_t val = reinterpret_cast<size_t>(ptr);
76  if (val % impl->MElemSize != 0) {
77  ptr += impl->MElemSize - val % impl->MElemSize;
78  }
79 
80  return ptr;
81 }
82 const property_list &LocalAccessorBaseHost::getPropList() const {
83  return impl->MPropertyList;
84 }
85 
86 int LocalAccessorBaseHost::getNumOfDims() { return impl->MDims; }
87 int LocalAccessorBaseHost::getElementSize() { return impl->MElemSize; }
88 
89 } // namespace detail
90 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
91 } // namespace sycl
The file contains implementations of accessor class.
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:47
Command group handler class.
Definition: handler.hpp:310
Objects of the property_list class are containers for the SYCL properties.
#define __SYCL_INLINE_VER_NAMESPACE(X)
device getDeviceFromHandler(handler &CommandGroupHandlerRef)
Definition: accessor.cpp:15
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