-
Notifications
You must be signed in to change notification settings - Fork 1
/
hamr_cuda_copy.h
176 lines (164 loc) · 6.48 KB
/
hamr_cuda_copy.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
60
61
62
63
64
65
66
67
68
69
70
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#ifndef hamr_cuda_copy_h
#define hamr_cuda_copy_h
#include "hamr_config.h"
#include <memory>
#include <type_traits>
/// heterogeneous accelerator memory resource
namespace hamr
{
#if !defined(HAMR_ENABLE_OBJECTS)
/** Copies an array to the active CUDA device.
*
* @param[in] dest an array of n elements accessible in CUDA
* @param[in] src an array of n elements accessible on the host
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T, typename U>
static int copy_to_cuda_from_host(T *dest, const U *src, size_t n_elem,
typename std::enable_if<!std::is_arithmetic<T>::value>::type * = nullptr);
#else
/** Copies an array to the active CUDA device (fast path for arrays of
* arithmetic types of the same type).
*
* @param[in] dest an array of n elements accessible in CUDA
* @param[in] src an array of n elements accessible on the host
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T>
static int copy_to_cuda_from_host(T *dest, const T *src, size_t n_elem,
typename std::enable_if<std::is_arithmetic<T>::value>::type * = nullptr);
#endif
/** Copies an array to the active CUDA device.
*
* @param[in] dest an array of n elements accessible in CUDA
* @param[in] src an array of n elements accessible on the host
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T, typename U>
static int copy_to_cuda_from_host(T *dest, const U *src, size_t n_elem
#if !defined(HAMR_ENABLE_OBJECTS)
,typename std::enable_if<std::is_arithmetic<T>::value>::type * = nullptr
#endif
);
#if !defined(HAMR_ENABLE_OBJECTS)
/** Copies an array on the active CUDA device.
*
* @param[in] dest an array of n elements accessible in CUDA
* @param[in] src an array of n elements accessible in CUDA
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T, typename U>
static int copy_to_cuda_from_cuda(T *dest, const U *src, size_t n_elem,
typename std::enable_if<!std::is_arithmetic<T>::value>::type * = nullptr);
#else
/** Ccopies an array on the active CUAD device (fast path for arrays of
* arithmetic types of the same type).
*
* @param[in] dest an array of n elements accessible in CUDA
* @param[in] src an array of n elements accessible on the host
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T>
static int copy_to_cuda_from_cuda(T *dest, const T *src, size_t n_elem,
typename std::enable_if<std::is_arithmetic<T>::value>::type * = nullptr);
#endif
/** Copies an array on the active CUDA device.
*
* @param[in] dest an array of n elements accessible in CUDA
* @param[in] src an array of n elements accessible in CUDA
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T, typename U>
static int copy_to_cuda_from_cuda(T *dest, const U *src, size_t n_elem
#if !defined(HAMR_ENABLE_OBJECTS)
,typename std::enable_if<std::is_arithmetic<T>::value>::type * = nullptr
#endif
);
#if !defined(HAMR_ENABLE_OBJECTS)
/** Copies an array to the active CUDA device from the named CUDA device,
*
* @param[in] dest an array of n elements accessible in CUDA
* @param[in] src an array of n elements accessible in CUDA
* @param[in] src_device the CUDA device on which src is allocated
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T, typename U>
static int copy_to_cuda_from_cuda(T *dest, const U *src, int src_device, size_t n_elem,
typename std::enable_if<!std::is_arithmetic<T>::value>::type * = nullptr);
#else
/** Copies an array to the active CUDA device from the named CUDA device, (fast
* path for arrays of arithmetic types of the same type).
*
* @param[in] dest an array of n elements accessible in CUDA
* @param[in] src an array of n elements accessible in CUDA
* @param[in] src_device the CUDA device on which src is allocated
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T>
static int copy_to_cuda_from_cuda(T *dest, const T *src, int src_device, size_t n_elem,
typename std::enable_if<std::is_arithmetic<T>::value>::type * = nullptr);
#endif
/** Copies an array on the active CUDA device.
*
* @param[in] dest an array of n elements accessible in CUDA
* @param[in] src an array of n elements accessible in CUDA
* @param[in] src_device the CUDA device on which src is allocated
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T, typename U>
static int copy_to_cuda_from_cuda(T *dest, const U *src, int src_device, size_t n_elem
#if !defined(HAMR_ENABLE_OBJECTS)
,typename std::enable_if<std::is_arithmetic<T>::value>::type * = nullptr
#endif
);
#if !defined(HAMR_ENABLE_OBJECTS)
/** Copies an array from the active CUDA device.
*
* @param[in] dest an array of n elements accessible on the host
* @param[in] src an array of n elements accessible in CUDA
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T, typename U>
static int copy_to_host_from_cuda(T *dest, const U *src, size_t n_elem,
typename std::enable_if<!std::is_arithmetic<T>::value>::type * = nullptr);
#else
/** Copies an array from the active CUDA device (fast path for arrays of
* arithmetic types of the same type).
*
* @param[in] dest an array of n elements accessible in CUDA
* @param[in] src an array of n elements accessible on the host
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T>
static int copy_to_host_from_cuda(T *dest, const T *src, size_t n_elem,
typename std::enable_if<std::is_arithmetic<T>::value>::type * = nullptr);
#endif
/** Copies an array from the active CUDA device.
*
* @param[in] dest an array of n elements accessible on the host
* @param[in] src an array of n elements accessible in CUDA
* @param[in] n_elem the number of elements in the array
* @returns 0 if there were no errors
*/
template <typename T, typename U>
static int copy_to_host_from_cuda(T *dest, const U *src, size_t n_elem
#if !defined(HAMR_ENABLE_OBJECTS)
,typename std::enable_if<std::is_arithmetic<T>::value>::type * = nullptr
#endif
);
}
#if !defined(HAMR_SEPARATE_IMPL)
#include "hamr_cuda_copy_impl.h"
#endif
#endif