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.

tbe_task_builder.h 2.9 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Copyright 2019-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_SINGLE_OP_TASK_TBE_TASK_BUILDER_H_
  17. #define GE_SINGLE_OP_TASK_TBE_TASK_BUILDER_H_
  18. #include <map>
  19. #include <memory>
  20. #include <mutex>
  21. #include <set>
  22. #include <string>
  23. #include "graph/op_desc.h"
  24. #include "single_op/single_op.h"
  25. #include "single_op/single_op_model.h"
  26. namespace ge {
  27. class KernelHolder {
  28. public:
  29. KernelHolder(const char *stub_func, std::shared_ptr<ge::OpKernelBin> kernel_bin);
  30. ~KernelHolder();
  31. void SetBinHandle(void *bin_handle) { bin_handle_ = bin_handle; }
  32. private:
  33. friend class KernelBinRegistry;
  34. const char *stub_func_;
  35. void *bin_handle_;
  36. std::shared_ptr<ge::OpKernelBin> kernel_bin_;
  37. };
  38. class KernelBinRegistry {
  39. public:
  40. static KernelBinRegistry &GetInstance() {
  41. static KernelBinRegistry instance;
  42. return instance;
  43. }
  44. const char *GetUnique(const string &stub_func);
  45. const char *GetStubFunc(const std::string &stub_name);
  46. bool AddKernel(const std::string &stub_name, std::unique_ptr<KernelHolder> &&holder);
  47. private:
  48. std::map<std::string, std::unique_ptr<KernelHolder>> registered_bins_;
  49. std::set<std::string> unique_stubs_;
  50. std::mutex mutex_;
  51. };
  52. class TbeTaskBuilder {
  53. public:
  54. TbeTaskBuilder(const std::string &model_name, const NodePtr &node, const domi::KernelDef &kernel_def);
  55. ~TbeTaskBuilder() = default;
  56. Status BuildTask(TbeOpTask &task, const SingleOpModelParam &param);
  57. private:
  58. Status InitTilingInfo(TbeOpTask &task);
  59. Status SetKernelArgs(TbeOpTask &task, const SingleOpModelParam &param, const OpDescPtr &op_desc);
  60. Status GetSmDesc(void **sm_desc, const SingleOpModelParam &param) const;
  61. Status RegisterKernel(TbeOpTask &task, const SingleOpModelParam &param);
  62. Status DoRegisterKernel(const OpKernelBin &kernel_bin, const char *bin_file_key, void **bin_handle,
  63. const SingleOpModelParam &param);
  64. Status DoRegisterBinary(const OpKernelBin &kernel_bin, void **bin_handle, const SingleOpModelParam &param) const;
  65. Status DoRegisterMeta(void *bin_handle);
  66. static Status DoRegisterFunction(void *bin_handle, const char *stub_name, const char *kernel_name);
  67. const NodePtr node_;
  68. const OpDescPtr op_desc_;
  69. const domi::KernelDef &kernel_def_;
  70. const std::string stub_name_;
  71. };
  72. } // namespace ge
  73. #endif // GE_SINGLE_OP_TASK_TBE_TASK_BUILDER_H_

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