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_OPERATOR_H
11 : #define DUMP_OPERATOR_H
12 :
13 : #include <string>
14 : #include <vector>
15 : #include <sstream>
16 : #include "adump_pub.h"
17 : #include "dump_tensor.h"
18 : #include "kernel_info_collector.h"
19 :
20 : namespace Adx {
21 : struct DumpWorkspace {
22 : DumpWorkspace() = default;
23 10 : DumpWorkspace(const void* wsAddr, uint64_t wsBytes, uint32_t wsArgsOffset)
24 10 : : addr(wsAddr), bytes(wsBytes), argsOffset(wsArgsOffset)
25 10 : {}
26 : const void* addr;
27 : uint64_t bytes;
28 : uint32_t argsOffset;
29 : };
30 :
31 : struct OpIdentity {
32 148 : OpIdentity() = default;
33 0 : OpIdentity(uint32_t deviceid, uint32_t taskid, uint32_t streamid)
34 0 : : deviceId(deviceid), taskId(taskid), streamId(streamid)
35 0 : {}
36 10 : OpIdentity(uint32_t deviceid, uint32_t taskid, uint32_t streamid, uint32_t contextid)
37 10 : : deviceId(deviceid), taskId(taskid), streamId(streamid), contextId(contextid)
38 10 : {}
39 :
40 : bool operator==(const OpIdentity& rhs) const;
41 : std::string GetString() const;
42 :
43 : uint32_t deviceId = 0U;
44 : uint32_t taskId = 0U;
45 : uint32_t streamId = 0U;
46 : uint32_t contextId = UINT32_MAX;
47 : };
48 :
49 : class DumpOperator {
50 : public:
51 1 : DumpOperator() = default;
52 : void Init(const OperatorInfoV2& opInfo);
53 : bool IsBelongTo(const OpIdentity& identity) const;
54 : int32_t LogExceptionInfo(const rtExceptionArgsInfo& argsInfo);
55 : int32_t CopyOpKernelFile() const;
56 : int32_t RefreshAddrs(const rtExceptionArgsInfo& argsInfo);
57 : int32_t DumpException(const uint32_t deviceId, const std::string& dumpPath);
58 : explicit DumpOperator(const OperatorInfoV2& opInfo);
59 :
60 : private:
61 : int32_t DumpExceptionFile(const uint32_t deviceId, const std::string& dumpPath);
62 : void InitDeviceArgs();
63 : bool IsTvmOperator() const;
64 : std::string GetTensorString(const DumpTensor& tensor);
65 : int32_t LogExceptionArgs(const rtExceptionArgsInfo& argsInfo) const;
66 : std::string GetDumpFilePath(const std::string& dumpPath) const;
67 : void PrintAdditionInfo(const char* flag) const;
68 : void PrintLog(void* const* argsOnHost, size_t argNum, const std::string& tag) const;
69 : void RecordCurrentLog(std::ostringstream& oss);
70 :
71 : // basic info
72 : std::string opName_;
73 : std::string opType_;
74 : OpIdentity identity_;
75 :
76 : std::vector<DeviceInfo> deviceInfos_;
77 : // args
78 : std::vector<void*> hostArgs_;
79 :
80 : // addition info
81 : std::map<std::string, std::string> additions_;
82 : std::string isHostArgs_;
83 :
84 : std::vector<DumpTensor> inputTensors_;
85 : std::vector<DumpTensor> outputTensors_;
86 : std::vector<DumpWorkspace> workspaces_;
87 : // log record
88 : std::vector<std::string> logRecord_;
89 :
90 : KernelInfoCollector kernelCollector_;
91 : };
92 : } // namespace Adx
93 : #endif // DUMP_OPERATOR_H
|