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.

debug.cc 2.7 kB

5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "graph/manager/util/debug.h"
  17. #include <string>
  18. #include "common/ge/ge_util.h"
  19. #include "framework/common/debug/ge_log.h"
  20. using google::protobuf::Message;
  21. using google::protobuf::io::CodedInputStream;
  22. using google::protobuf::io::FileOutputStream;
  23. namespace ge {
  24. Debug::Debug() = default;
  25. Debug::~Debug() = default;
  26. void Debug::DumpProto(const Message &proto, const char *file) {
  27. std::string file_path = RealPath(file);
  28. int fd = mmOpen2(file_path.c_str(), M_WRONLY | M_CREAT | O_TRUNC, M_IRUSR | M_IWUSR | M_UMASK_GRPREAD |
  29. M_UMASK_OTHREAD);
  30. if (fd == -1) {
  31. GELOGW("Write %s failed. errmsg:%s", file_path.c_str(), strerror(errno));
  32. return;
  33. }
  34. auto output = ge::MakeShared<FileOutputStream>(fd);
  35. if (output == nullptr) {
  36. GELOGW("create output failed.");
  37. if (mmClose(fd) != 0) {
  38. GELOGW("close fd failed. errmsg:%s", strerror(errno));
  39. }
  40. return;
  41. }
  42. bool ret = google::protobuf::TextFormat::Print(proto, output.get());
  43. if (!ret) {
  44. GELOGW("dump proto failed.");
  45. }
  46. if (mmClose(fd) != 0) {
  47. GELOGW("close fd failed. errmsg:%s", strerror(errno));
  48. }
  49. }
  50. Status Debug::DumpDevMem(const char *file, const void *addr, int64_t size) {
  51. if (size == 0) {
  52. GELOGI("Dump data failed because the size is 0.");
  53. return SUCCESS;
  54. }
  55. uint8_t *host_addr = nullptr;
  56. rtError_t ret = rtMallocHost(reinterpret_cast<void **>(&host_addr), size);
  57. if (ret != RT_ERROR_NONE) {
  58. REPORT_CALL_ERROR("E19999", "Call rtMallocHost failed, size:%zu, ret: 0x%X",
  59. size, ret);
  60. GELOGE(FAILED, "Call rt api rtMallocHost failed, ret: 0x%X", ret);
  61. return FAILED;
  62. }
  63. GE_MAKE_GUARD_RTMEM(host_addr);
  64. ret = rtMemcpy(host_addr, size, addr, size, RT_MEMCPY_DEVICE_TO_HOST);
  65. if (ret != RT_ERROR_NONE) {
  66. REPORT_CALL_ERROR("E19999", "Call rtMemcpy failed, size:%zu, ret: 0x%X",
  67. size, ret);
  68. GELOGE(FAILED, "Call rt api rtMemcpy failed, ret: 0x%X", ret);
  69. return FAILED;
  70. }
  71. GE_CHK_STATUS_RET(MemoryDumper::DumpToFile(file, host_addr, size));
  72. return SUCCESS;
  73. }
  74. } // namespace ge

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