common.cuh 1.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#pragma once

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
14

Chao Liu's avatar
Chao Liu committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__device__ unsigned get_thread_local_1d_id() { return threadIdx.x; }

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

template <class T, T N>
struct Constant
{
    static const T mValue = N;

    __host__ __device__ constexpr T Get() const { return mValue; }
};

template <unsigned N>
using Number = Constant<unsigned, N>;

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
65
    }
};