arith.h 2.02 KB
Newer Older
sangwzh's avatar
sangwzh committed
1
// !!! This is a file automatically generated by hipify!!!
2
/**
3
 *  Copyright (c) 2019 by Contributors
4
5
 * @file array/arith.h
 * @brief Arithmetic functors
6
7
8
9
 */
#ifndef DGL_ARRAY_ARITH_H_
#define DGL_ARRAY_ARITH_H_

sangwzh's avatar
sangwzh committed
10
11
#ifdef __HIPCC__
#define DGLDEVICE __device__ __host__
12
13
14
15
#define DGLINLINE __forceinline__
#else
#define DGLDEVICE
#define DGLINLINE inline
sangwzh's avatar
sangwzh committed
16
#endif  // __HIPCC__
17

18
19
20
21
22
23
namespace dgl {
namespace aten {
namespace arith {

struct Add {
  template <typename T>
24
  static DGLINLINE DGLDEVICE T Call(const T& t1, const T& t2) {
25
26
27
28
29
30
    return t1 + t2;
  }
};

struct Sub {
  template <typename T>
31
  static DGLINLINE DGLDEVICE T Call(const T& t1, const T& t2) {
32
33
34
35
36
37
    return t1 - t2;
  }
};

struct Mul {
  template <typename T>
38
  static DGLINLINE DGLDEVICE T Call(const T& t1, const T& t2) {
39
40
41
42
43
44
    return t1 * t2;
  }
};

struct Div {
  template <typename T>
45
  static DGLINLINE DGLDEVICE T Call(const T& t1, const T& t2) {
46
47
48
49
    return t1 / t2;
  }
};

50
51
52
53
54
55
56
struct Mod {
  template <typename T>
  static DGLINLINE DGLDEVICE T Call(const T& t1, const T& t2) {
    return t1 % t2;
  }
};

57
58
59
60
61
62
63
struct GT {
  template <typename T>
  static DGLINLINE DGLDEVICE bool Call(const T& t1, const T& t2) {
    return t1 > t2;
  }
};

64
65
struct LT {
  template <typename T>
66
  static DGLINLINE DGLDEVICE bool Call(const T& t1, const T& t2) {
67
68
69
70
    return t1 < t2;
  }
};

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
struct GE {
  template <typename T>
  static DGLINLINE DGLDEVICE bool Call(const T& t1, const T& t2) {
    return t1 >= t2;
  }
};

struct LE {
  template <typename T>
  static DGLINLINE DGLDEVICE bool Call(const T& t1, const T& t2) {
    return t1 <= t2;
  }
};

struct EQ {
  template <typename T>
  static DGLINLINE DGLDEVICE bool Call(const T& t1, const T& t2) {
    return t1 == t2;
  }
};

struct NE {
  template <typename T>
  static DGLINLINE DGLDEVICE bool Call(const T& t1, const T& t2) {
    return t1 != t2;
  }
};

struct Neg {
  template <typename T>
  static DGLINLINE DGLDEVICE T Call(const T& t1) {
    return -t1;
  }
};

106
107
108
109
110
}  // namespace arith
}  // namespace aten
}  // namespace dgl

#endif  // DGL_ARRAY_ARITH_H_