MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / MakeSubBuffer

Method MakeSubBuffer

tensorflow/compiler/xrt/xrt_state.cc:354–393  ·  view source on GitHub ↗

static*/

Source from the content-addressed store, hash-verified

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
395void XRTTupleAllocation::SetDeviceMemorySize() {
396 size_t size = 0;

Callers

nothing calls this directly

Calls 9

CopySubtreeFromMethod · 0.80
SetDeviceMemorySizeMethod · 0.80
device_ordinalMethod · 0.45
ForEachElementMethod · 0.45
RefMethod · 0.45
ForEachMutableElementMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
mutable_elementMethod · 0.45

Tested by

no test coverage detected