| 625 | } |
| 626 | |
| 627 | TfLiteStatus ArmnnSubgraph::Invoke(TfLiteOpaqueContext* tfLiteContext, TfLiteOpaqueNode* tfLiteNode) |
| 628 | { |
| 629 | // Get array of input indices, inputIndexArray is set from the TfLiteOpaqueNodeInputs function |
| 630 | // This function turns inputIndexArray into an int array of indices. These indices point to the tensors for |
| 631 | // each input slot in the node. |
| 632 | const int* inputIndexArray; |
| 633 | int numInputs; |
| 634 | if(TfLiteOpaqueNodeInputs(tfLiteNode, &inputIndexArray, &numInputs) != kTfLiteOk) |
| 635 | { |
| 636 | throw armnn::Exception("TfLiteArmnnOpaqueDelegate: Unable to load subgraph inputs!"); |
| 637 | } |
| 638 | // Prepare inputs |
| 639 | armnn::InputTensors inputTensors; |
| 640 | size_t inputIndex = 0; |
| 641 | for (int inputIdx = 0; inputIdx < numInputs; inputIdx++) |
| 642 | { |
| 643 | TfLiteOpaqueTensor* tensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext, inputIndexArray[inputIdx]); |
| 644 | |
| 645 | if(!IsValid(tensor)) |
| 646 | { |
| 647 | return kTfLiteError; |
| 648 | } |
| 649 | // If tensor is not read only |
| 650 | if (TfLiteOpaqueTensorGetAllocationType(tensor) != kTfLiteMmapRo) |
| 651 | { |
| 652 | const armnn::BindingPointInfo& inputBinding = m_InputBindings[inputIndex]; |
| 653 | armnn::TensorInfo inputTensorInfo = inputBinding.second; |
| 654 | inputTensorInfo.SetConstant(true); |
| 655 | const armnn::ConstTensor inputTensor(inputTensorInfo, TfLiteOpaqueTensorData(tensor)); |
| 656 | inputTensors.emplace_back(inputIndexArray[inputIdx], inputTensor); |
| 657 | |
| 658 | ++inputIndex; |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | // Get array of output indices, outputIndexArray is set from the TfLiteOpaqueNodeOutputs function |
| 663 | // This function turns outputIndexArray into an int array of indices. These indices point to the tensors for |
| 664 | // each output slot in the node. |
| 665 | const int* outputIndexArray; |
| 666 | int numOutputs; |
| 667 | if(TfLiteOpaqueNodeOutputs(tfLiteNode, &outputIndexArray, &numOutputs) != kTfLiteOk) |
| 668 | { |
| 669 | throw armnn::Exception("TfLiteArmnnOpaqueDelegate: Unable to load subgraph outputs!"); |
| 670 | } |
| 671 | // Assign the tensors from the outputIndexArray to the armnn BindingPointInfo |
| 672 | armnn::OutputTensors outputTensors; |
| 673 | for (int outputIdx = 0; outputIdx < numOutputs; outputIdx++) |
| 674 | { |
| 675 | const armnn::BindingPointInfo& outputBinding = m_OutputBindings[outputIdx]; |
| 676 | TfLiteOpaqueTensor* tensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext, outputIndexArray[outputIdx]); |
| 677 | if(!IsValid(tensor)) |
| 678 | { |
| 679 | return kTfLiteError; |
| 680 | } |
| 681 | |
| 682 | const armnn::Tensor outputTensor(outputBinding.second, reinterpret_cast<TfLiteTensor*>(tensor)->data |
| 683 | .data); |
| 684 | outputTensors.emplace_back(outputIndexArray[outputIdx], outputTensor); |