Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / runtime / onert / core / include / ir / TypeInfo.h
1 /*
2  * Copyright (c) 2018 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 #ifndef __ONERT_IR_TYPEINFO_H__
18 #define __ONERT_IR_TYPEINFO_H__
19
20 #include <cstdint>
21 #include <vector>
22
23 #include "ir/DataType.h"
24
25 namespace onert
26 {
27 namespace ir
28 {
29
30 class TypeInfo
31 {
32 public:
33   TypeInfo() = delete;
34
35   explicit TypeInfo(DataType type, float scale = 0, int32_t offset = 0)
36       : _type(type), _scale(scale), _offset(offset), _sparse(false)
37   {
38   }
39
40 public:
41   DataType type() const { return _type; }
42   float scale() const { return _scale; }
43   int32_t offset() const { return _offset; }
44   bool sparse() const { return _sparse; }
45   const uint16_t *w1_segments() const { return _w1_segments.data(); }
46   const uint16_t *w1_indices() const { return _w1_indices.data(); }
47
48 public:
49   void type(const DataType type) { _type = type; }
50   void sparse2DMetadata(std::vector<uint16_t> &&w1_segments, std::vector<uint16_t> &&w1_indices)
51   {
52     _sparse = true;
53     _w1_segments = w1_segments;
54     _w1_indices = w1_indices;
55   }
56
57 private:
58   DataType _type;
59   // for quantization
60   float _scale;
61   int32_t _offset;
62   // for sparsity
63   bool _sparse;
64   std::vector<uint16_t> _w1_segments;
65   std::vector<uint16_t> _w1_indices;
66 };
67
68 bool operator==(const TypeInfo &lhs, const TypeInfo &rhs);
69 bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs);
70
71 } // namespace ir
72 } // namespace onert
73
74 #endif // __ONERT_IR_TYPEINFO_H__