| 32 | |
| 33 | template <typename T> |
| 34 | static std::vector<T> ToVector(const T *x, |
| 35 | size_t n, |
| 36 | const phi::Place &place UNUSED) { |
| 37 | #ifdef __NVCC__ |
| 38 | if (place.GetType() == AllocationType::GPU) { |
| 39 | using CopyT = typename std:: |
| 40 | conditional<std::is_same<T, bool>::value, uint8_t, T>::type; |
| 41 | std::vector<CopyT> cpu_x(n); |
| 42 | auto *dev_ctx = |
| 43 | static_cast<GPUContext *>(DeviceContextPool::Instance().Get(place)); |
| 44 | memory_utils::Copy( |
| 45 | CPUPlace(), cpu_x.data(), place, x, n * sizeof(T), dev_ctx->stream()); |
| 46 | dev_ctx->Wait(); |
| 47 | return std::vector<T>(cpu_x.data(), cpu_x.data() + n); |
| 48 | } |
| 49 | #endif |
| 50 | return std::vector<T>(x, x + n); |
| 51 | } |
| 52 | |
| 53 | template <typename T> |
| 54 | static std::vector<T> ToVector(const DenseTensor &src) { |