LCOV - code coverage report
Current view: top level - adump/exception - dump_file.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2026-08-31 10:09:28 Functions: 100.0 % 2 2

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

Generated by: LCOV version 2.0-1