| 43 | } |
| 44 | |
| 45 | Status SYCLDevice::MakeTensorFromProto(const TensorProto& tensor_proto, |
| 46 | const AllocatorAttributes alloc_attrs, |
| 47 | Tensor* tensor) { |
| 48 | AllocatorAttributes attr; |
| 49 | attr.set_on_host(true); |
| 50 | Allocator* host_alloc = GetAllocator(attr); |
| 51 | |
| 52 | Tensor parsed(tensor_proto.dtype()); |
| 53 | if (!parsed.FromProto(host_alloc, tensor_proto)) { |
| 54 | return errors::InvalidArgument("Cannot parse tensor from proto: ", |
| 55 | tensor_proto.DebugString()); |
| 56 | } |
| 57 | Status status; |
| 58 | if (alloc_attrs.on_host()) { |
| 59 | *tensor = parsed; |
| 60 | } else { |
| 61 | Tensor copy(GetAllocator(alloc_attrs), parsed.dtype(), parsed.shape()); |
| 62 | |
| 63 | // If the tensor is not initialized, we likely ran out of memory. |
| 64 | if (!copy.IsInitialized()) { |
| 65 | return errors::ResourceExhausted( |
| 66 | "OOM when allocating tensor of shape ", parsed.shape().DebugString(), |
| 67 | " and type ", DataTypeString(parsed.dtype())); |
| 68 | } |
| 69 | |
| 70 | device_context_->CopyCPUTensorToDevice( |
| 71 | &parsed, this, ©, [&status](const Status& s) { status = s; }); |
| 72 | *tensor = copy; |
| 73 | } |
| 74 | return status; |
| 75 | } |
| 76 | |
| 77 | Status SYCLDevice::TryGetDeviceContext(DeviceContext** out_context) { |
| 78 | device_context_->Ref(); |
no test coverage detected