static*/
| 167 | } |
| 168 | |
| 169 | /*static*/ Status XRTTupleAllocation::CreateAndTransfer( |
| 170 | const xla::LiteralBase& literal, XRTMemoryManager* memory_manager, |
| 171 | xla::Backend* backend, int device_ordinal, |
| 172 | XRTTupleAllocation** allocation) { |
| 173 | auto transfer_manager = backend->transfer_manager(); |
| 174 | std::unique_ptr<xla::ScopedShapedBuffer> scoped_buffer; |
| 175 | TF_RETURN_IF_ERROR(AllocateScopedShapedBuffer(memory_manager, backend, |
| 176 | device_ordinal, literal.shape(), |
| 177 | &scoped_buffer)); |
| 178 | TF_ASSIGN_OR_RETURN(auto stream, backend->BorrowStream(device_ordinal)); |
| 179 | TF_RETURN_IF_ERROR(transfer_manager->TransferLiteralToDevice( |
| 180 | stream.get(), literal, *scoped_buffer)); |
| 181 | |
| 182 | // By releasing the ScopedShapedBuffer we ensure that the underlying storage |
| 183 | // won't be freed when the buffer goes out of scope at the end of this |
| 184 | // call. To avoid a leak, there must be no error-case returns from here until |
| 185 | // the end of the method. |
| 186 | auto shaped_buffer = scoped_buffer->release(); |
| 187 | *allocation = new XRTTupleAllocation( |
| 188 | device_ordinal, backend->memory_allocator(), |
| 189 | shaped_buffer.on_host_shape(), shaped_buffer.on_device_shape()); |
| 190 | (*allocation) |
| 191 | ->InitializeFromShapedBuffer(shaped_buffer, backend->memory_allocator(), |
| 192 | device_ordinal); |
| 193 | (*allocation)->SetDeviceMemorySize(); |
| 194 | return Status::OK(); |
| 195 | } |
| 196 | |
| 197 | /*static*/ Status XRTTupleAllocation::CreateUninitialized( |
| 198 | const xla::Shape& shape, XRTMemoryManager* memory_manager, |
nothing calls this directly
no test coverage detected