Imported Upstream version 1.25.0
[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         default:
70           break;
71       }
72     }
73   }
74
75   return node;
76 }
77
78 /**
79  * @brief A helper function to create const node with value
80  */
81 template <Type DT, typename T>
82 luci::CircleConst *create_const(loco::Graph *g, luci::test::ShapeU32 shape,
83                                 std::initializer_list<T> values)
84 {
85   auto node = g->nodes()->create<luci::CircleConst>();
86   {
87     node->dtype(DT);
88     node->shape(shape);
89     node->size<DT>(luci::test::num_elements(shape));
90
91     assert(values.size() == node->size<DT>());
92
93     uint32_t index = 0;
94     for (auto val : values)
95     {
96       node->at<DT>(index++) = static_cast<T>(val);
97     }
98   }
99
100   return node;
101 }
102
103 void insert_scale_zp(luci::CircleNode *node, float scale, int64_t zp)
104 {
105   auto qparam = node->quantparam();
106   assert(qparam != nullptr); // FIX_CALLER_UNLESS
107   qparam->scale.push_back(scale);
108   qparam->zerop.push_back(zp);
109 }
110
111 void run_phase(loco::Graph *g, Type quantized_dtype, Granularity granularity)
112 {
113   logo::Phase phase;
114
115   // Default passes.
116   phase.emplace_back(std::make_unique<luci::CircleTypeInferencePass>());
117
118   auto ctx = std::make_unique<luci::QuantizeWithMinMaxPass::Context>();
119   {
120     ctx->input_model_dtype = loco::DataType::FLOAT32;
121     ctx->output_model_dtype = quantized_dtype;
122     ctx->granularity = granularity;
123     // Test graph has only one input/output
124     ctx->input_types = {quantized_dtype};
125     ctx->output_types = {quantized_dtype};
126   }
127
128   phase.emplace_back(std::make_unique<luci::QuantizeWithMinMaxPass>(std::move(ctx)));
129
130   logo::PhaseRunner<logo::PhaseStrategy::Restart> phase_runner{g};
131   phase_runner.run(phase);
132 }
133
134 void run_phase(loco::Graph *g, std::unique_ptr<luci::QuantizeWithMinMaxPass::Context> &&ctx)
135 {
136   logo::Phase phase;
137
138   // Default passes.
139   phase.emplace_back(std::make_unique<luci::CircleTypeInferencePass>());
140
141   phase.emplace_back(std::make_unique<luci::QuantizeWithMinMaxPass>(std::move(ctx)));
142
143   logo::PhaseRunner<logo::PhaseStrategy::Restart> phase_runner{g};
144   phase_runner.run(phase);
145 }
146
147 void quantize_and_verify(loco::Graph *g, Type quantized_dtype, Granularity granularity)
148 {
149   run_phase(g, quantized_dtype, granularity);
150
151   auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
152   {
153     ctx->output_model_dtype = quantized_dtype;
154     ctx->granularity = granularity;
155     // Test graph has only one input/output
156     ctx->input_types = {quantized_dtype};
157     ctx->output_types = {quantized_dtype};
158   }
159
160   luci::QuantizedModelVerifier verifier(std::move(ctx));
161   verifier.verify(g);
162 }
163
164 void quantize_and_verify_with_layer_info(loco::Graph *g, Type quantized_dtype,
165                                          Granularity granularity)
166 {
167   // A layer named "test" has dtype different from quantized_dtype
168   luci::LayerInfo info;
169   {
170     info.name = "test";
171     // dtype is different from quantized_dtype
172     info.dtype = quantized_dtype == Type::U8 ? Type::S16 : Type::U8;
173     info.granularity = Granularity::ChannelWise;
174   }
175
176   // Do quantization
177   {
178     auto ctx = std::make_unique<luci::QuantizeWithMinMaxPass::Context>();
179     {
180       ctx->input_model_dtype = Type::FLOAT32;
181       ctx->output_model_dtype = quantized_dtype;
182       ctx->granularity = granularity;
183       // Test graph has only one input/output
184       ctx->input_types = {quantized_dtype};
185       ctx->output_types = {quantized_dtype};
186       ctx->TF_style_maxpool = false;
187       ctx->layers_info.push_back(info);
188     }
189
190     run_phase(g, std::move(ctx));
191   }
192
193   // Do verification
194   {
195     auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
196     {
197       ctx->output_model_dtype = quantized_dtype;
198       ctx->granularity = granularity;
199       ctx->input_types = {quantized_dtype};
200       ctx->output_types = {quantized_dtype};
201       ctx->TF_style_maxpool = false;
202       ctx->layers_info.push_back(info);
203     }
204
205     luci::QuantizedModelVerifier verifier(std::move(ctx));
206     verifier.verify(g);
207   }
208 }
209
210 // Helper function to reduce duplicate test codes
211 // Assumption: g->output()->from() is the target node
212 void quantize_and_verify_with_wrong_type(luci::test::TestIOGraph *g, Type quantized_dtype,
213                                          Granularity granularity, Type wrong_dtype)
214 {
215   run_phase(g->g(), quantized_dtype, granularity);
216
217   auto node = loco::must_cast<luci::CircleNode *>(g->output()->from());
218   node->dtype(wrong_dtype);
219
220   auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
221   {
222     ctx->output_model_dtype = quantized_dtype;
223     ctx->granularity = granularity;
224     // Test graph has only one input/output
225     ctx->input_types = {quantized_dtype};
226     ctx->output_types = {quantized_dtype};
227   }
228
229   luci::QuantizedModelVerifier verifier(std::move(ctx));
230   verifier.verify(g->g());
231 }
232
233 // Helper function to reduce duplicate test codes
234 // Assumption: g->output()->from() is the target node
235 void quantize_and_verify_with_wrong_granularity(luci::test::TestIOGraph *g, Type quantized_dtype,
236                                                 Granularity granularity)
237 {
238   run_phase(g->g(), quantized_dtype, granularity);
239
240   auto node = loco::must_cast<luci::CircleNode *>(g->output()->from());
241   insert_scale_zp(node, 1.0, 1);
242
243   auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();
244   {
245     ctx->output_model_dtype = quantized_dtype;
246     ctx->granularity = granularity;
247     // Test graph has only one input/output
248     ctx->input_types = {quantized_dtype};
249     ctx->output_types = {quantized_dtype};
250   }
251
252   luci::QuantizedModelVerifier verifier(std::move(ctx));
253   verifier.verify(g->g());
254 }
255
256 // Set min/max for all non-const nodes in the graph
257 void set_minmax_to_non_const(loco::Graph *g, float min, float max)
258 {
259   for (auto node : loco::all_nodes(g))
260   {
261     auto const_node = dynamic_cast<luci::CircleConst *>(node);
262     if (const_node != nullptr)
263       continue;
264
265     // Min/Max is not recorded for ArgMax
266     // See MinMaxObserver.cpp in record_minmax module
267     auto argmax_node = dynamic_cast<luci::CircleArgMax *>(node);
268     if (argmax_node != nullptr)
269       continue;
270
271     // Min/Max is not recorded for Split
272     // See MinMaxObserver.cpp in record_minmax module
273     auto split_node = dynamic_cast<luci::CircleSplit *>(node);
274     if (split_node != nullptr)
275       continue;
276
277     // Min/Max is not recorded for SplitV
278     // See MinMaxObserver.cpp in record_minmax module
279     auto splitv_node = dynamic_cast<luci::CircleSplitV *>(node);
280     if (splitv_node != nullptr)
281       continue;
282
283     auto circle_node = loco::must_cast<luci::CircleNode *>(node);
284     auto qparam = std::make_unique<luci::CircleQuantParam>();
285     {
286       qparam->min.emplace_back(min);
287       qparam->max.emplace_back(max);
288     }
289     circle_node->quantparam(std::move(qparam));
290   }
291 }
292
293 /**
294  * @brief Simple Test Graph
295  * @note
296  * The simple test graph's nodes are initialized with
297  * simple shapes and values.
298  */
299 class SimpleTestGraph : public luci::test::TestIOGraph
300 {
301 public:
302   virtual void init(void) = 0;
303 };
304
305 class TypedTestGraph : public luci::test::TestIOGraph
306 {
307 protected:
308   void init(Type T, const luci::test::ShapeU32 shape_in, const luci::test::ShapeU32 shape_out)
309   {
310     TestIOGraph::init(shape_in, shape_out);
311
312     input()->dtype(T);
313     output()->dtype(T);
314
315     g()->inputs()->at(0)->dtype(T);
316     g()->outputs()->at(0)->dtype(T);
317   }
318
319 public:
320   virtual void init(void) = 0;
321 };
322
323 class InstanceNormTestGraph final : public SimpleTestGraph
324 {
325 public:
326   void init(void) override
327   {
328     TestIOGraph::init({32}, {32});
329     _gamma = create_dummy_const<Type::FLOAT32>(g(), {32});
330     _beta = create_dummy_const<Type::FLOAT32>(g(), {32});
331     _instnorm = g()->nodes()->create<luci::CircleInstanceNorm>();
332     {
333       _instnorm->input(input());
334       _instnorm->gamma(_gamma);
335       _instnorm->beta(_beta);
336       _instnorm->fusedActivationFunction(luci::FusedActFunc::NONE);
337       _instnorm->name("test");
338     }
339     output()->from(_instnorm);
340
341     set_minmax_to_non_const(g(), -1, 1);
342   }
343
344 public:
345   loco::Node *gamma(void) const { return _instnorm->gamma(); }
346   loco::Node *beta(void) const { return _instnorm->beta(); }
347
348 private:
349   luci::CircleInstanceNorm *_instnorm = nullptr;
350   luci::CircleConst *_input = nullptr;
351   luci::CircleConst *_gamma = nullptr;
352   luci::CircleConst *_beta = nullptr;
353 };
354
355 class LogisticTestGraph final : public SimpleTestGraph
356 {
357 public:
358   void init(void) override
359   {
360     TestIOGraph::init({32}, {32});
361     _logistic = g()->nodes()->create<luci::CircleLogistic>();
362     {
363       _logistic->x(input());
364       _logistic->name("test");
365     }
366     output()->from(_logistic);
367
368     set_minmax_to_non_const(g(), -1, 1);
369   }
370
371 private:
372   luci::CircleLogistic *_logistic = nullptr;
373 };
374
375 class LocalResponseNormalizationTestGraph final : public SimpleTestGraph
376 {
377 public:
378   void init(void) override
379   {
380     TestIOGraph::init({1, 2, 2, 32}, {1, 2, 2, 32});
381     _lrn = g()->nodes()->create<luci::CircleLocalResponseNormalization>();
382     {
383       _lrn->input(input());
384       _lrn->name("test");
385     }
386     output()->from(_lrn);
387
388     set_minmax_to_non_const(g(), -1, 1);
389   }
390
391 private:
392   luci::CircleLocalResponseNormalization *_lrn = nullptr;
393 };
394
395 class SoftmaxTestGraph final : public SimpleTestGraph
396 {
397 public:
398   void init(void) override
399   {
400     TestIOGraph::init({32}, {32});
401     _softmax = g()->nodes()->create<luci::CircleSoftmax>();
402     {
403       _softmax->logits(input());
404       _softmax->beta(0.1);
405       _softmax->name("test");
406     }
407     output()->from(_softmax);
408
409     set_minmax_to_non_const(g(), -1, 1);
410   }
411
412 private:
413   luci::CircleSoftmax *_softmax = nullptr;
414 };
415
416 class SpaceToBatchNDTestGraph final : public SimpleTestGraph
417 {
418 public:
419   void init(void) override
420   {
421     TestIOGraph::init({1, 2, 2, 1}, {4, 1, 1, 1});
422     _block_shape = create_dummy_const<Type::S32>(g(), {2});
423     for (uint32_t i = 0; i < 2; i++)
424       _block_shape->at<Type::S32>(i) = 2;
425
426     _paddings = create_dummy_const<Type::S32>(g(), {2, 2});
427     for (uint32_t i = 0; i < 4; i++)
428       _paddings->at<Type::S32>(i) = 0;
429
430     _stob = g()->nodes()->create<luci::CircleSpaceToBatchND>();
431     {
432       _stob->input(input());
433       _stob->block_shape(_block_shape);
434       _stob->paddings(_paddings);
435       _stob->name("test");
436     }
437     output()->from(_stob);
438
439     set_minmax_to_non_const(g(), -1, 1);
440   }
441
442 private:
443   luci::CircleSpaceToBatchND *_stob = nullptr;
444   luci::CircleConst *_block_shape = nullptr;
445   luci::CircleConst *_paddings = nullptr;
446 };
447
448 class SpaceToDepthTestGraph final : public SimpleTestGraph
449 {
450 public:
451   void init(void) override
452   {
453     TestIOGraph::init({1, 2, 2, 1}, {1, 1, 1, 4});
454     _stod = g()->nodes()->create<luci::CircleSpaceToDepth>();
455     {
456       _stod->input(input());
457       _stod->block_size(2);
458       _stod->name("test");
459     }
460     output()->from(_stod);
461
462     set_minmax_to_non_const(g(), -1, 1);
463   }
464
465 private:
466   luci::CircleSpaceToDepth *_stod = nullptr;
467 };
468
469 template <Type indexT> class SliceTestGraph final : public SimpleTestGraph
470 {
471 public:
472   void init(void) override
473   {
474     TestIOGraph::init({32}, {32});
475     _begin = g()->nodes()->template create<luci::CircleConst>();
476     {
477       _begin->dtype(indexT);
478     }
479     _size = g()->nodes()->template create<luci::CircleConst>();
480     {
481       _size->dtype(indexT);
482     }
483     _slice = g()->nodes()->template create<luci::CircleSlice>();
484     {
485       _slice->input(input());
486       _slice->begin(_begin);
487       _slice->size(_size);
488       _slice->name("test");
489     }
490     output()->from(_slice);
491
492     set_minmax_to_non_const(g(), -1, 1);
493   }
494
495 private:
496   luci::CircleSlice *_slice = nullptr;
497   luci::CircleConst *_begin = nullptr;
498   luci::CircleConst *_size = nullptr;
499 };
500
501 class SplitTestGraph final : public luci::test::TestIOGraph
502 {
503 public:
504   void init(void)
505   {
506     TestIOGraph::init({1, 32}, {32});
507     _split_dim = create_dummy_const<Type::S32>(g(), {1});
508     _split = g()->nodes()->create<luci::CircleSplit>();
509     {
510       _split->input(input());
511       _split->split_dim(_split_dim);
512     }
513     _split_o1 = g()->nodes()->create<luci::CircleSplitOut>();
514     {
515       _split_o1->input(_split);
516       _split_o1->index(0);
517     }
518
519     output()->from(_split_o1);
520
521     set_minmax_to_non_const(g(), -1, 1);
522   }
523
524 private:
525   luci::CircleSplit *_split = nullptr;
526   luci::CircleSplitOut *_split_o1 = nullptr;
527   luci::CircleConst *_split_dim = nullptr;
528 };
529
530 class SplitVTestGraph final : public luci::test::TestIOGraph
531 {
532 public:
533   void init(void)
534   {
535     TestIOGraph::init({1, 32}, {32});
536     _size_splits = create_dummy_const<Type::S32>(g(), {1});
537     _split_dim = create_dummy_const<Type::S32>(g(), {1});
538     _splitv = g()->nodes()->create<luci::CircleSplitV>();
539     {
540       _splitv->input(input());
541       _splitv->size_splits(_size_splits);
542       _splitv->split_dim(_split_dim);
543     }
544     _splitv_o1 = g()->nodes()->create<luci::CircleSplitVOut>();
545     {
546       _splitv_o1->input(_splitv);
547       _splitv_o1->index(0);
548     }
549
550     output()->from(_splitv_o1);
551
552     set_minmax_to_non_const(g(), -1, 1);
553   }
554
555 private:
556   luci::CircleSplitV *_splitv = nullptr;
557   luci::CircleSplitVOut *_splitv_o1 = nullptr;
558   luci::CircleConst *_size_splits = nullptr;
559   luci::CircleConst *_split_dim = nullptr;
560 };
561
562 class StridedSliceTestGraph final : public SimpleTestGraph
563 {
564 public:
565   void init(void) override
566   {
567     TestIOGraph::init({32}, {32});
568     _begin = g()->nodes()->create<luci::CircleConst>();
569     {
570       _begin->dtype(Type::S32);
571     }
572     _end = g()->nodes()->create<luci::CircleConst>();
573     {
574       _end->dtype(Type::S32);
575     }
576     _strides = g()->nodes()->create<luci::CircleConst>();
577     {
578       _strides->dtype(Type::S32);
579     }
580     _slice = g()->nodes()->create<luci::CircleStridedSlice>();
581     {
582       _slice->input(input());
583       _slice->begin(_begin);
584       _slice->end(_end);
585       _slice->strides(_strides);
586       _slice->name("test");
587     }
588     output()->from(_slice);
589
590     set_minmax_to_non_const(g(), -1, 1);
591   }
592
593 private:
594   luci::CircleStridedSlice *_slice = nullptr;
595   luci::CircleConst *_begin = nullptr;
596   luci::CircleConst *_end = nullptr;
597   luci::CircleConst *_strides = nullptr;
598 };
599
600 class SumTestGraph final : public SimpleTestGraph
601 {
602 public:
603   void init(void) override
604   {
605     TestIOGraph::init({4, 3, 2}, {2});
606
607     _axis = create_const<Type::S32, int32_t>(g(), {2}, {1, 0});
608     _sum = g()->nodes()->create<luci::CircleSum>();
609     {
610       _sum->input(input());
611       _sum->reduction_indices(_axis);
612       _sum->name("test");
613       _sum->keep_dims(false);
614     }
615     output()->from(_sum);
616
617     set_minmax_to_non_const(g(), -1, 1);
618   }
619
620 private:
621   luci::CircleSum *_sum = nullptr;
622   luci::CircleConst *_axis = nullptr;
623 };
624
625 class ReshapeTestGraph final : public SimpleTestGraph
626 {
627 public:
628   void init(void) override
629   {
630     TestIOGraph::init({32}, {32});
631     _shape = g()->nodes()->create<luci::CircleConst>();
632     {
633       _shape->dtype(Type::S32);
634     }
635     _reshape = g()->nodes()->create<luci::CircleReshape>();
636     {
637       _reshape->tensor(input());
638       _reshape->shape(_shape);
639       _reshape->name("test");
640     }
641     output()->from(_reshape);
642
643     set_minmax_to_non_const(g(), -1, 1);
644   }
645
646 private:
647   luci::CircleReshape *_reshape = nullptr;
648   luci::CircleConst *_shape = nullptr;
649 };
650
651 class TanhTestGraph final : public SimpleTestGraph
652 {
653 public:
654   void init(void) override
655   {
656     TestIOGraph::init({32}, {32});
657     _tanh = g()->nodes()->create<luci::CircleTanh>();
658     {
659       _tanh->x(input());
660       _tanh->name("test");
661     }
662     output()->from(_tanh);
663
664     set_minmax_to_non_const(g(), -1, 1);
665   }
666
667 private:
668   luci::CircleTanh *_tanh = nullptr;
669 };
670
671 class FloorTestGraph final : public SimpleTestGraph
672 {
673 public:
674   void init(void) override
675   {
676     TestIOGraph::init({32}, {32});
677     _floor = g()->nodes()->create<luci::CircleFloor>();
678     {
679       _floor->x(input());
680       _floor->name("test");
681     }
682     output()->from(_floor);
683
684     set_minmax_to_non_const(g(), -1, 1);
685   }
686
687 private:
688   luci::CircleFloor *_floor = nullptr;
689 };
690
691 template <Type indexT> class ArgMaxTestGraph final : public SimpleTestGraph
692 {
693 public:
694   void init(void) override
695   {
696     TestIOGraph::init({32}, {1});
697     // output dtype is float by default, but ArgMax should have indexType (s32/s64)
698     output()->dtype(indexT);
699     _dimension = g()->nodes()->template create<luci::CircleConst>();
700     {
701       _dimension->dtype(indexT);
702     }
703     _argmax = g()->nodes()->template create<luci::CircleArgMax>();
704     {
705       _argmax->input(input());
706       _argmax->dimension(_dimension);
707       _argmax->output_type(indexT);
708       _argmax->dtype(indexT);
709     }
710     output()->from(_argmax);
711
712     set_minmax_to_non_const(g(), -1, 1);
713
714     // Sync output dtype with graph's output dtype
715     g()->outputs()->at(0)->dtype(output()->dtype());
716   }
717
718 public:
719   // NOTE: Do not override `luci::CircleNode* input(void)` incidentally
720   loco::Node *input_argmax(void) { return _argmax->input(); }
721   loco::Node *dimension(void) { return _argmax->dimension(); }
722
723 private:
724   luci::CircleArgMax *_argmax = nullptr;
725   luci::CircleConst *_dimension = nullptr;
726 };
727
728 class BatchToSpaceNDTestGraph final : public SimpleTestGraph
729 {
730 public:
731   void init(void) override
732   {
733     TestIOGraph::init({32}, {32});
734     _block_shape = g()->nodes()->create<luci::CircleConst>();
735     {
736       _block_shape->dtype(Type::S32);
737     }
738     _crops = g()->nodes()->create<luci::CircleConst>();
739     {
740       _crops->dtype(Type::S32);
741     }
742     _btos = g()->nodes()->create<luci::CircleBatchToSpaceND>();
743     {
744       _btos->input(input());
745       _btos->block_shape(_block_shape);
746       _btos->crops(_crops);
747       _btos->name("test");
748     }
749     output()->from(_btos);
750
751     set_minmax_to_non_const(g(), -1, 1);
752   }
753
754 private:
755   luci::CircleBatchToSpaceND *_btos = nullptr;
756   luci::CircleConst *_block_shape = nullptr;
757   luci::CircleConst *_crops = nullptr;
758 };
759
760 class DepthToSpaceTestGraph final : public SimpleTestGraph
761 {
762 public:
763   void init(void) override
764   {
765     TestIOGraph::init({1, 1, 1, 4}, {1, 2, 2, 1});
766     _dtos = g()->nodes()->create<luci::CircleDepthToSpace>();
767     {
768       _dtos->input(input());
769       _dtos->block_size(2);
770       _dtos->name("test");
771     }
772     output()->from(_dtos);
773
774     set_minmax_to_non_const(g(), -1, 1);
775   }
776
777 private:
778   luci::CircleDepthToSpace *_dtos = nullptr;
779 };
780
781 class PackTestGraph final : public SimpleTestGraph
782 {
783 public:
784   void init(void) override
785   {
786     TestIOGraph::init({16}, {32});
787     _param = create_dummy_const<Type::FLOAT32>(g(), {16});
788     _pack = g()->nodes()->create<luci::CirclePack>(2);
789     {
790       _pack->values(0, input());
791       _pack->values(1, _param);
792       _pack->axis(0);
793       _pack->name("test");
794     }
795     output()->from(_pack);
796
797     set_minmax_to_non_const(g(), -1, 1);
798
799     // Set min/max of the input
800     // pack's qparam will be propagted, overwritten to the input
801     auto input = loco::must_cast<luci::CircleNode *>(pack()->values(0));
802     auto qp = input->quantparam();
803     qp->min[0] = -0.5;
804     qp->max[0] = 0.5;
805   }
806
807 public:
808   luci::CirclePack *pack(void) { return _pack; }
809
810 private:
811   luci::CirclePack *_pack = nullptr;
812   luci::CircleConst *_param = nullptr;
813 };
814
815 class PadTestGraph final : public SimpleTestGraph
816 {
817 public:
818   void init(void) override
819   {
820     TestIOGraph::init({32}, {32});
821     _paddings = g()->nodes()->create<luci::CircleConst>();
822     {
823       _paddings->dtype(Type::S32);
824     }
825     _pad = g()->nodes()->create<luci::CirclePad>();
826     {
827       _pad->input(input());
828       _pad->paddings(_paddings);
829       _pad->name("test");
830     }
831     output()->from(_pad);
832
833     set_minmax_to_non_const(g(), -1, 1);
834   }
835
836 private:
837   luci::CirclePad *_pad = nullptr;
838   luci::CircleConst *_paddings = nullptr;
839 };
840
841 class PadV2TestGraph final : public SimpleTestGraph
842 {
843 public:
844   void init(void) override
845   {
846     TestIOGraph::init({32}, {32});
847     _paddings = g()->nodes()->create<luci::CircleConst>();
848     {
849       _paddings->dtype(Type::S32);
850     }
851     _constant_values = create_dummy_const<Type::FLOAT32>(g(), {1});
852     _pad = g()->nodes()->create<luci::CirclePadV2>();
853     {
854       _pad->input(input());
855       _pad->paddings(_paddings);
856       _pad->constant_values(_constant_values);
857       _pad->name("test");
858     }
859     output()->from(_pad);
860
861     set_minmax_to_non_const(g(), -1, 1);
862   }
863
864 private:
865   luci::CirclePadV2 *_pad = nullptr;
866   luci::CircleConst *_paddings = nullptr;
867   luci::CircleConst *_constant_values = nullptr;
868 };
869
870 class MirrorPadTestGraph final : public SimpleTestGraph
871 {
872 public:
873   void init(void) override
874   {
875     TestIOGraph::init({32}, {32});
876     _paddings = g()->nodes()->create<luci::CircleConst>();
877     {
878       _paddings->dtype(Type::S32);
879     }
880     _constant_values = create_dummy_const<Type::FLOAT32>(g(), {1});
881     _mirror_pad = g()->nodes()->create<luci::CircleMirrorPad>();
882     {
883       _mirror_pad->input(input());
884       _mirror_pad->paddings(_paddings);
885       _mirror_pad->mode(luci::MirrorPadMode::REFLECT);
886       _mirror_pad->name("test");
887     }
888     output()->from(_mirror_pad);
889
890     set_minmax_to_non_const(g(), -1, 1);
891   }
892
893 private:
894   luci::CircleMirrorPad *_mirror_pad = nullptr;
895   luci::CircleConst *_paddings = nullptr;
896   luci::CircleConst *_constant_values = nullptr;
897 };
898
899 class TransposeTestGraph final : public SimpleTestGraph
900 {
901 public:
902   void init(void) override
903   {
904     TestIOGraph::init({32}, {32});
905     _perm = g()->nodes()->create<luci::CircleConst>();
906     {
907       _perm->dtype(Type::S32);
908     }
909     _transpose = g()->nodes()->create<luci::CircleTranspose>();
910     {
911       _transpose->a(input());
912       _transpose->perm(_perm);
913       _transpose->name("test");
914     }
915     output()->from(_transpose);
916
917     set_minmax_to_non_const(g(), -1, 1);
918   }
919
920 private:
921   luci::CircleTranspose *_transpose = nullptr;
922   luci::CircleConst *_perm = nullptr;
923 };
924
925 class ConcatenationTestGraph final : public SimpleTestGraph
926 {
927 public:
928   void init(void) override
929   {
930     TestIOGraph::init({16}, {32});
931     _param = create_dummy_const<Type::FLOAT32>(g(), {16});
932     _concat = g()->nodes()->create<luci::CircleConcatenation>(2);
933     {
934       _concat->values(0, input());
935       _concat->values(1, _param);
936       _concat->axis(0);
937       _concat->fusedActivationFunction(luci::FusedActFunc::NONE);
938       _concat->name("test");
939     }
940     output()->from(_concat);
941
942     set_minmax_to_non_const(g(), -1, 1);
943   }
944
945 private:
946   luci::CircleConcatenation *_concat = nullptr;
947   luci::CircleConst *_param = nullptr;
948 };
949
950 template <Type indexT> class OneHotTestGraph final : public SimpleTestGraph
951 {
952 public:
953   void init(void) override
954   {
955     TestIOGraph::init({32}, {32, 10});
956     {
957       // input dtype is float by default, but OneHot's input should have indexType (s32/s64)
958       input()->dtype(indexT);
959     }
960
961     _depth = g()->nodes()->template create<luci::CircleConst>();
962     {
963       _depth->dtype(loco::DataType::S32);
964     }
965
966     _on_value = g()->nodes()->template create<luci::CircleConst>();
967     {
968       _on_value->dtype(loco::DataType::FLOAT32);
969     }
970
971     _off_value = g()->nodes()->template create<luci::CircleConst>();
972     {
973       _off_value->dtype(loco::DataType::FLOAT32);
974     }
975
976     _one_hot = g()->nodes()->template create<luci::CircleOneHot>();
977     {
978       _one_hot->indices(input());
979       _one_hot->depth(_depth);
980       _one_hot->on_value(_on_value);
981       _one_hot->off_value(_off_value);
982       _one_hot->axis(-1);
983       _one_hot->dtype(loco::DataType::FLOAT32);
984       _one_hot->name("test");
985     }
986     output()->from(_one_hot);
987
988     set_minmax_to_non_const(g(), -1, 1);
989   }
990
991 private:
992   luci::CircleOneHot *_one_hot = nullptr;
993   luci::CircleConst *_depth = nullptr;
994   luci::CircleConst *_on_value = nullptr;
995   luci::CircleConst *_off_value = nullptr;
996 };
997
998 // Test graph for comparison Ops
999 // GREATER, GREATER_EQUAL, LESS, LESS_EQUAL, EQUAL, NOT_EQUAL
1000 template <class Op> class ComparisonOpTestGraph final : public SimpleTestGraph
1001 {
1002 public:
1003   void init(void) override
1004   {
1005     TestIOGraph::init({32}, {32});
1006     output()->dtype(loco::DataType::BOOL);
1007     _y = create_dummy_const<Type::FLOAT32>(g(), {32});
1008     _op = g()->nodes()->template create<Op>();
1009     {
1010       _op->x(input());
1011       _op->y(_y);
1012       _op->dtype(loco::DataType::BOOL);
1013     }
1014     output()->from(_op);
1015
1016     set_minmax_to_non_const(g(), -1, 1);
1017
1018     // Sync output dtype with graph's output dtype
1019     g()->outputs()->at(0)->dtype(output()->dtype());
1020   }
1021
1022   loco::Node *x(void) const { return _op->x(); }
1023   loco::Node *y(void) const { return _op->y(); }
1024
1025 private:
1026   Op *_op = nullptr;
1027   luci::CircleConst *_y = nullptr;
1028 };
1029
1030 // Test graph for binary logical Ops
1031 // LOGICAL_OR, LOGICAL_AND
1032 template <class Op> class BinaryLogicalOpTestGraph final : public SimpleTestGraph
1033 {
1034 public:
1035   void init(void) override
1036   {
1037     TestIOGraph::init({32}, {32});
1038     input()->dtype(loco::DataType::BOOL);
1039     output()->dtype(loco::DataType::BOOL);
1040     _y = create_dummy_const<Type::BOOL>(g(), {32});
1041     _op = g()->nodes()->template create<Op>();
1042     {
1043       _op->x(input());
1044       _op->y(_y);
1045       _op->dtype(loco::DataType::BOOL);
1046     }
1047     output()->from(_op);
1048
1049     set_minmax_to_non_const(g(), -1, 1);
1050
1051     // Sync output dtype with graph's output dtype
1052     g()->outputs()->at(0)->dtype(output()->dtype());
1053   }
1054
1055   loco::Node *x(void) const { return _op->x(); }
1056   loco::Node *y(void) const { return _op->y(); }
1057
1058 private:
1059   Op *_op = nullptr;
1060   luci::CircleConst *_y = nullptr;
1061 };
1062
1063 class DivTestGraph final : public SimpleTestGraph
1064 {
1065 public:
1066   void init(void) override
1067   {
1068     TestIOGraph::init({32}, {32});
1069
1070     _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1071     _div = g()->nodes()->create<luci::CircleDiv>();
1072     {
1073       _div->x(input());
1074       _div->y(_const);
1075       _div->name("test");
1076     }
1077     output()->from(_div);
1078
1079     set_minmax_to_non_const(g(), -1, 1);
1080   }
1081
1082   loco::Node *x() { return _div->x(); }
1083
1084   loco::Node *y() { return _div->y(); }
1085
1086 private:
1087   luci::CircleDiv *_div = nullptr;
1088   luci::CircleConst *_const = nullptr;
1089 };
1090
1091 class FloorDivTestGraph final : public SimpleTestGraph
1092 {
1093 public:
1094   void init(void) override
1095   {
1096     TestIOGraph::init({32}, {32});
1097
1098     _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1099     _floor_div = g()->nodes()->create<luci::CircleFloorDiv>();
1100     {
1101       _floor_div->x(input());
1102       _floor_div->y(_const);
1103       _floor_div->name("test");
1104     }
1105     output()->from(_floor_div);
1106
1107     set_minmax_to_non_const(g(), -1, 1);
1108   }
1109
1110   loco::Node *x() { return _floor_div->x(); }
1111
1112   loco::Node *y() { return _floor_div->y(); }
1113
1114 private:
1115   luci::CircleFloorDiv *_floor_div = nullptr;
1116   luci::CircleConst *_const = nullptr;
1117 };
1118
1119 class RsqrtTestGraph final : public SimpleTestGraph
1120 {
1121 public:
1122   void init(void) override
1123   {
1124     TestIOGraph::init({32}, {32});
1125     _rsqrt = g()->nodes()->create<luci::CircleRsqrt>();
1126     {
1127       _rsqrt->x(input());
1128       _rsqrt->name("test");
1129     }
1130     output()->from(_rsqrt);
1131
1132     set_minmax_to_non_const(g(), -1, 1);
1133   }
1134
1135 private:
1136   luci::CircleRsqrt *_rsqrt = nullptr;
1137 };
1138
1139 class SqrtTestGraph final : public SimpleTestGraph
1140 {
1141 public:
1142   void init(void) override
1143   {
1144     TestIOGraph::init({32}, {32});
1145     _sqrt = g()->nodes()->create<luci::CircleSqrt>();
1146     {
1147       _sqrt->x(input());
1148       _sqrt->name("test");
1149     }
1150     output()->from(_sqrt);
1151
1152     set_minmax_to_non_const(g(), -1, 1);
1153   }
1154
1155 private:
1156   luci::CircleSqrt *_sqrt = nullptr;
1157 };
1158
1159 class EluTestGraph final : public SimpleTestGraph
1160 {
1161 public:
1162   void init(void) override
1163   {
1164     TestIOGraph::init({32}, {32});
1165     _elu = g()->nodes()->create<luci::CircleElu>();
1166     {
1167       _elu->features(input());
1168       _elu->name("test");
1169     }
1170     output()->from(_elu);
1171
1172     set_minmax_to_non_const(g(), -1, 1);
1173   }
1174
1175 private:
1176   luci::CircleElu *_elu = nullptr;
1177 };
1178
1179 class PowTestGraph final : public SimpleTestGraph
1180 {
1181 public:
1182   void init(void) override
1183   {
1184     TestIOGraph::init({32}, {32});
1185
1186     _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1187     _pow = g()->nodes()->create<luci::CirclePow>();
1188     {
1189       _pow->x(input());
1190       _pow->y(_const);
1191       _pow->name("test");
1192     }
1193     output()->from(_pow);
1194
1195     set_minmax_to_non_const(g(), -1, 1);
1196   }
1197
1198   loco::Node *x() { return _pow->x(); }
1199
1200   loco::Node *y() { return _pow->y(); }
1201
1202 private:
1203   luci::CirclePow *_pow = nullptr;
1204   luci::CircleConst *_const = nullptr;
1205 };
1206
1207 class ReduceMaxTestGraph final : public SimpleTestGraph
1208 {
1209 public:
1210   void init(void) override
1211   {
1212     TestIOGraph::init({4, 3, 2}, {2});
1213
1214     _axis = create_const<Type::S32, int32_t>(g(), {4}, {1, 0, -3, -3});
1215     _reduce_max = g()->nodes()->create<luci::CircleReduceMax>();
1216     {
1217       _reduce_max->input(input());
1218       _reduce_max->reduction_indices(_axis);
1219       _reduce_max->name("test");
1220       _reduce_max->keep_dims(false);
1221     }
1222     output()->from(_reduce_max);
1223
1224     set_minmax_to_non_const(g(), -1, 1);
1225   }
1226
1227 private:
1228   luci::CircleReduceMax *_reduce_max = nullptr;
1229   luci::CircleConst *_axis = nullptr;
1230 };
1231
1232 class ResizeBilinearTestGraph final : public SimpleTestGraph
1233 {
1234 public:
1235   void init(void) override
1236   {
1237     TestIOGraph::init({1, 4, 4, 1}, {1, 8, 8, 1});
1238
1239     _size = create_const<Type::S32, int32_t>(g(), {2}, {8, 8});
1240     _resize_bilinear = g()->nodes()->create<luci::CircleResizeBilinear>();
1241     {
1242       _resize_bilinear->input(input());
1243       _resize_bilinear->size(_size);
1244       _resize_bilinear->name("test");
1245     }
1246     output()->from(_resize_bilinear);
1247
1248     set_minmax_to_non_const(g(), -1, 1);
1249   }
1250
1251 private:
1252   luci::CircleResizeBilinear *_resize_bilinear = nullptr;
1253   luci::CircleConst *_size = nullptr;
1254 };
1255
1256 class ResizeNearestNeighborTestGraph final : public luci::test::TestIOGraph
1257 {
1258 public:
1259   void init(void)
1260   {
1261     TestIOGraph::init({1, 4, 4, 1}, {1, 8, 8, 1});
1262
1263     _size = create_const<Type::S32, int32_t>(g(), {2}, {8, 8});
1264     _resize_nearest_neighbor = g()->nodes()->create<luci::CircleResizeNearestNeighbor>();
1265     {
1266       _resize_nearest_neighbor->input(input());
1267       _resize_nearest_neighbor->size(_size);
1268       _resize_nearest_neighbor->name("test");
1269     }
1270     output()->from(_resize_nearest_neighbor);
1271
1272     set_minmax_to_non_const(g(), -1, 1);
1273   }
1274
1275 private:
1276   luci::CircleResizeNearestNeighbor *_resize_nearest_neighbor = nullptr;
1277   luci::CircleConst *_size = nullptr;
1278 };
1279
1280 class UnpackTestGraph final : public luci::test::TestIOGraph
1281 {
1282 public:
1283   void init(void)
1284   {
1285     TestIOGraph::init({1, 32}, {32});
1286     _unpack = g()->nodes()->create<luci::CircleUnpack>();
1287     {
1288       _unpack->value(input());
1289       _unpack->axis(0);
1290       _unpack->num(1);
1291     }
1292     _unpack_o1 = g()->nodes()->create<luci::CircleUnpackOut>();
1293     {
1294       _unpack_o1->input(_unpack);
1295       _unpack_o1->index(0);
1296     }
1297
1298     output()->from(_unpack_o1);
1299
1300     set_minmax_to_non_const(g(), -1, 1);
1301   }
1302
1303 private:
1304   luci::CircleUnpack *_unpack = nullptr;
1305   luci::CircleUnpackOut *_unpack_o1 = nullptr;
1306   luci::CircleConst *_unpack_dim = nullptr;
1307 };
1308
1309 class MulTestGraph final : public SimpleTestGraph
1310 {
1311 public:
1312   void init(void) override
1313   {
1314     TestIOGraph::init({32}, {32});
1315
1316     _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1317     _mul = g()->nodes()->create<luci::CircleMul>();
1318     {
1319       _mul->x(input());
1320       _mul->y(_const);
1321       _mul->fusedActivationFunction(luci::FusedActFunc::NONE);
1322       _mul->name("test");
1323     }
1324     output()->from(_mul);
1325
1326     set_minmax_to_non_const(g(), -1, 1);
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 template <Type T> class IntMulTestGraph final : public TypedTestGraph
1338 {
1339 public:
1340   void init(void) override
1341   {
1342     TypedTestGraph::init(T, {32}, {32});
1343
1344     _const = create_dummy_const<T>(g(), {32});
1345     _mul = g()->nodes()->template create<luci::CircleMul>();
1346     {
1347       _mul->x(input());
1348       _mul->y(_const);
1349       _mul->fusedActivationFunction(luci::FusedActFunc::NONE);
1350       _mul->name("test");
1351       _mul->dtype(T);
1352     }
1353     output()->from(_mul);
1354   }
1355
1356   loco::Node *x() { return _mul->x(); }
1357   loco::Node *y() { return _mul->y(); }
1358
1359 private:
1360   luci::CircleMul *_mul = nullptr;
1361   luci::CircleConst *_const = nullptr;
1362 };
1363
1364 class AddTestGraph final : public SimpleTestGraph
1365 {
1366 public:
1367   void init(void) override
1368   {
1369     TestIOGraph::init({32}, {32});
1370
1371     _const = create_dummy_const<Type::FLOAT32>(g(), {32});
1372     _add = g()->nodes()->create<luci::CircleAdd>();
1373     {
1374       _add->x(input());
1375       _add->y(_const);
1376       _add->fusedActivationFunction(luci::FusedActFunc::NONE);
1377       _add->name("test");
1378     }
1379     output()->from(_add);
1380
1381     set_minmax_to_non_const(g(), -1, 1);
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 template <Type T> class IntAddTestGraph final : public TypedTestGraph
1393 {
1394 public:
1395   void init(void) override
1396   {
1397     TypedTestGraph::init(T, {32}, {32});
1398
1399     _const = create_dummy_const<T>(g(), {32});
1400     _add = g()->nodes()->template create<luci::CircleAdd>();
1401     {
1402       _add->x(input());
1403       _add->y(_const);
1404       _add->fusedActivationFunction(luci::FusedActFunc::NONE);
1405       _add->name("test");
1406       _add->dtype(T);
1407     }
1408     output()->from(_add);
1409   }
1410
1411   loco::Node *x() { return _add->x(); }
1412   loco::Node *y() { return _add->y(); }
1413
1414 private:
1415   luci::CircleAdd *_add = nullptr;
1416   luci::CircleConst *_const = nullptr;
1417 };
1418
1419 } // namespace
1420
1421 // Quantize and verify with given configurations
1422 #define TEST_WITH_GRAPH(graph, type, granularity)                   \
1423   do                                                                \
1424   {                                                                 \
1425     graph g;                                                        \
1426     g.init();                                                       \
1427     EXPECT_NO_THROW(quantize_and_verify(g.g(), type, granularity)); \
1428   } while (0)
1429
1430 // Quantize and verify with layer info
1431 #define TEST_WITH_LAYER_INFO(graph, type, granularity)                              \
1432   do                                                                                \
1433   {                                                                                 \
1434     graph g;                                                                        \
1435     g.init();                                                                       \
1436     EXPECT_NO_THROW(quantize_and_verify_with_layer_info(g.g(), type, granularity)); \
1437   } while (0)
1438
1439 // Quantize and verify with wrong type
1440 #define TEST_WITH_WRONG_TYPE(graph, type, granularity, wrong_dtype)                            \
1441   do                                                                                           \
1442   {                                                                                            \
1443     graph g;                                                                                   \
1444     g.init();                                                                                  \
1445     EXPECT_ANY_THROW(quantize_and_verify_with_wrong_type(&g, type, granularity, wrong_dtype)); \
1446   } while (0)
1447
1448 // Quantize and verify with wrong granularity
1449 #define TEST_WITH_WRONG_GRANULARITY(graph, type, granularity)                            \
1450   do                                                                                     \
1451   {                                                                                      \
1452     graph g;                                                                             \
1453     g.init();                                                                            \
1454     EXPECT_ANY_THROW(quantize_and_verify_with_wrong_granularity(&g, type, granularity)); \
1455   } while (0)
1456
1457 // Quantize and verify with wrong type
1458 // Users can specify the test target
1459 #define TEST_WITH_WRONG_TYPE_TARGET(graph, type, granularity_, wrong_dtype, target) \
1460   do                                                                                \
1461   {                                                                                 \
1462     graph g;                                                                        \
1463     g.init();                                                                       \
1464     auto node = loco::must_cast<luci::CircleNode *>(target);                        \
1465     run_phase(g.g(), type, granularity_);                                           \
1466     auto after_node = loco::must_cast<luci::CircleNode *>(target);                  \
1467     after_node->dtype(wrong_dtype);                                                 \
1468     auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();           \
1469     {                                                                               \
1470       ctx->output_model_dtype = type;                                               \
1471       ctx->granularity = granularity_;                                              \
1472       ctx->input_types = {type};                                                    \
1473       ctx->output_types = {type};                                                   \
1474     }                                                                               \
1475     luci::QuantizedModelVerifier verifier(std::move(ctx));                          \
1476     EXPECT_ANY_THROW(verifier.verify(g.g()));                                       \
1477   } while (0)
1478
1479 // Quantize and verify with wrong granularity
1480 // Users can specify the test target
1481 #define TEST_WITH_WRONG_GRANULARITY_TARGET(graph, type, granularity_, target) \
1482   do                                                                          \
1483   {                                                                           \
1484     graph g;                                                                  \
1485     g.init();                                                                 \
1486     auto node = loco::must_cast<luci::CircleNode *>(target);                  \
1487     run_phase(g.g(), type, granularity_);                                     \
1488     auto after_node = loco::must_cast<luci::CircleNode *>(target);            \
1489     insert_scale_zp(after_node, 1.0, 1);                                      \
1490     auto ctx = std::make_unique<luci::QuantizedModelVerifier::Context>();     \
1491     {                                                                         \
1492       ctx->output_model_dtype = type;                                         \
1493       ctx->granularity = granularity_;                                        \
1494       ctx->input_types = {type};                                              \
1495       ctx->output_types = {type};                                             \
1496     }                                                                         \
1497     luci::QuantizedModelVerifier verifier(std::move(ctx));                    \
1498     EXPECT_ANY_THROW(verifier.verify(g.g()));                                 \
1499   } while (0)
1500
1501 // Test a local helper function
1502 TEST(QuantizedModelVerifierTest, LocalCreateDummyConst)
1503 {
1504   loco::Graph g;
1505
1506   EXPECT_NO_THROW(create_dummy_const<Type::FLOAT32>(&g, {32, 32}));
1507 }
1508
1509 TEST(QuantizedModelVerifierTest, LocalCreateConst)
1510 {
1511   loco::Graph g;
1512   std::initializer_list<float> values = {0.1, 0, -5, 100};
1513   luci::CircleConst *node = create_const<Type::FLOAT32, float>(&g, {2, 2}, values);
1514
1515   uint32_t index = 0;
1516   for (auto val : values)
1517   {
1518     EXPECT_EQ(node->at<Type::FLOAT32>(index++), val);
1519   }
1520 }
1521
1522 TEST(QuantizedModelVerifierTest, InstanceNorm)
1523 {
1524   TEST_WITH_GRAPH(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1525   TEST_WITH_GRAPH(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1526   TEST_WITH_GRAPH(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1527
1528   TEST_WITH_LAYER_INFO(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1529   TEST_WITH_LAYER_INFO(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1530   TEST_WITH_LAYER_INFO(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1531   SUCCEED();
1532 }
1533
1534 TEST(QuantizedModelVerifierTest, InstanceNorm_wrong_type_NEG)
1535 {
1536   TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1537   TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1538   TEST_WITH_WRONG_TYPE(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1539   SUCCEED();
1540 }
1541
1542 TEST(QuantizedModelVerifierTest, InstanceNorm_wrong_granularity_NEG)
1543 {
1544   TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::U8, Granularity::LayerWise);
1545   TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::U8, Granularity::ChannelWise);
1546   TEST_WITH_WRONG_GRANULARITY(InstanceNormTestGraph, Type::S16, Granularity::ChannelWise);
1547   SUCCEED();
1548 }
1549
1550 TEST(QuantizedModelVerifierTest, LocalResponseNormalization)
1551 {
1552   TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise);
1553   TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise);
1554   TEST_WITH_GRAPH(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise);
1555
1556   TEST_WITH_LAYER_INFO(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise);
1557   TEST_WITH_LAYER_INFO(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise);
1558   TEST_WITH_LAYER_INFO(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise);
1559   SUCCEED();
1560 }
1561
1562 TEST(QuantizedModelVerifierTest, LocalResponseNormalization_wrong_type_NEG)
1563 {
1564   TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::U8, Granularity::LayerWise,
1565                        Type::S16);
1566   TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::U8, Granularity::ChannelWise,
1567                        Type::S16);
1568   TEST_WITH_WRONG_TYPE(LocalResponseNormalizationTestGraph, Type::S16, Granularity::ChannelWise,
1569                        Type::U8);
1570   SUCCEED();
1571 }
1572
1573 TEST(QuantizedModelVerifierTest, LocalResponseNormalization_wrong_granularity_NEG)
1574 {
1575   TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::U8,
1576                               Granularity::LayerWise);
1577   TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::U8,
1578                               Granularity::ChannelWise);
1579   TEST_WITH_WRONG_GRANULARITY(LocalResponseNormalizationTestGraph, Type::S16,
1580                               Granularity::ChannelWise);
1581   SUCCEED();
1582 }
1583
1584 TEST(QuantizedModelVerifierTest, Logistic)
1585 {
1586   TEST_WITH_GRAPH(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1587   TEST_WITH_GRAPH(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1588   TEST_WITH_GRAPH(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1589
1590   TEST_WITH_LAYER_INFO(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1591   TEST_WITH_LAYER_INFO(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1592   TEST_WITH_LAYER_INFO(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1593   SUCCEED();
1594 }
1595
1596 TEST(QuantizedModelVerifierTest, Logistic_wrong_type_NEG)
1597 {
1598   TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1599   TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1600   TEST_WITH_WRONG_TYPE(LogisticTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1601   SUCCEED();
1602 }
1603
1604 TEST(QuantizedModelVerifierTest, Logistic_wrong_granularity_NEG)
1605 {
1606   TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::U8, Granularity::LayerWise);
1607   TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::U8, Granularity::ChannelWise);
1608   TEST_WITH_WRONG_GRANULARITY(LogisticTestGraph, Type::S16, Granularity::ChannelWise);
1609   SUCCEED();
1610 }
1611
1612 TEST(QuantizedModelVerifierTest, Softmax)
1613 {
1614   TEST_WITH_GRAPH(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1615   TEST_WITH_GRAPH(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1616   TEST_WITH_GRAPH(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1617
1618   TEST_WITH_LAYER_INFO(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1619   TEST_WITH_LAYER_INFO(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1620   TEST_WITH_LAYER_INFO(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1621   SUCCEED();
1622 }
1623
1624 TEST(QuantizedModelVerifierTest, Softmax_wrong_type_NEG)
1625 {
1626   TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1627   TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1628   TEST_WITH_WRONG_TYPE(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1629   SUCCEED();
1630 }
1631
1632 TEST(QuantizedModelVerifierTest, Softmax_wrong_granularity_NEG)
1633 {
1634   TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::U8, Granularity::LayerWise);
1635   TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::U8, Granularity::ChannelWise);
1636   TEST_WITH_WRONG_GRANULARITY(SoftmaxTestGraph, Type::S16, Granularity::ChannelWise);
1637   SUCCEED();
1638 }
1639
1640 TEST(QuantizedModelVerifierTest, SpaceToBatchND)
1641 {
1642   TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1643   TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1644   TEST_WITH_GRAPH(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1645
1646   TEST_WITH_LAYER_INFO(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1647   TEST_WITH_LAYER_INFO(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1648   TEST_WITH_LAYER_INFO(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1649   SUCCEED();
1650 }
1651
1652 TEST(QuantizedModelVerifierTest, SpaceToBatchND_wrong_type_NEG)
1653 {
1654   TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1655   TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1656   TEST_WITH_WRONG_TYPE(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1657   SUCCEED();
1658 }
1659
1660 TEST(QuantizedModelVerifierTest, SpaceToBatchND_wrong_granularity_NEG)
1661 {
1662   TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::U8, Granularity::LayerWise);
1663   TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::U8, Granularity::ChannelWise);
1664   TEST_WITH_WRONG_GRANULARITY(SpaceToBatchNDTestGraph, Type::S16, Granularity::ChannelWise);
1665   SUCCEED();
1666 }
1667
1668 TEST(QuantizedModelVerifierTest, SpaceToDepth)
1669 {
1670   TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1671   TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1672   TEST_WITH_GRAPH(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1673
1674   TEST_WITH_LAYER_INFO(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1675   TEST_WITH_LAYER_INFO(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1676   TEST_WITH_LAYER_INFO(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1677   SUCCEED();
1678 }
1679
1680 TEST(QuantizedModelVerifierTest, SpaceToDepth_wrong_type_NEG)
1681 {
1682   TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1683   TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1684   TEST_WITH_WRONG_TYPE(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1685   SUCCEED();
1686 }
1687
1688 TEST(QuantizedModelVerifierTest, SpaceToDepth_wrong_granularity_NEG)
1689 {
1690   TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::U8, Granularity::LayerWise);
1691   TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::U8, Granularity::ChannelWise);
1692   TEST_WITH_WRONG_GRANULARITY(SpaceToDepthTestGraph, Type::S16, Granularity::ChannelWise);
1693   SUCCEED();
1694 }
1695
1696 TEST(QuantizedModelVerifierTest, Slice)
1697 {
1698   TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1699   TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1700   TEST_WITH_GRAPH(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1701
1702   TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1703   TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1704   TEST_WITH_GRAPH(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1705
1706   TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1707   TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1708   TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1709
1710   TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1711   TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1712   TEST_WITH_LAYER_INFO(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1713   SUCCEED();
1714 }
1715
1716 TEST(QuantizedModelVerifierTest, Slice_wrong_type_NEG)
1717 {
1718   TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
1719   TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
1720   TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
1721
1722   TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
1723   TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
1724   TEST_WITH_WRONG_TYPE(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
1725   SUCCEED();
1726 }
1727
1728 TEST(QuantizedModelVerifierTest, Slice_wrong_granularity_NEG)
1729 {
1730   TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1731   TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1732   TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1733
1734   TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1735   TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1736   TEST_WITH_WRONG_GRANULARITY(SliceTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1737   SUCCEED();
1738 }
1739
1740 TEST(QuantizedModelVerifierTest, Split)
1741 {
1742   TEST_WITH_GRAPH(SplitTestGraph, Type::U8, Granularity::LayerWise);
1743   TEST_WITH_GRAPH(SplitTestGraph, Type::U8, Granularity::ChannelWise);
1744   TEST_WITH_GRAPH(SplitTestGraph, Type::S16, Granularity::ChannelWise);
1745   SUCCEED();
1746 }
1747
1748 TEST(QuantizedModelVerifierTest, Split_wrong_type_NEG)
1749 {
1750   TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1751   TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1752   TEST_WITH_WRONG_TYPE(SplitTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1753   SUCCEED();
1754 }
1755
1756 TEST(QuantizedModelVerifierTest, Split_wrong_granularity_NEG)
1757 {
1758   TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::U8, Granularity::LayerWise);
1759   TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::U8, Granularity::ChannelWise);
1760   TEST_WITH_WRONG_GRANULARITY(SplitTestGraph, Type::S16, Granularity::ChannelWise);
1761   SUCCEED();
1762 }
1763
1764 TEST(QuantizedModelVerifierTest, SplitV)
1765 {
1766   TEST_WITH_GRAPH(SplitVTestGraph, Type::U8, Granularity::LayerWise);
1767   TEST_WITH_GRAPH(SplitVTestGraph, Type::U8, Granularity::ChannelWise);
1768   TEST_WITH_GRAPH(SplitVTestGraph, Type::S16, Granularity::ChannelWise);
1769   SUCCEED();
1770 }
1771
1772 TEST(QuantizedModelVerifierTest, SplitV_wrong_type_NEG)
1773 {
1774   TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1775   TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1776   TEST_WITH_WRONG_TYPE(SplitVTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1777   SUCCEED();
1778 }
1779
1780 TEST(QuantizedModelVerifierTest, SplitV_wrong_granularity_NEG)
1781 {
1782   TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::U8, Granularity::LayerWise);
1783   TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::U8, Granularity::ChannelWise);
1784   TEST_WITH_WRONG_GRANULARITY(SplitVTestGraph, Type::S16, Granularity::ChannelWise);
1785   SUCCEED();
1786 }
1787
1788 TEST(QuantizedModelVerifierTest, StridedSlice)
1789 {
1790   TEST_WITH_GRAPH(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1791   TEST_WITH_GRAPH(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1792   TEST_WITH_GRAPH(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1793
1794   TEST_WITH_LAYER_INFO(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1795   TEST_WITH_LAYER_INFO(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1796   TEST_WITH_LAYER_INFO(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1797   SUCCEED();
1798 }
1799
1800 TEST(QuantizedModelVerifierTest, StridedSlice_wrong_type_NEG)
1801 {
1802   TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1803   TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1804   TEST_WITH_WRONG_TYPE(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1805   SUCCEED();
1806 }
1807
1808 TEST(QuantizedModelVerifierTest, StridedSlice_wrong_granularity_NEG)
1809 {
1810   TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::U8, Granularity::LayerWise);
1811   TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::U8, Granularity::ChannelWise);
1812   TEST_WITH_WRONG_GRANULARITY(StridedSliceTestGraph, Type::S16, Granularity::ChannelWise);
1813   SUCCEED();
1814 }
1815
1816 TEST(QuantizedModelVerifierTest, Sum)
1817 {
1818   TEST_WITH_GRAPH(SumTestGraph, Type::U8, Granularity::LayerWise);
1819   TEST_WITH_GRAPH(SumTestGraph, Type::U8, Granularity::ChannelWise);
1820   TEST_WITH_GRAPH(SumTestGraph, Type::S16, Granularity::ChannelWise);
1821
1822   TEST_WITH_LAYER_INFO(SumTestGraph, Type::U8, Granularity::LayerWise);
1823   TEST_WITH_LAYER_INFO(SumTestGraph, Type::U8, Granularity::ChannelWise);
1824   TEST_WITH_LAYER_INFO(SumTestGraph, Type::S16, Granularity::ChannelWise);
1825   SUCCEED();
1826 }
1827
1828 TEST(QuantizedModelVerifierTest, Sum_wrong_type_NEG)
1829 {
1830   TEST_WITH_WRONG_TYPE(SumTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1831   TEST_WITH_WRONG_TYPE(SumTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1832   TEST_WITH_WRONG_TYPE(SumTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1833   SUCCEED();
1834 }
1835
1836 TEST(QuantizedModelVerifierTest, Sum_wrong_granularity_NEG)
1837 {
1838   TEST_WITH_WRONG_GRANULARITY(SumTestGraph, Type::U8, Granularity::LayerWise);
1839   TEST_WITH_WRONG_GRANULARITY(SumTestGraph, Type::U8, Granularity::ChannelWise);
1840   TEST_WITH_WRONG_GRANULARITY(SumTestGraph, Type::S16, Granularity::ChannelWise);
1841   SUCCEED();
1842 }
1843
1844 TEST(QuantizedModelVerifierTest, ArgMax)
1845 {
1846   TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
1847   TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
1848   TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
1849
1850   TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
1851   TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
1852   TEST_WITH_GRAPH(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
1853   SUCCEED();
1854 }
1855
1856 TEST(QuantizedModelVerifierTest, ArgMax_wrong_input_type_NEG)
1857 {
1858   TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
1859   TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
1860   TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
1861
1862   TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
1863   TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
1864   TEST_WITH_WRONG_TYPE(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
1865   SUCCEED();
1866 }
1867
1868 TEST(QuantizedModelVerifierTest, ArgMax_wrong_dimension_type_NEG)
1869 {
1870   TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise,
1871                               Type::S16, g.dimension());
1872   TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise,
1873                               Type::S16, g.dimension());
1874   TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise,
1875                               Type::U8, g.dimension());
1876
1877   TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise,
1878                               Type::S16, g.dimension());
1879   TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise,
1880                               Type::S16, g.dimension());
1881   TEST_WITH_WRONG_TYPE_TARGET(ArgMaxTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise,
1882                               Type::U8, g.dimension());
1883   SUCCEED();
1884 }
1885
1886 TEST(QuantizedModelVerifierTest, ArgMax_wrong_granularity_NEG)
1887 {
1888   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::LayerWise,
1889                                      g.input_argmax());
1890   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise,
1891                                      g.input_argmax());
1892   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S32>, Type::S16,
1893                                      Granularity::ChannelWise, g.input_argmax());
1894
1895   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::LayerWise,
1896                                      g.input_argmax());
1897   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise,
1898                                      g.input_argmax());
1899   TEST_WITH_WRONG_GRANULARITY_TARGET(ArgMaxTestGraph<Type::S64>, Type::S16,
1900                                      Granularity::ChannelWise, g.input_argmax());
1901   SUCCEED();
1902 }
1903
1904 TEST(QuantizedModelVerifierTest, BatchToSpaceND)
1905 {
1906   TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1907   TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1908   TEST_WITH_GRAPH(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1909
1910   TEST_WITH_LAYER_INFO(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1911   TEST_WITH_LAYER_INFO(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1912   TEST_WITH_LAYER_INFO(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1913   SUCCEED();
1914 }
1915
1916 TEST(QuantizedModelVerifierTest, BatchToSpaceND_wrong_type_NEG)
1917 {
1918   TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1919   TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1920   TEST_WITH_WRONG_TYPE(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1921   SUCCEED();
1922 }
1923
1924 TEST(QuantizedModelVerifierTest, BatchToSpaceND_wrong_granularity_NEG)
1925 {
1926   TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::U8, Granularity::LayerWise);
1927   TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::U8, Granularity::ChannelWise);
1928   TEST_WITH_WRONG_GRANULARITY(BatchToSpaceNDTestGraph, Type::S16, Granularity::ChannelWise);
1929   SUCCEED();
1930 }
1931
1932 TEST(QuantizedModelVerifierTest, DepthToSpace)
1933 {
1934   TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1935   TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1936   TEST_WITH_GRAPH(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1937
1938   TEST_WITH_LAYER_INFO(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1939   TEST_WITH_LAYER_INFO(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1940   TEST_WITH_LAYER_INFO(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1941   SUCCEED();
1942 }
1943
1944 TEST(QuantizedModelVerifierTest, DepthToSpace_wrong_type_NEG)
1945 {
1946   TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1947   TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1948   TEST_WITH_WRONG_TYPE(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1949   SUCCEED();
1950 }
1951
1952 TEST(QuantizedModelVerifierTest, DepthToSpace_wrong_granularity_NEG)
1953 {
1954   TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::U8, Granularity::LayerWise);
1955   TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::U8, Granularity::ChannelWise);
1956   TEST_WITH_WRONG_GRANULARITY(DepthToSpaceTestGraph, Type::S16, Granularity::ChannelWise);
1957   SUCCEED();
1958 }
1959
1960 TEST(QuantizedModelVerifierTest, Concatenation)
1961 {
1962   TEST_WITH_GRAPH(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1963   TEST_WITH_GRAPH(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1964   TEST_WITH_GRAPH(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1965
1966   TEST_WITH_LAYER_INFO(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1967   TEST_WITH_LAYER_INFO(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1968   TEST_WITH_LAYER_INFO(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1969   SUCCEED();
1970 }
1971
1972 TEST(QuantizedModelVerifierTest, Concatenation_wrong_type_NEG)
1973 {
1974   TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
1975   TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
1976   TEST_WITH_WRONG_TYPE(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
1977   SUCCEED();
1978 }
1979
1980 TEST(QuantizedModelVerifierTest, Concatenation_wrong_granularity_NEG)
1981 {
1982   TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::U8, Granularity::LayerWise);
1983   TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::U8, Granularity::ChannelWise);
1984   TEST_WITH_WRONG_GRANULARITY(ConcatenationTestGraph, Type::S16, Granularity::ChannelWise);
1985   SUCCEED();
1986 }
1987
1988 TEST(QuantizedModelVerifierTest, LogicalOr)
1989 {
1990   TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1991                   Granularity::LayerWise);
1992   TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
1993                   Granularity::ChannelWise);
1994   TEST_WITH_GRAPH(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::S16,
1995                   Granularity::ChannelWise);
1996   SUCCEED();
1997 }
1998
1999 TEST(QuantizedModelVerifierTest, LogicalOr_wrong_type_NEG)
2000 {
2001   TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
2002                        Granularity::LayerWise, Type::U8);
2003   TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::U8,
2004                        Granularity::ChannelWise, Type::U8);
2005   TEST_WITH_WRONG_TYPE(BinaryLogicalOpTestGraph<luci::CircleLogicalOr>, Type::S16,
2006                        Granularity::ChannelWise, Type::S16);
2007   SUCCEED();
2008 }
2009
2010 TEST(QuantizedModelVerifierTest, Reshape)
2011 {
2012   TEST_WITH_GRAPH(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
2013   TEST_WITH_GRAPH(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
2014   TEST_WITH_GRAPH(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
2015
2016   TEST_WITH_LAYER_INFO(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
2017   TEST_WITH_LAYER_INFO(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
2018   TEST_WITH_LAYER_INFO(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
2019   SUCCEED();
2020 }
2021
2022 TEST(QuantizedModelVerifierTest, Reshape_wrong_type_NEG)
2023 {
2024   TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2025   TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2026   TEST_WITH_WRONG_TYPE(ReshapeTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2027   SUCCEED();
2028 }
2029
2030 TEST(QuantizedModelVerifierTest, Reshape_wrong_granularity_NEG)
2031 {
2032   TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::U8, Granularity::LayerWise);
2033   TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::U8, Granularity::ChannelWise);
2034   TEST_WITH_WRONG_GRANULARITY(ReshapeTestGraph, Type::S16, Granularity::ChannelWise);
2035   SUCCEED();
2036 }
2037
2038 TEST(QuantizedModelVerifierTest, Tanh)
2039 {
2040   TEST_WITH_GRAPH(TanhTestGraph, Type::U8, Granularity::LayerWise);
2041   TEST_WITH_GRAPH(TanhTestGraph, Type::U8, Granularity::ChannelWise);
2042   TEST_WITH_GRAPH(TanhTestGraph, Type::S16, Granularity::ChannelWise);
2043
2044   TEST_WITH_LAYER_INFO(TanhTestGraph, Type::U8, Granularity::LayerWise);
2045   TEST_WITH_LAYER_INFO(TanhTestGraph, Type::U8, Granularity::ChannelWise);
2046   TEST_WITH_LAYER_INFO(TanhTestGraph, Type::S16, Granularity::ChannelWise);
2047   SUCCEED();
2048 }
2049
2050 TEST(QuantizedModelVerifierTest, Tanh_wrong_type_NEG)
2051 {
2052   TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2053   TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2054   TEST_WITH_WRONG_TYPE(TanhTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2055   SUCCEED();
2056 }
2057
2058 TEST(QuantizedModelVerifierTest, Tanh_wrong_granularity_NEG)
2059 {
2060   TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::U8, Granularity::LayerWise);
2061   TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::U8, Granularity::ChannelWise);
2062   TEST_WITH_WRONG_GRANULARITY(TanhTestGraph, Type::S16, Granularity::ChannelWise);
2063   SUCCEED();
2064 }
2065
2066 TEST(QuantizedModelVerifierTest, Pack)
2067 {
2068   TEST_WITH_GRAPH(PackTestGraph, Type::U8, Granularity::LayerWise);
2069   TEST_WITH_GRAPH(PackTestGraph, Type::U8, Granularity::ChannelWise);
2070   TEST_WITH_GRAPH(PackTestGraph, Type::S16, Granularity::ChannelWise);
2071
2072   TEST_WITH_LAYER_INFO(PackTestGraph, Type::U8, Granularity::LayerWise);
2073   TEST_WITH_LAYER_INFO(PackTestGraph, Type::U8, Granularity::ChannelWise);
2074   TEST_WITH_LAYER_INFO(PackTestGraph, Type::S16, Granularity::ChannelWise);
2075
2076   // Test if Pack's qparam is propagated to the input
2077   {
2078     PackTestGraph g;
2079     g.init();
2080     quantize_and_verify(g.g(), Type::U8, Granularity::ChannelWise);
2081     auto input = loco::must_cast<luci::CircleNode *>(g.pack()->values(0));
2082     auto qp = input->quantparam();
2083     EXPECT_FLOAT_EQ(2.0 / 255.0, qp->scale[0]);
2084     EXPECT_FLOAT_EQ(128, qp->zerop[0]);
2085   }
2086   SUCCEED();
2087 }
2088
2089 TEST(QuantizedModelVerifierTest, Pack_wrong_type_NEG)
2090 {
2091   TEST_WITH_WRONG_TYPE(PackTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2092   TEST_WITH_WRONG_TYPE(PackTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2093   TEST_WITH_WRONG_TYPE(PackTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2094   SUCCEED();
2095 }
2096
2097 TEST(QuantizedModelVerifierTest, Pack_wrong_granularity_NEG)
2098 {
2099   TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::U8, Granularity::LayerWise);
2100   TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::U8, Granularity::ChannelWise);
2101   TEST_WITH_WRONG_GRANULARITY(PackTestGraph, Type::S16, Granularity::ChannelWise);
2102   SUCCEED();
2103 }
2104
2105 TEST(QuantizedModelVerifierTest, Pad)
2106 {
2107   TEST_WITH_GRAPH(PadTestGraph, Type::U8, Granularity::LayerWise);
2108   TEST_WITH_GRAPH(PadTestGraph, Type::U8, Granularity::ChannelWise);
2109   TEST_WITH_GRAPH(PadTestGraph, Type::S16, Granularity::ChannelWise);
2110
2111   TEST_WITH_LAYER_INFO(PadTestGraph, Type::U8, Granularity::LayerWise);
2112   TEST_WITH_LAYER_INFO(PadTestGraph, Type::U8, Granularity::ChannelWise);
2113   TEST_WITH_LAYER_INFO(PadTestGraph, Type::S16, Granularity::ChannelWise);
2114   SUCCEED();
2115 }
2116
2117 TEST(QuantizedModelVerifierTest, Pad_wrong_type_NEG)
2118 {
2119   TEST_WITH_WRONG_TYPE(PadTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2120   TEST_WITH_WRONG_TYPE(PadTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2121   TEST_WITH_WRONG_TYPE(PadTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2122   SUCCEED();
2123 }
2124
2125 TEST(QuantizedModelVerifierTest, Pad_wrong_granularity_NEG)
2126 {
2127   TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::U8, Granularity::LayerWise);
2128   TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::U8, Granularity::ChannelWise);
2129   TEST_WITH_WRONG_GRANULARITY(PadTestGraph, Type::S16, Granularity::ChannelWise);
2130   SUCCEED();
2131 }
2132
2133 TEST(QuantizedModelVerifierTest, PadV2)
2134 {
2135   TEST_WITH_GRAPH(PadV2TestGraph, Type::U8, Granularity::LayerWise);
2136   TEST_WITH_GRAPH(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
2137   TEST_WITH_GRAPH(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
2138
2139   TEST_WITH_LAYER_INFO(PadV2TestGraph, Type::U8, Granularity::LayerWise);
2140   TEST_WITH_LAYER_INFO(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
2141   TEST_WITH_LAYER_INFO(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
2142   SUCCEED();
2143 }
2144
2145 TEST(QuantizedModelVerifierTest, PadV2_wrong_type_NEG)
2146 {
2147   TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2148   TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2149   TEST_WITH_WRONG_TYPE(PadV2TestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2150   SUCCEED();
2151 }
2152
2153 TEST(QuantizedModelVerifierTest, PadV2_wrong_granularity_NEG)
2154 {
2155   TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::U8, Granularity::LayerWise);
2156   TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::U8, Granularity::ChannelWise);
2157   TEST_WITH_WRONG_GRANULARITY(PadV2TestGraph, Type::S16, Granularity::ChannelWise);
2158   SUCCEED();
2159 }
2160
2161 TEST(QuantizedModelVerifierTest, MirrorPad)
2162 {
2163   TEST_WITH_GRAPH(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
2164   TEST_WITH_GRAPH(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
2165   TEST_WITH_GRAPH(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
2166
2167   TEST_WITH_LAYER_INFO(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
2168   TEST_WITH_LAYER_INFO(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
2169   TEST_WITH_LAYER_INFO(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
2170   SUCCEED();
2171 }
2172
2173 TEST(QuantizedModelVerifierTest, MirrorPad_wrong_type_NEG)
2174 {
2175   TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2176   TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2177   TEST_WITH_WRONG_TYPE(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2178   SUCCEED();
2179 }
2180
2181 TEST(QuantizedModelVerifierTest, MirrorPad_wrong_granularity_NEG)
2182 {
2183   TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::U8, Granularity::LayerWise);
2184   TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::U8, Granularity::ChannelWise);
2185   TEST_WITH_WRONG_GRANULARITY(MirrorPadTestGraph, Type::S16, Granularity::ChannelWise);
2186   SUCCEED();
2187 }
2188
2189 TEST(QuantizedModelVerifierTest, Transpose)
2190 {
2191   TEST_WITH_GRAPH(TransposeTestGraph, Type::U8, Granularity::LayerWise);
2192   TEST_WITH_GRAPH(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
2193   TEST_WITH_GRAPH(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
2194
2195   TEST_WITH_LAYER_INFO(TransposeTestGraph, Type::U8, Granularity::LayerWise);
2196   TEST_WITH_LAYER_INFO(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
2197   TEST_WITH_LAYER_INFO(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
2198   SUCCEED();
2199 }
2200
2201 TEST(QuantizedModelVerifierTest, Transpose_wrong_type_NEG)
2202 {
2203   TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2204   TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2205   TEST_WITH_WRONG_TYPE(TransposeTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2206   SUCCEED();
2207 }
2208
2209 TEST(QuantizedModelVerifierTest, Transpose_wrong_granularity_NEG)
2210 {
2211   TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::U8, Granularity::LayerWise);
2212   TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::U8, Granularity::ChannelWise);
2213   TEST_WITH_WRONG_GRANULARITY(TransposeTestGraph, Type::S16, Granularity::ChannelWise);
2214   SUCCEED();
2215 }
2216
2217 TEST(QuantizedModelVerifierTest, Floor)
2218 {
2219   TEST_WITH_GRAPH(FloorTestGraph, Type::U8, Granularity::LayerWise);
2220   TEST_WITH_GRAPH(FloorTestGraph, Type::U8, Granularity::ChannelWise);
2221   TEST_WITH_GRAPH(FloorTestGraph, Type::S16, Granularity::ChannelWise);
2222
2223   TEST_WITH_LAYER_INFO(FloorTestGraph, Type::U8, Granularity::LayerWise);
2224   TEST_WITH_LAYER_INFO(FloorTestGraph, Type::U8, Granularity::ChannelWise);
2225   TEST_WITH_LAYER_INFO(FloorTestGraph, Type::S16, Granularity::ChannelWise);
2226   SUCCEED();
2227 }
2228
2229 TEST(QuantizedModelVerifierTest, Floor_wrong_type_NEG)
2230 {
2231   TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2232   TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2233   TEST_WITH_WRONG_TYPE(FloorTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2234   SUCCEED();
2235 }
2236
2237 TEST(QuantizedModelVerifierTest, Floor_wrong_granularity_NEG)
2238 {
2239   TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::U8, Granularity::LayerWise);
2240   TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::U8, Granularity::ChannelWise);
2241   TEST_WITH_WRONG_GRANULARITY(FloorTestGraph, Type::S16, Granularity::ChannelWise);
2242   SUCCEED();
2243 }
2244
2245 TEST(QuantizedModelVerifierTest, GreaterEqual)
2246 {
2247   TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2248                   Granularity::LayerWise);
2249   TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2250                   Granularity::ChannelWise);
2251   TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2252                   Granularity::ChannelWise);
2253   SUCCEED();
2254 }
2255
2256 TEST(QuantizedModelVerifierTest, GreaterEqual_wrong_type_NEG)
2257 {
2258   TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2259                        Granularity::LayerWise, Type::U8);
2260   TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2261                        Granularity::ChannelWise, Type::U8);
2262   TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2263                        Granularity::ChannelWise, Type::S16);
2264   SUCCEED();
2265 }
2266
2267 TEST(QuantizedModelVerifierTest, GreaterEqual_wrong_granularity_NEG)
2268 {
2269   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2270                                      Granularity::LayerWise, g.x());
2271   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2272                                      Granularity::ChannelWise, g.x());
2273   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2274                                      Granularity::ChannelWise, g.x());
2275
2276   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2277                                      Granularity::LayerWise, g.y());
2278   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::U8,
2279                                      Granularity::ChannelWise, g.y());
2280   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreaterEqual>, Type::S16,
2281                                      Granularity::ChannelWise, g.y());
2282   SUCCEED();
2283 }
2284
2285 TEST(QuantizedModelVerifierTest, Greater)
2286 {
2287   TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::LayerWise);
2288   TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::ChannelWise);
2289   TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16, Granularity::ChannelWise);
2290   SUCCEED();
2291 }
2292
2293 TEST(QuantizedModelVerifierTest, Greater_wrong_type_NEG)
2294 {
2295   TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8, Granularity::LayerWise,
2296                        Type::U8);
2297   TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2298                        Granularity::ChannelWise, Type::U8);
2299   TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
2300                        Granularity::ChannelWise, Type::S16);
2301   SUCCEED();
2302 }
2303
2304 TEST(QuantizedModelVerifierTest, Greater_wrong_granularity_NEG)
2305 {
2306   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2307                                      Granularity::LayerWise, g.x());
2308   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2309                                      Granularity::ChannelWise, g.x());
2310   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
2311                                      Granularity::ChannelWise, g.x());
2312
2313   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2314                                      Granularity::LayerWise, g.y());
2315   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::U8,
2316                                      Granularity::ChannelWise, g.y());
2317   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleGreater>, Type::S16,
2318                                      Granularity::ChannelWise, g.y());
2319   SUCCEED();
2320 }
2321
2322 TEST(QuantizedModelVerifierTest, NotEqual)
2323 {
2324   TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8, Granularity::LayerWise);
2325   TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8, Granularity::ChannelWise);
2326   TEST_WITH_GRAPH(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16, Granularity::ChannelWise);
2327   SUCCEED();
2328 }
2329
2330 TEST(QuantizedModelVerifierTest, NotEqual_wrong_type_NEG)
2331 {
2332   TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2333                        Granularity::LayerWise, Type::U8);
2334   TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2335                        Granularity::ChannelWise, Type::U8);
2336   TEST_WITH_WRONG_TYPE(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
2337                        Granularity::ChannelWise, Type::S16);
2338   SUCCEED();
2339 }
2340
2341 TEST(QuantizedModelVerifierTest, NotEqual_wrong_granularity_NEG)
2342 {
2343   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2344                                      Granularity::LayerWise, g.x());
2345   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2346                                      Granularity::ChannelWise, g.x());
2347   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
2348                                      Granularity::ChannelWise, g.x());
2349
2350   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2351                                      Granularity::LayerWise, g.y());
2352   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::U8,
2353                                      Granularity::ChannelWise, g.y());
2354   TEST_WITH_WRONG_GRANULARITY_TARGET(ComparisonOpTestGraph<luci::CircleNotEqual>, Type::S16,
2355                                      Granularity::ChannelWise, g.y());
2356   SUCCEED();
2357 }
2358
2359 TEST(QuantizedModelVerifierTest, OneHot)
2360 {
2361   TEST_WITH_GRAPH(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2362   TEST_WITH_GRAPH(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2363   TEST_WITH_GRAPH(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2364
2365   TEST_WITH_GRAPH(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2366   TEST_WITH_GRAPH(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2367   TEST_WITH_GRAPH(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2368
2369   TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2370   TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2371   TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2372
2373   TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2374   TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2375   TEST_WITH_LAYER_INFO(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2376   SUCCEED();
2377 }
2378
2379 TEST(QuantizedModelVerifierTest, OneHot_wrong_input_type_NEG)
2380 {
2381   TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise, Type::S16);
2382   TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise, Type::S16);
2383   TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise, Type::U8);
2384
2385   TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise, Type::S16);
2386   TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise, Type::S16);
2387   TEST_WITH_WRONG_TYPE(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise, Type::U8);
2388   SUCCEED();
2389 }
2390
2391 TEST(QuantizedModelVerifierTest, OneHot_wrong_granularity_NEG)
2392 {
2393   TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2394   TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2395   TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2396
2397   TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2398   TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2399   TEST_WITH_WRONG_GRANULARITY(OneHotTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2400   SUCCEED();
2401 }
2402
2403 TEST(QuantizedModelVerifierTest, Div)
2404 {
2405   TEST_WITH_GRAPH(DivTestGraph, Type::U8, Granularity::LayerWise);
2406   TEST_WITH_GRAPH(DivTestGraph, Type::U8, Granularity::ChannelWise);
2407   TEST_WITH_GRAPH(DivTestGraph, Type::S16, Granularity::ChannelWise);
2408
2409   TEST_WITH_LAYER_INFO(DivTestGraph, Type::U8, Granularity::LayerWise);
2410   TEST_WITH_LAYER_INFO(DivTestGraph, Type::U8, Granularity::ChannelWise);
2411   TEST_WITH_LAYER_INFO(DivTestGraph, Type::S16, Granularity::ChannelWise);
2412   SUCCEED();
2413 }
2414
2415 TEST(QuantizedModelVerifierTest, Div_wrong_type_NEG)
2416 {
2417   TEST_WITH_WRONG_TYPE(DivTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2418   TEST_WITH_WRONG_TYPE(DivTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2419   TEST_WITH_WRONG_TYPE(DivTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2420   SUCCEED();
2421 }
2422
2423 TEST(QuantizedModelVerifierTest, Div_wrong_granularity_NEG)
2424 {
2425   TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::LayerWise, g.x());
2426   TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2427   TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2428
2429   TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::LayerWise, g.y());
2430   TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2431   TEST_WITH_WRONG_GRANULARITY_TARGET(DivTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2432   SUCCEED();
2433 }
2434
2435 TEST(QuantizedModelVerifierTest, FloorDiv)
2436 {
2437   TEST_WITH_GRAPH(FloorDivTestGraph, Type::U8, Granularity::LayerWise);
2438   TEST_WITH_GRAPH(FloorDivTestGraph, Type::U8, Granularity::ChannelWise);
2439   TEST_WITH_GRAPH(FloorDivTestGraph, Type::S16, Granularity::ChannelWise);
2440
2441   TEST_WITH_LAYER_INFO(FloorDivTestGraph, Type::U8, Granularity::LayerWise);
2442   TEST_WITH_LAYER_INFO(FloorDivTestGraph, Type::U8, Granularity::ChannelWise);
2443   TEST_WITH_LAYER_INFO(FloorDivTestGraph, Type::S16, Granularity::ChannelWise);
2444   SUCCEED();
2445 }
2446
2447 TEST(QuantizedModelVerifierTest, FloorDiv_wrong_type_NEG)
2448 {
2449   TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2450   TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2451   TEST_WITH_WRONG_TYPE(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2452   SUCCEED();
2453 }
2454
2455 TEST(QuantizedModelVerifierTest, FloorDiv_wrong_granularity_NEG)
2456 {
2457   TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::LayerWise, g.x());
2458   TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2459   TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2460
2461   TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::LayerWise, g.y());
2462   TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2463   TEST_WITH_WRONG_GRANULARITY_TARGET(FloorDivTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2464   SUCCEED();
2465 }
2466
2467 TEST(QuantizedModelVerifierTest, Rsqrt)
2468 {
2469   TEST_WITH_GRAPH(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
2470   TEST_WITH_GRAPH(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
2471   TEST_WITH_GRAPH(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
2472
2473   TEST_WITH_LAYER_INFO(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
2474   TEST_WITH_LAYER_INFO(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
2475   TEST_WITH_LAYER_INFO(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
2476   SUCCEED();
2477 }
2478
2479 TEST(QuantizedModelVerifierTest, Rsqrt_wrong_type_NEG)
2480 {
2481   TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2482   TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2483   TEST_WITH_WRONG_TYPE(RsqrtTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2484   SUCCEED();
2485 }
2486
2487 TEST(QuantizedModelVerifierTest, Rsqrt_wrong_granularity_NEG)
2488 {
2489   TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::U8, Granularity::LayerWise);
2490   TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::U8, Granularity::ChannelWise);
2491   TEST_WITH_WRONG_GRANULARITY(RsqrtTestGraph, Type::S16, Granularity::ChannelWise);
2492   SUCCEED();
2493 }
2494
2495 TEST(QuantizedModelVerifierTest, Sqrt)
2496 {
2497   TEST_WITH_GRAPH(SqrtTestGraph, Type::U8, Granularity::LayerWise);
2498   TEST_WITH_GRAPH(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
2499   TEST_WITH_GRAPH(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
2500
2501   TEST_WITH_LAYER_INFO(SqrtTestGraph, Type::U8, Granularity::LayerWise);
2502   TEST_WITH_LAYER_INFO(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
2503   TEST_WITH_LAYER_INFO(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
2504   SUCCEED();
2505 }
2506
2507 TEST(QuantizedModelVerifierTest, Sqrt_wrong_type_NEG)
2508 {
2509   TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2510   TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2511   TEST_WITH_WRONG_TYPE(SqrtTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2512   SUCCEED();
2513 }
2514
2515 TEST(QuantizedModelVerifierTest, Sqrt_wrong_granularity_NEG)
2516 {
2517   TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::U8, Granularity::LayerWise);
2518   TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::U8, Granularity::ChannelWise);
2519   TEST_WITH_WRONG_GRANULARITY(SqrtTestGraph, Type::S16, Granularity::ChannelWise);
2520   SUCCEED();
2521 }
2522
2523 TEST(QuantizedModelVerifierTest, Elu)
2524 {
2525   TEST_WITH_GRAPH(EluTestGraph, Type::U8, Granularity::LayerWise);
2526   TEST_WITH_GRAPH(EluTestGraph, Type::U8, Granularity::ChannelWise);
2527   TEST_WITH_GRAPH(EluTestGraph, Type::S16, Granularity::ChannelWise);
2528
2529   TEST_WITH_LAYER_INFO(EluTestGraph, Type::U8, Granularity::LayerWise);
2530   TEST_WITH_LAYER_INFO(EluTestGraph, Type::U8, Granularity::ChannelWise);
2531   TEST_WITH_LAYER_INFO(EluTestGraph, Type::S16, Granularity::ChannelWise);
2532   SUCCEED();
2533 }
2534
2535 TEST(QuantizedModelVerifierTest, Elu_wrong_type_NEG)
2536 {
2537   TEST_WITH_WRONG_TYPE(EluTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2538   TEST_WITH_WRONG_TYPE(EluTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2539   TEST_WITH_WRONG_TYPE(EluTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2540   SUCCEED();
2541 }
2542
2543 TEST(QuantizedModelVerifierTest, Elu_wrong_granularity_NEG)
2544 {
2545   TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::U8, Granularity::LayerWise);
2546   TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::U8, Granularity::ChannelWise);
2547   TEST_WITH_WRONG_GRANULARITY(EluTestGraph, Type::S16, Granularity::ChannelWise);
2548   SUCCEED();
2549 }
2550
2551 TEST(QuantizedModelVerifierTest, Pow)
2552 {
2553   TEST_WITH_GRAPH(PowTestGraph, Type::U8, Granularity::LayerWise);
2554   TEST_WITH_GRAPH(PowTestGraph, Type::U8, Granularity::ChannelWise);
2555   TEST_WITH_GRAPH(PowTestGraph, Type::S16, Granularity::ChannelWise);
2556
2557   TEST_WITH_LAYER_INFO(PowTestGraph, Type::U8, Granularity::LayerWise);
2558   TEST_WITH_LAYER_INFO(PowTestGraph, Type::U8, Granularity::ChannelWise);
2559   TEST_WITH_LAYER_INFO(PowTestGraph, Type::S16, Granularity::ChannelWise);
2560   SUCCEED();
2561 }
2562
2563 TEST(QuantizedModelVerifierTest, Pow_wrong_type_NEG)
2564 {
2565   TEST_WITH_WRONG_TYPE(PowTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2566   TEST_WITH_WRONG_TYPE(PowTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2567   TEST_WITH_WRONG_TYPE(PowTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2568   SUCCEED();
2569 }
2570
2571 TEST(QuantizedModelVerifierTest, Pow_wrong_granularity_NEG)
2572 {
2573   TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::LayerWise, g.x());
2574   TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2575   TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2576
2577   TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::LayerWise, g.y());
2578   TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2579   TEST_WITH_WRONG_GRANULARITY_TARGET(PowTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2580   SUCCEED();
2581 }
2582
2583 TEST(QuantizedModelVerifierTest, ReduceMax)
2584 {
2585   TEST_WITH_GRAPH(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise);
2586   TEST_WITH_GRAPH(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise);
2587   TEST_WITH_GRAPH(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise);
2588
2589   TEST_WITH_LAYER_INFO(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise);
2590   TEST_WITH_LAYER_INFO(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise);
2591   TEST_WITH_LAYER_INFO(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise);
2592   SUCCEED();
2593 }
2594
2595 TEST(QuantizedModelVerifierTest, ReduceMax_wrong_type_NEG)
2596 {
2597   TEST_WITH_WRONG_TYPE(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2598   TEST_WITH_WRONG_TYPE(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2599   TEST_WITH_WRONG_TYPE(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2600   SUCCEED();
2601 }
2602
2603 TEST(QuantizedModelVerifierTest, ReduceMax_wrong_granularity_NEG)
2604 {
2605   TEST_WITH_WRONG_GRANULARITY(ReduceMaxTestGraph, Type::U8, Granularity::LayerWise);
2606   TEST_WITH_WRONG_GRANULARITY(ReduceMaxTestGraph, Type::U8, Granularity::ChannelWise);
2607   TEST_WITH_WRONG_GRANULARITY(ReduceMaxTestGraph, Type::S16, Granularity::ChannelWise);
2608   SUCCEED();
2609 }
2610
2611 TEST(QuantizedModelVerifierTest, ResizeBilinear)
2612 {
2613   TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2614   TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2615   TEST_WITH_GRAPH(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2616
2617   TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2618   TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2619   TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2620   SUCCEED();
2621 }
2622
2623 TEST(QuantizedModelVerifierTest, ResizeBilinear_wrong_type_NEG)
2624 {
2625   TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2626   TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2627   TEST_WITH_WRONG_TYPE(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2628   SUCCEED();
2629 }
2630
2631 TEST(QuantizedModelVerifierTest, ResizeBilinear_wrong_granularity_NEG)
2632 {
2633   TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2634   TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2635   TEST_WITH_WRONG_GRANULARITY(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2636   SUCCEED();
2637 }
2638
2639 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor)
2640 {
2641   TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise);
2642   TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise);
2643   TEST_WITH_GRAPH(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise);
2644
2645   TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::LayerWise);
2646   TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::U8, Granularity::ChannelWise);
2647   TEST_WITH_LAYER_INFO(ResizeBilinearTestGraph, Type::S16, Granularity::ChannelWise);
2648   SUCCEED();
2649 }
2650
2651 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor_wrong_type_NEG)
2652 {
2653   TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2654   TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise,
2655                        Type::S16);
2656   TEST_WITH_WRONG_TYPE(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise,
2657                        Type::U8);
2658   SUCCEED();
2659 }
2660
2661 TEST(QuantizedModelVerifierTest, ResizeNearestNeighbor_wrong_granularity_NEG)
2662 {
2663   TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::U8, Granularity::LayerWise);
2664   TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::U8, Granularity::ChannelWise);
2665   TEST_WITH_WRONG_GRANULARITY(ResizeNearestNeighborTestGraph, Type::S16, Granularity::ChannelWise);
2666   SUCCEED();
2667 }
2668
2669 TEST(QuantizedModelVerifierTest, Unpack)
2670 {
2671   TEST_WITH_GRAPH(UnpackTestGraph, Type::U8, Granularity::LayerWise);
2672   TEST_WITH_GRAPH(UnpackTestGraph, Type::U8, Granularity::ChannelWise);
2673   TEST_WITH_GRAPH(UnpackTestGraph, Type::S16, Granularity::ChannelWise);
2674   SUCCEED();
2675 }
2676
2677 TEST(QuantizedModelVerifierTest, Unpack_wrong_type_NEG)
2678 {
2679   TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2680   TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2681   TEST_WITH_WRONG_TYPE(UnpackTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2682   SUCCEED();
2683 }
2684
2685 TEST(QuantizedModelVerifierTest, Unpack_wrong_granularity_NEG)
2686 {
2687   TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::U8, Granularity::LayerWise);
2688   TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::U8, Granularity::ChannelWise);
2689   TEST_WITH_WRONG_GRANULARITY(UnpackTestGraph, Type::S16, Granularity::ChannelWise);
2690   SUCCEED();
2691 }
2692
2693 TEST(QuantizedModelVerifierTest, Add)
2694 {
2695   TEST_WITH_GRAPH(AddTestGraph, Type::U8, Granularity::LayerWise);
2696   TEST_WITH_GRAPH(AddTestGraph, Type::U8, Granularity::ChannelWise);
2697   TEST_WITH_GRAPH(AddTestGraph, Type::S16, Granularity::ChannelWise);
2698
2699   TEST_WITH_LAYER_INFO(AddTestGraph, Type::U8, Granularity::LayerWise);
2700   TEST_WITH_LAYER_INFO(AddTestGraph, Type::U8, Granularity::ChannelWise);
2701   TEST_WITH_LAYER_INFO(AddTestGraph, Type::S16, Granularity::ChannelWise);
2702   SUCCEED();
2703 }
2704
2705 TEST(QuantizedModelVerifierTest, Add_wrong_type_NEG)
2706 {
2707   TEST_WITH_WRONG_TYPE(AddTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2708   TEST_WITH_WRONG_TYPE(AddTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2709   TEST_WITH_WRONG_TYPE(AddTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2710   SUCCEED();
2711 }
2712
2713 TEST(QuantizedModelVerifierTest, Add_wrong_granularity_NEG)
2714 {
2715   TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::LayerWise, g.x());
2716   TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2717   TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2718
2719   TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::LayerWise, g.y());
2720   TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2721   TEST_WITH_WRONG_GRANULARITY_TARGET(AddTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2722   SUCCEED();
2723 }
2724
2725 TEST(QuantizedModelVerifierTest, Add_inttype)
2726 {
2727   // Tests for S32
2728   TEST_WITH_GRAPH(IntAddTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2729   TEST_WITH_GRAPH(IntAddTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2730   TEST_WITH_GRAPH(IntAddTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2731
2732   TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2733   TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2734   TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2735
2736   // Tests for S64
2737   TEST_WITH_GRAPH(IntAddTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2738   TEST_WITH_GRAPH(IntAddTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2739   TEST_WITH_GRAPH(IntAddTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2740
2741   TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2742   TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2743   TEST_WITH_LAYER_INFO(IntAddTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2744
2745   SUCCEED();
2746 }
2747
2748 TEST(QuantizedModelVerifierTest, Mul)
2749 {
2750   TEST_WITH_GRAPH(MulTestGraph, Type::U8, Granularity::LayerWise);
2751   TEST_WITH_GRAPH(MulTestGraph, Type::U8, Granularity::ChannelWise);
2752   TEST_WITH_GRAPH(MulTestGraph, Type::S16, Granularity::ChannelWise);
2753
2754   TEST_WITH_LAYER_INFO(MulTestGraph, Type::U8, Granularity::LayerWise);
2755   TEST_WITH_LAYER_INFO(MulTestGraph, Type::U8, Granularity::ChannelWise);
2756   TEST_WITH_LAYER_INFO(MulTestGraph, Type::S16, Granularity::ChannelWise);
2757   SUCCEED();
2758 }
2759
2760 TEST(QuantizedModelVerifierTest, Mul_wrong_type_NEG)
2761 {
2762   TEST_WITH_WRONG_TYPE(MulTestGraph, Type::U8, Granularity::LayerWise, Type::S16);
2763   TEST_WITH_WRONG_TYPE(MulTestGraph, Type::U8, Granularity::ChannelWise, Type::S16);
2764   TEST_WITH_WRONG_TYPE(MulTestGraph, Type::S16, Granularity::ChannelWise, Type::U8);
2765   SUCCEED();
2766 }
2767
2768 TEST(QuantizedModelVerifierTest, Mul_wrong_granularity_NEG)
2769 {
2770   TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::LayerWise, g.x());
2771   TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::ChannelWise, g.x());
2772   TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::S16, Granularity::ChannelWise, g.x());
2773
2774   TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::LayerWise, g.y());
2775   TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::U8, Granularity::ChannelWise, g.y());
2776   TEST_WITH_WRONG_GRANULARITY_TARGET(MulTestGraph, Type::S16, Granularity::ChannelWise, g.y());
2777   SUCCEED();
2778 }
2779
2780 TEST(QuantizedModelVerifierTest, Mul_inttype)
2781 {
2782   // Tests for S32
2783   TEST_WITH_GRAPH(IntMulTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2784   TEST_WITH_GRAPH(IntMulTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2785   TEST_WITH_GRAPH(IntMulTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2786
2787   TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S32>, Type::U8, Granularity::LayerWise);
2788   TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S32>, Type::U8, Granularity::ChannelWise);
2789   TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S32>, Type::S16, Granularity::ChannelWise);
2790
2791   // Tests for S64
2792   TEST_WITH_GRAPH(IntMulTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2793   TEST_WITH_GRAPH(IntMulTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2794   TEST_WITH_GRAPH(IntMulTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2795
2796   TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S64>, Type::U8, Granularity::LayerWise);
2797   TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S64>, Type::U8, Granularity::ChannelWise);
2798   TEST_WITH_LAYER_INFO(IntMulTestGraph<Type::S64>, Type::S16, Granularity::ChannelWise);
2799
2800   SUCCEED();
2801 }
2802
2803 // TODO Add following testcases
2804 //
2805 // CircleConv2D
2806 //
2807 // CircleDepthwiseConv2D
2808 //
2809 // CirclePRelu
2810 //
2811 // CircleTransposeConv
2812 //
2813 // CircleFullyConnected
2814 //
2815 // CircleAveragePool2D
2816 //
2817 // CircleMaxPool2D
2818 //
2819 // CircleMean
2820 //
2821 // CircleRelu
2822 //
2823 // CircleCast
2824 //
2825
2826 #undef TEST_WITH_GRAPH
2827 #undef TEST_WITH_WRONG_TYPE
2828 #undef TEST_WITH_WRONG_GRANULARITY