LCOV - code coverage report
Current view: top level - src/api_check - kernel_loaddata_check.cpp (source / functions) Coverage Total Hit
Test: coverage.info_filtered Lines: 0.0 % 95 0
Test Date: 2026-07-27 14:41:20 Functions: 0.0 % 6 0

            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_loaddata_check.cpp
      13              :  * \brief
      14              :  */
      15              : 
      16              : #include "kernel_loaddata_check.h"
      17              : #include "kernel_utils.h"
      18              : #include "kernel_check_params.h"
      19              : 
      20              : namespace AscendC {
      21              : namespace check {
      22            0 : bool TikcppLoaddata2dCheck::CheckAllHighLevel()
      23              : {
      24            0 :     if ((param_.srcPos == static_cast<uint8_t>(HardWareIndex::L1)) &&
      25            0 :         ((param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0A)) &&
      26            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0B)))) {
      27            0 :         ASCENDC_CHECK_TPOSITION(
      28              :             (false), "dst", "L0A Buffer(A2)/L0B Buffer(B2)", "LoadData",
      29              :             GetPositionDisplay(static_cast<TPosition>(param_.dstLogicPos)));
      30            0 :         return false;
      31              :     }
      32            0 :     if ((param_.srcPos == static_cast<uint8_t>(HardWareIndex::GM)) &&
      33            0 :         ((param_.dstPos != static_cast<uint8_t>(HardWareIndex::L1)) &&
      34            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0A)) &&
      35            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0B)))) {
      36            0 :         ASCENDC_CHECK_TPOSITION(
      37              :             (false), "dst", "L1 Buffer(A1/B1)/L0A Buffer(A2)/L0B Buffer(B2)", "LoadData",
      38              :             GetPositionDisplay(static_cast<TPosition>(param_.dstLogicPos)));
      39            0 :         return false;
      40              :     }
      41            0 :     if ((param_.srcPos != static_cast<uint8_t>(HardWareIndex::L1)) &&
      42            0 :         (param_.srcPos != static_cast<uint8_t>(HardWareIndex::GM))) {
      43            0 :         ASCENDC_CHECK_TPOSITION(
      44              :             (false), "src", "L1 Buffer(A1/B1)/GM", "LoadData",
      45              :             GetPositionDisplay(static_cast<TPosition>(param_.srcLogicPos)));
      46            0 :         return false;
      47              :     }
      48            0 :     if (param_.srcPos != static_cast<uint8_t>(HardWareIndex::GM)) {
      49            0 :         ASCENDC_CHECK(CheckBufferSizeOverFlow(
      50              :             param_.srcSize, GlobalParams::Instance().bufferSizeMap.at(param_.srcPos),
      51              :             "check src tensor buffersize failed"));
      52              :     }
      53            0 :     ASCENDC_CHECK(CheckBufferSizeOverFlow(
      54              :         param_.dstSize, GlobalParams::Instance().bufferSizeMap.at(param_.dstPos),
      55              :         "check dst tensor buffersize failed"));
      56              :     // unit element
      57            0 :     if (param_.srcDtypeBytes == 0 || param_.dstDtypeBytes == 0) {
      58            0 :         CHECK_LOG_ERROR("src/dst dtype bytes is zeros");
      59            0 :         return false;
      60              :     }
      61            0 :     int32_t dataLen = (param_.repeatTimes - 1) * param_.srcStride + 1;
      62            0 :     int32_t srcLenElement = (param_.startIndex + dataLen) * BYTE_PER_FRACTAL / param_.srcDtypeBytes;
      63            0 :     int32_t dstLenElement =
      64            0 :         (param_.repeatTimes * BYTE_PER_FRACTAL + (param_.repeatTimes - 1) * param_.dstGap * BYTE_PER_FRACTAL) /
      65            0 :         param_.dstDtypeBytes;
      66            0 :     ASCENDC_CHECK(CheckTensorOverflowHigh(param_.dstDtypeBytes, param_.dstSize, dstLenElement, "dstLocal"));
      67            0 :     ASCENDC_CHECK(CheckTensorOverflowHigh(param_.srcDtypeBytes, param_.srcSize, srcLenElement, "srcLocal"));
      68            0 :     return true;
      69              : };
      70              : 
      71            0 : bool TikcppLoaddata2dv2Check::CheckAllHighLevel() const
      72              : {
      73              : #if defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3102 || (__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
      74              :     if ((param_.srcPos == static_cast<uint8_t>(HardWareIndex::L1)) &&
      75              :         ((param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0A)) &&
      76              :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0B)))) {
      77              :         CHECK_LOG_ERROR("check dst tensor position failed,"
      78              :                         "the src hardware pos is L1, the dst hardware pos support L0A or L0B.");
      79              :         return false;
      80              :     }
      81              :     if ((param_.srcPos == static_cast<uint8_t>(HardWareIndex::GM)) &&
      82              :         ((param_.dstPos != static_cast<uint8_t>(HardWareIndex::L1)) &&
      83              :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0A)) &&
      84              :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0B)))) {
      85              :         CHECK_LOG_ERROR("check dst tensor position failed,"
      86              :                         "the src hardware pos is GM, the dst hardware pos support L1 or L0A or L0B.");
      87              :         return false;
      88              :     }
      89              :     if ((param_.srcPos != static_cast<uint8_t>(HardWareIndex::L1)) &&
      90              :         (param_.srcPos != static_cast<uint8_t>(HardWareIndex::GM))) {
      91              :         CHECK_LOG_ERROR("check src tensor position failed,"
      92              :                         "the src hardware pos support L1 or GM.");
      93              :         return false;
      94              :     }
      95              :     ASCENDC_CHECK(CheckBufferSizeOverFlow(
      96              :         param_.dstSize, GlobalParams::Instance().bufferSizeMap.at(param_.dstPos),
      97              :         "check dst tensor buffersize failed"));
      98              :     if (param_.srcPos != static_cast<uint8_t>(HardWareIndex::GM)) {
      99              :         ASCENDC_CHECK(CheckBufferSizeOverFlow(
     100              :             param_.srcSize, GlobalParams::Instance().bufferSizeMap.at(param_.srcPos),
     101              :             "check src tensor buffersize failed"));
     102              :     }
     103              :     // unit element
     104              :     if (param_.srcDtypeBytes == 0 || param_.dstDtypeBytes == 0) {
     105              :         CHECK_LOG_ERROR("src/dst dtype bytes is zeros");
     106              :         return false;
     107              :     }
     108              :     return true;
     109              : #else
     110            0 :     CHECK_LOG_ERROR("Current version don't support LoadData2dv2");
     111            0 :     return false;
     112              : #endif
     113              : }
     114              : 
     115            0 : bool TikcppLoaddata3dv1Check::CheckAllHighLevel() const
     116              : {
     117              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 2201) || (__NPU_ARCH__ == 3002) || (__NPU_ARCH__ == 3102) || \
     118              :                               (__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     119            0 :     CHECK_LOG_ERROR("unsupport Loaddata3dv1");
     120            0 :     return false;
     121              : #else
     122            0 :     if ((param_.srcPos == static_cast<uint8_t>(HardWareIndex::L1)) &&
     123            0 :         ((param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0A)) &&
     124            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0B)) &&
     125            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::UB)))) {
     126            0 :         CHECK_LOG_ERROR("check dst tensor position failed,"
     127              :                         "the src hardware pos is L1, the dst hardware pos support L0A or L0B or UB.");
     128            0 :         return false;
     129              :     }
     130              : 
     131            0 :     ASCENDC_CHECK(CheckTensorScope(param_.srcLogicPos, static_cast<uint8_t>(HardWareIndex::L1), "srcLocal", "A1/B1"));
     132              : 
     133            0 :     ASCENDC_CHECK(CheckBufferSizeOverFlow(
     134              :         param_.dstSize, GlobalParams::Instance().bufferSizeMap.at(param_.dstPos),
     135              :         "check dst tensor buffersize failed"));
     136            0 :     ASCENDC_CHECK(CheckBufferSizeOverFlow(
     137              :         param_.srcSize, GlobalParams::Instance().bufferSizeMap.at(param_.srcPos),
     138              :         "check src tensor buffersize failed"));
     139              :     // unit element
     140              :     int32_t dstLenElement;
     141            0 :     if (param_.dstDtypeBytes == 0) {
     142            0 :         CHECK_LOG_ERROR("dst dtype bytes is zeros");
     143            0 :         return false;
     144              :     }
     145            0 :     if (param_.repeatMode == 0) {
     146            0 :         dstLenElement = param_.repeatTime * BYTE_PER_FRACTAL / param_.dstDtypeBytes;
     147              :     } else {
     148            0 :         dstLenElement =
     149            0 :             ((param_.repeatTime - 1) * param_.jumpStride * BYTE_PER_FRACTAL + BYTE_PER_FRACTAL) / param_.dstDtypeBytes;
     150              :     }
     151            0 :     ASCENDC_CHECK(CheckTensorOverflowHigh(param_.dstDtypeBytes, param_.dstSize, dstLenElement, "dstLocal"));
     152            0 :     return true;
     153              : #endif
     154              : };
     155              : 
     156            0 : bool TikcppLoaddata3dv2Check::CheckAllHighLevel()
     157              : {
     158              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 2201) || (__NPU_ARCH__ == 3002) || (__NPU_ARCH__ == 3102) || \
     159              :                               (__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     160            0 :     if ((param_.srcPos == static_cast<uint8_t>(HardWareIndex::L1)) &&
     161            0 :         ((param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0A)) &&
     162            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0B)))) {
     163            0 :         CHECK_LOG_ERROR("check dst tensor position failed,"
     164              :                         "the src hardware pos is L1, the dst hardware pos support L0A or L0B.");
     165            0 :         return false;
     166              :     }
     167              : #elif defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 2002) || (__NPU_ARCH__ == 2201) || (__NPU_ARCH__ == 3002) || \
     168              :                                 (__NPU_ARCH__ == 3102) || (__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     169            0 :     if ((param_.srcPos == static_cast<uint8_t>(HardWareIndex::L1)) &&
     170            0 :         ((param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0A)) &&
     171            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0B)) &&
     172            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::UB)))) {
     173            0 :         CHECK_LOG_ERROR("check dst tensor position failed,"
     174              :                         "the src hardware pos is L1, the dst hardware pos support L0A or L0B or UB.");
     175            0 :         return false;
     176              :     }
     177              : #endif
     178            0 :     ASCENDC_CHECK(CheckTensorScope(param_.srcLogicPos, static_cast<uint8_t>(HardWareIndex::L1), "srcLocal", "A1/B1"));
     179              : 
     180            0 :     ASCENDC_CHECK(CheckBufferSizeOverFlow(
     181              :         param_.dstSize, GlobalParams::Instance().bufferSizeMap.at(param_.dstPos),
     182              :         "check dst tensor buffersize failed"));
     183            0 :     ASCENDC_CHECK(CheckBufferSizeOverFlow(
     184              :         param_.srcSize, GlobalParams::Instance().bufferSizeMap.at(param_.srcPos),
     185              :         "check src tensor buffersize failed"));
     186              :     // unit element
     187            0 :     int32_t dstLenElement = param_.mExtension * param_.kExtension;
     188            0 :     ASCENDC_CHECK(CheckTensorOverflowHigh(param_.dstDtypeBytes, param_.dstSize, dstLenElement, "dstLocal"));
     189            0 :     return true;
     190              : };
     191              : 
     192            0 : bool TikcppLoaddata3dv2ProCheck::CheckAllHighLevel()
     193              : {
     194              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 2201) || (__NPU_ARCH__ == 3002) || (__NPU_ARCH__ == 3102) || \
     195              :                               (__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     196            0 :     if ((param_.srcPos == static_cast<uint8_t>(HardWareIndex::L1)) &&
     197            0 :         ((param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0A)) &&
     198            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0B)))) {
     199            0 :         CHECK_LOG_ERROR("check dst tensor position failed,"
     200              :                         "the src hardware pos is L1, the dst hardware pos support L0A or L0B.");
     201            0 :         return false;
     202              :     }
     203              : #elif defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 2002) || (__NPU_ARCH__ == 2201) || (__NPU_ARCH__ == 3002) || \
     204              :                                 (__NPU_ARCH__ == 3102) || (__NPU_ARCH__ == 3510))
     205            0 :     if ((param_.srcPos == static_cast<uint8_t>(HardWareIndex::L1)) &&
     206            0 :         ((param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0A)) &&
     207            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::L0B)) &&
     208            0 :          (param_.dstPos != static_cast<uint8_t>(HardWareIndex::UB)))) {
     209            0 :         CHECK_LOG_ERROR("check dst tensor position failed,"
     210              :                         "the src hardware pos is L1, the dst hardware pos support L0A or L0B or UB.");
     211            0 :         return false;
     212              :     }
     213              : #endif
     214            0 :     ASCENDC_CHECK(CheckTensorScope(param_.srcLogicPos, static_cast<uint8_t>(HardWareIndex::L1), "srcLocal", "A1/B1"));
     215              : 
     216            0 :     ASCENDC_CHECK(CheckBufferSizeOverFlow(
     217              :         param_.dstSize, GlobalParams::Instance().bufferSizeMap.at(param_.dstPos),
     218              :         "check dst tensor buffersize failed"));
     219            0 :     ASCENDC_CHECK(CheckBufferSizeOverFlow(
     220              :         param_.srcSize, GlobalParams::Instance().bufferSizeMap.at(param_.srcPos),
     221              :         "check src tensor buffersize failed"));
     222              :     // unit element
     223            0 :     int32_t dstLenElement = param_.mExtension * param_.kExtension;
     224            0 :     ASCENDC_CHECK(CheckTensorOverflowHigh(param_.dstDtypeBytes, param_.dstSize, dstLenElement, "dstLocal"));
     225            0 :     return true;
     226              : };
     227              : 
     228            0 : bool TikcppLoadImageToLocalCheck::CheckAllHighLevel()
     229              : {
     230              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ != 3510) || (__NPU_ARCH__ == 5102))
     231            0 :     ASCENDC_CHECK(CheckTensorScope(param_.dstLogicPos, static_cast<uint8_t>(HardWareIndex::L1), "dstLocal", "A1/B1"));
     232              : #endif
     233            0 :     ASCENDC_CHECK(CheckTensorAddrAlign(param_.dstAddr, param_.dstPos, ONE_BLK_SIZE, "dst"));
     234              : 
     235            0 :     ASCENDC_CHECK(CheckBufferSizeOverFlow(
     236              :         param_.dstSize, GlobalParams::Instance().bufferSizeMap.at(param_.dstPos),
     237              :         "check dst tensor buffersize failed"));
     238            0 :     return true;
     239              : };
     240              : } // namespace check
     241              : } // namespace AscendC
        

Generated by: LCOV version 2.0-1