statically_indexed_array.hpp Source File

statically_indexed_array.hpp Source File#

Composable Kernel: statically_indexed_array.hpp Source File
utility/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
11namespace ck {
12
13namespace detail {
14template <typename X, typename Y>
16
17template <typename... Xs, typename... Ys>
18struct tuple_concat<Tuple<Xs...>, Tuple<Ys...>>
19{
20 using type = Tuple<Xs..., Ys...>;
21};
22
23template <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
31template <typename T>
33{
34 using type = Tuple<>;
35};
36
37template <typename T>
39{
40 using type = Tuple<T>;
41};
42} // namespace detail
43
44template <typename T, index_t N>
46
47template <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
54template <typename X>
55__host__ __device__ constexpr auto make_statically_indexed_array()
56{
58}
59
60template <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 threadwise_tensor_slice_transfer_util.hpp:15
Definition ck.hpp:268
typename detail::StaticallyIndexedArrayImpl< T, N >::type StaticallyIndexedArray
Definition utility/statically_indexed_array.hpp:45
int32_t index_t
Definition ck.hpp:299
__host__ __device__ constexpr auto make_statically_indexed_array()
Definition utility/statically_indexed_array.hpp:55
integral_constant< index_t, N > Number
Definition number.hpp:12
__host__ __device__ constexpr const auto & operator[](Number< I > i) const
Definition utility/statically_indexed_array.hpp:87
__host__ __device__ constexpr auto & At(Number< I >)
Definition utility/statically_indexed_array.hpp:78
T data_[N]
Definition utility/statically_indexed_array.hpp:101
__host__ __device__ constexpr const auto & At(Number< I >) const
Definition utility/statically_indexed_array.hpp:69
__host__ __device__ constexpr StaticallyIndexedArray_v2()=default
__host__ static __device__ constexpr index_t Size()
Definition utility/statically_indexed_array.hpp:65
__host__ __device__ constexpr auto & operator()(Number< I > i)
Definition utility/statically_indexed_array.hpp:94
__host__ static __device__ constexpr bool IsStaticBuffer()
Definition utility/statically_indexed_array.hpp:99
Definition utility/tuple.hpp:186
Definition utility/tuple.hpp:117
Tuple<> type
Definition utility/statically_indexed_array.hpp:34
Tuple< T > type
Definition utility/statically_indexed_array.hpp:40
Definition utility/statically_indexed_array.hpp:25
typename tuple_concat< typename StaticallyIndexedArrayImpl< T, N/2 >::type, typename StaticallyIndexedArrayImpl< T, N - N/2 >::type >::type type
Definition utility/statically_indexed_array.hpp:26
Tuple< Xs..., Ys... > type
Definition utility/statically_indexed_array.hpp:20
Definition utility/statically_indexed_array.hpp:15