-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselector.h
59 lines (48 loc) · 1.17 KB
/
selector.h
1
2
3
4
5
6
7
8
9
10
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
/*!
* Copyright (c) 2020 by Contributors
* \file array/selector.h
* \brief Selector functions to select among src/edge/dst attributes.
*/
#ifndef DGL_ARRAY_SELECTOR_H_
#define DGL_ARRAY_SELECTOR_H_
#include <dmlc/logging.h>
namespace dgl {
namespace {
#ifdef __CUDACC__
#define DGLDEVICE __device__
#define DGLINLINE __forceinline__
#else
#define DGLDEVICE
#define DGLINLINE inline
#endif // __CUDACC__
} // namespace
/*!
* \brief Select among src/edge/dst feature/idx.
* \note the integer argument target specifies which target
* to choose, 0: src, 1: edge, 2: dst.
*/
template <int target>
struct Selector {
template <typename T>
static DGLDEVICE DGLINLINE T Call(T src, T edge, T dst) {
LOG(INFO) << "Target " << target << " not recognized.";
return src;
}
};
template <>
template <typename T>
DGLDEVICE DGLINLINE T Selector<0>::Call(T src, T edge, T dst) {
return src;
}
template <>
template <typename T>
DGLDEVICE DGLINLINE T Selector<1>::Call(T src, T edge, T dst) {
return edge;
}
template <>
template <typename T>
DGLDEVICE DGLINLINE T Selector<2>::Call(T src, T edge, T dst) {
return dst;
}
} // namespace dgl
#endif // DGL_ARRAY_SELECTOR_H_