| 70 | } |
| 71 | |
| 72 | inline phi::DenseTensor TransDataLayout(const phi::DenseTensor& tensor, |
| 73 | DataLayout layout) { |
| 74 | auto& pool = phi::DeviceContextPool::Instance(); |
| 75 | VLOG(3) << "DataLayoutTransform src_layout: " << tensor.layout() |
| 76 | << " dst_layout: " << layout; |
| 77 | if (tensor.place().GetType() == phi::AllocationType::CPU) { |
| 78 | auto* dev_ctx = static_cast<phi::CPUContext*>(pool.Get(tensor.place())); |
| 79 | return phi::TransferLayout(*dev_ctx, tensor, layout); |
| 80 | } else { |
| 81 | PADDLE_THROW(common::errors::PreconditionNotMet( |
| 82 | "Unsupported data layout cast from CPU to GPU.")); |
| 83 | } |
| 84 | return tensor; |
| 85 | } |
| 86 | |
| 87 | template <typename Context> |
| 88 | phi::DenseTensor CastDataType(const Context& dev_ctx, |