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
#define __SYCL_INLINE_VER_NAMESPACE(X)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
bool operator==(const ItemBase &Rhs) const
Definition: item_base.hpp:49
bool operator!=(const ItemBase &Rhs) const
Definition: item_base.hpp:53
bool operator==(const ItemBase &Rhs) const
Definition: item_base.hpp:24
bool operator!=(const ItemBase &Rhs) const
Definition: item_base.hpp:29