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

Chao Liu's avatar
Chao Liu committed
8
9
10
11
#if DEVICE_BACKEDN_HIP
#include "inline_asm.hpp"
#endif

Chao Liu's avatar
Chao Liu committed
12
__device__ index_t get_thread_local_1d_id() { return threadIdx.x; }
Chao Liu's avatar
Chao Liu committed
13

Chao Liu's avatar
Chao Liu committed
14
__device__ index_t get_block_1d_id() { return blockIdx.x; }
15

16
17
18
19
20
21
22
23
24
25
26
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
27

Chao Liu's avatar
Chao Liu committed
28
__host__ __device__ constexpr index_t integer_divide_ceil(index_t a, index_t b)
Chao Liu's avatar
Chao Liu committed
29
{
Chao Liu's avatar
Chao Liu committed
30
    return (a + b - 1) / b;
Chao Liu's avatar
Chao Liu committed
31
32
}

33
namespace mod_conv { // namespace mod_conv
Chao Liu's avatar
Chao Liu committed
34
35
template <class T>
__host__ __device__ constexpr T max(T x, T y)
Chao Liu's avatar
Chao Liu committed
36
{
Chao Liu's avatar
Chao Liu committed
37
    return x > y ? x : y;
Chao Liu's avatar
Chao Liu committed
38
39
}

Chao Liu's avatar
Chao Liu committed
40
41
template <class T, class... Ts>
__host__ __device__ constexpr T max(T x, Ts... xs)
Chao Liu's avatar
Chao Liu committed
42
{
Chao Liu's avatar
Chao Liu committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    static_assert(sizeof...(xs) > 0, "not enough argument");

    auto y = max(xs...);

    static_assert(is_same<decltype(y), T>::value, "not the same type");

    return x > y ? x : y;
}

template <class T>
__host__ __device__ constexpr T min(T x, T y)
{
    return x < y ? x : y;
}

template <class T, class... Ts>
__host__ __device__ constexpr T min(T x, Ts... xs)
{
    static_assert(sizeof...(xs) > 0, "not enough argument");

    auto y = min(xs...);

    static_assert(is_same<decltype(y), T>::value, "not the same type");

    return x < y ? x : y;
}
Chao Liu's avatar
tidy up  
Chao Liu committed
69
} // namespace mod_conv
70
71
72
73
74

#if DEVICE_BACKEND_HIP
// cast a pointer of LDS to its address
extern "C" __attribute__((address_space(3))) void* __to_local(void* p)[[hc]];
#endif