From 214740e71006cbdb232dfeca02a67fbc775a5116 Mon Sep 17 00:00:00 2001 From: zhangzhaoju Date: Sat, 30 Oct 2021 10:40:50 +0800 Subject: [PATCH] Correcting some error type of log --- .../frontend/operator/cc_implementations.cc | 309 +++++++++--------- 1 file changed, 155 insertions(+), 154 deletions(-) diff --git a/mindspore/ccsrc/frontend/operator/cc_implementations.cc b/mindspore/ccsrc/frontend/operator/cc_implementations.cc index 917a401782..5a5c384dc7 100644 --- a/mindspore/ccsrc/frontend/operator/cc_implementations.cc +++ b/mindspore/ccsrc/frontend/operator/cc_implementations.cc @@ -53,8 +53,8 @@ T InnerScalarAdd(T x, T y) { if constexpr (std::is_integral::value && std::is_signed::value) { T res; if (__builtin_add_overflow(x, y, &res)) { - MS_LOG(EXCEPTION) << "Overflow of the sum of two signed number x: " << std::to_string(x) - << ", y: " << std::to_string(y) << "."; + MS_EXCEPTION(ValueError) << "Overflow of the sum of two signed number x: " << std::to_string(x) + << ", y: " << std::to_string(y) << "."; } return res; } @@ -66,8 +66,8 @@ T InnerScalarSub(T x, T y) { if constexpr (std::is_integral::value && std::is_signed::value) { T res; if (__builtin_sub_overflow(x, y, &res)) { - MS_LOG(EXCEPTION) << "Overflow of the sub of two signed number x: " << std::to_string(x) - << ", y: " << std::to_string(y) << "."; + MS_EXCEPTION(ValueError) << "Overflow of the sub of two signed number x: " << std::to_string(x) + << ", y: " << std::to_string(y) << "."; } return res; } @@ -79,8 +79,8 @@ T InnerScalarMul(T x, T y) { if constexpr (std::is_integral::value && std::is_signed::value) { T res; if (__builtin_mul_overflow(x, y, &res)) { - MS_LOG(EXCEPTION) << "Overflow of the mul of two signed number x: " << std::to_string(x) - << ", y: " << std::to_string(y) << "."; + MS_EXCEPTION(ValueError) << "Overflow of the mul of two signed number x: " << std::to_string(x) + << ", y: " << std::to_string(y) << "."; } return res; } @@ -90,12 +90,12 @@ T InnerScalarMul(T x, T y) { template float InnerScalarDiv(T x, T y) { if (y == 0) { - MS_LOG(EXCEPTION) << "The divisor could not be zero."; + MS_EXCEPTION(ValueError) << "The divisor could not be zero."; } if constexpr (std::is_integral::value && std::is_signed::value) { if (x == std::numeric_limits::min() && static_cast(y) == -1) { - MS_LOG(EXCEPTION) << "Overflow of the div of two signed number x: " << std::to_string(x) - << ", y: " << std::to_string(y) << "."; + MS_EXCEPTION(ValueError) << "Overflow of the div of two signed number x: " << std::to_string(x) + << ", y: " << std::to_string(y) << "."; } } return static_cast(x) / static_cast(y); @@ -110,15 +110,15 @@ T InnerScalarFloordiv(T x, T y) { template T InnerScalarMod(T x, T y) { if (y == 0) { - MS_LOG(EXCEPTION) << "Could not mod to zero."; + MS_EXCEPTION(ValueError) << "Could not mod to zero."; } if constexpr (!std::is_integral::value) { return x - y * std::floor(x / y); } if constexpr (std::is_signed::value) { if (x == std::numeric_limits::min() && static_cast(y) == -1) { - MS_LOG(EXCEPTION) << "Overflow of the mod of two signed number x: " << std::to_string(x) - << ", y: " << std::to_string(y) << "."; + MS_EXCEPTION(ValueError) << "Overflow of the mod of two signed number x: " << std::to_string(x) + << ", y: " << std::to_string(y) << "."; } } return static_cast(x) % static_cast(y); @@ -161,66 +161,67 @@ bool InnerScalarGe(T x, U y) { return x >= y; } -#define SCALAR_OP(op_t) \ - ValuePtr Scalar##op_t(const ValuePtrList &list) { \ - if (list.size() < 2) { \ - MS_LOG(EXCEPTION) << "The length of input list for Scalar" << #op_t << " is less than 2."; \ - } \ - const ValuePtr &x = list[0]; \ - const ValuePtr &y = list[1]; \ - MS_EXCEPTION_IF_NULL(x); \ - MS_EXCEPTION_IF_NULL(y); \ - if (x->isa() && y->isa()) { \ - double sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - float sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - int sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - float sum = InnerScalar##op_t(IntToFloat(GetValue(x)), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - float sum = InnerScalar##op_t(GetValue(x), IntToFloat(GetValue(y))); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - int64_t sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - double sum = InnerScalar##op_t(LongToDouble(GetValue(x)), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - double sum = InnerScalar##op_t(LongToDouble(GetValue(x)), FloatToDouble(GetValue(y))); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - int64_t sum = InnerScalar##op_t(GetValue(x), IntToLong(GetValue(y))); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - double sum = InnerScalar##op_t(FloatToDouble(GetValue(x)), LongToDouble(GetValue(y))); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - double sum = InnerScalar##op_t(GetValue(x), LongToDouble(GetValue(y))); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - int64_t sum = InnerScalar##op_t(IntToLong(GetValue(x)), GetValue(y)); \ - return MakeValue(sum); \ - } \ - MS_LOG(EXCEPTION) << "Unsupported input type for Scalar" << #op_t << ", type of x:" << x->type_name() \ - << ", value of x:" << x->ToString() << ", type of y:" << y->type_name() \ - << ", value of y:" << y->ToString(); \ +#define SCALAR_OP(op_t) \ + ValuePtr Scalar##op_t(const ValuePtrList &list) { \ + constexpr size_t kListInputSize = 2; \ + if (list.size() != kListInputSize) { \ + MS_EXCEPTION(NotSupportError) << "Input number of Scalar" << #op_t << " should be 2, but got " << list.size(); \ + } \ + const ValuePtr &x = list[0]; \ + const ValuePtr &y = list[1]; \ + MS_EXCEPTION_IF_NULL(x); \ + MS_EXCEPTION_IF_NULL(y); \ + if (x->isa() && y->isa()) { \ + double sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + float sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + int sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + float sum = InnerScalar##op_t(IntToFloat(GetValue(x)), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + float sum = InnerScalar##op_t(GetValue(x), IntToFloat(GetValue(y))); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + int64_t sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + double sum = InnerScalar##op_t(LongToDouble(GetValue(x)), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + double sum = InnerScalar##op_t(LongToDouble(GetValue(x)), FloatToDouble(GetValue(y))); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + int64_t sum = InnerScalar##op_t(GetValue(x), IntToLong(GetValue(y))); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + double sum = InnerScalar##op_t(FloatToDouble(GetValue(x)), LongToDouble(GetValue(y))); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + double sum = InnerScalar##op_t(GetValue(x), LongToDouble(GetValue(y))); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + int64_t sum = InnerScalar##op_t(IntToLong(GetValue(x)), GetValue(y)); \ + return MakeValue(sum); \ + } \ + MS_EXCEPTION(TypeError) << "Unsupported input type for Scalar" << #op_t << ", type of x:" << x->type_name() \ + << ", value of x:" << x->ToString() << ", type of y:" << y->type_name() \ + << ", value of y:" << y->ToString(); \ } SCALAR_OP(Add) @@ -231,75 +232,75 @@ SCALAR_OP(Mod) SCALAR_OP(Pow) SCALAR_OP(Floordiv) -#define LOGIC_OP(op_t) \ - ValuePtr Scalar##op_t(const ValuePtrList &list) { \ - constexpr size_t kListInputSize = 2; \ - if (list.size() < kListInputSize) { \ - MS_LOG(EXCEPTION) << "The length of input list for Scalar" << #op_t << " is less than 2."; \ - } \ - const ValuePtr &x = list[0]; \ - const ValuePtr &y = list[1]; \ - MS_EXCEPTION_IF_NULL(x); \ - MS_EXCEPTION_IF_NULL(y); \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - MS_LOG(EXCEPTION) << "Unsupported input type for Scalar" << #op_t << ", type of x:" << x->type_name() \ - << ", value of x:" << x->ToString() << ", type of y:" << y->type_name() \ - << ", value of y:" << y->ToString(); \ +#define LOGIC_OP(op_t) \ + ValuePtr Scalar##op_t(const ValuePtrList &list) { \ + constexpr size_t kListInputSize = 2; \ + if (list.size() != kListInputSize) { \ + MS_EXCEPTION(NotSupportError) << "Input number of Scalar" << #op_t << " should be 2, but got " << list.size(); \ + } \ + const ValuePtr &x = list[0]; \ + const ValuePtr &y = list[1]; \ + MS_EXCEPTION_IF_NULL(x); \ + MS_EXCEPTION_IF_NULL(y); \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + MS_EXCEPTION(TypeError) << "Unsupported input type for Scalar" << #op_t << ", type of x:" << x->type_name() \ + << ", value of x:" << x->ToString() << ", type of y:" << y->type_name() \ + << ", value of y:" << y->ToString(); \ } LOGIC_OP(Eq) @@ -311,7 +312,7 @@ LOGIC_OP(Ge) ValuePtr ScalarUAdd(const ValuePtrList &list) { if (list.size() != 1) { - MS_LOG(EXCEPTION) << "Input number of ScalarUAdd should be 1, but got " << list.size(); + MS_EXCEPTION(NotSupportError) << "Input number of ScalarUAdd should be 1, but got " << list.size(); } ValuePtr x = list[0]; MS_EXCEPTION_IF_NULL(x); @@ -320,7 +321,7 @@ ValuePtr ScalarUAdd(const ValuePtrList &list) { ValuePtr ScalarUSub(const ValuePtrList &list) { if (list.size() != 1) { - MS_LOG(EXCEPTION) << "Input number of ScalarUSub should be 1, but got " << list.size(); + MS_EXCEPTION(NotSupportError) << "Input number of ScalarUSub should be 1, but got " << list.size(); } ValuePtr x = list[0]; MS_EXCEPTION_IF_NULL(x); @@ -338,12 +339,12 @@ ValuePtr ScalarUSub(const ValuePtrList &list) { return MakeValue(sum); } - MS_LOG(EXCEPTION) << "Unsupported Value for ScalarUSub, x: " << x->ToString() << "."; + MS_EXCEPTION(NotSupportError) << "Not support ScalarUSub [x:" << x->ToString() << "]."; } ValuePtr ScalarLog(const ValuePtrList &list) { if (list.size() != 1) { - MS_LOG(EXCEPTION) << "Input number of ScalarLog should be 1, but got " << list.size(); + MS_EXCEPTION(NotSupportError) << "Input number of ScalarLog must be 1, but got " << list.size(); } ValuePtr x = list[0]; MS_EXCEPTION_IF_NULL(x); @@ -357,12 +358,12 @@ ValuePtr ScalarLog(const ValuePtrList &list) { return MakeValue(v); } - MS_LOG(EXCEPTION) << "Unsupported Value for ScalarLog, x: " << x->ToString(); + MS_EXCEPTION(NotSupportError) << "Not support ScalarLog [x:" << x->ToString() << "]."; } ValuePtr BoolNot(const ValuePtrList &list) { if (list.size() != 1) { - MS_LOG(EXCEPTION) << "Input number of BoolNot should be 1, but got " << list.size(); + MS_EXCEPTION(NotSupportError) << "Input number of BoolNot must be 1, but got " << list.size(); } ValuePtr x = list[0]; MS_EXCEPTION_IF_NULL(x); @@ -373,13 +374,13 @@ ValuePtr BoolNot(const ValuePtrList &list) { return MakeValue(res); } - MS_LOG(EXCEPTION) << "Unsupported Value for BoolNot, x: " << x->ToString(); + MS_EXCEPTION(NotSupportError) << "Not support BoolNot [x:" << x->ToString() << "]."; } ValuePtr BoolAnd(const ValuePtrList &list) { constexpr size_t kListInputSize = 2; if (list.size() != kListInputSize) { - MS_LOG(EXCEPTION) << "Input number of BoolAnd must be 2, but got " << list.size(); + MS_EXCEPTION(NotSupportError) << "Input number of BoolAnd must be 2, but got " << list.size(); } ValuePtr x = list[0]; ValuePtr y = list[1]; @@ -393,13 +394,13 @@ ValuePtr BoolAnd(const ValuePtrList &list) { return MakeValue(res); } - MS_LOG(EXCEPTION) << "Unsupported Value for BoolAnd, x: " << x->ToString() << " y: " << y->ToString() << "."; + MS_EXCEPTION(NotSupportError) << "Not support [x:" << x->ToString() << "] BoolAnd [y:" << y->ToString(); } ValuePtr BoolOr(const ValuePtrList &list) { constexpr size_t kListInputSize = 2; if (list.size() != kListInputSize) { - MS_LOG(EXCEPTION) << "Input number of BoolOr must be 2, but got " << list.size(); + MS_EXCEPTION(NotSupportError) << "Input number of BoolOr must be 2, but got " << list.size(); } ValuePtr x = list[0]; ValuePtr y = list[1]; @@ -413,13 +414,13 @@ ValuePtr BoolOr(const ValuePtrList &list) { return MakeValue(res); } - MS_LOG(EXCEPTION) << "Unsupported Value for BoolOr, x: " << x->ToString() << " y: " << y->ToString() << "."; + MS_EXCEPTION(NotSupportError) << "Not support [x:" << x->ToString() << "] BoolOr [y:" << y->ToString() << "]."; } ValuePtr BoolEq(const ValuePtrList &list) { constexpr size_t kListInputSize = 2; if (list.size() != kListInputSize) { - MS_LOG(EXCEPTION) << "Input number of BoolEq must be 2, but got " << list.size(); + MS_EXCEPTION(NotSupportError) << "Input number of BoolEq must be 2, but got " << list.size(); } ValuePtr x = list[0]; ValuePtr y = list[1]; @@ -433,7 +434,7 @@ ValuePtr BoolEq(const ValuePtrList &list) { return MakeValue(res); } - MS_LOG(EXCEPTION) << "Unsupported Value for BoolEq, x: " << x->ToString() << " y: " << y->ToString() << "."; + MS_EXCEPTION(NotSupportError) << "Not support [x:" << x->ToString() << "] BoolEq [y:" << y->ToString() << "]."; } } // namespace prim } // namespace mindspore