Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #ifndef DUMP_CORE_H
11 : #define DUMP_CORE_H
12 :
13 : #include <vector>
14 : #include <string>
15 : #include "runtime/base.h"
16 : #include "dump_args.h"
17 : #include "dump_ELF.h"
18 : #include "dump_common.h"
19 : #include "register_config.h"
20 : #include "adump_platform_api.h"
21 : #include "kernel_symbol_locator.h"
22 : #include "inner_kernel.h"
23 :
24 : namespace Adx {
25 : constexpr uint16_t CORE_ID_BIT_MAP_SIZE = 64;
26 : constexpr uint64_t JSON_SUFFIX_LEN = 5; // length of ".json"
27 : constexpr uint32_t SOC_VERSION_SIZE = 50U;
28 : constexpr uint32_t MAX_DIM_SIZE = 25U;
29 : const std::string DEFAULT_KERNEL_NAME("unknow_kernel");
30 :
31 : class DumpCore {
32 : public:
33 11 : explicit DumpCore(const std::string& path, uint32_t devId) : path_(path), devId_(devId) {};
34 11 : ~DumpCore() = default;
35 : int32_t DumpCoreFile(const rtExceptionInfo& exception);
36 : void DumpV2Register(uint8_t coreType, uint16_t coreId);
37 : void DumpV4Register(uint8_t coreType, uint16_t coreId);
38 :
39 : private:
40 : struct CacheParam {
41 : uint8_t coreType;
42 : uint16_t coreId;
43 : uint64_t memSize;
44 : uint64_t memAddr;
45 : uint32_t sectionIndex;
46 : rtDebugMemoryType_t cacheType;
47 33 : CacheParam() : coreType(0), coreId(0), memSize(0), memAddr(0), sectionIndex(0), cacheType(RT_MEM_TYPE_MAX) {}
48 76 : CacheParam(uint8_t type, uint16_t id, uint64_t size, uint64_t addr, uint32_t index, rtDebugMemoryType_t memType)
49 76 : : coreType(type), coreId(id), memSize(size), memAddr(addr), sectionIndex(index), cacheType(memType)
50 76 : {}
51 : };
52 :
53 : void DumpCoreInfo(uint32_t devId);
54 :
55 : void DumpGlobalMemory(const rtExceptionInfo& exception);
56 : int32_t ProcessGlobalMemory(GlobalMemInfo& memInfo, std::vector<GlobalMemInfo>& memInfoList, bool checkAddr = true);
57 : void DumpArgsInfo(const rtExceptionArgsInfo_t& exceptionArgsInfo, std::vector<GlobalMemInfo>& memInfoList);
58 : void DumpInput(const DumpArgs& args, std::vector<GlobalMemInfo>& memInfoList);
59 : void DumpTensorBuffer(const DumpArgs& args, std::vector<GlobalMemInfo>& memInfoList);
60 : void DumpWorkSpace(const DumpArgs& args, std::vector<GlobalMemInfo>& memInfoList);
61 : void DumpStack(const rtBinHandle& binHandle, std::vector<GlobalMemInfo>& memInfoList);
62 : void DumpCoreStack(const rtBinHandle& binHandle, const uint8_t coreType, const uint16_t coreId, bool checkAddr,
63 : const rtStackType_t rtStackType, DfxTensorType dumpStackType, std::vector<GlobalMemInfo> &memInfoList);
64 : void DumpHostKernelBin(const rtExceptionKernelInfo_t& kernelInfo);
65 : void DumpDeviceKernelBin(const rtExceptionKernelInfo_t& kernelInfo, std::vector<GlobalMemInfo>& memInfoList);
66 : void DumpHostFile(const rtExceptionArgsInfo_t& argsInfo);
67 : void DumpHostFile(const std::string& filePath, uint32_t sectionType, const std::string& sectionName);
68 : void DumpKernelInfo(const std::string& kernelName);
69 : void DumpGlobalAuxInfo(const std::vector<GlobalMemInfo>& memInfoList);
70 : int32_t D2HMemcpyWithCheck(const GlobalMemInfo& memInfo, std::string& data) const;
71 : int32_t D2HMemcpyWithNoCheck(const GlobalMemInfo& memInfo, std::string& data) const;
72 : void DumpResourceInit();
73 : void DumpLocalMemory(uint8_t coreType, uint16_t coreId);
74 : void DumpCache(
75 : uint8_t coreType, uint16_t coreId, const std::string& sectionName, std::vector<LocalMemInfo>& localMemInfoList);
76 : void DumpCache(
77 : uint8_t coreType, uint16_t coreId, const CacheParam& cacheParam, const std::string& sectionName,
78 : std::vector<LocalMemInfo>& localMemInfoList);
79 : void DumpBuffer(
80 : uint8_t coreType, uint16_t coreId, const std::string& sectionName, std::vector<LocalMemInfo>& localMemInfoList);
81 : void DumpLocalAuxInfo(const std::string& coreIdStr, std::vector<LocalMemInfo>& localMemInfoList);
82 : void DumpRegister(uint8_t coreType, uint16_t coreId);
83 : void DumpV2DebugRegister(
84 : uint8_t coreType, uint16_t coreId, const std::vector<RegisterTable>& tables,
85 : std::vector<RegInfo>& regData) const;
86 : void DumpV2ErrorRegister(
87 : uint8_t coreType, uint16_t coreId, const std::vector<ErrorRegisterTable>& tables,
88 : std::vector<RegInfo>& regData) const;
89 : void DumpV4DebugRegister(
90 : uint8_t coreType, uint16_t coreId, RegisterType regType, const std::vector<RegisterTable>& tables,
91 : std::vector<RegInfoWide>& regData) const;
92 : void DumpV4ErrorRegister(
93 : uint8_t coreType, uint16_t coreId, const std::vector<ErrorRegisterTable>& tables,
94 : std::vector<RegInfoWide>& regData) const;
95 : bool DumpReadDebugAICoreRegister(
96 : uint8_t coreType, uint16_t coreId, RegisterType regType, const RegisterTable& table, std::vector<uint8_t>& data) const;
97 : std::string FormatRegisterData(const uint8_t* valAddr, uint8_t valSize) const;
98 : template <typename T>
99 : void DumpDebugRegisterImpl(
100 : uint8_t coreType, uint16_t coreId, RegisterType regType, const std::vector<RegisterTable>& tables, std::vector<T>& regData) const;
101 : template <typename T>
102 : void DumpErrorRegisterImpl(
103 : uint8_t coreType, uint16_t coreId, const std::vector<ErrorRegisterTable>& tables,
104 : std::vector<T>& regData) const;
105 : uint16_t ConvertCoreId(uint8_t coreType, uint16_t coreId) const;
106 : void SaveCoreFile(const rtExceptionInfo& exception);
107 : std::string path_;
108 : uint32_t devId_;
109 : ELF::DumpELF coreFile_;
110 : std::vector<uint16_t> aiCoreIds_;
111 : std::vector<uint16_t> aiVectorCoreIds_;
112 : BufferSize bufferSize_{};
113 :
114 : CacheParam binParam_;
115 : CacheParam argsParam_;
116 : CacheParam tilingDataParam_;
117 : std::vector<CacheParam> stackParamList_;
118 : ExceptionRegInfo exceptionRegInfo_{0, nullptr};
119 : };
120 : } // namespace Adx
121 : #endif
|