MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / CopyCPUDataToCUDAHelper

Function CopyCPUDataToCUDAHelper

paddle/phi/core/mixed_vector.cc:68–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66
67template <typename T>
68void CopyCPUDataToCUDAHelper(std::vector<T> *cpu_,
69 Allocator::AllocationPtr *gpu_,
70 size_t *gpu_memory_size_,
71 const Place &place) {
72#if defined(PADDLE_WITH_CUSTOM_DEVICE)
73 void *src = cpu_->data();
74 *gpu_memory_size_ = cpu_->size() * sizeof(T); // sizeof(T)
75 (*gpu_) = memory_utils::Alloc(place, *gpu_memory_size_);
76 void *dst = (*gpu_)->ptr();
77 auto *dev_ctx =
78 static_cast<CustomContext *>(DeviceContextPool::Instance().Get(place));
79 auto stream = dev_ctx->stream();
80 memory_utils::Copy(OptionalCustomPlace(*gpu_).get(),
81 dst,
82 CPUPlace(),
83 src,
84 *gpu_memory_size_,
85 stream);
86 dev_ctx->Wait();
87#elif defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
88 void *src = cpu_->data();
89 *gpu_memory_size_ = cpu_->size() * sizeof(T); // sizeof(T)
90 (*gpu_) = memory_utils::Alloc(place, *gpu_memory_size_);
91 void *dst = (*gpu_)->ptr();
92 auto *dev_ctx =
93 static_cast<GPUContext *>(DeviceContextPool::Instance().Get(place));
94 auto stream = dev_ctx->stream();
95 memory_utils::Copy(OptionalCUDAPlace(*gpu_).get(),
96 dst,
97 CPUPlace(),
98 src,
99 *gpu_memory_size_,
100 stream);
101 dev_ctx->Wait();
102#endif
103}
104
105#define INSTANTIATE_VECTOR_FOR_TYPE(__TYPE__) \
106 template <> \

Callers

nothing calls this directly

Calls 13

InstanceFunction · 0.85
OptionalCustomPlaceFunction · 0.85
OptionalCUDAPlaceFunction · 0.85
CopyFunction · 0.70
AllocFunction · 0.50
CPUPlaceClass · 0.50
dataMethod · 0.45
sizeMethod · 0.45
ptrMethod · 0.45
GetMethod · 0.45
streamMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected