-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcopyAsync.h
43 lines (35 loc) · 1.64 KB
/
copyAsync.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
#ifndef HeterogeneousCore_CUDAUtilities_copyAsync_h
#define HeterogeneousCore_CUDAUtilities_copyAsync_h
#include "device_unique_ptr.h"
#include "host_unique_ptr.h"
#include <cuda_runtime.h>
#include <type_traits>
namespace cudautils {
// Single element
template <typename T>
inline
void copyAsync(cudautils::device::unique_ptr<T>& dst, const cudautils::host::unique_ptr<T>& src, cudaStream_t stream) {
// Shouldn't compile for array types because of sizeof(T), but
// let's add an assert with a more helpful message
static_assert(std::is_array<T>::value == false, "For array types, use the other overload with the size parameter");
cudaMemcpyAsync(dst.get(), src.get(), sizeof(T), cudaMemcpyDefault, stream);
}
template <typename T>
inline
void copyAsync(cudautils::host::unique_ptr<T>& dst, const cudautils::device::unique_ptr<T>& src, cudaStream_t stream) {
static_assert(std::is_array<T>::value == false, "For array types, use the other overload with the size parameter");
cudaMemcpyAsync(dst.get(), src.get(), sizeof(T), cudaMemcpyDefault, stream);
}
// Multiple elements
template <typename T>
inline
void copyAsync(cudautils::device::unique_ptr<T[]>& dst, const cudautils::host::unique_ptr<T[]>& src, size_t nelements, cudaStream_t stream) {
cudaMemcpyAsync(dst.get(), src.get(), nelements*sizeof(T), cudaMemcpyDefault, stream);
}
template <typename T>
inline
void copyAsync(cudautils::host::unique_ptr<T[]>& dst, const cudautils::device::unique_ptr<T[]>& src, size_t nelements, cudaStream_t stream) {
cudaMemcpyAsync(dst.get(), src.get(), nelements*sizeof(T), cudaMemcpyDefault, stream);
}
}
#endif