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

Method MakeTensorFromProto

tensorflow/core/common_runtime/sycl/sycl_device.cc:45–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45Status 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, &copy, [&status](const Status& s) { status = s; });
72 *tensor = copy;
73 }
74 return status;
75}
76
77Status SYCLDevice::TryGetDeviceContext(DeviceContext** out_context) {
78 device_context_->Ref();

Callers 2

InitFromMethod · 0.45
ParseFromMethod · 0.45

Calls 12

InvalidArgumentFunction · 0.85
ResourceExhaustedFunction · 0.85
set_on_hostMethod · 0.80
GetAllocatorFunction · 0.50
DataTypeStringFunction · 0.50
dtypeMethod · 0.45
FromProtoMethod · 0.45
DebugStringMethod · 0.45
on_hostMethod · 0.45
shapeMethod · 0.45
IsInitializedMethod · 0.45
CopyCPUTensorToDeviceMethod · 0.45

Tested by

no test coverage detected