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 :
11 : #ifndef ADUMP_EXCEPTION_DUMP_FILE_H
12 : #define ADUMP_EXCEPTION_DUMP_FILE_H
13 :
14 : #include <string>
15 : #include <vector>
16 :
17 : #include "proto/dump_task.pb.h"
18 : #include "file.h"
19 : #include "dump_operator.h"
20 : #include "dump_tensor.h"
21 : #include "dump_args.h"
22 :
23 : namespace Adx {
24 : class DumpFile {
25 : public:
26 85 : DumpFile(const uint32_t deviceId, const std::string &filePath) : deviceId_(deviceId),
27 85 : file_(filePath, M_RDWR | M_CREAT | M_APPEND, M_IRUSR | M_IWUSR, true) {}
28 : void SetHeader(const std::string &opName);
29 : void SetOpAttr(const std::string &name, const std::string &value);
30 : void SetInputTensors(const std::vector<DumpTensor> &inputTensors);
31 : void SetOutputTensors(const std::vector<DumpTensor> &outputTensors);
32 : void SetWorkspaces(const std::vector<DumpWorkspace> &workspaces);
33 : void SetTensors(const std::vector<TensorInfo> &tensors, std::vector<std::string> &record);
34 : void SetInputBuffer(const std::vector<InputBuffer> input);
35 : void SetTensorBuffer(const std::vector<TensorBuffer> &tensorBuffer);
36 : int32_t Dump(std::vector<std::string> &record);
37 : #if !defined(ADUMP_SOC_HOST) || ADUMP_SOC_HOST == 1
38 : void SetMc2spaces(const std::vector<DumpWorkspace> &mc2Spaces);
39 : #endif
40 :
41 : private:
42 : bool HasDumpData() const;
43 : void SetAicInfo(std::vector<std::string> &record);
44 : int32_t WriteHeader() const;
45 : int32_t WriteInputTensors();
46 : int32_t WriteOutputTensors();
47 : int32_t WriteWorkspace();
48 : int32_t WriteMc2Space() const;
49 : int32_t WriteInputBuffer();
50 :
51 : struct DeviceData {
52 169 : DeviceData(const void *data, uint64_t size) : addr(data), bytes(size) {}
53 : const void *addr;
54 : uint64_t bytes;
55 : };
56 : int32_t WriteDeviceDataToFile(const DeviceData &devData) const;
57 : void LogIsOtherDeviceAddress(const DeviceData &devData, rtMemInfo_t &memInfo) const;
58 : int32_t AllocDefaultMemory(void **hostPtr, uint64_t size) const;
59 : #if !defined(ADUMP_SOC_HOST) || ADUMP_SOC_HOST == 1
60 : bool SupportDumpMc2spaces() const;
61 : uint64_t ComputeStructSize() const;
62 : uint64_t HandleMc2Ctx(const void *hostData, uint64_t opParamSize, size_t index);
63 : void HandleMc2CtxV1(const void *hostData, uint64_t &totalSize, std::vector<DeviceData> &dataList) const;
64 : uint64_t GetMc2DataSize(const void *addr, size_t index, uint64_t &opParamSize);
65 : #endif
66 :
67 : uint32_t deviceId_;
68 : File file_;
69 : // file format
70 : toolkit::dump::DumpData header_;
71 : std::vector<DeviceData> inputs_;
72 : std::vector<DeviceData> outputs_;
73 : std::vector<DeviceData> workspaces_;
74 : std::vector<DeviceData> inputBuffer_;
75 : // log record
76 : std::vector<std::string> logRecord_;
77 : #if !defined(ADUMP_SOC_HOST) || ADUMP_SOC_HOST == 1
78 : std::vector<DeviceData> mc2Spaces_;
79 : std::map<size_t, std::vector<DeviceData>> mc2Ctx_;
80 : #endif
81 : };
82 : } // namespace Adx
83 : #endif // ADUMP_EXCEPTION_DUMP_FILE_H
|