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.h 2.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright 2019 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_H_
  17. #define MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_H_
  18. #include <iostream>
  19. #include <vector>
  20. #include <string>
  21. #include <unordered_map>
  22. #include <memory>
  23. #include "pybind11/pybind11.h"
  24. #include "pybind11/stl.h"
  25. #include "utils/any.h"
  26. #include "utils/profile.h"
  27. #include "ir/manager.h"
  28. #include "pipeline/jit/resource_base.h"
  29. #include "pipeline/jit/static_analysis/prim.h"
  30. #include "pipeline/jit/static_analysis/static_analysis.h"
  31. namespace mindspore {
  32. namespace pipeline {
  33. namespace py = pybind11;
  34. const char kBackend[] = "backend";
  35. const char kStepParallelGraph[] = "step_parallel";
  36. const char kOutput[] = "output";
  37. const char kPynativeGraphId[] = "graph_id";
  38. class InferenceResource;
  39. using BuiltInTypeMap = std::unordered_map<int, std::unordered_map<std::string, Any>>;
  40. BuiltInTypeMap &GetMethodMap();
  41. BuiltInTypeMap &GetAttrMap();
  42. class Resource : public ResourceBase {
  43. public:
  44. explicit Resource(const py::object &obj = py::none());
  45. ~Resource() override;
  46. abstract::AnalysisEnginePtr engine() { return engine_; }
  47. static bool IsTypeInBuiltInMap(const TypeId &type);
  48. static Any GetMethodPtr(const TypeId &type, const std::string &name);
  49. static Any GetAttrPtr(const TypeId &type, const std::string &name);
  50. const py::object &input() const { return input_; }
  51. FuncGraphPtr func_graph() const { return func_graph_; }
  52. void set_func_graph(const FuncGraphPtr &func_graph) { func_graph_ = func_graph; }
  53. const abstract::AbstractBasePtrList &args_spec() const { return args_spec_; }
  54. void set_args_spec(const abstract::AbstractBasePtrList &args_spec) { args_spec_ = args_spec; }
  55. // Reclaim resource and clear the cache.
  56. // ExecutorPy::Compile() can be called multiple times, so cache
  57. // should be cleared.
  58. void Clean();
  59. private:
  60. abstract::AnalysisEnginePtr engine_;
  61. FuncGraphPtr func_graph_;
  62. abstract::AbstractBasePtrList args_spec_;
  63. py::object input_;
  64. bool is_cleaned_;
  65. };
  66. using ResourcePtr = std::shared_ptr<pipeline::Resource>;
  67. } // namespace pipeline
  68. } // namespace mindspore
  69. #endif // MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_H_