LCOV - code coverage report
Current view: top level - adump/exception - dump_args.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 26 26
Test Date: 2026-07-28 10:54:24 Functions: 100.0 % 5 5

            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_ARGS_H
      11              : #define DUMP_ARGS_H
      12              : 
      13              : #include <string>
      14              : #include <vector>
      15              : #include <sstream>
      16              : #include "adump_pub.h"
      17              : #include "adump_api.h"
      18              : #include "dump_operator.h"
      19              : #include "runtime/rt.h"
      20              : #include "kernel_info_collector.h"
      21              : #include "log/adx_log.h"
      22              : #include "adx_exception_callback.h"
      23              : 
      24              : namespace Adx {
      25              : #define IDE_CHECK_RET(ret, action)    \
      26              :     do {                              \
      27              :         if ((ret) != ADUMP_SUCCESS) { \
      28              :             action;                   \
      29              :         }                             \
      30              :     } while (0)
      31              : 
      32              : constexpr uint16_t TYPE_L0_EXCEPTION_DFX = 4U;
      33              : constexpr uint16_t TYPE_L0_EXCEPTION_DFX_ARGS_INFO = 5U;
      34              : constexpr uint16_t TYPE_L0_EXCEPTION_DFX_IS_TIK = 6U;
      35              : constexpr uint64_t TENSOR_TYPE_MASK = 0x0FFFF;              // 0~15 bit
      36              : constexpr uint64_t POINTER_TYPE_MASK = 0x0FFFF0000;         // 16~31 bit
      37              : constexpr uint64_t TENSOR_COUNT_MASK = 0xFFFFFFFF00000000;  // high 32 bits
      38              : constexpr uint64_t TENSOR_DIMENSION_MASK = 0x0FFFFFFFF;     // low 32 bits
      39              : constexpr uint32_t TENSOR_COUNT_SHIFT_BITS = 32;
      40              : constexpr uint32_t POINTER_TYPE_SHIFT_BITS = 16;
      41              : constexpr int32_t ELF_DATA2MSB = 2;
      42              : constexpr uint32_t BITS_PER_BYTE = 8U;
      43              : 
      44              : enum class DfxPointerType : uint16_t {
      45              :     INVALID_POINTER = 0,
      46              :     LEVEL_1_POINTER = 1,
      47              :     LEVEL_2_POINTER,
      48              :     LEVEL_2_POINTER_WITH_SHAPE,
      49              :     SHAPE_TENSOR_PLACEHOLD
      50              : };
      51              : 
      52              : struct InputBuffer {
      53          125 :     InputBuffer(const void *argAddr, uint64_t len, uint32_t index) : addr(argAddr), length(len), argIndex(index) {}
      54              :     const void *addr;
      55              :     uint64_t length;
      56              :     uint32_t argIndex;
      57              : };
      58              : 
      59              : struct TensorBuffer {
      60           50 :     TensorBuffer(const void *argAddr, uint32_t index, DfxTensorType dfxTensorType, DfxPointerType dfxPointerType)
      61           50 :         : addr(argAddr),
      62           50 :           argIndex(index),
      63           50 :           tensorType(dfxTensorType),
      64           50 :           pointerType(dfxPointerType)
      65              :     {
      66           50 :     }
      67              :     const void *addr{nullptr};
      68              :     uint64_t size{0U};
      69              :     uint64_t dataTypeSize{1U};  // 无data type size情况下,默认值为1,size为实际内存大小
      70              :     bool isDataTypeSizeByte{true};  // 标记dataTypeSize以bit还是byte为单位
      71              :     uint64_t dimension{0U};
      72              :     std::vector<uint64_t> shape;
      73              :     uint32_t argIndex;
      74              :     DfxTensorType tensorType;
      75              :     DfxPointerType pointerType;
      76           42 :     uint64_t GetTotalByteSize() const
      77              :     {
      78           42 :         if (isDataTypeSizeByte) {
      79           34 :             return dataTypeSize * size;
      80              :         }
      81            8 :         uint64_t totalBits = dataTypeSize * size;
      82            8 :         uint32_t remainder = totalBits % BITS_PER_BYTE == 0 ? 0 : 1;  // 向上取整
      83            8 :         return totalBits / BITS_PER_BYTE + remainder;
      84              :     }
      85              : };
      86              : 
      87              : extern uint64_t g_chunk[RING_CHUNK_SIZE + MAX_TENSOR_NUM];
      88              : 
      89              : class DumpArgs {
      90              : public:
      91           67 :     DumpArgs()
      92          134 :         : sizeInfo_(nullptr),
      93           67 :           sizeBeginIndex_(0),
      94           67 :           skipNum_(0),
      95           67 :           inputNum_(0),
      96           67 :           argAddr_(nullptr),
      97           67 :           argSize_(0),
      98           67 :           dumpWithDfxFlag_(false),
      99           67 :           isTik_(false),
     100           67 :           exceptionDfxPtr_(nullptr),
     101           67 :           exceptionDfxSize_(0),
     102           67 :           kernelCollector_(std::make_shared<KernelInfoCollector>()){};
     103           67 :     ~DumpArgs() = default;
     104              :     int32_t LoadArgsExceptionInfo(const rtExceptionInfo &exception);
     105              :     int32_t DumpArgsExceptionInfo(const uint32_t deviceId, const std::string &dumpPath);
     106              : 
     107              :     bool DumpArgsDumpWithDfxFlag() const;
     108              :     const std::vector<InputBuffer> &DumpArgsGetInputBuffer() const;
     109              :     const std::vector<TensorBuffer> &DumpArgsGetTensorBuffer() const;
     110              :     const std::vector<DumpWorkspace> &DumpArgsGetWorkSpace() const;
     111              : 
     112              : private:
     113              :     int32_t DumpArgsExceptionFile(const uint32_t deviceId, const std::string &dumpPath);
     114              :     std::string GetDumpFilePath(const std::string &dumpPath) const;
     115              :     int32_t CheckParam(const rtExceptionArgsInfo_t &exceptionArgsInfo,
     116              :                        const rtExceptionExpandInfo_t &exceptionExpandInfo) const;
     117              :     int32_t InitAttributes(const rtExceptionArgsInfo_t &exceptionArgsInfo,
     118              :                            const rtExceptionExpandInfo_t &exceptionExpandInfo);
     119              :     int32_t InitTensorModeInfo(const uint8_t *exceptionDfxPtr);
     120              :     int32_t InitTensorModeInfoInner(const uint8_t *exceptionDfxPtr, uint64_t &currDfxSize, uint32_t currArgsIndex);
     121              :     int32_t LoadArgsInfoWithDfx(const rtExceptionArgsInfo_t &exceptionArgsInfo);
     122              :     int32_t LoadArgsInfoWithSizeInfo(const rtExceptionArgsInfo_t &exceptionArgsInfo,
     123              :                                      const rtExceptionExpandInfo_t &exceptionExpandInfo);
     124              :     void LogArgsInfo(const void **argOnHost, uint32_t maxArgNum);
     125              :     int32_t LoadInputBuffer(const void **argOnHost, const uint32_t argIndex, uint64_t &sizeInfoIdx);
     126              :     int32_t LoadPointerTensor(const void **argOnHost, const uint32_t argIndex, uint64_t &sizeInfoIdx);
     127              :     void LoadTilingData();
     128              : 
     129              :     template <typename T>
     130              :     int32_t GetPointerValueByBigEndian(const uint8_t **ptr, T &value, uint64_t &currentDfxSize,
     131              :                                        uint16_t totalDfxSize) const;
     132              :     template <typename T>
     133              :     int32_t GetPointerValueByLittleEndian(const uint8_t **ptr, T &value, uint64_t &currentDfxSize,
     134              :                                           uint16_t totalDfxSize) const;
     135              :     int32_t FindExceptionDfx(const rtExceptionArgsInfo_t &exceptionArgsInfo);
     136              :     int32_t CheckAddressOverArgs(const uint64_t *address, const void **argOnHost, uint64_t maxArgNum) const;
     137              :     int32_t GetAddressBias(uint64_t &addrBias, const void *argAddr, void *baseAddr, uint64_t argsSize) const;
     138              :     void RecordCurrentLog();
     139              :     std::string taskId_;
     140              :     std::string streamId_;
     141              :     std::vector<InputBuffer> inputBuffer_;
     142              :     std::vector<InputBuffer> tilingData_;
     143              :     std::vector<TensorBuffer> tensorBuffer_;
     144              :     std::vector<DumpWorkspace> workspace_;
     145              :     std::vector<DumpWorkspace> mc2Space_;
     146              :     uint64_t *sizeInfo_;
     147              :     uint32_t sizeBeginIndex_;
     148              :     uint32_t skipNum_;
     149              :     uint32_t inputNum_;
     150              :     void *argAddr_;
     151              :     uint64_t argSize_;
     152              :     bool dumpWithDfxFlag_;
     153              :     bool isTik_;
     154              :     const uint8_t *exceptionDfxPtr_;
     155              :     uint16_t exceptionDfxSize_;
     156              :     std::shared_ptr<KernelInfoCollector> kernelCollector_;
     157              :     std::vector<std::string> logRecord_;
     158              :     std::ostringstream oss_;
     159              : };
     160              : }  // namespace Adx
     161              : #endif
        

Generated by: LCOV version 2.0-1