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 2.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include <mutex>
  19. #include "framework/common/ge_inner_error_codes.h"
  20. #include "graph/node.h"
  21. #include "graph/operator.h"
  22. #include "register/register.h"
  23. namespace ge {
  24. class HostCpuEngine {
  25. public:
  26. ~HostCpuEngine() = default;
  27. static HostCpuEngine &GetInstance() {
  28. static HostCpuEngine instance;
  29. return instance;
  30. }
  31. ge::Status Initialize();
  32. void Finalize();
  33. static bool CheckSupported(const string &op_type);
  34. ge::Status Run(NodePtr &node, const vector<ConstGeTensorPtr> &inputs, std::vector<GeTensorPtr> &outputs);
  35. private:
  36. HostCpuEngine() = default;
  37. void CloseSo();
  38. ge::Status LoadLibs(std::vector<std::string> &lib_paths);
  39. ge::Status LoadLib(const std::string &lib_path);
  40. static ge::Status GetRealPath(std::string &path);
  41. static ge::Status GetLibPath(std::string &lib_path);
  42. static ge::Status ListSoFiles(const std::string &base_dir, std::vector<std::string> &names);
  43. static bool IsSoFile(const std::string &file_name);
  44. static ge::Status FindOpKernel(const NodePtr &node, std::unique_ptr<HostCpuOp> &op_kernel);
  45. static ge::Status PrepareInputs(const ConstOpDescPtr &op_desc, const vector<ConstGeTensorPtr> &inputs,
  46. std::map<std::string, const Tensor> &named_inputs);
  47. static ge::Status PrepareOutputs(const ConstOpDescPtr &op_desc, vector<GeTensorPtr> &outputs,
  48. std::map<std::string, Tensor> &named_outputs);
  49. static ge::Status RunInternal(const OpDescPtr &op_desc, HostCpuOp &op_kernel,
  50. std::map<std::string, const Tensor> &named_inputs,
  51. std::map<std::string, Tensor> &named_outputs);
  52. std::mutex mu_;
  53. std::vector<void *> lib_handles_;
  54. bool initialized_ = false;
  55. };
  56. } // namespace ge
  57. #endif // GE_GE_LOCAL_ENGINE_ENGINE_HOST_CPU_ENGINE_H_

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