/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck/utility/statically_indexed_array.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck/utility/statically_indexed_array.hpp Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck/utility/statically_indexed_array.hpp Source File
statically_indexed_array.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: MIT
2 // Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
3 
4 #ifndef CK_STATICALLY_INDEXED_ARRAY_HPP
5 #define CK_STATICALLY_INDEXED_ARRAY_HPP
6 
7 #include "functional2.hpp"
8 #include "sequence.hpp"
9 #include "tuple.hpp"
10 
11 namespace ck {
12 
13 namespace detail {
14 template <typename X, typename Y>
15 struct tuple_concat;
16 
17 template <typename... Xs, typename... Ys>
18 struct tuple_concat<Tuple<Xs...>, Tuple<Ys...>>
19 {
20  using type = Tuple<Xs..., Ys...>;
21 };
22 
23 template <typename T, index_t N>
25 {
26  using type =
27  typename tuple_concat<typename StaticallyIndexedArrayImpl<T, N / 2>::type,
28  typename StaticallyIndexedArrayImpl<T, N - N / 2>::type>::type;
29 };
30 
31 template <typename T>
33 {
34  using type = Tuple<>;
35 };
36 
37 template <typename T>
39 {
40  using type = Tuple<T>;
41 };
42 } // namespace detail
43 
44 template <typename T, index_t N>
46 
47 template <typename X, typename... Xs>
48 __host__ __device__ constexpr auto make_statically_indexed_array(const X& x, const Xs&... xs)
49 {
50  return StaticallyIndexedArray<X, sizeof...(Xs) + 1>(x, static_cast<X>(xs)...);
51 }
52 
53 // make empty StaticallyIndexedArray
54 template <typename X>
55 __host__ __device__ constexpr auto make_statically_indexed_array()
56 {
58 }
59 
60 template <typename T, index_t N>
62 {
63  __host__ __device__ constexpr StaticallyIndexedArray_v2() = default;
64 
65  __host__ __device__ static constexpr index_t Size() { return N; }
66 
67  // read access
68  template <index_t I>
69  __host__ __device__ constexpr const auto& At(Number<I>) const
70  {
71  static_assert(I < N, "wrong! out of range");
72 
73  return data_[I];
74  }
75 
76  // write access
77  template <index_t I>
78  __host__ __device__ constexpr auto& At(Number<I>)
79  {
80  static_assert(I < N, "wrong! out of range");
81 
82  return data_[I];
83  }
84 
85  // read access
86  template <index_t I>
87  __host__ __device__ constexpr const auto& operator[](Number<I> i) const
88  {
89  return At(i);
90  }
91 
92  // write access
93  template <index_t I>
94  __host__ __device__ constexpr auto& operator()(Number<I> i)
95  {
96  return At(i);
97  }
98 
99  __host__ __device__ static constexpr bool IsStaticBuffer() { return true; }
100 
101  T data_[N];
102 };
103 
104 } // namespace ck
105 #endif
Definition: ck.hpp:267
typename detail::StaticallyIndexedArrayImpl< T, N >::type StaticallyIndexedArray
Definition: statically_indexed_array.hpp:45
__host__ constexpr __device__ auto make_statically_indexed_array(const X &x, const Xs &... xs)
Definition: statically_indexed_array.hpp:48
int32_t index_t
Definition: ck.hpp:298
Definition: statically_indexed_array.hpp:62
__host__ constexpr __device__ StaticallyIndexedArray_v2()=default
__host__ static constexpr __device__ index_t Size()
Definition: statically_indexed_array.hpp:65
T data_[N]
Definition: statically_indexed_array.hpp:101
__host__ constexpr __device__ const auto & At(Number< I >) const
Definition: statically_indexed_array.hpp:69
__host__ constexpr __device__ auto & At(Number< I >)
Definition: statically_indexed_array.hpp:78
__host__ constexpr __device__ const auto & operator[](Number< I > i) const
Definition: statically_indexed_array.hpp:87
__host__ static constexpr __device__ bool IsStaticBuffer()
Definition: statically_indexed_array.hpp:99
__host__ constexpr __device__ auto & operator()(Number< I > i)
Definition: statically_indexed_array.hpp:94
Definition: tuple.hpp:186
Definition: tuple.hpp:117
Definition: statically_indexed_array.hpp:25
typename tuple_concat< typename StaticallyIndexedArrayImpl< T, N/2 >::type, typename StaticallyIndexedArrayImpl< T, N - N/2 >::type >::type type
Definition: statically_indexed_array.hpp:28
Definition: statically_indexed_array.hpp:15
Definition: integral_constant.hpp:20