| 486 | } |
| 487 | |
| 488 | Status XlaDevice::MakeTensorFromProto(XlaDeviceContext* device_context, |
| 489 | const TensorProto& tensor_proto, |
| 490 | const AllocatorAttributes alloc_attrs, |
| 491 | Tensor* tensor) { |
| 492 | Tensor parsed(tensor_proto.dtype()); |
| 493 | if (!parsed.FromProto(cpu_allocator(), tensor_proto)) { |
| 494 | return errors::InvalidArgument("Cannot parse tensor from proto: ", |
| 495 | tensor_proto.DebugString()); |
| 496 | } |
| 497 | |
| 498 | Status status; |
| 499 | if (alloc_attrs.on_host()) { |
| 500 | *tensor = parsed; |
| 501 | } else { |
| 502 | mutex_lock lock(mu_); |
| 503 | Allocator* allocator = GetAllocatorLocked(alloc_attrs); |
| 504 | Tensor copy(allocator, parsed.dtype(), parsed.shape()); |
| 505 | Notification n; |
| 506 | device_context->CopyCPUTensorToDevice( |
| 507 | &parsed, this, ©, |
| 508 | [&n, &status](const Status& s) { |
| 509 | status = s; |
| 510 | n.Notify(); |
| 511 | }, |
| 512 | true /*sync_dst_compute*/); |
| 513 | n.WaitForNotification(); |
| 514 | *tensor = copy; |
| 515 | } |
| 516 | VLOG(2) << "Allocated tensor at " << DMAHelper::base(tensor); |
| 517 | return status; |
| 518 | } |
| 519 | |
| 520 | Status XlaDevice::MakeTensorFromProto(const TensorProto& tensor_proto, |
| 521 | const AllocatorAttributes alloc_attrs, |
no test coverage detected