From 1debfced284b7634449c5e0344d5d9e7214c39d6 Mon Sep 17 00:00:00 2001 From: "wangwenhua1@huawei.com" Date: Tue, 17 Nov 2020 15:29:22 +0800 Subject: [PATCH] error message add format --- ge/common/formats/formats.cc | 26 ---------------- ge/common/formats/formats.h | 4 --- .../formats/utils/formats_trans_utils.cc | 31 +++++++++++++++++-- ge/common/formats/utils/formats_trans_utils.h | 4 +++ 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/ge/common/formats/formats.cc b/ge/common/formats/formats.cc index 32f20536..0b21a884 100755 --- a/ge/common/formats/formats.cc +++ b/ge/common/formats/formats.cc @@ -96,31 +96,5 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool IsTransFormatSupport(const T GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool IsTransDataTypeSupport(const CastArgs &args) { return DataTypeTransferExists(args); } - -GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool IsTransShapeSrcCorrect(const TransArgs &args, std::vector &expect_shape) { - if (!args.src_shape.empty() && args.src_shape != expect_shape) { - std::string error = "Failed to trans format from" + - FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + - FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ", invalid relationship between src shape " + - FmtToStr(ShapeToString(args.src_shape)) + " and dst " + - FmtToStr(ShapeToString(args.dst_shape)); - GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); - return false; - } - return true; -} - -GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool IsTransShapeDstCorrect(const TransArgs &args, std::vector &expect_shape) { - if (!args.dst_shape.empty() && args.dst_shape != expect_shape) { - std::string error = "Failed to trans format from " + - FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + - FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ", the dst shape" + - FmtToStr(ShapeToString(args.dst_shape)) + " is invalid, expect" + - FmtToStr(ShapeToString(expect_shape)); - GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); - return false; - } - return true; -} } // namespace formats } // namespace ge diff --git a/ge/common/formats/formats.h b/ge/common/formats/formats.h index 594bb2f8..52ae84ad 100644 --- a/ge/common/formats/formats.h +++ b/ge/common/formats/formats.h @@ -44,10 +44,6 @@ Status TransDataType(const CastArgs &args, TransResult &result); bool IsTransFormatSupport(const TransArgs &args); bool IsTransDataTypeSupport(const CastArgs &args); - -bool IsTransShapeSrcCorrect(const TransArgs &args, std::vector &expect_shape); - -bool IsTransShapeDstCorrect(const TransArgs &args, std::vector &expect_shape); } // namespace formats } // namespace ge #endif // GE_COMMON_FORMATS_FORMATS_H_ diff --git a/ge/common/formats/utils/formats_trans_utils.cc b/ge/common/formats/utils/formats_trans_utils.cc index d18e4e1d..b48874f0 100755 --- a/ge/common/formats/utils/formats_trans_utils.cc +++ b/ge/common/formats/utils/formats_trans_utils.cc @@ -19,6 +19,7 @@ #include #include "common/formats/utils/formats_definitions.h" +#include "common/util/error_manager/error_manager.h" #include "framework/common/debug/ge_log.h" #include "framework/common/debug/log.h" #include "framework/common/ge_inner_error_codes.h" @@ -30,8 +31,8 @@ int64_t GetCubeSizeByDataType(DataType data_type) { // Current cube does not support 4 bytes and longer data auto size = GetSizeByDataType(data_type); if (size <= 0) { - std::string error = "Failed to get cube size, the data type [" + - TypeUtils::DataTypeToSerialString(data_type) + "] is invalid"; + std::string error = "Failed to get cube size, the data type " + + FmtToStr(TypeUtils::DataTypeToSerialString(data_type)) + " is invalid"; GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); return -1; } else if (size == 1) { @@ -101,6 +102,30 @@ bool IsShapeEqual(const GeShape &src, const GeShape &dst) { return true; } -bool +GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool IsTransShapeSrcCorrect(const TransArgs &args, std::vector &expect_shape) { + if (!args.src_shape.empty() && args.src_shape != expect_shape) { + std::string error = "Failed to trans format from" + + FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + + FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ", invalid relationship between src shape " + + FmtToStr(ShapeToString(args.src_shape)) + " and dst " + + FmtToStr(ShapeToString(args.dst_shape)); + GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); + return false; + } + return true; +} + +GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool IsTransShapeDstCorrect(const TransArgs &args, std::vector &expect_shape) { + if (!args.dst_shape.empty() && args.dst_shape != expect_shape) { + std::string error = "Failed to trans format from " + + FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + + FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ", the dst shape" + + FmtToStr(ShapeToString(args.dst_shape)) + " is invalid, expect" + + FmtToStr(ShapeToString(expect_shape)); + GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); + return false; + } + return true; +} } // namespace formats } // namespace ge diff --git a/ge/common/formats/utils/formats_trans_utils.h b/ge/common/formats/utils/formats_trans_utils.h index a480b814..a6c27d36 100755 --- a/ge/common/formats/utils/formats_trans_utils.h +++ b/ge/common/formats/utils/formats_trans_utils.h @@ -61,6 +61,10 @@ bool IsShapeValid(const std::vector &shape); bool IsShapeEqual(const GeShape &src, const GeShape &dst); +bool IsTransShapeSrcCorrect(const TransArgs &args, std::vector &expect_shape); + +bool IsTransShapeDstCorrect(const TransArgs &args, std::vector &expect_shape); + template T Ceil(T n1, T n2) { if (n1 == 0) {