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"
21 #include <luci/test/TestIOGraph.h>
23 #include <gtest/gtest.h>
25 using Type = loco::DataType;
26 using Granularity = luci::QuantizationGranularity;
32 * @brief A helper function to create dummy const node
34 template <Type T> luci::CircleConst *create_dummy_const(loco::Graph *g, luci::test::ShapeU32 shape)
36 auto node = g->nodes()->create<luci::CircleConst>();
40 node->size<T>(luci::test::num_elements(shape));
42 for (int32_t i = 0; i < luci::test::num_elements(shape); i++)
46 // Filling with any random numbers are fine
47 // Q. Should it include minus numbers?
52 node->at<T>(i) = static_cast<float>(i);
56 node->at<T>(i) = (i % 2) ? true : false;
60 node->at<T>(i) = static_cast<uint8_t>(i);
64 node->at<T>(i) = static_cast<int16_t>(i);
74 * @brief A helper function to create const node with value
76 template <Type DT, typename T>
77 luci::CircleConst *create_const(loco::Graph *g, luci::test::ShapeU32 shape,
78 std::initializer_list<T> values)
80 auto node = g->nodes()->create<luci::CircleConst>();
84 node->size<DT>(luci::test::num_elements(shape));
86 assert(values.size() == node->size<DT>());
89 for (auto val : values)
91 node->at<DT>(index++) = static_cast<T>(val);
98 void insert_scale_zp(luci::CircleNode *node, float scale, int64_t zp)
100 auto qparam = node->quantparam();
101 assert(qparam != nullptr); // FIX_CALLER_UNLESS
102 qparam->scale.push_back(scale);
103 qparam->zerop.push_back(zp);
106 void quantize_and_verify(loco::Graph *g, Type quantized_dtype, Granularity granularity)
108 luci::QuantizeWithMinMaxPass pass(Type::FLOAT32, quantized_dtype, granularity);
111 luci::QuantizedModelVerifier verifier(quantized_dtype, granularity);
115 // Helper function to reduce duplicate test codes
116 // Assumption: g->output()->from() is the target node
117 void quantize_and_verify_with_wrong_type(luci::test::TestIOGraph *g, Type quantized_dtype,
118 Granularity granularity, Type wrong_dtype)
120 luci::QuantizeWithMinMaxPass pass(Type::FLOAT32, quantized_dtype, granularity);
123 auto node = loco::must_cast<luci::CircleNode *>(g->output()->from());
124 node->dtype(wrong_dtype);
126 luci::QuantizedModelVerifier verifier(quantized_dtype, granularity);
127 verifier.verify(g->g());
130 void quantize_and_verify_with_wrong_type(luci::test::TestIOGraph *g, Type quantized_dtype,
131 Granularity granularity, Type wrong_dtype,
132 luci::CircleNode *target)
134 luci::QuantizeWithMinMaxPass pass(Type::FLOAT32, quantized_dtype, granularity);
137 target->dtype(wrong_dtype);
139 luci::QuantizedModelVerifier verifier(quantized_dtype, granularity);
140 verifier.verify(g->g());
143 // Helper function to reduce duplicate test codes
144 // Assumption: g->output()->from() is the target node
145 void quantize_and_verify_with_wrong_granularity(luci::test::TestIOGraph *g, Type quantized_dtype,
146 Granularity granularity)
148 luci::QuantizeWithMinMaxPass pass(Type::FLOAT32, quantized_dtype, granularity);
151 auto node = loco::must_cast<luci::CircleNode *>(g->output()->from());
152 insert_scale_zp(node, 1.0, 1);
154 luci::QuantizedModelVerifier verifier(quantized_dtype, granularity);
155 verifier.verify(g->g());
158 // Helper function to reduce duplicate test codes
159 void quantize_and_verify_with_wrong_granularity(luci::test::TestIOGraph *g, Type quantized_dtype,
160 Granularity granularity, luci::CircleNode *target)
162 luci::QuantizeWithMinMaxPass pass(Type::FLOAT32, quantized_dtype, granularity);
165 insert_scale_zp(target, 1.0, 1);
167 luci::QuantizedModelVerifier verifier(quantized_dtype, granularity);
168 verifier.verify(g->g());
171 // Set min/max for all non-const nodes in the graph
172 void set_minmax_to_non_const(loco::Graph *g, float min, float max)
174 for (auto node : loco::all_nodes(g))
176 auto const_node = dynamic_cast<luci::CircleConst *>(node);
177 if (const_node != nullptr)
180 // Min/Max is not recorded for ArgMax
181 // See MinMaxObserver.cpp in record_minmax module
182 auto argmax_node = dynamic_cast<luci::CircleArgMax *>(node);
183 if (argmax_node != nullptr)
186 // Min/Max is not recorded for Split
187 // See MinMaxObserver.cpp in record_minmax module
188 auto split_node = dynamic_cast<luci::CircleSplit *>(node);
189 if (split_node != nullptr)
192 // Min/Max is not recorded for SplitV
193 // See MinMaxObserver.cpp in record_minmax module
194 auto splitv_node = dynamic_cast<luci::CircleSplitV *>(node);
195 if (splitv_node != nullptr)
198 auto circle_node = loco::must_cast<luci::CircleNode *>(node);
199 auto qparam = std::make_unique<luci::CircleQuantParam>();
201 qparam->min.emplace_back(min);
202 qparam->max.emplace_back(max);
204 circle_node->quantparam(std::move(qparam));
209 * @brief Simple Test Graph
211 * The simple test graph's nodes are initialized with
212 * simple shapes and values.
214 class SimpleTestGraph : public luci::test::TestIOGraph
217 virtual void init(void) = 0;
220 class InstanceNormTestGraph final : public SimpleTestGraph
223 void init(void) override
225 TestIOGraph::init({32}, {32});
226 _gamma = create_dummy_const<Type::FLOAT32>(g(), {32});
227 _beta = create_dummy_const<Type::FLOAT32>(g(), {32});
228 _instnorm = g()->nodes()->create<luci::CircleInstanceNorm>();
230 _instnorm->input(input());
231 _instnorm->gamma(_gamma);
232 _instnorm->beta(_beta);
234 output()->from(_instnorm);
236 set_minmax_to_non_const(g(), -1, 1);
240 loco::Node *gamma(void) const { return _instnorm->gamma(); }
241 loco::Node *beta(void) const { return _instnorm->beta(); }
244 luci::CircleInstanceNorm *_instnorm = nullptr;
245 luci::CircleConst *_input = nullptr;
246 luci::CircleConst *_gamma = nullptr;
247 luci::CircleConst *_beta = nullptr;
250 class LogisticTestGraph final : public SimpleTestGraph
253 void init(void) override
255 TestIOGraph::init({32}, {32});
256 _logistic = g()->nodes()->create<luci::CircleLogistic>();
258 _logistic->x(input());
260 output()->from(_logistic);
262 set_minmax_to_non_const(g(), -1, 1);
266 luci::CircleLogistic *_logistic = nullptr;
269 class LocalResponseNormalizationTestGraph final : public SimpleTestGraph
272 void init(void) override
274 TestIOGraph::init({1, 2, 2, 32}, {1, 2, 2, 32});
275 _lrn = g()->nodes()->create<luci::CircleLocalResponseNormalization>();
277 _lrn->input(input());
279 output()->from(_lrn);
281 set_minmax_to_non_const(g(), -1, 1);
285 luci::CircleLocalResponseNormalization *_lrn = nullptr;
288 class SoftmaxTestGraph final : public SimpleTestGraph
291 void init(void) override
293 TestIOGraph::init({32}, {32});
294 _softmax = g()->nodes()->create<luci::CircleSoftmax>();
296 _softmax->logits(input());
299 output()->from(_softmax);
301 set_minmax_to_non_const(g(), -1, 1);
305 luci::CircleSoftmax *_softmax = nullptr;
308 class SpaceToBatchNDTestGraph final : public SimpleTestGraph
311 void init(void) override
313 TestIOGraph::init({1, 2, 2, 1}, {4, 1, 1, 1});
314 _block_shape = create_dummy_const<Type::S32>(g(), {2});
315 for (uint32_t i = 0; i < 2; i++)
316 _block_shape->at<Type::S32>(i) = 2;
318 _paddings = create_dummy_const<Type::S32>(g(), {2, 2});
319 for (uint32_t i = 0; i < 4; i++)
320 _paddings->at<Type::S32>(i) = 0;
322 _stob = g()->nodes()->create<luci::CircleSpaceToBatchND>();
324 _stob->input(input());
325 _stob->block_shape(_block_shape);
326 _stob->paddings(_paddings);
328 output()->from(_stob);
330 set_minmax_to_non_const(g(), -1, 1);
334 luci::CircleSpaceToBatchND *_stob = nullptr;
335 luci::CircleConst *_block_shape = nullptr;
336 luci::CircleConst *_paddings = nullptr;
339 class SpaceToDepthTestGraph final : public SimpleTestGraph
342 void init(void) override
344 TestIOGraph::init({1, 2, 2, 1}, {1, 1, 1, 4});
345 _stod = g()->nodes()->create<luci::CircleSpaceToDepth>();
347 _stod->input(input());
348 _stod->block_size(2);
350 output()->from(_stod);
352 set_minmax_to_non_const(g(), -1, 1);
356 luci::CircleSpaceToDepth *_stod = nullptr;
359 template <Type indexT> class SliceTestGraph final : public SimpleTestGraph
362 void init(void) override
364 TestIOGraph::init({32}, {32});
365 _begin = g()->nodes()->create<luci::CircleConst>();
367 _begin->dtype(indexT);
369 _size = g()->nodes()->create<luci::CircleConst>();
371 _size->dtype(indexT);
373 _slice = g()->nodes()->create<luci::CircleSlice>();
375 _slice->input(input());
376 _slice->begin(_begin);
379 output()->from(_slice);
381 set_minmax_to_non_const(g(), -1, 1);
385 luci::CircleSlice *_slice = nullptr;
386 luci::CircleConst *_begin = nullptr;
387 luci::CircleConst *_size = nullptr;
390 class SplitTestGraph final : public luci::test::TestIOGraph
395 TestIOGraph::init({1, 32}, {32});
396 _split_dim = create_dummy_const<Type::S32>(g(), {1});
397 _split = g()->nodes()->create<luci::CircleSplit>();
399 _split->input(input());
400 _split->split_dim(_split_dim);
402 _split_o1 = g()->nodes()->create<luci::CircleSplitOut>();
404 _split_o1->input(_split);
408 output()->from(_split_o1);
410 set_minmax_to_non_const(g(), -1, 1);
414 luci::CircleSplit *_split = nullptr;
415 luci::CircleSplitOut *_split_o1 = nullptr;
416 luci::CircleConst *_split_dim = nullptr;
419 class SplitVTestGraph final : public luci::test::TestIOGraph
424 TestIOGraph::init({1, 32}, {32});
425 _size_splits = create_dummy_const<Type::S32>(g(), {1});
426 _split_dim = create_dummy_const<Type::S32>(g(), {1});
427 _splitv = g()->nodes()->create<luci::CircleSplitV>();
429 _splitv->input(input());
430 _splitv->size_splits(_size_splits);
431 _splitv->split_dim(_split_dim);
433 _splitv_o1 = g()->nodes()->create<luci::CircleSplitVOut>();
435 _splitv_o1->input(_splitv);
436 _splitv_o1->index(0);
439 output()->from(_splitv_o1);
441 set_minmax_to_non_const(g(), -1, 1);
445 luci::CircleSplitV *_splitv = nullptr;
446 luci::CircleSplitVOut *_splitv_o1 = nullptr;
447 luci::CircleConst *_size_splits = nullptr;
448 luci::CircleConst *_split_dim = nullptr;
451 class StridedSliceTestGraph final : public SimpleTestGraph
454 void init(void) override
456 TestIOGraph::init({32}, {32});
457 _begin = g()->nodes()->create<luci::CircleConst>();
459 _begin->dtype(Type::S32);
461 _end = g()->nodes()->create<luci::CircleConst>();
463 _end->dtype(Type::S32);
465 _strides = g()->nodes()->create<luci::CircleConst>();
467 _strides->dtype(Type::S32);
469 _slice = g()->nodes()->create<luci::CircleStridedSlice>();
471 _slice->input(input());
472 _slice->begin(_begin);
474 _slice->strides(_strides);
476 output()->from(_slice);
478 set_minmax_to_non_const(g(), -1, 1);
482 luci::CircleStridedSlice *_slice = nullptr;
483 luci::CircleConst *_begin = nullptr;
484 luci::CircleConst *_end = nullptr;
485 luci::CircleConst *_strides = nullptr;
488 class ReshapeTestGraph final : public SimpleTestGraph
491 void init(void) override
493 TestIOGraph::init({32}, {32});
494 _shape = g()->nodes()->create<luci::CircleConst>();
496 _shape->dtype(Type::S32);
498 _reshape = g()->nodes()->create<luci::CircleReshape>();
500 _reshape->tensor(input());
501 _reshape->shape(_shape);
503 output()->from(_reshape);
505 set_minmax_to_non_const(g(), -1, 1);
509 luci::CircleReshape *_reshape = nullptr;
510 luci::CircleConst *_shape = nullptr;
513 class TanhTestGraph final : public SimpleTestGraph
516 void init(void) override
518 TestIOGraph::init({32}, {32});
519 _tanh = g()->nodes()->create<luci::CircleTanh>();
523 output()->from(_tanh);
525 set_minmax_to_non_const(g(), -1, 1);
529 luci::CircleTanh *_tanh = nullptr;
532 class FloorTestGraph final : public SimpleTestGraph
535 void init(void) override
537 TestIOGraph::init({32}, {32});
538 _floor = g()->nodes()->create<luci::CircleFloor>();
542 output()->from(_floor);
544 set_minmax_to_non_const(g(), -1, 1);
548 luci::CircleFloor *_floor = nullptr;
551 template <Type indexT> class ArgMaxTestGraph final : public SimpleTestGraph
554 void init(void) override
556 TestIOGraph::init({32}, {1});
557 // output dtype is float by default, but ArgMax should have indexType (s32/s64)
558 output()->dtype(indexT);
559 _dimension = g()->nodes()->create<luci::CircleConst>();
561 _dimension->dtype(indexT);
563 _argmax = g()->nodes()->create<luci::CircleArgMax>();
565 _argmax->input(input());
566 _argmax->dimension(_dimension);
567 _argmax->output_type(indexT);
568 _argmax->dtype(indexT);
570 output()->from(_argmax);
572 set_minmax_to_non_const(g(), -1, 1);
576 // NOTE: Do not override `luci::CircleNode* input(void)` incidentally
577 loco::Node *input_argmax(void) { return _argmax->input(); }
578 loco::Node *dimension(void) { return _argmax->dimension(); }
581 luci::CircleArgMax *_argmax = nullptr;
582 luci::CircleConst *_dimension = nullptr;
585 class BatchToSpaceNDTestGraph final : public SimpleTestGraph
588 void init(void) override
590 TestIOGraph::init({32}, {32});
591 _block_shape = g()->nodes()->create<luci::CircleConst>();
593 _block_shape->dtype(Type::S32);
595 _crops = g()->nodes()->create<luci::CircleConst>();
597 _crops->dtype(Type::S32);
599 _btos = g()->nodes()->create<luci::CircleBatchToSpaceND>();
601 _btos->input(input());
602 _btos->block_shape(_block_shape);
603 _btos->crops(_crops);
605 output()->from(_btos);
607 set_minmax_to_non_const(g(), -1, 1);
611 luci::CircleBatchToSpaceND *_btos = nullptr;
612 luci::CircleConst *_block_shape = nullptr;
613 luci::CircleConst *_crops = nullptr;
616 class DepthToSpaceTestGraph final : public SimpleTestGraph
619 void init(void) override
621 TestIOGraph::init({1, 1, 1, 4}, {1, 2, 2, 1});
622 _dtos = g()->nodes()->create<luci::CircleDepthToSpace>();
624 _dtos->input(input());
625 _dtos->block_size(2);
627 output()->from(_dtos);
629 set_minmax_to_non_const(g(), -1, 1);
633 luci::CircleDepthToSpace *_dtos = nullptr;
636 class PackTestGraph final : public SimpleTestGraph
639 void init(void) override
641 TestIOGraph::init({16}, {32});
642 _param = create_dummy_const<Type::FLOAT32>(g(), {16});
643 _pack = g()->nodes()->create<luci::CirclePack>(2);
645 _pack->values(0, input());
646 _pack->values(1, _param);
649 output()->from(_pack);
651 set_minmax_to_non_const(g(), -1, 1);
653 // Set min/max of the input
654 // pack's qparam will be propagted, overwritten to the input
655 auto input = loco::must_cast<luci::CircleNode *>(pack()->values(0));
656 auto qp = input->quantparam();
662 luci::CirclePack *pack(void) { return _pack; }
665 luci::CirclePack *_pack = nullptr;
666 luci::CircleConst *_param = nullptr;
669 class PadTestGraph final : public SimpleTestGraph
672 void init(void) override
674 TestIOGraph::init({32}, {32});
675 _paddings = g()->nodes()->create<luci::CircleConst>();
677 _paddings->dtype(Type::S32);
679 _pad = g()->nodes()->create<luci::CirclePad>();
681 _pad->input(input());
682 _pad->paddings(_paddings);
684 output()->from(_pad);
686 set_minmax_to_non_const(g(), -1, 1);
690 luci::CirclePad *_pad = nullptr;
691 luci::CircleConst *_paddings = nullptr;
694 class PadV2TestGraph final : public SimpleTestGraph
697 void init(void) override
699 TestIOGraph::init({32}, {32});
700 _paddings = g()->nodes()->create<luci::CircleConst>();
702 _paddings->dtype(Type::S32);
704 _constant_values = create_dummy_const<Type::FLOAT32>(g(), {1});
705 _pad = g()->nodes()->create<luci::CirclePadV2>();
707 _pad->input(input());
708 _pad->paddings(_paddings);
709 _pad->constant_values(_constant_values);
711 output()->from(_pad);
713 set_minmax_to_non_const(g(), -1, 1);
717 luci::CirclePadV2 *_pad = nullptr;
718 luci::CircleConst *_paddings = nullptr;
719 luci::CircleConst *_constant_values = nullptr;
722 class MirrorPadTestGraph final : public SimpleTestGraph
725 void init(void) override
727 TestIOGraph::init({32}, {32});
728 _paddings = g()->nodes()->create<luci::CircleConst>();
730 _paddings->dtype(Type::S32);
732 _constant_values = create_dummy_const<Type::FLOAT32>(g(), {1});
733 _mirror_pad = g()->nodes()->create<luci::CircleMirrorPad>();
735 _mirror_pad->input(input());
736 _mirror_pad->paddings(_paddings);
737 _mirror_pad->mode(luci::MirrorPadMode::REFLECT);
739 output()->from(_mirror_pad);
741 set_minmax_to_non_const(g(), -1, 1);
745 luci::CircleMirrorPad *_mirror_pad = nullptr;
746 luci::CircleConst *_paddings = nullptr;
747 luci::CircleConst *_constant_values = nullptr;
750 class TransposeTestGraph final : public SimpleTestGraph
753 void init(void) override
755 TestIOGraph::init({32}, {32});
756 _perm = g()->nodes()->create<luci::CircleConst>();
758 _perm->dtype(Type::S32);
760 _transpose = g()->nodes()->create<luci::CircleTranspose>();
762 _transpose->a(input());
763 _transpose->perm(_perm);
765 output()->from(_transpose);
767 set_minmax_to_non_const(g(), -1, 1);
771 luci::CircleTranspose *_transpose = nullptr;
772 luci::CircleConst *_perm = nullptr;
775 class ConcatenationTestGraph final : public SimpleTestGraph
778 void init(void) override
780 TestIOGraph::init({16}, {32});
781 _param = create_dummy_const<Type::FLOAT32>(g(), {16});
782 _concat = g()->nodes()->create<luci::CircleConcatenation>(2);
784 _concat->values(0, input());
785 _concat->values(1, _param);
788 output()->from(_concat);
790 set_minmax_to_non_const(g(), -1, 1);
794 luci::CircleConcatenation *_concat = nullptr;
795 luci::CircleConst *_param = nullptr;
798 // Test graph for comparison Ops
799 // GREATER, GREATER_EQUAL, LESS, LESS_EQUAL, EQUAL, NOT_EQUAL
800 template <class Op> class ComparisonOpTestGraph final : public SimpleTestGraph
803 void init(void) override
805 TestIOGraph::init({32}, {32});
806 output()->dtype(loco::DataType::BOOL);
807 _y = create_dummy_const<Type::FLOAT32>(g(), {32});
808 _op = g()->nodes()->create<Op>();
812 _op->dtype(loco::DataType::BOOL);
816 set_minmax_to_non_const(g(), -1, 1);
819 loco::Node *x(void) const { return _op->x(); }
820 loco::Node *y(void) const { return _op->y(); }
824 luci::CircleConst *_y = nullptr;
827 // Test graph for binary logical Ops
828 // LOGICAL_OR, LOGICAL_AND
829 template <class Op> class BinaryLogicalOpTestGraph final : public SimpleTestGraph
832 void init(void) override
834 TestIOGraph::init({32}, {32});
835 input()->dtype(loco::DataType::BOOL);
836 output()->dtype(loco::DataType::BOOL);
837 _y = create_dummy_const<Type::BOOL>(g(), {32});
838 _op = g()->nodes()->create<Op>();
842 _op->dtype(loco::DataType::BOOL);
846 set_minmax_to_non_const(g(), -1, 1);
849 loco::Node *x(void) const { return _op->x(); }
850 loco::Node *y(void) const { return _op->y(); }
854 luci::CircleConst *_y = nullptr;
857 class DivTestGraph final : public SimpleTestGraph
860 void init(void) override
862 TestIOGraph::init({32}, {32});
864 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
865 _div = g()->nodes()->create<luci::CircleDiv>();
870 output()->from(_div);
872 set_minmax_to_non_const(g(), -1, 1);
875 loco::Node *x() { return _div->x(); }
877 loco::Node *y() { return _div->y(); }
880 luci::CircleDiv *_div = nullptr;
881 luci::CircleConst *_const = nullptr;
884 class FloorDivTestGraph final : public SimpleTestGraph
887 void init(void) override
889 TestIOGraph::init({32}, {32});
891 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
892 _floor_div = g()->nodes()->create<luci::CircleFloorDiv>();
894 _floor_div->x(input());
895 _floor_div->y(_const);
897 output()->from(_floor_div);
899 set_minmax_to_non_const(g(), -1, 1);
902 loco::Node *x() { return _floor_div->x(); }
904 loco::Node *y() { return _floor_div->y(); }
907 luci::CircleFloorDiv *_floor_div = nullptr;
908 luci::CircleConst *_const = nullptr;
911 class RsqrtTestGraph final : public SimpleTestGraph
914 void init(void) override
916 TestIOGraph::init({32}, {32});
917 _rsqrt = g()->nodes()->create<luci::CircleRsqrt>();
921 output()->from(_rsqrt);
923 set_minmax_to_non_const(g(), -1, 1);
927 luci::CircleRsqrt *_rsqrt = nullptr;
930 class SqrtTestGraph final : public SimpleTestGraph
933 void init(void) override
935 TestIOGraph::init({32}, {32});
936 _sqrt = g()->nodes()->create<luci::CircleSqrt>();
940 output()->from(_sqrt);
942 set_minmax_to_non_const(g(), -1, 1);
946 luci::CircleSqrt *_sqrt = nullptr;
949 class EluTestGraph final : public SimpleTestGraph
952 void init(void) override
954 TestIOGraph::init({32}, {32});
955 _elu = g()->nodes()->create<luci::CircleElu>();
957 _elu->features(input());
959 output()->from(_elu);
961 set_minmax_to_non_const(g(), -1, 1);
965 luci::CircleElu *_elu = nullptr;
968 class PowTestGraph final : public SimpleTestGraph
971 void init(void) override
973 TestIOGraph::init({32}, {32});
975 _const = create_dummy_const<Type::FLOAT32>(g(), {32});
976 _pow = g()->nodes()->create<luci::CirclePow>();
981 output()->from(_pow);
983 set_minmax_to_non_const(g(), -1, 1);
986 loco::Node *x() { return _pow->x(); }
988 loco::Node *y() { return _pow->y(); }
991 luci::CirclePow *_pow = nullptr;
992 luci::CircleConst *_const = nullptr;
995 class ResizeBilinearTestGraph final : public SimpleTestGraph
998 void init(void) override
1000 TestIOGraph::init({1, 4, 4, 1}, {1, 8, 8, 1});
1002 _size = create_const<Type::S32, int32_t>(g(), {2}, {8, 8});
1003 _resize_bilinear = g()->nodes()->create<luci::CircleResizeBilinear>();
1005 _resize_bilinear->input(input());
1006 _resize_bilinear->size(_size);
1008 output()->from(_resize_bilinear);
1010 set_minmax_to_non_const(g(), -1, 1);
1014 luci::CircleResizeBilinear *_resize_bilinear = nullptr;
1015 luci::CircleConst *_size = nullptr;
1018 class ResizeNearestNeighborTestGraph final : public luci::test::TestIOGraph
1023 TestIOGraph::init({1, 4, 4, 1}, {1, 8, 8, 1});
1025 _size = create_const<Type::S32, int32_t>(g(), {2}, {8, 8});
1026 _resize_nearest_neighbor = g()->nodes()->create<luci::CircleResizeNearestNeighbor>();
1028 _resize_nearest_neighbor->input(input());
1029 _resize_nearest_neighbor->size(_size);
1031 output()->from(_resize_nearest_neighbor);
1033 set_minmax_to_non_const(g(), -1, 1);
1037 luci::CircleResizeNearestNeighbor *_resize_nearest_neighbor = nullptr;
1038 luci::CircleConst *_size = nullptr;
1041 class UnpackTestGraph final : public luci::test::TestIOGraph
1046 TestIOGraph::init({1, 32}, {32});
1047 _unpack = g()->nodes()->create<luci::CircleUnpack>();
1049 _unpack->value(input());
1053 _unpack_o1 = g()->nodes()->create<luci::CircleUnpackOut>();
1055 _unpack_o1->input(_unpack);
1056 _unpack_o1->index(0);
1059 output()->from(_unpack_o1);
1061 set_minmax_to_non_const(g(), -1, 1);
1065 luci::CircleUnpack *_unpack = nullptr;
1066 luci::CircleUnpackOut *_unpack_o1 = nullptr;
1067 luci::CircleConst *_unpack_dim = nullptr;
1072 // Quantize and verify with given configurations
1073 #define TEST_WITH_GRAPH(graph, type, granularity) \
1078 EXPECT_NO_THROW(quantize_and_verify(g.g(), type, granularity)); \
1081 // Quantize and verify with wrong type
1082 #define TEST_WITH_WRONG_TYPE(graph, type, granularity, wrong_dtype) \
1087 EXPECT_ANY_THROW(quantize_and_verify_with_wrong_type(&g, type, granularity, wrong_dtype)); \
1090 // Quantize and verify with wrong granularity
1091 #define TEST_WITH_WRONG_GRANULARITY(graph, type, granularity) \
1096 EXPECT_ANY_THROW(quantize_and_verify_with_wrong_granularity(&g, type, granularity)); \
1099 // Quantize and verify with wrong type
1100 // Users can specify the test target
1101 #define TEST_WITH_WRONG_TYPE_TARGET(graph, type, granularity, wrong_dtype, target) \
1106 auto node = loco::must_cast<luci::CircleNode *>(target); \
1108 quantize_and_verify_with_wrong_type(&g, type, granularity, wrong_dtype, node)); \
1111 // Quantize and verify with wrong granularity
1112 // Users can specify the test target
1113 #define TEST_WITH_WRONG_GRANULARITY_TARGET(graph, type, granularity, target) \
1118 auto node = loco::must_cast<luci::CircleNode *>(target); \
1119 EXPECT_ANY_THROW(quantize_and_verify_with_wrong_granularity(&g, type, granularity, node)); \
1122 // Test a local helper function
1123 TEST(QuantizedModelVerifierTest, LocalCreateDummyConst)
1127 EXPECT_NO_THROW(create_dummy_const<Type::FLOAT32>(&g, {32, 32}));
1130 TEST(QuantizedModelVerifierTest, LocalCreateConst)
1133 std::initializer_list<float> values = {0.1, 0, -5, 100};
1134 luci::CircleConst *node = create_const<Type::FLOAT32, float>(&g, {2, 2}, values);
1137 for (auto val : values)
1139 EXPECT_EQ(node->at<Type::FLOAT32>(index++), val);
1143 TEST(QuantizedModelVerifierTest, InstanceNorm)
1145 TEST_WITH_GRAPH(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1146 TEST_WITH_GRAPH(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1147 TEST_WITH_GRAPH(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1151 TEST(QuantizedModelVerifierTest, InstanceNorm_wrong_type_NEG)
1153 TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1154 TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1155 TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1159 TEST(QuantizedModelVerifierTest, InstanceNorm_wrong_granularity_NEG)
1161 TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1162 TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1163 TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1167 TEST(QuantizedModelVerifierTest, LocalResponseNormalization)
1169 TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise);
1170 TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise);
1171 TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise);
1175 TEST(QuantizedModelVerifierTest, LocalResponseNormalization_wrong_type_NEG)
1177 TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise,
1179 TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise,
1181 TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise,
1186 TEST(QuantizedModelVerifierTest, LocalResponseNormalization_wrong_granularity_NEG)
1188 TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::U8,
1189 Granularity::LayerWise);
1190 TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::U8,
1191 Granularity::ChannelWise);
1192 TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::S16,
1193 Granularity::ChannelWise);
1197 TEST(QuantizedModelVerifierTest, Logistic)
1199 TEST_WITH_GRAPH(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1200 TEST_WITH_GRAPH(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1201 TEST_WITH_GRAPH(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1205 TEST(QuantizedModelVerifierTest, Logistic_wrong_type_NEG)
1207 TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1208 TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1209 TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1213 TEST(QuantizedModelVerifierTest, Logistic_wrong_granularity_NEG)
1215 TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1216 TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1217 TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1221 TEST(QuantizedModelVerifierTest, Softmax)
1223 TEST_WITH_GRAPH(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1224 TEST_WITH_GRAPH(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1225 TEST_WITH_GRAPH(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1229 TEST(QuantizedModelVerifierTest, Softmax_wrong_type_NEG)
1231 TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1232 TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1233 TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1237 TEST(QuantizedModelVerifierTest, Softmax_wrong_granularity_NEG)
1239 TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1240 TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1241 TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1245 TEST(QuantizedModelVerifierTest, SpaceToBatchND)
1247 TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1248 TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1249 TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1253 TEST(QuantizedModelVerifierTest, SpaceToBatchND_wrong_type_NEG)
1255 TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1256 TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1257 TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1261 TEST(QuantizedModelVerifierTest, SpaceToBatchND_wrong_granularity_NEG)
1263 TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1264 TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1265 TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1269 TEST(QuantizedModelVerifierTest, SpaceToDepth)
1271 TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1272 TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1273 TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1277 TEST(QuantizedModelVerifierTest, SpaceToDepth_wrong_type_NEG)
1279 TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1280 TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1281 TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1285 TEST(QuantizedModelVerifierTest, SpaceToDepth_wrong_granularity_NEG)
1287 TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1288 TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1289 TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1293 TEST(QuantizedModelVerifierTest, Slice)
1295 TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1296 TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1297 TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1299 TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1300 TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1301 TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1305 TEST(QuantizedModelVerifierTest, Slice_wrong_type_NEG)
1307 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
1308 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
1309 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
1311 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
1312 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
1313 TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
1317 TEST(QuantizedModelVerifierTest, Slice_wrong_granularity_NEG)
1319 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1320 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1321 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1323 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1324 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1325 TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1329 TEST(QuantizedModelVerifierTest, Split)
1331 TEST_WITH_GRAPH(SplitTestGraph, Type::U8, Granularity::LayerWise);
1332 TEST_WITH_GRAPH(SplitTestGraph, Type::U8, Granularity::ChannelWise);
1333 TEST_WITH_GRAPH(SplitTestGraph, Type::S16, Granularity::ChannelWise);
1337 TEST(QuantizedModelVerifierTest, Split_wrong_type_NEG)
1339 TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1340 TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1341 TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1345 TEST(QuantizedModelVerifierTest, Split_wrong_granularity_NEG)
1347 TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::U8, Granularity::LayerWise);
1348 TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::U8, Granularity::ChannelWise);
1349 TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::S16, Granularity::ChannelWise);
1353 TEST(QuantizedModelVerifierTest, SplitV)
1355 TEST_WITH_GRAPH(SplitVTestGraph, Type::U8, Granularity::LayerWise);
1356 TEST_WITH_GRAPH(SplitVTestGraph, Type::U8, Granularity::ChannelWise);
1357 TEST_WITH_GRAPH(SplitVTestGraph, Type::S16, Granularity::ChannelWise);
1361 TEST(QuantizedModelVerifierTest, SplitV_wrong_type_NEG)
1363 TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1364 TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1365 TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1369 TEST(QuantizedModelVerifierTest, SplitV_wrong_granularity_NEG)
1371 TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::U8, Granularity::LayerWise);
1372 TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::U8, Granularity::ChannelWise);
1373 TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::S16, Granularity::ChannelWise);
1377 TEST(QuantizedModelVerifierTest, StridedSlice)
1379 TEST_WITH_GRAPH(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1380 TEST_WITH_GRAPH(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1381 TEST_WITH_GRAPH(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1385 TEST(QuantizedModelVerifierTest, StridedSlice_wrong_type_NEG)
1387 TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1388 TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1389 TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1393 TEST(QuantizedModelVerifierTest, StridedSlice_wrong_granularity_NEG)
1395 TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1396 TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1397 TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1401 TEST(QuantizedModelVerifierTest, ArgMax)
1403 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1404 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1405 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1407 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1408 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1409 TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1413 TEST(QuantizedModelVerifierTest, ArgMax_wrong_input_type_NEG)
1415 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
1416 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
1417 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
1419 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
1420 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
1421 TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
1425 TEST(QuantizedModelVerifierTest, ArgMax_wrong_dimension_type_NEG)
1427 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise,
1428 Type::S16, g.dimension());
1429 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise,
1430 Type::S16, g.dimension());
1431 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise,
1432 Type::U8, g.dimension());
1434 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise,
1435 Type::S16, g.dimension());
1436 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise,
1437 Type::S16, g.dimension());
1438 TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise,
1439 Type::U8, g.dimension());
1443 TEST(QuantizedModelVerifierTest, ArgMax_wrong_granularity_NEG)
1445 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise,
1447 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise,
1449 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::S16,
1450 Granularity::ChannelWise, g.input_argmax());
1452 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise,
1454 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise,
1456 TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::S16,
1457 Granularity::ChannelWise, g.input_argmax());
1461 TEST(QuantizedModelVerifierTest, BatchToSpaceND)
1463 TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1464 TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1465 TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1469 TEST(QuantizedModelVerifierTest, BatchToSpaceND_wrong_type_NEG)
1471 TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1472 TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1473 TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1477 TEST(QuantizedModelVerifierTest, BatchToSpaceND_wrong_granularity_NEG)
1479 TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1480 TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1481 TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1485 TEST(QuantizedModelVerifierTest, DepthToSpace)
1487 TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1488 TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1489 TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1493 TEST(QuantizedModelVerifierTest, DepthToSpace_wrong_type_NEG)
1495 TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1496 TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1497 TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1501 TEST(QuantizedModelVerifierTest, DepthToSpace_wrong_granularity_NEG)
1503 TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1504 TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1505 TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1509 TEST(QuantizedModelVerifierTest, Concatenation)
1511 TEST_WITH_GRAPH(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1512 TEST_WITH_GRAPH(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1513 TEST_WITH_GRAPH(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1517 TEST(QuantizedModelVerifierTest, Concatenation_wrong_type_NEG)
1519 TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1520 TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1521 TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1525 TEST(QuantizedModelVerifierTest, Concatenation_wrong_granularity_NEG)
1527 TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1528 TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1529 TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1533 TEST(QuantizedModelVerifierTest, LogicalOr)
1535 TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1536 Granularity::LayerWise);
1537 TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1538 Granularity::ChannelWise);
1539 TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::S16,
1540 Granularity::ChannelWise);
1544 TEST(QuantizedModelVerifierTest, LogicalOr_wrong_type_NEG)
1546 TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1547 Granularity::LayerWise, Type::U8);
1548 TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1549 Granularity::ChannelWise, Type::U8);
1550 TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::S16,
1551 Granularity::ChannelWise, Type::S16);
1555 TEST(QuantizedModelVerifierTest, Reshape)
1557 TEST_WITH_GRAPH(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
1558 TEST_WITH_GRAPH(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
1559 TEST_WITH_GRAPH(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
1563 TEST(QuantizedModelVerifierTest, Reshape_wrong_type_NEG)
1565 TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1566 TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1567 TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1571 TEST(QuantizedModelVerifierTest, Reshape_wrong_granularity_NEG)
1573 TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
1574 TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
1575 TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
1579 TEST(QuantizedModelVerifierTest, Tanh)
1581 TEST_WITH_GRAPH(TanhTestGraph, Type::U8, Granularity::LayerWise);
1582 TEST_WITH_GRAPH(TanhTestGraph, Type::U8, Granularity::ChannelWise);
1583 TEST_WITH_GRAPH(TanhTestGraph, Type::S16, Granularity::ChannelWise);
1587 TEST(QuantizedModelVerifierTest, Tanh_wrong_type_NEG)
1589 TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1590 TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1591 TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1595 TEST(QuantizedModelVerifierTest, Tanh_wrong_granularity_NEG)
1597 TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::U8, Granularity::LayerWise);
1598 TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::U8, Granularity::ChannelWise);
1599 TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::S16, Granularity::ChannelWise);
1603 TEST(QuantizedModelVerifierTest, Pack)
1605 TEST_WITH_GRAPH(PackTestGraph, Type::U8, Granularity::LayerWise);
1606 TEST_WITH_GRAPH(PackTestGraph, Type::U8, Granularity::ChannelWise);
1607 TEST_WITH_GRAPH(PackTestGraph, Type::S16, Granularity::ChannelWise);
1609 // Test if Pack's qparam is propagated to the input
1613 quantize_and_verify(g.g(), Type::U8, Granularity::ChannelWise);
1614 auto input = loco::must_cast<luci::CircleNode *>(g.pack()->values(0));
1615 auto qp = input->quantparam();
1616 EXPECT_FLOAT_EQ(2.0 / 255.0, qp->scale[0]);
1617 EXPECT_FLOAT_EQ(128, qp->zerop[0]);
1622 TEST(QuantizedModelVerifierTest, Pack_wrong_type_NEG)
1624 TEST_WITH_WRONG_TYPE(PackTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1625 TEST_WITH_WRONG_TYPE(PackTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1626 TEST_WITH_WRONG_TYPE(PackTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1630 TEST(QuantizedModelVerifierTest, Pack_wrong_granularity_NEG)
1632 TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::U8, Granularity::LayerWise);
1633 TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::U8, Granularity::ChannelWise);
1634 TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::S16, Granularity::ChannelWise);
1638 TEST(QuantizedModelVerifierTest, Pad)
1640 TEST_WITH_GRAPH(PadTestGraph, Type::U8, Granularity::LayerWise);
1641 TEST_WITH_GRAPH(PadTestGraph, Type::U8, Granularity::ChannelWise);
1642 TEST_WITH_GRAPH(PadTestGraph, Type::S16, Granularity::ChannelWise);
1646 TEST(QuantizedModelVerifierTest, Pad_wrong_type_NEG)
1648 TEST_WITH_WRONG_TYPE(PadTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1649 TEST_WITH_WRONG_TYPE(PadTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1650 TEST_WITH_WRONG_TYPE(PadTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1654 TEST(QuantizedModelVerifierTest, Pad_wrong_granularity_NEG)
1656 TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::U8, Granularity::LayerWise);
1657 TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::U8, Granularity::ChannelWise);
1658 TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::S16, Granularity::ChannelWise);
1662 TEST(QuantizedModelVerifierTest, PadV2)
1664 TEST_WITH_GRAPH(PadV2TestGraph, Type::U8, Granularity::LayerWise);
1665 TEST_WITH_GRAPH(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
1666 TEST_WITH_GRAPH(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
1670 TEST(QuantizedModelVerifierTest, PadV2_wrong_type_NEG)
1672 TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1673 TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1674 TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1678 TEST(QuantizedModelVerifierTest, PadV2_wrong_granularity_NEG)
1680 TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::U8, Granularity::LayerWise);
1681 TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
1682 TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
1686 TEST(QuantizedModelVerifierTest, MirrorPad)
1688 TEST_WITH_GRAPH(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
1689 TEST_WITH_GRAPH(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
1690 TEST_WITH_GRAPH(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
1694 TEST(QuantizedModelVerifierTest, MirrorPad_wrong_type_NEG)
1696 TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1697 TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1698 TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1702 TEST(QuantizedModelVerifierTest, MirrorPad_wrong_granularity_NEG)
1704 TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
1705 TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
1706 TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
1710 TEST(QuantizedModelVerifierTest, Transpose)
1712 TEST_WITH_GRAPH(TransposeTestGraph, Type::U8, Granularity::LayerWise);
1713 TEST_WITH_GRAPH(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
1714 TEST_WITH_GRAPH(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
1718 TEST(QuantizedModelVerifierTest, Transpose_wrong_type_NEG)
1720 TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1721 TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1722 TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1726 TEST(QuantizedModelVerifierTest, Transpose_wrong_granularity_NEG)
1728 TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::U8, Granularity::LayerWise);
1729 TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
1730 TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
1734 TEST(QuantizedModelVerifierTest, Floor)
1736 TEST_WITH_GRAPH(FloorTestGraph, Type::U8, Granularity::LayerWise);
1737 TEST_WITH_GRAPH(FloorTestGraph, Type::U8, Granularity::ChannelWise);
1738 TEST_WITH_GRAPH(FloorTestGraph, Type::S16, Granularity::ChannelWise);
1742 TEST(QuantizedModelVerifierTest, Floor_wrong_type_NEG)
1744 TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1745 TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1746 TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1750 TEST(QuantizedModelVerifierTest, Floor_wrong_granularity_NEG)
1752 TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::U8, Granularity::LayerWise);
1753 TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::U8, Granularity::ChannelWise);
1754 TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::S16, Granularity::ChannelWise);
1758 TEST(QuantizedModelVerifierTest, GreaterEqual)
1760 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
1761 Granularity::LayerWise);
1762 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
1763 Granularity::ChannelWise);
1764 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
1765 Granularity::ChannelWise);
1769 TEST(QuantizedModelVerifierTest, GreaterEqual_wrong_type_NEG)
1771 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
1772 Granularity::LayerWise, Type::U8);
1773 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
1774 Granularity::ChannelWise, Type::U8);
1775 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
1776 Granularity::ChannelWise, Type::S16);
1780 TEST(QuantizedModelVerifierTest, GreaterEqual_wrong_granularity_NEG)
1782 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
1783 Granularity::LayerWise, g.x());
1784 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
1785 Granularity::ChannelWise, g.x());
1786 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
1787 Granularity::ChannelWise, g.x());
1789 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
1790 Granularity::LayerWise, g.y());
1791 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
1792 Granularity::ChannelWise, g.y());
1793 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
1794 Granularity::ChannelWise, g.y());
1798 TEST(QuantizedModelVerifierTest, Greater)
1800 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::LayerWise);
1801 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::ChannelWise);
1802 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16, Granularity::ChannelWise);
1806 TEST(QuantizedModelVerifierTest, Greater_wrong_type_NEG)
1808 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::LayerWise,
1810 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
1811 Granularity::ChannelWise, Type::U8);
1812 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
1813 Granularity::ChannelWise, Type::S16);
1817 TEST(QuantizedModelVerifierTest, Greater_wrong_granularity_NEG)
1819 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
1820 Granularity::LayerWise, g.x());
1821 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
1822 Granularity::ChannelWise, g.x());
1823 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
1824 Granularity::ChannelWise, g.x());
1826 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
1827 Granularity::LayerWise, g.y());
1828 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
1829 Granularity::ChannelWise, g.y());
1830 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
1831 Granularity::ChannelWise, g.y());
1835 TEST(QuantizedModelVerifierTest, NotEqual)
1837 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8, Granularity::LayerWise);
1838 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8, Granularity::ChannelWise);
1839 TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16, Granularity::ChannelWise);
1843 TEST(QuantizedModelVerifierTest, NotEqual_wrong_type_NEG)
1845 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
1846 Granularity::LayerWise, Type::U8);
1847 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
1848 Granularity::ChannelWise, Type::U8);
1849 TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
1850 Granularity::ChannelWise, Type::S16);
1854 TEST(QuantizedModelVerifierTest, NotEqual_wrong_granularity_NEG)
1856 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
1857 Granularity::LayerWise, g.x());
1858 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
1859 Granularity::ChannelWise, g.x());
1860 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
1861 Granularity::ChannelWise, g.x());
1863 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
1864 Granularity::LayerWise, g.y());
1865 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
1866 Granularity::ChannelWise, g.y());
1867 TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
1868 Granularity::ChannelWise, g.y());
1872 TEST(QuantizedModelVerifierTest, Div)
1874 TEST_WITH_GRAPH(DivTestGraph, Type::U8, Granularity::LayerWise);
1875 TEST_WITH_GRAPH(DivTestGraph, Type::U8, Granularity::ChannelWise);
1876 TEST_WITH_GRAPH(DivTestGraph, Type::S16, Granularity::ChannelWise);
1880 TEST(QuantizedModelVerifierTest, Div_wrong_type_NEG)
1882 TEST_WITH_WRONG_TYPE(DivTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1883 TEST_WITH_WRONG_TYPE(DivTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1884 TEST_WITH_WRONG_TYPE(DivTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1888 TEST(QuantizedModelVerifierTest, Div_wrong_granularity_NEG)
1890 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::LayerWise, g.x());
1891 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::ChannelWise, g.x());
1892 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::S16, Granularity::ChannelWise, g.x());
1894 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::LayerWise, g.y());
1895 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::ChannelWise, g.y());
1896 TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::S16, Granularity::ChannelWise, g.y());
1900 TEST(QuantizedModelVerifierTest, FloorDiv)
1902 TEST_WITH_GRAPH(FloorDivTestGraph, Type::U8, Granularity::LayerWise);
1903 TEST_WITH_GRAPH(FloorDivTestGraph, Type::U8, Granularity::ChannelWise);
1904 TEST_WITH_GRAPH(FloorDivTestGraph, Type::S16, Granularity::ChannelWise);
1908 TEST(QuantizedModelVerifierTest, FloorDiv_wrong_type_NEG)
1910 TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1911 TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1912 TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1916 TEST(QuantizedModelVerifierTest, FloorDiv_wrong_granularity_NEG)
1918 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::LayerWise, g.x());
1919 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, g.x());
1920 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, g.x());
1922 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::LayerWise, g.y());
1923 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, g.y());
1924 TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, g.y());
1928 TEST(QuantizedModelVerifierTest, Rsqrt)
1930 TEST_WITH_GRAPH(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
1931 TEST_WITH_GRAPH(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
1932 TEST_WITH_GRAPH(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
1936 TEST(QuantizedModelVerifierTest, Rsqrt_wrong_type_NEG)
1938 TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1939 TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1940 TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1944 TEST(QuantizedModelVerifierTest, Rsqrt_wrong_granularity_NEG)
1946 TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
1947 TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
1948 TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
1952 TEST(QuantizedModelVerifierTest, Sqrt)
1954 TEST_WITH_GRAPH(SqrtTestGraph, Type::U8, Granularity::LayerWise);
1955 TEST_WITH_GRAPH(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
1956 TEST_WITH_GRAPH(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
1960 TEST(QuantizedModelVerifierTest, Sqrt_wrong_type_NEG)
1962 TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1963 TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1964 TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1968 TEST(QuantizedModelVerifierTest, Sqrt_wrong_granularity_NEG)
1970 TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::U8, Granularity::LayerWise);
1971 TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
1972 TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
1976 TEST(QuantizedModelVerifierTest, Elu)
1978 TEST_WITH_GRAPH(EluTestGraph, Type::U8, Granularity::LayerWise);
1979 TEST_WITH_GRAPH(EluTestGraph, Type::U8, Granularity::ChannelWise);
1980 TEST_WITH_GRAPH(EluTestGraph, Type::S16, Granularity::ChannelWise);
1984 TEST(QuantizedModelVerifierTest, Elu_wrong_type_NEG)
1986 TEST_WITH_WRONG_TYPE(EluTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1987 TEST_WITH_WRONG_TYPE(EluTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1988 TEST_WITH_WRONG_TYPE(EluTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1992 TEST(QuantizedModelVerifierTest, Elu_wrong_granularity_NEG)
1994 TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::U8, Granularity::LayerWise);
1995 TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::U8, Granularity::ChannelWise);
1996 TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::S16, Granularity::ChannelWise);
2000 TEST(QuantizedModelVerifierTest, Pow)
2002 TEST_WITH_GRAPH(PowTestGraph, Type::U8, Granularity::LayerWise);
2003 TEST_WITH_GRAPH(PowTestGraph, Type::U8, Granularity::ChannelWise);
2004 TEST_WITH_GRAPH(PowTestGraph, Type::S16, Granularity::ChannelWise);
2008 TEST(QuantizedModelVerifierTest, Pow_wrong_type_NEG)
2010 TEST_WITH_WRONG_TYPE(PowTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2011 TEST_WITH_WRONG_TYPE(PowTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2012 TEST_WITH_WRONG_TYPE(PowTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2016 TEST(QuantizedModelVerifierTest, Pow_wrong_granularity_NEG)
2018 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::LayerWise, g.x());
2019 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2020 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2022 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::LayerWise, g.y());
2023 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2024 TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2028 TEST(QuantizedModelVerifierTest, ResizeBilinear)
2030 TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2031 TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2032 TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2036 TEST(QuantizedModelVerifierTest, ResizeBilinear_wrong_type_NEG)
2038 TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2039 TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2040 TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2044 TEST(QuantizedModelVerifierTest, ResizeBilinear_wrong_granularity_NEG)
2046 TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2047 TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2048 TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2052 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor)
2054 TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise);
2055 TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise);
2056 TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise);
2060 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor_wrong_type_NEG)
2062 TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2063 TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise,
2065 TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise,
2070 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor_wrong_granularity_NEG)
2072 TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise);
2073 TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise);
2074 TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise);
2078 TEST(QuantizedModelVerifierTest, Unpack)
2080 TEST_WITH_GRAPH(UnpackTestGraph, Type::U8, Granularity::LayerWise);
2081 TEST_WITH_GRAPH(UnpackTestGraph, Type::U8, Granularity::ChannelWise);
2082 TEST_WITH_GRAPH(UnpackTestGraph, Type::S16, Granularity::ChannelWise);
2086 TEST(QuantizedModelVerifierTest, Unpack_wrong_type_NEG)
2088 TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2089 TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2090 TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2094 TEST(QuantizedModelVerifierTest, Unpack_wrong_granularity_NEG)
2096 TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::U8, Granularity::LayerWise);
2097 TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::U8, Granularity::ChannelWise);
2098 TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::S16, Granularity::ChannelWise);
2102 #undef TEST_WITH_GRAPH
2103 #undef TEST_WITH_WRONG_TYPE
2104 #undef TEST_WITH_WRONG_GRANULARITY