blob: ba81cd8d56f6ab77f8f52c1dca32c616ad050641 [file] [log] [blame]
Jan Eilerse339bf62020-11-10 18:43:23 +00001//
Teresa Charlinad1b3d72023-03-14 12:10:28 +00002// Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved.
Jan Eilerse339bf62020-11-10 18:43:23 +00003// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +00008#include <tensorflow/lite/c/common.h>
Jan Eilerse339bf62020-11-10 18:43:23 +00009#include <tensorflow/lite/interpreter.h>
10
Matthew Sloyan91c41712020-11-13 09:47:35 +000011#include <doctest/doctest.h>
12
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000013#include <half/half.hpp>
14
15using Half = half_float::half;
16
Jan Eilerse339bf62020-11-10 18:43:23 +000017namespace armnnDelegate
18{
19
Matthew Sloyanebe392d2023-03-30 10:12:08 +010020constexpr const char* FILE_IDENTIFIER = "TFL3";
Finn Williams63e6ace2021-02-17 18:12:39 +000021
Jan Eilersfe73b042020-11-18 10:36:46 +000022/// Can be used to compare bool data coming from a tflite interpreter
23/// Boolean types get converted to a bit representation in a vector. vector.data() returns a void pointer
24/// instead of a pointer to bool. Therefore a special function to compare to vector of bool is required
Matthew Sloyanebe392d2023-03-30 10:12:08 +010025void CompareData(std::vector<bool>& tensor1, std::vector<bool>& tensor2, size_t tensorSize);
Jan Eilersfe73b042020-11-18 10:36:46 +000026void CompareData(bool tensor1[], bool tensor2[], size_t tensorSize);
27
28/// Can be used to compare float data coming from a tflite interpreter with a tolerance of limit_of_float*100
Jan Eilers3812fbc2020-11-17 19:06:35 +000029void CompareData(float tensor1[], float tensor2[], size_t tensorSize);
Jan Eilersfe73b042020-11-18 10:36:46 +000030
Narumol Prangnawarat7684b182021-08-12 14:48:15 +010031/// Can be used to compare float data coming from a tflite interpreter with a given percentage tolerance
32void CompareData(float tensor1[], float tensor2[], size_t tensorSize, float percentTolerance);
33
Jan Eilersfe73b042020-11-18 10:36:46 +000034/// Can be used to compare int8_t data coming from a tflite interpreter with a tolerance of 1
Jan Eilers3812fbc2020-11-17 19:06:35 +000035void CompareData(int8_t tensor1[], int8_t tensor2[], size_t tensorSize);
Jan Eilersfe73b042020-11-18 10:36:46 +000036
37/// Can be used to compare uint8_t data coming from a tflite interpreter with a tolerance of 1
Jan Eilers3812fbc2020-11-17 19:06:35 +000038void CompareData(uint8_t tensor1[], uint8_t tensor2[], size_t tensorSize);
Jan Eilersfe73b042020-11-18 10:36:46 +000039
40/// Can be used to compare int16_t data coming from a tflite interpreter with a tolerance of 1
Jan Eilers3812fbc2020-11-17 19:06:35 +000041void CompareData(int16_t tensor1[], int16_t tensor2[], size_t tensorSize);
42
Sadik Armagan29b49cf2021-02-22 18:09:07 +000043/// Can be used to compare int32_t data coming from a tflite interpreter with a tolerance of 1
44void CompareData(int32_t tensor1[], int32_t tensor2[], size_t tensorSize);
45
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000046/// Can be used to compare Half (Float16) data with a tolerance of limit_of_float*100
47void CompareData(Half tensor1[], Half tensor2[], size_t tensorSize);
48
49/// Can be used to compare TfLiteFloat16 data coming from a tflite interpreter
50void CompareData(TfLiteFloat16 tensor1[], TfLiteFloat16 tensor2[], size_t tensorSize);
51
52/// Can be used to compare Half (Float16) data and TfLiteFloat16 data coming from a tflite interpreter
53void CompareData(TfLiteFloat16 tensor1[], Half tensor2[], size_t tensorSize);
Jan Eilers3812fbc2020-11-17 19:06:35 +000054
Matthew Sloyanebe392d2023-03-30 10:12:08 +010055/// Can be used to compare the output tensor shape
56/// Example usage can be found in ControlTestHelper.hpp
57void CompareOutputShape(const std::vector<int32_t>& tfLiteDelegateShape,
58 const std::vector<int32_t>& armnnDelegateShape,
59 const std::vector<int32_t>& expectedOutputShape);
60
61/// Can be used to compare the output tensor values
Jan Eilersfe73b042020-11-18 10:36:46 +000062/// Example usage can be found in ControlTestHelper.hpp
Matthew Sloyan91c41712020-11-13 09:47:35 +000063template <typename T>
Matthew Sloyanebe392d2023-03-30 10:12:08 +010064void CompareOutputData(std::vector<T>& tfLiteDelegateOutputs,
65 std::vector<T>& armnnDelegateOutputs,
66 std::vector<T>& expectedOutputValues)
Matthew Sloyan91c41712020-11-13 09:47:35 +000067{
Matthew Sloyanebe392d2023-03-30 10:12:08 +010068 armnnDelegate::CompareData(expectedOutputValues.data(), armnnDelegateOutputs.data(), expectedOutputValues.size());
69 armnnDelegate::CompareData(tfLiteDelegateOutputs.data(), expectedOutputValues.data(), expectedOutputValues.size());
70 armnnDelegate::CompareData(tfLiteDelegateOutputs.data(), armnnDelegateOutputs.data(), expectedOutputValues.size());
Matthew Sloyan91c41712020-11-13 09:47:35 +000071}
72
Jan Eilerse339bf62020-11-10 18:43:23 +000073} // namespace armnnDelegate