• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 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_INCLUDE_API_MODEL_GROUP_H
17 #define MINDSPORE_INCLUDE_API_MODEL_GROUP_H
18 
19 #include <string>
20 #include <vector>
21 #include <map>
22 #include <memory>
23 #include <utility>
24 #include "include/api/model.h"
25 #include "include/api/status.h"
26 #include "include/api/types.h"
27 #include "include/api/context.h"
28 
29 namespace mindspore {
30 class ModelGroupImpl;
31 
32 /// \brief The ModelGroup class is used to define a MindSpore model group, facilitating
33 /// multiple models to share workspace memory.
34 
35 enum class ModelGroupFlag : int {
36   kShareWeight = 0x0001,
37   kShareWorkspace = 0x0002,
38 };
39 
40 class MS_API ModelGroup {
41  public:
42   explicit ModelGroup(ModelGroupFlag flags = ModelGroupFlag::kShareWorkspace);
43   ~ModelGroup() = default;
44 
45   /// \brief Add models that require shared workspace memory.
46   ///
47   /// \param[in] model_path_list Define the list of model path.
48   ///
49   /// \return Status.
50   Status AddModel(const std::vector<std::string> &model_path_list);
51 
52   /// \brief Add models that require shared workspace memory.
53   ///
54   /// \param[in] model_buff_list Define the list of model buff.
55   ///
56   /// \return Status.
57   Status AddModel(const std::vector<std::pair<const void *, size_t>> &model_buff_list);
58 
59   /// \brief Add models that require shared weight memory.
60   ///
61   /// \param[in] model_list Define the list of model object.
62   ///
63   /// \return Status.
64   Status AddModel(const std::vector<Model> &model_list);
65 
66   /// \brief Calculate the max workspace of the added models.
67   ///
68   /// \param[in] model_type Define The type of model file. Options: ModelType::kMindIR_Lite, ModelType::kMindIR. Only
69   /// ModelType::kMindIR_Lite is valid for Lite.
70   /// \param[in] ms_context A context used to store options.
71   ///
72   /// \return Status.
73   Status CalMaxSizeOfWorkspace(ModelType model_type, const std::shared_ptr<Context> &ms_context);
74 
75  private:
76   std::shared_ptr<ModelGroupImpl> impl_;
77 };
78 }  // namespace mindspore
79 #endif  // MINDSPORE_INCLUDE_API_MODEL_GROUP_H
80