• 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 MINDSPORE_LITE_MICRO_CODER_GENERATOR_H_
18 #define MINDSPORE_LITE_MICRO_CODER_GENERATOR_H_
19 
20 #include <sys/stat.h>
21 #include <fstream>
22 #include <functional>
23 #include <map>
24 #include <memory>
25 #include <sstream>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 #include "include/errorcode.h"
30 #include "src/tensor.h"
31 #include "coder/log.h"
32 #include "coder/config.h"
33 #include "coder/context.h"
34 #include "coder/utils/type_cast.h"
35 
36 namespace mindspore::lite::micro {
37 
38 class Generator {
39  public:
40   explicit Generator(std::unique_ptr<CoderContext> ctx);
41   virtual ~Generator();
42 
43   int GenerateCode();
44 
45  protected:
46   virtual int CodeNetHFile() = 0;
47   virtual int CodeNetCFile() = 0;
48   virtual int CodeWeightFile();
49   virtual int CodeRegKernelHFile();
50 
51   void CodeNetRunFunc(std::ofstream &ofs);
52 
53   Configurator *config_{nullptr};
54   std::unique_ptr<CoderContext> ctx_{nullptr};
55 
56   bool is_get_quant_args_{false};
57   std::string net_inc_hfile_;
58   std::string net_src_cfile_;
59   std::string net_weight_hfile_;
60 
61   std::string net_src_file_path_;
62   std::string net_main_file_path_;
63 
64  private:
65   int CodeSourceCMakeFile();
66   int CodeStaticContent();
67   int CodeSessionImplement();
68 
69   std::string cmake_file_name_{"net.cmake"};
70 #ifdef _MSC_VER
71   unsigned int user_umask_ = 18;
72   unsigned int origin_umask_ = 0;
73 #else
74   // the user's generated file's permission
75   mode_t user_umask_ = 0022;
76   // the origin file's permission
77   mode_t origin_umask_ = 0000;
78 #endif
79 };
80 
81 }  // namespace mindspore::lite::micro
82 
83 #endif  // MINDSPORE_LITE_MICRO_CODER_GENERATOR_H_
84