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

Method Prepare

tensorflow/lite/delegates/gpu/gl_delegate.cc:129–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127 }
128
129 Status Prepare(TfLiteContext* context,
130 const TfLiteDelegateParams* delegate_params) {
131 // Extract TFLite delegate execution plan from the context and convert it
132 // into FlowGraph32.
133 GraphFloat32 graph;
134 RETURN_IF_ERROR(BuildModel(context, delegate_params, &graph));
135
136 // Apply general transformations on the graph.
137 NullTransformationReporter reporter;
138 ModelTransformer transformer(&graph, &reporter);
139 if (!ApplyGeneralTransformations(&transformer)) {
140 return InternalError("Graph general transformations failed");
141 }
142
143 if (!env_) RETURN_IF_ERROR(EglEnvironment::NewEglEnvironment(&env_));
144
145 // TODO(impjdi): Remove code duplication.
146 auto values = graph.values();
147 auto find_value = [&](int tensor_index) -> Value<TensorRef<BHWC>>* {
148 for (auto value : values) {
149 if (value->tensor.ref == tensor_index) return value;
150 }
151 return nullptr;
152 };
153 tensors_.reserve(values.back()->id + 1);
154 for (auto value : values) {
155 if (tensors_.size() <= value->id) {
156 tensors_.resize(value->id + 1);
157 }
158 tensors_[value->id] = {value->tensor.shape, 0};
159 }
160
161 std::unordered_set<int> tflite_graph_io;
162
163 // Prepare graph inputs.
164 //
165 // Note that graph.inputs() cannot be used directly, as the notion of
166 // graph input has a different meaning in public API and GPU-internal API.
167 {
168 inputs_.clear();
169 inputs_.reserve(delegate_params->input_tensors->size);
170 for (int i = 0; i < delegate_params->input_tensors->size; ++i) {
171 const int tensor_index = delegate_params->input_tensors->data[i];
172 auto* tensor = context->tensors + tensor_index;
173 if (tensor->allocation_type == TfLiteAllocationType::kTfLiteMmapRo) {
174 continue;
175 }
176 tflite_graph_io.insert(tensor_index);
177 const auto* input = find_value(tensor_index);
178 if (!input || tensor->type != TfLiteType::kTfLiteFloat32) {
179 return NotFoundError("Input tensor is not found in the graph.");
180 }
181
182 inputs_.push_back(input->id);
183 tensor->buffer_handle = input->id;
184 tensor->delegate = &delegate_;
185 tensors_[input->id].tensor_index = tensor_index;
186

Callers 1

DelegatePrepareFunction · 0.45

Implementers 1

NnApiDelegatetensorflow/lite/delegates/nnapi/java/s

Calls 15

BuildModelFunction · 0.85
IsPHWC4Function · 0.85
GetElementsSizeForPHWC4Function · 0.85
NewNodeShaderRegistryFunction · 0.85
RequestGpuInfoFunction · 0.85
NewCommandQueueFunction · 0.85
OkStatusFunction · 0.85
FindBufferMethod · 0.80
MakeRefMethod · 0.80
InternalErrorFunction · 0.50

Tested by

no test coverage detected