• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
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 MICRO_LITE_MICRO_CODER_OPCODERS_NNACL_DEQUANT_DEQUANT_H_
18 #define MICRO_LITE_MICRO_CODER_OPCODERS_NNACL_DEQUANT_DEQUANT_H_
19 
20 #include <string>
21 #include <vector>
22 #include "src/tensor.h"
23 #include "coder/opcoders/serializers/nnacl_serializer/nnacl_fp32_serializer.h"
24 namespace mindspore::lite::micro::nnacl {
25 class Dequant {
26  public:
27   Dequant(const Dequant &) = delete;
28   Dequant &operator=(const Dequant &) = delete;
GetInstance()29   static Dequant *GetInstance() {
30     static Dequant dequant;
31     return &dequant;
32   }
33 
34   void set_de_quant_buffer_str(const std::string &de_quant_buffer_str);
35 
de_quant_max_workspace()36   const size_t de_quant_max_workspace() const { return de_quant_max_workspace_; }
37 
de_quant_buffer_str()38   const std::string de_quant_buffer_str() const { return de_quant_buffer_str_; }
39 
40   bool CheckDequantFlag(const Tensor *quant_tensor);
41 
42   std::string GetMicroDeQuantFunction(const Tensor *quant_tensor, const std::string &quant_tensor_addr);
43 
44  private:
45   void DeQuantFunctionPerTensor(const Tensor *quant_tensor, const std::vector<DeQuantArg> &de_quant_args,
46                                 const std::string &de_quant_arg_base_str, NNaclFp32Serializer *de_quant_code);
47 
48   void DeQuantFunction(const Tensor *quant_tensor, const std::vector<DeQuantArg> &de_quant_args,
49                        const std::string &de_quant_arg_base_str, NNaclFp32Serializer *de_quant_code);
50 
51   void DeQuantFunctionPerChannel(const Tensor *quant_tensor, const std::vector<DeQuantArg> &de_quant_args,
52                                  const std::string &de_quant_arg_base_str, NNaclFp32Serializer *de_quant_code);
53 
54   Dequant() = default;
55   ~Dequant() = default;
56   void DequantRecordWorkspcae(size_t curr_workspace);
57 
58   std::string de_quant_buffer_str_;
59   std::string quant_tensor_addr_;
60   size_t de_quant_max_workspace_{0};
61 };
62 }  // namespace mindspore::lite::micro::nnacl
63 #endif  // MICRO_LITE_MICRO_CODER_OPCODERS_NNACL_DEQUANT_DEQUANT_H_
64