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

Function CopyFromBufferHandle

tensorflow/lite/delegates/flex/delegate.cc:77–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77TfLiteStatus CopyFromBufferHandle(TfLiteContext* context,
78 TfLiteDelegate* delegate,
79 TfLiteBufferHandle buffer_handle,
80 TfLiteTensor* output) {
81 BufferMap* buffer_map =
82 reinterpret_cast<DelegateData*>(delegate->data_)->GetBufferMap(context);
83
84 if (!buffer_map->HasTensor(buffer_handle)) {
85 context->ReportError(context, "Invalid tensor index %d.", buffer_handle);
86 return kTfLiteError;
87 }
88
89 tensorflow::Tensor t = buffer_map->GetTensor(buffer_handle);
90
91 if (output->type == kTfLiteString) {
92 if (t.dtype() != tensorflow::DT_STRING) {
93 context->ReportError(context,
94 "Inconsistent type for TF string tensor index %d.",
95 buffer_handle);
96 return kTfLiteError;
97 }
98 DynamicBuffer dynamic_buffer;
99
100 auto tf_data = t.flat<tensorflow::tstring>();
101 for (int i = 0; i < t.NumElements(); ++i) {
102 dynamic_buffer.AddString(tf_data(i).data(), tf_data(i).size());
103 }
104
105 dynamic_buffer.WriteToTensor(output, /*new_shape=*/nullptr);
106 return kTfLiteOk;
107 }
108
109 tensorflow::StringPiece t_data = t.tensor_data();
110
111 if (output->bytes != t_data.size()) {
112 context->ReportError(context,
113 absl::StrCat("The given ", output->bytes,
114 " bytes are not enough to store "
115 "TensorFlow's aligned buffer of size ",
116 t_data.size(), " bytes.")
117 .c_str());
118 return kTfLiteError;
119 }
120
121 memcpy(output->data.raw, t_data.data(), t_data.size());
122 return kTfLiteOk;
123}
124
125} // namespace delegate
126} // namespace flex

Callers 1

InvokeMethod · 0.85

Calls 13

GetBufferMapMethod · 0.80
AddStringMethod · 0.80
WriteToTensorMethod · 0.80
tensor_dataMethod · 0.80
c_strMethod · 0.80
StrCatFunction · 0.50
HasTensorMethod · 0.45
ReportErrorMethod · 0.45
GetTensorMethod · 0.45
dtypeMethod · 0.45
NumElementsMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected