"vscode:/vscode.git/clone" did not exist on "3a4ac1eee9039eee0f0a3aad1e55c1394446b7ba"
sequence_helper.hpp 942 Bytes
Newer Older
Chao Liu's avatar
Chao Liu committed
1
2
3
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.

Chao Liu's avatar
Chao Liu committed
4
5
6
#ifndef CK_SEQUENCE_HELPER_HPP
#define CK_SEQUENCE_HELPER_HPP

7
#include "tuple.hpp"
Chao Liu's avatar
Chao Liu committed
8
9
10

namespace ck {

11
12
13
14
15
16
17
template <index_t... Is>
__host__ __device__ constexpr auto make_sequence(Number<Is>...)
{
    return Sequence<Is...>{};
}

// F returns index_t
Chao Liu's avatar
Chao Liu committed
18
19
20
21
22
23
template <typename F, index_t N>
__host__ __device__ constexpr auto generate_sequence(F, Number<N>)
{
    return typename sequence_gen<N, F>::type{};
}

24
25
26
27
28
29
30
31
// F returns Number<>
template <typename F, index_t N>
__host__ __device__ constexpr auto generate_sequence_v2(F&& f, Number<N>)
{
    return unpack([&f](auto&&... xs) { return make_sequence(f(xs)...); },
                  typename arithmetic_sequence_gen<0, N, 1>::type{});
}

32
33
34
35
36
37
template <index_t... Is>
__host__ __device__ constexpr auto to_sequence(Tuple<Number<Is>...>)
{
    return Sequence<Is...>{};
}

Chao Liu's avatar
Chao Liu committed
38
39
} // namespace ck
#endif