• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-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 #ifndef MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_BASE_H_
18 #define MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_BASE_H_
19 
20 #include <iostream>
21 #include <vector>
22 #include <string>
23 #include <memory>
24 
25 #include "utils/hash_map.h"
26 #include "utils/any.h"
27 #include "ir/manager.h"
28 
29 namespace mindspore {
30 namespace pipeline {
31 class ResourceBase {
32  public:
ResourceBase()33   ResourceBase() { manager_ = MakeManager({}, true, true); }
34 
35   virtual ~ResourceBase() = default;
36 
manager()37   FuncGraphManagerPtr manager() { return manager_; }
38   // set a manager defined outside which will not manage the graphs.
set_manager(const FuncGraphManagerPtr & manager)39   void set_manager(const FuncGraphManagerPtr &manager) { manager_ = manager; }
40 
SetResult(const std::string & key,const Any & value)41   void SetResult(const std::string &key, const Any &value) { results_[key] = value; }
42 
GetResult(const std::string & key)43   Any GetResult(const std::string &key) const {
44     auto iter = results_.find(key);
45     if (iter == results_.end()) {
46       MS_LOG(INTERNAL_EXCEPTION) << "this key is not in resource list:" << key;
47     }
48     return iter->second;
49   }
50 
HasResult(const std::string & key)51   bool HasResult(const std::string &key) const { return results_.count(key) != 0; }
52 
53  protected:
54   FuncGraphManagerPtr manager_;
55   mindspore::HashMap<std::string, Any> results_;
56 };
57 
58 using ResourceBasePtr = std::shared_ptr<pipeline::ResourceBase>;
59 }  // namespace pipeline
60 }  // namespace mindspore
61 
62 #endif  // MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_BASE_H_
63