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

Function CopyDeviceToHost

tensorflow/core/common_runtime/copy_tensor.cc:344–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

342} // namespace
343
344void CopyDeviceToHost(const Tensor* input, Allocator* cpu_allocator,
345 Allocator* out_allocator, StringPiece edge_name,
346 Device* src, Tensor* output,
347 DeviceContext* send_dev_context, StatusCallback done) {
348 if (input->dtype() == DT_VARIANT) {
349 Tensor copy(cpu_allocator, DT_VARIANT, input->shape());
350 auto* status_cb = new ReffedStatusCallback(std::move(done));
351 core::ScopedUnref status_cb_unref(status_cb);
352
353 auto wrapped_done = [status_cb](const Status& s) {
354 status_cb->UpdateStatus(s);
355 status_cb->Unref();
356 };
357 auto copier = std::bind(
358 [edge_name, src, send_dev_context, out_allocator, status_cb,
359 cpu_allocator](StatusCallback wrapped_done_,
360 // Begin unbound arguments
361 const Tensor& from, Tensor* to) {
362 if (from.dtype() == DT_VARIANT) {
363 status_cb->Ref();
364 CopyDeviceToHost(&from, cpu_allocator, out_allocator, edge_name,
365 src, to, send_dev_context, wrapped_done_);
366 return Status::OK();
367 } else {
368 if (!DMAHelper::CanUseDMA(&from)) {
369 Status err = errors::InvalidArgument(
370 "During Variant Device->Host Copy: "
371 "non-DMA-copy attempted of tensor type: ",
372 DataTypeString(from.dtype()));
373 status_cb->UpdateStatus(err);
374 return err;
375 }
376 if (status_cb->ok()) {
377 status_cb->Ref();
378 *to = Tensor(out_allocator, from.dtype(), from.shape());
379 send_dev_context->CopyDeviceTensorToCPU(&from, edge_name, src, to,
380 wrapped_done_);
381 return Status::OK();
382 } else {
383 return status_cb->status();
384 }
385 }
386 },
387 std::move(wrapped_done), std::placeholders::_1, std::placeholders::_2);
388
389 const Variant* v = input->flat<Variant>().data();
390 Variant* v_out = copy.flat<Variant>().data();
391 Status s_copy_init;
392 for (int64 i = 0; i < input->NumElements(); ++i) {
393 s_copy_init = VariantDeviceCopy(
394 VariantDeviceCopyDirection::DEVICE_TO_HOST, v[i], &v_out[i], copier);
395 if (!s_copy_init.ok()) {
396 status_cb->UpdateStatus(s_copy_init);
397 break;
398 }
399 }
400 if (s_copy_init.ok()) {
401 *output = std::move(copy);

Callers 3

ViaDMAMethod · 0.85
GrpcRecvTensorAsyncMethod · 0.85

Calls 14

InvalidArgumentFunction · 0.85
VariantDeviceCopyFunction · 0.85
TensorClass · 0.70
DataTypeStringFunction · 0.50
dtypeMethod · 0.45
shapeMethod · 0.45
UpdateStatusMethod · 0.45
UnrefMethod · 0.45
RefMethod · 0.45
okMethod · 0.45
CopyDeviceTensorToCPUMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected