"vscode:/vscode.git/clone" did not exist on "b3ac3ac148f2cfaa07f8cc0dc7bafffea18f689c"
common.hip.hpp 1.6 KB
Newer Older
1
2
#pragma once

Chao Liu's avatar
Chao Liu committed
3
4
5
__device__ unsigned get_thread_local_1d_id() { return threadIdx.x; }

__device__ unsigned get_block_1d_id() { return blockIdx.x; }
6

7
8
9
10
11
12
13
14
15
16
17
template <class T1, class T2>
struct is_same
{
    static const bool value = false;
};

template <class T>
struct is_same<T, T>
{
    static const bool value = true;
};
Chao Liu's avatar
Chao Liu committed
18

Chao Liu's avatar
Chao Liu committed
19
template <class T, T N>
Chao Liu's avatar
Chao Liu committed
20
struct integral_constant
Chao Liu's avatar
Chao Liu committed
21
{
Chao Liu's avatar
Chao Liu committed
22
    static const T value = N;
Chao Liu's avatar
Chao Liu committed
23

Chao Liu's avatar
Chao Liu committed
24
    __host__ __device__ constexpr T Get() const { return value; }
Chao Liu's avatar
Chao Liu committed
25
26
27
};

template <unsigned N>
Chao Liu's avatar
Chao Liu committed
28
using Number = integral_constant<unsigned, N>;
Chao Liu's avatar
Chao Liu committed
29
30
31
32

template <unsigned... Is>
struct Sequence
{
Chao Liu's avatar
Chao Liu committed
33
34
    using Type = Sequence<Is...>;

Chao Liu's avatar
Chao Liu committed
35
36
37
38
39
40
41
42
43
44
45
    static constexpr unsigned nDim = sizeof...(Is);

    const unsigned mData[nDim] = {Is...};

    template <unsigned I>
    __host__ __device__ constexpr unsigned Get(Number<I>) const
    {
        return mData[I];
    }

    template <unsigned I0, unsigned I1, unsigned I2, unsigned I3>
Chao Liu's avatar
Chao Liu committed
46
    __host__ __device__ constexpr auto ReorderByGetNewFromOld(Sequence<I0, I1, I2, I3>) const
Chao Liu's avatar
Chao Liu committed
47
    {
Chao Liu's avatar
Chao Liu committed
48
        constexpr auto old_sequence = Type{};
Chao Liu's avatar
Chao Liu committed
49

Chao Liu's avatar
Chao Liu committed
50
51
52
53
54
55
        constexpr unsigned NR0 = old_sequence.mData[I0];
        constexpr unsigned NR1 = old_sequence.mData[I1];
        constexpr unsigned NR2 = old_sequence.mData[I2];
        constexpr unsigned NR3 = old_sequence.mData[I3];

        return Sequence<NR0, NR1, NR2, NR3>{};
Chao Liu's avatar
Chao Liu committed
56
57
58
    }

    template <unsigned I0, unsigned I1, unsigned I2, unsigned I3>
Chao Liu's avatar
Chao Liu committed
59
    __host__ __device__ constexpr auto ReorderByPutOldToNew(Sequence<I0, I1, I2, I3>) const
Chao Liu's avatar
Chao Liu committed
60
    {
Chao Liu's avatar
Chao Liu committed
61
62
63
        // don't know how to implement this
        printf("Sequence::ReorderByPutOldToNew not implemented");
        assert(false);
Chao Liu's avatar
Chao Liu committed
64
    }
Chao Liu's avatar
Chao Liu committed
65
};