forked from cms-patatrack/pixeltrack-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copyAsync.h
69 lines (57 loc) · 2.84 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
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
#ifndef HeterogeneousCore_CUDAUtilities_copyAsync_h
#define HeterogeneousCore_CUDAUtilities_copyAsync_h
#include "CUDACore/cudaCheck.h"
#include "CUDACore/device_unique_ptr.h"
#include "CUDACore/host_noncached_unique_ptr.h"
#include "CUDACore/host_unique_ptr.h"
#include <type_traits>
namespace cms {
namespace cuda {
// Single element
template <typename T>
inline void copyAsync(device::unique_ptr<T>& dst, const 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");
cudaCheck(cudaMemcpyAsync(dst.get(), src.get(), sizeof(T), cudaMemcpyHostToDevice, stream));
}
template <typename T>
inline void copyAsync(device::unique_ptr<T>& dst, const host::noncached::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");
cudaCheck(cudaMemcpyAsync(dst.get(), src.get(), sizeof(T), cudaMemcpyHostToDevice, stream));
}
template <typename T>
inline void copyAsync(host::unique_ptr<T>& dst, const 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");
cudaCheck(cudaMemcpyAsync(dst.get(), src.get(), sizeof(T), cudaMemcpyDeviceToHost, stream));
}
// Multiple elements
template <typename T>
inline void copyAsync(device::unique_ptr<T[]>& dst,
const host::unique_ptr<T[]>& src,
size_t nelements,
cudaStream_t stream) {
cudaCheck(cudaMemcpyAsync(dst.get(), src.get(), nelements * sizeof(T), cudaMemcpyHostToDevice, stream));
}
template <typename T>
inline void copyAsync(device::unique_ptr<T[]>& dst,
const host::noncached::unique_ptr<T[]>& src,
size_t nelements,
cudaStream_t stream) {
cudaCheck(cudaMemcpyAsync(dst.get(), src.get(), nelements * sizeof(T), cudaMemcpyHostToDevice, stream));
}
template <typename T>
inline void copyAsync(host::unique_ptr<T[]>& dst,
const device::unique_ptr<T[]>& src,
size_t nelements,
cudaStream_t stream) {
cudaCheck(cudaMemcpyAsync(dst.get(), src.get(), nelements * sizeof(T), cudaMemcpyDeviceToHost, stream));
}
} // namespace cuda
} // namespace cms
#endif