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