DPC++ Runtime
Runtime libraries for oneAPI DPC++
item_base.hpp
Go to the documentation of this file.
1 //==----------- item_base.hpp --- SYCL iteration ItemBase ------------------==//
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/id.hpp>
12 #include <sycl/range.hpp>
13 
14 namespace sycl {
16 template <int dimensions> class id;
17 template <int dimensions> class range;
18 
19 namespace detail {
20 template <int Dims, bool WithOffset> struct ItemBase;
21 
22 template <int Dims> struct ItemBase<Dims, true> {
23 
24  bool operator==(const ItemBase &Rhs) const {
25  return (Rhs.MIndex == MIndex) && (Rhs.MExtent == MExtent) &&
26  (Rhs.MOffset == MOffset);
27  }
28 
29  bool operator!=(const ItemBase &Rhs) const { return !((*this) == Rhs); }
30 
31  size_t get_linear_id() const {
32  if (1 == Dims) {
33  return MIndex[0] - MOffset[0];
34  }
35  if (2 == Dims) {
36  return (MIndex[0] - MOffset[0]) * MExtent[1] + (MIndex[1] - MOffset[1]);
37  }
38  return ((MIndex[0] - MOffset[0]) * MExtent[1] * MExtent[2]) +
39  ((MIndex[1] - MOffset[1]) * MExtent[2]) + (MIndex[2] - MOffset[2]);
40  }
41 
45 };
46 
47 template <int Dims> struct ItemBase<Dims, false> {
48 
49  bool operator==(const ItemBase &Rhs) const {
50  return (Rhs.MIndex == MIndex) && (Rhs.MExtent == MExtent);
51  }
52 
53  bool operator!=(const ItemBase &Rhs) const { return !((*this) == Rhs); }
54 
55  operator ItemBase<Dims, true>() const {
56  return ItemBase<Dims, true>(MExtent, MIndex, id<Dims>{});
57  }
58 
59  size_t get_linear_id() const {
60  if (1 == Dims) {
61  return MIndex[0];
62  }
63  if (2 == Dims) {
64  return MIndex[0] * MExtent[1] + MIndex[1];
65  }
66  return (MIndex[0] * MExtent[1] * MExtent[2]) + (MIndex[1] * MExtent[2]) +
67  MIndex[2];
68  }
69 
72 };
73 
74 } // namespace detail
75 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
76 } // namespace sycl
sycl::_V1::detail::ItemBase< Dims, true >::MIndex
id< Dims > MIndex
Definition: item_base.hpp:43
sycl::_V1::detail::ItemBase< Dims, true >::MExtent
range< Dims > MExtent
Definition: item_base.hpp:42
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::detail::ItemBase< Dims, false >::MExtent
range< Dims > MExtent
Definition: item_base.hpp:70
sycl::_V1::detail::ItemBase< Dims, false >::MIndex
id< Dims > MIndex
Definition: item_base.hpp:71
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::id< Dims >
id.hpp
sycl::_V1::detail::ItemBase< Dims, false >::operator==
bool operator==(const ItemBase &Rhs) const
Definition: item_base.hpp:49
sycl::_V1::detail::ItemBase< Dims, false >::operator!=
bool operator!=(const ItemBase &Rhs) const
Definition: item_base.hpp:53
sycl::_V1::range< Dims >
range.hpp
sycl::_V1::detail::ItemBase
Definition: item_base.hpp:20
sycl::_V1::detail::ItemBase< Dims, true >::operator!=
bool operator!=(const ItemBase &Rhs) const
Definition: item_base.hpp:29
sycl::_V1::detail::ItemBase< Dims, true >
Definition: item_base.hpp:22
sycl::_V1::detail::ItemBase< Dims, true >::get_linear_id
size_t get_linear_id() const
Definition: item_base.hpp:31
sycl::_V1::detail::ItemBase< Dims, true >::operator==
bool operator==(const ItemBase &Rhs) const
Definition: item_base.hpp:24
sycl::_V1::detail::ItemBase< Dims, true >::MOffset
id< Dims > MOffset
Definition: item_base.hpp:44
sycl::_V1::detail::ItemBase< Dims, false >::get_linear_id
size_t get_linear_id() const
Definition: item_base.hpp:59