1 /** 2 * Copyright 2020 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 <unordered_map> 24 #include <memory> 25 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(); } 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 results()41 std::unordered_map<std::string, Any> &results() { return results_; } 42 SetResult(const std::string & key,const Any & value)43 void SetResult(const std::string &key, const Any &value) { results_[key] = value; } 44 GetResult(const std::string & key)45 Any GetResult(const std::string &key) { 46 if (results_.count(key) == 0) { 47 MS_LOG(EXCEPTION) << "this key is not in resource list:" << key; 48 } 49 return results_[key]; 50 } 51 HasResult(const std::string & key)52 bool HasResult(const std::string &key) const { return results_.count(key) != 0; } 53 54 protected: 55 FuncGraphManagerPtr manager_; 56 std::unordered_map<std::string, Any> results_; 57 }; 58 59 using ResourceBasePtr = std::shared_ptr<pipeline::ResourceBase>; 60 } // namespace pipeline 61 } // namespace mindspore 62 63 #endif // MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_BASE_H_ 64