From 42c6940bb1e0422f06bc0c3a1986c86da8b641f0 Mon Sep 17 00:00:00 2001 From: "wangwenhua1@huawei.com" Date: Tue, 17 Nov 2020 11:25:40 +0800 Subject: [PATCH] error message add format --- .../formats/format_transfers/datatype_transfer.cc | 22 +++++++++++---------- .../format_transfer_c1hwncoc0_hwcn.cc | 23 ++++++++++------------ .../format_transfers/format_transfer_fractal_z.cc | 4 ++-- .../format_transfers/format_transfer_fractal_zz.cc | 4 ++-- .../format_transfers/format_transfer_fracz_hwcn.cc | 13 +++++++----- .../format_transfers/format_transfer_fracz_nchw.cc | 7 ++++--- .../format_transfers/format_transfer_fracz_nhwc.cc | 7 ++++--- .../format_transfer_hwcn_c1hwncoc0.cc | 7 ++++--- .../format_transfer_nc1hwc0_nchw.cc | 7 ++++--- .../format_transfer_nc1hwc0_nhwc.cc | 7 ++++--- .../format_transfer_nchw_nc1hwc0.cc | 7 ++++--- .../format_transfer_nhwc_nc1hwc0.cc | 7 ++++--- .../format_transfers/format_transfer_transpose.cc | 2 +- ge/common/formats/utils/formats_trans_utils.cc | 11 +++++------ inc/framework/common/debug/log.h | 2 +- 15 files changed, 69 insertions(+), 61 deletions(-) diff --git a/ge/common/formats/format_transfers/datatype_transfer.cc b/ge/common/formats/format_transfers/datatype_transfer.cc index 9c7f4ac0..54600000 100644 --- a/ge/common/formats/format_transfers/datatype_transfer.cc +++ b/ge/common/formats/format_transfers/datatype_transfer.cc @@ -24,6 +24,7 @@ #include "common/fp16_t.h" #include "common/ge/ge_util.h" #include "framework/common/debug/ge_log.h" +#include "framework/common/debug/log.h" #include "graph/utils/type_utils.h" #include "securec.h" @@ -123,9 +124,9 @@ Status DataTypeTransfer::TransDataType(const CastArgs &args, TransResult &result std::pair trans_info(args.src_data_type, args.dst_data_type); auto iter = trans_mode_map.find(trans_info); if (iter == trans_mode_map.end()) { - std::string error = "Failed to trans data from datatype [" + - TypeUtils::FormatToSerialString(args.src_data_type) + "] to " + "[" + - TypeUtils::FormatToSerialString(args.dst_data_type) + "], it is not supported."; + std::string error = "Failed to trans data from datatype " + + FmtToStr(TypeUtils::DataTypeToSerialString(args.src_data_type)) + " to " + + FmtToStr(TypeUtils::DataTypeToSerialString(args.dst_data_type)) + " , it is not supported."; GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); return UNSUPPORTED; } @@ -133,14 +134,14 @@ Status DataTypeTransfer::TransDataType(const CastArgs &args, TransResult &result int size = GetSizeByDataType(args.dst_data_type); if (size <= 0) { - std::string error = "Failed to calc size from data type[" + - TypeUtils::DataTypeToSerialString(args.dst_data_type) + "], it is not supported."; + std::string error = "Failed to calc size from data type" + + FmtToStr(TypeUtils::DataTypeToSerialString(args.dst_data_type)) + ", it is not supported."; GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); return PARAM_INVALID; } if (args.src_data_size > static_cast(SIZE_MAX / size)) { - std::string error = "args.src_data_size[" + std::to_string(args.src_data_size) + - "] or data type size[" + std::to_string(size) + "is too big"; + std::string error = "args.src_data_size" + FmtToStr(args.src_data_size) + + " or data type size" + FmtToStr(std::to_string(size)) + " is too big"; GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); return PARAM_INVALID; } @@ -158,9 +159,10 @@ Status DataTypeTransfer::TransDataType(const CastArgs &args, TransResult &result } if (CastKernel(args, dst.get(), args.src_data_size, trans_mode) != SUCCESS) { - std::string error = "Failed to cast data from datatype [" + - TypeUtils::FormatToSerialString(args.src_data_type) + "] to " + "[" + - TypeUtils::FormatToSerialString(args.dst_data_type) + "], data size is " + std::to_string(args.src_data_size); + std::string error = "Failed to cast data from datatype " + + FmtToStr(TypeUtils::DataTypeToSerialString(args.src_data_type)) + " to " + + FmtToStr(TypeUtils::DataTypeToSerialString(args.dst_data_type)) + ", data size is " + + FmtToStr(std::to_string(args.src_data_size)); GE_ERRORLOG_AND_ERRORMSG(INTERNAL_ERROR, error.c_str()); return INTERNAL_ERROR; } diff --git a/ge/common/formats/format_transfers/format_transfer_c1hwncoc0_hwcn.cc b/ge/common/formats/format_transfers/format_transfer_c1hwncoc0_hwcn.cc index aa5ec7ec..16b559c4 100644 --- a/ge/common/formats/format_transfers/format_transfer_c1hwncoc0_hwcn.cc +++ b/ge/common/formats/format_transfers/format_transfer_c1hwncoc0_hwcn.cc @@ -36,16 +36,14 @@ Status CheckArgsForC1hwncoc0ToHwcn(const TransArgs &args) { auto dst_shape = args.dst_shape; if (args.src_format != FORMAT_C1HWNCoC0 || args.dst_format != FORMAT_HWCN) { std::string error = "Dose not support trans format from " + - FmtEgStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + - FmtEgStr(TypeUtils::FormatToSerialString(args.dst_format)); - GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", - TypeUtils::FormatToSerialString(args.src_format).c_str(), - TypeUtils::FormatToSerialString(args.dst_format).c_str()); + FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + + FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); + GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); return UNSUPPORTED; } if (!CheckDataTypeSupported(args.src_data_type)) { - std::string error = "Failed to trans shape from NC1HWNCoC0 to HWCN, invalid data type[" + - TypeUtils::DataTypeToSerialString(args.src_data_type).c_str() + "]"; + std::string error = "Failed to trans shape from NC1HWNCoC0 to HWCN, invalid data type" + + FmtToStr(TypeUtils::DataTypeToSerialString(args.src_data_type)); GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); return UNSUPPORTED; } @@ -62,8 +60,8 @@ Status CheckArgsForC1hwncoc0ToHwcn(const TransArgs &args) { src_shape.at(kC1hwncoc0H) != dst_shape.at(kHwcnH) || src_shape.at(kC1hwncoc0W) != dst_shape.at(kHwcnW) || src_shape.at(kC1hwncoc0N) != dst_shape.at(kHwcnN) || src_shape.at(kC1hwncoc0Co) != cube_size || src_shape.at(kC1hwncoc0C0) != cube_size) { - std::string error = "Failed to check relationship between src and dst shape, src shape[" + - ShapeToString(src_shape) + "], dst shape[" + ShapeToString(dst_shape) + "]"; + std::string error = "Failed to check relationship between src and dst shape, src shape" + + FmtToStr(ShapeToString(src_shape)) + ", dst shape" + FmtToStr(ShapeToString(dst_shape)); GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); return PARAM_INVALID; } @@ -74,10 +72,9 @@ Status CheckArgsForC1hwncoc0ToHwcn(const TransArgs &args) { Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, int size, int64_t total_size) { std::shared_ptr dst(new (std::nothrow) uint8_t[total_size], std::default_delete()); if (dst == nullptr) { - std::string error = "Failed to trans format from[" + TypeUtils::FormatToSerialString(args.src_format).c_str() + - "] to [" + TypeUtils::FormatToSerialString(args.dst_format) + "], can not alloc the memory for dst buf[" + - std::to_string(total_size) + "], shape[" + ShapeToString(args.dst_shape) + "]"; - GE_ERRORLOG_AND_ERRORMSG(OUT_OF_MEMORY, error.c_str()); + GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", + TypeUtils::FormatToSerialString(args.src_format).c_str(), + TypeUtils::FormatToSerialString(args.dst_format).c_str(), total_size, ShapeToString(args.dst_shape).c_str()); return OUT_OF_MEMORY; } diff --git a/ge/common/formats/format_transfers/format_transfer_fractal_z.cc b/ge/common/formats/format_transfers/format_transfer_fractal_z.cc index d19702ff..378d0dd1 100644 --- a/ge/common/formats/format_transfers/format_transfer_fractal_z.cc +++ b/ge/common/formats/format_transfers/format_transfer_fractal_z.cc @@ -159,8 +159,8 @@ Status TransFormatFromNchwToFz(const TransArgs &args, TransResult &result) { ret = memset_s(dst.get() + offset, static_cast(protected_size), 0, static_cast(size)); } else { if (protected_size < size) { - std::string error = "Failed to operate the dst memory, protected_size is[" + - std::to_string(protected_size) + "] and size is [" + std::to_string(size) + "]"; + std::string error = "Failed to operate the dst memory, protected_size is " + + FmtToStr(protected_size) + " and size is " + FmtToStr(size); GE_ERRORLOG_AND_ERRORMSG(INTERNAL_ERROR, error.c_str()); return INTERNAL_ERROR; } diff --git a/ge/common/formats/format_transfers/format_transfer_fractal_zz.cc b/ge/common/formats/format_transfers/format_transfer_fractal_zz.cc index c05eef1d..76e9bd0f 100755 --- a/ge/common/formats/format_transfers/format_transfer_fractal_zz.cc +++ b/ge/common/formats/format_transfers/format_transfer_fractal_zz.cc @@ -39,8 +39,8 @@ bool CheckShape(Format format, const ShapeVector &shape) { case FORMAT_NHWC: return CheckShapeValid(shape, kDimSize4D); default: - std::string error = "Trans format between[" + TypeUtils::FormatToSerialString(format) + - "] and FORMAT_FRACTAL_ZZ is not supported."; + std::string error = "Trans format between " + FmtToStr(TypeUtils::FormatToSerialString(format)) + + " and FORMAT_FRACTAL_ZZ is not supported."; GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); return false; } diff --git a/ge/common/formats/format_transfers/format_transfer_fracz_hwcn.cc b/ge/common/formats/format_transfers/format_transfer_fracz_hwcn.cc index 299cfe2e..347ee2b2 100755 --- a/ge/common/formats/format_transfers/format_transfer_fracz_hwcn.cc +++ b/ge/common/formats/format_transfers/format_transfer_fracz_hwcn.cc @@ -33,9 +33,10 @@ Status CheckArgsForFracZToHwcn(const TransArgs &args) { auto src_shape = args.src_shape; auto dst_shape = args.dst_shape; if (args.src_format != FORMAT_FRACTAL_Z || args.dst_format != FORMAT_HWCN) { - std::string error = "Dose not support trans format from [" + - TypeUtils::FormatToSerialString(args.src_format) + "] to " + "[" + - TypeUtils::FormatToSerialString(args.dst_format) + "]"; + std::string error = "Dose not support trans format from " + + FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + + FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; + GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); return UNSUPPORTED; } if (!CheckDataTypeSupported(args.src_data_type)) { @@ -59,8 +60,10 @@ Status CheckArgsForFracZToHwcn(const TransArgs &args) { int64_t n0 = Ceil(dst_shape.at(kHwcnN), static_cast(kNiSize)); if (src_shape.at(kFracZHWC1) != dst_shape.at(kHwcnH) * dst_shape.at(kHwcnW) * c1 || src_shape.at(kFracZC0) != c0 || src_shape.at(kFracZNi) != kNiSize || src_shape.at(kFracZN0) != n0) { - GELOGE(PARAM_INVALID, "Failed to check relationship between src and dst shape, src shape %s, dst shape %s", - ShapeToString(src_shape).c_str(), ShapeToString(dst_shape).c_str()); + std::string error = "Failed to check relationship between src shape" + + FmtToStr(ShapeToString(src_shape)) + " and dst shape" + + FmtToStr(ShapeToString(dst_shape)) + ; + GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); return PARAM_INVALID; } diff --git a/ge/common/formats/format_transfers/format_transfer_fracz_nchw.cc b/ge/common/formats/format_transfers/format_transfer_fracz_nchw.cc index 042559ca..6639fe11 100755 --- a/ge/common/formats/format_transfers/format_transfer_fracz_nchw.cc +++ b/ge/common/formats/format_transfers/format_transfer_fracz_nchw.cc @@ -33,9 +33,10 @@ Status CheckArgsForFracZToNchw(const TransArgs &args) { auto src_shape = args.src_shape; auto dst_shape = args.dst_shape; if (args.src_format != FORMAT_FRACTAL_Z || args.dst_format != FORMAT_NCHW) { - GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", - TypeUtils::FormatToSerialString(args.src_format).c_str(), - TypeUtils::FormatToSerialString(args.dst_format).c_str()); + std::string error = "Dose not support trans format from " + + FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + + FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; + GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); return UNSUPPORTED; } if (!CheckDataTypeSupported(args.src_data_type)) { diff --git a/ge/common/formats/format_transfers/format_transfer_fracz_nhwc.cc b/ge/common/formats/format_transfers/format_transfer_fracz_nhwc.cc index 98bd1807..b55b7c5e 100755 --- a/ge/common/formats/format_transfers/format_transfer_fracz_nhwc.cc +++ b/ge/common/formats/format_transfers/format_transfer_fracz_nhwc.cc @@ -33,9 +33,10 @@ Status CheckArgsForFracZToNhwc(const TransArgs &args) { auto src_shape = args.src_shape; auto dst_shape = args.dst_shape; if (args.src_format != FORMAT_FRACTAL_Z || args.dst_format != FORMAT_NHWC) { - GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", - TypeUtils::FormatToSerialString(args.src_format).c_str(), - TypeUtils::FormatToSerialString(args.dst_format).c_str()); + std::string error = "Dose not support trans format from " + + FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + + FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; + GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); return UNSUPPORTED; } if (!CheckDataTypeSupported(args.src_data_type)) { diff --git a/ge/common/formats/format_transfers/format_transfer_hwcn_c1hwncoc0.cc b/ge/common/formats/format_transfers/format_transfer_hwcn_c1hwncoc0.cc index d2f8cf30..511a4731 100755 --- a/ge/common/formats/format_transfers/format_transfer_hwcn_c1hwncoc0.cc +++ b/ge/common/formats/format_transfers/format_transfer_hwcn_c1hwncoc0.cc @@ -50,9 +50,10 @@ Status TransShapeHwcnToC1hwncoc0(const DataType &data_type, const std::vector &src_shape, DataType d Status CheckArgsForNchwToNc1hwc0(const TransArgs &args) { if (args.src_format != FORMAT_NCHW || args.dst_format != FORMAT_NC1HWC0) { - GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", - TypeUtils::FormatToSerialString(args.src_format).c_str(), - TypeUtils::FormatToSerialString(args.dst_format).c_str()); + std::string error = "Dose not support trans format from " + + FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + + FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; + GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); return UNSUPPORTED; } std::vector expect_5d_shape; diff --git a/ge/common/formats/format_transfers/format_transfer_nhwc_nc1hwc0.cc b/ge/common/formats/format_transfers/format_transfer_nhwc_nc1hwc0.cc index 3ae7a924..27a7154b 100755 --- a/ge/common/formats/format_transfers/format_transfer_nhwc_nc1hwc0.cc +++ b/ge/common/formats/format_transfers/format_transfer_nhwc_nc1hwc0.cc @@ -51,9 +51,10 @@ Status TransShapeNhwcToNc1hwc0(const std::vector &src_shape, DataType d Status CheckArgsForNhwcToNc1hwc0(const TransArgs &args) { if (args.src_format != FORMAT_NHWC || args.dst_format != FORMAT_NC1HWC0) { - GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", - TypeUtils::FormatToSerialString(args.src_format).c_str(), - TypeUtils::FormatToSerialString(args.dst_format).c_str()); + std::string error = "Dose not support trans format from " + + FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + + FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; + GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); return UNSUPPORTED; } if (!CheckDataTypeSupported(args.src_data_type)) { diff --git a/ge/common/formats/format_transfers/format_transfer_transpose.cc b/ge/common/formats/format_transfers/format_transfer_transpose.cc index 86781e13..b8d800cf 100755 --- a/ge/common/formats/format_transfers/format_transfer_transpose.cc +++ b/ge/common/formats/format_transfers/format_transfer_transpose.cc @@ -223,7 +223,7 @@ Status FormatTransferTranspose::TransFormat(const TransArgs &args, TransResult & if (ret != SUCCESS) { return ret; } - if (!IsTransShapeDstCorrect(args, expect_shape)) { + if (!IsTransShapeDstCorrect(args, expected_shape)) { return PARAM_INVALID; } diff --git a/ge/common/formats/utils/formats_trans_utils.cc b/ge/common/formats/utils/formats_trans_utils.cc index cdf1f363..d18e4e1d 100755 --- a/ge/common/formats/utils/formats_trans_utils.cc +++ b/ge/common/formats/utils/formats_trans_utils.cc @@ -20,6 +20,7 @@ #include "common/formats/utils/formats_definitions.h" #include "framework/common/debug/ge_log.h" +#include "framework/common/debug/log.h" #include "framework/common/ge_inner_error_codes.h" #include "graph/utils/type_utils.h" @@ -58,9 +59,8 @@ int64_t GetItemNumByShape(const std::vector &shape) { bool CheckShapeValid(const std::vector &shape, const int64_t expect_dims) { if (expect_dims <= 0 || shape.size() != static_cast(expect_dims)) { - std::string error = " Invalid shape, dims num [" + std::to_string(shape.size()) + - "], expect [" + std::to_string(expect_dims) + "]"; - TypeUtils::DataTypeToSerialString(data_type) + "] is invalid"; + std::string error = " Invalid shape, dims num " + FmtToStr(shape.size()) + + ", expect " + FmtToStr(expect_dims); GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); return false; } @@ -74,13 +74,12 @@ bool IsShapeValid(const std::vector &shape) { int64_t num = 1; for (auto dim : shape) { if (dim < 0) { - std::string error = "Invalid negative dims in the shape [" + ShapeToString(shape).c_str() + "]"; + std::string error = "Invalid negative dims in the shape " + FmtToStr(ShapeToString(shape)); GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); return false; } if (dim != 0 && kShapeItemNumMAX / dim < num) { - std::string error = "Shape overflow, the total count should be less than [" + - std::to_string(kShapeItemNumMAX) + "]"; + std::string error = "Shape overflow, the total count should be less than " + FmtToStr(kShapeItemNumMAX); GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); return false; } diff --git a/inc/framework/common/debug/log.h b/inc/framework/common/debug/log.h index aaf76621..575779bf 100644 --- a/inc/framework/common/debug/log.h +++ b/inc/framework/common/debug/log.h @@ -271,7 +271,7 @@ } while (0) template -std::string FmtEgStr(const T &t) { +std::string FmtToStr(const T &t) { std::string fmt; std::stringstream st; st << "[" << t << "]";