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.

output.cc 3.1 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include "ge_runtime/output.h"
  17. #include "framework/common/ge_inner_error_codes.h"
  18. #include "framework/common/util.h"
  19. #include "framework/common/debug/ge_log.h"
  20. namespace ge {
  21. namespace model_runner {
  22. Output::Output(const OpInfoPtr &op_info, const std::shared_ptr<DavinciModel> &model)
  23. : model_(model), op_info_(op_info), input_num_(0) {}
  24. Output::~Output() {}
  25. bool Output::Init() {
  26. if (op_info_ == nullptr || model_ == nullptr) {
  27. GELOGE(INTERNAL_ERROR, "The op_desc_ or model_ is nullptr.");
  28. return false;
  29. }
  30. input_num_ = op_info_->input_tensors.size();
  31. v_input_size_.clear();
  32. v_input_data_addr_.clear();
  33. auto input_vector = op_info_->input_addrs;
  34. if (input_num_ != input_vector.size()) {
  35. GELOGE(INTERNAL_ERROR, "The input desc size: %zu != input addr size: %zu.", input_num_, input_vector.size());
  36. return false;
  37. }
  38. for (size_t i = 0; i < input_num_; i++) {
  39. uint32_t tensorSize = 0;
  40. const auto &input_info = op_info_->input_tensors.at(i);
  41. tensorSize = input_info.size;
  42. v_input_size_.push_back(tensorSize);
  43. v_input_data_addr_.push_back(reinterpret_cast<uint8_t *>(input_vector.at(i)));
  44. }
  45. GELOGI("Init output:%zu, %zu, %zu", input_num_, v_input_size_.size(), v_input_data_addr_.size());
  46. return true;
  47. }
  48. ///
  49. /// @ingroup domi_ome
  50. /// @brief Copy Op Output to user space.
  51. /// @brief when model running, Add one DataOp as input node, Add one Output Op as output node.
  52. /// @return Status
  53. ///
  54. bool Output::CopyRslt(OutputData *rslt, uint32_t data_begin, uint32_t &data_index, bool support_mem_share) {
  55. if (rslt == nullptr) {
  56. GELOGE(FAILED, "OutputData is null.");
  57. return false;
  58. }
  59. uint32_t data_count = 0;
  60. if (v_input_size_.empty() || v_input_data_addr_.empty()) {
  61. GELOGE(INTERNAL_ERROR, "v_output_size_ or v_output_data_addr_ is empty!");
  62. return false;
  63. }
  64. for (size_t i = 0; i < input_num_; i++) {
  65. DataBuffer data_buf = rslt->blobs[data_begin + data_count];
  66. bool ret = SetDataBuf(data_buf, data_begin, data_count, i, support_mem_share);
  67. if (!ret) {
  68. GELOGE(FAILED, "Copy data to host failed. index: %lu, addr: %p", i, v_input_data_addr_[i]);
  69. return ret;
  70. }
  71. data_index = data_begin + data_count;
  72. }
  73. return true;
  74. }
  75. bool Output::SetDataBuf(DataBuffer &data_buf, uint32_t data_begin, uint32_t &data_count, size_t i,
  76. bool support_mem_share) {
  77. return true;
  78. }
  79. } // namespace model_runner
  80. } // namespace ge

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