You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

resource_base.h 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #ifndef MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_BASE_H_
  17. #define MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_BASE_H_
  18. #include <iostream>
  19. #include <vector>
  20. #include <string>
  21. #include <unordered_map>
  22. #include <memory>
  23. #include "utils/any.h"
  24. #include "ir/manager.h"
  25. namespace mindspore {
  26. namespace pipeline {
  27. class ResourceBase {
  28. public:
  29. ResourceBase() { manager_ = MakeManager(); }
  30. virtual ~ResourceBase() = default;
  31. FuncGraphManagerPtr manager() { return manager_; }
  32. // set a manager defined outside which will not manage the graphs.
  33. void set_manager(const FuncGraphManagerPtr &manager) { manager_ = manager; }
  34. std::unordered_map<std::string, Any> &results() { return results_; }
  35. void SetResult(const std::string &key, const Any &value) { results_[key] = value; }
  36. Any GetResult(const std::string &key) {
  37. if (results_.count(key) == 0) {
  38. MS_LOG(EXCEPTION) << "this key is not in resource list:" << key;
  39. }
  40. return results_[key];
  41. }
  42. bool HasResult(const std::string &key) const { return results_.count(key) != 0; }
  43. std::unordered_map<std::string, Any> results_;
  44. protected:
  45. FuncGraphManagerPtr manager_;
  46. };
  47. using ResourceBasePtr = std::shared_ptr<pipeline::ResourceBase>;
  48. } // namespace pipeline
  49. } // namespace mindspore
  50. #endif // MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_BASE_H_