2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "CircleNodeSummaryBuilder.h"
19 #include <luci/IR/CircleNodes.h>
20 #include <locop/NodeSummary.h>
21 #include <locop/SymbolTable.h>
23 #include <gtest/gtest.h>
28 class MockSymbolTable : public locop::SymbolTable
30 std::string lookup(const loco::Node *) const override
32 return "Do nothing because it is mocking Symbol Table!";
36 class CircleNodeSummaryBuilderTest : public ::testing::Test
39 bool mock_build(const loco::Node *node)
41 return luci::CircleNodeSummaryBuilder().build(node, &_tbl, _s);
46 locop::NodeSummary _s;
51 TEST_F(CircleNodeSummaryBuilderTest, Add_validate)
54 node.fusedActivationFunction(luci::FusedActFunc::RELU);
55 EXPECT_TRUE(mock_build(&node));
58 TEST_F(CircleNodeSummaryBuilderTest, Add_validate_fused_NEG)
61 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
62 EXPECT_FALSE(mock_build(&node));
65 TEST_F(CircleNodeSummaryBuilderTest, AveragePool2D_validate)
67 luci::CircleAveragePool2D node;
68 node.fusedActivationFunction(luci::FusedActFunc::RELU);
69 node.padding(luci::Padding::SAME);
70 EXPECT_TRUE(mock_build(&node));
73 TEST_F(CircleNodeSummaryBuilderTest, AveragePool2D_validate_fused_NEG)
75 luci::CircleAveragePool2D node;
76 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
77 node.padding(luci::Padding::SAME);
78 EXPECT_FALSE(mock_build(&node));
81 TEST_F(CircleNodeSummaryBuilderTest, AveragePool2D_validate_padding_NEG)
83 luci::CircleAveragePool2D node;
84 node.fusedActivationFunction(luci::FusedActFunc::RELU);
85 node.padding(luci::Padding::UNDEFINED);
86 EXPECT_FALSE(mock_build(&node));
89 TEST_F(CircleNodeSummaryBuilderTest, BCQFullyConnected_validate)
91 luci::CircleBCQFullyConnected node;
92 node.fusedActivationFunction(luci::FusedActFunc::RELU);
93 EXPECT_TRUE(mock_build(&node));
96 TEST_F(CircleNodeSummaryBuilderTest, BCQFullyConnected_validate_fused_NEG)
98 luci::CircleBCQFullyConnected node;
99 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
100 EXPECT_FALSE(mock_build(&node));
103 TEST_F(CircleNodeSummaryBuilderTest, Concatenation_validate)
105 luci::CircleConcatenation node(2);
106 node.fusedActivationFunction(luci::FusedActFunc::RELU);
107 EXPECT_TRUE(mock_build(&node));
110 TEST_F(CircleNodeSummaryBuilderTest, Concatenation_validate_fused_NEG)
112 luci::CircleConcatenation node(2);
113 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
114 EXPECT_FALSE(mock_build(&node));
117 TEST_F(CircleNodeSummaryBuilderTest, Conv2D_validate)
119 luci::CircleConv2D node;
120 node.fusedActivationFunction(luci::FusedActFunc::RELU);
121 node.padding(luci::Padding::SAME);
122 EXPECT_TRUE(mock_build(&node));
125 TEST_F(CircleNodeSummaryBuilderTest, Conv2D_validate_fused_NEG)
127 luci::CircleConv2D node;
128 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
129 node.padding(luci::Padding::SAME);
130 EXPECT_FALSE(mock_build(&node));
133 TEST_F(CircleNodeSummaryBuilderTest, Conv2D_validate_padding_NEG)
135 luci::CircleConv2D node;
136 node.fusedActivationFunction(luci::FusedActFunc::RELU);
137 node.padding(luci::Padding::UNDEFINED);
138 EXPECT_FALSE(mock_build(&node));
141 TEST_F(CircleNodeSummaryBuilderTest, DepthwiseConv2D_validate)
143 luci::CircleDepthwiseConv2D node;
144 node.fusedActivationFunction(luci::FusedActFunc::RELU);
145 node.padding(luci::Padding::SAME);
146 EXPECT_TRUE(mock_build(&node));
149 TEST_F(CircleNodeSummaryBuilderTest, DepthwiseConv2D_validate_fused_NEG)
151 luci::CircleDepthwiseConv2D node;
152 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
153 node.padding(luci::Padding::SAME);
154 EXPECT_FALSE(mock_build(&node));
157 TEST_F(CircleNodeSummaryBuilderTest, DepthwiseConv2D_validate_padding_NEG)
159 luci::CircleDepthwiseConv2D node;
160 node.fusedActivationFunction(luci::FusedActFunc::RELU);
161 node.padding(luci::Padding::UNDEFINED);
162 EXPECT_FALSE(mock_build(&node));
165 TEST_F(CircleNodeSummaryBuilderTest, FullyConnected_validate)
167 luci::CircleFullyConnected node;
168 node.fusedActivationFunction(luci::FusedActFunc::RELU);
169 EXPECT_TRUE(mock_build(&node));
172 TEST_F(CircleNodeSummaryBuilderTest, FullyConnected_validate_fused_NEG)
174 luci::CircleFullyConnected node;
175 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
176 EXPECT_FALSE(mock_build(&node));
179 TEST_F(CircleNodeSummaryBuilderTest, InstanceNorm_validate)
181 luci::CircleInstanceNorm node;
182 node.fusedActivationFunction(luci::FusedActFunc::RELU);
183 EXPECT_TRUE(mock_build(&node));
186 TEST_F(CircleNodeSummaryBuilderTest, InstanceNorm_validate_fused_NEG)
188 luci::CircleInstanceNorm node;
189 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
190 EXPECT_FALSE(mock_build(&node));
193 TEST_F(CircleNodeSummaryBuilderTest, L2Normalize_validate)
195 luci::CircleL2Normalize node;
196 node.fusedActivationFunction(luci::FusedActFunc::RELU);
197 EXPECT_TRUE(mock_build(&node));
200 TEST_F(CircleNodeSummaryBuilderTest, L2Normalize_validate_fused_NEG)
202 luci::CircleL2Normalize node;
203 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
204 EXPECT_FALSE(mock_build(&node));
207 TEST_F(CircleNodeSummaryBuilderTest, L2Pool2D_validate)
209 luci::CircleL2Pool2D node;
210 node.fusedActivationFunction(luci::FusedActFunc::RELU);
211 node.padding(luci::Padding::SAME);
212 EXPECT_TRUE(mock_build(&node));
215 TEST_F(CircleNodeSummaryBuilderTest, L2Pool2D_validate_fused_NEG)
217 luci::CircleL2Pool2D node;
218 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
219 node.padding(luci::Padding::SAME);
220 EXPECT_FALSE(mock_build(&node));
223 TEST_F(CircleNodeSummaryBuilderTest, L2Pool2D_validate_padding_NEG)
225 luci::CircleL2Pool2D node;
226 node.fusedActivationFunction(luci::FusedActFunc::RELU);
227 node.padding(luci::Padding::UNDEFINED);
228 EXPECT_FALSE(mock_build(&node));
231 TEST_F(CircleNodeSummaryBuilderTest, MaxPool2D_validate)
233 luci::CircleMaxPool2D node;
234 node.fusedActivationFunction(luci::FusedActFunc::RELU);
235 node.padding(luci::Padding::SAME);
236 EXPECT_TRUE(mock_build(&node));
239 TEST_F(CircleNodeSummaryBuilderTest, MaxPool2D_validate_fused_NEG)
241 luci::CircleMaxPool2D node;
242 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
243 node.padding(luci::Padding::SAME);
244 EXPECT_FALSE(mock_build(&node));
247 TEST_F(CircleNodeSummaryBuilderTest, MaxPool2D_validate_padding_NEG)
249 luci::CircleMaxPool2D node;
250 node.fusedActivationFunction(luci::FusedActFunc::RELU);
251 node.padding(luci::Padding::UNDEFINED);
252 EXPECT_FALSE(mock_build(&node));
255 TEST_F(CircleNodeSummaryBuilderTest, MirrorPad_validate)
257 luci::CircleMirrorPad node;
258 node.mode(luci::MirrorPadMode::REFLECT);
259 EXPECT_TRUE(mock_build(&node));
262 TEST_F(CircleNodeSummaryBuilderTest, MirrorPad_validate_mirror_padding_NEG)
264 luci::CircleMirrorPad node;
265 node.mode(luci::MirrorPadMode::UNDEFINED);
266 EXPECT_FALSE(mock_build(&node));
269 TEST_F(CircleNodeSummaryBuilderTest, Mul_validate)
271 luci::CircleMul node;
272 node.fusedActivationFunction(luci::FusedActFunc::RELU);
273 EXPECT_TRUE(mock_build(&node));
276 TEST_F(CircleNodeSummaryBuilderTest, Mul_validate_fused_NEG)
278 luci::CircleMul node;
279 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
280 EXPECT_FALSE(mock_build(&node));
283 TEST_F(CircleNodeSummaryBuilderTest, SVDF_validate)
285 luci::CircleSVDF node;
286 node.fusedActivationFunction(luci::FusedActFunc::RELU);
287 EXPECT_TRUE(mock_build(&node));
290 TEST_F(CircleNodeSummaryBuilderTest, SVDF_validate_fused_NEG)
292 luci::CircleSVDF node;
293 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
294 EXPECT_FALSE(mock_build(&node));
297 TEST_F(CircleNodeSummaryBuilderTest, TransposeConv_validate)
299 luci::CircleTransposeConv node;
300 node.padding(luci::Padding::SAME);
301 node.fusedActivationFunction(luci::FusedActFunc::RELU);
302 EXPECT_TRUE(mock_build(&node));
305 TEST_F(CircleNodeSummaryBuilderTest, TransposeConv_validate_padding_NEG)
307 luci::CircleTransposeConv node;
308 node.padding(luci::Padding::UNDEFINED);
309 EXPECT_FALSE(mock_build(&node));
312 TEST_F(CircleNodeSummaryBuilderTest, TransposeConv_validate_fused_NEG)
314 luci::CircleTransposeConv node;
315 node.fusedActivationFunction(luci::FusedActFunc::UNDEFINED);
316 EXPECT_FALSE(mock_build(&node));