| 293 | } // namespace |
| 294 | |
| 295 | TfLiteStatus InterpreterBuilder::ParseNodes( |
| 296 | const flatbuffers::Vector<flatbuffers::Offset<Operator>>* operators, |
| 297 | Subgraph* subgraph) { |
| 298 | TfLiteStatus status = kTfLiteOk; |
| 299 | |
| 300 | // Reduce the number of redundant allocations |
| 301 | subgraph->ReserveNodes(operators->Length()); |
| 302 | |
| 303 | for (int i = 0; i < operators->Length(); ++i) { |
| 304 | const auto* op = operators->Get(i); |
| 305 | int index = op->opcode_index(); |
| 306 | if (index < 0 || index >= flatbuffer_op_index_to_registration_.size()) { |
| 307 | error_reporter_->Report("Missing registration for opcode_index %d\n", |
| 308 | index); |
| 309 | status = kTfLiteError; |
| 310 | continue; |
| 311 | } |
| 312 | |
| 313 | const TfLiteRegistration* registration = |
| 314 | flatbuffer_op_index_to_registration_[index]; |
| 315 | if (registration == nullptr) { |
| 316 | error_reporter_->Report("Skipping op for opcode_index %d\n", index); |
| 317 | status = kTfLiteError; |
| 318 | continue; |
| 319 | } |
| 320 | |
| 321 | BuiltinOperator op_type = |
| 322 | static_cast<BuiltinOperator>(registration->builtin_code); |
| 323 | |
| 324 | if (op_type != BuiltinOperator_CUSTOM && op->custom_options()) { |
| 325 | error_reporter_->Report( |
| 326 | "Found builtin operator %s with custom options.\n", |
| 327 | EnumNameBuiltinOperator(op_type)); |
| 328 | } |
| 329 | |
| 330 | if (op_type == BuiltinOperator_CUSTOM) { |
| 331 | if (op->custom_options()) { |
| 332 | subgraph->AddNodeWithParameters( |
| 333 | FlatBufferIntArrayToVector(op->inputs()), |
| 334 | FlatBufferIntArrayToVector(op->outputs()), |
| 335 | FlatBufferIntArrayToVector(op->intermediates()), |
| 336 | reinterpret_cast<const char*>(op->custom_options()->data()), |
| 337 | op->custom_options()->size(), nullptr, registration); |
| 338 | } else { |
| 339 | subgraph->AddNodeWithParameters( |
| 340 | FlatBufferIntArrayToVector(op->inputs()), |
| 341 | FlatBufferIntArrayToVector(op->outputs()), |
| 342 | FlatBufferIntArrayToVector(op->intermediates()), nullptr, 0, |
| 343 | nullptr, registration); |
| 344 | } |
| 345 | } else { |
| 346 | void* builtin_data = nullptr; |
| 347 | MallocDataAllocator malloc_allocator; |
| 348 | TF_LITE_ENSURE_STATUS(ParseOpData(op, op_type, error_reporter_, |
| 349 | &malloc_allocator, &builtin_data)); |
| 350 | subgraph->AddNodeWithParameters( |
| 351 | FlatBufferIntArrayToVector(op->inputs()), |
| 352 | FlatBufferIntArrayToVector(op->outputs()), |
nothing calls this directly
no test coverage detected