05ec31727c9b6ac6d0aea4c91378fe991c45d876
[platform/core/ml/nnfw.git] / compiler / luci / pass / src / QuantizedModelVerifier.test.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
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
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "QuantizedModelVerifier.h"
18
19 #include "luci/Pass/QuantizeWithMinMaxPass.h"
20 #include "luci/Pass/QuantizationParameters.h"
21 #include "luci/Pass/CircleTypeInferencePass.h"
22
23 #include <logo/Phase.h>
24 #include <luci/test/TestIOGraph.h>
25
26 #include <gtest/gtest.h>
27
28 using Type = loco::DataType;
29 using Granularity = luci::QuantizationGranularity;
30
31 namespace
32 {
33
34 /**
35  * @brief A helper function to create dummy const node
36  */
37 template <Type T> luci::CircleConst *create_dummy_const(loco::Graph *g, luci::test::ShapeU32 shape)
38 {
39   auto node = g->nodes()->create<luci::CircleConst>();
40   {
41     node->dtype(T);
42     node->shape(shape);
43     node->size<T>(luci::test::num_elements(shape));
44
45     for (int32_t i = 0; i < luci::test::num_elements(shape); i++)
46     {
47       // DESIGN NOTE
48       //
49       // Filling with any random numbers are fine
50       // Q. Should it include minus numbers?
51       switch (T)
52       {
53         case Type::FLOAT32:
54           // Fill with index
55           node->at<T>(i) = static_cast<float>(i);
56           break;
57         case Type::BOOL:
58           // Fill by flip
59           node->at<T>(i) = (i % 2) ? true : false;
60           break;
61         case Type::U8:
62           // Fill with index
63           node->at<T>(i) = static_cast<uint8_t>(i);
64           break;
65         case Type::S16:
66           // Fill with index
67           node->at<T>(i) = static_cast<int16_t>(i);
68           break;
69       }
70     }
71   }
72
73   return node;
74 }
75
76 /**
77  * @brief A helper function to create const node with value
78  */
79 template <Type DT, typename T>
80 luci::CircleConst *create_const(loco::Graph *g, luci::test::ShapeU32 shape,
81                                 std::initializer_list<T> values)
82 {
83   auto node = g->nodes()->create<luci::CircleConst>();
84   {
85     node->dtype(DT);
86     node->shape(shape);
87     node->size<DT>(luci::test::num_elements(shape));
88
89     assert(values.size() == node->size<DT>());
90
91     uint32_t index = 0;
92     for (auto val : values)
93     {
94       node->at<DT>(index++) = static_cast<T>(val);
95     }
96   }
97
98   return node;
99 }
100
101 void insert_scale_zp(luci::CircleNode *node, float scale, int64_t zp)
102 {
103   auto qparam = node->quantparam();
104   assert(qparam != nullptr); // FIX_CALLER_UNLESS
105   qparam->scale.push_back(scale);
106   qparam->zerop.push_back(zp);
107 }
108
109 void run_phase(loco::Graph *g, Type quantized_dtype, Granularity granularity)
110 {
111   logo::Phase phase;
112
113   // Default passes.
114   phase.emplace_back(std::make_unique<luci::CircleTypeInferencePass>());
115
116   auto ctx = std::make_unique<luci::QuantizeWithMinMaxPass::Context>();
117   {
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};
124   }
125
126   phase.emplace_back(std::make_unique<luci::QuantizeWithMinMaxPass>(std::move(ctx)));
127
128   logo::PhaseRunner<logo::PhaseStrategy::Restart> phase_runner{g};
129   phase_runner.run(phase);
130 }
131
132 void run_phase(loco::Graph *g, std::unique_ptr<luci::QuantizeWithMinMaxPass::Context> &&ctx)
133 {
134   logo::Phase phase;
135
136   // Default passes.
137   phase.emplace_back(std::make_unique<luci::CircleTypeInferencePass>());
138
139   phase.emplace_back(std::make_unique<luci::QuantizeWithMinMaxPass>(std::move(ctx)));
140
141   logo::PhaseRunner<logo::PhaseStrategy::Restart> phase_runner{g};
142   phase_runner.run(phase);
143 }
144
145 void quantize_and_verify(loco::Graph *g, Type quantized_dtype, Granularity granularity)
146 {
147   run_phase(g, quantized_dtype, granularity);
148
149   auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
150   {
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};
156   }
157
158   luci::QuantizedModelVerifier verifier(std::move(ctx));
159   verifier.verify(g);
160 }
161
162 void quantize_and_verify_with_layer_info(loco::Graph *g, Type quantized_dtype,
163                                          Granularity granularity)
164 {
165   // A layer named "test" has dtype different from quantized_dtype
166   luci::LayerInfo info;
167   {
168     info.name = "test";
169     // dtype is different from quantized_dtype
170     info.dtype = quantized_dtype == Type::U8 ? Type::S16 : Type::U8;
171     info.granularity = Granularity::ChannelWise;
172   }
173
174   // Do quantization
175   {
176     auto ctx = std::make_unique<luci::QuantizeWithMinMaxPass::Context>();
177     {
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);
186     }
187
188     run_phase(g, std::move(ctx));
189   }
190
191   // Do verification
192   {
193     auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
194     {
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);
201     }
202
203     luci::QuantizedModelVerifier verifier(std::move(ctx));
204     verifier.verify(g);
205   }
206 }
207
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)
212 {
213   run_phase(g->g(), quantized_dtype, granularity);
214
215   auto node = loco::must_cast<luci::CircleNode *>(g->output()->from());
216   node->dtype(wrong_dtype);
217
218   auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
219   {
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};
225   }
226
227   luci::QuantizedModelVerifier verifier(std::move(ctx));
228   verifier.verify(g->g());
229 }
230
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)
235 {
236   run_phase(g->g(), quantized_dtype, granularity);
237
238   auto node = loco::must_cast<luci::CircleNode *>(g->output()->from());
239   insert_scale_zp(node, 1.0, 1);
240
241   auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
242   {
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};
248   }
249
250   luci::QuantizedModelVerifier verifier(std::move(ctx));
251   verifier.verify(g->g());
252 }
253
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)
256 {
257   for (auto node : loco::all_nodes(g))
258   {
259     auto const_node = dynamic_cast<luci::CircleConst *>(node);
260     if (const_node != nullptr)
261       continue;
262
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)
267       continue;
268
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)
273       continue;
274
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)
279       continue;
280
281     auto circle_node = loco::must_cast<luci::CircleNode *>(node);
282     auto qparam = std::make_unique<luci::CircleQuantParam>();
283     {
284       qparam->min.emplace_back(min);
285       qparam->max.emplace_back(max);
286     }
287     circle_node->quantparam(std::move(qparam));
288   }
289 }
290
291 /**
292  * @brief Simple Test Graph
293  * @note
294  * The simple test graph's nodes are initialized with
295  * simple shapes and values.
296  */
297 class SimpleTestGraph : public luci::test::TestIOGraph
298 {
299 public:
300   virtual void init(void) = 0;
301 };
302
303 class TypedTestGraph : public luci::test::TestIOGraph
304 {
305 protected:
306   void init(Type T, const luci::test::ShapeU32 shape_in, const luci::test::ShapeU32 shape_out)
307   {
308     TestIOGraph::init(shape_in, shape_out);
309
310     input()->dtype(T);
311     output()->dtype(T);
312
313     g()->inputs()->at(0)->dtype(T);
314     g()->outputs()->at(0)->dtype(T);
315   }
316
317 public:
318   virtual void init(void) = 0;
319 };
320
321 class InstanceNormTestGraph final : public SimpleTestGraph
322 {
323 public:
324   void init(void) override
325   {
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>();
330     {
331       _instnorm->input(input());
332       _instnorm->gamma(_gamma);
333       _instnorm->beta(_beta);
334       _instnorm->fusedActivationFunction(luci::FusedActFunc::NONE);
335       _instnorm->name("test");
336     }
337     output()->from(_instnorm);
338
339     set_minmax_to_non_const(g(), -1, 1);
340   }
341
342 public:
343   loco::Node *gamma(void) const { return _instnorm->gamma(); }
344   loco::Node *beta(void) const { return _instnorm->beta(); }
345
346 private:
347   luci::CircleInstanceNorm *_instnorm = nullptr;
348   luci::CircleConst *_input = nullptr;
349   luci::CircleConst *_gamma = nullptr;
350   luci::CircleConst *_beta = nullptr;
351 };
352
353 class LogisticTestGraph final : public SimpleTestGraph
354 {
355 public:
356   void init(void) override
357   {
358     TestIOGraph::init({32}, {32});
359     _logistic = g()->nodes()->create<luci::CircleLogistic>();
360     {
361       _logistic->x(input());
362       _logistic->name("test");
363     }
364     output()->from(_logistic);
365
366     set_minmax_to_non_const(g(), -1, 1);
367   }
368
369 private:
370   luci::CircleLogistic *_logistic = nullptr;
371 };
372
373 class LocalResponseNormalizationTestGraph final : public SimpleTestGraph
374 {
375 public:
376   void init(void) override
377   {
378     TestIOGraph::init({1, 2, 2, 32}, {1, 2, 2, 32});
379     _lrn = g()->nodes()->create<luci::CircleLocalResponseNormalization>();
380     {
381       _lrn->input(input());
382       _lrn->name("test");
383     }
384     output()->from(_lrn);
385
386     set_minmax_to_non_const(g(), -1, 1);
387   }
388
389 private:
390   luci::CircleLocalResponseNormalization *_lrn = nullptr;
391 };
392
393 class SoftmaxTestGraph final : public SimpleTestGraph
394 {
395 public:
396   void init(void) override
397   {
398     TestIOGraph::init({32}, {32});
399     _softmax = g()->nodes()->create<luci::CircleSoftmax>();
400     {
401       _softmax->logits(input());
402       _softmax->beta(0.1);
403       _softmax->name("test");
404     }
405     output()->from(_softmax);
406
407     set_minmax_to_non_const(g(), -1, 1);
408   }
409
410 private:
411   luci::CircleSoftmax *_softmax = nullptr;
412 };
413
414 class SpaceToBatchNDTestGraph final : public SimpleTestGraph
415 {
416 public:
417   void init(void) override
418   {
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;
423
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;
427
428     _stob = g()->nodes()->create<luci::CircleSpaceToBatchND>();
429     {
430       _stob->input(input());
431       _stob->block_shape(_block_shape);
432       _stob->paddings(_paddings);
433       _stob->name("test");
434     }
435     output()->from(_stob);
436
437     set_minmax_to_non_const(g(), -1, 1);
438   }
439
440 private:
441   luci::CircleSpaceToBatchND *_stob = nullptr;
442   luci::CircleConst *_block_shape = nullptr;
443   luci::CircleConst *_paddings = nullptr;
444 };
445
446 class SpaceToDepthTestGraph final : public SimpleTestGraph
447 {
448 public:
449   void init(void) override
450   {
451     TestIOGraph::init({1, 2, 2, 1}, {1, 1, 1, 4});
452     _stod = g()->nodes()->create<luci::CircleSpaceToDepth>();
453     {
454       _stod->input(input());
455       _stod->block_size(2);
456       _stod->name("test");
457     }
458     output()->from(_stod);
459
460     set_minmax_to_non_const(g(), -1, 1);
461   }
462
463 private:
464   luci::CircleSpaceToDepth *_stod = nullptr;
465 };
466
467 template <Type indexT> class SliceTestGraph final : public SimpleTestGraph
468 {
469 public:
470   void init(void) override
471   {
472     TestIOGraph::init({32}, {32});
473     _begin = g()->nodes()->create<luci::CircleConst>();
474     {
475       _begin->dtype(indexT);
476     }
477     _size = g()->nodes()->create<luci::CircleConst>();
478     {
479       _size->dtype(indexT);
480     }
481     _slice = g()->nodes()->create<luci::CircleSlice>();
482     {
483       _slice->input(input());
484       _slice->begin(_begin);
485       _slice->size(_size);
486       _slice->name("test");
487     }
488     output()->from(_slice);
489
490     set_minmax_to_non_const(g(), -1, 1);
491   }
492
493 private:
494   luci::CircleSlice *_slice = nullptr;
495   luci::CircleConst *_begin = nullptr;
496   luci::CircleConst *_size = nullptr;
497 };
498
499 class SplitTestGraph final : public luci::test::TestIOGraph
500 {
501 public:
502   void init(void)
503   {
504     TestIOGraph::init({1, 32}, {32});
505     _split_dim = create_dummy_const<Type::S32>(g(), {1});
506     _split = g()->nodes()->create<luci::CircleSplit>();
507     {
508       _split->input(input());
509       _split->split_dim(_split_dim);
510     }
511     _split_o1 = g()->nodes()->create<luci::CircleSplitOut>();
512     {
513       _split_o1->input(_split);
514       _split_o1->index(0);
515     }
516
517     output()->from(_split_o1);
518
519     set_minmax_to_non_const(g(), -1, 1);
520   }
521
522 private:
523   luci::CircleSplit *_split = nullptr;
524   luci::CircleSplitOut *_split_o1 = nullptr;
525   luci::CircleConst *_split_dim = nullptr;
526 };
527
528 class SplitVTestGraph final : public luci::test::TestIOGraph
529 {
530 public:
531   void init(void)
532   {
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>();
537     {
538       _splitv->input(input());
539       _splitv->size_splits(_size_splits);
540       _splitv->split_dim(_split_dim);
541     }
542     _splitv_o1 = g()->nodes()->create<luci::CircleSplitVOut>();
543     {
544       _splitv_o1->input(_splitv);
545       _splitv_o1->index(0);
546     }
547
548     output()->from(_splitv_o1);
549
550     set_minmax_to_non_const(g(), -1, 1);
551   }
552
553 private:
554   luci::CircleSplitV *_splitv = nullptr;
555   luci::CircleSplitVOut *_splitv_o1 = nullptr;
556   luci::CircleConst *_size_splits = nullptr;
557   luci::CircleConst *_split_dim = nullptr;
558 };
559
560 class StridedSliceTestGraph final : public SimpleTestGraph
561 {
562 public:
563   void init(void) override
564   {
565     TestIOGraph::init({32}, {32});
566     _begin = g()->nodes()->create<luci::CircleConst>();
567     {
568       _begin->dtype(Type::S32);
569     }
570     _end = g()->nodes()->create<luci::CircleConst>();
571     {
572       _end->dtype(Type::S32);
573     }
574     _strides = g()->nodes()->create<luci::CircleConst>();
575     {
576       _strides->dtype(Type::S32);
577     }
578     _slice = g()->nodes()->create<luci::CircleStridedSlice>();
579     {
580       _slice->input(input());
581       _slice->begin(_begin);
582       _slice->end(_end);
583       _slice->strides(_strides);
584       _slice->name("test");
585     }
586     output()->from(_slice);
587
588     set_minmax_to_non_const(g(), -1, 1);
589   }
590
591 private:
592   luci::CircleStridedSlice *_slice = nullptr;
593   luci::CircleConst *_begin = nullptr;
594   luci::CircleConst *_end = nullptr;
595   luci::CircleConst *_strides = nullptr;
596 };
597
598 class ReshapeTestGraph final : public SimpleTestGraph
599 {
600 public:
601   void init(void) override
602   {
603     TestIOGraph::init({32}, {32});
604     _shape = g()->nodes()->create<luci::CircleConst>();
605     {
606       _shape->dtype(Type::S32);
607     }
608     _reshape = g()->nodes()->create<luci::CircleReshape>();
609     {
610       _reshape->tensor(input());
611       _reshape->shape(_shape);
612       _reshape->name("test");
613     }
614     output()->from(_reshape);
615
616     set_minmax_to_non_const(g(), -1, 1);
617   }
618
619 private:
620   luci::CircleReshape *_reshape = nullptr;
621   luci::CircleConst *_shape = nullptr;
622 };
623
624 class TanhTestGraph final : public SimpleTestGraph
625 {
626 public:
627   void init(void) override
628   {
629     TestIOGraph::init({32}, {32});
630     _tanh = g()->nodes()->create<luci::CircleTanh>();
631     {
632       _tanh->x(input());
633       _tanh->name("test");
634     }
635     output()->from(_tanh);
636
637     set_minmax_to_non_const(g(), -1, 1);
638   }
639
640 private:
641   luci::CircleTanh *_tanh = nullptr;
642 };
643
644 class FloorTestGraph final : public SimpleTestGraph
645 {
646 public:
647   void init(void) override
648   {
649     TestIOGraph::init({32}, {32});
650     _floor = g()->nodes()->create<luci::CircleFloor>();
651     {
652       _floor->x(input());
653       _floor->name("test");
654     }
655     output()->from(_floor);
656
657     set_minmax_to_non_const(g(), -1, 1);
658   }
659
660 private:
661   luci::CircleFloor *_floor = nullptr;
662 };
663
664 template <Type indexT> class ArgMaxTestGraph final : public SimpleTestGraph
665 {
666 public:
667   void init(void) override
668   {
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>();
673     {
674       _dimension->dtype(indexT);
675     }
676     _argmax = g()->nodes()->create<luci::CircleArgMax>();
677     {
678       _argmax->input(input());
679       _argmax->dimension(_dimension);
680       _argmax->output_type(indexT);
681       _argmax->dtype(indexT);
682     }
683     output()->from(_argmax);
684
685     set_minmax_to_non_const(g(), -1, 1);
686
687     // Sync output dtype with graph's output dtype
688     g()->outputs()->at(0)->dtype(output()->dtype());
689   }
690
691 public:
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(); }
695
696 private:
697   luci::CircleArgMax *_argmax = nullptr;
698   luci::CircleConst *_dimension = nullptr;
699 };
700
701 class BatchToSpaceNDTestGraph final : public SimpleTestGraph
702 {
703 public:
704   void init(void) override
705   {
706     TestIOGraph::init({32}, {32});
707     _block_shape = g()->nodes()->create<luci::CircleConst>();
708     {
709       _block_shape->dtype(Type::S32);
710     }
711     _crops = g()->nodes()->create<luci::CircleConst>();
712     {
713       _crops->dtype(Type::S32);
714     }
715     _btos = g()->nodes()->create<luci::CircleBatchToSpaceND>();
716     {
717       _btos->input(input());
718       _btos->block_shape(_block_shape);
719       _btos->crops(_crops);
720       _btos->name("test");
721     }
722     output()->from(_btos);
723
724     set_minmax_to_non_const(g(), -1, 1);
725   }
726
727 private:
728   luci::CircleBatchToSpaceND *_btos = nullptr;
729   luci::CircleConst *_block_shape = nullptr;
730   luci::CircleConst *_crops = nullptr;
731 };
732
733 class DepthToSpaceTestGraph final : public SimpleTestGraph
734 {
735 public:
736   void init(void) override
737   {
738     TestIOGraph::init({1, 1, 1, 4}, {1, 2, 2, 1});
739     _dtos = g()->nodes()->create<luci::CircleDepthToSpace>();
740     {
741       _dtos->input(input());
742       _dtos->block_size(2);
743       _dtos->name("test");
744     }
745     output()->from(_dtos);
746
747     set_minmax_to_non_const(g(), -1, 1);
748   }
749
750 private:
751   luci::CircleDepthToSpace *_dtos = nullptr;
752 };
753
754 class PackTestGraph final : public SimpleTestGraph
755 {
756 public:
757   void init(void) override
758   {
759     TestIOGraph::init({16}, {32});
760     _param = create_dummy_const<Type::FLOAT32>(g(), {16});
761     _pack = g()->nodes()->create<luci::CirclePack>(2);
762     {
763       _pack->values(0, input());
764       _pack->values(1, _param);
765       _pack->axis(0);
766       _pack->name("test");
767     }
768     output()->from(_pack);
769
770     set_minmax_to_non_const(g(), -1, 1);
771
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();
776     qp->min[0] = -0.5;
777     qp->max[0] = 0.5;
778   }
779
780 public:
781   luci::CirclePack *pack(void) { return _pack; }
782
783 private:
784   luci::CirclePack *_pack = nullptr;
785   luci::CircleConst *_param = nullptr;
786 };
787
788 class PadTestGraph final : public SimpleTestGraph
789 {
790 public:
791   void init(void) override
792   {
793     TestIOGraph::init({32}, {32});
794     _paddings = g()->nodes()->create<luci::CircleConst>();
795     {
796       _paddings->dtype(Type::S32);
797     }
798     _pad = g()->nodes()->create<luci::CirclePad>();
799     {
800       _pad->input(input());
801       _pad->paddings(_paddings);
802       _pad->name("test");
803     }
804     output()->from(_pad);
805
806     set_minmax_to_non_const(g(), -1, 1);
807   }
808
809 private:
810   luci::CirclePad *_pad = nullptr;
811   luci::CircleConst *_paddings = nullptr;
812 };
813
814 class PadV2TestGraph final : public SimpleTestGraph
815 {
816 public:
817   void init(void) override
818   {
819     TestIOGraph::init({32}, {32});
820     _paddings = g()->nodes()->create<luci::CircleConst>();
821     {
822       _paddings->dtype(Type::S32);
823     }
824     _constant_values = create_dummy_const<Type::FLOAT32>(g(), {1});
825     _pad = g()->nodes()->create<luci::CirclePadV2>();
826     {
827       _pad->input(input());
828       _pad->paddings(_paddings);
829       _pad->constant_values(_constant_values);
830       _pad->name("test");
831     }
832     output()->from(_pad);
833
834     set_minmax_to_non_const(g(), -1, 1);
835   }
836
837 private:
838   luci::CirclePadV2 *_pad = nullptr;
839   luci::CircleConst *_paddings = nullptr;
840   luci::CircleConst *_constant_values = nullptr;
841 };
842
843 class MirrorPadTestGraph final : public SimpleTestGraph
844 {
845 public:
846   void init(void) override
847   {
848     TestIOGraph::init({32}, {32});
849     _paddings = g()->nodes()->create<luci::CircleConst>();
850     {
851       _paddings->dtype(Type::S32);
852     }
853     _constant_values = create_dummy_const<Type::FLOAT32>(g(), {1});
854     _mirror_pad = g()->nodes()->create<luci::CircleMirrorPad>();
855     {
856       _mirror_pad->input(input());
857       _mirror_pad->paddings(_paddings);
858       _mirror_pad->mode(luci::MirrorPadMode::REFLECT);
859       _mirror_pad->name("test");
860     }
861     output()->from(_mirror_pad);
862
863     set_minmax_to_non_const(g(), -1, 1);
864   }
865
866 private:
867   luci::CircleMirrorPad *_mirror_pad = nullptr;
868   luci::CircleConst *_paddings = nullptr;
869   luci::CircleConst *_constant_values = nullptr;
870 };
871
872 class TransposeTestGraph final : public SimpleTestGraph
873 {
874 public:
875   void init(void) override
876   {
877     TestIOGraph::init({32}, {32});
878     _perm = g()->nodes()->create<luci::CircleConst>();
879     {
880       _perm->dtype(Type::S32);
881     }
882     _transpose = g()->nodes()->create<luci::CircleTranspose>();
883     {
884       _transpose->a(input());
885       _transpose->perm(_perm);
886       _transpose->name("test");
887     }
888     output()->from(_transpose);
889
890     set_minmax_to_non_const(g(), -1, 1);
891   }
892
893 private:
894   luci::CircleTranspose *_transpose = nullptr;
895   luci::CircleConst *_perm = nullptr;
896 };
897
898 class ConcatenationTestGraph final : public SimpleTestGraph
899 {
900 public:
901   void init(void) override
902   {
903     TestIOGraph::init({16}, {32});
904     _param = create_dummy_const<Type::FLOAT32>(g(), {16});
905     _concat = g()->nodes()->create<luci::CircleConcatenation>(2);
906     {
907       _concat->values(0, input());
908       _concat->values(1, _param);
909       _concat->axis(0);
910       _concat->fusedActivationFunction(luci::FusedActFunc::NONE);
911       _concat->name("test");
912     }
913     output()->from(_concat);
914
915     set_minmax_to_non_const(g(), -1, 1);
916   }
917
918 private:
919   luci::CircleConcatenation *_concat = nullptr;
920   luci::CircleConst *_param = nullptr;
921 };
922
923 template <Type indexT> class OneHotTestGraph final : public SimpleTestGraph
924 {
925 public:
926   void init(void) override
927   {
928     TestIOGraph::init({32}, {32, 10});
929     {
930       // input dtype is float by default, but OneHot's input should have indexType (s32/s64)
931       input()->dtype(indexT);
932     }
933
934     _depth = g()->nodes()->template create<luci::CircleConst>();
935     {
936       _depth->dtype(loco::DataType::S32);
937     }
938
939     _on_value = g()->nodes()->template create<luci::CircleConst>();
940     {
941       _on_value->dtype(loco::DataType::FLOAT32);
942     }
943
944     _off_value = g()->nodes()->template create<luci::CircleConst>();
945     {
946       _off_value->dtype(loco::DataType::FLOAT32);
947     }
948
949     _one_hot = g()->nodes()->template create<luci::CircleOneHot>();
950     {
951       _one_hot->indices(input());
952       _one_hot->depth(_depth);
953       _one_hot->on_value(_on_value);
954       _one_hot->off_value(_off_value);
955       _one_hot->axis(-1);
956       _one_hot->dtype(loco::DataType::FLOAT32);
957       _one_hot->name("test");
958     }
959     output()->from(_one_hot);
960
961     set_minmax_to_non_const(g(), -1, 1);
962   }
963
964 private:
965   luci::CircleOneHot *_one_hot = nullptr;
966   luci::CircleConst *_depth = nullptr;
967   luci::CircleConst *_on_value = nullptr;
968   luci::CircleConst *_off_value = nullptr;
969 };
970
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
974 {
975 public:
976   void init(void) override
977   {
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>();
982     {
983       _op->x(input());
984       _op->y(_y);
985       _op->dtype(loco::DataType::BOOL);
986     }
987     output()->from(_op);
988
989     set_minmax_to_non_const(g(), -1, 1);
990
991     // Sync output dtype with graph's output dtype
992     g()->outputs()->at(0)->dtype(output()->dtype());
993   }
994
995   loco::Node *x(void) const { return _op->x(); }
996   loco::Node *y(void) const { return _op->y(); }
997
998 private:
999   Op *_op = nullptr;
1000   luci::CircleConst *_y = nullptr;
1001 };
1002
1003 // Test graph for binary logical Ops
1004 // LOGICAL_OR, LOGICAL_AND
1005 template <class Op> class BinaryLogicalOpTestGraph final : public SimpleTestGraph
1006 {
1007 public:
1008   void init(void) override
1009   {
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>();
1015     {
1016       _op->x(input());
1017       _op->y(_y);
1018       _op->dtype(loco::DataType::BOOL);
1019     }
1020     output()->from(_op);
1021
1022     set_minmax_to_non_const(g(), -1, 1);
1023
1024     // Sync output dtype with graph's output dtype
1025     g()->outputs()->at(0)->dtype(output()->dtype());
1026   }
1027
1028   loco::Node *x(void) const { return _op->x(); }
1029   loco::Node *y(void) const { return _op->y(); }
1030
1031 private:
1032   Op *_op = nullptr;
1033   luci::CircleConst *_y = nullptr;
1034 };
1035
1036 class DivTestGraph final : public SimpleTestGraph
1037 {
1038 public:
1039   void init(void) override
1040   {
1041     TestIOGraph::init({32}, {32});
1042
1043     _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1044     _div = g()->nodes()->create<luci::CircleDiv>();
1045     {
1046       _div->x(input());
1047       _div->y(_const);
1048       _div->name("test");
1049     }
1050     output()->from(_div);
1051
1052     set_minmax_to_non_const(g(), -1, 1);
1053   }
1054
1055   loco::Node *x() { return _div->x(); }
1056
1057   loco::Node *y() { return _div->y(); }
1058
1059 private:
1060   luci::CircleDiv *_div = nullptr;
1061   luci::CircleConst *_const = nullptr;
1062 };
1063
1064 class FloorDivTestGraph final : public SimpleTestGraph
1065 {
1066 public:
1067   void init(void) override
1068   {
1069     TestIOGraph::init({32}, {32});
1070
1071     _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1072     _floor_div = g()->nodes()->create<luci::CircleFloorDiv>();
1073     {
1074       _floor_div->x(input());
1075       _floor_div->y(_const);
1076       _floor_div->name("test");
1077     }
1078     output()->from(_floor_div);
1079
1080     set_minmax_to_non_const(g(), -1, 1);
1081   }
1082
1083   loco::Node *x() { return _floor_div->x(); }
1084
1085   loco::Node *y() { return _floor_div->y(); }
1086
1087 private:
1088   luci::CircleFloorDiv *_floor_div = nullptr;
1089   luci::CircleConst *_const = nullptr;
1090 };
1091
1092 class RsqrtTestGraph final : public SimpleTestGraph
1093 {
1094 public:
1095   void init(void) override
1096   {
1097     TestIOGraph::init({32}, {32});
1098     _rsqrt = g()->nodes()->create<luci::CircleRsqrt>();
1099     {
1100       _rsqrt->x(input());
1101       _rsqrt->name("test");
1102     }
1103     output()->from(_rsqrt);
1104
1105     set_minmax_to_non_const(g(), -1, 1);
1106   }
1107
1108 private:
1109   luci::CircleRsqrt *_rsqrt = nullptr;
1110 };
1111
1112 class SqrtTestGraph final : public SimpleTestGraph
1113 {
1114 public:
1115   void init(void) override
1116   {
1117     TestIOGraph::init({32}, {32});
1118     _sqrt = g()->nodes()->create<luci::CircleSqrt>();
1119     {
1120       _sqrt->x(input());
1121       _sqrt->name("test");
1122     }
1123     output()->from(_sqrt);
1124
1125     set_minmax_to_non_const(g(), -1, 1);
1126   }
1127
1128 private:
1129   luci::CircleSqrt *_sqrt = nullptr;
1130 };
1131
1132 class EluTestGraph final : public SimpleTestGraph
1133 {
1134 public:
1135   void init(void) override
1136   {
1137     TestIOGraph::init({32}, {32});
1138     _elu = g()->nodes()->create<luci::CircleElu>();
1139     {
1140       _elu->features(input());
1141       _elu->name("test");
1142     }
1143     output()->from(_elu);
1144
1145     set_minmax_to_non_const(g(), -1, 1);
1146   }
1147
1148 private:
1149   luci::CircleElu *_elu = nullptr;
1150 };
1151
1152 class PowTestGraph final : public SimpleTestGraph
1153 {
1154 public:
1155   void init(void) override
1156   {
1157     TestIOGraph::init({32}, {32});
1158
1159     _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1160     _pow = g()->nodes()->create<luci::CirclePow>();
1161     {
1162       _pow->x(input());
1163       _pow->y(_const);
1164       _pow->name("test");
1165     }
1166     output()->from(_pow);
1167
1168     set_minmax_to_non_const(g(), -1, 1);
1169   }
1170
1171   loco::Node *x() { return _pow->x(); }
1172
1173   loco::Node *y() { return _pow->y(); }
1174
1175 private:
1176   luci::CirclePow *_pow = nullptr;
1177   luci::CircleConst *_const = nullptr;
1178 };
1179
1180 class ReduceMaxTestGraph final : public SimpleTestGraph
1181 {
1182 public:
1183   void init(void) override
1184   {
1185     TestIOGraph::init({4, 3, 2}, {2});
1186
1187     _axis = create_const<Type::S32, int32_t>(g(), {4}, {1, 0, -3, -3});
1188     _reduce_max = g()->nodes()->create<luci::CircleReduceMax>();
1189     {
1190       _reduce_max->input(input());
1191       _reduce_max->reduction_indices(_axis);
1192       _reduce_max->name("test");
1193       _reduce_max->keep_dims(false);
1194     }
1195     output()->from(_reduce_max);
1196
1197     set_minmax_to_non_const(g(), -1, 1);
1198   }
1199
1200 private:
1201   luci::CircleReduceMax *_reduce_max = nullptr;
1202   luci::CircleConst *_axis = nullptr;
1203 };
1204
1205 class ResizeBilinearTestGraph final : public SimpleTestGraph
1206 {
1207 public:
1208   void init(void) override
1209   {
1210     TestIOGraph::init({1, 4, 4, 1}, {1, 8, 8, 1});
1211
1212     _size = create_const<Type::S32, int32_t>(g(), {2}, {8, 8});
1213     _resize_bilinear = g()->nodes()->create<luci::CircleResizeBilinear>();
1214     {
1215       _resize_bilinear->input(input());
1216       _resize_bilinear->size(_size);
1217       _resize_bilinear->name("test");
1218     }
1219     output()->from(_resize_bilinear);
1220
1221     set_minmax_to_non_const(g(), -1, 1);
1222   }
1223
1224 private:
1225   luci::CircleResizeBilinear *_resize_bilinear = nullptr;
1226   luci::CircleConst *_size = nullptr;
1227 };
1228
1229 class ResizeNearestNeighborTestGraph final : public luci::test::TestIOGraph
1230 {
1231 public:
1232   void init(void)
1233   {
1234     TestIOGraph::init({1, 4, 4, 1}, {1, 8, 8, 1});
1235
1236     _size = create_const<Type::S32, int32_t>(g(), {2}, {8, 8});
1237     _resize_nearest_neighbor = g()->nodes()->create<luci::CircleResizeNearestNeighbor>();
1238     {
1239       _resize_nearest_neighbor->input(input());
1240       _resize_nearest_neighbor->size(_size);
1241       _resize_nearest_neighbor->name("test");
1242     }
1243     output()->from(_resize_nearest_neighbor);
1244
1245     set_minmax_to_non_const(g(), -1, 1);
1246   }
1247
1248 private:
1249   luci::CircleResizeNearestNeighbor *_resize_nearest_neighbor = nullptr;
1250   luci::CircleConst *_size = nullptr;
1251 };
1252
1253 class UnpackTestGraph final : public luci::test::TestIOGraph
1254 {
1255 public:
1256   void init(void)
1257   {
1258     TestIOGraph::init({1, 32}, {32});
1259     _unpack = g()->nodes()->create<luci::CircleUnpack>();
1260     {
1261       _unpack->value(input());
1262       _unpack->axis(0);
1263       _unpack->num(1);
1264     }
1265     _unpack_o1 = g()->nodes()->create<luci::CircleUnpackOut>();
1266     {
1267       _unpack_o1->input(_unpack);
1268       _unpack_o1->index(0);
1269     }
1270
1271     output()->from(_unpack_o1);
1272
1273     set_minmax_to_non_const(g(), -1, 1);
1274   }
1275
1276 private:
1277   luci::CircleUnpack *_unpack = nullptr;
1278   luci::CircleUnpackOut *_unpack_o1 = nullptr;
1279   luci::CircleConst *_unpack_dim = nullptr;
1280 };
1281
1282 class MulTestGraph final : public SimpleTestGraph
1283 {
1284 public:
1285   void init(void) override
1286   {
1287     TestIOGraph::init({32}, {32});
1288
1289     _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1290     _mul = g()->nodes()->create<luci::CircleMul>();
1291     {
1292       _mul->x(input());
1293       _mul->y(_const);
1294       _mul->fusedActivationFunction(luci::FusedActFunc::NONE);
1295       _mul->name("test");
1296     }
1297     output()->from(_mul);
1298
1299     set_minmax_to_non_const(g(), -1, 1);
1300   }
1301
1302   loco::Node *x() { return _mul->x(); }
1303   loco::Node *y() { return _mul->y(); }
1304
1305 private:
1306   luci::CircleMul *_mul = nullptr;
1307   luci::CircleConst *_const = nullptr;
1308 };
1309
1310 template <Type T> class IntMulTestGraph final : public TypedTestGraph
1311 {
1312 public:
1313   void init(void) override
1314   {
1315     TypedTestGraph::init(T, {32}, {32});
1316
1317     _const = create_dummy_const<T>(g(), {32});
1318     _mul = g()->nodes()->create<luci::CircleMul>();
1319     {
1320       _mul->x(input());
1321       _mul->y(_const);
1322       _mul->fusedActivationFunction(luci::FusedActFunc::NONE);
1323       _mul->name("test");
1324       _mul->dtype(T);
1325     }
1326     output()->from(_mul);
1327   }
1328
1329   loco::Node *x() { return _mul->x(); }
1330   loco::Node *y() { return _mul->y(); }
1331
1332 private:
1333   luci::CircleMul *_mul = nullptr;
1334   luci::CircleConst *_const = nullptr;
1335 };
1336
1337 class AddTestGraph final : public SimpleTestGraph
1338 {
1339 public:
1340   void init(void) override
1341   {
1342     TestIOGraph::init({32}, {32});
1343
1344     _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1345     _add = g()->nodes()->create<luci::CircleAdd>();
1346     {
1347       _add->x(input());
1348       _add->y(_const);
1349       _add->fusedActivationFunction(luci::FusedActFunc::NONE);
1350       _add->name("test");
1351     }
1352     output()->from(_add);
1353
1354     set_minmax_to_non_const(g(), -1, 1);
1355   }
1356
1357   loco::Node *x() { return _add->x(); }
1358   loco::Node *y() { return _add->y(); }
1359
1360 private:
1361   luci::CircleAdd *_add = nullptr;
1362   luci::CircleConst *_const = nullptr;
1363 };
1364
1365 template <Type T> class IntAddTestGraph final : public TypedTestGraph
1366 {
1367 public:
1368   void init(void) override
1369   {
1370     TypedTestGraph::init(T, {32}, {32});
1371
1372     _const = create_dummy_const<T>(g(), {32});
1373     _add = g()->nodes()->create<luci::CircleAdd>();
1374     {
1375       _add->x(input());
1376       _add->y(_const);
1377       _add->fusedActivationFunction(luci::FusedActFunc::NONE);
1378       _add->name("test");
1379       _add->dtype(T);
1380     }
1381     output()->from(_add);
1382   }
1383
1384   loco::Node *x() { return _add->x(); }
1385   loco::Node *y() { return _add->y(); }
1386
1387 private:
1388   luci::CircleAdd *_add = nullptr;
1389   luci::CircleConst *_const = nullptr;
1390 };
1391
1392 } // namespace
1393
1394 // Quantize and verify with given configurations
1395 #define TEST_WITH_GRAPH(graph, type, granularity)                   \
1396   do                                                                \
1397   {                                                                 \
1398     graph g;                                                        \
1399     g.init();                                                       \
1400     EXPECT_NO_THROW(quantize_and_verify(g.g(), type, granularity)); \
1401   } while (0)
1402
1403 // Quantize and verify with layer info
1404 #define TEST_WITH_LAYER_INFO(graph, type, granularity)                              \
1405   do                                                                                \
1406   {                                                                                 \
1407     graph g;                                                                        \
1408     g.init();                                                                       \
1409     EXPECT_NO_THROW(quantize_and_verify_with_layer_info(g.g(), type, granularity)); \
1410   } while (0)
1411
1412 // Quantize and verify with wrong type
1413 #define TEST_WITH_WRONG_TYPE(graph, type, granularity, wrong_dtype)                            \
1414   do                                                                                           \
1415   {                                                                                            \
1416     graph g;                                                                                   \
1417     g.init();                                                                                  \
1418     EXPECT_ANY_THROW(quantize_and_verify_with_wrong_type(&g, type, granularity, wrong_dtype)); \
1419   } while (0)
1420
1421 // Quantize and verify with wrong granularity
1422 #define TEST_WITH_WRONG_GRANULARITY(graph, type, granularity)                            \
1423   do                                                                                     \
1424   {                                                                                      \
1425     graph g;                                                                             \
1426     g.init();                                                                            \
1427     EXPECT_ANY_THROW(quantize_and_verify_with_wrong_granularity(&g, type, granularity)); \
1428   } while (0)
1429
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) \
1433   do                                                                                \
1434   {                                                                                 \
1435     graph g;                                                                        \
1436     g.init();                                                                       \
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>();           \
1442     {                                                                               \
1443       ctx->output_model_dtype = type;                                               \
1444       ctx->granularity = granularity_;                                              \
1445       ctx->input_types = {type};                                                    \
1446       ctx->output_types = {type};                                                   \
1447     }                                                                               \
1448     luci::QuantizedModelVerifier verifier(std::move(ctx));                          \
1449     EXPECT_ANY_THROW(verifier.verify(g.g()));                                       \
1450   } while (0)
1451
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) \
1455   do                                                                          \
1456   {                                                                           \
1457     graph g;                                                                  \
1458     g.init();                                                                 \
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>();     \
1464     {                                                                         \
1465       ctx->output_model_dtype = type;                                         \
1466       ctx->granularity = granularity_;                                        \
1467       ctx->input_types = {type};                                              \
1468       ctx->output_types = {type};                                             \
1469     }                                                                         \
1470     luci::QuantizedModelVerifier verifier(std::move(ctx));                    \
1471     EXPECT_ANY_THROW(verifier.verify(g.g()));                                 \
1472   } while (0)
1473
1474 // Test a local helper function
1475 TEST(QuantizedModelVerifierTest, LocalCreateDummyConst)
1476 {
1477   loco::Graph g;
1478
1479   EXPECT_NO_THROW(create_dummy_const<Type::FLOAT32>(&g, {32, 32}));
1480 }
1481
1482 TEST(QuantizedModelVerifierTest, LocalCreateConst)
1483 {
1484   loco::Graph g;
1485   std::initializer_list<float> values = {0.1, 0, -5, 100};
1486   luci::CircleConst *node = create_const<Type::FLOAT32, float>(&g, {2, 2}, values);
1487
1488   uint32_t index = 0;
1489   for (auto val : values)
1490   {
1491     EXPECT_EQ(node->at<Type::FLOAT32>(index++), val);
1492   }
1493 }
1494
1495 TEST(QuantizedModelVerifierTest, InstanceNorm)
1496 {
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);
1500
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);
1504   SUCCEED();
1505 }
1506
1507 TEST(QuantizedModelVerifierTest, InstanceNorm_wrong_type_NEG)
1508 {
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);
1512   SUCCEED();
1513 }
1514
1515 TEST(QuantizedModelVerifierTest, InstanceNorm_wrong_granularity_NEG)
1516 {
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);
1520   SUCCEED();
1521 }
1522
1523 TEST(QuantizedModelVerifierTest, LocalResponseNormalization)
1524 {
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);
1528
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);
1532   SUCCEED();
1533 }
1534
1535 TEST(QuantizedModelVerifierTest, LocalResponseNormalization_wrong_type_NEG)
1536 {
1537   TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise,
1538                        Type::S16);
1539   TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise,
1540                        Type::S16);
1541   TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise,
1542                        Type::U8);
1543   SUCCEED();
1544 }
1545
1546 TEST(QuantizedModelVerifierTest, LocalResponseNormalization_wrong_granularity_NEG)
1547 {
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);
1554   SUCCEED();
1555 }
1556
1557 TEST(QuantizedModelVerifierTest, Logistic)
1558 {
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);
1562
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);
1566   SUCCEED();
1567 }
1568
1569 TEST(QuantizedModelVerifierTest, Logistic_wrong_type_NEG)
1570 {
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);
1574   SUCCEED();
1575 }
1576
1577 TEST(QuantizedModelVerifierTest, Logistic_wrong_granularity_NEG)
1578 {
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);
1582   SUCCEED();
1583 }
1584
1585 TEST(QuantizedModelVerifierTest, Softmax)
1586 {
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);
1590
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);
1594   SUCCEED();
1595 }
1596
1597 TEST(QuantizedModelVerifierTest, Softmax_wrong_type_NEG)
1598 {
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);
1602   SUCCEED();
1603 }
1604
1605 TEST(QuantizedModelVerifierTest, Softmax_wrong_granularity_NEG)
1606 {
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);
1610   SUCCEED();
1611 }
1612
1613 TEST(QuantizedModelVerifierTest, SpaceToBatchND)
1614 {
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);
1618
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);
1622   SUCCEED();
1623 }
1624
1625 TEST(QuantizedModelVerifierTest, SpaceToBatchND_wrong_type_NEG)
1626 {
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);
1630   SUCCEED();
1631 }
1632
1633 TEST(QuantizedModelVerifierTest, SpaceToBatchND_wrong_granularity_NEG)
1634 {
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);
1638   SUCCEED();
1639 }
1640
1641 TEST(QuantizedModelVerifierTest, SpaceToDepth)
1642 {
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);
1646
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);
1650   SUCCEED();
1651 }
1652
1653 TEST(QuantizedModelVerifierTest, SpaceToDepth_wrong_type_NEG)
1654 {
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);
1658   SUCCEED();
1659 }
1660
1661 TEST(QuantizedModelVerifierTest, SpaceToDepth_wrong_granularity_NEG)
1662 {
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);
1666   SUCCEED();
1667 }
1668
1669 TEST(QuantizedModelVerifierTest, Slice)
1670 {
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);
1674
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);
1678
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);
1682
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);
1686   SUCCEED();
1687 }
1688
1689 TEST(QuantizedModelVerifierTest, Slice_wrong_type_NEG)
1690 {
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);
1694
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);
1698   SUCCEED();
1699 }
1700
1701 TEST(QuantizedModelVerifierTest, Slice_wrong_granularity_NEG)
1702 {
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);
1706
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);
1710   SUCCEED();
1711 }
1712
1713 TEST(QuantizedModelVerifierTest, Split)
1714 {
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);
1718   SUCCEED();
1719 }
1720
1721 TEST(QuantizedModelVerifierTest, Split_wrong_type_NEG)
1722 {
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);
1726   SUCCEED();
1727 }
1728
1729 TEST(QuantizedModelVerifierTest, Split_wrong_granularity_NEG)
1730 {
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);
1734   SUCCEED();
1735 }
1736
1737 TEST(QuantizedModelVerifierTest, SplitV)
1738 {
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);
1742   SUCCEED();
1743 }
1744
1745 TEST(QuantizedModelVerifierTest, SplitV_wrong_type_NEG)
1746 {
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);
1750   SUCCEED();
1751 }
1752
1753 TEST(QuantizedModelVerifierTest, SplitV_wrong_granularity_NEG)
1754 {
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);
1758   SUCCEED();
1759 }
1760
1761 TEST(QuantizedModelVerifierTest, StridedSlice)
1762 {
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);
1766
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);
1770   SUCCEED();
1771 }
1772
1773 TEST(QuantizedModelVerifierTest, StridedSlice_wrong_type_NEG)
1774 {
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);
1778   SUCCEED();
1779 }
1780
1781 TEST(QuantizedModelVerifierTest, StridedSlice_wrong_granularity_NEG)
1782 {
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);
1786   SUCCEED();
1787 }
1788
1789 TEST(QuantizedModelVerifierTest, ArgMax)
1790 {
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);
1794
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);
1798   SUCCEED();
1799 }
1800
1801 TEST(QuantizedModelVerifierTest, ArgMax_wrong_input_type_NEG)
1802 {
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);
1806
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);
1810   SUCCEED();
1811 }
1812
1813 TEST(QuantizedModelVerifierTest, ArgMax_wrong_dimension_type_NEG)
1814 {
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());
1821
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());
1828   SUCCEED();
1829 }
1830
1831 TEST(QuantizedModelVerifierTest, ArgMax_wrong_granularity_NEG)
1832 {
1833   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise,
1834                                      g.input_argmax());
1835   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise,
1836                                      g.input_argmax());
1837   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::S16,
1838                                      Granularity::ChannelWise, g.input_argmax());
1839
1840   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise,
1841                                      g.input_argmax());
1842   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise,
1843                                      g.input_argmax());
1844   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::S16,
1845                                      Granularity::ChannelWise, g.input_argmax());
1846   SUCCEED();
1847 }
1848
1849 TEST(QuantizedModelVerifierTest, BatchToSpaceND)
1850 {
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);
1854
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);
1858   SUCCEED();
1859 }
1860
1861 TEST(QuantizedModelVerifierTest, BatchToSpaceND_wrong_type_NEG)
1862 {
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);
1866   SUCCEED();
1867 }
1868
1869 TEST(QuantizedModelVerifierTest, BatchToSpaceND_wrong_granularity_NEG)
1870 {
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);
1874   SUCCEED();
1875 }
1876
1877 TEST(QuantizedModelVerifierTest, DepthToSpace)
1878 {
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);
1882
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);
1886   SUCCEED();
1887 }
1888
1889 TEST(QuantizedModelVerifierTest, DepthToSpace_wrong_type_NEG)
1890 {
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);
1894   SUCCEED();
1895 }
1896
1897 TEST(QuantizedModelVerifierTest, DepthToSpace_wrong_granularity_NEG)
1898 {
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);
1902   SUCCEED();
1903 }
1904
1905 TEST(QuantizedModelVerifierTest, Concatenation)
1906 {
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);
1910
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);
1914   SUCCEED();
1915 }
1916
1917 TEST(QuantizedModelVerifierTest, Concatenation_wrong_type_NEG)
1918 {
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);
1922   SUCCEED();
1923 }
1924
1925 TEST(QuantizedModelVerifierTest, Concatenation_wrong_granularity_NEG)
1926 {
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);
1930   SUCCEED();
1931 }
1932
1933 TEST(QuantizedModelVerifierTest, LogicalOr)
1934 {
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);
1941   SUCCEED();
1942 }
1943
1944 TEST(QuantizedModelVerifierTest, LogicalOr_wrong_type_NEG)
1945 {
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);
1952   SUCCEED();
1953 }
1954
1955 TEST(QuantizedModelVerifierTest, Reshape)
1956 {
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);
1960
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);
1964   SUCCEED();
1965 }
1966
1967 TEST(QuantizedModelVerifierTest, Reshape_wrong_type_NEG)
1968 {
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);
1972   SUCCEED();
1973 }
1974
1975 TEST(QuantizedModelVerifierTest, Reshape_wrong_granularity_NEG)
1976 {
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);
1980   SUCCEED();
1981 }
1982
1983 TEST(QuantizedModelVerifierTest, Tanh)
1984 {
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);
1988
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);
1992   SUCCEED();
1993 }
1994
1995 TEST(QuantizedModelVerifierTest, Tanh_wrong_type_NEG)
1996 {
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);
2000   SUCCEED();
2001 }
2002
2003 TEST(QuantizedModelVerifierTest, Tanh_wrong_granularity_NEG)
2004 {
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);
2008   SUCCEED();
2009 }
2010
2011 TEST(QuantizedModelVerifierTest, Pack)
2012 {
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);
2016
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);
2020
2021   // Test if Pack's qparam is propagated to the input
2022   {
2023     PackTestGraph g;
2024     g.init();
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]);
2030   }
2031   SUCCEED();
2032 }
2033
2034 TEST(QuantizedModelVerifierTest, Pack_wrong_type_NEG)
2035 {
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);
2039   SUCCEED();
2040 }
2041
2042 TEST(QuantizedModelVerifierTest, Pack_wrong_granularity_NEG)
2043 {
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);
2047   SUCCEED();
2048 }
2049
2050 TEST(QuantizedModelVerifierTest, Pad)
2051 {
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);
2055
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);
2059   SUCCEED();
2060 }
2061
2062 TEST(QuantizedModelVerifierTest, Pad_wrong_type_NEG)
2063 {
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);
2067   SUCCEED();
2068 }
2069
2070 TEST(QuantizedModelVerifierTest, Pad_wrong_granularity_NEG)
2071 {
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);
2075   SUCCEED();
2076 }
2077
2078 TEST(QuantizedModelVerifierTest, PadV2)
2079 {
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);
2083
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);
2087   SUCCEED();
2088 }
2089
2090 TEST(QuantizedModelVerifierTest, PadV2_wrong_type_NEG)
2091 {
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);
2095   SUCCEED();
2096 }
2097
2098 TEST(QuantizedModelVerifierTest, PadV2_wrong_granularity_NEG)
2099 {
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);
2103   SUCCEED();
2104 }
2105
2106 TEST(QuantizedModelVerifierTest, MirrorPad)
2107 {
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);
2111
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);
2115   SUCCEED();
2116 }
2117
2118 TEST(QuantizedModelVerifierTest, MirrorPad_wrong_type_NEG)
2119 {
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);
2123   SUCCEED();
2124 }
2125
2126 TEST(QuantizedModelVerifierTest, MirrorPad_wrong_granularity_NEG)
2127 {
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);
2131   SUCCEED();
2132 }
2133
2134 TEST(QuantizedModelVerifierTest, Transpose)
2135 {
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);
2139
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);
2143   SUCCEED();
2144 }
2145
2146 TEST(QuantizedModelVerifierTest, Transpose_wrong_type_NEG)
2147 {
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);
2151   SUCCEED();
2152 }
2153
2154 TEST(QuantizedModelVerifierTest, Transpose_wrong_granularity_NEG)
2155 {
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);
2159   SUCCEED();
2160 }
2161
2162 TEST(QuantizedModelVerifierTest, Floor)
2163 {
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);
2167
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);
2171   SUCCEED();
2172 }
2173
2174 TEST(QuantizedModelVerifierTest, Floor_wrong_type_NEG)
2175 {
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);
2179   SUCCEED();
2180 }
2181
2182 TEST(QuantizedModelVerifierTest, Floor_wrong_granularity_NEG)
2183 {
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);
2187   SUCCEED();
2188 }
2189
2190 TEST(QuantizedModelVerifierTest, GreaterEqual)
2191 {
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);
2198   SUCCEED();
2199 }
2200
2201 TEST(QuantizedModelVerifierTest, GreaterEqual_wrong_type_NEG)
2202 {
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);
2209   SUCCEED();
2210 }
2211
2212 TEST(QuantizedModelVerifierTest, GreaterEqual_wrong_granularity_NEG)
2213 {
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());
2220
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());
2227   SUCCEED();
2228 }
2229
2230 TEST(QuantizedModelVerifierTest, Greater)
2231 {
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);
2235   SUCCEED();
2236 }
2237
2238 TEST(QuantizedModelVerifierTest, Greater_wrong_type_NEG)
2239 {
2240   TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::LayerWise,
2241                        Type::U8);
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);
2246   SUCCEED();
2247 }
2248
2249 TEST(QuantizedModelVerifierTest, Greater_wrong_granularity_NEG)
2250 {
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());
2257
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());
2264   SUCCEED();
2265 }
2266
2267 TEST(QuantizedModelVerifierTest, NotEqual)
2268 {
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);
2272   SUCCEED();
2273 }
2274
2275 TEST(QuantizedModelVerifierTest, NotEqual_wrong_type_NEG)
2276 {
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);
2283   SUCCEED();
2284 }
2285
2286 TEST(QuantizedModelVerifierTest, NotEqual_wrong_granularity_NEG)
2287 {
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());
2294
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());
2301   SUCCEED();
2302 }
2303
2304 TEST(QuantizedModelVerifierTest, OneHot)
2305 {
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);
2309
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);
2313
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);
2317
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);
2321   SUCCEED();
2322 }
2323
2324 TEST(QuantizedModelVerifierTest, OneHot_wrong_input_type_NEG)
2325 {
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);
2329
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);
2333   SUCCEED();
2334 }
2335
2336 TEST(QuantizedModelVerifierTest, OneHot_wrong_granularity_NEG)
2337 {
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);
2341
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);
2345   SUCCEED();
2346 }
2347
2348 TEST(QuantizedModelVerifierTest, Div)
2349 {
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);
2353
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);
2357   SUCCEED();
2358 }
2359
2360 TEST(QuantizedModelVerifierTest, Div_wrong_type_NEG)
2361 {
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);
2365   SUCCEED();
2366 }
2367
2368 TEST(QuantizedModelVerifierTest, Div_wrong_granularity_NEG)
2369 {
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());
2373
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());
2377   SUCCEED();
2378 }
2379
2380 TEST(QuantizedModelVerifierTest, FloorDiv)
2381 {
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);
2385
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);
2389   SUCCEED();
2390 }
2391
2392 TEST(QuantizedModelVerifierTest, FloorDiv_wrong_type_NEG)
2393 {
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);
2397   SUCCEED();
2398 }
2399
2400 TEST(QuantizedModelVerifierTest, FloorDiv_wrong_granularity_NEG)
2401 {
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());
2405
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());
2409   SUCCEED();
2410 }
2411
2412 TEST(QuantizedModelVerifierTest, Rsqrt)
2413 {
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);
2417
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);
2421   SUCCEED();
2422 }
2423
2424 TEST(QuantizedModelVerifierTest, Rsqrt_wrong_type_NEG)
2425 {
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);
2429   SUCCEED();
2430 }
2431
2432 TEST(QuantizedModelVerifierTest, Rsqrt_wrong_granularity_NEG)
2433 {
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);
2437   SUCCEED();
2438 }
2439
2440 TEST(QuantizedModelVerifierTest, Sqrt)
2441 {
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);
2445
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);
2449   SUCCEED();
2450 }
2451
2452 TEST(QuantizedModelVerifierTest, Sqrt_wrong_type_NEG)
2453 {
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);
2457   SUCCEED();
2458 }
2459
2460 TEST(QuantizedModelVerifierTest, Sqrt_wrong_granularity_NEG)
2461 {
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);
2465   SUCCEED();
2466 }
2467
2468 TEST(QuantizedModelVerifierTest, Elu)
2469 {
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);
2473
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);
2477   SUCCEED();
2478 }
2479
2480 TEST(QuantizedModelVerifierTest, Elu_wrong_type_NEG)
2481 {
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);
2485   SUCCEED();
2486 }
2487
2488 TEST(QuantizedModelVerifierTest, Elu_wrong_granularity_NEG)
2489 {
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);
2493   SUCCEED();
2494 }
2495
2496 TEST(QuantizedModelVerifierTest, Pow)
2497 {
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);
2501
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);
2505   SUCCEED();
2506 }
2507
2508 TEST(QuantizedModelVerifierTest, Pow_wrong_type_NEG)
2509 {
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);
2513   SUCCEED();
2514 }
2515
2516 TEST(QuantizedModelVerifierTest, Pow_wrong_granularity_NEG)
2517 {
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());
2521
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());
2525   SUCCEED();
2526 }
2527
2528 TEST(QuantizedModelVerifierTest, ReduceMax)
2529 {
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);
2533
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);
2537   SUCCEED();
2538 }
2539
2540 TEST(QuantizedModelVerifierTest, ReduceMax_wrong_type_NEG)
2541 {
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);
2545   SUCCEED();
2546 }
2547
2548 TEST(QuantizedModelVerifierTest, ReduceMax_wrong_granularity_NEG)
2549 {
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);
2553   SUCCEED();
2554 }
2555
2556 TEST(QuantizedModelVerifierTest, ResizeBilinear)
2557 {
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);
2561
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);
2565   SUCCEED();
2566 }
2567
2568 TEST(QuantizedModelVerifierTest, ResizeBilinear_wrong_type_NEG)
2569 {
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);
2573   SUCCEED();
2574 }
2575
2576 TEST(QuantizedModelVerifierTest, ResizeBilinear_wrong_granularity_NEG)
2577 {
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);
2581   SUCCEED();
2582 }
2583
2584 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor)
2585 {
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);
2589
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);
2593   SUCCEED();
2594 }
2595
2596 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor_wrong_type_NEG)
2597 {
2598   TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2599   TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise,
2600                        Type::S16);
2601   TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise,
2602                        Type::U8);
2603   SUCCEED();
2604 }
2605
2606 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor_wrong_granularity_NEG)
2607 {
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);
2611   SUCCEED();
2612 }
2613
2614 TEST(QuantizedModelVerifierTest, Unpack)
2615 {
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);
2619   SUCCEED();
2620 }
2621
2622 TEST(QuantizedModelVerifierTest, Unpack_wrong_type_NEG)
2623 {
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);
2627   SUCCEED();
2628 }
2629
2630 TEST(QuantizedModelVerifierTest, Unpack_wrong_granularity_NEG)
2631 {
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);
2635   SUCCEED();
2636 }
2637
2638 TEST(QuantizedModelVerifierTest, Add)
2639 {
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);
2643
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);
2647   SUCCEED();
2648 }
2649
2650 TEST(QuantizedModelVerifierTest, Add_wrong_type_NEG)
2651 {
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);
2655   SUCCEED();
2656 }
2657
2658 TEST(QuantizedModelVerifierTest, Add_wrong_granularity_NEG)
2659 {
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());
2663
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());
2667   SUCCEED();
2668 }
2669
2670 TEST(QuantizedModelVerifierTest, Add_inttype)
2671 {
2672   // Tests for S32
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);
2676
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);
2680
2681   // Tests for S64
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);
2685
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);
2689
2690   SUCCEED();
2691 }
2692
2693 TEST(QuantizedModelVerifierTest, Mul)
2694 {
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);
2698
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);
2702   SUCCEED();
2703 }
2704
2705 TEST(QuantizedModelVerifierTest, Mul_wrong_type_NEG)
2706 {
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);
2710   SUCCEED();
2711 }
2712
2713 TEST(QuantizedModelVerifierTest, Mul_wrong_granularity_NEG)
2714 {
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());
2718
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());
2722   SUCCEED();
2723 }
2724
2725 TEST(QuantizedModelVerifierTest, Mul_inttype)
2726 {
2727   // Tests for S32
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);
2731
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);
2735
2736   // Tests for S64
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);
2740
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);
2744
2745   SUCCEED();
2746 }
2747
2748 // TODO Add following testcases
2749 //
2750 // CircleConv2D
2751 //
2752 // CircleDepthwiseConv2D
2753 //
2754 // CirclePRelu
2755 //
2756 // CircleTransposeConv
2757 //
2758 // CircleFullyConnected
2759 //
2760 // CircleAveragePool2D
2761 //
2762 // CircleMaxPool2D
2763 //
2764 // CircleMean
2765 //
2766 // CircleRelu
2767 //
2768 // CircleCast
2769 //
2770
2771 #undef TEST_WITH_GRAPH
2772 #undef TEST_WITH_WRONG_TYPE
2773 #undef TEST_WITH_WRONG_GRANULARITY