Merged
feat: 支持 DT_HIFLOAT4_SCALE 数据类型 #4737
shangdfAdd on Sep 4
feat: 支持 DT_HIFLOAT4_SCALE 数据类型 #4737
Merged
Merged fromshangdf/gefeature/hifloat4-scale-datatypeintocann/gedevelop
Total: 23 files changed+174-121
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <memory> | 16 | #include <memory> |
| 17 | 17 | ||
| 18 | #include "framework/common/debug/log.h" | 18 | #include "framework/common/debug/log.h" |
| 19 | +#include "framework/common/output_type_map.h" | ||
| 19 | #include "common/plugin/ge_make_unique_util.h" | 20 | #include "common/plugin/ge_make_unique_util.h" |
| 20 | #include "framework/common/helper/model_helper.h" | 21 | #include "framework/common/helper/model_helper.h" |
| 21 | #include "common/helper/model_parser_base.h" | 22 | #include "common/helper/model_parser_base.h" |
| @@ -79,13 +80,6 @@ void UpdateOutputTypeNameAndIndex(std::string &node_name, std::string &index_str | |||
| 79 | const std::set<std::string> kOmBlackFields = {"output", "data_offset", "data", "workspace", "workspace_bytes", | 80 | const std::set<std::string> kOmBlackFields = {"output", "data_offset", "data", "workspace", "workspace_bytes", |
| 80 | "memory_size", "weight_size", "size", "bt", "quantize_factor"}; | 81 | "memory_size", "weight_size", "size", "bt", "quantize_factor"}; |
| 81 | 82 | ||
| 82 | -static std::map<std::string, ge::DataType> output_type_str_to_datatype = { | ||
| 83 | - {"FP32", ge::DT_FLOAT}, {"FP16", ge::DT_FLOAT16}, | ||
| 84 | - {"UINT8", ge::DT_UINT8}, {"INT8", ge::DT_INT8}, | ||
| 85 | - {"HIF8", ge::DT_HIFLOAT8}, {"HIF4", ge::DT_HIFLOAT4}, | ||
| 86 | - {"FP8E5M2", ge::DT_FLOAT8_E5M2}, {"FP8E4M3FN", ge::DT_FLOAT8_E4M3FN}, | ||
| 87 | -}; | ||
| 88 | - | ||
| 89 | static bool CheckInputTrueOrFalse(const std::string &s, const std::string &atc_param) { | 83 | static bool CheckInputTrueOrFalse(const std::string &s, const std::string &atc_param) { |
| 90 | if ((s == "true") || (s == "false")) { | 84 | if ((s == "true") || (s == "false")) { |
| 91 | return true; | 85 | return true; |
| @@ -341,6 +335,7 @@ domi::Status VerifyOutputTypeAndOutNodes(std::vector<std::string> &out_type_vec) | |||
| 341 | } | 335 | } |
| 342 | 336 | ||
| 343 | domi::Status CheckOutPutDataTypeSupport(const std::string &output_type) { | 337 | domi::Status CheckOutPutDataTypeSupport(const std::string &output_type) { |
| 338 | + const auto &output_type_str_to_datatype = ge::OutputTypeStrToDatatype(); | ||
| 344 | std::map<std::string, ge::DataType>::const_iterator it = output_type_str_to_datatype.find(output_type); | 339 | std::map<std::string, ge::DataType>::const_iterator it = output_type_str_to_datatype.find(output_type); |
| 345 | if (it == output_type_str_to_datatype.cend()) { | 340 | if (it == output_type_str_to_datatype.cend()) { |
| 346 | REPORT_PREDEFINED_ERR_MSG("E10001", std::vector<const char *>({"parameter", "value", "reason"}), | 341 | REPORT_PREDEFINED_ERR_MSG("E10001", std::vector<const char *>({"parameter", "value", "reason"}), |
| @@ -378,6 +373,7 @@ domi::Status ParseOutputType(const std::string &output_type, | |||
| 378 | return FAILED; | 373 | return FAILED; |
| 379 | } | 374 | } |
| 380 | std::string dt_value = StringUtils::Trim(node_index_type_v[kDTValueIndex]); | 375 | std::string dt_value = StringUtils::Trim(node_index_type_v[kDTValueIndex]); |
| 376 | + const auto &output_type_str_to_datatype = ge::OutputTypeStrToDatatype(); | ||
| 381 | std::map<std::string, ge::DataType>::const_iterator it = output_type_str_to_datatype.find(dt_value); | 377 | std::map<std::string, ge::DataType>::const_iterator it = output_type_str_to_datatype.find(dt_value); |
| 382 | if (it == output_type_str_to_datatype.cend()) { | 378 | if (it == output_type_str_to_datatype.cend()) { |
| 383 | REPORT_PREDEFINED_ERR_MSG("E10001", std::vector<const char *>({"parameter", "value", "reason"}), | 379 | REPORT_PREDEFINED_ERR_MSG("E10001", std::vector<const char *>({"parameter", "value", "reason"}), |
| @@ -58,7 +58,8 @@ class DataType(IntEnum): | |||
| 58 | DT_FLOAT4_E2M1 = 40 # float4_e2m1 type | 58 | DT_FLOAT4_E2M1 = 40 # float4_e2m1 type |
| 59 | DT_FLOAT4_E1M2 = 41 # float4_e1m2 type | 59 | DT_FLOAT4_E1M2 = 41 # float4_e1m2 type |
| 60 | DT_HIFLOAT4 = 42 # hifloat4 type | 60 | DT_HIFLOAT4 = 42 # hifloat4 type |
| 61 | - DT_MAX = 43 # Mark the boundaries of data types | 61 | + DT_HIFLOAT4_SCALE = 43 # hifloat4 scale type |
| 62 | + DT_MAX = 44 # Mark the boundaries of data types | ||
| 62 | 63 | ||
| 63 | 64 | ||
| 64 | class Format(IntEnum): | 65 | class Format(IntEnum): |
| @@ -15,6 +15,7 @@ | |||
| 15 | #include <malloc.h> | 15 | #include <malloc.h> |
| 16 | #include "ge/ge_api_v2.h" | 16 | #include "ge/ge_api_v2.h" |
| 17 | #include "ge_is_initialize.h" | 17 | #include "ge_is_initialize.h" |
| 18 | +#include "output_data_logger.h" | ||
| 18 | #include "common/compile_profiling/ge_call_wrapper.h" | 19 | #include "common/compile_profiling/ge_call_wrapper.h" |
| 19 | #include "common/plugin/datatype_util.h" | 20 | #include "common/plugin/datatype_util.h" |
| 20 | #include "graph_metadef/common/plugin/plugin_manager.h" | 21 | #include "graph_metadef/common/plugin/plugin_manager.h" |
| @@ -76,13 +77,14 @@ constexpr size_t kGesizeuint16 = sizeof(uint16_t); | |||
| 76 | constexpr size_t kGesizeuint32 = sizeof(uint32_t); | 77 | constexpr size_t kGesizeuint32 = sizeof(uint32_t); |
| 77 | 78 | ||
| 78 | std::map<ge::DataType, size_t> CONST_OPDATA_TYPE_SIZE_MAP = { | 79 | std::map<ge::DataType, size_t> CONST_OPDATA_TYPE_SIZE_MAP = { |
| 79 | - {ge::DT_FLOAT, kGesizefloat}, {ge::DT_FLOAT16, kGesizehalffloat}, {ge::DT_INT8, kGesizeint8}, | 80 | + {ge::DT_FLOAT, kGesizefloat}, {ge::DT_FLOAT16, kGesizehalffloat}, {ge::DT_INT8, kGesizeint8}, |
| 80 | - {ge::DT_INT16, kGesizeint16}, {ge::DT_INT32, kGesizeint32}, {ge::DT_INT64, kGesizeint64}, | 81 | + {ge::DT_INT16, kGesizeint16}, {ge::DT_INT32, kGesizeint32}, {ge::DT_INT64, kGesizeint64}, |
| 81 | - {ge::DT_UINT8, kGesizeuint8}, {ge::DT_UINT16, kGesizeuint16}, {ge::DT_UINT32, kGesizeuint32}, | 82 | + {ge::DT_UINT8, kGesizeuint8}, {ge::DT_UINT16, kGesizeuint16}, {ge::DT_UINT32, kGesizeuint32}, |
| 82 | - {ge::DT_UINT64, kGesizeuint64}, {ge::DT_DOUBLE, kGesizedouble}, {ge::DT_BOOL, kGesizebool}, | 83 | + {ge::DT_UINT64, kGesizeuint64}, {ge::DT_DOUBLE, kGesizedouble}, {ge::DT_BOOL, kGesizebool}, |
| 83 | - {ge::DT_HIFLOAT8, kGesizefloat8}, {ge::DT_FLOAT8_E5M2, kGesizefloat8}, {ge::DT_FLOAT8_E4M3FN, kGesizefloat8}, | 84 | + {ge::DT_HIFLOAT8, kGesizefloat8}, {ge::DT_FLOAT8_E5M2, kGesizefloat8}, {ge::DT_FLOAT8_E4M3FN, kGesizefloat8}, |
| 84 | - {ge::DT_FLOAT8_E8M0, kGesizefloat8}, {ge::DT_FLOAT6_E3M2, kGesizefloat8}, {ge::DT_FLOAT6_E2M3, kGesizefloat8}, | 85 | + {ge::DT_FLOAT8_E8M0, kGesizefloat8}, {ge::DT_FLOAT6_E3M2, kGesizefloat8}, {ge::DT_FLOAT6_E2M3, kGesizefloat8}, |
| 85 | - {ge::DT_FLOAT4_E2M1, kGesizefloat8}, {ge::DT_FLOAT4_E1M2, kGesizefloat8}, {ge::DT_HIFLOAT4, kGesizefloat8}, | 86 | + {ge::DT_FLOAT4_E2M1, kGesizefloat8}, {ge::DT_FLOAT4_E1M2, kGesizefloat8}, {ge::DT_HIFLOAT4, kGesizefloat8}, |
| 87 | + {ge::DT_HIFLOAT4_SCALE, kGesizefloat}, | ||
| 86 | }; | 88 | }; |
| 87 | 89 | ||
| 88 | // dfx for RunGraphAsync, log error on error return | 90 | // dfx for RunGraphAsync, log error on error return |
| @@ -540,45 +542,10 @@ static void PrintOutputResult(std::vector<Tensor> &outputs) { | |||
| 540 | GELOGI("DataType %s has not defined size", TypeUtils::DataTypeToSerialString(data_type).c_str()); | 542 | GELOGI("DataType %s has not defined size", TypeUtils::DataTypeToSerialString(data_type).c_str()); |
| 541 | return; | 543 | return; |
| 542 | } | 544 | } |
| 545 | + const auto addr = outputs[0].GetData(); | ||
| 543 | // take first 10 at most | 546 | // take first 10 at most |
| 544 | for (size_t i = 0UL; (i < 10UL) && (i < (outputs[0].GetSize() / CONST_OPDATA_TYPE_SIZE_MAP[data_type])); ++i) { | 547 | for (size_t i = 0UL; (i < 10UL) && (i < (outputs[0].GetSize() / CONST_OPDATA_TYPE_SIZE_MAP[data_type])); ++i) { |
| 545 | - switch (data_type) { | 548 | + LogOutputData(i, data_type, addr); |
| 546 | - case DT_BOOL: | ||
| 547 | - case DT_INT8: | ||
| 548 | - case DT_UINT8: | ||
| 549 | - case DT_HIFLOAT8: | ||
| 550 | - case DT_FLOAT8_E5M2: | ||
| 551 | - case DT_FLOAT8_E4M3FN: | ||
| 552 | - case DT_FLOAT8_E8M0: | ||
| 553 | - case DT_FLOAT6_E3M2: | ||
| 554 | - case DT_FLOAT6_E2M3: | ||
| 555 | - case DT_HIFLOAT4: | ||
| 556 | - case DT_FLOAT4_E2M1: | ||
| 557 | - case DT_FLOAT4_E1M2: | ||
| 558 | - GELOGI("output data[%zu]=%d", i, *(reinterpret_cast<int8_t *>(outputs[0].GetData()) + i)); | ||
| 559 | - break; | ||
| 560 | - case DT_INT16: | ||
| 561 | - case DT_UINT16: | ||
| 562 | - GELOGI("output data[%zu]=%d", i, *(reinterpret_cast<int16_t *>(outputs[0].GetData()) + i)); | ||
| 563 | - break; | ||
| 564 | - case DT_INT32: | ||
| 565 | - case DT_UINT32: | ||
| 566 | - GELOGI("output data[%zu]=%d", i, *(reinterpret_cast<int32_t *>(outputs[0].GetData()) + i)); | ||
| 567 | - break; | ||
| 568 | - case DT_INT64: | ||
| 569 | - case DT_UINT64: | ||
| 570 | - GELOGI("output data[%zu]=%ld", i, *(reinterpret_cast<int64_t *>(outputs[0].GetData()) + i)); | ||
| 571 | - break; | ||
| 572 | - case DT_FLOAT: | ||
| 573 | - GELOGI("output data[%zu]=%f", i, *(reinterpret_cast<float *>(outputs[0].GetData()) + i)); | ||
| 574 | - break; | ||
| 575 | - case DT_DOUBLE: | ||
| 576 | - GELOGI("output data[%zu]=%lf", i, *(reinterpret_cast<double *>(outputs[0].GetData()) + i)); | ||
| 577 | - break; | ||
| 578 | - default: | ||
| 579 | - GELOGI("Output datatype %s is not supported.", TypeUtils::DataTypeToSerialString(data_type).c_str()); | ||
| 580 | - return; | ||
| 581 | - } | ||
| 582 | } | 549 | } |
| 583 | } | 550 | } |
| 584 | 551 | ||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <iostream> | 13 | #include <iostream> |
| 14 | #include <malloc.h> | 14 | #include <malloc.h> |
| 15 | #include "ge_is_initialize.h" | 15 | #include "ge_is_initialize.h" |
| 16 | +#include "output_data_logger.h" | ||
| 16 | #include "common/compile_profiling/ge_call_wrapper.h" | 17 | #include "common/compile_profiling/ge_call_wrapper.h" |
| 17 | #include "common/plugin/datatype_util.h" | 18 | #include "common/plugin/datatype_util.h" |
| 18 | #include "graph_metadef/common/plugin/plugin_manager.h" | 19 | #include "graph_metadef/common/plugin/plugin_manager.h" |
| @@ -77,13 +78,14 @@ constexpr size_t kGesizeuint16 = sizeof(uint16_t); | |||
| 77 | constexpr size_t kGesizeuint32 = sizeof(uint32_t); | 78 | constexpr size_t kGesizeuint32 = sizeof(uint32_t); |
| 78 | 79 | ||
| 79 | std::map<ge::DataType, size_t> CONST_OPDATA_TYPE_SIZE_MAP = { | 80 | std::map<ge::DataType, size_t> CONST_OPDATA_TYPE_SIZE_MAP = { |
| 80 | - {ge::DT_FLOAT, kGesizefloat}, {ge::DT_FLOAT16, kGesizehalffloat}, {ge::DT_INT8, kGesizeint8}, | 81 | + {ge::DT_FLOAT, kGesizefloat}, {ge::DT_FLOAT16, kGesizehalffloat}, {ge::DT_INT8, kGesizeint8}, |
| 81 | - {ge::DT_INT16, kGesizeint16}, {ge::DT_INT32, kGesizeint32}, {ge::DT_INT64, kGesizeint64}, | 82 | + {ge::DT_INT16, kGesizeint16}, {ge::DT_INT32, kGesizeint32}, {ge::DT_INT64, kGesizeint64}, |
| 82 | - {ge::DT_UINT8, kGesizeuint8}, {ge::DT_UINT16, kGesizeuint16}, {ge::DT_UINT32, kGesizeuint32}, | 83 | + {ge::DT_UINT8, kGesizeuint8}, {ge::DT_UINT16, kGesizeuint16}, {ge::DT_UINT32, kGesizeuint32}, |
| 83 | - {ge::DT_UINT64, kGesizeuint64}, {ge::DT_DOUBLE, kGesizedouble}, {ge::DT_BOOL, kGesizebool}, | 84 | + {ge::DT_UINT64, kGesizeuint64}, {ge::DT_DOUBLE, kGesizedouble}, {ge::DT_BOOL, kGesizebool}, |
| 84 | - {ge::DT_HIFLOAT8, kGesizefloat8}, {ge::DT_FLOAT8_E5M2, kGesizefloat8}, {ge::DT_FLOAT8_E4M3FN, kGesizefloat8}, | 85 | + {ge::DT_HIFLOAT8, kGesizefloat8}, {ge::DT_FLOAT8_E5M2, kGesizefloat8}, {ge::DT_FLOAT8_E4M3FN, kGesizefloat8}, |
| 85 | - {ge::DT_FLOAT8_E8M0, kGesizefloat8}, {ge::DT_FLOAT6_E3M2, kGesizefloat8}, {ge::DT_FLOAT6_E2M3, kGesizefloat8}, | 86 | + {ge::DT_FLOAT8_E8M0, kGesizefloat8}, {ge::DT_FLOAT6_E3M2, kGesizefloat8}, {ge::DT_FLOAT6_E2M3, kGesizefloat8}, |
| 86 | - {ge::DT_FLOAT4_E2M1, kGesizefloat8}, {ge::DT_FLOAT4_E1M2, kGesizefloat8}, {ge::DT_HIFLOAT4, kGesizefloat8}, | 87 | + {ge::DT_FLOAT4_E2M1, kGesizefloat8}, {ge::DT_FLOAT4_E1M2, kGesizefloat8}, {ge::DT_HIFLOAT4, kGesizefloat8}, |
| 88 | + {ge::DT_HIFLOAT4_SCALE, kGesizefloat}, | ||
| 87 | }; | 89 | }; |
| 88 | 90 | ||
| 89 | ge::Status InitProfiling(const std::map<std::string, std::string> &options) { | 91 | ge::Status InitProfiling(const std::map<std::string, std::string> &options) { |
| @@ -636,43 +638,7 @@ static void PrintOutputResult(std::vector<gert::Tensor> &outputs) { | |||
| 636 | const auto addr = outputs[0].GetAddr(); | 638 | const auto addr = outputs[0].GetAddr(); |
| 637 | // take first 10 at most | 639 | // take first 10 at most |
| 638 | for (size_t i = 0UL; (i < 10UL) && (i < (outputs[0].GetSize() / CONST_OPDATA_TYPE_SIZE_MAP[data_type])); ++i) { | 640 | for (size_t i = 0UL; (i < 10UL) && (i < (outputs[0].GetSize() / CONST_OPDATA_TYPE_SIZE_MAP[data_type])); ++i) { |
| 639 | - switch (data_type) { | 641 | + LogOutputData(i, data_type, addr); |
| 640 | - case DT_BOOL: | ||
| 641 | - case DT_INT8: | ||
| 642 | - case DT_UINT8: | ||
| 643 | - case DT_HIFLOAT8: | ||
| 644 | - case DT_FLOAT8_E5M2: | ||
| 645 | - case DT_FLOAT8_E4M3FN: | ||
| 646 | - case DT_FLOAT8_E8M0: | ||
| 647 | - case DT_FLOAT6_E3M2: | ||
| 648 | - case DT_FLOAT6_E2M3: | ||
| 649 | - case DT_HIFLOAT4: | ||
| 650 | - case DT_FLOAT4_E2M1: | ||
| 651 | - case DT_FLOAT4_E1M2: | ||
| 652 | - GELOGI("output data[%zu]=%d", i, *(reinterpret_cast<int8_t *>(addr) + i)); | ||
| 653 | - break; | ||
| 654 | - case DT_INT16: | ||
| 655 | - case DT_UINT16: | ||
| 656 | - GELOGI("output data[%zu]=%d", i, *(reinterpret_cast<int16_t *>(addr) + i)); | ||
| 657 | - break; | ||
| 658 | - case DT_INT32: | ||
| 659 | - case DT_UINT32: | ||
| 660 | - GELOGI("output data[%zu]=%d", i, *(reinterpret_cast<int32_t *>(addr) + i)); | ||
| 661 | - break; | ||
| 662 | - case DT_INT64: | ||
| 663 | - case DT_UINT64: | ||
| 664 | - GELOGI("output data[%zu]=%ld", i, *(reinterpret_cast<int64_t *>(addr) + i)); | ||
| 665 | - break; | ||
| 666 | - case DT_FLOAT: | ||
| 667 | - GELOGI("output data[%zu]=%f", i, *(reinterpret_cast<float *>(addr) + i)); | ||
| 668 | - break; | ||
| 669 | - case DT_DOUBLE: | ||
| 670 | - GELOGI("output data[%zu]=%lf", i, *(reinterpret_cast<double *>(addr) + i)); | ||
| 671 | - break; | ||
| 672 | - default: | ||
| 673 | - GELOGI("Output datatype %s is not supported.", TypeUtils::DataTypeToSerialString(data_type).c_str()); | ||
| 674 | - return; | ||
| 675 | - } | ||
| 676 | } | 642 | } |
| 677 | } | 643 | } |
| 678 | 644 | ||
| @@ -0,0 +1,64 @@ | |||
| 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 AIR_RUNNER_CLIENT_OUTPUT_DATA_LOGGER_H_ | ||
| 12 | +#define AIR_RUNNER_CLIENT_OUTPUT_DATA_LOGGER_H_ | ||
| 13 | + | ||
| 14 | +#include <cstddef> | ||
| 15 | + | ||
| 16 | +#include "graph/types.h" | ||
| 17 | +#include "framework/common/debug/log.h" | ||
| 18 | +#include "graph/utils/type_utils.h" | ||
| 19 | + | ||
| 20 | +namespace ge { | ||
| 21 | +// RunGraph 输出数据打点:按数据类型取前几条元素值打印,v1/v2 会话共用 | ||
| 22 | +inline void LogOutputData(size_t i, DataType data_type, const void *addr) { | ||
| 23 | + switch (data_type) { | ||
| 24 | + case DT_BOOL: | ||
| 25 | + case DT_INT8: | ||
| 26 | + case DT_UINT8: | ||
| 27 | + case DT_HIFLOAT8: | ||
| 28 | + case DT_FLOAT8_E5M2: | ||
| 29 | + case DT_FLOAT8_E4M3FN: | ||
| 30 | + case DT_FLOAT8_E8M0: | ||
| 31 | + case DT_FLOAT6_E3M2: | ||
| 32 | + case DT_FLOAT6_E2M3: | ||
| 33 | + case DT_HIFLOAT4: | ||
| 34 | + case DT_FLOAT4_E2M1: | ||
| 35 | + case DT_FLOAT4_E1M2: | ||
| 36 | + GELOGI("output data[%zu]=%d", i, *(reinterpret_cast<const int8_t *>(addr) + i)); | ||
| 37 | + break; | ||
| 38 | + case DT_INT16: | ||
| 39 | + case DT_UINT16: | ||
| 40 | + GELOGI("output data[%zu]=%d", i, *(reinterpret_cast<const int16_t *>(addr) + i)); | ||
| 41 | + break; | ||
| 42 | + case DT_INT32: | ||
| 43 | + case DT_UINT32: | ||
| 44 | + GELOGI("output data[%zu]=%d", i, *(reinterpret_cast<const int32_t *>(addr) + i)); | ||
| 45 | + break; | ||
| 46 | + case DT_INT64: | ||
| 47 | + case DT_UINT64: | ||
| 48 | + GELOGI("output data[%zu]=%ld", i, *(reinterpret_cast<const int64_t *>(addr) + i)); | ||
| 49 | + break; | ||
| 50 | + case DT_HIFLOAT4_SCALE: | ||
| 51 | + case DT_FLOAT: | ||
| 52 | + GELOGI("output data[%zu]=%f", i, *(reinterpret_cast<const float *>(addr) + i)); | ||
| 53 | + break; | ||
| 54 | + case DT_DOUBLE: | ||
| 55 | + GELOGI("output data[%zu]=%lf", i, *(reinterpret_cast<const double *>(addr) + i)); | ||
| 56 | + break; | ||
| 57 | + default: | ||
| 58 | + GELOGI("Output datatype %s is not supported.", TypeUtils::DataTypeToSerialString(data_type).c_str()); | ||
| 59 | + break; | ||
| 60 | + } | ||
| 61 | +} | ||
| 62 | +} // namespace ge | ||
| 63 | + | ||
| 64 | +#endif // AIR_RUNNER_CLIENT_OUTPUT_DATA_LOGGER_H_ | ||
| @@ -51,6 +51,7 @@ std::map<ge::DataType, ge::proto::DataType> g_dump_data_type_map = { | |||
| 51 | {ge::DT_UINT2, ge::proto::DT_UINT2}, | 51 | {ge::DT_UINT2, ge::proto::DT_UINT2}, |
| 52 | {ge::DT_HIFLOAT8, ge::proto::DT_HIFLOAT8}, | 52 | {ge::DT_HIFLOAT8, ge::proto::DT_HIFLOAT8}, |
| 53 | {ge::DT_HIFLOAT4, ge::proto::DT_HIFLOAT4}, | 53 | {ge::DT_HIFLOAT4, ge::proto::DT_HIFLOAT4}, |
| 54 | + {ge::DT_HIFLOAT4_SCALE, ge::proto::DT_HIFLOAT4_SCALE}, | ||
| 54 | {ge::DT_FLOAT8_E5M2, ge::proto::DT_FLOAT8_E5M2}, | 55 | {ge::DT_FLOAT8_E5M2, ge::proto::DT_FLOAT8_E5M2}, |
| 55 | {ge::DT_FLOAT8_E4M3FN, ge::proto::DT_FLOAT8_E4M3FN}, | 56 | {ge::DT_FLOAT8_E4M3FN, ge::proto::DT_FLOAT8_E4M3FN}, |
| 56 | {ge::DT_FLOAT8_E8M0, ge::proto::DT_FLOAT8_E8M0}, | 57 | {ge::DT_FLOAT8_E8M0, ge::proto::DT_FLOAT8_E8M0}, |
| @@ -91,6 +91,7 @@ map<std::string, DataType> kDataTypeDict = { | |||
| 91 | {"int4", DT_INT4}, | 91 | {"int4", DT_INT4}, |
| 92 | {"hifloat8", DT_HIFLOAT8}, | 92 | {"hifloat8", DT_HIFLOAT8}, |
| 93 | {"hifloat4", DT_HIFLOAT4}, | 93 | {"hifloat4", DT_HIFLOAT4}, |
| 94 | + {"hifloat4_scale", DT_HIFLOAT4_SCALE}, | ||
| 94 | {"float8_e5m2", DT_FLOAT8_E5M2}, | 95 | {"float8_e5m2", DT_FLOAT8_E5M2}, |
| 95 | {"float8_e4m3fn", DT_FLOAT8_E4M3FN}, | 96 | {"float8_e4m3fn", DT_FLOAT8_E4M3FN}, |
| 96 | }; | 97 | }; |
| @@ -187,10 +187,10 @@ Status HostCpuEngine::PrepareOutputs(const ge::ConstOpDescPtr &op_desc, std::vec | |||
| 187 | 187 | ||
| 188 | Status ret = SUCCESS; | 188 | Status ret = SUCCESS; |
| 189 | const std::set<DataType> output_data_type_set = { | 189 | const std::set<DataType> output_data_type_set = { |
| 190 | - DT_BOOL, DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, | 190 | + DT_BOOL, DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, |
| 191 | - DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, | 191 | + DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, |
| 192 | - DT_INT4, DT_COMPLEX64, DT_COMPLEX128, DT_HIFLOAT8, DT_HIFLOAT4, DT_FLOAT8_E4M3FN, | 192 | + DT_INT4, DT_COMPLEX64, DT_COMPLEX128, DT_HIFLOAT8, DT_HIFLOAT4, DT_HIFLOAT4_SCALE, |
| 193 | - DT_FLOAT8_E5M2, DT_FLOAT4_E2M1, DT_FLOAT4_E1M2, DT_FLOAT8_E8M0}; | 193 | + DT_FLOAT8_E4M3FN, DT_FLOAT8_E5M2, DT_FLOAT4_E2M1, DT_FLOAT4_E1M2, DT_FLOAT8_E8M0}; |
| 194 | for (size_t i = 0U; i < op_desc->GetOutputsSize(); ++i) { | 194 | for (size_t i = 0U; i < op_desc->GetOutputsSize(); ++i) { |
| 195 | const auto &out_desc = op_desc->GetOutputDesc(static_cast<uint32_t>(i)); | 195 | const auto &out_desc = op_desc->GetOutputDesc(static_cast<uint32_t>(i)); |
| 196 | const std::set<DataType>::const_iterator &output_data_type_iter = output_data_type_set.find(out_desc.GetDataType()); | 196 | const std::set<DataType>::const_iterator &output_data_type_iter = output_data_type_set.find(out_desc.GetDataType()); |
| @@ -24,6 +24,7 @@ | |||
| 24 | #include "ge/ge_api_types.h" | 24 | #include "ge/ge_api_types.h" |
| 25 | #include "framework/common/string_util.h" | 25 | #include "framework/common/string_util.h" |
| 26 | #include "framework/common/framework_types_internal.h" | 26 | #include "framework/common/framework_types_internal.h" |
| 27 | +#include "framework/common/output_type_map.h" | ||
| 27 | #include "framework/common/util.h" | 28 | #include "framework/common/util.h" |
| 28 | #include "graph/ge_context.h" | 29 | #include "graph/ge_context.h" |
| 29 | #include "common/checker.h" | 30 | #include "common/checker.h" |
| @@ -46,14 +47,10 @@ const int64_t kDynamicImageSizeNum = 2; | |||
| 46 | const constexpr size_t kLeastStrElementNum = 2UL; | 47 | const constexpr size_t kLeastStrElementNum = 2UL; |
| 47 | const int32_t kBase = 10; | 48 | const int32_t kBase = 10; |
| 48 | // datatype/formats from user to GE, Unified to util interface file later | 49 | // datatype/formats from user to GE, Unified to util interface file later |
| 49 | -const std::map<std::string, ge::DataType> kOutputTypeSupportDatatype = { | 50 | +const auto &kOutputTypeSupportDatatype = ge::OutputTypeStrToDatatype(); |
| 50 | - {"FP32", ge::DT_FLOAT}, {"FP16", ge::DT_FLOAT16}, | ||
| 51 | - {"UINT8", ge::DT_UINT8}, {"INT8", ge::DT_INT8}, | ||
| 52 | - {"HIF8", ge::DT_HIFLOAT8}, {"HIF4", ge::DT_HIFLOAT4}, | ||
| 53 | - {"FP8E5M2", ge::DT_FLOAT8_E5M2}, {"FP8E4M3FN", ge::DT_FLOAT8_E4M3FN}, | ||
| 54 | -}; | ||
| 55 | const char *const kOutputTypeSupport = | 51 | const char *const kOutputTypeSupport = |
| 56 | - "The current value is not within the valid range. Only support FP32, FP16, UINT8, INT8, HIF8, FP8E5M2, FP8E4M3FN."; | 52 | + "The current value is not within the valid range. Only support FP32, FP16, UINT8, INT8, HIF8, HIF4SCALE, " |
| 53 | + "FP8E5M2, FP8E4M3FN."; | ||
| 57 | const std::set<std::string> kBufferOptimizeSupportOption = {"l1_optimize", "l2_optimize", "off_optimize", | 54 | const std::set<std::string> kBufferOptimizeSupportOption = {"l1_optimize", "l2_optimize", "off_optimize", |
| 58 | "l1_and_l2_optimize"}; | 55 | "l1_and_l2_optimize"}; |
| 59 | // The function is incomplete. Currently, only l2_optimize, off_optimize is supported. | 56 | // The function is incomplete. Currently, only l2_optimize, off_optimize is supported. |
| @@ -131,8 +131,9 @@ struct MemsetNodeAddrAndAttr { | |||
| 131 | 131 | ||
| 132 | inline bool IsFloatType(const DataType dt) { | 132 | inline bool IsFloatType(const DataType dt) { |
| 133 | return (dt == DT_FLOAT) || (dt == DT_FLOAT16) || (dt == DT_DOUBLE) || (dt == DT_BF16) || (dt == DT_HIFLOAT8) || | 133 | return (dt == DT_FLOAT) || (dt == DT_FLOAT16) || (dt == DT_DOUBLE) || (dt == DT_BF16) || (dt == DT_HIFLOAT8) || |
| 134 | - (dt == DT_HIFLOAT4) || (dt == DT_FLOAT8_E5M2) || (dt == DT_FLOAT8_E4M3FN) || (dt == DT_FLOAT8_E8M0) || | 134 | + (dt == DT_HIFLOAT4) || (dt == DT_HIFLOAT4_SCALE) || (dt == DT_FLOAT8_E5M2) || (dt == DT_FLOAT8_E4M3FN) || |
| 135 | - (dt == DT_FLOAT6_E3M2) || (dt == DT_FLOAT6_E2M3) || (dt == DT_FLOAT4_E2M1) || (dt == DT_FLOAT4_E1M2); | 135 | + (dt == DT_FLOAT8_E8M0) || (dt == DT_FLOAT6_E3M2) || (dt == DT_FLOAT6_E2M3) || (dt == DT_FLOAT4_E2M1) || |
| 136 | + (dt == DT_FLOAT4_E1M2); | ||
| 136 | } | 137 | } |
| 137 | 138 | ||
| 138 | const std::list<NodeIndexIO> *FindSymbolAnchors(const BlockMemAssignerPtr &mem_assigner, const NodePtr &node, | 139 | const std::list<NodeIndexIO> *FindSymbolAnchors(const BlockMemAssignerPtr &mem_assigner, const NodePtr &node, |
| @@ -182,6 +182,7 @@ int32_t CondRemovePass::GetCondIndex(const GeTensor *tensor) { | |||
| 182 | case DT_UINT8: | 182 | case DT_UINT8: |
| 183 | case DT_HIFLOAT8: | 183 | case DT_HIFLOAT8: |
| 184 | case DT_HIFLOAT4: | 184 | case DT_HIFLOAT4: |
| 185 | + case DT_HIFLOAT4_SCALE: | ||
| 185 | case DT_FLOAT8_E5M2: | 186 | case DT_FLOAT8_E5M2: |
| 186 | case DT_FLOAT8_E4M3FN: | 187 | case DT_FLOAT8_E4M3FN: |
| 187 | return (tensor_size >= sizeof(uint8_t)) ? static_cast<int32_t>(*data_ptr) : kInvalidRetVal; | 188 | return (tensor_size >= sizeof(uint8_t)) ? static_cast<int32_t>(*data_ptr) : kInvalidRetVal; |
| @@ -45,6 +45,7 @@ bool ParsePred(const ConstGeTensorPtr &tensor) { | |||
| 45 | case DT_UINT8: | 45 | case DT_UINT8: |
| 46 | case DT_HIFLOAT8: | 46 | case DT_HIFLOAT8: |
| 47 | case DT_HIFLOAT4: | 47 | case DT_HIFLOAT4: |
| 48 | + case DT_HIFLOAT4_SCALE: | ||
| 48 | case DT_FLOAT8_E5M2: | 49 | case DT_FLOAT8_E5M2: |
| 49 | case DT_FLOAT8_E4M3FN: | 50 | case DT_FLOAT8_E4M3FN: |
| 50 | return static_cast<bool>(*data_ptr); | 51 | return static_cast<bool>(*data_ptr); |
| @@ -34,6 +34,7 @@ constexpr ge::float32_t E5M2_MAX_VALUE = 1.75 * std::pow(2, 15); | |||
| 34 | constexpr ge::float32_t E4M3FN_MAX_VALUE = 1.75 * std::pow(2, 8); | 34 | constexpr ge::float32_t E4M3FN_MAX_VALUE = 1.75 * std::pow(2, 8); |
| 35 | constexpr ge::float32_t HIF4_MAX_VALUE = 1.3125f * 262144.0f; | 35 | constexpr ge::float32_t HIF4_MAX_VALUE = 1.3125f * 262144.0f; |
| 36 | constexpr ge::float32_t HIF4_MIN_VALUE = 8.881784197e-16f; | 36 | constexpr ge::float32_t HIF4_MIN_VALUE = 8.881784197e-16f; |
| 37 | +// hif4_scale 的取值范围由缩放因子决定,不存在静态上下限,权重裁剪不涉及该类型 | ||
| 37 | bool IsFloatDt(const ge::DataType &dt) { | 38 | bool IsFloatDt(const ge::DataType &dt) { |
| 38 | return (dt == ge::DT_FLOAT) || (dt == ge::DT_FLOAT16) || (dt == ge::DT_DOUBLE) || (dt == ge::DT_BF16) || | 39 | return (dt == ge::DT_FLOAT) || (dt == ge::DT_FLOAT16) || (dt == ge::DT_DOUBLE) || (dt == ge::DT_BF16) || |
| 39 | (dt == ge::DT_HIFLOAT8) || (dt == ge::DT_HIFLOAT4) || (dt == ge::DT_FLOAT8_E5M2) || | 40 | (dt == ge::DT_HIFLOAT8) || (dt == ge::DT_HIFLOAT4) || (dt == ge::DT_FLOAT8_E5M2) || |
| @@ -31,14 +31,23 @@ | |||
| 31 | 31 | ||
| 32 | namespace ge { | 32 | namespace ge { |
| 33 | static std::map<std::string, ge::DataType> output_type_str_to_datatype = { | 33 | static std::map<std::string, ge::DataType> output_type_str_to_datatype = { |
| 34 | - {"FP32", ge::DT_FLOAT}, {"FP16", ge::DT_FLOAT16}, | 34 | + {"FP32", ge::DT_FLOAT}, |
| 35 | - {"INT8", ge::DT_INT8}, {"INT16", ge::DT_INT16}, | 35 | + {"FP16", ge::DT_FLOAT16}, |
| 36 | - {"UINT16", ge::DT_UINT16}, {"UINT8", ge::DT_UINT8}, | 36 | + {"INT8", ge::DT_INT8}, |
| 37 | - {"INT32", ge::DT_INT32}, {"INT64", ge::DT_INT64}, | 37 | + {"INT16", ge::DT_INT16}, |
| 38 | - {"UINT32", ge::DT_UINT32}, {"UINT64", ge::DT_UINT64}, | 38 | + {"UINT16", ge::DT_UINT16}, |
| 39 | - {"DOUBLE", ge::DT_DOUBLE}, {"BF16", ge::DT_BF16}, | 39 | + {"UINT8", ge::DT_UINT8}, |
| 40 | - {"HIF4", ge::DT_HIFLOAT4}, {"HIF8", ge::DT_HIFLOAT8}, | 40 | + {"INT32", ge::DT_INT32}, |
| 41 | - {"FP8E5M2", ge::DT_FLOAT8_E5M2}, {"FP8E4M3FN", ge::DT_FLOAT8_E4M3FN}, | 41 | + {"INT64", ge::DT_INT64}, |
| 42 | + {"UINT32", ge::DT_UINT32}, | ||
| 43 | + {"UINT64", ge::DT_UINT64}, | ||
| 44 | + {"DOUBLE", ge::DT_DOUBLE}, | ||
| 45 | + {"BF16", ge::DT_BF16}, | ||
| 46 | + {"HIF4", ge::DT_HIFLOAT4}, | ||
| 47 | + {"HIF4SCALE", ge::DT_HIFLOAT4_SCALE}, | ||
| 48 | + {"HIF8", ge::DT_HIFLOAT8}, | ||
| 49 | + {"FP8E5M2", ge::DT_FLOAT8_E5M2}, | ||
| 50 | + {"FP8E4M3FN", ge::DT_FLOAT8_E4M3FN}, | ||
| 42 | }; | 51 | }; |
| 43 | 52 | ||
| 44 | // the size of user defined output datatype or format std::string after split by ":". | 53 | // the size of user defined output datatype or format std::string after split by ":". |
| @@ -63,7 +63,8 @@ DataType is an enumeration class inheriting from IntEnum, used to define all ele | |||
| 63 | | DT_FLOAT4_E2M1 | 40 | 4-bit floating-point (E2M1 format) | | 63 | | DT_FLOAT4_E2M1 | 40 | 4-bit floating-point (E2M1 format) | |
| 64 | | DT_FLOAT4_E1M2 | 41 | 4-bit floating-point (E1M2 format) | | 64 | | DT_FLOAT4_E1M2 | 41 | 4-bit floating-point (E1M2 format) | |
| 65 | | DT_HIFLOAT4 | 42 | 4-bit high-precision floating-point | | 65 | | DT_HIFLOAT4 | 42 | 4-bit high-precision floating-point | |
| 66 | -| DT_MAX | 43 | Data type boundary marker, not representing actual data type | | 66 | +| DT_HIFLOAT4_SCALE | 43 | hifloat4 with scale factor (4 bytes per element) | |
| 67 | +| DT_MAX | 44 | Data type boundary marker, not representing actual data type | | ||
| 67 | 68 | ||
| 68 | ## Constraint Description | 69 | ## Constraint Description |
| 69 | 70 | ||
| @@ -63,7 +63,8 @@ DataType 是一个继承自 IntEnum 的枚举类,用于定义张量支持的 | |||
| 63 | | DT_FLOAT4_E2M1 | 40 | 4 位浮点型(E2M1 格式) | | 63 | | DT_FLOAT4_E2M1 | 40 | 4 位浮点型(E2M1 格式) | |
| 64 | | DT_FLOAT4_E1M2 | 41 | 4 位浮点型(E1M2 格式) | | 64 | | DT_FLOAT4_E1M2 | 41 | 4 位浮点型(E1M2 格式) | |
| 65 | | DT_HIFLOAT4 | 42 | 4 位高精度浮点型 | | 65 | | DT_HIFLOAT4 | 42 | 4 位高精度浮点型 | |
| 66 | -| DT_MAX | 43 | 数据类型边界标记,不代表实际数据类型 | | 66 | +| DT_HIFLOAT4_SCALE | 43 | hifloat4 带缩放因子类型(4 字节/元素) | |
| 67 | +| DT_MAX | 44 | 数据类型边界标记,不代表实际数据类型 | | ||
| 67 | 68 | ||
| 68 | ## 约束说明 | 69 | ## 约束说明 |
| 69 | 70 | ||
| @@ -122,6 +122,7 @@ const std::map<std::string, DataType> kStringTodataTypeMap = { | |||
| 122 | {"DT_FLOAT4_E2M1", DT_FLOAT4_E2M1}, // mxfp4 | 122 | {"DT_FLOAT4_E2M1", DT_FLOAT4_E2M1}, // mxfp4 |
| 123 | {"DT_FLOAT4_E1M2", DT_FLOAT4_E1M2}, // mxfp4 | 123 | {"DT_FLOAT4_E1M2", DT_FLOAT4_E1M2}, // mxfp4 |
| 124 | {"DT_HIFLOAT4", DT_HIFLOAT4}, | 124 | {"DT_HIFLOAT4", DT_HIFLOAT4}, |
| 125 | + {"DT_HIFLOAT4_SCALE", DT_HIFLOAT4_SCALE}, | ||
| 125 | {"RESERVED", DT_UNDEFINED}, // RESERVED will be deserialized to DT_UNDEFINED | 126 | {"RESERVED", DT_UNDEFINED}, // RESERVED will be deserialized to DT_UNDEFINED |
| 126 | }; | 127 | }; |
| 127 | 128 | ||
| @@ -77,6 +77,7 @@ const std::map<DataType, ::ge::proto::DataType> kDataTypeMap = { | |||
| 77 | {DT_FLOAT6_E3M2, proto::DT_FLOAT6_E3M2}, | 77 | {DT_FLOAT6_E3M2, proto::DT_FLOAT6_E3M2}, |
| 78 | {DT_FLOAT6_E2M3, proto::DT_FLOAT6_E2M3}, | 78 | {DT_FLOAT6_E2M3, proto::DT_FLOAT6_E2M3}, |
| 79 | {DT_HIFLOAT4, proto::DT_HIFLOAT4}, | 79 | {DT_HIFLOAT4, proto::DT_HIFLOAT4}, |
| 80 | + {DT_HIFLOAT4_SCALE, proto::DT_HIFLOAT4_SCALE}, | ||
| 80 | {DT_FLOAT4_E2M1, proto::DT_FLOAT4_E2M1}, | 81 | {DT_FLOAT4_E2M1, proto::DT_FLOAT4_E2M1}, |
| 81 | {DT_FLOAT4_E1M2, proto::DT_FLOAT4_E1M2}, | 82 | {DT_FLOAT4_E1M2, proto::DT_FLOAT4_E1M2}, |
| 82 | }; | 83 | }; |
| @@ -52,6 +52,7 @@ const std::map<DataType, ::ge::proto::DataType> kDataTypeMap = {{DT_UNDEFINED, p | |||
| 52 | {DT_FLOAT6_E3M2, proto::DT_FLOAT6_E3M2}, | 52 | {DT_FLOAT6_E3M2, proto::DT_FLOAT6_E3M2}, |
| 53 | {DT_FLOAT6_E2M3, proto::DT_FLOAT6_E2M3}, | 53 | {DT_FLOAT6_E2M3, proto::DT_FLOAT6_E2M3}, |
| 54 | {DT_HIFLOAT4, proto::DT_HIFLOAT4}, | 54 | {DT_HIFLOAT4, proto::DT_HIFLOAT4}, |
| 55 | + {DT_HIFLOAT4_SCALE, proto::DT_HIFLOAT4_SCALE}, | ||
| 55 | {DT_FLOAT4_E2M1, proto::DT_FLOAT4_E2M1}, | 56 | {DT_FLOAT4_E2M1, proto::DT_FLOAT4_E2M1}, |
| 56 | {DT_FLOAT4_E1M2, proto::DT_FLOAT4_E1M2}}; | 57 | {DT_FLOAT4_E1M2, proto::DT_FLOAT4_E1M2}}; |
| 57 | 58 | ||
| @@ -54,6 +54,7 @@ enum OutputDataType { | |||
| 54 | DT_FLOAT4_E2M1 = 39; // float4_e2m1 type | 54 | DT_FLOAT4_E2M1 = 39; // float4_e2m1 type |
| 55 | DT_FLOAT4_E1M2 = 40; // float4_e1m2 type | 55 | DT_FLOAT4_E1M2 = 40; // float4_e1m2 type |
| 56 | DT_HIFLOAT4 = 41; | 56 | DT_HIFLOAT4 = 41; |
| 57 | + DT_HIFLOAT4_SCALE = 42; | ||
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | enum OutputFormat { | 60 | enum OutputFormat { |
| @@ -55,6 +55,7 @@ enum DataType | |||
| 55 | DT_FLOAT4_E2M1 = 39; // float4_e2m1 type | 55 | DT_FLOAT4_E2M1 = 39; // float4_e2m1 type |
| 56 | DT_FLOAT4_E1M2 = 40; // float4_e1m2 type | 56 | DT_FLOAT4_E1M2 = 40; // float4_e1m2 type |
| 57 | DT_HIFLOAT4 = 41; // hifloat4 type | 57 | DT_HIFLOAT4 = 41; // hifloat4 type |
| 58 | + DT_HIFLOAT4_SCALE = 42; // hifloat4_scale type | ||
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | message AttrDef | 61 | message AttrDef |
| @@ -0,0 +1,37 @@ | |||
| 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 INC_FRAMEWORK_COMMON_OUTPUT_TYPE_MAP_H_ | ||
| 12 | +#define INC_FRAMEWORK_COMMON_OUTPUT_TYPE_MAP_H_ | ||
| 13 | + | ||
| 14 | +#include <map> | ||
| 15 | +#include <string> | ||
| 16 | + | ||
| 17 | +#include "graph/types.h" | ||
| 18 | + | ||
| 19 | +namespace ge { | ||
| 20 | +// 用户输出类型字符串到 DataType 的映射,供 atc 与 aclgrph 的 --output_type 解析共用 | ||
| 21 | +inline const std::map<std::string, DataType> &OutputTypeStrToDatatype() { | ||
| 22 | + static const std::map<std::string, DataType> kOutputTypeStrToDatatype = { | ||
| 23 | + {"FP32", DT_FLOAT}, | ||
| 24 | + {"FP16", DT_FLOAT16}, | ||
| 25 | + {"UINT8", DT_UINT8}, | ||
| 26 | + {"INT8", DT_INT8}, | ||
| 27 | + {"HIF8", DT_HIFLOAT8}, | ||
| 28 | + {"HIF4", DT_HIFLOAT4}, | ||
| 29 | + {"HIF4SCALE", DT_HIFLOAT4_SCALE}, | ||
| 30 | + {"FP8E5M2", DT_FLOAT8_E5M2}, | ||
| 31 | + {"FP8E4M3FN", DT_FLOAT8_E4M3FN}, | ||
| 32 | + }; | ||
| 33 | + return kOutputTypeStrToDatatype; | ||
| 34 | +} | ||
| 35 | +} // namespace ge | ||
| 36 | + | ||
| 37 | +#endif // INC_FRAMEWORK_COMMON_OUTPUT_TYPE_MAP_H_ | ||
| @@ -81,7 +81,8 @@ class TestDataType: | |||
| 81 | assert DataType.DT_FLOAT4_E2M1 == 40 | 81 | assert DataType.DT_FLOAT4_E2M1 == 40 |
| 82 | assert DataType.DT_FLOAT4_E1M2 == 41 | 82 | assert DataType.DT_FLOAT4_E1M2 == 41 |
| 83 | assert DataType.DT_HIFLOAT4 == 42 | 83 | assert DataType.DT_HIFLOAT4 == 42 |
| 84 | - assert DataType.DT_MAX == 43 | 84 | + assert DataType.DT_HIFLOAT4_SCALE == 43 |
| 85 | + assert DataType.DT_MAX == 44 | ||
| 85 | 86 | ||
| 86 | def test_data_type_enum_inheritance(self): | 87 | def test_data_type_enum_inheritance(self): |
| 87 | """测试 DataType 枚举继承""" | 88 | """测试 DataType 枚举继承""" |
| @@ -163,7 +164,9 @@ class TestAttrValueType: | |||
| 163 | # 测试枚举 repr | 164 | # 测试枚举 repr |
| 164 | assert repr(AttrValueType.VT_STRING) == "<AttrValueType.VT_STRING: 1>" | 165 | assert repr(AttrValueType.VT_STRING) == "<AttrValueType.VT_STRING: 1>" |
| 165 | assert repr(AttrValueType.VT_FLOAT) == "<AttrValueType.VT_FLOAT: 2>" | 166 | assert repr(AttrValueType.VT_FLOAT) == "<AttrValueType.VT_FLOAT: 2>" |
| 166 | - assert repr(AttrValueType.VT_LIST_STRING) == "<AttrValueType.VT_LIST_STRING: 1001>" | 167 | + assert ( |
| 168 | + repr(AttrValueType.VT_LIST_STRING) == "<AttrValueType.VT_LIST_STRING: 1001>" | ||
| 169 | + ) | ||
| 167 | 170 | ||
| 168 | def test_attr_data_type_enum_usage_in_attr_value(self): | 171 | def test_attr_data_type_enum_usage_in_attr_value(self): |
| 169 | """测试 AttrValueType 在 AttrValue 中的使用""" | 172 | """测试 AttrValueType 在 AttrValue 中的使用""" |