static*/
| 352 | } |
| 353 | |
| 354 | /*static*/ Status XRTTupleAllocation::MakeSubBuffer( |
| 355 | XRTTupleAllocation* parent, const xla::ShapeIndex& subshape, |
| 356 | XRTTupleAllocation** allocation, bool alias_parent_allocation) { |
| 357 | TF_ASSIGN_OR_RETURN( |
| 358 | const xla::Shape* host_sub_shape, |
| 359 | xla::ShapeUtil::TryGetSubshape(parent->on_host_shape(), subshape)); |
| 360 | TF_ASSIGN_OR_RETURN( |
| 361 | const xla::Shape* device_sub_shape, |
| 362 | xla::ShapeUtil::TryGetSubshape(parent->on_device_shape(), subshape)); |
| 363 | |
| 364 | *allocation = |
| 365 | new XRTTupleAllocation(parent->device_ordinal(), parent->allocator_, |
| 366 | *host_sub_shape, *device_sub_shape); |
| 367 | if (alias_parent_allocation) { |
| 368 | // Copy the subtree of allocations from the parent allocation. |
| 369 | (*allocation)->buffers_.CopySubtreeFrom(parent->buffers_, subshape, {}); |
| 370 | // Increment the refcount on each aliased buffer. |
| 371 | (*allocation) |
| 372 | ->buffers_.ForEachElement( |
| 373 | [](const xla::ShapeIndex& index, |
| 374 | const XRTBufferAllocationPtr& buffer) { buffer->Ref(); }); |
| 375 | } else { |
| 376 | // Find the buffers in the parent allocation that match the subtree, and |
| 377 | // move the parent allocation's buffer over to the new allocation. |
| 378 | (*allocation) |
| 379 | ->buffers_.ForEachMutableElement( |
| 380 | [&](const xla::ShapeIndex& index, XRTBufferAllocationPtr* buffer) { |
| 381 | // Extend the allocation's index to the parent's frame by adding |
| 382 | // subshape as a prefix. |
| 383 | xla::ShapeIndex parent_index = subshape; |
| 384 | for (int i = 0; i < index.size(); ++i) { |
| 385 | parent_index.push_back(index[i]); |
| 386 | } |
| 387 | *buffer = parent->buffers_.element(parent_index); |
| 388 | *parent->buffers_.mutable_element(parent_index) = nullptr; |
| 389 | }); |
| 390 | } |
| 391 | (*allocation)->SetDeviceMemorySize(); |
| 392 | return Status::OK(); |
| 393 | } |
| 394 | |
| 395 | void XRTTupleAllocation::SetDeviceMemorySize() { |
| 396 | size_t size = 0; |
nothing calls this directly
no test coverage detected