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.

host_cpu_engine.h 3.0 kB

4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 GE_GE_LOCAL_ENGINE_ENGINE_HOST_CPU_ENGINE_H_
  17. #define GE_GE_LOCAL_ENGINE_ENGINE_HOST_CPU_ENGINE_H_
  18. #if defined(_MSC_VER)
  19. #ifdef FUNC_VISIBILITY
  20. #define GE_FUNC_VISIBILITY _declspec(dllexport)
  21. #else
  22. #define GE_FUNC_VISIBILITY
  23. #endif
  24. #else
  25. #ifdef FUNC_VISIBILITY
  26. #define GE_FUNC_VISIBILITY __attribute__((visibility("default")))
  27. #else
  28. #define GE_FUNC_VISIBILITY
  29. #endif
  30. #endif
  31. #include <mutex>
  32. #include "framework/common/ge_inner_error_codes.h"
  33. #include "graph/node.h"
  34. #include "external/graph/operator.h"
  35. #include "external/../register/register.h"
  36. namespace ge {
  37. class GE_FUNC_VISIBILITY HostCpuEngine {
  38. public:
  39. ~HostCpuEngine() = default;
  40. static HostCpuEngine &GetInstance() {
  41. static HostCpuEngine instance;
  42. return instance;
  43. }
  44. ge::Status Initialize();
  45. void Finalize();
  46. static bool CheckSupported(const string &op_type);
  47. ge::Status Run(NodePtr &node, const vector<ConstGeTensorPtr> &inputs, std::vector<GeTensorPtr> &outputs);
  48. void *GetConstantFoldingHandle() const { return constant_folding_handle_; }
  49. private:
  50. HostCpuEngine() = default;
  51. void CloseSo();
  52. ge::Status LoadLibs(std::vector<std::string> &lib_paths);
  53. ge::Status LoadLib(const std::string &lib_path);
  54. static ge::Status GetRealPath(std::string &path);
  55. static ge::Status GetLibPath(std::string &lib_path);
  56. static ge::Status ListSoFiles(const std::string &base_dir, std::vector<std::string> &names);
  57. static bool IsSoFile(const std::string &file_name);
  58. static ge::Status FindOpKernel(const NodePtr &node, std::unique_ptr<HostCpuOp> &op_kernel);
  59. static ge::Status PrepareInputs(const ConstOpDescPtr &op_desc, const vector<ConstGeTensorPtr> &inputs,
  60. std::map<std::string, const Tensor> &named_inputs);
  61. static ge::Status PrepareOutputs(const ConstOpDescPtr &op_desc, vector<GeTensorPtr> &outputs,
  62. std::map<std::string, Tensor> &named_outputs);
  63. static ge::Status RunInternal(const OpDescPtr &op_desc, HostCpuOp &op_kernel,
  64. std::map<std::string, const Tensor> &named_inputs,
  65. std::map<std::string, Tensor> &named_outputs);
  66. std::mutex mu_;
  67. std::vector<void *> lib_handles_;
  68. void *constant_folding_handle_ = nullptr;
  69. bool initialized_ = false;
  70. };
  71. } // namespace ge
  72. #endif // GE_GE_LOCAL_ENGINE_ENGINE_HOST_CPU_ENGINE_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示