"tests/L0/vscode:/vscode.git/clone" did not exist on "848c777dfeb01867998755401a6d4b263b3e9fa4"
functional.hip.hpp 1.16 KB
Newer Older
1
2
3
#pragma once
#include "constant_integral.hip.hpp"

Chao Liu's avatar
Chao Liu committed
4
template <index_t NLoop>
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
struct static_loop_n
{
    template <class F>
    __host__ __device__ void operator()(F f) const
    {
        static_assert(NLoop > 1, "out-of-range");

        f(Number<NLoop - 1>{});
        static_loop_n<NLoop - 1>{}(f);
    }
};

template <>
struct static_loop_n<1>
{
    template <class F>
    __host__ __device__ void operator()(F f) const
    {
        f(Number<0>{});
    }
};

Chao Liu's avatar
Chao Liu committed
27
template <index_t NLoop>
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
struct static_const_reduce_n
{
    template <class F, class Reduce>
    __host__ __device__ constexpr auto operator()(F f, Reduce r) const
    {
        static_assert(NLoop > 1, "out-of-range");

        constexpr auto a = f(Number<NLoop - 1>{});
        auto b = static_const_reduce_n<NLoop - 1>{}(f, r); // cannot use constexpr here, weird
        return r(a, b);
    }
};

template <>
struct static_const_reduce_n<1>
{
    template <class F, class Reduce>
    __host__ __device__ constexpr auto operator()(F f, Reduce) const
    {
        return f(Number<0>{});
    }
};
50
51
52
53
54
55
56
57

#if 0
template<class F>
__host__ __device__ constexpr auto unpacker(F f)
{
    return [=](auto xs_array){ f(xs...); };
}
#endif