| 62 | using se::Stream; |
| 63 | |
| 64 | Status PrepareCopy(Device* device, const DeviceContext* ctx, const Tensor& src, |
| 65 | const Tensor* dst, |
| 66 | const DeviceBase::GpuDeviceInfo** dev_info, |
| 67 | se::Stream** stream) { |
| 68 | if (device == nullptr) { |
| 69 | return errors::Internal("Unexpected null device."); |
| 70 | } |
| 71 | auto di = device->tensorflow_gpu_device_info(); |
| 72 | if (di == nullptr) { |
| 73 | return errors::Internal("Unexpected null device info."); |
| 74 | } |
| 75 | *dev_info = di; |
| 76 | if (ctx == nullptr) { |
| 77 | return errors::Internal("Unexpected null device context."); |
| 78 | } |
| 79 | auto gs = static_cast<const GPUDeviceContext*>(ctx)->stream(); |
| 80 | if (gs == nullptr) { |
| 81 | return errors::Internal("No gpu stream is available."); |
| 82 | } |
| 83 | *stream = gs; |
| 84 | if (dst != nullptr) { |
| 85 | if (src.dtype() != dst->dtype()) { |
| 86 | return errors::Internal("Can't copy a tensor of ", |
| 87 | DataTypeString(src.dtype()), " into a tensor of ", |
| 88 | DataTypeString(dst->dtype())); |
| 89 | } |
| 90 | if (src.TotalBytes() != dst->TotalBytes()) { |
| 91 | return errors::Internal("Can't copy ", src.TotalBytes(), |
| 92 | " bytes of a tensor into another with ", |
| 93 | dst->TotalBytes(), " bytes buffer."); |
| 94 | } |
| 95 | if ((src.TotalBytes() > 0) && !src.IsInitialized()) { |
| 96 | return errors::Internal("Src tensor is not initialized."); |
| 97 | } |
| 98 | if ((dst->TotalBytes() > 0) && !dst->IsInitialized()) { |
| 99 | return errors::Internal("Dst tensor is not initialized."); |
| 100 | } |
| 101 | } |
| 102 | if (!DMAHelper::CanUseDMA(&src)) { |
| 103 | return errors::Internal("GPU copy from non-DMA ", |
| 104 | DataTypeString(src.dtype()), " tensor"); |
| 105 | } |
| 106 | return Status::OK(); |
| 107 | } |
| 108 | |
| 109 | void* GetBase(const Tensor* src) { |
| 110 | return const_cast<void*>(DMAHelper::base(src)); |
no test coverage detected