• 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 #ifndef MINDSPORE_LITE_MICRO_CODER_SESSION_H_
17 #define MINDSPORE_LITE_MICRO_CODER_SESSION_H_
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 #include <memory>
23 #include "schema/inner/model_generated.h"
24 #include "coder/graph.h"
25 #include "coder/context.h"
26 #include "coder/config.h"
27 #include "coder/allocator/allocator.h"
28 #include "coder/opcoders/op_coder.h"
29 
30 namespace mindspore::lite::micro {
31 class CoderSession {
32  public:
33   CoderSession();
34 
35   ~CoderSession();
36 
37   int Init(const std::string &model_path);
38 
39   int Build();
40 
41   int Run();
42 
43   int GenerateCode();
44 
45  private:
46   OpParameter *GenParameterAndInfer(const Model::Node *node, const std::vector<lite::Tensor *> &inputs,
47                                     std::vector<lite::Tensor *> *outputs) const;
48   int InitOpcodersInputsAndOutputs();
49   int InitTensorsRef();
50   int CreateOpCoders();
51   int InitCodeGraph();
52   int CompileGraph();
53   void EndCode();
54 
55   std::unique_ptr<CoderGraph> coder_graph_{nullptr};
56   std::unique_ptr<CoderContext> context_{nullptr};
57   MemoryAllocator *allocator_{nullptr};
58   std::vector<std::unique_ptr<OperatorCoder>> op_coders_;
59   int schema_version_ = SCHEMA_VERSION::SCHEMA_CUR;
60 };
61 
62 std::shared_ptr<CoderSession> CreateCoderSession();
63 
64 }  // namespace mindspore::lite::micro
65 #endif  // MINDSPORE_LITE_MICRO_CODER_SESSION_H_
66