LCOV - code coverage report
Current view: top level - extern_include - metadef_types.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 87.5 % 8 7
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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 AICPU_SD_EXTERNAL_GRAPH_METADEF_TYPES_H_
      12              : #define AICPU_SD_EXTERNAL_GRAPH_METADEF_TYPES_H_
      13              : 
      14              : #include <cstdint>
      15              : 
      16              : namespace ge {
      17              : using char_t = char;
      18              : using float32_t = float;
      19              : using float64_t = double;
      20              : 
      21              : // When data type unit is bit, this offset need to be added.
      22              : static constexpr int32_t kDataTypeSizeBitOffset = 1000;
      23              : static constexpr uint32_t kBitNumOfOneByte = 8U;
      24              : 
      25              : enum DataType {
      26              :   DT_FLOAT = 0,
      27              :   DT_FLOAT16 = 1,
      28              :   DT_INT8 = 2,
      29              :   DT_INT32 = 3,
      30              :   DT_UINT8 = 4,
      31              :   // 5 reserved
      32              :   DT_INT16 = 6,
      33              :   DT_UINT16 = 7,
      34              :   DT_UINT32 = 8,
      35              :   DT_INT64 = 9,
      36              :   DT_UINT64 = 10,
      37              :   DT_DOUBLE = 11,
      38              :   DT_BOOL = 12,
      39              :   DT_STRING = 13,
      40              :   DT_DUAL_SUB_INT8 = 14,
      41              :   DT_DUAL_SUB_UINT8 = 15,
      42              :   DT_COMPLEX64 = 16,
      43              :   DT_COMPLEX128 = 17,
      44              :   DT_QINT8 = 18,
      45              :   DT_QINT16 = 19,
      46              :   DT_QINT32 = 20,
      47              :   DT_QUINT8 = 21,
      48              :   DT_QUINT16 = 22,
      49              :   DT_RESOURCE = 23,
      50              :   DT_STRING_REF = 24,
      51              :   DT_DUAL = 25,
      52              :   DT_VARIANT = 26,
      53              :   DT_BF16 = 27,
      54              :   DT_UNDEFINED = 28,
      55              :   DT_INT4 = 29,
      56              :   DT_UINT1 = 30,
      57              :   DT_INT2 = 31,
      58              :   DT_UINT2 = 32,
      59              :   DT_COMPLEX32 = 33,
      60              :   DT_HIFLOAT8 = 34,
      61              :   DT_FLOAT8_E5M2 = 35,
      62              :   DT_FLOAT8_E4M3FN = 36,
      63              :   DT_FLOAT8_E8M0 = 37,
      64              :   DT_FLOAT6_E3M2 = 38,
      65              :   DT_FLOAT6_E2M3 = 39,
      66              :   DT_FLOAT4_E2M1 = 40,
      67              :   DT_FLOAT4_E1M2 = 41,
      68              :   DT_HIFLOAT4 = 42,
      69              :   DT_MAX = 43,
      70              : };
      71              : 
      72           42 : inline int GetSizeByDataType(DataType data_type) {
      73              :   static int data_type_size[DT_MAX] = {
      74              :       4,                           // DT_FLOAT = 0,             float type
      75              :       2,                           // DT_FLOAT16 = 1,           fp16 type
      76              :       1,                           // DT_INT8 = 2,              int8 type
      77              :       4,                           // DT_INT32 = 3,             int32 type
      78              :       1,                           // DT_UINT8 = 4,             uint8 type
      79              :       -1,                          // reserved
      80              :       2,                           // DT_INT16 = 6,             int16 type
      81              :       2,                           // DT_UINT16 = 7,            uint16 type
      82              :       4,                           // DT_UINT32 = 8,            unsigned int32
      83              :       8,                           // DT_INT64 = 9,             int64 type
      84              :       8,                           // DT_UINT64 = 10,           unsigned int64
      85              :       8,                           // DT_DOUBLE = 11,           double type
      86              :       1,                           // DT_BOOL = 12,             bool type
      87              :       -1,                          // DT_STRING = 13,           string type
      88              :       1,                           // DT_DUAL_SUB_INT8 = 14,    dual output int8 type
      89              :       1,                           // DT_DUAL_SUB_UINT8 = 15,   dual output uint8 type
      90              :       8,                           // DT_COMPLEX64 = 16,        complex64 type
      91              :       16,                          // DT_COMPLEX128 = 17,       complex128 type
      92              :       1,                           // DT_QINT8 = 18,            qint8 type
      93              :       2,                           // DT_QINT16 = 19,           qint16 type
      94              :       4,                           // DT_QINT32 = 20,           qint32 type
      95              :       1,                           // DT_QUINT8 = 21,           quint8 type
      96              :       2,                           // DT_QUINT16 = 22,          quint16 type
      97              :       8,                           // DT_RESOURCE = 23,         resource type
      98              :       -1,                          // DT_STRING_REF = 24,       string ref type
      99              :       5,                           // DT_DUAL = 25,             dual output type (float + int8)
     100              :       8,                           // DT_VARIANT                variant type
     101              :       2,                           // DT_BF16 = 27,             bf16 type
     102              :       -1,                          // DT_UNDEFINED = 28         Used to indicate a DataType field has not been set.
     103              :       kDataTypeSizeBitOffset + 4,  // DT_INT4 = 29,             int4 type
     104              :       kDataTypeSizeBitOffset + 1,  // DT_UINT1 = 30,            uint1 type
     105              :       kDataTypeSizeBitOffset + 2,  // DT_INT2 = 31,             int2 type
     106              :       kDataTypeSizeBitOffset + 2,  // DT_UINT2 = 32,            uint2 type
     107              :       4,                           // DT_COMPLEX32 = 33,        complex32 type
     108              :       1,                           // DT_HIFLOAT8,              hifloat8 type
     109              :       1,                           // DT_FLOAT8_E5M2,           float8_e5m2 type
     110              :       1,                           // DT_FLOAT8_E4M3FN,         float8_e4m3fn type
     111              :       1,                           // DT_FLOAT8_E8M0,           float8_e8m0 type
     112              :       kDataTypeSizeBitOffset + 6,  // DT_FLOAT6_E3M2,           float6_e3m2 type, 6bit
     113              :       kDataTypeSizeBitOffset + 6,  // DT_FLOAT6_E2M3,           float6_e2m3 type, 6bit
     114              :       kDataTypeSizeBitOffset + 4,  // DT_FLOAT4_E2M1,           float4_e2m1 type, 4bit
     115              :       kDataTypeSizeBitOffset + 4,  // DT_FLOAT4_E1M2,           float4_e1m2 type, 4bit
     116              :       kDataTypeSizeBitOffset + 4,  // DT_HIFLOAT4,              hifloat4 type, 4bit
     117              :                                    // DT_MAX
     118              :   };
     119           42 :   if ((data_type < 0) || (data_type >= DT_MAX)) {
     120            0 :     return -1;
     121              :   }
     122           42 :   return data_type_size[data_type];
     123              : }
     124              : 
     125          182 : inline int32_t GetPrimaryFormat(int32_t format) {
     126          182 :   return static_cast<int32_t>(static_cast<uint32_t>(format) & 0xffU);
     127              : }
     128              : 
     129           99 : inline int32_t GetSubFormat(int32_t format) {
     130           99 :   return static_cast<int32_t>((static_cast<uint32_t>(format) & 0xffff00U) >> kBitNumOfOneByte);
     131              : }
     132              : 
     133              : }  // namespace ge
     134              : 
     135              : #endif  // AICPU_SD_EXTERNAL_GRAPH_METADEF_TYPES_H_
        

Generated by: LCOV version 2.0-1