common.hip.hpp 2.02 KB
Newer Older
1
#pragma once
2
3
4
5
#include "constant_integral.hip.hpp"
#include "Sequence.hip.hpp"
#include "Array.hip.hpp"
#include "functional.hip.hpp"
6

Chao Liu's avatar
Chao Liu committed
7
8
9
__device__ unsigned get_thread_local_1d_id() { return threadIdx.x; }

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

11
12
13
14
15
16
17
18
19
20
21
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
22

Chao Liu's avatar
Chao Liu committed
23
24
25
26
27
28
29
30
template <class T, unsigned N>
struct vector_type
{
};

template <>
struct vector_type<float, 1>
{
31
    using VectorType = float;
Chao Liu's avatar
Chao Liu committed
32
33
34
35
36
};

template <>
struct vector_type<float, 2>
{
37
    using VectorType = float2;
Chao Liu's avatar
Chao Liu committed
38
39
40
41
42
};

template <>
struct vector_type<float, 4>
{
43
    using VectorType = float4;
Chao Liu's avatar
Chao Liu committed
44
45
46
47
48
49
};

#if 0
template <>
struct vector_type<half_float::half, 1>
{
50
    using VectorType = half_float::half;
Chao Liu's avatar
Chao Liu committed
51
52
53
54
55
};

template <>
struct vector_type<half_float::half, 2>
{
56
    using VectorType = float;
Chao Liu's avatar
Chao Liu committed
57
58
59
60
61
};

template <>
struct vector_type<half_float::half, 4>
{
62
    using VectorType = float2;
Chao Liu's avatar
Chao Liu committed
63
64
65
66
67
};

template <>
struct vector_type<half_float::half, 8>
{
68
    using VectorType = float4;
Chao Liu's avatar
Chao Liu committed
69
70
71
72
73
74
75
};
#endif

#if 1
template <>
struct vector_type<half, 1>
{
76
77
78
    using VectorType = half;

    __host__ __device__ static VectorType pack(half s) { return s; }
Chao Liu's avatar
Chao Liu committed
79
80
81
82
83
};

template <>
struct vector_type<half, 2>
{
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    using VectorType = half2;

    union Data
    {
        VectorType vector;
        half scalar[2];
    };

    __host__ __device__ static VectorType pack(half s0, half s1)
    {
        Data data;
        data.scalar[0] = s0;
        data.scalar[1] = s1;
        return data.vector;
    }
Chao Liu's avatar
Chao Liu committed
99
100
101
102
103
};

template <>
struct vector_type<half, 4>
{
104
    using VectorType = float2;
Chao Liu's avatar
Chao Liu committed
105
106
107
108
109
};

template <>
struct vector_type<half, 8>
{
110
    using VectorType = float4;
Chao Liu's avatar
Chao Liu committed
111
112
113
};
#endif

Chao Liu's avatar
Chao Liu committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
template <typename T>
__host__ __device__ constexpr T max(T a, T b)
{
    return a > b ? a : b;
}

template <typename T>
__host__ __device__ constexpr T min(T a, T b)
{
    return a < b ? a : b;
}

__host__ __device__ constexpr unsigned integer_divide_ceil(unsigned a, unsigned b)
{
    return (a + b - 1) / b;
}