• 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 
17 #include "include/api/model_group.h"
18 #include <mutex>
19 #include "include/api/types.h"
20 #include "include/api/context.h"
21 #include "include/api/dual_abi_helper.h"
22 #include "src/litert/cxx_api/model/model_group_impl.h"
23 #include "src/common/log_adapter.h"
24 
25 namespace mindspore {
ModelGroup(ModelGroupFlag flags)26 ModelGroup::ModelGroup(ModelGroupFlag flags) {
27   impl_ = std::make_shared<ModelGroupImpl>(flags);
28   if (impl_ == nullptr) {
29     MS_LOG(ERROR) << "New model group impl_ failed.";
30   }
31 }
32 
AddModel(const std::vector<std::string> & model_path_list)33 Status ModelGroup::AddModel(const std::vector<std::string> &model_path_list) {
34   if (impl_ == nullptr) {
35     MS_LOG(ERROR) << "Model group implement is null.";
36     return kLiteUninitializedObj;
37   }
38   return impl_->AddModel(model_path_list);
39 }
40 
AddModel(const std::vector<std::pair<const void *,size_t>> & model_buff_list)41 Status ModelGroup::AddModel(const std::vector<std::pair<const void *, size_t>> &model_buff_list) {
42   if (impl_ == nullptr) {
43     MS_LOG(ERROR) << "Model group implement is null.";
44     return kLiteUninitializedObj;
45   }
46   return impl_->AddModel(model_buff_list);
47 }
48 
AddModel(const std::vector<Model> &)49 Status ModelGroup::AddModel(const std::vector<Model> &) {
50   MS_LOG(ERROR) << "Unsupported Feature.";
51   return kLiteNotSupport;
52 }
53 
CalMaxSizeOfWorkspace(ModelType model_type,const std::shared_ptr<Context> & ms_context)54 Status ModelGroup::CalMaxSizeOfWorkspace(ModelType model_type, const std::shared_ptr<Context> &ms_context) {
55   if (impl_ == nullptr) {
56     MS_LOG(ERROR) << "Model group implement is null.";
57     return kLiteUninitializedObj;
58   }
59   return impl_->CalMaxSizeOfWorkspace(model_type, ms_context);
60 }
61 }  // namespace mindspore
62