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.4 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 | M_UMASK_OTHREAD);
  29. if (fd == -1) {
  30. GELOGW("Write %s failed", file_path.c_str());
  31. return;
  32. }
  33. auto output = ge::MakeShared<FileOutputStream>(fd);
  34. if (output == nullptr) {
  35. GELOGW("create output failed.");
  36. if (mmClose(fd) != 0) {
  37. GELOGW("close fd failed.");
  38. }
  39. return;
  40. }
  41. bool ret = google::protobuf::TextFormat::Print(proto, output.get());
  42. if (!ret) {
  43. GELOGW("dump proto failed.");
  44. }
  45. if (mmClose(fd) != 0) {
  46. GELOGW("close fd failed.");
  47. }
  48. }
  49. Status Debug::DumpDevMem(const char *file, const void *addr, int64_t size) {
  50. if (size == 0) {
  51. GELOGI("Dump data failed because the size is 0.");
  52. return SUCCESS;
  53. }
  54. uint8_t *host_addr = nullptr;
  55. rtError_t ret = rtMallocHost(reinterpret_cast<void **>(&host_addr), size);
  56. if (ret != RT_ERROR_NONE) {
  57. GELOGE(FAILED, "Call rt api rtMallocHost failed, ret: 0x%X", ret);
  58. return FAILED;
  59. }
  60. GE_MAKE_GUARD_RTMEM(host_addr);
  61. ret = rtMemcpy(host_addr, size, addr, size, RT_MEMCPY_DEVICE_TO_HOST);
  62. if (ret != RT_ERROR_NONE) {
  63. GELOGE(FAILED, "Call rt api rtMemcpy failed, ret: 0x%X", ret);
  64. return FAILED;
  65. }
  66. GE_CHK_STATUS_RET(MemoryDumper::DumpToFile(file, host_addr, size));
  67. return SUCCESS;
  68. }
  69. } // namespace ge

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