Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / compiler / souschef / include / souschef / TensorFiller.h
1 /*
2  * Copyright (c) 2020 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 __SOUSCHEF_TENSOR_FILLER_H__
18 #define __SOUSCHEF_TENSOR_FILLER_H__
19
20 #include <map>
21 #include <vector>
22
23 namespace souschef
24 {
25
26 class TensorFiller
27 {
28 public:
29   virtual ~TensorFiller() = default;
30
31   /**
32    * @brief This will record the tensor by index, if it needs filler option,
33    *        such as kernel, bias.
34    */
35   void set_tensor_filler(uint32_t tensor_index) { _tensor_filler[tensor_index] = true; }
36
37   /**
38    * @brief This will store int32 filler values such as reshape information for the tensor
39    */
40   void set_tensor_filler(uint32_t tensor_index, std::vector<int32_t> &expvalues)
41   {
42     _tensor_filler_vint32[tensor_index] = expvalues;
43   }
44
45   void set_tensor_filler(uint32_t tensor_index, std::vector<float> &expvalues)
46   {
47     _tensor_filler_vfloat[tensor_index] = expvalues;
48   }
49
50   /**
51    * @brief This will return true if the tensor by index, needs a filler option.
52    */
53   bool get_tensor_filler(uint32_t tensor_index)
54   {
55     auto it = _tensor_filler.find(tensor_index);
56     if (it != _tensor_filler.end())
57     {
58       return it->second;
59     }
60     return false;
61   }
62
63   /**
64    * @brief This will return true if the tensor by index, needs a int array filler option.
65    */
66   bool get_tensor_filler(uint32_t tensor_index, std::vector<int32_t> &expvalues)
67   {
68     auto it = _tensor_filler_vint32.find(tensor_index);
69     if (it != _tensor_filler_vint32.end())
70     {
71       expvalues = it->second;
72       return true;
73     }
74     return false;
75   }
76
77   bool get_tensor_filler(uint32_t tensor_index, std::vector<float> &expvalues)
78   {
79     auto it = _tensor_filler_vfloat.find(tensor_index);
80     if (it != _tensor_filler_vfloat.end())
81     {
82       expvalues = it->second;
83       return true;
84     }
85     return false;
86   }
87
88 private:
89   std::map<uint32_t, bool> _tensor_filler{};
90   std::map<uint32_t, std::vector<int32_t>> _tensor_filler_vint32{};
91   std::map<uint32_t, std::vector<float>> _tensor_filler_vfloat{};
92 };
93
94 } // namespace souschef
95
96 #endif // __SOUSCHEF_TENSOR_FILLER_H__