| 10 | { |
| 11 | |
| 12 | TfLiteStatus VisitCastOperator(DelegateData& delegateData, |
| 13 | TfLiteOpaqueContext* tfLiteContext, |
| 14 | TfLiteOpaqueNode* tfLiteNode, |
| 15 | int nodeIndex, |
| 16 | int32_t operatorCode) |
| 17 | { |
| 18 | TF_LITE_ENSURE_STATUS(ValidateNumInputs(tfLiteContext, tfLiteNode, 1, nodeIndex)); |
| 19 | TF_LITE_ENSURE_STATUS(ValidateNumOutputs(tfLiteContext, tfLiteNode, 1, nodeIndex)); |
| 20 | int numInputs = 0; |
| 21 | const int* inputTensors; |
| 22 | if (TfLiteOpaqueNodeInputs(tfLiteNode, &inputTensors, &numInputs) != kTfLiteOk) |
| 23 | { |
| 24 | return kTfLiteError; |
| 25 | } |
| 26 | |
| 27 | // This layer only has 1 input, so we can directly assign tensor[0] to a new opaque tensor |
| 28 | const TfLiteOpaqueTensor* |
| 29 | tfLiteInputTensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext, inputTensors[numInputs-1]); |
| 30 | if (!IsValid(tfLiteContext, tfLiteInputTensor, operatorCode, nodeIndex)) |
| 31 | { |
| 32 | return kTfLiteError; |
| 33 | } |
| 34 | |
| 35 | int numOutputs = 0; |
| 36 | const int* outputTensors; |
| 37 | if (TfLiteOpaqueNodeOutputs(tfLiteNode, &outputTensors, &numOutputs) != kTfLiteOk) |
| 38 | { |
| 39 | return kTfLiteError; |
| 40 | } |
| 41 | |
| 42 | // This layer only has 1 output, so we can directly assign tensor[0] to a new opaque tensor |
| 43 | const TfLiteOpaqueTensor* |
| 44 | tfLiteOutputTensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext, outputTensors[numOutputs-1]); |
| 45 | if (!IsValid(tfLiteContext, tfLiteOutputTensor, operatorCode, nodeIndex)) |
| 46 | { |
| 47 | return kTfLiteError; |
| 48 | } |
| 49 | |
| 50 | const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteOpaqueTensor(tfLiteInputTensor); |
| 51 | const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteOpaqueTensor(tfLiteOutputTensor, true); |
| 52 | |
| 53 | bool isSupported = false; |
| 54 | armnn::BackendId setBackend; |
| 55 | auto validateFunc = [&](const armnn::TensorInfo& outInfo, bool& isSupported) { |
| 56 | FORWARD_LAYER_OPAQUE_SUPPORT_FUNC("CAST", |
| 57 | tfLiteContext, |
| 58 | IsCastSupported, |
| 59 | delegateData.m_Backends, |
| 60 | isSupported, |
| 61 | setBackend, |
| 62 | inputTensorInfo, |
| 63 | outInfo); |
| 64 | }; |
| 65 | |
| 66 | // If the m_Network is a nullptr, this signals that a prerequisite TfLite callback is required to clarify the |
| 67 | // support for the operator |
| 68 | // If supported, VisitCastOperator will be called again to add the layer to the network as seen further below |
| 69 | if (!delegateData.m_Network) |
no test coverage detected