blob: 641fd7ba56b1afb50528c609f47af37af4173dcf [file] [log] [blame]
Bruno Goncalves3d7efe92018-12-27 14:21:43 -02001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Bruno Goncalves3d7efe92018-12-27 14:21:43 -02006#include "ParserFlatbuffersFixture.hpp"
7#include "../TfLiteParser.hpp"
8
9#include <string>
10#include <iostream>
11
Kevin May7d96b162021-02-03 17:38:41 +000012using armnnTfLiteParser::TfLiteParserImpl;
Bruno Goncalves3d7efe92018-12-27 14:21:43 -020013
Sadik Armagan1625efc2021-06-10 18:24:34 +010014TEST_SUITE("TensorflowLiteParser_Constant")
15{
Bruno Goncalves3d7efe92018-12-27 14:21:43 -020016struct ConstantAddFixture : public ParserFlatbuffersFixture
17{
18 explicit ConstantAddFixture(const std::string & inputShape,
19 const std::string & outputShape,
20 const std::string & constShape,
21 const std::string & constData)
22 {
23 m_JsonString = R"(
24 {
25 "version": 3,
26 "operator_codes": [ { "builtin_code": "ADD" } ],
27 "subgraphs": [ {
28 "tensors": [
29 {
30 "shape": )" + constShape + R"( ,
31 "type": "UINT8",
32 "buffer": 3,
33 "name": "ConstTensor",
34 "quantization": {
35 "min": [ 0.0 ],
36 "max": [ 255.0 ],
37 "scale": [ 1.0 ],
38 "zero_point": [ 0 ],
39 }
40 },
41 {
42 "shape": )" + inputShape + R"(,
43 "type": "UINT8",
44 "buffer": 1,
45 "name": "InputTensor",
46 "quantization": {
47 "min": [ 0.0 ],
48 "max": [ 255.0 ],
49 "scale": [ 1.0 ],
50 "zero_point": [ 0 ],
51 }
52 },
53 {
54 "shape": )" + outputShape + R"( ,
55 "type": "UINT8",
56 "buffer": 2,
57 "name": "OutputTensor",
58 "quantization": {
59 "min": [ 0.0 ],
60 "max": [ 255.0 ],
61 "scale": [ 1.0 ],
62 "zero_point": [ 0 ],
63 }
64 }
65 ],
66 "inputs": [ 1 ],
67 "outputs": [ 2 ],
68 "operators": [
69 {
70 "opcode_index": 0,
71 "inputs": [ 1, 0 ],
72 "outputs": [ 2 ],
73 "builtin_options_type": "AddOptions",
74 "builtin_options": {
75 },
76 "custom_options_format": "FLEXBUFFERS"
77 }
78 ],
79 } ],
80 "buffers" : [
81 { },
82 { },
83 { },
84 { "data": )" + constData + R"(, },
85 ]
86 }
87 )";
88 Setup();
89 }
90};
91
92
93struct SimpleConstantAddFixture : ConstantAddFixture
94{
95 SimpleConstantAddFixture()
96 : ConstantAddFixture("[ 2, 2 ]", // inputShape
97 "[ 2, 2 ]", // outputShape
98 "[ 2, 2 ]", // constShape
99 "[ 4,5, 6,7 ]") // constData
100 {}
101};
102
Sadik Armagan1625efc2021-06-10 18:24:34 +0100103TEST_CASE_FIXTURE(SimpleConstantAddFixture, "SimpleConstantAdd")
Bruno Goncalves3d7efe92018-12-27 14:21:43 -0200104{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000105 RunTest<2, armnn::DataType::QAsymmU8>(
Bruno Goncalves3d7efe92018-12-27 14:21:43 -0200106 0,
107 {{"InputTensor", { 0, 1, 2, 3 }}},
108 {{"OutputTensor", { 4, 6, 8, 10 }}}
109 );
110}
111
Sadik Armagan1625efc2021-06-10 18:24:34 +0100112}