LCOV - code coverage report
Current view: top level - utils/include/utils - kernel_utils_constants.h (source / functions) Coverage Total Hit
Test: coverage.info_filtered Lines: 100.0 % 22 22
Test Date: 2026-07-27 14:41:20 Functions: 100.0 % 8 8

            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_utils_constants.h
      13              :  * \brief
      14              :  */
      15              : #ifndef ASCENDC_MODULE_UTILS_CONSTANTS_H
      16              : #define ASCENDC_MODULE_UTILS_CONSTANTS_H
      17              : #include "utils/kernel_utils_ceil_oom_que.h"
      18              : 
      19              : namespace AscendC {
      20              : const int32_t DEFAULT_BLK_NUM = 8;
      21              : const int32_t HALF_FACTOR = 2;
      22              : const int32_t DEFAULT_BLK_STRIDE = 1;
      23              : const uint8_t DEFAULT_REPEAT_STRIDE = 8;
      24              : const uint64_t FULL_MASK = 0xffffffffffffffff;
      25              : const uint64_t CONST_MASK_VALUE = 0x8000000000000000;
      26              : const uint16_t MAX_HALF_MASK_LEN = 64;
      27              : const int32_t DEFAULT_C0_SIZE = 32;
      28              : const int32_t DEFAULT_BLOCK_SIZE = 256;
      29              : const int32_t MAX_REPEAT_TIMES = 255;
      30              : const int32_t MIN_REPEAT_TIMES = 0;
      31              : const int32_t ONE_BYTE_BIT_SIZE = 8;
      32              : const uint32_t MAX_SLICE_SIZE = 6 * 256;
      33              : const uint16_t VALUE_512 = 512; // align with 512B / value range [0, 512]
      34              : 
      35              : // int4b_t param
      36              : constexpr uint32_t INT4_TWO = 2;
      37              : constexpr uint32_t INT4_BIT_NUM = 4;
      38              : 
      39              : #if (__NPU_ARCH__ == 5102)
      40              : // int2b_t param
      41              : constexpr uint32_t INT2_FOUR = 4;
      42              : constexpr uint32_t INT2_BIT_NUM = 2;
      43              : constexpr uint32_t INT1_BIT_NUM = 1;
      44              : #endif
      45              : 
      46              : #if defined(__NPU_ARCH__) && \
      47              :     ((__NPU_ARCH__ == 2103) || (__NPU_ARCH__ == 3003) || (__NPU_ARCH__ == 3103) || (__NPU_ARCH__ == 3113))
      48              : // int3b_t param
      49              : constexpr uint32_t INT3_BIT_NUM = 3;
      50              : // int2b_t param
      51              : constexpr uint32_t INT2_FOUR = 4;
      52              : constexpr uint32_t INT2_BIT_NUM = 2;
      53              : #endif
      54              : 
      55              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
      56              : namespace ConstantsInternal {
      57              : constexpr uint32_t ASCENDC_B4_TWO = 2;
      58              : constexpr uint32_t ASCENDC_B4_BIT_NUM = 4;
      59              : } // namespace ConstantsInternal
      60              : #endif
      61              : 
      62              : // AddDeqRelu param
      63              : constexpr int32_t DEQ_SHIFT_LEFT_17_BIT = 131072;
      64              : constexpr float DEQ_SHIFT_RIGHT_17_BIT = 1.0 / DEQ_SHIFT_LEFT_17_BIT;
      65              : constexpr int8_t ADDDEQRELU_MASK_MODE_ONE = 1;
      66              : constexpr int8_t ADDDEQRELU_MASK_MODE_TWO = 2;
      67              : 
      68              : #if (__NPU_ARCH__ == 5102)
      69              : const int32_t TOTAL_VEC_LOCAL_SIZE = 248 * 1024;
      70              : const uint32_t TOTAL_UB_SIZE = 248 * 1024;
      71              : const uint32_t TMP_UB_OFFSET = 248 * 1024;
      72              : const uint32_t TOTAL_L1_SIZE = 1024 * 1024;
      73              : const uint32_t SINGLE_MSG_SIZE = 64;
      74              : const uint32_t CACHE_LINE_SIZE = 64;
      75              : const uint32_t TOTAL_L0C_SIZE = 256 * 1024;
      76              : const uint32_t VECTOR_REG_WIDTH = 256;
      77              : const uint32_t VECTOR_REG_WIDTH_2XVL = 512;
      78              : const uint32_t ONE_BLOCK_SIZE = 32;
      79              : #elif defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 1001) || (__NPU_ARCH__ == 2002))
      80              : const int32_t TOTAL_VEC_LOCAL_SIZE = 248 * 1024;
      81              : const uint32_t TOTAL_UB_SIZE = 256 * 1024;
      82              : 
      83              : const uint32_t TMP_UB_OFFSET = 248 * 1024;
      84              : const uint32_t TOTAL_L1_SIZE = 1024 * 1024;
      85              : const uint32_t TOTAL_L0C_SIZE = 256 * 1024;
      86              : #elif defined(__NPU_ARCH__) && (__NPU_ARCH__ == 2103)
      87              : const int32_t TOTAL_VEC_LOCAL_SIZE = 112 * 1024;
      88              : const uint32_t TOTAL_UB_SIZE = 120 * 1024;
      89              : const uint32_t TMP_UB_OFFSET = 112 * 1024;
      90              : const uint32_t TOTAL_L1_SIZE = 1024 * 1024;
      91              : const uint32_t VECTOR_REG_WIDTH = 128;
      92              : const uint32_t ONE_BLOCK_SIZE = 32;
      93              : const uint32_t TOTAL_L0C_SIZE = 64 * 1024;
      94              : #elif (__NPU_ARCH__ == 2201)
      95              : const int32_t TOTAL_VEC_LOCAL_SIZE = 184 * 1024;
      96              : const uint32_t TOTAL_UB_SIZE = 192 * 1024;
      97              : const uint32_t TMP_UB_OFFSET = 184 * 1024;
      98              : #ifndef KFC_L1_RESERVER_SIZE
      99              : #define KFC_L1_RESERVER_SIZE 128
     100              : #endif
     101              : const uint32_t TOTAL_L1_SIZE = 512 * 1024 - KFC_L1_RESERVER_SIZE;
     102              : const uint32_t SINGLE_MSG_SIZE = 64;
     103              : const uint32_t CACHE_LINE_SIZE = 64;
     104              : const uint32_t TOTAL_L0C_SIZE = 128 * 1024;
     105              : #elif (__NPU_ARCH__ == 3002)
     106              : const int32_t TOTAL_VEC_LOCAL_SIZE = 184 * 1024;
     107              : const uint32_t TOTAL_UB_SIZE = 248 * 1024;
     108              : const uint32_t TMP_UB_OFFSET = 248 * 1024;
     109              : const uint32_t TOTAL_L1_SIZE = 1024 * 1024;
     110              : const uint32_t SINGLE_MSG_SIZE = 64;
     111              : const uint32_t CACHE_LINE_SIZE = 64;
     112              : const uint32_t TOTAL_L0C_SIZE = 128 * 1024;
     113              : const uint32_t VECTOR_REG_WIDTH = 256;
     114              : #elif defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3003)
     115              : const int32_t TOTAL_VEC_LOCAL_SIZE = 118 * 1024;
     116              : const uint32_t TOTAL_UB_SIZE = 118 * 1024;
     117              : const uint32_t TMP_UB_OFFSET = 118 * 1024;
     118              : const uint32_t TOTAL_L1_SIZE = 1024 * 1024;
     119              : const uint32_t VECTOR_REG_WIDTH = 256;
     120              : const uint32_t ONE_BLOCK_SIZE = 32;
     121              : const uint32_t TOTAL_L0C_SIZE = 128 * 1024;
     122              : #elif (__NPU_ARCH__ == 3102)
     123              : const int32_t TOTAL_VEC_LOCAL_SIZE = 184 * 1024;
     124              : const uint32_t TOTAL_UB_SIZE = 256 * 1024;
     125              : const uint32_t TMP_UB_OFFSET = 248 * 1024;
     126              : const uint32_t TOTAL_L1_SIZE = 1024 * 1024;
     127              : const uint32_t SINGLE_MSG_SIZE = 64;
     128              : const uint32_t CACHE_LINE_SIZE = 64;
     129              : const uint32_t TOTAL_L0C_SIZE = 128 * 1024;
     130              : const uint32_t VECTOR_REG_WIDTH = 256;
     131              : #elif (__NPU_ARCH__ == 3510)
     132              : const int32_t TOTAL_VEC_LOCAL_SIZE = 248 * 1024;
     133              : const uint32_t TOTAL_UB_SIZE = 248 * 1024;
     134              : const uint32_t TMP_UB_OFFSET = 248 * 1024;
     135              : const uint32_t TOTAL_L1_SIZE = 512 * 1024;
     136              : const uint32_t SINGLE_MSG_SIZE = 64;
     137              : const uint32_t CACHE_LINE_SIZE = 64;
     138              : const uint32_t TOTAL_L0C_SIZE = 256 * 1024;
     139              : const uint32_t VECTOR_REG_WIDTH = 256;
     140              : const uint32_t VECTOR_REG_WIDTH_2XVL = 512;
     141              : const uint32_t ONE_BLOCK_SIZE = 32;
     142              : #elif defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3113)
     143              : const int32_t TOTAL_VEC_LOCAL_SIZE = 118 * 1024;
     144              : const uint32_t TOTAL_UB_SIZE = 118 * 1024;
     145              : const uint32_t TMP_UB_OFFSET = 118 * 1024;
     146              : const uint32_t TOTAL_L1_SIZE = 512 * 1024;
     147              : const uint32_t TOTAL_L0C_SIZE = 64 * 1024;
     148              : const uint32_t VECTOR_REG_WIDTH = 256;
     149              : const uint32_t ONE_BLOCK_SIZE = 32;
     150              : #endif
     151              : 
     152              : #ifndef __NPU_HOST__
     153              : 
     154              : #ifndef ASCC_PARAM_BLOCK_CUBE
     155              : #define ASCC_PARAM_BLOCK_CUBE
     156              : const int32_t BLOCK_CUBE = 16;
     157              : #endif
     158              : 
     159              : #ifndef ASCC_PARAM_ONE_BLK_SIZE
     160              : #define ASCC_PARAM_ONE_BLK_SIZE
     161              : const uint16_t ONE_BLK_SIZE = 32;
     162              : #endif
     163              : 
     164              : #ifndef ASCC_PARAM_CUBE_MAX_SIZE
     165              : #define ASCC_PARAM_CUBE_MAX_SIZE
     166              : const int32_t CUBE_MAX_SIZE = 256;
     167              : #endif
     168              : 
     169              : #else // #ifdef __NPU_HOST__
     170              : 
     171              : #ifndef ASCC_PARAM_BLOCK_CUBE
     172              : #define ASCC_PARAM_BLOCK_CUBE
     173              : constexpr uint32_t BLOCK_CUBE = 16;
     174              : #endif
     175              : 
     176              : #ifndef ASCC_PARAM_ONE_BLK_SIZE
     177              : #define ASCC_PARAM_ONE_BLK_SIZE
     178              : constexpr uint32_t ONE_BLK_SIZE = 32;
     179              : #endif
     180              : 
     181              : #ifndef ASCC_PARAM_CUBE_MAX_SIZE
     182              : #define ASCC_PARAM_CUBE_MAX_SIZE
     183              : constexpr int32_t CUBE_MAX_SIZE = 256;
     184              : #endif
     185              : 
     186              : #endif // __NPU_HOST__
     187              : const uint8_t PAD_SIZE = 4;
     188              : const uint8_t MRG_SORT_ELEMENT_LEN = 4;
     189              : const uint8_t DEFAULT_DATA_COPY_NBURST = 1;
     190              : const uint8_t DEFAULT_DATA_COPY_STRIDE = 0;
     191              : const int32_t BYTE_PER_FRACTAL = 512;
     192              : const int32_t SRC_BURST_LEN_SIZE_ELE = 16;
     193              : const int32_t SRC_GAP_SIZE_BYTE = 32;
     194              : const int32_t DST_BURST_LEN_SIZE_ELE = 256;
     195              : const int32_t VREDUCE_PER_REP_OUTPUT = 2;
     196              : const uint16_t ONE_PARAM_SIZE = 8;
     197              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     198              : const uint16_t AIV_CORE_NUM = 72;
     199              : #else
     200              : const uint16_t AIV_CORE_NUM = 50;
     201              : #endif
     202              : const uint16_t DUMP_MSG_HEAD_SIZE = 24;
     203              : #if defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3103)
     204              : const int32_t ONE_REPEAT_BYTE_SIZE = 128;
     205              : #else
     206              : const int32_t ONE_REPEAT_BYTE_SIZE = 256;
     207              : #endif
     208              : const int32_t FULL_MASK_LEN = 128;
     209              : const int32_t HLAF_MASK_LEN = 64;
     210              : const int32_t DEFAULT_REDUCE_DST_REP_SRIDE = 1;
     211              : const uint8_t B64_BYTE_SIZE = 8;
     212              : const uint8_t B32_BYTE_SIZE = 4;
     213              : const uint8_t B16_BYTE_SIZE = 2;
     214              : const uint8_t B8_BYTE_SIZE = 1;
     215              : const uint8_t B32_DATA_NUM_PER_BLOCK = 8;
     216              : const uint8_t B16_DATA_NUM_PER_BLOCK = 16;
     217              : #if defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3103)
     218              : const int32_t B16_DATA_NUM_PER_REPEAT = 64;
     219              : const int32_t B32_DATA_NUM_PER_REPEAT = 32;
     220              : #else
     221              : const int32_t B16_DATA_NUM_PER_REPEAT = 128;
     222              : const int32_t B32_DATA_NUM_PER_REPEAT = 64;
     223              : #endif
     224              : 
     225              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     226              : const uint32_t B64_DATA_NUM_PER_REPEAT = 32;
     227              : const uint32_t B4_BYTE_SIZE_PER_REPEAT = 64;
     228              : const uint32_t L1_DUMP_UB_SIZE = TOTAL_UB_SIZE - 32 * 1024;
     229              : #endif
     230              : 
     231              : const int32_t BLOCK_STRIDE_POS_IN_SM = 16;
     232              : const int32_t PLD_BUFFER_SIZE = 2;
     233              : const uint8_t FIXPIPE_DEQ_TENSOR_SIZE = 16;
     234              : const uint8_t SET_DATA_EXP_ZERO = 0;
     235              : const uint8_t SET_DATA_EXP_ONE = 1;
     236              : const uint8_t SET_DATA_EXP_TWO = 2;
     237              : const uint8_t SET_DATA_EXP_THREE = 3;
     238              : const uint8_t VDEQ_TENSOR_SIZE = 16;
     239              : // workspace system reserve 16MB
     240              : #if (__NPU_ARCH__ == 1001)
     241              : constexpr size_t RESERVED_WORKSPACE = 2 * 1024 * 1024;
     242              : #elif (__NPU_ARCH__ == 2002)
     243              : constexpr size_t RESERVED_WORKSPACE = 2 * 1024 * 1024;
     244              : #elif (__NPU_ARCH__ == 2201)
     245              : constexpr size_t RESERVED_WORKSPACE = 16 * 1024 * 1024;
     246              : #elif (__NPU_ARCH__ == 3002)
     247              : constexpr size_t RESERVED_WORKSPACE = 16 * 1024 * 1024;
     248              : #elif (__NPU_ARCH__ == 3102)
     249              : constexpr size_t RESERVED_WORKSPACE = 16 * 1024 * 1024;
     250              : #elif defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     251              : constexpr size_t RESERVED_WORKSPACE = 16 * 1024 * 1024;
     252              : #elif defined(__NPU_ARCH__) && (__NPU_ARCH__ == 2103)
     253              : constexpr size_t RESERVED_WORKSPACE = 16 * 1024 * 1024;
     254              : #elif defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3003)
     255              : constexpr size_t RESERVED_WORKSPACE = 0;
     256              : #elif defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3103) || (__NPU_ARCH__ == 3113))
     257              : constexpr size_t RESERVED_WORKSPACE = 0;
     258              : #endif
     259              : 
     260              : // nchwconv address list size
     261              : const int32_t NCHW_CONV_ADDR_LIST_SIZE = 16;
     262              : const int32_t VA_REG_ARRAY_LEN = 8;
     263              : const uint8_t CONV2D_IMG_SIZE = 2;
     264              : const uint8_t CONV2D_KERNEL_SIZE = 2;
     265              : const uint8_t CONV2D_STRIDE = 2;
     266              : const uint8_t CONV2D_PAD = 4;
     267              : const uint8_t CONV2D_DILATION = 2;
     268              : const int32_t K_MAX_DIM = 8;
     269              : 
     270              : const uint32_t TWO_OF_STACK_BUFFER = 2;
     271              : const uint32_t THREE_OF_STACK_BUFFER = 3;
     272              : const uint32_t HALF_REPEAT_SIZE = ONE_REPEAT_BYTE_SIZE / B16_BYTE_SIZE;
     273              : const uint32_t FLOAT_REPEAT_SIZE = ONE_REPEAT_BYTE_SIZE / B32_BYTE_SIZE;
     274              : const uint32_t ONE_REPEAT_FLOAT_SIZE = ONE_REPEAT_BYTE_SIZE / B32_BYTE_SIZE;
     275              : const uint32_t ONE_REPEAT_HALF_SIZE = ONE_REPEAT_BYTE_SIZE / B16_BYTE_SIZE;
     276              : const uint32_t MAX_REPEAT_FLOAT_SIZE = ONE_REPEAT_FLOAT_SIZE * MAX_REPEAT_TIMES;
     277              : const uint32_t MAX_REPEAT_HALF_SIZE = ONE_REPEAT_HALF_SIZE * MAX_REPEAT_TIMES;
     278              : const uint32_t ONE_BLK_HALF_NUM = ONE_BLK_SIZE / B16_BYTE_SIZE;
     279              : const uint32_t ONE_BLK_FLOAT_NUM = ONE_BLK_SIZE / B32_BYTE_SIZE;
     280              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     281              : namespace ConstantsInternal {
     282              : const uint32_t ONE_BLK_FP4_NUM = 64;
     283              : const uint32_t ONE_BLK_B2_NUM = 128;
     284              : } // namespace ConstantsInternal
     285              : #endif
     286              : const uint32_t BRCB_BROADCAST_NUMBER = 8;
     287              : const uint32_t BRCB_MAX_REPEAT_SIZE = BRCB_BROADCAST_NUMBER * MAX_REPEAT_TIMES;
     288              : const int32_t MIN_BLOCK_LEN = 1;
     289              : const uint32_t PAIR_REDUCE_REPEAT_STRIDE_LEN = 128;
     290              : const uint32_t PAIR_REDUCE_SUM_MERGES = 2;
     291              : const uint32_t TWO_HUNDRED_FIFTY_TWO_REPEAT = 252;
     292              : const uint32_t TWO_HUNDRED_FIFTY_TWO_REPEAT_BYTE_SIZE = TWO_HUNDRED_FIFTY_TWO_REPEAT * ONE_REPEAT_BYTE_SIZE;
     293              : const uint32_t REDUCEV2_MODE_SEVEN = 7;
     294              : const uint32_t DROPOUT_MODE_BYTE_MISALIGN = 1;
     295              : const uint32_t DROPOUT_MODE_BYTE_ALIGN = 2;
     296              : const uint32_t DROPOUT_MODE_BIT_ALIGN = 3;
     297              : const uint32_t DROPOUT_MODE_BIT_MISALIGN = 4;
     298              : const uint32_t REDUCEV2_MODE_ONE = 1;
     299              : const uint32_t REDUCEV2_MODE_TWO = 2;
     300              : const uint32_t REDUCEV2_MODE_THREE = 3;
     301              : 
     302              : // 4dTrans param size
     303              : const int32_t B8_TMP_ELE_LEN = 1024;
     304              : const int32_t B16_TMP_ELE_LEN = 256;
     305              : const int32_t B32_TMP_ELE_LEN = 128;
     306              : const int32_t B8_TRANS_LEN = 1024;
     307              : const int32_t B8_TRANS_FRACTAL = 512;
     308              : const int32_t B8_TRANS_ROW = 32;
     309              : const int32_t B8_COPY_COL = 32;
     310              : 
     311              : // load3dPro config
     312              : const uint64_t LOAD_M_START_POSITION = 48;
     313              : const uint64_t LOAD_K_START_POSITION = 32;
     314              : const uint64_t LOAD_M_EXTENSION = 16;
     315              : const uint64_t LOAD_DILATION_FILTER_H = 40;
     316              : const uint64_t LOAD_DILATION_FILTER_W = 32;
     317              : const uint64_t LOAD_FILTER_H = 24;
     318              : const uint64_t LOAD_FILTER_W = 16;
     319              : const uint64_t LOAD_STRIDE_H = 8;
     320              : 
     321              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     322              : namespace Internal {
     323              : constexpr int32_t TSCM_CROSS_SYNC_ID_MAX = 11;
     324              : }
     325              : #endif
     326              : 
     327              : #if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 1
     328              : // param check size
     329              : const int32_t MAX_BLOCK_COUNT = 4095;
     330              : const int32_t MIN_BLOCK_COUNT = 1;
     331              : const int32_t MAX_BLOCK_LEN = 65535;
     332              : 
     333              : const int32_t MAX_16BITS_STRIDE = 65535;
     334              : const int32_t MAX_8BITS_STRIDE = 255;
     335              : const int32_t MIN_BLOCK_NUM = 1;
     336              : const int32_t MAX_PROPOSAL_MODE_NUM = 5;
     337              : const int32_t MIN_PROPOSAL_MODE_NUM = 0;
     338              : 
     339              : // load2d param size
     340              : const int32_t MAX_LOAD2D_START_INDEX = 65535;
     341              : const int32_t MIN_LOAD2D_START_INDEX = 0;
     342              : const int32_t MAX_LOAD2D_SID = 15;
     343              : const int32_t MIN_LOAD2D_SID = 0;
     344              : 
     345              : // load3dv1 param size
     346              : const int32_t MAX_LOAD3D_PAD = 255;
     347              : const int32_t MIN_LOAD3D_PAD = 0;
     348              : const int32_t MAX_LOAD3D_L1 = 32767;
     349              : const int32_t MIN_LOAD3D_L1 = 1;
     350              : const int32_t MAX_LOAD3D_C1_IDX = 4095;
     351              : const int32_t MIN_LOAD3D_C1_IDX = 0;
     352              : const int32_t MAX_LOAD3D_LEFT_TOP = 32767;
     353              : const int32_t MIN_LOAD3D_LEFT_TOP = -255;
     354              : const int32_t MAX_LOAD3D_STRIDE = 63;
     355              : const int32_t MIN_LOAD3D_STRIDE = 1;
     356              : const int32_t MAX_LOAD3D_FILTER = 255;
     357              : const int32_t MIN_LOAD3D_FILTER = 1;
     358              : const int32_t MIN_LOAD3D_FETCH_FILTER = 0;
     359              : const int32_t MAX_LOAD3D_FETCH_FILTER = 254;
     360              : const int32_t MIN_LOAD3D_DILATION_FILTER = 1;
     361              : const int32_t MAX_LOAD3D_JUMP_STRIDE = 127;
     362              : const int32_t MIN_LOAD3D_JUMP_STRIDE = 1;
     363              : const int32_t MAX_LOAD3D_REPEAT_MODE = 1;
     364              : const int32_t MIN_LOAD3D_REPEAT_MODE = 0;
     365              : const int32_t MIN_LOAD3D_REPEAT_TIMES = 1;
     366              : const int32_t MAX_LOAD3D_CSIZE = 1;
     367              : const int32_t MIN_LOAD3D_CSIZE = 0;
     368              : 
     369              : // load3dv2 param size
     370              : const int32_t MAX_LOAD3D_CHANNEL_SIZE = 65535;
     371              : const int32_t MIN_LOAD3D_CHANNEL_SIZE = 1;
     372              : const int32_t MAX_LOAD3D_EXTENSION = 65535;
     373              : const int32_t MIN_LOAD3D_EXTENSION = 1;
     374              : const int32_t MAX_LOAD3D_START_PT = 65535;
     375              : const int32_t MIN_LOAD3D_START_PT = 0;
     376              : const int32_t KEXTENSION_HALF = 16;
     377              : const int32_t MEXTENSION_HALF = 16;
     378              : const int32_t KSTARTPT_HALF = 16;
     379              : const int32_t MSTARTPT_HALF = 16;
     380              : const int32_t KEXTENSION_B8 = 32;
     381              : const int32_t MEXTENSION_B8 = 16;
     382              : const int32_t KSTARTPT_B8 = 32;
     383              : const int32_t MSTARTPT_B8 = 16;
     384              : 
     385              : // loadImageToLocal param size
     386              : constexpr int32_t MAX_LOADIMANG_L1_HORSIZE = 4095;
     387              : constexpr int32_t MIN_LOADIMANG_L1_HORSIZE = 1;
     388              : constexpr int32_t MAX_LOADIMANG_L1_VERSIZE = 4095;
     389              : constexpr int32_t MIN_LOADIMANG_L1_VERSIZE = 0;
     390              : constexpr int32_t MAX_LOADIMANG_L1_HWSTART = 4095;
     391              : constexpr int32_t MIN_LOADIMANG_L1_HWSTART = 0;
     392              : constexpr int32_t MAX_LOADIMANG_L1_SHORRES = 65535;
     393              : constexpr int32_t MIN_LOADIMANG_L1_SHORRES = 1;
     394              : constexpr int32_t MIN_LOADIMANG_L1_PADSIZE = 0;
     395              : 
     396              : // mmad param size
     397              : const int32_t MAX_M_K_N_SIZE = 4095;
     398              : const int32_t MIN_M_K_N_SIZE = 0;
     399              : 
     400              : // mrgsort4 param size
     401              : const int32_t MAX_SORT_ELE_LEN = 4095;
     402              : const int32_t MIN_SORT_ELE_LEN = 0;
     403              : const int32_t MIN_SORT_REPEAT_TIMES = 1;
     404              : namespace Internal {
     405              : constexpr uint8_t REGION_PROPOSAL_ELEMENT_NUM = 8;
     406              : }
     407              : 
     408              : template <typename T>
     409              : std::string ScalarToString(T scalarValue);
     410              : template <>
     411            4 : inline std::string ScalarToString(half scalarValue)
     412              : {
     413            4 :     return std::to_string(scalarValue.ToFloat());
     414              : }
     415              : #if defined(__NPU_ARCH__) && \
     416              :     ((__NPU_ARCH__ == 2201) || (__NPU_ARCH__ == 3002) || (__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     417              : template <>
     418              : inline std::string ScalarToString(bfloat16_t scalarValue)
     419              : {
     420              :     return std::to_string(scalarValue.ToFloat());
     421              : }
     422              : #endif
     423              : template <typename T>
     424              : uint64_t GetScalarBitcode(T scalarValue);
     425              : // deq tensor ptr could not be passed by cce instructions, so pass ptr to model by this function
     426              : void SetModelDeqTensor(void* deqTensor);
     427              : #if __NPU_ARCH__ == 3002
     428              : void SetEleSrcPara(uint64_t baseAddr);
     429              : #endif
     430              : #if __NPU_ARCH__ == 2002
     431              : void SetVbiSrc0Param(half* vbiSrc0Ptr, int32_t vbiSrc0Size);
     432              : void SetUnzipCompressedLen(uint32_t compressedLength);
     433              : #endif
     434              : void SetModelBiasTensor(void* biasTensor);
     435              : void SetIndexMatrix(void* indexMatrix);
     436              : 
     437              : // src0 of gatherb instr could not be accessed by cce instructions, so pass ptr to model by this function
     438              : void SetModelGatherbSrc0Tensor(uint64_t src0, const uint32_t length);
     439              : 
     440              : // dst0 of scatter instr could not be accessed by cce instructions, so pass ptr to model by this function
     441              : void SetModelScatterDst0Tensor(uint64_t dst0, const uint32_t length);
     442              : 
     443              : #endif // ASCENDC_CPU_DEBUG
     444              : 
     445              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     446              : template <typename T>
     447              : struct GetPadValueType {
     448              :     using Type = T;
     449              : };
     450              : 
     451              : // To support FP8 datacopypad, pad type needs transfer to b8
     452              : template <>
     453              : struct GetPadValueType<fp8_e5m2_t> {
     454              :     using Type = uint8_t;
     455              : };
     456              : 
     457              : template <>
     458              : struct GetPadValueType<fp8_e4m3fn_t> {
     459              :     using Type = uint8_t;
     460              : };
     461              : 
     462              : template <>
     463              : struct GetPadValueType<fp8_e8m0_t> {
     464              :     using Type = uint8_t;
     465              : };
     466              : 
     467              : template <>
     468              : struct GetPadValueType<hifloat8_t> {
     469              :     using Type = uint8_t;
     470              : };
     471              : 
     472              : // To support FP4 datacopypad, pad type needs transfer to b8
     473              : template <>
     474              : struct GetPadValueType<fp4x2_e1m2_t> {
     475              :     using Type = uint8_t;
     476              : };
     477              : 
     478              : template <>
     479              : struct GetPadValueType<fp4x2_e2m1_t> {
     480              :     using Type = uint8_t;
     481              : };
     482              : #endif
     483              : 
     484              : template <bool condition, class T1, class T2>
     485              : struct Conditional {
     486              :     using type = T1;
     487              : };
     488              : 
     489              : template <class T1, class T2>
     490              : struct Conditional<false, T1, T2> {
     491              :     using type = T2;
     492              : };
     493              : 
     494              : template <int bitNum, bool sign = true>
     495              : struct IntegerSubType {
     496              :     static int const kBits = bitNum;
     497              :     static bool const kSigned = sign;
     498              : 
     499              :     using T = typename Conditional<kSigned, int8_t, uint8_t>::type;
     500              :     using Storage = uint8_t;
     501              : 
     502              :     static Storage const mask = Storage(((static_cast<uint64_t>(1)) << static_cast<uint32_t>(kBits)) - 1);
     503              :     Storage storage;
     504              :     __aicore__ inline IntegerSubType() = default;
     505              : 
     506              :     __aicore__ inline IntegerSubType(uint32_t value) : storage(reinterpret_cast<Storage const&>(value) & mask) {}
     507              : 
     508           76 :     __aicore__ inline IntegerSubType(int32_t value) : storage(reinterpret_cast<Storage const&>(value) & mask) {}
     509              : 
     510            8 :     __aicore__ inline operator T() const
     511              :     {
     512            8 :         if (kSigned && ((storage & Storage(static_cast<uint64_t>(1) << static_cast<uint32_t>(kBits - 1))) != 0)) {
     513              :             // Sign extend
     514            4 :             return T(storage) | ~T(mask);
     515              :         }
     516            4 :         return T(storage);
     517              :     }
     518              : 
     519            8 :     __aicore__ inline bool operator==(IntegerSubType const& rhs) const { return storage == rhs.storage; }
     520              : 
     521              :     __aicore__ inline bool operator!=(IntegerSubType const& rhs) const { return storage != rhs.storage; }
     522              : 
     523           28 :     __aicore__ inline bool operator>(IntegerSubType const& rhs) const
     524              :     {
     525           28 :         bool lhsIsNeg = (this->storage & (static_cast<uint64_t>(1) << static_cast<uint32_t>(this->kBits - 1)));
     526           28 :         bool rhsIsNeg = (rhs.storage & (static_cast<uint64_t>(1) << static_cast<uint32_t>(rhs.kBits - 1)));
     527           28 :         if (kSigned && (lhsIsNeg != rhsIsNeg)) {
     528           12 :             return (!lhsIsNeg) && rhsIsNeg;
     529              :         }
     530           16 :         return this->storage > rhs.storage;
     531              :     }
     532              : 
     533           32 :     __aicore__ inline bool operator>=(IntegerSubType const& rhs) const
     534              :     {
     535           32 :         bool lhsIsNeg = (this->storage & (static_cast<uint64_t>(1) << static_cast<uint32_t>(this->kBits - 1)));
     536           32 :         bool rhsIsNeg = (rhs.storage & (static_cast<uint64_t>(1) << static_cast<uint32_t>(rhs.kBits - 1)));
     537           32 :         if (kSigned && (lhsIsNeg != rhsIsNeg)) {
     538           12 :             return (!lhsIsNeg) && rhsIsNeg;
     539              :         }
     540           20 :         return storage >= rhs.storage;
     541              :     }
     542              : 
     543           16 :     __aicore__ inline bool operator<(IntegerSubType const& rhs) const { return !(*this >= rhs); }
     544              : 
     545           16 :     __aicore__ inline bool operator<=(IntegerSubType const& rhs) const { return !(*this > rhs); }
     546              : };
     547              : 
     548              : using int4b_t = IntegerSubType<INT4_BIT_NUM, true>;
     549              : 
     550              : #if (__NPU_ARCH__ == 5102)
     551              : using int2b_t = IntegerSubType<INT2_BIT_NUM, true>;
     552              : #endif
     553              : 
     554              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     555              : using mx_fp8_e5m2_t = struct {};
     556              : using mx_fp8_e4m3_t = struct {};
     557              : using mx_fp8_e8m0_t = struct {};
     558              : 
     559              : template <typename T>
     560              : struct GetDstType {
     561              :     using Type = T;
     562              : };
     563              : 
     564              : template <>
     565              : struct GetDstType<mx_fp8_e5m2_t> {
     566              :     using Type = fp8_e5m2_t;
     567              : };
     568              : 
     569              : template <>
     570              : struct GetDstType<mx_fp8_e4m3_t> {
     571              :     using Type = fp8_e4m3fn_t;
     572              : };
     573              : 
     574              : template <>
     575              : struct GetDstType<mx_fp8_e8m0_t> {
     576              :     using Type = fp8_e8m0_t;
     577              : };
     578              : #endif
     579              : 
     580              : } // namespace AscendC
     581              : #endif // ASCENDC_MODULE_UTILS_CONSTANTS_H
        

Generated by: LCOV version 2.0-1