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 <CL/sycl/id.hpp>
12 #include <CL/sycl/range.hpp>
13 
15 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 } // namespace sycl
76 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::ItemBase< Dims, false >::operator!=
bool operator!=(const ItemBase &Rhs) const
Definition: item_base.hpp:53
cl::sycl::detail::ItemBase< Dims, true >::operator!=
bool operator!=(const ItemBase &Rhs) const
Definition: item_base.hpp:29
cl::sycl::id< Dims >
cl::sycl::detail::ItemBase< Dims, true >
Definition: item_base.hpp:22
cl::sycl::detail::ItemBase< Dims, true >::MExtent
range< Dims > MExtent
Definition: item_base.hpp:42
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::ItemBase< Dims, true >::get_linear_id
size_t get_linear_id() const
Definition: item_base.hpp:31
id.hpp
cl::sycl::range< Dims >
range.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::ItemBase< Dims, false >::operator==
bool operator==(const ItemBase &Rhs) const
Definition: item_base.hpp:49
cl::sycl::detail::ItemBase
Definition: item_base.hpp:20
cl::sycl::detail::ItemBase< Dims, false >::get_linear_id
size_t get_linear_id() const
Definition: item_base.hpp:59
cl::sycl::detail::ItemBase< Dims, true >::MOffset
id< Dims > MOffset
Definition: item_base.hpp:44
cl::sycl::detail::ItemBase< Dims, true >::MIndex
id< Dims > MIndex
Definition: item_base.hpp:43
cl::sycl::detail::ItemBase< Dims, false >::MExtent
range< Dims > MExtent
Definition: item_base.hpp:70
cl::sycl::detail::ItemBase< Dims, false >::MIndex
id< Dims > MIndex
Definition: item_base.hpp:71
cl::sycl::detail::ItemBase< Dims, true >::operator==
bool operator==(const ItemBase &Rhs) const
Definition: item_base.hpp:24
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12