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);
77 * @brief A helper function to create const node with value
79 template <Type DT, typename T>
80 luci::CircleConst *create_const(loco::Graph *g, luci::test::ShapeU32 shape,
81 std::initializer_list<T> values)
83 auto node = g->nodes()->create<luci::CircleConst>();
87 node->size<DT>(luci::test::num_elements(shape));
89 assert(values.size() == node->size<DT>());
92 for (auto val : values)
94 node->at<DT>(index++) = static_cast<T>(val);
101 void insert_scale_zp(luci::CircleNode *node, float scale, int64_t zp)
103 auto qparam = node->quantparam();
104 assert(qparam != nullptr); // FIX_CALLER_UNLESS
105 qparam->scale.push_back(scale);
106 qparam->zerop.push_back(zp);
109 void run_phase(loco::Graph *g, Type quantized_dtype, Granularity granularity)
114 phase.emplace_back(std::make_unique<luci::CircleTypeInferencePass>());
116 auto ctx = std::make_unique<luci::QuantizeWithMinMaxPass::Context>();
118 ctx->input_model_dtype = loco::DataType::FLOAT32;
119 ctx->output_model_dtype = quantized_dtype;
120 ctx->granularity = granularity;
121 // Test graph has only one input/output
122 ctx->input_types = {quantized_dtype};
123 ctx->output_types = {quantized_dtype};
126 phase.emplace_back(std::make_unique<luci::QuantizeWithMinMaxPass>(std::move(ctx)));
128 logo::PhaseRunner<logo::PhaseStrategy::Restart> phase_runner{g};
129 phase_runner.run(phase);
132 void run_phase(loco::Graph *g, std::unique_ptr<luci::QuantizeWithMinMaxPass::Context> &&ctx)
137 phase.emplace_back(std::make_unique<luci::CircleTypeInferencePass>());
139 phase.emplace_back(std::make_unique<luci::QuantizeWithMinMaxPass>(std::move(ctx)));
141 logo::PhaseRunner<logo::PhaseStrategy::Restart> phase_runner{g};
142 phase_runner.run(phase);
145 void quantize_and_verify(loco::Graph *g, Type quantized_dtype, Granularity granularity)
147 run_phase(g, quantized_dtype, granularity);
149 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
151 ctx->output_model_dtype = quantized_dtype;
152 ctx->granularity = granularity;
153 // Test graph has only one input/output
154 ctx->input_types = {quantized_dtype};
155 ctx->output_types = {quantized_dtype};
158 luci::QuantizedModelVerifier verifier(std::move(ctx));
162 void quantize_and_verify_with_layer_info(loco::Graph *g, Type quantized_dtype,
163 Granularity granularity)
165 // A layer named "test" has dtype different from quantized_dtype
166 luci::LayerInfo info;
169 // dtype is different from quantized_dtype
170 info.dtype = quantized_dtype == Type::U8 ? Type::S16 : Type::U8;
171 info.granularity = Granularity::ChannelWise;
176 auto ctx = std::make_unique<luci::QuantizeWithMinMaxPass::Context>();
178 ctx->input_model_dtype = Type::FLOAT32;
179 ctx->output_model_dtype = quantized_dtype;
180 ctx->granularity = granularity;
181 // Test graph has only one input/output
182 ctx->input_types = {quantized_dtype};
183 ctx->output_types = {quantized_dtype};
184 ctx->TF_style_maxpool = false;
185 ctx->layers_info.push_back(info);
188 run_phase(g, std::move(ctx));
193 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
195 ctx->output_model_dtype = quantized_dtype;
196 ctx->granularity = granularity;
197 ctx->input_types = {quantized_dtype};
198 ctx->output_types = {quantized_dtype};
199 ctx->TF_style_maxpool = false;
200 ctx->layers_info.push_back(info);
203 luci::QuantizedModelVerifier verifier(std::move(ctx));
208 // Helper function to reduce duplicate test codes
209 // Assumption: g->output()->from() is the target node
210 void quantize_and_verify_with_wrong_type(luci::test::TestIOGraph *g, Type quantized_dtype,
211 Granularity granularity, Type wrong_dtype)
213 run_phase(g->g(), quantized_dtype, granularity);
215 auto node = loco::must_cast<luci::CircleNode *>(g->output()->from());
216 node->dtype(wrong_dtype);
218 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
220 ctx->output_model_dtype = quantized_dtype;
221 ctx->granularity = granularity;
222 // Test graph has only one input/output
223 ctx->input_types = {quantized_dtype};
224 ctx->output_types = {quantized_dtype};
227 luci::QuantizedModelVerifier verifier(std::move(ctx));
228 verifier.verify(g->g());
231 // Helper function to reduce duplicate test codes
232 // Assumption: g->output()->from() is the target node
233 void quantize_and_verify_with_wrong_granularity(luci::test::TestIOGraph *g, Type quantized_dtype,
234 Granularity granularity)
236 run_phase(g->g(), quantized_dtype, granularity);
238 auto node = loco::must_cast<luci::CircleNode *>(g->output()->from());
239 insert_scale_zp(node, 1.0, 1);
241 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
243 ctx->output_model_dtype = quantized_dtype;
244 ctx->granularity = granularity;
245 // Test graph has only one input/output
246 ctx->input_types = {quantized_dtype};
247 ctx->output_types = {quantized_dtype};
250 luci::QuantizedModelVerifier verifier(std::move(ctx));
251 verifier.verify(g->g());
254 // Set min/max for all non-const nodes in the graph
255 void set_minmax_to_non_const(loco::Graph *g, float min, float max)
257 for (auto node : loco::all_nodes(g))
259 auto const_node = dynamic_cast<luci::CircleConst *>(node);
260 if (const_node != nullptr)
263 // Min/Max is not recorded for ArgMax
264 // See MinMaxObserver.cpp in record_minmax module
265 auto argmax_node = dynamic_cast<luci::CircleArgMax *>(node);
266 if (argmax_node != nullptr)
269 // Min/Max is not recorded for Split
270 // See MinMaxObserver.cpp in record_minmax module
271 auto split_node = dynamic_cast<luci::CircleSplit *>(node);
272 if (split_node != nullptr)
275 // Min/Max is not recorded for SplitV
276 // See MinMaxObserver.cpp in record_minmax module
277 auto splitv_node = dynamic_cast<luci::CircleSplitV *>(node);
278 if (splitv_node != nullptr)
281 auto circle_node = loco::must_cast<luci::CircleNode *>(node);
282 auto qparam = std::make_unique<luci::CircleQuantParam>();
284 qparam->min.emplace_back(min);
285 qparam->max.emplace_back(max);
287 circle_node->quantparam(std::move(qparam));
292 * @brief Simple Test Graph
294 * The simple test graph's nodes are initialized with
295 * simple shapes and values.
297 class SimpleTestGraph : public luci::test::TestIOGraph
300 virtual void init(void) = 0;
303 class TypedTestGraph : public luci::test::TestIOGraph
306 void init(Type T, const luci::test::ShapeU32 shape_in, const luci::test::ShapeU32 shape_out)
308 TestIOGraph::init(shape_in, shape_out);
313 g()->inputs()->at(0)->dtype(T);
314 g()->outputs()->at(0)->dtype(T);
318 virtual void init(void) = 0;
321 class InstanceNormTestGraph final : public SimpleTestGraph
324 void init(void) override
326 TestIOGraph::init({32}, {32});
327 _gamma = create_dummy_const<Type::FLOAT32>(g(), {32});
328 _beta = create_dummy_const<Type::FLOAT32>(g(), {32});
329 _instnorm = g()->nodes()->create<luci::CircleInstanceNorm>();
331 _instnorm->input(input());
332 _instnorm->gamma(_gamma);
333 _instnorm->beta(_beta);
334 _instnorm->fusedActivationFunction(luci::FusedActFunc::NONE);
335 _instnorm->name("test");
337 output()->from(_instnorm);
339 set_minmax_to_non_const(g(), -1, 1);
343 loco::Node *gamma(void) const { return _instnorm->gamma(); }
344 loco::Node *beta(void) const { return _instnorm->beta(); }
347 luci::CircleInstanceNorm *_instnorm = nullptr;
348 luci::CircleConst *_input = nullptr;
349 luci::CircleConst *_gamma = nullptr;
350 luci::CircleConst *_beta = nullptr;
353 class LogisticTestGraph final : public SimpleTestGraph
356 void init(void) override
358 TestIOGraph::init({32}, {32});
359 _logistic = g()->nodes()->create<luci::CircleLogistic>();
361 _logistic->x(input());
362 _logistic->name("test");
364 output()->from(_logistic);
366 set_minmax_to_non_const(g(), -1, 1);
370 luci::CircleLogistic *_logistic = nullptr;
373 class LocalResponseNormalizationTestGraph final : public SimpleTestGraph
376 void init(void) override
378 TestIOGraph::init({1, 2, 2, 32}, {1, 2, 2, 32});
379 _lrn = g()->nodes()->create<luci::CircleLocalResponseNormalization>();
381 _lrn->input(input());
384 output()->from(_lrn);
386 set_minmax_to_non_const(g(), -1, 1);
390 luci::CircleLocalResponseNormalization *_lrn = nullptr;
393 class SoftmaxTestGraph final : public SimpleTestGraph
396 void init(void) override
398 TestIOGraph::init({32}, {32});
399 _softmax = g()->nodes()->create<luci::CircleSoftmax>();
401 _softmax->logits(input());
403 _softmax->name("test");
405 output()->from(_softmax);
407 set_minmax_to_non_const(g(), -1, 1);
411 luci::CircleSoftmax *_softmax = nullptr;
414 class SpaceToBatchNDTestGraph final : public SimpleTestGraph
417 void init(void) override
419 TestIOGraph::init({1, 2, 2, 1}, {4, 1, 1, 1});
420 _block_shape = create_dummy_const<Type::S32>(g(), {2});
421 for (uint32_t i = 0; i < 2; i++)
422 _block_shape->at<Type::S32>(i) = 2;
424 _paddings = create_dummy_const<Type::S32>(g(), {2, 2});
425 for (uint32_t i = 0; i < 4; i++)
426 _paddings->at<Type::S32>(i) = 0;
428 _stob = g()->nodes()->create<luci::CircleSpaceToBatchND>();
430 _stob->input(input());
431 _stob->block_shape(_block_shape);
432 _stob->paddings(_paddings);
435 output()->from(_stob);
437 set_minmax_to_non_const(g(), -1, 1);
441 luci::CircleSpaceToBatchND *_stob = nullptr;
442 luci::CircleConst *_block_shape = nullptr;
443 luci::CircleConst *_paddings = nullptr;
446 class SpaceToDepthTestGraph final : public SimpleTestGraph
449 void init(void) override
451 TestIOGraph::init({1, 2, 2, 1}, {1, 1, 1, 4});
452 _stod = g()->nodes()->create<luci::CircleSpaceToDepth>();
454 _stod->input(input());
455 _stod->block_size(2);
458 output()->from(_stod);
460 set_minmax_to_non_const(g(), -1, 1);
464 luci::CircleSpaceToDepth *_stod = nullptr;
467 template <Type indexT> class SliceTestGraph final : public SimpleTestGraph
470 void init(void) override
472 TestIOGraph::init({32}, {32});
473 _begin = g()->nodes()->create<luci::CircleConst>();
475 _begin->dtype(indexT);
477 _size = g()->nodes()->create<luci::CircleConst>();
479 _size->dtype(indexT);
481 _slice = g()->nodes()->create<luci::CircleSlice>();
483 _slice->input(input());
484 _slice->begin(_begin);
486 _slice->name("test");
488 output()->from(_slice);
490 set_minmax_to_non_const(g(), -1, 1);
494 luci::CircleSlice *_slice = nullptr;
495 luci::CircleConst *_begin = nullptr;
496 luci::CircleConst *_size = nullptr;
499 class SplitTestGraph final : public luci::test::TestIOGraph
504 TestIOGraph::init({1, 32}, {32});
505 _split_dim = create_dummy_const<Type::S32>(g(), {1});
506 _split = g()->nodes()->create<luci::CircleSplit>();
508 _split->input(input());
509 _split->split_dim(_split_dim);
511 _split_o1 = g()->nodes()->create<luci::CircleSplitOut>();
513 _split_o1->input(_split);
517 output()->from(_split_o1);
519 set_minmax_to_non_const(g(), -1, 1);
523 luci::CircleSplit *_split = nullptr;
524 luci::CircleSplitOut *_split_o1 = nullptr;
525 luci::CircleConst *_split_dim = nullptr;
528 class SplitVTestGraph final : public luci::test::TestIOGraph
533 TestIOGraph::init({1, 32}, {32});
534 _size_splits = create_dummy_const<Type::S32>(g(), {1});
535 _split_dim = create_dummy_const<Type::S32>(g(), {1});
536 _splitv = g()->nodes()->create<luci::CircleSplitV>();
538 _splitv->input(input());
539 _splitv->size_splits(_size_splits);
540 _splitv->split_dim(_split_dim);
542 _splitv_o1 = g()->nodes()->create<luci::CircleSplitVOut>();
544 _splitv_o1->input(_splitv);
545 _splitv_o1->index(0);
548 output()->from(_splitv_o1);
550 set_minmax_to_non_const(g(), -1, 1);
554 luci::CircleSplitV *_splitv = nullptr;
555 luci::CircleSplitVOut *_splitv_o1 = nullptr;
556 luci::CircleConst *_size_splits = nullptr;
557 luci::CircleConst *_split_dim = nullptr;
560 class StridedSliceTestGraph final : public SimpleTestGraph
563 void init(void) override
565 TestIOGraph::init({32}, {32});
566 _begin = g()->nodes()->create<luci::CircleConst>();
568 _begin->dtype(Type::S32);
570 _end = g()->nodes()->create<luci::CircleConst>();
572 _end->dtype(Type::S32);
574 _strides = g()->nodes()->create<luci::CircleConst>();
576 _strides->dtype(Type::S32);
578 _slice = g()->nodes()->create<luci::CircleStridedSlice>();
580 _slice->input(input());
581 _slice->begin(_begin);
583 _slice->strides(_strides);
584 _slice->name("test");
586 output()->from(_slice);
588 set_minmax_to_non_const(g(), -1, 1);
592 luci::CircleStridedSlice *_slice = nullptr;
593 luci::CircleConst *_begin = nullptr;
594 luci::CircleConst *_end = nullptr;
595 luci::CircleConst *_strides = nullptr;
598 class ReshapeTestGraph final : public SimpleTestGraph
601 void init(void) override
603 TestIOGraph::init({32}, {32});
604 _shape = g()->nodes()->create<luci::CircleConst>();
606 _shape->dtype(Type::S32);
608 _reshape = g()->nodes()->create<luci::CircleReshape>();
610 _reshape->tensor(input());
611 _reshape->shape(_shape);
612 _reshape->name("test");
614 output()->from(_reshape);
616 set_minmax_to_non_const(g(), -1, 1);
620 luci::CircleReshape *_reshape = nullptr;
621 luci::CircleConst *_shape = nullptr;
624 class TanhTestGraph final : public SimpleTestGraph
627 void init(void) override
629 TestIOGraph::init({32}, {32});
630 _tanh = g()->nodes()->create<luci::CircleTanh>();
635 output()->from(_tanh);
637 set_minmax_to_non_const(g(), -1, 1);
641 luci::CircleTanh *_tanh = nullptr;
644 class FloorTestGraph final : public SimpleTestGraph
647 void init(void) override
649 TestIOGraph::init({32}, {32});
650 _floor = g()->nodes()->create<luci::CircleFloor>();
653 _floor->name("test");
655 output()->from(_floor);
657 set_minmax_to_non_const(g(), -1, 1);
661 luci::CircleFloor *_floor = nullptr;
664 template <Type indexT> class ArgMaxTestGraph final : public SimpleTestGraph
667 void init(void) override
669 TestIOGraph::init({32}, {1});
670 // output dtype is float by default, but ArgMax should have indexType (s32/s64)
671 output()->dtype(indexT);
672 _dimension = g()->nodes()->create<luci::CircleConst>();
674 _dimension->dtype(indexT);
676 _argmax = g()->nodes()->create<luci::CircleArgMax>();
678 _argmax->input(input());
679 _argmax->dimension(_dimension);
680 _argmax->output_type(indexT);
681 _argmax->dtype(indexT);
683 output()->from(_argmax);
685 set_minmax_to_non_const(g(), -1, 1);
687 // Sync output dtype with graph's output dtype
688 g()->outputs()->at(0)->dtype(output()->dtype());
692 // NOTE: Do not override `luci::CircleNode* input(void)` incidentally
693 loco::Node *input_argmax(void) { return _argmax->input(); }
694 loco::Node *dimension(void) { return _argmax->dimension(); }
697 luci::CircleArgMax *_argmax = nullptr;
698 luci::CircleConst *_dimension = nullptr;
701 class BatchToSpaceNDTestGraph final : public SimpleTestGraph
704 void init(void) override
706 TestIOGraph::init({32}, {32});
707 _block_shape = g()->nodes()->create<luci::CircleConst>();
709 _block_shape->dtype(Type::S32);
711 _crops = g()->nodes()->create<luci::CircleConst>();
713 _crops->dtype(Type::S32);
715 _btos = g()->nodes()->create<luci::CircleBatchToSpaceND>();
717 _btos->input(input());
718 _btos->block_shape(_block_shape);
719 _btos->crops(_crops);
722 output()->from(_btos);
724 set_minmax_to_non_const(g(), -1, 1);
728 luci::CircleBatchToSpaceND *_btos = nullptr;
729 luci::CircleConst *_block_shape = nullptr;
730 luci::CircleConst *_crops = nullptr;
733 class DepthToSpaceTestGraph final : public SimpleTestGraph
736 void init(void) override
738 TestIOGraph::init({1, 1, 1, 4}, {1, 2, 2, 1});
739 _dtos = g()->nodes()->create<luci::CircleDepthToSpace>();
741 _dtos->input(input());
742 _dtos->block_size(2);
745 output()->from(_dtos);
747 set_minmax_to_non_const(g(), -1, 1);
751 luci::CircleDepthToSpace *_dtos = nullptr;
754 class PackTestGraph final : public SimpleTestGraph
757 void init(void) override
759 TestIOGraph::init({16}, {32});
760 _param = create_dummy_const<Type::FLOAT32>(g(), {16});
761 _pack = g()->nodes()->create<luci::CirclePack>(2);
763 _pack->values(0, input());
764 _pack->values(1, _param);
768 output()->from(_pack);
770 set_minmax_to_non_const(g(), -1, 1);
772 // Set min/max of the input
773 // pack's qparam will be propagted, overwritten to the input
774 auto input = loco::must_cast<luci::CircleNode *>(pack()->values(0));
775 auto qp = input->quantparam();
781 luci::CirclePack *pack(void) { return _pack; }
784 luci::CirclePack *_pack = nullptr;
785 luci::CircleConst *_param = nullptr;
788 class PadTestGraph final : public SimpleTestGraph
791 void init(void) override
793 TestIOGraph::init({32}, {32});
794 _paddings = g()->nodes()->create<luci::CircleConst>();
796 _paddings->dtype(Type::S32);
798 _pad = g()->nodes()->create<luci::CirclePad>();
800 _pad->input(input());
801 _pad->paddings(_paddings);
804 output()->from(_pad);
806 set_minmax_to_non_const(g(), -1, 1);
810 luci::CirclePad *_pad = nullptr;
811 luci::CircleConst *_paddings = nullptr;
814 class PadV2TestGraph final : public SimpleTestGraph
817 void init(void) override
819 TestIOGraph::init({32}, {32});
820 _paddings = g()->nodes()->create<luci::CircleConst>();
822 _paddings->dtype(Type::S32);
824 _constant_values = create_dummy_const<Type::FLOAT32>(g(), {1});
825 _pad = g()->nodes()->create<luci::CirclePadV2>();
827 _pad->input(input());
828 _pad->paddings(_paddings);
829 _pad->constant_values(_constant_values);
832 output()->from(_pad);
834 set_minmax_to_non_const(g(), -1, 1);
838 luci::CirclePadV2 *_pad = nullptr;
839 luci::CircleConst *_paddings = nullptr;
840 luci::CircleConst *_constant_values = nullptr;
843 class MirrorPadTestGraph final : public SimpleTestGraph
846 void init(void) override
848 TestIOGraph::init({32}, {32});
849 _paddings = g()->nodes()->create<luci::CircleConst>();
851 _paddings->dtype(Type::S32);
853 _constant_values = create_dummy_const<Type::FLOAT32>(g(), {1});
854 _mirror_pad = g()->nodes()->create<luci::CircleMirrorPad>();
856 _mirror_pad->input(input());
857 _mirror_pad->paddings(_paddings);
858 _mirror_pad->mode(luci::MirrorPadMode::REFLECT);
859 _mirror_pad->name("test");
861 output()->from(_mirror_pad);
863 set_minmax_to_non_const(g(), -1, 1);
867 luci::CircleMirrorPad *_mirror_pad = nullptr;
868 luci::CircleConst *_paddings = nullptr;
869 luci::CircleConst *_constant_values = nullptr;
872 class TransposeTestGraph final : public SimpleTestGraph
875 void init(void) override
877 TestIOGraph::init({32}, {32});
878 _perm = g()->nodes()->create<luci::CircleConst>();
880 _perm->dtype(Type::S32);
882 _transpose = g()->nodes()->create<luci::CircleTranspose>();
884 _transpose->a(input());
885 _transpose->perm(_perm);
886 _transpose->name("test");
888 output()->from(_transpose);
890 set_minmax_to_non_const(g(), -1, 1);
894 luci::CircleTranspose *_transpose = nullptr;
895 luci::CircleConst *_perm = nullptr;
898 class ConcatenationTestGraph final : public SimpleTestGraph
901 void init(void) override
903 TestIOGraph::init({16}, {32});
904 _param = create_dummy_const<Type::FLOAT32>(g(), {16});
905 _concat = g()->nodes()->create<luci::CircleConcatenation>(2);
907 _concat->values(0, input());
908 _concat->values(1, _param);
910 _concat->fusedActivationFunction(luci::FusedActFunc::NONE);
911 _concat->name("test");
913 output()->from(_concat);
915 set_minmax_to_non_const(g(), -1, 1);
919 luci::CircleConcatenation *_concat = nullptr;
920 luci::CircleConst *_param = nullptr;
923 template <Type indexT> class OneHotTestGraph final : public SimpleTestGraph
926 void init(void) override
928 TestIOGraph::init({32}, {32, 10});
930 // input dtype is float by default, but OneHot's input should have indexType (s32/s64)
931 input()->dtype(indexT);
934 _depth = g()->nodes()->template create<luci::CircleConst>();
936 _depth->dtype(loco::DataType::S32);
939 _on_value = g()->nodes()->template create<luci::CircleConst>();
941 _on_value->dtype(loco::DataType::FLOAT32);
944 _off_value = g()->nodes()->template create<luci::CircleConst>();
946 _off_value->dtype(loco::DataType::FLOAT32);
949 _one_hot = g()->nodes()->template create<luci::CircleOneHot>();
951 _one_hot->indices(input());
952 _one_hot->depth(_depth);
953 _one_hot->on_value(_on_value);
954 _one_hot->off_value(_off_value);
956 _one_hot->dtype(loco::DataType::FLOAT32);
957 _one_hot->name("test");
959 output()->from(_one_hot);
961 set_minmax_to_non_const(g(), -1, 1);
965 luci::CircleOneHot *_one_hot = nullptr;
966 luci::CircleConst *_depth = nullptr;
967 luci::CircleConst *_on_value = nullptr;
968 luci::CircleConst *_off_value = nullptr;
971 // Test graph for comparison Ops
972 // GREATER, GREATER_EQUAL, LESS, LESS_EQUAL, EQUAL, NOT_EQUAL
973 template <class Op> class ComparisonOpTestGraph final : public SimpleTestGraph
976 void init(void) override
978 TestIOGraph::init({32}, {32});
979 output()->dtype(loco::DataType::BOOL);
980 _y = create_dummy_const<Type::FLOAT32>(g(), {32});
981 _op = g()->nodes()->create<Op>();
985 _op->dtype(loco::DataType::BOOL);
989 set_minmax_to_non_const(g(), -1, 1);
991 // Sync output dtype with graph's output dtype
992 g()->outputs()->at(0)->dtype(output()->dtype());
995 loco::Node *x(void) const { return _op->x(); }
996 loco::Node *y(void) const { return _op->y(); }
1000 luci::CircleConst *_y = nullptr;
1003 // Test graph for binary logical Ops
1004 // LOGICAL_OR, LOGICAL_AND
1005 template <class Op> class BinaryLogicalOpTestGraph final : public SimpleTestGraph
1008 void init(void) override
1010 TestIOGraph::init({32}, {32});
1011 input()->dtype(loco::DataType::BOOL);
1012 output()->dtype(loco::DataType::BOOL);
1013 _y = create_dummy_const<Type::BOOL>(g(), {32});
1014 _op = g()->nodes()->create<Op>();
1018 _op->dtype(loco::DataType::BOOL);
1020 output()->from(_op);
1022 set_minmax_to_non_const(g(), -1, 1);
1024 // Sync output dtype with graph's output dtype
1025 g()->outputs()->at(0)->dtype(output()->dtype());
1028 loco::Node *x(void) const { return _op->x(); }
1029 loco::Node *y(void) const { return _op->y(); }
1033 luci::CircleConst *_y = nullptr;
1036 class DivTestGraph final : public SimpleTestGraph
1039 void init(void) override
1041 TestIOGraph::init({32}, {32});
1043 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1044 _div = g()->nodes()->create<luci::CircleDiv>();
1050 output()->from(_div);
1052 set_minmax_to_non_const(g(), -1, 1);
1055 loco::Node *x() { return _div->x(); }
1057 loco::Node *y() { return _div->y(); }
1060 luci::CircleDiv *_div = nullptr;
1061 luci::CircleConst *_const = nullptr;
1064 class FloorDivTestGraph final : public SimpleTestGraph
1067 void init(void) override
1069 TestIOGraph::init({32}, {32});
1071 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1072 _floor_div = g()->nodes()->create<luci::CircleFloorDiv>();
1074 _floor_div->x(input());
1075 _floor_div->y(_const);
1076 _floor_div->name("test");
1078 output()->from(_floor_div);
1080 set_minmax_to_non_const(g(), -1, 1);
1083 loco::Node *x() { return _floor_div->x(); }
1085 loco::Node *y() { return _floor_div->y(); }
1088 luci::CircleFloorDiv *_floor_div = nullptr;
1089 luci::CircleConst *_const = nullptr;
1092 class RsqrtTestGraph final : public SimpleTestGraph
1095 void init(void) override
1097 TestIOGraph::init({32}, {32});
1098 _rsqrt = g()->nodes()->create<luci::CircleRsqrt>();
1101 _rsqrt->name("test");
1103 output()->from(_rsqrt);
1105 set_minmax_to_non_const(g(), -1, 1);
1109 luci::CircleRsqrt *_rsqrt = nullptr;
1112 class SqrtTestGraph final : public SimpleTestGraph
1115 void init(void) override
1117 TestIOGraph::init({32}, {32});
1118 _sqrt = g()->nodes()->create<luci::CircleSqrt>();
1121 _sqrt->name("test");
1123 output()->from(_sqrt);
1125 set_minmax_to_non_const(g(), -1, 1);
1129 luci::CircleSqrt *_sqrt = nullptr;
1132 class EluTestGraph final : public SimpleTestGraph
1135 void init(void) override
1137 TestIOGraph::init({32}, {32});
1138 _elu = g()->nodes()->create<luci::CircleElu>();
1140 _elu->features(input());
1143 output()->from(_elu);
1145 set_minmax_to_non_const(g(), -1, 1);
1149 luci::CircleElu *_elu = nullptr;
1152 class PowTestGraph final : public SimpleTestGraph
1155 void init(void) override
1157 TestIOGraph::init({32}, {32});
1159 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1160 _pow = g()->nodes()->create<luci::CirclePow>();
1166 output()->from(_pow);
1168 set_minmax_to_non_const(g(), -1, 1);
1171 loco::Node *x() { return _pow->x(); }
1173 loco::Node *y() { return _pow->y(); }
1176 luci::CirclePow *_pow = nullptr;
1177 luci::CircleConst *_const = nullptr;
1180 class ReduceMaxTestGraph final : public SimpleTestGraph
1183 void init(void) override
1185 TestIOGraph::init({4, 3, 2}, {2});
1187 _axis = create_const<Type::S32, int32_t>(g(), {4}, {1, 0, -3, -3});
1188 _reduce_max = g()->nodes()->create<luci::CircleReduceMax>();
1190 _reduce_max->input(input());
1191 _reduce_max->reduction_indices(_axis);
1192 _reduce_max->name("test");
1193 _reduce_max->keep_dims(false);
1195 output()->from(_reduce_max);
1197 set_minmax_to_non_const(g(), -1, 1);
1201 luci::CircleReduceMax *_reduce_max = nullptr;
1202 luci::CircleConst *_axis = nullptr;
1205 class ResizeBilinearTestGraph final : public SimpleTestGraph
1208 void init(void) override
1210 TestIOGraph::init({1, 4, 4, 1}, {1, 8, 8, 1});
1212 _size = create_const<Type::S32, int32_t>(g(), {2}, {8, 8});
1213 _resize_bilinear = g()->nodes()->create<luci::CircleResizeBilinear>();
1215 _resize_bilinear->input(input());
1216 _resize_bilinear->size(_size);
1217 _resize_bilinear->name("test");
1219 output()->from(_resize_bilinear);
1221 set_minmax_to_non_const(g(), -1, 1);
1225 luci::CircleResizeBilinear *_resize_bilinear = nullptr;
1226 luci::CircleConst *_size = nullptr;
1229 class ResizeNearestNeighborTestGraph final : public luci::test::TestIOGraph
1234 TestIOGraph::init({1, 4, 4, 1}, {1, 8, 8, 1});
1236 _size = create_const<Type::S32, int32_t>(g(), {2}, {8, 8});
1237 _resize_nearest_neighbor = g()->nodes()->create<luci::CircleResizeNearestNeighbor>();
1239 _resize_nearest_neighbor->input(input());
1240 _resize_nearest_neighbor->size(_size);
1241 _resize_nearest_neighbor->name("test");
1243 output()->from(_resize_nearest_neighbor);
1245 set_minmax_to_non_const(g(), -1, 1);
1249 luci::CircleResizeNearestNeighbor *_resize_nearest_neighbor = nullptr;
1250 luci::CircleConst *_size = nullptr;
1253 class UnpackTestGraph final : public luci::test::TestIOGraph
1258 TestIOGraph::init({1, 32}, {32});
1259 _unpack = g()->nodes()->create<luci::CircleUnpack>();
1261 _unpack->value(input());
1265 _unpack_o1 = g()->nodes()->create<luci::CircleUnpackOut>();
1267 _unpack_o1->input(_unpack);
1268 _unpack_o1->index(0);
1271 output()->from(_unpack_o1);
1273 set_minmax_to_non_const(g(), -1, 1);
1277 luci::CircleUnpack *_unpack = nullptr;
1278 luci::CircleUnpackOut *_unpack_o1 = nullptr;
1279 luci::CircleConst *_unpack_dim = nullptr;
1282 class MulTestGraph final : public SimpleTestGraph
1285 void init(void) override
1287 TestIOGraph::init({32}, {32});
1289 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1290 _mul = g()->nodes()->create<luci::CircleMul>();
1294 _mul->fusedActivationFunction(luci::FusedActFunc::NONE);
1297 output()->from(_mul);
1299 set_minmax_to_non_const(g(), -1, 1);
1302 loco::Node *x() { return _mul->x(); }
1303 loco::Node *y() { return _mul->y(); }
1306 luci::CircleMul *_mul = nullptr;
1307 luci::CircleConst *_const = nullptr;
1310 template <Type T> class IntMulTestGraph final : public TypedTestGraph
1313 void init(void) override
1315 TypedTestGraph::init(T, {32}, {32});
1317 _const = create_dummy_const<T>(g(), {32});
1318 _mul = g()->nodes()->create<luci::CircleMul>();
1322 _mul->fusedActivationFunction(luci::FusedActFunc::NONE);
1326 output()->from(_mul);
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 class AddTestGraph final : public SimpleTestGraph
1340 void init(void) override
1342 TestIOGraph::init({32}, {32});
1344 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1345 _add = g()->nodes()->create<luci::CircleAdd>();
1349 _add->fusedActivationFunction(luci::FusedActFunc::NONE);
1352 output()->from(_add);
1354 set_minmax_to_non_const(g(), -1, 1);
1357 loco::Node *x() { return _add->x(); }
1358 loco::Node *y() { return _add->y(); }
1361 luci::CircleAdd *_add = nullptr;
1362 luci::CircleConst *_const = nullptr;
1365 template <Type T> class IntAddTestGraph final : public TypedTestGraph
1368 void init(void) override
1370 TypedTestGraph::init(T, {32}, {32});
1372 _const = create_dummy_const<T>(g(), {32});
1373 _add = g()->nodes()->create<luci::CircleAdd>();
1377 _add->fusedActivationFunction(luci::FusedActFunc::NONE);
1381 output()->from(_add);
1384 loco::Node *x() { return _add->x(); }
1385 loco::Node *y() { return _add->y(); }
1388 luci::CircleAdd *_add = nullptr;
1389 luci::CircleConst *_const = nullptr;
1394 // Quantize and verify with given configurations
1395 #define TEST_WITH_GRAPH(graph, type, granularity) \
1400 EXPECT_NO_THROW(quantize_and_verify(g.g(), type, granularity)); \
1403 // Quantize and verify with layer info
1404 #define TEST_WITH_LAYER_INFO(graph, type, granularity) \
1409 EXPECT_NO_THROW(quantize_and_verify_with_layer_info(g.g(), type, granularity)); \
1412 // Quantize and verify with wrong type
1413 #define TEST_WITH_WRONG_TYPE(graph, type, granularity, wrong_dtype) \
1418 EXPECT_ANY_THROW(quantize_and_verify_with_wrong_type(&g, type, granularity, wrong_dtype)); \
1421 // Quantize and verify with wrong granularity
1422 #define TEST_WITH_WRONG_GRANULARITY(graph, type, granularity) \
1427 EXPECT_ANY_THROW(quantize_and_verify_with_wrong_granularity(&g, type, granularity)); \
1430 // Quantize and verify with wrong type
1431 // Users can specify the test target
1432 #define TEST_WITH_WRONG_TYPE_TARGET(graph, type, granularity_, wrong_dtype, target) \
1437 auto node = loco::must_cast<luci::CircleNode *>(target); \
1438 run_phase(g.g(), type, granularity_); \
1439 auto after_node = loco::must_cast<luci::CircleNode *>(target); \
1440 after_node->dtype(wrong_dtype); \
1441 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>(); \
1443 ctx->output_model_dtype = type; \
1444 ctx->granularity = granularity_; \
1445 ctx->input_types = {type}; \
1446 ctx->output_types = {type}; \
1448 luci::QuantizedModelVerifier verifier(std::move(ctx)); \
1449 EXPECT_ANY_THROW(verifier.verify(g.g())); \
1452 // Quantize and verify with wrong granularity
1453 // Users can specify the test target
1454 #define TEST_WITH_WRONG_GRANULARITY_TARGET(graph, type, granularity_, target) \
1459 auto node = loco::must_cast<luci::CircleNode *>(target); \
1460 run_phase(g.g(), type, granularity_); \
1461 auto after_node = loco::must_cast<luci::CircleNode *>(target); \
1462 insert_scale_zp(after_node, 1.0, 1); \
1463 auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>(); \
1465 ctx->output_model_dtype = type; \
1466 ctx->granularity = granularity_; \
1467 ctx->input_types = {type}; \
1468 ctx->output_types = {type}; \
1470 luci::QuantizedModelVerifier verifier(std::move(ctx)); \
1471 EXPECT_ANY_THROW(verifier.verify(g.g())); \
1474 // Test a local helper function
1475 TEST(QuantizedModelVerifierTest, LocalCreateDummyConst)
1479 EXPECT_NO_THROW(create_dummy_const<Type::FLOAT32>(&g, {32, 32}));
1482 TEST(QuantizedModelVerifierTest, LocalCreateConst)
1485 std::initializer_list<float> values = {0.1, 0, -5, 100};
1486 luci::CircleConst *node = create_const<Type::FLOAT32, float>(&g, {2, 2}, values);
1489 for (auto val : values)
1491 EXPECT_EQ(node->at<Type::FLOAT32>(index++), val);
1495 TEST(QuantizedModelVerifierTest, InstanceNorm)
1497 TEST_WITH_GRAPH(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1498 TEST_WITH_GRAPH(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1499 TEST_WITH_GRAPH(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1501 TEST_WITH_LAYER_INFO(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1502 TEST_WITH_LAYER_INFO(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1503 TEST_WITH_LAYER_INFO(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1507 TEST(QuantizedModelVerifierTest, InstanceNorm_wrong_type_NEG)
1509 TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1510 TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1511 TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1515 TEST(QuantizedModelVerifierTest, InstanceNorm_wrong_granularity_NEG)
1517 TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1518 TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1519 TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1523 TEST(QuantizedModelVerifierTest, LocalResponseNormalization)
1525 TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise);
1526 TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise);
1527 TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise);
1529 TEST_WITH_LAYER_INFO(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise);
1530 TEST_WITH_LAYER_INFO(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise);
1531 TEST_WITH_LAYER_INFO(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise);
1535 TEST(QuantizedModelVerifierTest, LocalResponseNormalization_wrong_type_NEG)
1537 TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise,
1539 TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise,
1541 TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise,
1546 TEST(QuantizedModelVerifierTest, LocalResponseNormalization_wrong_granularity_NEG)
1548 TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::U8,
1549 Granularity::LayerWise);
1550 TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::U8,
1551 Granularity::ChannelWise);
1552 TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::S16,
1553 Granularity::ChannelWise);
1557 TEST(QuantizedModelVerifierTest, Logistic)
1559 TEST_WITH_GRAPH(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1560 TEST_WITH_GRAPH(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1561 TEST_WITH_GRAPH(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1563 TEST_WITH_LAYER_INFO(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1564 TEST_WITH_LAYER_INFO(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1565 TEST_WITH_LAYER_INFO(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1569 TEST(QuantizedModelVerifierTest, Logistic_wrong_type_NEG)
1571 TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1572 TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1573 TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1577 TEST(QuantizedModelVerifierTest, Logistic_wrong_granularity_NEG)
1579 TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1580 TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1581 TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1585 TEST(QuantizedModelVerifierTest, Softmax)
1587 TEST_WITH_GRAPH(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1588 TEST_WITH_GRAPH(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1589 TEST_WITH_GRAPH(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1591 TEST_WITH_LAYER_INFO(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1592 TEST_WITH_LAYER_INFO(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1593 TEST_WITH_LAYER_INFO(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1597 TEST(QuantizedModelVerifierTest, Softmax_wrong_type_NEG)
1599 TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1600 TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1601 TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1605 TEST(QuantizedModelVerifierTest, Softmax_wrong_granularity_NEG)
1607 TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1608 TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1609 TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1613 TEST(QuantizedModelVerifierTest, SpaceToBatchND)
1615 TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1616 TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1617 TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1619 TEST_WITH_LAYER_INFO(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1620 TEST_WITH_LAYER_INFO(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1621 TEST_WITH_LAYER_INFO(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1625 TEST(QuantizedModelVerifierTest, SpaceToBatchND_wrong_type_NEG)
1627 TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1628 TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1629 TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1633 TEST(QuantizedModelVerifierTest, SpaceToBatchND_wrong_granularity_NEG)
1635 TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1636 TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1637 TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1641 TEST(QuantizedModelVerifierTest, SpaceToDepth)
1643 TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1644 TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1645 TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1647 TEST_WITH_LAYER_INFO(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1648 TEST_WITH_LAYER_INFO(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1649 TEST_WITH_LAYER_INFO(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1653 TEST(QuantizedModelVerifierTest, SpaceToDepth_wrong_type_NEG)
1655 TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1656 TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1657 TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1661 TEST(QuantizedModelVerifierTest, SpaceToDepth_wrong_granularity_NEG)
1663 TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1664 TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1665 TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1669 TEST(QuantizedModelVerifierTest, Slice)
1671 TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1672 TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1673 TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1675 TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1676 TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1677 TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1679 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1680 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1681 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1683 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1684 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1685 TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1689 TEST(QuantizedModelVerifierTest, Slice_wrong_type_NEG)
1691 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
1692 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
1693 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
1695 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
1696 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
1697 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
1701 TEST(QuantizedModelVerifierTest, Slice_wrong_granularity_NEG)
1703 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1704 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1705 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1707 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1708 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1709 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1713 TEST(QuantizedModelVerifierTest, Split)
1715 TEST_WITH_GRAPH(SplitTestGraph, Type::U8, Granularity::LayerWise);
1716 TEST_WITH_GRAPH(SplitTestGraph, Type::U8, Granularity::ChannelWise);
1717 TEST_WITH_GRAPH(SplitTestGraph, Type::S16, Granularity::ChannelWise);
1721 TEST(QuantizedModelVerifierTest, Split_wrong_type_NEG)
1723 TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1724 TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1725 TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1729 TEST(QuantizedModelVerifierTest, Split_wrong_granularity_NEG)
1731 TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::U8, Granularity::LayerWise);
1732 TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::U8, Granularity::ChannelWise);
1733 TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::S16, Granularity::ChannelWise);
1737 TEST(QuantizedModelVerifierTest, SplitV)
1739 TEST_WITH_GRAPH(SplitVTestGraph, Type::U8, Granularity::LayerWise);
1740 TEST_WITH_GRAPH(SplitVTestGraph, Type::U8, Granularity::ChannelWise);
1741 TEST_WITH_GRAPH(SplitVTestGraph, Type::S16, Granularity::ChannelWise);
1745 TEST(QuantizedModelVerifierTest, SplitV_wrong_type_NEG)
1747 TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1748 TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1749 TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1753 TEST(QuantizedModelVerifierTest, SplitV_wrong_granularity_NEG)
1755 TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::U8, Granularity::LayerWise);
1756 TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::U8, Granularity::ChannelWise);
1757 TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::S16, Granularity::ChannelWise);
1761 TEST(QuantizedModelVerifierTest, StridedSlice)
1763 TEST_WITH_GRAPH(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1764 TEST_WITH_GRAPH(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1765 TEST_WITH_GRAPH(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1767 TEST_WITH_LAYER_INFO(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1768 TEST_WITH_LAYER_INFO(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1769 TEST_WITH_LAYER_INFO(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1773 TEST(QuantizedModelVerifierTest, StridedSlice_wrong_type_NEG)
1775 TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1776 TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1777 TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1781 TEST(QuantizedModelVerifierTest, StridedSlice_wrong_granularity_NEG)
1783 TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1784 TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1785 TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1789 TEST(QuantizedModelVerifierTest, ArgMax)
1791 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1792 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1793 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1795 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1796 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1797 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1801 TEST(QuantizedModelVerifierTest, ArgMax_wrong_input_type_NEG)
1803 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
1804 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
1805 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
1807 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
1808 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
1809 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
1813 TEST(QuantizedModelVerifierTest, ArgMax_wrong_dimension_type_NEG)
1815 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise,
1816 Type::S16, g.dimension());
1817 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise,
1818 Type::S16, g.dimension());
1819 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise,
1820 Type::U8, g.dimension());
1822 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise,
1823 Type::S16, g.dimension());
1824 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise,
1825 Type::S16, g.dimension());
1826 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise,
1827 Type::U8, g.dimension());
1831 TEST(QuantizedModelVerifierTest, ArgMax_wrong_granularity_NEG)
1833 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise,
1835 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise,
1837 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::S16,
1838 Granularity::ChannelWise, g.input_argmax());
1840 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise,
1842 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise,
1844 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::S16,
1845 Granularity::ChannelWise, g.input_argmax());
1849 TEST(QuantizedModelVerifierTest, BatchToSpaceND)
1851 TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1852 TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1853 TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1855 TEST_WITH_LAYER_INFO(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1856 TEST_WITH_LAYER_INFO(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1857 TEST_WITH_LAYER_INFO(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1861 TEST(QuantizedModelVerifierTest, BatchToSpaceND_wrong_type_NEG)
1863 TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1864 TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1865 TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1869 TEST(QuantizedModelVerifierTest, BatchToSpaceND_wrong_granularity_NEG)
1871 TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1872 TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1873 TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1877 TEST(QuantizedModelVerifierTest, DepthToSpace)
1879 TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1880 TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1881 TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1883 TEST_WITH_LAYER_INFO(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1884 TEST_WITH_LAYER_INFO(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1885 TEST_WITH_LAYER_INFO(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1889 TEST(QuantizedModelVerifierTest, DepthToSpace_wrong_type_NEG)
1891 TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1892 TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1893 TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1897 TEST(QuantizedModelVerifierTest, DepthToSpace_wrong_granularity_NEG)
1899 TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1900 TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1901 TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1905 TEST(QuantizedModelVerifierTest, Concatenation)
1907 TEST_WITH_GRAPH(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1908 TEST_WITH_GRAPH(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1909 TEST_WITH_GRAPH(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1911 TEST_WITH_LAYER_INFO(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1912 TEST_WITH_LAYER_INFO(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1913 TEST_WITH_LAYER_INFO(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1917 TEST(QuantizedModelVerifierTest, Concatenation_wrong_type_NEG)
1919 TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1920 TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1921 TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1925 TEST(QuantizedModelVerifierTest, Concatenation_wrong_granularity_NEG)
1927 TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1928 TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1929 TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1933 TEST(QuantizedModelVerifierTest, LogicalOr)
1935 TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1936 Granularity::LayerWise);
1937 TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1938 Granularity::ChannelWise);
1939 TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::S16,
1940 Granularity::ChannelWise);
1944 TEST(QuantizedModelVerifierTest, LogicalOr_wrong_type_NEG)
1946 TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1947 Granularity::LayerWise, Type::U8);
1948 TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1949 Granularity::ChannelWise, Type::U8);
1950 TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::S16,
1951 Granularity::ChannelWise, Type::S16);
1955 TEST(QuantizedModelVerifierTest, Reshape)
1957 TEST_WITH_GRAPH(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
1958 TEST_WITH_GRAPH(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
1959 TEST_WITH_GRAPH(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
1961 TEST_WITH_LAYER_INFO(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
1962 TEST_WITH_LAYER_INFO(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
1963 TEST_WITH_LAYER_INFO(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
1967 TEST(QuantizedModelVerifierTest, Reshape_wrong_type_NEG)
1969 TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1970 TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1971 TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1975 TEST(QuantizedModelVerifierTest, Reshape_wrong_granularity_NEG)
1977 TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
1978 TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
1979 TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
1983 TEST(QuantizedModelVerifierTest, Tanh)
1985 TEST_WITH_GRAPH(TanhTestGraph, Type::U8, Granularity::LayerWise);
1986 TEST_WITH_GRAPH(TanhTestGraph, Type::U8, Granularity::ChannelWise);
1987 TEST_WITH_GRAPH(TanhTestGraph, Type::S16, Granularity::ChannelWise);
1989 TEST_WITH_LAYER_INFO(TanhTestGraph, Type::U8, Granularity::LayerWise);
1990 TEST_WITH_LAYER_INFO(TanhTestGraph, Type::U8, Granularity::ChannelWise);
1991 TEST_WITH_LAYER_INFO(TanhTestGraph, Type::S16, Granularity::ChannelWise);
1995 TEST(QuantizedModelVerifierTest, Tanh_wrong_type_NEG)
1997 TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1998 TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1999 TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2003 TEST(QuantizedModelVerifierTest, Tanh_wrong_granularity_NEG)
2005 TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::U8, Granularity::LayerWise);
2006 TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::U8, Granularity::ChannelWise);
2007 TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::S16, Granularity::ChannelWise);
2011 TEST(QuantizedModelVerifierTest, Pack)
2013 TEST_WITH_GRAPH(PackTestGraph, Type::U8, Granularity::LayerWise);
2014 TEST_WITH_GRAPH(PackTestGraph, Type::U8, Granularity::ChannelWise);
2015 TEST_WITH_GRAPH(PackTestGraph, Type::S16, Granularity::ChannelWise);
2017 TEST_WITH_LAYER_INFO(PackTestGraph, Type::U8, Granularity::LayerWise);
2018 TEST_WITH_LAYER_INFO(PackTestGraph, Type::U8, Granularity::ChannelWise);
2019 TEST_WITH_LAYER_INFO(PackTestGraph, Type::S16, Granularity::ChannelWise);
2021 // Test if Pack's qparam is propagated to the input
2025 quantize_and_verify(g.g(), Type::U8, Granularity::ChannelWise);
2026 auto input = loco::must_cast<luci::CircleNode *>(g.pack()->values(0));
2027 auto qp = input->quantparam();
2028 EXPECT_FLOAT_EQ(2.0 / 255.0, qp->scale[0]);
2029 EXPECT_FLOAT_EQ(128, qp->zerop[0]);
2034 TEST(QuantizedModelVerifierTest, Pack_wrong_type_NEG)
2036 TEST_WITH_WRONG_TYPE(PackTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2037 TEST_WITH_WRONG_TYPE(PackTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2038 TEST_WITH_WRONG_TYPE(PackTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2042 TEST(QuantizedModelVerifierTest, Pack_wrong_granularity_NEG)
2044 TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::U8, Granularity::LayerWise);
2045 TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::U8, Granularity::ChannelWise);
2046 TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::S16, Granularity::ChannelWise);
2050 TEST(QuantizedModelVerifierTest, Pad)
2052 TEST_WITH_GRAPH(PadTestGraph, Type::U8, Granularity::LayerWise);
2053 TEST_WITH_GRAPH(PadTestGraph, Type::U8, Granularity::ChannelWise);
2054 TEST_WITH_GRAPH(PadTestGraph, Type::S16, Granularity::ChannelWise);
2056 TEST_WITH_LAYER_INFO(PadTestGraph, Type::U8, Granularity::LayerWise);
2057 TEST_WITH_LAYER_INFO(PadTestGraph, Type::U8, Granularity::ChannelWise);
2058 TEST_WITH_LAYER_INFO(PadTestGraph, Type::S16, Granularity::ChannelWise);
2062 TEST(QuantizedModelVerifierTest, Pad_wrong_type_NEG)
2064 TEST_WITH_WRONG_TYPE(PadTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2065 TEST_WITH_WRONG_TYPE(PadTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2066 TEST_WITH_WRONG_TYPE(PadTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2070 TEST(QuantizedModelVerifierTest, Pad_wrong_granularity_NEG)
2072 TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::U8, Granularity::LayerWise);
2073 TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::U8, Granularity::ChannelWise);
2074 TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::S16, Granularity::ChannelWise);
2078 TEST(QuantizedModelVerifierTest, PadV2)
2080 TEST_WITH_GRAPH(PadV2TestGraph, Type::U8, Granularity::LayerWise);
2081 TEST_WITH_GRAPH(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
2082 TEST_WITH_GRAPH(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
2084 TEST_WITH_LAYER_INFO(PadV2TestGraph, Type::U8, Granularity::LayerWise);
2085 TEST_WITH_LAYER_INFO(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
2086 TEST_WITH_LAYER_INFO(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
2090 TEST(QuantizedModelVerifierTest, PadV2_wrong_type_NEG)
2092 TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2093 TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2094 TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2098 TEST(QuantizedModelVerifierTest, PadV2_wrong_granularity_NEG)
2100 TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::U8, Granularity::LayerWise);
2101 TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
2102 TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
2106 TEST(QuantizedModelVerifierTest, MirrorPad)
2108 TEST_WITH_GRAPH(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
2109 TEST_WITH_GRAPH(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
2110 TEST_WITH_GRAPH(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
2112 TEST_WITH_LAYER_INFO(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
2113 TEST_WITH_LAYER_INFO(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
2114 TEST_WITH_LAYER_INFO(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
2118 TEST(QuantizedModelVerifierTest, MirrorPad_wrong_type_NEG)
2120 TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2121 TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2122 TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2126 TEST(QuantizedModelVerifierTest, MirrorPad_wrong_granularity_NEG)
2128 TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
2129 TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
2130 TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
2134 TEST(QuantizedModelVerifierTest, Transpose)
2136 TEST_WITH_GRAPH(TransposeTestGraph, Type::U8, Granularity::LayerWise);
2137 TEST_WITH_GRAPH(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
2138 TEST_WITH_GRAPH(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
2140 TEST_WITH_LAYER_INFO(TransposeTestGraph, Type::U8, Granularity::LayerWise);
2141 TEST_WITH_LAYER_INFO(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
2142 TEST_WITH_LAYER_INFO(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
2146 TEST(QuantizedModelVerifierTest, Transpose_wrong_type_NEG)
2148 TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2149 TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2150 TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2154 TEST(QuantizedModelVerifierTest, Transpose_wrong_granularity_NEG)
2156 TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::U8, Granularity::LayerWise);
2157 TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
2158 TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
2162 TEST(QuantizedModelVerifierTest, Floor)
2164 TEST_WITH_GRAPH(FloorTestGraph, Type::U8, Granularity::LayerWise);
2165 TEST_WITH_GRAPH(FloorTestGraph, Type::U8, Granularity::ChannelWise);
2166 TEST_WITH_GRAPH(FloorTestGraph, Type::S16, Granularity::ChannelWise);
2168 TEST_WITH_LAYER_INFO(FloorTestGraph, Type::U8, Granularity::LayerWise);
2169 TEST_WITH_LAYER_INFO(FloorTestGraph, Type::U8, Granularity::ChannelWise);
2170 TEST_WITH_LAYER_INFO(FloorTestGraph, Type::S16, Granularity::ChannelWise);
2174 TEST(QuantizedModelVerifierTest, Floor_wrong_type_NEG)
2176 TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2177 TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2178 TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2182 TEST(QuantizedModelVerifierTest, Floor_wrong_granularity_NEG)
2184 TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::U8, Granularity::LayerWise);
2185 TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::U8, Granularity::ChannelWise);
2186 TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::S16, Granularity::ChannelWise);
2190 TEST(QuantizedModelVerifierTest, GreaterEqual)
2192 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2193 Granularity::LayerWise);
2194 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2195 Granularity::ChannelWise);
2196 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2197 Granularity::ChannelWise);
2201 TEST(QuantizedModelVerifierTest, GreaterEqual_wrong_type_NEG)
2203 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2204 Granularity::LayerWise, Type::U8);
2205 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2206 Granularity::ChannelWise, Type::U8);
2207 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2208 Granularity::ChannelWise, Type::S16);
2212 TEST(QuantizedModelVerifierTest, GreaterEqual_wrong_granularity_NEG)
2214 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2215 Granularity::LayerWise, g.x());
2216 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2217 Granularity::ChannelWise, g.x());
2218 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2219 Granularity::ChannelWise, g.x());
2221 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2222 Granularity::LayerWise, g.y());
2223 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2224 Granularity::ChannelWise, g.y());
2225 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2226 Granularity::ChannelWise, g.y());
2230 TEST(QuantizedModelVerifierTest, Greater)
2232 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::LayerWise);
2233 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::ChannelWise);
2234 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16, Granularity::ChannelWise);
2238 TEST(QuantizedModelVerifierTest, Greater_wrong_type_NEG)
2240 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::LayerWise,
2242 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2243 Granularity::ChannelWise, Type::U8);
2244 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
2245 Granularity::ChannelWise, Type::S16);
2249 TEST(QuantizedModelVerifierTest, Greater_wrong_granularity_NEG)
2251 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2252 Granularity::LayerWise, g.x());
2253 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2254 Granularity::ChannelWise, g.x());
2255 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
2256 Granularity::ChannelWise, g.x());
2258 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2259 Granularity::LayerWise, g.y());
2260 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2261 Granularity::ChannelWise, g.y());
2262 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
2263 Granularity::ChannelWise, g.y());
2267 TEST(QuantizedModelVerifierTest, NotEqual)
2269 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8, Granularity::LayerWise);
2270 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8, Granularity::ChannelWise);
2271 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16, Granularity::ChannelWise);
2275 TEST(QuantizedModelVerifierTest, NotEqual_wrong_type_NEG)
2277 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2278 Granularity::LayerWise, Type::U8);
2279 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2280 Granularity::ChannelWise, Type::U8);
2281 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
2282 Granularity::ChannelWise, Type::S16);
2286 TEST(QuantizedModelVerifierTest, NotEqual_wrong_granularity_NEG)
2288 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2289 Granularity::LayerWise, g.x());
2290 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2291 Granularity::ChannelWise, g.x());
2292 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
2293 Granularity::ChannelWise, g.x());
2295 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2296 Granularity::LayerWise, g.y());
2297 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2298 Granularity::ChannelWise, g.y());
2299 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
2300 Granularity::ChannelWise, g.y());
2304 TEST(QuantizedModelVerifierTest, OneHot)
2306 TEST_WITH_GRAPH(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2307 TEST_WITH_GRAPH(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2308 TEST_WITH_GRAPH(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2310 TEST_WITH_GRAPH(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2311 TEST_WITH_GRAPH(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2312 TEST_WITH_GRAPH(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2314 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2315 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2316 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2318 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2319 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2320 TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2324 TEST(QuantizedModelVerifierTest, OneHot_wrong_input_type_NEG)
2326 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
2327 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
2328 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
2330 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
2331 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
2332 TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
2336 TEST(QuantizedModelVerifierTest, OneHot_wrong_granularity_NEG)
2338 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2339 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2340 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2342 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2343 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2344 TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2348 TEST(QuantizedModelVerifierTest, Div)
2350 TEST_WITH_GRAPH(DivTestGraph, Type::U8, Granularity::LayerWise);
2351 TEST_WITH_GRAPH(DivTestGraph, Type::U8, Granularity::ChannelWise);
2352 TEST_WITH_GRAPH(DivTestGraph, Type::S16, Granularity::ChannelWise);
2354 TEST_WITH_LAYER_INFO(DivTestGraph, Type::U8, Granularity::LayerWise);
2355 TEST_WITH_LAYER_INFO(DivTestGraph, Type::U8, Granularity::ChannelWise);
2356 TEST_WITH_LAYER_INFO(DivTestGraph, Type::S16, Granularity::ChannelWise);
2360 TEST(QuantizedModelVerifierTest, Div_wrong_type_NEG)
2362 TEST_WITH_WRONG_TYPE(DivTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2363 TEST_WITH_WRONG_TYPE(DivTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2364 TEST_WITH_WRONG_TYPE(DivTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2368 TEST(QuantizedModelVerifierTest, Div_wrong_granularity_NEG)
2370 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::LayerWise, g.x());
2371 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2372 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2374 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::LayerWise, g.y());
2375 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2376 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2380 TEST(QuantizedModelVerifierTest, FloorDiv)
2382 TEST_WITH_GRAPH(FloorDivTestGraph, Type::U8, Granularity::LayerWise);
2383 TEST_WITH_GRAPH(FloorDivTestGraph, Type::U8, Granularity::ChannelWise);
2384 TEST_WITH_GRAPH(FloorDivTestGraph, Type::S16, Granularity::ChannelWise);
2386 TEST_WITH_LAYER_INFO(FloorDivTestGraph, Type::U8, Granularity::LayerWise);
2387 TEST_WITH_LAYER_INFO(FloorDivTestGraph, Type::U8, Granularity::ChannelWise);
2388 TEST_WITH_LAYER_INFO(FloorDivTestGraph, Type::S16, Granularity::ChannelWise);
2392 TEST(QuantizedModelVerifierTest, FloorDiv_wrong_type_NEG)
2394 TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2395 TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2396 TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2400 TEST(QuantizedModelVerifierTest, FloorDiv_wrong_granularity_NEG)
2402 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::LayerWise, g.x());
2403 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2404 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2406 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::LayerWise, g.y());
2407 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2408 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2412 TEST(QuantizedModelVerifierTest, Rsqrt)
2414 TEST_WITH_GRAPH(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
2415 TEST_WITH_GRAPH(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
2416 TEST_WITH_GRAPH(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
2418 TEST_WITH_LAYER_INFO(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
2419 TEST_WITH_LAYER_INFO(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
2420 TEST_WITH_LAYER_INFO(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
2424 TEST(QuantizedModelVerifierTest, Rsqrt_wrong_type_NEG)
2426 TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2427 TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2428 TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2432 TEST(QuantizedModelVerifierTest, Rsqrt_wrong_granularity_NEG)
2434 TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
2435 TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
2436 TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
2440 TEST(QuantizedModelVerifierTest, Sqrt)
2442 TEST_WITH_GRAPH(SqrtTestGraph, Type::U8, Granularity::LayerWise);
2443 TEST_WITH_GRAPH(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
2444 TEST_WITH_GRAPH(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
2446 TEST_WITH_LAYER_INFO(SqrtTestGraph, Type::U8, Granularity::LayerWise);
2447 TEST_WITH_LAYER_INFO(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
2448 TEST_WITH_LAYER_INFO(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
2452 TEST(QuantizedModelVerifierTest, Sqrt_wrong_type_NEG)
2454 TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2455 TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2456 TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2460 TEST(QuantizedModelVerifierTest, Sqrt_wrong_granularity_NEG)
2462 TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::U8, Granularity::LayerWise);
2463 TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
2464 TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
2468 TEST(QuantizedModelVerifierTest, Elu)
2470 TEST_WITH_GRAPH(EluTestGraph, Type::U8, Granularity::LayerWise);
2471 TEST_WITH_GRAPH(EluTestGraph, Type::U8, Granularity::ChannelWise);
2472 TEST_WITH_GRAPH(EluTestGraph, Type::S16, Granularity::ChannelWise);
2474 TEST_WITH_LAYER_INFO(EluTestGraph, Type::U8, Granularity::LayerWise);
2475 TEST_WITH_LAYER_INFO(EluTestGraph, Type::U8, Granularity::ChannelWise);
2476 TEST_WITH_LAYER_INFO(EluTestGraph, Type::S16, Granularity::ChannelWise);
2480 TEST(QuantizedModelVerifierTest, Elu_wrong_type_NEG)
2482 TEST_WITH_WRONG_TYPE(EluTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2483 TEST_WITH_WRONG_TYPE(EluTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2484 TEST_WITH_WRONG_TYPE(EluTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2488 TEST(QuantizedModelVerifierTest, Elu_wrong_granularity_NEG)
2490 TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::U8, Granularity::LayerWise);
2491 TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::U8, Granularity::ChannelWise);
2492 TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::S16, Granularity::ChannelWise);
2496 TEST(QuantizedModelVerifierTest, Pow)
2498 TEST_WITH_GRAPH(PowTestGraph, Type::U8, Granularity::LayerWise);
2499 TEST_WITH_GRAPH(PowTestGraph, Type::U8, Granularity::ChannelWise);
2500 TEST_WITH_GRAPH(PowTestGraph, Type::S16, Granularity::ChannelWise);
2502 TEST_WITH_LAYER_INFO(PowTestGraph, Type::U8, Granularity::LayerWise);
2503 TEST_WITH_LAYER_INFO(PowTestGraph, Type::U8, Granularity::ChannelWise);
2504 TEST_WITH_LAYER_INFO(PowTestGraph, Type::S16, Granularity::ChannelWise);
2508 TEST(QuantizedModelVerifierTest, Pow_wrong_type_NEG)
2510 TEST_WITH_WRONG_TYPE(PowTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2511 TEST_WITH_WRONG_TYPE(PowTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2512 TEST_WITH_WRONG_TYPE(PowTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2516 TEST(QuantizedModelVerifierTest, Pow_wrong_granularity_NEG)
2518 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::LayerWise, g.x());
2519 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2520 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2522 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::LayerWise, g.y());
2523 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2524 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2528 TEST(QuantizedModelVerifierTest, ReduceMax)
2530 TEST_WITH_GRAPH(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise);
2531 TEST_WITH_GRAPH(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise);
2532 TEST_WITH_GRAPH(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise);
2534 TEST_WITH_LAYER_INFO(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise);
2535 TEST_WITH_LAYER_INFO(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise);
2536 TEST_WITH_LAYER_INFO(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise);
2540 TEST(QuantizedModelVerifierTest, ReduceMax_wrong_type_NEG)
2542 TEST_WITH_WRONG_TYPE(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2543 TEST_WITH_WRONG_TYPE(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2544 TEST_WITH_WRONG_TYPE(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2548 TEST(QuantizedModelVerifierTest, ReduceMax_wrong_granularity_NEG)
2550 TEST_WITH_WRONG_GRANULARITY(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise);
2551 TEST_WITH_WRONG_GRANULARITY(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise);
2552 TEST_WITH_WRONG_GRANULARITY(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise);
2556 TEST(QuantizedModelVerifierTest, ResizeBilinear)
2558 TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2559 TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2560 TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2562 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2563 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2564 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2568 TEST(QuantizedModelVerifierTest, ResizeBilinear_wrong_type_NEG)
2570 TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2571 TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2572 TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2576 TEST(QuantizedModelVerifierTest, ResizeBilinear_wrong_granularity_NEG)
2578 TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2579 TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2580 TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2584 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor)
2586 TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise);
2587 TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise);
2588 TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise);
2590 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2591 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2592 TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2596 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor_wrong_type_NEG)
2598 TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2599 TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise,
2601 TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise,
2606 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor_wrong_granularity_NEG)
2608 TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise);
2609 TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise);
2610 TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise);
2614 TEST(QuantizedModelVerifierTest, Unpack)
2616 TEST_WITH_GRAPH(UnpackTestGraph, Type::U8, Granularity::LayerWise);
2617 TEST_WITH_GRAPH(UnpackTestGraph, Type::U8, Granularity::ChannelWise);
2618 TEST_WITH_GRAPH(UnpackTestGraph, Type::S16, Granularity::ChannelWise);
2622 TEST(QuantizedModelVerifierTest, Unpack_wrong_type_NEG)
2624 TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2625 TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2626 TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2630 TEST(QuantizedModelVerifierTest, Unpack_wrong_granularity_NEG)
2632 TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::U8, Granularity::LayerWise);
2633 TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::U8, Granularity::ChannelWise);
2634 TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::S16, Granularity::ChannelWise);
2638 TEST(QuantizedModelVerifierTest, Add)
2640 TEST_WITH_GRAPH(AddTestGraph, Type::U8, Granularity::LayerWise);
2641 TEST_WITH_GRAPH(AddTestGraph, Type::U8, Granularity::ChannelWise);
2642 TEST_WITH_GRAPH(AddTestGraph, Type::S16, Granularity::ChannelWise);
2644 TEST_WITH_LAYER_INFO(AddTestGraph, Type::U8, Granularity::LayerWise);
2645 TEST_WITH_LAYER_INFO(AddTestGraph, Type::U8, Granularity::ChannelWise);
2646 TEST_WITH_LAYER_INFO(AddTestGraph, Type::S16, Granularity::ChannelWise);
2650 TEST(QuantizedModelVerifierTest, Add_wrong_type_NEG)
2652 TEST_WITH_WRONG_TYPE(AddTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2653 TEST_WITH_WRONG_TYPE(AddTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2654 TEST_WITH_WRONG_TYPE(AddTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2658 TEST(QuantizedModelVerifierTest, Add_wrong_granularity_NEG)
2660 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::LayerWise, g.x());
2661 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2662 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2664 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::LayerWise, g.y());
2665 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2666 TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2670 TEST(QuantizedModelVerifierTest, Add_inttype)
2673 TEST_WITH_GRAPH(IntAddTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2674 TEST_WITH_GRAPH(IntAddTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2675 TEST_WITH_GRAPH(IntAddTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2677 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2678 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2679 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2682 TEST_WITH_GRAPH(IntAddTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2683 TEST_WITH_GRAPH(IntAddTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2684 TEST_WITH_GRAPH(IntAddTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2686 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2687 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2688 TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2693 TEST(QuantizedModelVerifierTest, Mul)
2695 TEST_WITH_GRAPH(MulTestGraph, Type::U8, Granularity::LayerWise);
2696 TEST_WITH_GRAPH(MulTestGraph, Type::U8, Granularity::ChannelWise);
2697 TEST_WITH_GRAPH(MulTestGraph, Type::S16, Granularity::ChannelWise);
2699 TEST_WITH_LAYER_INFO(MulTestGraph, Type::U8, Granularity::LayerWise);
2700 TEST_WITH_LAYER_INFO(MulTestGraph, Type::U8, Granularity::ChannelWise);
2701 TEST_WITH_LAYER_INFO(MulTestGraph, Type::S16, Granularity::ChannelWise);
2705 TEST(QuantizedModelVerifierTest, Mul_wrong_type_NEG)
2707 TEST_WITH_WRONG_TYPE(MulTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2708 TEST_WITH_WRONG_TYPE(MulTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2709 TEST_WITH_WRONG_TYPE(MulTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2713 TEST(QuantizedModelVerifierTest, Mul_wrong_granularity_NEG)
2715 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::LayerWise, g.x());
2716 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2717 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2719 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::LayerWise, g.y());
2720 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2721 TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2725 TEST(QuantizedModelVerifierTest, Mul_inttype)
2728 TEST_WITH_GRAPH(IntMulTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2729 TEST_WITH_GRAPH(IntMulTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2730 TEST_WITH_GRAPH(IntMulTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2732 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2733 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2734 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2737 TEST_WITH_GRAPH(IntMulTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2738 TEST_WITH_GRAPH(IntMulTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2739 TEST_WITH_GRAPH(IntMulTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2741 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2742 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2743 TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2748 // TODO Add following testcases
2752 // CircleDepthwiseConv2D
2756 // CircleTransposeConv
2758 // CircleFullyConnected
2760 // CircleAveragePool2D
2771 #undef TEST_WITH_GRAPH
2772 #undef TEST_WITH_WRONG_TYPE
2773 #undef TEST_WITH_WRONG_GRANULARITY