"tests/vscode:/vscode.git/clone" did not exist on "8735815a0dae728b4720b410406c80aecd5ad920"
math_v2.hpp 1.23 KB
Newer Older
1
2
3
#ifndef CK_MATH_V2_HPP
#define CK_MATH_V2_HPP

4
#include <cmath>
5
#include "data_type.hpp"
6
#include "half.hpp"
7
8
9
10

namespace ck {
namespace math {

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
static inline __host__ float abs(float x) { return std::abs(x); };

static inline __host__ double abs(double x) { return std::abs(x); };

static inline __host__ int8_t abs(int8_t x)
{
    int8_t sgn = x >> (8 - 1);

    return (x ^ sgn) - sgn;
};

static inline __host__ int32_t abs(int32_t x)
{
    int32_t sgn = x >> (32 - 1);

    return (x ^ sgn) - sgn;
};

static inline __host__ half_t abs(half_t x)
{
    half_float::half xx = *reinterpret_cast<half_float::half*>(&x);

    half_float::half abs_xx = half_float::abs(xx);

    half_t abs_x = *reinterpret_cast<half_t*>(&abs_xx);

    return abs_x;
};

static inline __host__ float isnan(float x) { return std::isnan(x); };

static inline __host__ double isnan(double x) { return std::isnan(x); };

static inline __host__ int8_t isnan(int8_t x)
{
    (void)x;
    return false;
};

static inline __host__ int32_t isnan(int32_t x)
{
    (void)x;
    return false;
};

static inline __host__ bool isnan(half_t x)
{
    half_float::half xx = *reinterpret_cast<half_float::half*>(&x);

    return half_float::isnan(xx);
};
62
63
64
65
66

} // namespace math
} // namespace ck

#endif