| 2422 | } |
| 2423 | |
| 2424 | Status BuildModel(TfLiteContext* context, |
| 2425 | const TfLiteDelegateParams* delegate_params, |
| 2426 | GraphFloat32* graph) { |
| 2427 | std::vector<std::unique_ptr<TFLiteOperationParser>> operations; |
| 2428 | std::vector<int> tflite_nodes; |
| 2429 | for (int i = 0; i < delegate_params->nodes_to_replace->size; ++i) { |
| 2430 | TfLiteNode* tflite_node = nullptr; |
| 2431 | TfLiteRegistration* registration = nullptr; |
| 2432 | RETURN_IF_ERROR(GetNodeAndRegistration( |
| 2433 | context, delegate_params->nodes_to_replace->data[i], &tflite_node, |
| 2434 | ®istration)); |
| 2435 | if (registration->builtin_code == kTfLiteBuiltinDequantize) { |
| 2436 | // Ignore Dequantize nodes. |
| 2437 | continue; |
| 2438 | } |
| 2439 | auto op_parser = NewOperationParser(registration); |
| 2440 | if (!op_parser) { |
| 2441 | return UnimplementedError( |
| 2442 | absl::StrCat("Operation ", registration->builtin_code, "(", |
| 2443 | registration->custom_name, |
| 2444 | ") is not supported by TFLite GPU Delegate.")); |
| 2445 | } |
| 2446 | operations.push_back(std::move(op_parser)); |
| 2447 | tflite_nodes.push_back(i); |
| 2448 | } |
| 2449 | std::vector<Value<TensorRef<BHWC>>*> tensor_to_value(context->tensors_size, |
| 2450 | nullptr); |
| 2451 | for (int i = 0; i < operations.size(); ++i) { |
| 2452 | TfLiteNode* tflite_node; |
| 2453 | TfLiteRegistration* registration; |
| 2454 | RETURN_IF_ERROR(GetNodeAndRegistration( |
| 2455 | context, delegate_params->nodes_to_replace->data[tflite_nodes[i]], |
| 2456 | &tflite_node, ®istration)); |
| 2457 | ObjectReader reader(graph, context, tflite_node, &tensor_to_value); |
| 2458 | const auto status = |
| 2459 | operations[i]->Parse(tflite_node, registration, graph, &reader); |
| 2460 | if (!status.ok()) { |
| 2461 | return InternalError(absl::StrCat(GetOpNameByRegistration(registration), |
| 2462 | ": ", status.error_message())); |
| 2463 | } |
| 2464 | } |
| 2465 | return OkStatus(); |
| 2466 | } |
| 2467 | |
| 2468 | } // namespace gpu |
| 2469 | } // namespace tflite |
no test coverage detected