2 * Copyright (c) 2021 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 "QuantizedModelVerifier.h"
19 #include "luci/Pass/QuantizeWithMinMaxPass.h"
20 #include "luci/Pass/QuantizationParameters.h"
21 #include "luci/Pass/CircleTypeInferencePass.h"
23 #include <logo/Phase.h>
24 #include <luci/test/TestIOGraph.h>
26 #include <gtest/gtest.h>
28 using Type = loco::DataType;
29 using Granularity = luci::QuantizationGranularity;
35 * @brief A helper function to create dummy const node
37 template <Type T> luci::CircleConst *create_dummy_const(loco::Graph *g, luci::test::ShapeU32 shape)
39 auto node = g->nodes()->create<luci::CircleConst>();
43 node->size<T>(luci::test::num_elements(shape));
45 for (int32_t i = 0; i < luci::test::num_elements(shape); i++)
49 // Filling with any random numbers are fine
50 // Q. Should it include minus numbers?
55 node->at<T>(i) = static_cast<float>(i);
59 node->at<T>(i) = (i % 2) ? true : false;
63 node->at<T>(i) = static_cast<uint8_t>(i);
67 node->at<T>(i) = static_cast<int16_t>(i);
79 * @brief A helper function to create const node with value
81 template <Type DT, typename T>
82 luci::CircleConst *create_const(loco::Graph *g, luci::test::ShapeU32 shape,
83 std::initializer_list<T> values)
85 auto node = g->nodes()->create<luci::CircleConst>();
89 node->size<DT>(luci::test::num_elements(shape));
91 assert(values.size() == node->size<DT>());
94 for (auto val : values)
96 node->at<DT>(index++) = static_cast<T>(val);
103 void insert_scale_zp(luci::CircleNode *node, float scale, int64_t zp)
105 auto qparam = node->quantparam();
106 assert(qparam != nullptr); // FIX_CALLER_UNLESS
107 qparam->scale.push_back(scale);
108 qparam->zerop.push_back(zp);
111 void run_phase(loco::Graph *g, Type quantized_dtype, Granularity granularity)
116 phase.emplace_back(std::make_unique<luci::CircleTypeInferencePass>());
118 auto ctx = std::make_unique<luci::QuantizeWithMinMaxPass::Context>();
120 ctx->input_model_dtype = loco::DataType::FLOAT32;
121 ctx->output_model_dtype = quantized_dtype;
122 ctx->granularity = granularity;
123 // Test graph has only one input/output
124 ctx->input_types = {quantized_dtype};
125 ctx->output_types = {quantized_dtype};
128 phase.emplace_back(std::make_unique<luci::QuantizeWithMinMaxPass>(std::move(ctx)));
130 logo::PhaseRunner<logo::PhaseStrategy::Restart> phase_runner{g};
131 phase_runner.run(phase);
134 void run_phase(loco::Graph *g, std::unique_ptr<luci::QuantizeWithMinMaxPass::Context> &&ctx)
139 phase.emplace_back(std::make_unique<luci::CircleTypeInferencePass>());
141 phase.emplace_back(std::make_unique<luci::QuantizeWithMinMaxPass>(std::move(ctx)));
143 logo::PhaseRunner<logo::PhaseStrategy::Restart> phase_runner{g};
144 phase_runner.run(phase);
147 void quantize_and_verify(loco::Graph *g, Type quantized_dtype, Granularity granularity)
149 run_phase(g, quantized_dtype, granularity);
151 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
153 ctx->output_model_dtype = quantized_dtype;
154 ctx->granularity = granularity;
155 // Test graph has only one input/output
156 ctx->input_types = {quantized_dtype};
157 ctx->output_types = {quantized_dtype};
160 luci::QuantizedModelVerifier verifier(std::move(ctx));
164 void quantize_and_verify_with_layer_info(loco::Graph *g, Type quantized_dtype,
165 Granularity granularity)
167 // A layer named "test" has dtype different from quantized_dtype
168 luci::LayerInfo info;
171 // dtype is different from quantized_dtype
172 info.dtype = quantized_dtype == Type::U8 ? Type::S16 : Type::U8;
173 info.granularity = Granularity::ChannelWise;
178 auto ctx = std::make_unique<luci::QuantizeWithMinMaxPass::Context>();
180 ctx->input_model_dtype = Type::FLOAT32;
181 ctx->output_model_dtype = quantized_dtype;
182 ctx->granularity = granularity;
183 // Test graph has only one input/output
184 ctx->input_types = {quantized_dtype};
185 ctx->output_types = {quantized_dtype};
186 ctx->TF_style_maxpool = false;
187 ctx->layers_info.push_back(info);
190 run_phase(g, std::move(ctx));
195 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
197 ctx->output_model_dtype = quantized_dtype;
198 ctx->granularity = granularity;
199 ctx->input_types = {quantized_dtype};
200 ctx->output_types = {quantized_dtype};
201 ctx->TF_style_maxpool = false;
202 ctx->layers_info.push_back(info);
205 luci::QuantizedModelVerifier verifier(std::move(ctx));
210 // Helper function to reduce duplicate test codes
211 // Assumption: g->output()->from() is the target node
212 void quantize_and_verify_with_wrong_type(luci::test::TestIOGraph *g, Type quantized_dtype,
213 Granularity granularity, Type wrong_dtype)
215 run_phase(g->g(), quantized_dtype, granularity);
217 auto node = loco::must_cast<luci::CircleNode *>(g->output()->from());
218 node->dtype(wrong_dtype);
220 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
222 ctx->output_model_dtype = quantized_dtype;
223 ctx->granularity = granularity;
224 // Test graph has only one input/output
225 ctx->input_types = {quantized_dtype};
226 ctx->output_types = {quantized_dtype};
229 luci::QuantizedModelVerifier verifier(std::move(ctx));
230 verifier.verify(g->g());
233 // Helper function to reduce duplicate test codes
234 // Assumption: g->output()->from() is the target node
235 void quantize_and_verify_with_wrong_granularity(luci::test::TestIOGraph *g, Type quantized_dtype,
236 Granularity granularity)
238 run_phase(g->g(), quantized_dtype, granularity);
240 auto node = loco::must_cast<luci::CircleNode *>(g->output()->from());
241 insert_scale_zp(node, 1.0, 1);
243 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
245 ctx->output_model_dtype = quantized_dtype;
246 ctx->granularity = granularity;
247 // Test graph has only one input/output
248 ctx->input_types = {quantized_dtype};
249 ctx->output_types = {quantized_dtype};
252 luci::QuantizedModelVerifier verifier(std::move(ctx));
253 verifier.verify(g->g());
256 // Set min/max for all non-const nodes in the graph
257 void set_minmax_to_non_const(loco::Graph *g, float min, float max)
259 for (auto node : loco::all_nodes(g))
261 auto const_node = dynamic_cast<luci::CircleConst *>(node);
262 if (const_node != nullptr)
265 // Min/Max is not recorded for ArgMax
266 // See MinMaxObserver.cpp in record_minmax module
267 auto argmax_node = dynamic_cast<luci::CircleArgMax *>(node);
268 if (argmax_node != nullptr)
271 // Min/Max is not recorded for Split
272 // See MinMaxObserver.cpp in record_minmax module
273 auto split_node = dynamic_cast<luci::CircleSplit *>(node);
274 if (split_node != nullptr)
277 // Min/Max is not recorded for SplitV
278 // See MinMaxObserver.cpp in record_minmax module
279 auto splitv_node = dynamic_cast<luci::CircleSplitV *>(node);
280 if (splitv_node != nullptr)
283 auto circle_node = loco::must_cast<luci::CircleNode *>(node);
284 auto qparam = std::make_unique<luci::CircleQuantParam>();
286 qparam->min.emplace_back(min);
287 qparam->max.emplace_back(max);
289 circle_node->quantparam(std::move(qparam));
294 * @brief Simple Test Graph
296 * The simple test graph's nodes are initialized with
297 * simple shapes and values.
299 class SimpleTestGraph : public luci::test::TestIOGraph
302 virtual void init(void) = 0;
305 class TypedTestGraph : public luci::test::TestIOGraph
308 void init(Type T, const luci::test::ShapeU32 shape_in, const luci::test::ShapeU32 shape_out)
310 TestIOGraph::init(shape_in, shape_out);
315 g()->inputs()->at(0)->dtype(T);
316 g()->outputs()->at(0)->dtype(T);
320 virtual void init(void) = 0;
323 class InstanceNormTestGraph final : public SimpleTestGraph
326 void init(void) override
328 TestIOGraph::init({32}, {32});
329 _gamma = create_dummy_const<Type::FLOAT32>(g(), {32});
330 _beta = create_dummy_const<Type::FLOAT32>(g(), {32});
331 _instnorm = g()->nodes()->create<luci::CircleInstanceNorm>();
333 _instnorm->input(input());
334 _instnorm->gamma(_gamma);
335 _instnorm->beta(_beta);
336 _instnorm->fusedActivationFunction(luci::FusedActFunc::NONE);
337 _instnorm->name("test");
339 output()->from(_instnorm);
341 set_minmax_to_non_const(g(), -1, 1);
345 loco::Node *gamma(void) const { return _instnorm->gamma(); }
346 loco::Node *beta(void) const { return _instnorm->beta(); }
349 luci::CircleInstanceNorm *_instnorm = nullptr;
350 luci::CircleConst *_input = nullptr;
351 luci::CircleConst *_gamma = nullptr;
352 luci::CircleConst *_beta = nullptr;
355 class LogisticTestGraph final : public SimpleTestGraph
358 void init(void) override
360 TestIOGraph::init({32}, {32});
361 _logistic = g()->nodes()->create<luci::CircleLogistic>();
363 _logistic->x(input());
364 _logistic->name("test");
366 output()->from(_logistic);
368 set_minmax_to_non_const(g(), -1, 1);
372 luci::CircleLogistic *_logistic = nullptr;
375 class LocalResponseNormalizationTestGraph final : public SimpleTestGraph
378 void init(void) override
380 TestIOGraph::init({1, 2, 2, 32}, {1, 2, 2, 32});
381 _lrn = g()->nodes()->create<luci::CircleLocalResponseNormalization>();
383 _lrn->input(input());
386 output()->from(_lrn);
388 set_minmax_to_non_const(g(), -1, 1);
392 luci::CircleLocalResponseNormalization *_lrn = nullptr;
395 class SoftmaxTestGraph final : public SimpleTestGraph
398 void init(void) override
400 TestIOGraph::init({32}, {32});
401 _softmax = g()->nodes()->create<luci::CircleSoftmax>();
403 _softmax->logits(input());
405 _softmax->name("test");
407 output()->from(_softmax);
409 set_minmax_to_non_const(g(), -1, 1);
413 luci::CircleSoftmax *_softmax = nullptr;
416 class SpaceToBatchNDTestGraph final : public SimpleTestGraph
419 void init(void) override
421 TestIOGraph::init({1, 2, 2, 1}, {4, 1, 1, 1});
422 _block_shape = create_dummy_const<Type::S32>(g(), {2});
423 for (uint32_t i = 0; i < 2; i++)
424 _block_shape->at<Type::S32>(i) = 2;
426 _paddings = create_dummy_const<Type::S32>(g(), {2, 2});
427 for (uint32_t i = 0; i < 4; i++)
428 _paddings->at<Type::S32>(i) = 0;
430 _stob = g()->nodes()->create<luci::CircleSpaceToBatchND>();
432 _stob->input(input());
433 _stob->block_shape(_block_shape);
434 _stob->paddings(_paddings);
437 output()->from(_stob);
439 set_minmax_to_non_const(g(), -1, 1);
443 luci::CircleSpaceToBatchND *_stob = nullptr;
444 luci::CircleConst *_block_shape = nullptr;
445 luci::CircleConst *_paddings = nullptr;
448 class SpaceToDepthTestGraph final : public SimpleTestGraph
451 void init(void) override
453 TestIOGraph::init({1, 2, 2, 1}, {1, 1, 1, 4});
454 _stod = g()->nodes()->create<luci::CircleSpaceToDepth>();
456 _stod->input(input());
457 _stod->block_size(2);
460 output()->from(_stod);
462 set_minmax_to_non_const(g(), -1, 1);
466 luci::CircleSpaceToDepth *_stod = nullptr;
469 template <Type indexT> class SliceTestGraph final : public SimpleTestGraph
472 void init(void) override
474 TestIOGraph::init({32}, {32});
475 _begin = g()->nodes()->template create<luci::CircleConst>();
477 _begin->dtype(indexT);
479 _size = g()->nodes()->template create<luci::CircleConst>();
481 _size->dtype(indexT);
483 _slice = g()->nodes()->template create<luci::CircleSlice>();
485 _slice->input(input());
486 _slice->begin(_begin);
488 _slice->name("test");
490 output()->from(_slice);
492 set_minmax_to_non_const(g(), -1, 1);
496 luci::CircleSlice *_slice = nullptr;
497 luci::CircleConst *_begin = nullptr;
498 luci::CircleConst *_size = nullptr;
501 class SplitTestGraph final : public luci::test::TestIOGraph
506 TestIOGraph::init({1, 32}, {32});
507 _split_dim = create_dummy_const<Type::S32>(g(), {1});
508 _split = g()->nodes()->create<luci::CircleSplit>();
510 _split->input(input());
511 _split->split_dim(_split_dim);
513 _split_o1 = g()->nodes()->create<luci::CircleSplitOut>();
515 _split_o1->input(_split);
519 output()->from(_split_o1);
521 set_minmax_to_non_const(g(), -1, 1);
525 luci::CircleSplit *_split = nullptr;
526 luci::CircleSplitOut *_split_o1 = nullptr;
527 luci::CircleConst *_split_dim = nullptr;
530 class SplitVTestGraph final : public luci::test::TestIOGraph
535 TestIOGraph::init({1, 32}, {32});
536 _size_splits = create_dummy_const<Type::S32>(g(), {1});
537 _split_dim = create_dummy_const<Type::S32>(g(), {1});
538 _splitv = g()->nodes()->create<luci::CircleSplitV>();
540 _splitv->input(input());
541 _splitv->size_splits(_size_splits);
542 _splitv->split_dim(_split_dim);
544 _splitv_o1 = g()->nodes()->create<luci::CircleSplitVOut>();
546 _splitv_o1->input(_splitv);
547 _splitv_o1->index(0);
550 output()->from(_splitv_o1);
552 set_minmax_to_non_const(g(), -1, 1);
556 luci::CircleSplitV *_splitv = nullptr;
557 luci::CircleSplitVOut *_splitv_o1 = nullptr;
558 luci::CircleConst *_size_splits = nullptr;
559 luci::CircleConst *_split_dim = nullptr;
562 class StridedSliceTestGraph final : public SimpleTestGraph
565 void init(void) override
567 TestIOGraph::init({32}, {32});
568 _begin = g()->nodes()->create<luci::CircleConst>();
570 _begin->dtype(Type::S32);
572 _end = g()->nodes()->create<luci::CircleConst>();
574 _end->dtype(Type::S32);
576 _strides = g()->nodes()->create<luci::CircleConst>();
578 _strides->dtype(Type::S32);
580 _slice = g()->nodes()->create<luci::CircleStridedSlice>();
582 _slice->input(input());
583 _slice->begin(_begin);
585 _slice->strides(_strides);
586 _slice->name("test");
588 output()->from(_slice);
590 set_minmax_to_non_const(g(), -1, 1);
594 luci::CircleStridedSlice *_slice = nullptr;
595 luci::CircleConst *_begin = nullptr;
596 luci::CircleConst *_end = nullptr;
597 luci::CircleConst *_strides = nullptr;
600 class SumTestGraph final : public SimpleTestGraph
603 void init(void) override
605 TestIOGraph::init({4, 3, 2}, {2});
607 _axis = create_const<Type::S32, int32_t>(g(), {2}, {1, 0});
608 _sum = g()->nodes()->create<luci::CircleSum>();
610 _sum->input(input());
611 _sum->reduction_indices(_axis);
613 _sum->keep_dims(false);
615 output()->from(_sum);
617 set_minmax_to_non_const(g(), -1, 1);
621 luci::CircleSum *_sum = nullptr;
622 luci::CircleConst *_axis = nullptr;
625 class ReshapeTestGraph final : public SimpleTestGraph
628 void init(void) override
630 TestIOGraph::init({32}, {32});
631 _shape = g()->nodes()->create<luci::CircleConst>();
633 _shape->dtype(Type::S32);
635 _reshape = g()->nodes()->create<luci::CircleReshape>();
637 _reshape->tensor(input());
638 _reshape->shape(_shape);
639 _reshape->name("test");
641 output()->from(_reshape);
643 set_minmax_to_non_const(g(), -1, 1);
647 luci::CircleReshape *_reshape = nullptr;
648 luci::CircleConst *_shape = nullptr;
651 class TanhTestGraph final : public SimpleTestGraph
654 void init(void) override
656 TestIOGraph::init({32}, {32});
657 _tanh = g()->nodes()->create<luci::CircleTanh>();
662 output()->from(_tanh);
664 set_minmax_to_non_const(g(), -1, 1);
668 luci::CircleTanh *_tanh = nullptr;
671 class FloorTestGraph final : public SimpleTestGraph
674 void init(void) override
676 TestIOGraph::init({32}, {32});
677 _floor = g()->nodes()->create<luci::CircleFloor>();
680 _floor->name("test");
682 output()->from(_floor);
684 set_minmax_to_non_const(g(), -1, 1);
688 luci::CircleFloor *_floor = nullptr;
691 template <Type indexT> class ArgMaxTestGraph final : public SimpleTestGraph
694 void init(void) override
696 TestIOGraph::init({32}, {1});
697 // output dtype is float by default, but ArgMax should have indexType (s32/s64)
698 output()->dtype(indexT);
699 _dimension = g()->nodes()->template create<luci::CircleConst>();
701 _dimension->dtype(indexT);
703 _argmax = g()->nodes()->template create<luci::CircleArgMax>();
705 _argmax->input(input());
706 _argmax->dimension(_dimension);
707 _argmax->output_type(indexT);
708 _argmax->dtype(indexT);
710 output()->from(_argmax);
712 set_minmax_to_non_const(g(), -1, 1);
714 // Sync output dtype with graph's output dtype
715 g()->outputs()->at(0)->dtype(output()->dtype());
719 // NOTE: Do not override `luci::CircleNode* input(void)` incidentally
720 loco::Node *input_argmax(void) { return _argmax->input(); }
721 loco::Node *dimension(void) { return _argmax->dimension(); }
724 luci::CircleArgMax *_argmax = nullptr;
725 luci::CircleConst *_dimension = nullptr;
728 class BatchToSpaceNDTestGraph final : public SimpleTestGraph
731 void init(void) override
733 TestIOGraph::init({32}, {32});
734 _block_shape = g()->nodes()->create<luci::CircleConst>();
736 _block_shape->dtype(Type::S32);
738 _crops = g()->nodes()->create<luci::CircleConst>();
740 _crops->dtype(Type::S32);
742 _btos = g()->nodes()->create<luci::CircleBatchToSpaceND>();
744 _btos->input(input());
745 _btos->block_shape(_block_shape);
746 _btos->crops(_crops);
749 output()->from(_btos);
751 set_minmax_to_non_const(g(), -1, 1);
755 luci::CircleBatchToSpaceND *_btos = nullptr;
756 luci::CircleConst *_block_shape = nullptr;
757 luci::CircleConst *_crops = nullptr;
760 class DepthToSpaceTestGraph final : public SimpleTestGraph
763 void init(void) override
765 TestIOGraph::init({1, 1, 1, 4}, {1, 2, 2, 1});
766 _dtos = g()->nodes()->create<luci::CircleDepthToSpace>();
768 _dtos->input(input());
769 _dtos->block_size(2);
772 output()->from(_dtos);
774 set_minmax_to_non_const(g(), -1, 1);
778 luci::CircleDepthToSpace *_dtos = nullptr;
781 class PackTestGraph final : public SimpleTestGraph
784 void init(void) override
786 TestIOGraph::init({16}, {32});
787 _param = create_dummy_const<Type::FLOAT32>(g(), {16});
788 _pack = g()->nodes()->create<luci::CirclePack>(2);
790 _pack->values(0, input());
791 _pack->values(1, _param);
795 output()->from(_pack);
797 set_minmax_to_non_const(g(), -1, 1);
799 // Set min/max of the input
800 // pack's qparam will be propagted, overwritten to the input
801 auto input = loco::must_cast<luci::CircleNode *>(pack()->values(0));
802 auto qp = input->quantparam();
808 luci::CirclePack *pack(void) { return _pack; }
811 luci::CirclePack *_pack = nullptr;
812 luci::CircleConst *_param = nullptr;
815 class PadTestGraph final : public SimpleTestGraph
818 void init(void) override
820 TestIOGraph::init({32}, {32});
821 _paddings = g()->nodes()->create<luci::CircleConst>();
823 _paddings->dtype(Type::S32);
825 _pad = g()->nodes()->create<luci::CirclePad>();
827 _pad->input(input());
828 _pad->paddings(_paddings);
831 output()->from(_pad);
833 set_minmax_to_non_const(g(), -1, 1);
837 luci::CirclePad *_pad = nullptr;
838 luci::CircleConst *_paddings = nullptr;
841 class PadV2TestGraph final : public SimpleTestGraph
844 void init(void) override
846 TestIOGraph::init({32}, {32});
847 _paddings = g()->nodes()->create<luci::CircleConst>();
849 _paddings->dtype(Type::S32);
851 _constant_values = create_dummy_const<Type::FLOAT32>(g(), {1});
852 _pad = g()->nodes()->create<luci::CirclePadV2>();
854 _pad->input(input());
855 _pad->paddings(_paddings);
856 _pad->constant_values(_constant_values);
859 output()->from(_pad);
861 set_minmax_to_non_const(g(), -1, 1);
865 luci::CirclePadV2 *_pad = nullptr;
866 luci::CircleConst *_paddings = nullptr;
867 luci::CircleConst *_constant_values = nullptr;
870 class MirrorPadTestGraph final : public SimpleTestGraph
873 void init(void) override
875 TestIOGraph::init({32}, {32});
876 _paddings = g()->nodes()->create<luci::CircleConst>();
878 _paddings->dtype(Type::S32);
880 _constant_values = create_dummy_const<Type::FLOAT32>(g(), {1});
881 _mirror_pad = g()->nodes()->create<luci::CircleMirrorPad>();
883 _mirror_pad->input(input());
884 _mirror_pad->paddings(_paddings);
885 _mirror_pad->mode(luci::MirrorPadMode::REFLECT);
886 _mirror_pad->name("test");
888 output()->from(_mirror_pad);
890 set_minmax_to_non_const(g(), -1, 1);
894 luci::CircleMirrorPad *_mirror_pad = nullptr;
895 luci::CircleConst *_paddings = nullptr;
896 luci::CircleConst *_constant_values = nullptr;
899 class TransposeTestGraph final : public SimpleTestGraph
902 void init(void) override
904 TestIOGraph::init({32}, {32});
905 _perm = g()->nodes()->create<luci::CircleConst>();
907 _perm->dtype(Type::S32);
909 _transpose = g()->nodes()->create<luci::CircleTranspose>();
911 _transpose->a(input());
912 _transpose->perm(_perm);
913 _transpose->name("test");
915 output()->from(_transpose);
917 set_minmax_to_non_const(g(), -1, 1);
921 luci::CircleTranspose *_transpose = nullptr;
922 luci::CircleConst *_perm = nullptr;
925 class ConcatenationTestGraph final : public SimpleTestGraph
928 void init(void) override
930 TestIOGraph::init({16}, {32});
931 _param = create_dummy_const<Type::FLOAT32>(g(), {16});
932 _concat = g()->nodes()->create<luci::CircleConcatenation>(2);
934 _concat->values(0, input());
935 _concat->values(1, _param);
937 _concat->fusedActivationFunction(luci::FusedActFunc::NONE);
938 _concat->name("test");
940 output()->from(_concat);
942 set_minmax_to_non_const(g(), -1, 1);
946 luci::CircleConcatenation *_concat = nullptr;
947 luci::CircleConst *_param = nullptr;
950 template <Type indexT> class OneHotTestGraph final : public SimpleTestGraph
953 void init(void) override
955 TestIOGraph::init({32}, {32, 10});
957 // input dtype is float by default, but OneHot's input should have indexType (s32/s64)
958 input()->dtype(indexT);
961 _depth = g()->nodes()->template create<luci::CircleConst>();
963 _depth->dtype(loco::DataType::S32);
966 _on_value = g()->nodes()->template create<luci::CircleConst>();
968 _on_value->dtype(loco::DataType::FLOAT32);
971 _off_value = g()->nodes()->template create<luci::CircleConst>();
973 _off_value->dtype(loco::DataType::FLOAT32);
976 _one_hot = g()->nodes()->template create<luci::CircleOneHot>();
978 _one_hot->indices(input());
979 _one_hot->depth(_depth);
980 _one_hot->on_value(_on_value);
981 _one_hot->off_value(_off_value);
983 _one_hot->dtype(loco::DataType::FLOAT32);
984 _one_hot->name("test");
986 output()->from(_one_hot);
988 set_minmax_to_non_const(g(), -1, 1);
992 luci::CircleOneHot *_one_hot = nullptr;
993 luci::CircleConst *_depth = nullptr;
994 luci::CircleConst *_on_value = nullptr;
995 luci::CircleConst *_off_value = nullptr;
998 // Test graph for comparison Ops
999 // GREATER, GREATER_EQUAL, LESS, LESS_EQUAL, EQUAL, NOT_EQUAL
1000 template <class Op> class ComparisonOpTestGraph final : public SimpleTestGraph
1003 void init(void) override
1005 TestIOGraph::init({32}, {32});
1006 output()->dtype(loco::DataType::BOOL);
1007 _y = create_dummy_const<Type::FLOAT32>(g(), {32});
1008 _op = g()->nodes()->template create<Op>();
1012 _op->dtype(loco::DataType::BOOL);
1014 output()->from(_op);
1016 set_minmax_to_non_const(g(), -1, 1);
1018 // Sync output dtype with graph's output dtype
1019 g()->outputs()->at(0)->dtype(output()->dtype());
1022 loco::Node *x(void) const { return _op->x(); }
1023 loco::Node *y(void) const { return _op->y(); }
1027 luci::CircleConst *_y = nullptr;
1030 // Test graph for binary logical Ops
1031 // LOGICAL_OR, LOGICAL_AND
1032 template <class Op> class BinaryLogicalOpTestGraph final : public SimpleTestGraph
1035 void init(void) override
1037 TestIOGraph::init({32}, {32});
1038 input()->dtype(loco::DataType::BOOL);
1039 output()->dtype(loco::DataType::BOOL);
1040 _y = create_dummy_const<Type::BOOL>(g(), {32});
1041 _op = g()->nodes()->template create<Op>();
1045 _op->dtype(loco::DataType::BOOL);
1047 output()->from(_op);
1049 set_minmax_to_non_const(g(), -1, 1);
1051 // Sync output dtype with graph's output dtype
1052 g()->outputs()->at(0)->dtype(output()->dtype());
1055 loco::Node *x(void) const { return _op->x(); }
1056 loco::Node *y(void) const { return _op->y(); }
1060 luci::CircleConst *_y = nullptr;
1063 class DivTestGraph final : public SimpleTestGraph
1066 void init(void) override
1068 TestIOGraph::init({32}, {32});
1070 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1071 _div = g()->nodes()->create<luci::CircleDiv>();
1077 output()->from(_div);
1079 set_minmax_to_non_const(g(), -1, 1);
1082 loco::Node *x() { return _div->x(); }
1084 loco::Node *y() { return _div->y(); }
1087 luci::CircleDiv *_div = nullptr;
1088 luci::CircleConst *_const = nullptr;
1091 class FloorDivTestGraph final : public SimpleTestGraph
1094 void init(void) override
1096 TestIOGraph::init({32}, {32});
1098 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1099 _floor_div = g()->nodes()->create<luci::CircleFloorDiv>();
1101 _floor_div->x(input());
1102 _floor_div->y(_const);
1103 _floor_div->name("test");
1105 output()->from(_floor_div);
1107 set_minmax_to_non_const(g(), -1, 1);
1110 loco::Node *x() { return _floor_div->x(); }
1112 loco::Node *y() { return _floor_div->y(); }
1115 luci::CircleFloorDiv *_floor_div = nullptr;
1116 luci::CircleConst *_const = nullptr;
1119 class RsqrtTestGraph final : public SimpleTestGraph
1122 void init(void) override
1124 TestIOGraph::init({32}, {32});
1125 _rsqrt = g()->nodes()->create<luci::CircleRsqrt>();
1128 _rsqrt->name("test");
1130 output()->from(_rsqrt);
1132 set_minmax_to_non_const(g(), -1, 1);
1136 luci::CircleRsqrt *_rsqrt = nullptr;
1139 class SqrtTestGraph final : public SimpleTestGraph
1142 void init(void) override
1144 TestIOGraph::init({32}, {32});
1145 _sqrt = g()->nodes()->create<luci::CircleSqrt>();
1148 _sqrt->name("test");
1150 output()->from(_sqrt);
1152 set_minmax_to_non_const(g(), -1, 1);
1156 luci::CircleSqrt *_sqrt = nullptr;
1159 class EluTestGraph final : public SimpleTestGraph
1162 void init(void) override
1164 TestIOGraph::init({32}, {32});
1165 _elu = g()->nodes()->create<luci::CircleElu>();
1167 _elu->features(input());
1170 output()->from(_elu);
1172 set_minmax_to_non_const(g(), -1, 1);
1176 luci::CircleElu *_elu = nullptr;
1179 class PowTestGraph final : public SimpleTestGraph
1182 void init(void) override
1184 TestIOGraph::init({32}, {32});
1186 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1187 _pow = g()->nodes()->create<luci::CirclePow>();
1193 output()->from(_pow);
1195 set_minmax_to_non_const(g(), -1, 1);
1198 loco::Node *x() { return _pow->x(); }
1200 loco::Node *y() { return _pow->y(); }
1203 luci::CirclePow *_pow = nullptr;
1204 luci::CircleConst *_const = nullptr;
1207 class ReduceMaxTestGraph final : public SimpleTestGraph
1210 void init(void) override
1212 TestIOGraph::init({4, 3, 2}, {2});
1214 _axis = create_const<Type::S32, int32_t>(g(), {4}, {1, 0, -3, -3});
1215 _reduce_max = g()->nodes()->create<luci::CircleReduceMax>();
1217 _reduce_max->input(input());
1218 _reduce_max->reduction_indices(_axis);
1219 _reduce_max->name("test");
1220 _reduce_max->keep_dims(false);
1222 output()->from(_reduce_max);
1224 set_minmax_to_non_const(g(), -1, 1);
1228 luci::CircleReduceMax *_reduce_max = nullptr;
1229 luci::CircleConst *_axis = nullptr;
1232 class ResizeBilinearTestGraph final : public SimpleTestGraph
1235 void init(void) override
1237 TestIOGraph::init({1, 4, 4, 1}, {1, 8, 8, 1});
1239 _size = create_const<Type::S32, int32_t>(g(), {2}, {8, 8});
1240 _resize_bilinear = g()->nodes()->create<luci::CircleResizeBilinear>();
1242 _resize_bilinear->input(input());
1243 _resize_bilinear->size(_size);
1244 _resize_bilinear->name("test");
1246 output()->from(_resize_bilinear);
1248 set_minmax_to_non_const(g(), -1, 1);
1252 luci::CircleResizeBilinear *_resize_bilinear = nullptr;
1253 luci::CircleConst *_size = nullptr;
1256 class ResizeNearestNeighborTestGraph final : public luci::test::TestIOGraph
1261 TestIOGraph::init({1, 4, 4, 1}, {1, 8, 8, 1});
1263 _size = create_const<Type::S32, int32_t>(g(), {2}, {8, 8});
1264 _resize_nearest_neighbor = g()->nodes()->create<luci::CircleResizeNearestNeighbor>();
1266 _resize_nearest_neighbor->input(input());
1267 _resize_nearest_neighbor->size(_size);
1268 _resize_nearest_neighbor->name("test");
1270 output()->from(_resize_nearest_neighbor);
1272 set_minmax_to_non_const(g(), -1, 1);
1276 luci::CircleResizeNearestNeighbor *_resize_nearest_neighbor = nullptr;
1277 luci::CircleConst *_size = nullptr;
1280 class UnpackTestGraph final : public luci::test::TestIOGraph
1285 TestIOGraph::init({1, 32}, {32});
1286 _unpack = g()->nodes()->create<luci::CircleUnpack>();
1288 _unpack->value(input());
1292 _unpack_o1 = g()->nodes()->create<luci::CircleUnpackOut>();
1294 _unpack_o1->input(_unpack);
1295 _unpack_o1->index(0);
1298 output()->from(_unpack_o1);
1300 set_minmax_to_non_const(g(), -1, 1);
1304 luci::CircleUnpack *_unpack = nullptr;
1305 luci::CircleUnpackOut *_unpack_o1 = nullptr;
1306 luci::CircleConst *_unpack_dim = nullptr;
1309 class MulTestGraph final : public SimpleTestGraph
1312 void init(void) override
1314 TestIOGraph::init({32}, {32});
1316 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1317 _mul = g()->nodes()->create<luci::CircleMul>();
1321 _mul->fusedActivationFunction(luci::FusedActFunc::NONE);
1324 output()->from(_mul);
1326 set_minmax_to_non_const(g(), -1, 1);
1329 loco::Node *x() { return _mul->x(); }
1330 loco::Node *y() { return _mul->y(); }
1333 luci::CircleMul *_mul = nullptr;
1334 luci::CircleConst *_const = nullptr;
1337 template <Type T> class IntMulTestGraph final : public TypedTestGraph
1340 void init(void) override
1342 TypedTestGraph::init(T, {32}, {32});
1344 _const = create_dummy_const<T>(g(), {32});
1345 _mul = g()->nodes()->template create<luci::CircleMul>();
1349 _mul->fusedActivationFunction(luci::FusedActFunc::NONE);
1353 output()->from(_mul);
1356 loco::Node *x() { return _mul->x(); }
1357 loco::Node *y() { return _mul->y(); }
1360 luci::CircleMul *_mul = nullptr;
1361 luci::CircleConst *_const = nullptr;
1364 class AddTestGraph final : public SimpleTestGraph
1367 void init(void) override
1369 TestIOGraph::init({32}, {32});
1371 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1372 _add = g()->nodes()->create<luci::CircleAdd>();
1376 _add->fusedActivationFunction(luci::FusedActFunc::NONE);
1379 output()->from(_add);
1381 set_minmax_to_non_const(g(), -1, 1);
1384 loco::Node *x() { return _add->x(); }
1385 loco::Node *y() { return _add->y(); }
1388 luci::CircleAdd *_add = nullptr;
1389 luci::CircleConst *_const = nullptr;
1392 template <Type T> class IntAddTestGraph final : public TypedTestGraph
1395 void init(void) override
1397 TypedTestGraph::init(T, {32}, {32});
1399 _const = create_dummy_const<T>(g(), {32});
1400 _add = g()->nodes()->template create<luci::CircleAdd>();
1404 _add->fusedActivationFunction(luci::FusedActFunc::NONE);
1408 output()->from(_add);
1411 loco::Node *x() { return _add->x(); }
1412 loco::Node *y() { return _add->y(); }
1415 luci::CircleAdd *_add = nullptr;
1416 luci::CircleConst *_const = nullptr;
1421 // Quantize and verify with given configurations
1422 #define TEST_WITH_GRAPH(graph, type, granularity) \
1427 EXPECT_NO_THROW(quantize_and_verify(g.g(), type, granularity)); \
1430 // Quantize and verify with layer info
1431 #define TEST_WITH_LAYER_INFO(graph, type, granularity) \
1436 EXPECT_NO_THROW(quantize_and_verify_with_layer_info(g.g(), type, granularity)); \
1439 // Quantize and verify with wrong type
1440 #define TEST_WITH_WRONG_TYPE(graph, type, granularity, wrong_dtype) \
1445 EXPECT_ANY_THROW(quantize_and_verify_with_wrong_type(&g, type, granularity, wrong_dtype)); \
1448 // Quantize and verify with wrong granularity
1449 #define TEST_WITH_WRONG_GRANULARITY(graph, type, granularity) \
1454 EXPECT_ANY_THROW(quantize_and_verify_with_wrong_granularity(&g, type, granularity)); \
1457 // Quantize and verify with wrong type
1458 // Users can specify the test target
1459 #define TEST_WITH_WRONG_TYPE_TARGET(graph, type, granularity_, wrong_dtype, target) \
1464 auto node = loco::must_cast<luci::CircleNode *>(target); \
1465 run_phase(g.g(), type, granularity_); \
1466 auto after_node = loco::must_cast<luci::CircleNode *>(target); \
1467 after_node->dtype(wrong_dtype); \
1468 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>(); \
1470 ctx->output_model_dtype = type; \
1471 ctx->granularity = granularity_; \
1472 ctx->input_types = {type}; \
1473 ctx->output_types = {type}; \
1475 luci::QuantizedModelVerifier verifier(std::move(ctx)); \
1476 EXPECT_ANY_THROW(verifier.verify(g.g())); \
1479 // Quantize and verify with wrong granularity
1480 // Users can specify the test target
1481 #define TEST_WITH_WRONG_GRANULARITY_TARGET(graph, type, granularity_, target) \
1486 auto node = loco::must_cast<luci::CircleNode *>(target); \
1487 run_phase(g.g(), type, granularity_); \
1488 auto after_node = loco::must_cast<luci::CircleNode *>(target); \
1489 insert_scale_zp(after_node, 1.0, 1); \
1490 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>(); \
1492 ctx->output_model_dtype = type; \
1493 ctx->granularity = granularity_; \
1494 ctx->input_types = {type}; \
1495 ctx->output_types = {type}; \
1497 luci::QuantizedModelVerifier verifier(std::move(ctx)); \
1498 EXPECT_ANY_THROW(verifier.verify(g.g())); \
1501 // Test a local helper function
1502 TEST(QuantizedModelVerifierTest, LocalCreateDummyConst)
1506 EXPECT_NO_THROW(create_dummy_const<Type::FLOAT32>(&g, {32, 32}));
1509 TEST(QuantizedModelVerifierTest, LocalCreateConst)
1512 std::initializer_list<float> values = {0.1, 0, -5, 100};
1513 luci::CircleConst *node = create_const<Type::FLOAT32, float>(&g, {2, 2}, values);
1516 for (auto val : values)
1518 EXPECT_EQ(node->at<Type::FLOAT32>(index++), val);
1522 TEST(QuantizedModelVerifierTest, InstanceNorm)
1524 TEST_WITH_GRAPH(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1525 TEST_WITH_GRAPH(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1526 TEST_WITH_GRAPH(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1528 TEST_WITH_LAYER_INFO(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1529 TEST_WITH_LAYER_INFO(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1530 TEST_WITH_LAYER_INFO(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1534 TEST(QuantizedModelVerifierTest, InstanceNorm_wrong_type_NEG)
1536 TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1537 TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1538 TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1542 TEST(QuantizedModelVerifierTest, InstanceNorm_wrong_granularity_NEG)
1544 TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1545 TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1546 TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1550 TEST(QuantizedModelVerifierTest, LocalResponseNormalization)
1552 TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise);
1553 TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise);
1554 TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise);
1556 TEST_WITH_LAYER_INFO(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise);
1557 TEST_WITH_LAYER_INFO(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise);
1558 TEST_WITH_LAYER_INFO(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise);
1562 TEST(QuantizedModelVerifierTest, LocalResponseNormalization_wrong_type_NEG)
1564 TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise,
1566 TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise,
1568 TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise,
1573 TEST(QuantizedModelVerifierTest, LocalResponseNormalization_wrong_granularity_NEG)
1575 TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::U8,
1576 Granularity::LayerWise);
1577 TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::U8,
1578 Granularity::ChannelWise);
1579 TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::S16,
1580 Granularity::ChannelWise);
1584 TEST(QuantizedModelVerifierTest, Logistic)
1586 TEST_WITH_GRAPH(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1587 TEST_WITH_GRAPH(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1588 TEST_WITH_GRAPH(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1590 TEST_WITH_LAYER_INFO(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1591 TEST_WITH_LAYER_INFO(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1592 TEST_WITH_LAYER_INFO(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1596 TEST(QuantizedModelVerifierTest, Logistic_wrong_type_NEG)
1598 TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1599 TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1600 TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1604 TEST(QuantizedModelVerifierTest, Logistic_wrong_granularity_NEG)
1606 TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1607 TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1608 TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1612 TEST(QuantizedModelVerifierTest, Softmax)
1614 TEST_WITH_GRAPH(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1615 TEST_WITH_GRAPH(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1616 TEST_WITH_GRAPH(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1618 TEST_WITH_LAYER_INFO(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1619 TEST_WITH_LAYER_INFO(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1620 TEST_WITH_LAYER_INFO(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1624 TEST(QuantizedModelVerifierTest, Softmax_wrong_type_NEG)
1626 TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1627 TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1628 TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1632 TEST(QuantizedModelVerifierTest, Softmax_wrong_granularity_NEG)
1634 TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1635 TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1636 TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1640 TEST(QuantizedModelVerifierTest, SpaceToBatchND)
1642 TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1643 TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1644 TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1646 TEST_WITH_LAYER_INFO(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1647 TEST_WITH_LAYER_INFO(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1648 TEST_WITH_LAYER_INFO(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1652 TEST(QuantizedModelVerifierTest, SpaceToBatchND_wrong_type_NEG)
1654 TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1655 TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1656 TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1660 TEST(QuantizedModelVerifierTest, SpaceToBatchND_wrong_granularity_NEG)
1662 TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1663 TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1664 TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1668 TEST(QuantizedModelVerifierTest, SpaceToDepth)
1670 TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1671 TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1672 TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1674 TEST_WITH_LAYER_INFO(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1675 TEST_WITH_LAYER_INFO(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1676 TEST_WITH_LAYER_INFO(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1680 TEST(QuantizedModelVerifierTest, SpaceToDepth_wrong_type_NEG)
1682 TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1683 TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1684 TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1688 TEST(QuantizedModelVerifierTest, SpaceToDepth_wrong_granularity_NEG)
1690 TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1691 TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1692 TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1696 TEST(QuantizedModelVerifierTest, Slice)
1698 TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1699 TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1700 TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1702 TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1703 TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1704 TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1706 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1707 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1708 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1710 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1711 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1712 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1716 TEST(QuantizedModelVerifierTest, Slice_wrong_type_NEG)
1718 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
1719 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
1720 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
1722 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
1723 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
1724 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
1728 TEST(QuantizedModelVerifierTest, Slice_wrong_granularity_NEG)
1730 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1731 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1732 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1734 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1735 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1736 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1740 TEST(QuantizedModelVerifierTest, Split)
1742 TEST_WITH_GRAPH(SplitTestGraph, Type::U8, Granularity::LayerWise);
1743 TEST_WITH_GRAPH(SplitTestGraph, Type::U8, Granularity::ChannelWise);
1744 TEST_WITH_GRAPH(SplitTestGraph, Type::S16, Granularity::ChannelWise);
1748 TEST(QuantizedModelVerifierTest, Split_wrong_type_NEG)
1750 TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1751 TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1752 TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1756 TEST(QuantizedModelVerifierTest, Split_wrong_granularity_NEG)
1758 TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::U8, Granularity::LayerWise);
1759 TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::U8, Granularity::ChannelWise);
1760 TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::S16, Granularity::ChannelWise);
1764 TEST(QuantizedModelVerifierTest, SplitV)
1766 TEST_WITH_GRAPH(SplitVTestGraph, Type::U8, Granularity::LayerWise);
1767 TEST_WITH_GRAPH(SplitVTestGraph, Type::U8, Granularity::ChannelWise);
1768 TEST_WITH_GRAPH(SplitVTestGraph, Type::S16, Granularity::ChannelWise);
1772 TEST(QuantizedModelVerifierTest, SplitV_wrong_type_NEG)
1774 TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1775 TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1776 TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1780 TEST(QuantizedModelVerifierTest, SplitV_wrong_granularity_NEG)
1782 TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::U8, Granularity::LayerWise);
1783 TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::U8, Granularity::ChannelWise);
1784 TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::S16, Granularity::ChannelWise);
1788 TEST(QuantizedModelVerifierTest, StridedSlice)
1790 TEST_WITH_GRAPH(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1791 TEST_WITH_GRAPH(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1792 TEST_WITH_GRAPH(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1794 TEST_WITH_LAYER_INFO(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1795 TEST_WITH_LAYER_INFO(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1796 TEST_WITH_LAYER_INFO(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1800 TEST(QuantizedModelVerifierTest, StridedSlice_wrong_type_NEG)
1802 TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1803 TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1804 TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1808 TEST(QuantizedModelVerifierTest, StridedSlice_wrong_granularity_NEG)
1810 TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1811 TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1812 TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1816 TEST(QuantizedModelVerifierTest, Sum)
1818 TEST_WITH_GRAPH(SumTestGraph, Type::U8, Granularity::LayerWise);
1819 TEST_WITH_GRAPH(SumTestGraph, Type::U8, Granularity::ChannelWise);
1820 TEST_WITH_GRAPH(SumTestGraph, Type::S16, Granularity::ChannelWise);
1822 TEST_WITH_LAYER_INFO(SumTestGraph, Type::U8, Granularity::LayerWise);
1823 TEST_WITH_LAYER_INFO(SumTestGraph, Type::U8, Granularity::ChannelWise);
1824 TEST_WITH_LAYER_INFO(SumTestGraph, Type::S16, Granularity::ChannelWise);
1828 TEST(QuantizedModelVerifierTest, Sum_wrong_type_NEG)
1830 TEST_WITH_WRONG_TYPE(SumTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1831 TEST_WITH_WRONG_TYPE(SumTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1832 TEST_WITH_WRONG_TYPE(SumTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1836 TEST(QuantizedModelVerifierTest, Sum_wrong_granularity_NEG)
1838 TEST_WITH_WRONG_GRANULARITY(SumTestGraph, Type::U8, Granularity::LayerWise);
1839 TEST_WITH_WRONG_GRANULARITY(SumTestGraph, Type::U8, Granularity::ChannelWise);
1840 TEST_WITH_WRONG_GRANULARITY(SumTestGraph, Type::S16, Granularity::ChannelWise);
1844 TEST(QuantizedModelVerifierTest, ArgMax)
1846 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1847 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1848 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1850 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1851 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1852 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1856 TEST(QuantizedModelVerifierTest, ArgMax_wrong_input_type_NEG)
1858 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
1859 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
1860 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
1862 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
1863 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
1864 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
1868 TEST(QuantizedModelVerifierTest, ArgMax_wrong_dimension_type_NEG)
1870 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise,
1871 Type::S16, g.dimension());
1872 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise,
1873 Type::S16, g.dimension());
1874 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise,
1875 Type::U8, g.dimension());
1877 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise,
1878 Type::S16, g.dimension());
1879 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise,
1880 Type::S16, g.dimension());
1881 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise,
1882 Type::U8, g.dimension());
1886 TEST(QuantizedModelVerifierTest, ArgMax_wrong_granularity_NEG)
1888 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise,
1890 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise,
1892 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::S16,
1893 Granularity::ChannelWise, g.input_argmax());
1895 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise,
1897 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise,
1899 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::S16,
1900 Granularity::ChannelWise, g.input_argmax());
1904 TEST(QuantizedModelVerifierTest, BatchToSpaceND)
1906 TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1907 TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1908 TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1910 TEST_WITH_LAYER_INFO(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1911 TEST_WITH_LAYER_INFO(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1912 TEST_WITH_LAYER_INFO(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1916 TEST(QuantizedModelVerifierTest, BatchToSpaceND_wrong_type_NEG)
1918 TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1919 TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1920 TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1924 TEST(QuantizedModelVerifierTest, BatchToSpaceND_wrong_granularity_NEG)
1926 TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1927 TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1928 TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1932 TEST(QuantizedModelVerifierTest, DepthToSpace)
1934 TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1935 TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1936 TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1938 TEST_WITH_LAYER_INFO(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1939 TEST_WITH_LAYER_INFO(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1940 TEST_WITH_LAYER_INFO(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1944 TEST(QuantizedModelVerifierTest, DepthToSpace_wrong_type_NEG)
1946 TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1947 TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1948 TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1952 TEST(QuantizedModelVerifierTest, DepthToSpace_wrong_granularity_NEG)
1954 TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1955 TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1956 TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1960 TEST(QuantizedModelVerifierTest, Concatenation)
1962 TEST_WITH_GRAPH(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1963 TEST_WITH_GRAPH(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1964 TEST_WITH_GRAPH(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1966 TEST_WITH_LAYER_INFO(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1967 TEST_WITH_LAYER_INFO(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1968 TEST_WITH_LAYER_INFO(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1972 TEST(QuantizedModelVerifierTest, Concatenation_wrong_type_NEG)
1974 TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1975 TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1976 TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1980 TEST(QuantizedModelVerifierTest, Concatenation_wrong_granularity_NEG)
1982 TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1983 TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1984 TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1988 TEST(QuantizedModelVerifierTest, LogicalOr)
1990 TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1991 Granularity::LayerWise);
1992 TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1993 Granularity::ChannelWise);
1994 TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::S16,
1995 Granularity::ChannelWise);
1999 TEST(QuantizedModelVerifierTest, LogicalOr_wrong_type_NEG)
2001 TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
2002 Granularity::LayerWise, Type::U8);
2003 TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
2004 Granularity::ChannelWise, Type::U8);
2005 TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::S16,
2006 Granularity::ChannelWise, Type::S16);
2010 TEST(QuantizedModelVerifierTest, Reshape)
2012 TEST_WITH_GRAPH(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
2013 TEST_WITH_GRAPH(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
2014 TEST_WITH_GRAPH(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
2016 TEST_WITH_LAYER_INFO(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
2017 TEST_WITH_LAYER_INFO(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
2018 TEST_WITH_LAYER_INFO(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
2022 TEST(QuantizedModelVerifierTest, Reshape_wrong_type_NEG)
2024 TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2025 TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2026 TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2030 TEST(QuantizedModelVerifierTest, Reshape_wrong_granularity_NEG)
2032 TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
2033 TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
2034 TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
2038 TEST(QuantizedModelVerifierTest, Tanh)
2040 TEST_WITH_GRAPH(TanhTestGraph, Type::U8, Granularity::LayerWise);
2041 TEST_WITH_GRAPH(TanhTestGraph, Type::U8, Granularity::ChannelWise);
2042 TEST_WITH_GRAPH(TanhTestGraph, Type::S16, Granularity::ChannelWise);
2044 TEST_WITH_LAYER_INFO(TanhTestGraph, Type::U8, Granularity::LayerWise);
2045 TEST_WITH_LAYER_INFO(TanhTestGraph, Type::U8, Granularity::ChannelWise);
2046 TEST_WITH_LAYER_INFO(TanhTestGraph, Type::S16, Granularity::ChannelWise);
2050 TEST(QuantizedModelVerifierTest, Tanh_wrong_type_NEG)
2052 TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2053 TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2054 TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2058 TEST(QuantizedModelVerifierTest, Tanh_wrong_granularity_NEG)
2060 TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::U8, Granularity::LayerWise);
2061 TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::U8, Granularity::ChannelWise);
2062 TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::S16, Granularity::ChannelWise);
2066 TEST(QuantizedModelVerifierTest, Pack)
2068 TEST_WITH_GRAPH(PackTestGraph, Type::U8, Granularity::LayerWise);
2069 TEST_WITH_GRAPH(PackTestGraph, Type::U8, Granularity::ChannelWise);
2070 TEST_WITH_GRAPH(PackTestGraph, Type::S16, Granularity::ChannelWise);
2072 TEST_WITH_LAYER_INFO(PackTestGraph, Type::U8, Granularity::LayerWise);
2073 TEST_WITH_LAYER_INFO(PackTestGraph, Type::U8, Granularity::ChannelWise);
2074 TEST_WITH_LAYER_INFO(PackTestGraph, Type::S16, Granularity::ChannelWise);
2076 // Test if Pack's qparam is propagated to the input
2080 quantize_and_verify(g.g(), Type::U8, Granularity::ChannelWise);
2081 auto input = loco::must_cast<luci::CircleNode *>(g.pack()->values(0));
2082 auto qp = input->quantparam();
2083 EXPECT_FLOAT_EQ(2.0 / 255.0, qp->scale[0]);
2084 EXPECT_FLOAT_EQ(128, qp->zerop[0]);
2089 TEST(QuantizedModelVerifierTest, Pack_wrong_type_NEG)
2091 TEST_WITH_WRONG_TYPE(PackTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2092 TEST_WITH_WRONG_TYPE(PackTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2093 TEST_WITH_WRONG_TYPE(PackTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2097 TEST(QuantizedModelVerifierTest, Pack_wrong_granularity_NEG)
2099 TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::U8, Granularity::LayerWise);
2100 TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::U8, Granularity::ChannelWise);
2101 TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::S16, Granularity::ChannelWise);
2105 TEST(QuantizedModelVerifierTest, Pad)
2107 TEST_WITH_GRAPH(PadTestGraph, Type::U8, Granularity::LayerWise);
2108 TEST_WITH_GRAPH(PadTestGraph, Type::U8, Granularity::ChannelWise);
2109 TEST_WITH_GRAPH(PadTestGraph, Type::S16, Granularity::ChannelWise);
2111 TEST_WITH_LAYER_INFO(PadTestGraph, Type::U8, Granularity::LayerWise);
2112 TEST_WITH_LAYER_INFO(PadTestGraph, Type::U8, Granularity::ChannelWise);
2113 TEST_WITH_LAYER_INFO(PadTestGraph, Type::S16, Granularity::ChannelWise);
2117 TEST(QuantizedModelVerifierTest, Pad_wrong_type_NEG)
2119 TEST_WITH_WRONG_TYPE(PadTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2120 TEST_WITH_WRONG_TYPE(PadTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2121 TEST_WITH_WRONG_TYPE(PadTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2125 TEST(QuantizedModelVerifierTest, Pad_wrong_granularity_NEG)
2127 TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::U8, Granularity::LayerWise);
2128 TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::U8, Granularity::ChannelWise);
2129 TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::S16, Granularity::ChannelWise);
2133 TEST(QuantizedModelVerifierTest, PadV2)
2135 TEST_WITH_GRAPH(PadV2TestGraph, Type::U8, Granularity::LayerWise);
2136 TEST_WITH_GRAPH(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
2137 TEST_WITH_GRAPH(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
2139 TEST_WITH_LAYER_INFO(PadV2TestGraph, Type::U8, Granularity::LayerWise);
2140 TEST_WITH_LAYER_INFO(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
2141 TEST_WITH_LAYER_INFO(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
2145 TEST(QuantizedModelVerifierTest, PadV2_wrong_type_NEG)
2147 TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2148 TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2149 TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2153 TEST(QuantizedModelVerifierTest, PadV2_wrong_granularity_NEG)
2155 TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::U8, Granularity::LayerWise);
2156 TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
2157 TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
2161 TEST(QuantizedModelVerifierTest, MirrorPad)
2163 TEST_WITH_GRAPH(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
2164 TEST_WITH_GRAPH(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
2165 TEST_WITH_GRAPH(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
2167 TEST_WITH_LAYER_INFO(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
2168 TEST_WITH_LAYER_INFO(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
2169 TEST_WITH_LAYER_INFO(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
2173 TEST(QuantizedModelVerifierTest, MirrorPad_wrong_type_NEG)
2175 TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2176 TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2177 TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2181 TEST(QuantizedModelVerifierTest, MirrorPad_wrong_granularity_NEG)
2183 TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
2184 TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
2185 TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
2189 TEST(QuantizedModelVerifierTest, Transpose)
2191 TEST_WITH_GRAPH(TransposeTestGraph, Type::U8, Granularity::LayerWise);
2192 TEST_WITH_GRAPH(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
2193 TEST_WITH_GRAPH(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
2195 TEST_WITH_LAYER_INFO(TransposeTestGraph, Type::U8, Granularity::LayerWise);
2196 TEST_WITH_LAYER_INFO(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
2197 TEST_WITH_LAYER_INFO(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
2201 TEST(QuantizedModelVerifierTest, Transpose_wrong_type_NEG)
2203 TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2204 TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2205 TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2209 TEST(QuantizedModelVerifierTest, Transpose_wrong_granularity_NEG)
2211 TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::U8, Granularity::LayerWise);
2212 TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
2213 TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
2217 TEST(QuantizedModelVerifierTest, Floor)
2219 TEST_WITH_GRAPH(FloorTestGraph, Type::U8, Granularity::LayerWise);
2220 TEST_WITH_GRAPH(FloorTestGraph, Type::U8, Granularity::ChannelWise);
2221 TEST_WITH_GRAPH(FloorTestGraph, Type::S16, Granularity::ChannelWise);
2223 TEST_WITH_LAYER_INFO(FloorTestGraph, Type::U8, Granularity::LayerWise);
2224 TEST_WITH_LAYER_INFO(FloorTestGraph, Type::U8, Granularity::ChannelWise);
2225 TEST_WITH_LAYER_INFO(FloorTestGraph, Type::S16, Granularity::ChannelWise);
2229 TEST(QuantizedModelVerifierTest, Floor_wrong_type_NEG)
2231 TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2232 TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2233 TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2237 TEST(QuantizedModelVerifierTest, Floor_wrong_granularity_NEG)
2239 TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::U8, Granularity::LayerWise);
2240 TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::U8, Granularity::ChannelWise);
2241 TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::S16, Granularity::ChannelWise);
2245 TEST(QuantizedModelVerifierTest, GreaterEqual)
2247 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2248 Granularity::LayerWise);
2249 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2250 Granularity::ChannelWise);
2251 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2252 Granularity::ChannelWise);
2256 TEST(QuantizedModelVerifierTest, GreaterEqual_wrong_type_NEG)
2258 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2259 Granularity::LayerWise, Type::U8);
2260 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2261 Granularity::ChannelWise, Type::U8);
2262 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2263 Granularity::ChannelWise, Type::S16);
2267 TEST(QuantizedModelVerifierTest, GreaterEqual_wrong_granularity_NEG)
2269 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2270 Granularity::LayerWise, g.x());
2271 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2272 Granularity::ChannelWise, g.x());
2273 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2274 Granularity::ChannelWise, g.x());
2276 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2277 Granularity::LayerWise, g.y());
2278 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2279 Granularity::ChannelWise, g.y());
2280 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2281 Granularity::ChannelWise, g.y());
2285 TEST(QuantizedModelVerifierTest, Greater)
2287 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::LayerWise);
2288 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::ChannelWise);
2289 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16, Granularity::ChannelWise);
2293 TEST(QuantizedModelVerifierTest, Greater_wrong_type_NEG)
2295 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::LayerWise,
2297 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2298 Granularity::ChannelWise, Type::U8);
2299 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
2300 Granularity::ChannelWise, Type::S16);
2304 TEST(QuantizedModelVerifierTest, Greater_wrong_granularity_NEG)
2306 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2307 Granularity::LayerWise, g.x());
2308 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2309 Granularity::ChannelWise, g.x());
2310 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
2311 Granularity::ChannelWise, g.x());
2313 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2314 Granularity::LayerWise, g.y());
2315 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2316 Granularity::ChannelWise, g.y());
2317 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
2318 Granularity::ChannelWise, g.y());
2322 TEST(QuantizedModelVerifierTest, NotEqual)
2324 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8, Granularity::LayerWise);
2325 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8, Granularity::ChannelWise);
2326 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16, Granularity::ChannelWise);
2330 TEST(QuantizedModelVerifierTest, NotEqual_wrong_type_NEG)
2332 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2333 Granularity::LayerWise, Type::U8);
2334 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2335 Granularity::ChannelWise, Type::U8);
2336 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
2337 Granularity::ChannelWise, Type::S16);
2341 TEST(QuantizedModelVerifierTest, NotEqual_wrong_granularity_NEG)
2343 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2344 Granularity::LayerWise, g.x());
2345 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2346 Granularity::ChannelWise, g.x());
2347 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
2348 Granularity::ChannelWise, g.x());
2350 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2351 Granularity::LayerWise, g.y());
2352 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2353 Granularity::ChannelWise, g.y());
2354 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
2355 Granularity::ChannelWise, g.y());
2359 TEST(QuantizedModelVerifierTest, OneHot)
2361 TEST_WITH_GRAPH(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2362 TEST_WITH_GRAPH(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2363 TEST_WITH_GRAPH(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2365 TEST_WITH_GRAPH(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2366 TEST_WITH_GRAPH(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2367 TEST_WITH_GRAPH(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2369 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2370 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2371 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2373 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2374 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2375 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2379 TEST(QuantizedModelVerifierTest, OneHot_wrong_input_type_NEG)
2381 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
2382 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
2383 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
2385 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
2386 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
2387 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
2391 TEST(QuantizedModelVerifierTest, OneHot_wrong_granularity_NEG)
2393 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2394 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2395 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2397 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2398 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2399 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2403 TEST(QuantizedModelVerifierTest, Div)
2405 TEST_WITH_GRAPH(DivTestGraph, Type::U8, Granularity::LayerWise);
2406 TEST_WITH_GRAPH(DivTestGraph, Type::U8, Granularity::ChannelWise);
2407 TEST_WITH_GRAPH(DivTestGraph, Type::S16, Granularity::ChannelWise);
2409 TEST_WITH_LAYER_INFO(DivTestGraph, Type::U8, Granularity::LayerWise);
2410 TEST_WITH_LAYER_INFO(DivTestGraph, Type::U8, Granularity::ChannelWise);
2411 TEST_WITH_LAYER_INFO(DivTestGraph, Type::S16, Granularity::ChannelWise);
2415 TEST(QuantizedModelVerifierTest, Div_wrong_type_NEG)
2417 TEST_WITH_WRONG_TYPE(DivTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2418 TEST_WITH_WRONG_TYPE(DivTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2419 TEST_WITH_WRONG_TYPE(DivTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2423 TEST(QuantizedModelVerifierTest, Div_wrong_granularity_NEG)
2425 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::LayerWise, g.x());
2426 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2427 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2429 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::LayerWise, g.y());
2430 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2431 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2435 TEST(QuantizedModelVerifierTest, FloorDiv)
2437 TEST_WITH_GRAPH(FloorDivTestGraph, Type::U8, Granularity::LayerWise);
2438 TEST_WITH_GRAPH(FloorDivTestGraph, Type::U8, Granularity::ChannelWise);
2439 TEST_WITH_GRAPH(FloorDivTestGraph, Type::S16, Granularity::ChannelWise);
2441 TEST_WITH_LAYER_INFO(FloorDivTestGraph, Type::U8, Granularity::LayerWise);
2442 TEST_WITH_LAYER_INFO(FloorDivTestGraph, Type::U8, Granularity::ChannelWise);
2443 TEST_WITH_LAYER_INFO(FloorDivTestGraph, Type::S16, Granularity::ChannelWise);
2447 TEST(QuantizedModelVerifierTest, FloorDiv_wrong_type_NEG)
2449 TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2450 TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2451 TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2455 TEST(QuantizedModelVerifierTest, FloorDiv_wrong_granularity_NEG)
2457 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::LayerWise, g.x());
2458 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2459 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2461 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::LayerWise, g.y());
2462 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2463 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2467 TEST(QuantizedModelVerifierTest, Rsqrt)
2469 TEST_WITH_GRAPH(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
2470 TEST_WITH_GRAPH(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
2471 TEST_WITH_GRAPH(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
2473 TEST_WITH_LAYER_INFO(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
2474 TEST_WITH_LAYER_INFO(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
2475 TEST_WITH_LAYER_INFO(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
2479 TEST(QuantizedModelVerifierTest, Rsqrt_wrong_type_NEG)
2481 TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2482 TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2483 TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2487 TEST(QuantizedModelVerifierTest, Rsqrt_wrong_granularity_NEG)
2489 TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
2490 TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
2491 TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
2495 TEST(QuantizedModelVerifierTest, Sqrt)
2497 TEST_WITH_GRAPH(SqrtTestGraph, Type::U8, Granularity::LayerWise);
2498 TEST_WITH_GRAPH(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
2499 TEST_WITH_GRAPH(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
2501 TEST_WITH_LAYER_INFO(SqrtTestGraph, Type::U8, Granularity::LayerWise);
2502 TEST_WITH_LAYER_INFO(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
2503 TEST_WITH_LAYER_INFO(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
2507 TEST(QuantizedModelVerifierTest, Sqrt_wrong_type_NEG)
2509 TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2510 TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2511 TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2515 TEST(QuantizedModelVerifierTest, Sqrt_wrong_granularity_NEG)
2517 TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::U8, Granularity::LayerWise);
2518 TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
2519 TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
2523 TEST(QuantizedModelVerifierTest, Elu)
2525 TEST_WITH_GRAPH(EluTestGraph, Type::U8, Granularity::LayerWise);
2526 TEST_WITH_GRAPH(EluTestGraph, Type::U8, Granularity::ChannelWise);
2527 TEST_WITH_GRAPH(EluTestGraph, Type::S16, Granularity::ChannelWise);
2529 TEST_WITH_LAYER_INFO(EluTestGraph, Type::U8, Granularity::LayerWise);
2530 TEST_WITH_LAYER_INFO(EluTestGraph, Type::U8, Granularity::ChannelWise);
2531 TEST_WITH_LAYER_INFO(EluTestGraph, Type::S16, Granularity::ChannelWise);
2535 TEST(QuantizedModelVerifierTest, Elu_wrong_type_NEG)
2537 TEST_WITH_WRONG_TYPE(EluTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2538 TEST_WITH_WRONG_TYPE(EluTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2539 TEST_WITH_WRONG_TYPE(EluTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2543 TEST(QuantizedModelVerifierTest, Elu_wrong_granularity_NEG)
2545 TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::U8, Granularity::LayerWise);
2546 TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::U8, Granularity::ChannelWise);
2547 TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::S16, Granularity::ChannelWise);
2551 TEST(QuantizedModelVerifierTest, Pow)
2553 TEST_WITH_GRAPH(PowTestGraph, Type::U8, Granularity::LayerWise);
2554 TEST_WITH_GRAPH(PowTestGraph, Type::U8, Granularity::ChannelWise);
2555 TEST_WITH_GRAPH(PowTestGraph, Type::S16, Granularity::ChannelWise);
2557 TEST_WITH_LAYER_INFO(PowTestGraph, Type::U8, Granularity::LayerWise);
2558 TEST_WITH_LAYER_INFO(PowTestGraph, Type::U8, Granularity::ChannelWise);
2559 TEST_WITH_LAYER_INFO(PowTestGraph, Type::S16, Granularity::ChannelWise);
2563 TEST(QuantizedModelVerifierTest, Pow_wrong_type_NEG)
2565 TEST_WITH_WRONG_TYPE(PowTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2566 TEST_WITH_WRONG_TYPE(PowTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2567 TEST_WITH_WRONG_TYPE(PowTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2571 TEST(QuantizedModelVerifierTest, Pow_wrong_granularity_NEG)
2573 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::LayerWise, g.x());
2574 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2575 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2577 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::LayerWise, g.y());
2578 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2579 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2583 TEST(QuantizedModelVerifierTest, ReduceMax)
2585 TEST_WITH_GRAPH(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise);
2586 TEST_WITH_GRAPH(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise);
2587 TEST_WITH_GRAPH(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise);
2589 TEST_WITH_LAYER_INFO(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise);
2590 TEST_WITH_LAYER_INFO(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise);
2591 TEST_WITH_LAYER_INFO(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise);
2595 TEST(QuantizedModelVerifierTest, ReduceMax_wrong_type_NEG)
2597 TEST_WITH_WRONG_TYPE(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2598 TEST_WITH_WRONG_TYPE(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2599 TEST_WITH_WRONG_TYPE(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2603 TEST(QuantizedModelVerifierTest, ReduceMax_wrong_granularity_NEG)
2605 TEST_WITH_WRONG_GRANULARITY(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise);
2606 TEST_WITH_WRONG_GRANULARITY(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise);
2607 TEST_WITH_WRONG_GRANULARITY(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise);
2611 TEST(QuantizedModelVerifierTest, ResizeBilinear)
2613 TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2614 TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2615 TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2617 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2618 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2619 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2623 TEST(QuantizedModelVerifierTest, ResizeBilinear_wrong_type_NEG)
2625 TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2626 TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2627 TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2631 TEST(QuantizedModelVerifierTest, ResizeBilinear_wrong_granularity_NEG)
2633 TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2634 TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2635 TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2639 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor)
2641 TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise);
2642 TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise);
2643 TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise);
2645 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2646 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2647 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2651 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor_wrong_type_NEG)
2653 TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2654 TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise,
2656 TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise,
2661 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor_wrong_granularity_NEG)
2663 TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise);
2664 TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise);
2665 TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise);
2669 TEST(QuantizedModelVerifierTest, Unpack)
2671 TEST_WITH_GRAPH(UnpackTestGraph, Type::U8, Granularity::LayerWise);
2672 TEST_WITH_GRAPH(UnpackTestGraph, Type::U8, Granularity::ChannelWise);
2673 TEST_WITH_GRAPH(UnpackTestGraph, Type::S16, Granularity::ChannelWise);
2677 TEST(QuantizedModelVerifierTest, Unpack_wrong_type_NEG)
2679 TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2680 TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2681 TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2685 TEST(QuantizedModelVerifierTest, Unpack_wrong_granularity_NEG)
2687 TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::U8, Granularity::LayerWise);
2688 TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::U8, Granularity::ChannelWise);
2689 TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::S16, Granularity::ChannelWise);
2693 TEST(QuantizedModelVerifierTest, Add)
2695 TEST_WITH_GRAPH(AddTestGraph, Type::U8, Granularity::LayerWise);
2696 TEST_WITH_GRAPH(AddTestGraph, Type::U8, Granularity::ChannelWise);
2697 TEST_WITH_GRAPH(AddTestGraph, Type::S16, Granularity::ChannelWise);
2699 TEST_WITH_LAYER_INFO(AddTestGraph, Type::U8, Granularity::LayerWise);
2700 TEST_WITH_LAYER_INFO(AddTestGraph, Type::U8, Granularity::ChannelWise);
2701 TEST_WITH_LAYER_INFO(AddTestGraph, Type::S16, Granularity::ChannelWise);
2705 TEST(QuantizedModelVerifierTest, Add_wrong_type_NEG)
2707 TEST_WITH_WRONG_TYPE(AddTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2708 TEST_WITH_WRONG_TYPE(AddTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2709 TEST_WITH_WRONG_TYPE(AddTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2713 TEST(QuantizedModelVerifierTest, Add_wrong_granularity_NEG)
2715 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::LayerWise, g.x());
2716 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2717 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2719 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::LayerWise, g.y());
2720 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2721 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2725 TEST(QuantizedModelVerifierTest, Add_inttype)
2728 TEST_WITH_GRAPH(IntAddTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2729 TEST_WITH_GRAPH(IntAddTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2730 TEST_WITH_GRAPH(IntAddTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2732 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2733 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2734 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2737 TEST_WITH_GRAPH(IntAddTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2738 TEST_WITH_GRAPH(IntAddTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2739 TEST_WITH_GRAPH(IntAddTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2741 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2742 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2743 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2748 TEST(QuantizedModelVerifierTest, Mul)
2750 TEST_WITH_GRAPH(MulTestGraph, Type::U8, Granularity::LayerWise);
2751 TEST_WITH_GRAPH(MulTestGraph, Type::U8, Granularity::ChannelWise);
2752 TEST_WITH_GRAPH(MulTestGraph, Type::S16, Granularity::ChannelWise);
2754 TEST_WITH_LAYER_INFO(MulTestGraph, Type::U8, Granularity::LayerWise);
2755 TEST_WITH_LAYER_INFO(MulTestGraph, Type::U8, Granularity::ChannelWise);
2756 TEST_WITH_LAYER_INFO(MulTestGraph, Type::S16, Granularity::ChannelWise);
2760 TEST(QuantizedModelVerifierTest, Mul_wrong_type_NEG)
2762 TEST_WITH_WRONG_TYPE(MulTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2763 TEST_WITH_WRONG_TYPE(MulTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2764 TEST_WITH_WRONG_TYPE(MulTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2768 TEST(QuantizedModelVerifierTest, Mul_wrong_granularity_NEG)
2770 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::LayerWise, g.x());
2771 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2772 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2774 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::LayerWise, g.y());
2775 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2776 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2780 TEST(QuantizedModelVerifierTest, Mul_inttype)
2783 TEST_WITH_GRAPH(IntMulTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2784 TEST_WITH_GRAPH(IntMulTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2785 TEST_WITH_GRAPH(IntMulTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2787 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2788 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2789 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2792 TEST_WITH_GRAPH(IntMulTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2793 TEST_WITH_GRAPH(IntMulTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2794 TEST_WITH_GRAPH(IntMulTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2796 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2797 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2798 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2803 // TODO Add following testcases
2807 // CircleDepthwiseConv2D
2811 // CircleTransposeConv
2813 // CircleFullyConnected
2815 // CircleAveragePool2D
2826 #undef TEST_WITH_GRAPH
2827 #undef TEST_WITH_WRONG_TYPE
2828 #undef TEST_WITH_WRONG_GRANULARITY