common.cuh 1.61 KB
Newer Older
1
2
#pragma once

3
4
#define WARPSIZE 32;

5
6
7
8
9
10
11
12
13
14
15
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
16

Chao Liu's avatar
Chao Liu committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
__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
35
36
    using Type = Sequence<Is...>;

Chao Liu's avatar
Chao Liu committed
37
38
39
40
41
42
43
44
45
46
47
    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
48
    __host__ __device__ constexpr auto ReorderByGetNewFromOld(Sequence<I0, I1, I2, I3>) const
Chao Liu's avatar
Chao Liu committed
49
    {
Chao Liu's avatar
Chao Liu committed
50
        constexpr auto old_sequence = Type{};
Chao Liu's avatar
Chao Liu committed
51

Chao Liu's avatar
Chao Liu committed
52
53
54
55
56
57
        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
58
59
60
    }

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