LCOV - code coverage report
Current view: top level - src/api_check/inc - kernel_base_check.h (source / functions) Coverage Total Hit
Test: coverage.info_filtered Lines: 100.0 % 10 10
Test Date: 2026-07-27 14:41:20 Functions: 75.0 % 4 3

            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              : /*!
      12              :  * \file kernel_base_check.h
      13              :  * \brief
      14              :  */
      15              : 
      16              : #ifndef ASCENDC_BASE_CHECK_H
      17              : #define ASCENDC_BASE_CHECK_H
      18              : 
      19              : #include <vector>
      20              : #include <string>
      21              : #include "kernel_check_util.h"
      22              : 
      23              : namespace AscendC {
      24              : namespace check {
      25              : const uint32_t MASK_ARRAY_LEN = 2;
      26              : const uint32_t NAME_MAX_LEN = 128;
      27              : 
      28              : enum class ModeType : uint8_t { NONE_MODE = 0, NORM_MODE = 1, COUNTER_MODE = 2 };
      29              : 
      30              : struct TensorOverflowParams {
      31              :     TensorOverflowParams() = default;
      32              : 
      33          248 :     TensorOverflowParams(
      34              :         const uint64_t bufferSizeIn, const uint64_t dtypeSizeIn, const uint64_t repeatTimesIn,
      35              :         const uint64_t blkStrideIn, const uint64_t repStrideIn, const bool isCounterIn)
      36          248 :         : bufferSize(bufferSizeIn),
      37          248 :           dtypeSize(dtypeSizeIn),
      38          248 :           repeatTimes(repeatTimesIn),
      39          248 :           blkStride(blkStrideIn),
      40          248 :           repStride(repStrideIn),
      41          248 :           isCounter(isCounterIn)
      42          248 :     {}
      43              : 
      44              :     uint64_t bufferSize = 0;
      45              :     uint64_t dtypeSize = 1;
      46              :     uint64_t repeatTimes = 1;
      47              :     uint64_t blkStride = DEFAULT_BLK_STRIDE;
      48              :     uint64_t repStride = DEFAULT_REPEAT_STRIDE;
      49              :     bool isCounter = false; // only used for gathermask
      50              : };
      51              : 
      52              : /*
      53              :  * @funcname: GetMaskLength
      54              :  * @brief: the maximum number of elements calculated this repeat.
      55              :  *         For example mask is 0x30fff + 0xffffffff. The maximum num per repeat is 64 + 18 = 82
      56              :  * @return: uint64_t
      57              :  */
      58              : uint64_t GetMaskLength(std::vector<uint64_t>& maskArray, const uint32_t dtypeSize);
      59              : 
      60              : /*
      61              :  * @funcname: CheckTensorSizeOverflow
      62              :  * @brief: common method used to compare tensor size and minimum needed size, and report error if overflow
      63              :  *         mode 0: none, mode 1: norm mode, mode 2: counter mode
      64              :  * @return: true/false
      65              :  */
      66              : bool CheckTensorSizeOverflow(
      67              :     uint64_t expectedSize, uint64_t tensorSize, const std::string& tensorName, const std::string& apiName,
      68              :     const ModeType mode = ModeType::NONE_MODE);
      69              : 
      70              : void CounterSplitMainTail(
      71              :     std::vector<uint64_t>& maskArray, const uint32_t dtypeBytes, uint64_t& mainRepeatTimes, uint64_t& tailRepeatTimes,
      72              :     std::vector<uint64_t>& mainMaskArray, std::vector<uint64_t>& tailMaskArray);
      73              : 
      74              : uint64_t CalculateVectorMaxOffset(
      75              :     const uint64_t repeatTimes, const uint64_t blkStride, const uint64_t repStride, const uint64_t maskLen,
      76              :     const uint64_t blockLen);
      77              : 
      78              : class TikcppBaseCheck {
      79              : public:
      80          608 :     explicit TikcppBaseCheck(const std::string& name) : apiName(name) {}
      81          608 :     virtual ~TikcppBaseCheck() {}
      82              : 
      83              :     /*
      84              :      * @funcname: CheckTensorScope
      85              :      * @brief: check whether the tensor hardware position equal to the expect position.
      86              :      * @params: tensorPos, tensor physical position
      87              :      *          expectedPos, expected tensor physical position
      88              :      *          tensorInfo, src0 / src1/ dst for print information
      89              :      *          posInfo, expected position info for print information
      90              :      * @return: true/false
      91              :      */
      92              :     bool CheckTensorScope(
      93              :         const uint8_t logicPos, const uint8_t expectedPos, const std::string& tensorInfo,
      94              :         const std::string& posInfo) const;
      95              : 
      96              :     /*
      97              :      * @funcname: CheckBufferSizeOverFlow
      98              :      * @brief: check whether the tensor allocate size equal to the buffer limited size.
      99              :      * @return: true/false
     100              :      */
     101              :     bool CheckBufferSizeOverFlow(const uint64_t localSize, const uint64_t bufferSize, const std::string& errMsg) const;
     102              : 
     103              :     /*
     104              :      * @funcname: CheckMaskArray
     105              :      * @brief: check the mask in bits mode
     106              :      * @return: true/false
     107              :      */
     108              :     bool CheckMaskArray(std::vector<uint64_t> maskArray) const;
     109              : 
     110              :     /*
     111              :      * @funcname: CheckMaskImm
     112              :      * @brief: check the mask in continuous mode
     113              :      * @return: true/false
     114              :      */
     115              :     bool CheckMaskImm(const uint64_t mask) const;
     116              : 
     117              :     /*
     118              :      * @funcname: CheckTensorOverflowLow
     119              :      * @brief: check whether tensor used size over the allocated size in low api level
     120              :      * @return: true/false
     121              :      */
     122              :     bool CheckTensorOverflowLow(
     123              :         std::vector<uint64_t>& maskArray, const TensorOverflowParams& params, const std::string& tensorName) const;
     124              : 
     125              :     /*
     126              :      * @funcname: CheckTensorOverflowLowGatherMask
     127              :      * @brief: check whether tensor used size over the allocated size in low api level for GatherMask
     128              :      * @return: true/false
     129              :      */
     130              :     bool CheckTensorOverflowLowGathermask(
     131              :         std::vector<uint64_t>& maskArray, const TensorOverflowParams& params, const std::string& tensorName) const;
     132              : 
     133              :     /*
     134              :      * @funcname: CheckTensorOverflowLowBrcb
     135              :      * @brief: check whether tensor used size over the allocated size in low api level for Brcb
     136              :      *         Note that there is no counter mode for brcb + mask is not used
     137              :      * @return: true/false
     138              :      */
     139              :     bool CheckTensorOverflowLowBrcb(const TensorOverflowParams& params, const std::string& tensorName) const;
     140              : 
     141              :     /*
     142              :      * @funcname: CheckTensorOverflowHigh
     143              :      * @brief: check whether tensor used size over the allocated size in high api level
     144              :      * @return: true/false
     145              :      */
     146              :     bool CheckTensorOverflowHigh(
     147              :         const uint32_t dtypeSize, const uint64_t bufferSize, const uint32_t calCount,
     148              :         const std::string& tensorName) const;
     149              : 
     150              :     /*
     151              :      * @funcname: UpdateMaskArrayAndCheck
     152              :      * @brief: If isSetMask = false, replace maskArray with maskHigh and maskLow value in registers.
     153              :      *         Check the latest maskArray value is valid with given dtype
     154              :      * @params: maskArray, mask value given by user. Can be len 1 or len 2
     155              :      *          maxByteLen, among all dtypes given by function, the largest value of sizeof(dtype)
     156              :      * @return: true/false
     157              :      */
     158              :     bool UpdateMaskArrayAndCheck(std::vector<uint64_t>& maskArray, const uint32_t maxByteLen) const;
     159              : 
     160              :     /*
     161              :      * @funcname: CheckTensorAddrAlign
     162              :      * @brief: Check tensor start address is aligned with alignBytes
     163              :      * @params: tensorAddr, tensor address
     164              :      *          phyPos, tensor physical position, used to calculate real offset of tensor
     165              :      *          alignBytes, 32B aligned / 512B aligned etc
     166              :      *          tensorInfo, src0 / src1/ dst for print information
     167              :      * @return: true/false
     168              :      */
     169              :     bool CheckTensorAddrAlign(
     170              :         const uint64_t tensorAddr, const uint8_t phyPos, const uint64_t alignBytes,
     171              :         const std::string& tensorInfo) const;
     172              : 
     173              : protected:
     174              :     std::string apiName = "";
     175              : };
     176              : 
     177              : } // namespace check
     178              : } // namespace AscendC
     179              : #endif
        

Generated by: LCOV version 2.0-1