diff --git a/paddle/cinn/hlir/op/elementwise.cc b/paddle/cinn/hlir/op/elementwise.cc index 544a13621cc3b..3b67c1444cdad 100644 --- a/paddle/cinn/hlir/op/elementwise.cc +++ b/paddle/cinn/hlir/op/elementwise.cc @@ -74,8 +74,12 @@ std::shared_ptr StrategyForElementwise( const PeFunc &pe_func) { framework::CINNCompute unary_compute([=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) << "The input argument of " << op_name - << " compute is empty! Please check."; + PADDLE_ENFORCE_EQ( + !args.empty(), + true, + phi::errors::InvalidArgument("The input argument of %s compute is " + "empty! Please check.", + op_name)); CINNValuePack pack_args = args[0]; PADDLE_ENFORCE_GE( @@ -91,10 +95,17 @@ std::shared_ptr StrategyForElementwise( phi::errors::InvalidArgument("the size of pack_args should be" "equal to 2, but got %d.", pack_args.size())); - CHECK(pack_args[1].is_string()); + PADDLE_ENFORCE_EQ(pack_args[1].is_string(), + true, + phi::errors::InvalidArgument( + "the type of pack_args[1] should be string!" + "Please check.")); std::string tensor_name = pack_args[1].operator std::string(); Expr A_expr = pack_args[0]; - CHECK(A_expr.as_tensor()); + PADDLE_ENFORCE( + A_expr.as_tensor(), + phi::errors::InvalidArgument("The pack_args[0] should be tensor!" + "Please check.")); ir::Tensor A = A_expr.as_tensor_ref(); auto out = pe_func(A, tensor_name); std::vector res; @@ -122,8 +133,12 @@ std::shared_ptr StrategyForElementwiseSymbolic( const PeFunc &pe_func) { framework::CINNCompute unary_compute([=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) << "The input argument of " << op_name - << " compute is empty! Please check."; + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input argument of %s compute is empty!" + "Please check.", + op_name)); CINNValuePack pack_args = args[0]; PADDLE_ENFORCE_GE( pack_args.size(), @@ -138,10 +153,16 @@ std::shared_ptr StrategyForElementwiseSymbolic( phi::errors::InvalidArgument("the size of pack_args should be " "equal to 2, but got %d.", pack_args.size())); - CHECK(pack_args[1].is_string()); + PADDLE_ENFORCE_EQ(pack_args[1].is_string(), + true, + phi::errors::InvalidArgument( + "the type of pack_args[1] should be string!" + "Please check.")); std::string tensor_name = pack_args[1].operator std::string(); Expr A_expr = pack_args[0]; - CHECK(A_expr.as_tensor()); + PADDLE_ENFORCE(A_expr.as_tensor(), + phi::errors::InvalidArgument("The pack_args[0] should be " + "tensor! Please check.")); ir::Tensor A = A_expr.as_tensor_ref(); auto out = pe_func(A, tensor_name); std::vector res; @@ -178,13 +199,21 @@ std::shared_ptr StrategyForScale( } framework::CINNCompute scale_compute( [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input arguments of scale compute is empty! Please check."; + PADDLE_ENFORCE_EQ( + !args.empty(), + true, + phi::errors::InvalidArgument("The input argument of scale compute " + "is empty! Please check.")); CINNValuePack pack_args = args[0]; - CHECK(!pack_args.empty()) - << "The input tensors of scale compute is empty! Please check."; + PADDLE_ENFORCE_EQ( + !pack_args.empty(), + true, + phi::errors::InvalidArgument("The input tensors of scale compute " + "is empty! Please check.")); Expr A_expr = pack_args[0]; - CHECK(A_expr.as_tensor()); + PADDLE_ENFORCE(A_expr.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] is not a tensor! Please check.")); ir::Tensor A = A_expr.as_tensor_ref(); ir::Tensor out; PADDLE_ENFORCE_EQ( @@ -193,7 +222,11 @@ std::shared_ptr StrategyForScale( phi::errors::InvalidArgument("the size of pack_args should be " "equal to 2, but got %d.", pack_args.size())); - CHECK(pack_args[1].is_string()); + PADDLE_ENFORCE_EQ(pack_args[1].is_string(), + true, + phi::errors::InvalidArgument( + "the type of pack_args[1] should be string! " + "Please check.")); std::string tensor_name = pack_args[1].operator std::string(); // Paddle upscale float16 or bfloat16 compute to float32, @@ -254,13 +287,21 @@ std::shared_ptr StrategyForScaleSymbolic( } framework::CINNCompute scale_compute( [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input arguments of scale compute is empty! Please check."; + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input argument of scale compute is empty! " + "Please check.")); CINNValuePack pack_args = args[0]; - CHECK(!pack_args.empty()) - << "The input tensors of scale compute is empty! Please check."; + PADDLE_ENFORCE_EQ(!pack_args.empty(), + true, + phi::errors::InvalidArgument( + "The input tensors of scale compute is empty! " + "Please check.")); Expr A_expr = pack_args[0]; - CHECK(A_expr.as_tensor()); + PADDLE_ENFORCE(A_expr.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] is not a tensor! Please check.")); ir::Tensor A = A_expr.as_tensor_ref(); ir::Tensor out; PADDLE_ENFORCE_EQ( @@ -269,7 +310,11 @@ std::shared_ptr StrategyForScaleSymbolic( phi::errors::InvalidArgument("the size of pack_args should be " "equal to 2, but got %d.", pack_args.size())); - CHECK(pack_args[1].is_string()); + PADDLE_ENFORCE_EQ(pack_args[1].is_string(), + true, + phi::errors::InvalidArgument( + "the type of pack_args[1] should be string! " + "Please check.")); std::string tensor_name = pack_args[1].operator std::string(); // Paddle upscale float16 or bfloat16 compute to float32, @@ -363,8 +408,12 @@ std::shared_ptr StrategyForConstScalar( const Target &target) { framework::CINNCompute const_scalar_compute([=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input argument of const_float compute is empty! Please check."; + PADDLE_ENFORCE_EQ( + !args.empty(), + true, + phi::errors::InvalidArgument( + "The input argument of const_scalar compute is empty! " + "Please check.")); auto scalar = GetScalarExpr(attrs.attr_store.at("value")); auto scalar_type = out_type.at(0); CINNValuePack pack_args = args[0]; @@ -374,7 +423,11 @@ std::shared_ptr StrategyForConstScalar( phi::errors::InvalidArgument("the size of pack_args should be " "equal to 1, but got %d.", pack_args.size())); - CHECK(pack_args[0].is_string()); + PADDLE_ENFORCE_EQ(pack_args[0].is_string(), + true, + phi::errors::InvalidArgument( + "the type of pack_args[0] should be string! " + "Please check.")); std::string tensor_name = pack_args[0].operator std::string(); auto out = lang::Compute( @@ -386,8 +439,11 @@ std::shared_ptr StrategyForConstScalar( return res; }, tensor_name); - CHECK(out.defined()) << "can't create const scalar with the given type " - << out_type[0]; + PADDLE_ENFORCE_EQ( + out.defined(), + true, + phi::errors::InvalidArgument( + "can't create const scalar with the given type %s", out_type[0])); *ret = CINNValuePack{{CINNValue(out)}}; }); @@ -417,46 +473,73 @@ std::shared_ptr StrategyForFillConstant( const std::vector &out_type, const std::vector> &output_shapes, const Target &target) { - framework::CINNCompute fill_constant_compute( - [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) << "The input argument of fill_constant compute " - "is empty! Please check."; - bool force_cpu = false; - CHECK(attrs.attr_store.count("shape")); - auto shape = absl::get>(attrs.attr_store.at("shape")); - CHECK(attrs.attr_store.count("value")); - auto value = GetScalarExpr(attrs.attr_store.at("value")); - CHECK(attrs.attr_store.count("force_cpu")); - force_cpu = absl::get(attrs.attr_store.at("force_cpu")); - - if (force_cpu && target != cinn::common::DefaultHostTarget()) { - LOG(WARNING) << "The attribute \"force_cpu\" of \"fill_constant\" " - "not supported in CINN! The \"fill_constant\"'s " - "output tensor will placed on " - << target; - } - - CINNValuePack arg_pack = args[0]; - PADDLE_ENFORCE_EQ( - arg_pack.size(), - 1U, - phi::errors::InvalidArgument("the size of arg_pack should be " - "equal to 1, but got %d.", - arg_pack.size())); - CHECK(arg_pack[0].is_string()); - std::string tensor_name = arg_pack[0].operator std::string(); - CHECK(!shape.empty()) << "shape attr is empty!"; - auto shape_exprs = ToCinnExprs(shape); - auto out = lang::Compute( - shape_exprs, - [=](const std::vector &indice) { - return ir::Cast::Make(out_type[0], value); - }, - tensor_name); - CHECK(out.defined()) - << "can't create fill_constant with the given type " << out_type[0]; - *ret = CINNValuePack{{CINNValue(out)}}; - }); + framework::CINNCompute fill_constant_compute([=](lang::Args args, + lang::RetValue *ret) { + PADDLE_ENFORCE_EQ( + !args.empty(), + true, + phi::errors::InvalidArgument("The input argument of fill_constant " + "compute is empty! Please check.")); + bool force_cpu = false; + PADDLE_ENFORCE_EQ( + attrs.attr_store.count("shape"), + true, + phi::errors::InvalidArgument( + "The attribute \"shape\" of \"fill_constant\" is not found! " + "Please check.")); + auto shape = absl::get>(attrs.attr_store.at("shape")); + PADDLE_ENFORCE_EQ( + attrs.attr_store.count("value"), + true, + phi::errors::InvalidArgument( + "The attribute \"value\" of \"fill_constant\" is not found! " + "Please check.")); + auto value = GetScalarExpr(attrs.attr_store.at("value")); + PADDLE_ENFORCE_EQ( + attrs.attr_store.count("force_cpu"), + true, + phi::errors::InvalidArgument( + "The attribute \"force_cpu\" of \"fill_constant\" is not found! " + "Please check.")); + force_cpu = absl::get(attrs.attr_store.at("force_cpu")); + + if (force_cpu && target != cinn::common::DefaultHostTarget()) { + LOG(WARNING) << "The attribute \"force_cpu\" of \"fill_constant\" " + "not supported in CINN! The \"fill_constant\"'s " + "output tensor will placed on " + << target; + } + + CINNValuePack arg_pack = args[0]; + PADDLE_ENFORCE_EQ( + arg_pack.size(), + 1U, + phi::errors::InvalidArgument("the size of arg_pack should be " + "equal to 1, but got %d.", + arg_pack.size())); + PADDLE_ENFORCE_EQ(arg_pack[0].is_string(), + true, + phi::errors::InvalidArgument( + "the type of arg_pack[0] should be string! " + "Please check.")); + std::string tensor_name = arg_pack[0].operator std::string(); + PADDLE_ENFORCE_EQ(!shape.empty(), + true, + phi::errors::InvalidArgument("shape attr is empty!")); + auto shape_exprs = ToCinnExprs(shape); + auto out = lang::Compute( + shape_exprs, + [=](const std::vector &indice) { + return ir::Cast::Make(out_type[0], value); + }, + tensor_name); + PADDLE_ENFORCE_EQ( + out.defined(), + true, + phi::errors::InvalidArgument( + "can't create fill_constant with the given type %s", out_type[0])); + *ret = CINNValuePack{{CINNValue(out)}}; + }); auto strategy = std::make_shared(); strategy->AddImpl(fill_constant_compute, @@ -473,45 +556,66 @@ std::shared_ptr StrategyForFillConstantSymbolic( const std::vector &out_type, const std::vector> &output_shapes, const Target &target) { - framework::CINNCompute fill_constant_compute( - [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) << "The input argument of fill_constant compute " - "is empty! Please check."; - bool force_cpu = false; - auto shape = output_shapes[0]; - CHECK(attrs.attr_store.count("value")); - auto value = GetScalarExpr(attrs.attr_store.at("value")); - CHECK(attrs.attr_store.count("force_cpu")); - force_cpu = absl::get(attrs.attr_store.at("force_cpu")); - - if (force_cpu && target != cinn::common::DefaultHostTarget()) { - LOG(WARNING) << "The attribute \"force_cpu\" of \"fill_constant\" " - "not supported in CINN! The \"fill_constant\"'s " - "output tensor will placed on " - << target; - } - - CINNValuePack arg_pack = args[0]; - PADDLE_ENFORCE_EQ( - arg_pack.size(), - 1U, - phi::errors::InvalidArgument("the size of arg_pack should be " - "equal to 1, but got %d.", - arg_pack.size())); - CHECK(arg_pack[0].is_string()); - std::string tensor_name = arg_pack[0].operator std::string(); - CHECK(!shape.empty()) << "shape attr is empty!"; - auto shape_exprs = ToCinnExprs(shape); - auto out = lang::Compute( - shape_exprs, - [=](const std::vector &indice) { - return ir::Cast::Make(out_type[0], value); - }, - tensor_name); - CHECK(out.defined()) - << "can't create fill_constant with the given type " << out_type[0]; - *ret = CINNValuePack{{CINNValue(out)}}; - }); + framework::CINNCompute fill_constant_compute([=](lang::Args args, + lang::RetValue *ret) { + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input argument of fill_constant compute " + "is empty! Please check.")); + bool force_cpu = false; + auto shape = output_shapes[0]; + PADDLE_ENFORCE_EQ(attrs.attr_store.count("value"), + true, + phi::errors::InvalidArgument( + "The attribute \"value\" of \"fill_constant\" " + "is not found! Please check.")); + auto value = GetScalarExpr(attrs.attr_store.at("value")); + PADDLE_ENFORCE_EQ(attrs.attr_store.count("force_cpu"), + true, + phi::errors::InvalidArgument( + "The attribute \"force_cpu\" of \"fill_constant\" " + "is not found! Please check.")); + force_cpu = absl::get(attrs.attr_store.at("force_cpu")); + + if (force_cpu && target != cinn::common::DefaultHostTarget()) { + LOG(WARNING) << "The attribute \"force_cpu\" of \"fill_constant\" " + "not supported in CINN! The \"fill_constant\"'s " + "output tensor will placed on " + << target; + } + + CINNValuePack arg_pack = args[0]; + PADDLE_ENFORCE_EQ( + arg_pack.size(), + 1U, + phi::errors::InvalidArgument("the size of arg_pack should be " + "equal to 1, but got %d.", + arg_pack.size())); + PADDLE_ENFORCE_EQ(arg_pack[0].is_string(), + true, + phi::errors::InvalidArgument( + "the type of arg_pack[0] should be string! " + "Please check.")); + std::string tensor_name = arg_pack[0].operator std::string(); + PADDLE_ENFORCE_EQ(!shape.empty(), + true, + phi::errors::InvalidArgument("shape attr is empty!")); + auto shape_exprs = ToCinnExprs(shape); + auto out = lang::Compute( + shape_exprs, + [=](const std::vector &indice) { + return ir::Cast::Make(out_type[0], value); + }, + tensor_name); + PADDLE_ENFORCE_EQ(out.defined(), + true, + phi::errors::InvalidArgument( + "can't create fill_constant with the given type " + "%s", + out_type[0])); + *ret = CINNValuePack{{CINNValue(out)}}; + }); auto strategy = std::make_shared(); strategy->AddImpl(fill_constant_compute, @@ -537,10 +641,17 @@ std::shared_ptr StrategyForAssignValue( const Target &target) { framework::CINNCompute assign_value_compute([=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input argument of assign_value compute is empty! Please check."; - CHECK(attrs.attr_store.count("values")) - << "assign_value should set attribute [values]! Please check."; + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input argument of assign_value compute is " + "empty! Please check.")); + PADDLE_ENFORCE_EQ( + attrs.attr_store.count("values"), + true, + phi::errors::InvalidArgument( + "The attribute \"values\" of \"assign_value\" is not found! " + "Please check.")); const auto &value = attrs.attr_store.at("values"); CINNValuePack arg_pack = args[0]; @@ -550,7 +661,11 @@ std::shared_ptr StrategyForAssignValue( phi::errors::InvalidArgument("the size of arg_pack should be " "equal to 1, but got %d.", arg_pack.size())); - CHECK(arg_pack[0].is_string()); + PADDLE_ENFORCE_EQ(arg_pack[0].is_string(), + true, + phi::errors::InvalidArgument( + "the type of arg_pack[0] should be string! " + "Please check.")); std::string tensor_name = arg_pack[0].operator std::string(); absl::optional out; @@ -574,8 +689,10 @@ std::shared_ptr StrategyForAssignValue( } #undef EXPAND_VALUE_TO_TENSOR - CHECK(out && out.value().defined()) - << "can't create assign_value with the given type " << out_type[0]; + PADDLE_ENFORCE( + out.has_value(), + phi::errors::InvalidArgument( + "can't create assign_value with the given type %s", out_type[0])); *ret = CINNValuePack{{CINNValue(Expr(out.value().get()))}}; }); @@ -645,8 +762,11 @@ std::shared_ptr StrategyForSqueeze( framework::CINNCompute squeeze_compute([=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input arguments of Squeeze compute is empty! Please check.\n"; + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input arguments of Squeeze compute is empty! " + "Please check.")); CINNValuePack pack_args = args[0]; PADDLE_ENFORCE_GE( pack_args.size(), @@ -655,8 +775,14 @@ std::shared_ptr StrategyForSqueeze( "equal to 1, but got %d.", pack_args.size())); Expr A = pack_args[0]; - CHECK(A.as_tensor()); - CHECK(!output_shapes.empty()); + PADDLE_ENFORCE(A.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] should be tensor! Please check.")); + PADDLE_ENFORCE_EQ( + !output_shapes.empty(), + true, + phi::errors::InvalidArgument( + "The output_shapes of Squeeze is empty! Please check.")); auto tensor_A = A.as_tensor_ref(); VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") << ", output_shapes: " << utils::Join(output_shapes[0], ", "); @@ -672,8 +798,10 @@ std::shared_ptr StrategyForSqueeze( ir::Tensor out = pe::Squeeze(tensor_A, axes, tensor_name); std::vector res; res.push_back(CINNValue(out)); - CHECK(!out_type.empty()) - << "Output type of Squeeze is empty! Please check.\n"; + PADDLE_ENFORCE_EQ(!out_type.empty(), + true, + phi::errors::InvalidArgument( + "Output type of Squeeze is empty! Please check.")); *ret = CINNValuePack{res}; }); @@ -698,7 +826,11 @@ std::shared_ptr StrategyForExpandDims( framework::CINNCompute expand_dims_compute{[=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) << "The input args are empty! Please check again."; + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input arguments of ExpandDims compute is empty! " + "Please check.")); CINNValuePack input_args = args[0]; int input_size = input_args.size(); PADDLE_ENFORCE_GE( @@ -708,7 +840,9 @@ std::shared_ptr StrategyForExpandDims( "the input_size should be greater than or equal to 1, but got %d", input_size)); Expr x = input_args[0]; - CHECK(x.as_tensor()); + PADDLE_ENFORCE(x.as_tensor(), + phi::errors::InvalidArgument( + "The input_args[0] should be tensor! Please check.")); PADDLE_ENFORCE_EQ( input_args.size(), @@ -716,7 +850,11 @@ std::shared_ptr StrategyForExpandDims( phi::errors::InvalidArgument("the size of input_args should be " "equal to 2, but got %d.", input_args.size())); - CHECK(input_args[1].is_string()); + PADDLE_ENFORCE_EQ(input_args[1].is_string(), + true, + phi::errors::InvalidArgument( + "the type of input_args[1] should be string! " + "Please check.")); std::string tensor_name = input_args[1].operator std::string(); auto out = @@ -742,8 +880,11 @@ std::shared_ptr StrategyForReshape( const Target &target) { framework::CINNCompute reshape_compute([=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input arguments of Reshape compute is empty! Please check.\n"; + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input arguments of Reshape compute is empty! " + "Please check.")); CINNValuePack pack_args = args[0]; PADDLE_ENFORCE_GE(pack_args.size(), 1U, @@ -752,10 +893,17 @@ std::shared_ptr StrategyForReshape( "equal to 1, but got %d.", pack_args.size())); Expr A = pack_args[0]; - CHECK(A.as_tensor()); - CHECK(!output_shapes.empty()); + PADDLE_ENFORCE(A.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] should be tensor! Please check.")); + PADDLE_ENFORCE_EQ( + !output_shapes.empty(), + true, + phi::errors::InvalidArgument( + "The output_shapes of Reshape is empty! Please check.")); auto attr_store = attrs.attr_store; - CHECK(attr_store.count("shape")) << "find no attr of shape"; + PADDLE_ENFORCE(attr_store.count("shape"), + phi::errors::InvalidArgument("find no attr of shape")); std::vector new_shape = absl::get>(attr_store.at("shape")); auto tensor_A = A.as_tensor_ref(); @@ -768,14 +916,20 @@ std::shared_ptr StrategyForReshape( "the size of pack_args should be greater than or " "equal to 2, but got %d.", pack_args.size())); - CHECK(pack_args[1].is_string()); + PADDLE_ENFORCE_EQ(pack_args[1].is_string(), + true, + phi::errors::InvalidArgument( + "the type of pack_args[1] should be string! " + "Please check.")); std::string tensor_name = pack_args[1].operator std::string(); ir::Tensor out = pe::Reshape(tensor_A, output_shapes[0], tensor_name); std::vector res; res.push_back(CINNValue(out)); - CHECK(!out_type.empty()) - << "Output type of Reshape is empty! Please check.\n"; + PADDLE_ENFORCE_EQ(!out_type.empty(), + true, + phi::errors::InvalidArgument( + "Output type of Reshape is empty! Please check.")); *ret = CINNValuePack{res}; }); @@ -796,8 +950,11 @@ std::shared_ptr StrategyForReshapeSymbolic( const Target &target) { framework::CINNCompute reshape_compute([=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input arguments of Reshape compute is empty! Please check.\n"; + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input arguments of Reshape compute is empty! " + "Please check.")); CINNValuePack pack_args = args[0]; PADDLE_ENFORCE_GE(pack_args.size(), 1U, @@ -806,26 +963,42 @@ std::shared_ptr StrategyForReshapeSymbolic( "equal to 1, but got %d.", pack_args.size())); Expr A = pack_args[0]; - CHECK(A.as_tensor()); - CHECK(!output_shapes.empty()); + PADDLE_ENFORCE(A.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] should be tensor! Please check.")); + PADDLE_ENFORCE_EQ( + !output_shapes.empty(), + true, + phi::errors::InvalidArgument( + "The output_shapes of Reshape is empty! Please check.")); auto tensor_A = A.as_tensor_ref(); VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") << ", output_shapes: " << utils::Join(output_shapes[0], ", "); std::string tensor_name; if (pack_args.size() == 4 || pack_args.size() == 3) { - CHECK(pack_args[2].is_string()); + PADDLE_ENFORCE_EQ(pack_args[2].is_string(), + true, + phi::errors::InvalidArgument( + "the type of pack_args[2] should be string! " + "Please check.")); tensor_name = pack_args[2].operator std::string(); } else { - CHECK(pack_args[1].is_string()); + PADDLE_ENFORCE_EQ(pack_args[1].is_string(), + true, + phi::errors::InvalidArgument( + "the type of pack_args[1] should be string! " + "Please check.")); tensor_name = pack_args[1].operator std::string(); } ir::Tensor out = pe::Reshape(tensor_A, output_shapes[0], tensor_name); std::vector res; res.push_back(CINNValue(out)); - CHECK(!out_type.empty()) - << "Output type of Reshape is empty! Please check.\n"; + PADDLE_ENFORCE_EQ(!out_type.empty(), + true, + phi::errors::InvalidArgument( + "Output type of Reshape is empty! Please check.")); *ret = CINNValuePack{res}; }); @@ -842,37 +1015,47 @@ std::shared_ptr StrategyForCast( const std::vector &out_type, const std::vector> &output_shapes, const Target &target) { - framework::CINNCompute cast_compute( - [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input arguments of Cast compute is empty! Please check.\n"; - CINNValuePack pack_args = args[0]; - PADDLE_ENFORCE_GE(pack_args.size(), - 1U, - phi::errors::InvalidArgument( - "the size of pack_args should be greater than or " - "equal to 1, but got %d.", - pack_args.size())); - Expr A = pack_args[0]; - CHECK(A.as_tensor()); - CHECK(!output_shapes.empty()); - auto tensor_A = A.as_tensor_ref(); - VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") - << ", output_shapes: " << utils::Join(output_shapes[0], ", "); - PADDLE_ENFORCE_EQ( - pack_args.size(), - 2U, - phi::errors::InvalidArgument("the size of pack_args should be " - "equal to 2, but got %d.", - pack_args.size())); - std::string tensor_name = pack_args[1].operator std::string(); - ir::Tensor out = pe::Cast(tensor_A, out_type[0], tensor_name); - std::vector res; - res.push_back(CINNValue(out)); - CHECK(!out_type.empty()) - << "Output type of Cast is empty! Please check.\n"; - *ret = CINNValuePack{res}; - }); + framework::CINNCompute cast_compute([=](lang::Args args, + lang::RetValue *ret) { + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input arguments of Cast compute is empty! " + "Please check.")); + CINNValuePack pack_args = args[0]; + PADDLE_ENFORCE_GE(pack_args.size(), + 1U, + phi::errors::InvalidArgument( + "the size of pack_args should be greater than or " + "equal to 1, but got %d.", + pack_args.size())); + Expr A = pack_args[0]; + PADDLE_ENFORCE(A.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] should be tensor! Please check.")); + PADDLE_ENFORCE_EQ(!output_shapes.empty(), + true, + phi::errors::InvalidArgument( + "The output_shapes of Cast is empty! Please check.")); + auto tensor_A = A.as_tensor_ref(); + VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") + << ", output_shapes: " << utils::Join(output_shapes[0], ", "); + PADDLE_ENFORCE_EQ( + pack_args.size(), + 2U, + phi::errors::InvalidArgument("the size of pack_args should be " + "equal to 2, but got %d.", + pack_args.size())); + std::string tensor_name = pack_args[1].operator std::string(); + ir::Tensor out = pe::Cast(tensor_A, out_type[0], tensor_name); + std::vector res; + res.push_back(CINNValue(out)); + PADDLE_ENFORCE_EQ(!out_type.empty(), + true, + phi::errors::InvalidArgument( + "Output type of Cast is empty! Please check.")); + *ret = CINNValuePack{res}; + }); auto strategy = std::make_shared(); strategy->AddImpl(cast_compute, @@ -888,37 +1071,47 @@ std::shared_ptr StrategyForCastSymbolic( const std::vector &out_type, const std::vector> &output_shapes, const Target &target) { - framework::CINNCompute cast_compute( - [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input arguments of Cast compute is empty! Please check.\n"; - CINNValuePack pack_args = args[0]; - PADDLE_ENFORCE_GE(pack_args.size(), - 1U, - phi::errors::InvalidArgument( - "the size of pack_args should be greater than or " - "equal to 1, but got %d.", - pack_args.size())); - Expr A = pack_args[0]; - CHECK(A.as_tensor()); - CHECK(!output_shapes.empty()); - auto tensor_A = A.as_tensor_ref(); - VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") - << ", output_shapes: " << utils::Join(output_shapes[0], ", "); - PADDLE_ENFORCE_EQ( - pack_args.size(), - 2U, - phi::errors::InvalidArgument("the size of pack_args should be " - "equal to 2, but got %d.", - pack_args.size())); - std::string tensor_name = pack_args[1].operator std::string(); - ir::Tensor out = pe::Cast(tensor_A, out_type[0], tensor_name); - std::vector res; - res.push_back(CINNValue(out)); - CHECK(!out_type.empty()) - << "Output type of Cast is empty! Please check.\n"; - *ret = CINNValuePack{res}; - }); + framework::CINNCompute cast_compute([=](lang::Args args, + lang::RetValue *ret) { + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input arguments of Cast compute is empty! " + "Please check.")); + CINNValuePack pack_args = args[0]; + PADDLE_ENFORCE_GE(pack_args.size(), + 1U, + phi::errors::InvalidArgument( + "the size of pack_args should be greater than or " + "equal to 1, but got %d.", + pack_args.size())); + Expr A = pack_args[0]; + PADDLE_ENFORCE(A.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] should be tensor! Please check.")); + PADDLE_ENFORCE_EQ(!output_shapes.empty(), + true, + phi::errors::InvalidArgument( + "The output_shapes of Cast is empty! Please check.")); + auto tensor_A = A.as_tensor_ref(); + VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") + << ", output_shapes: " << utils::Join(output_shapes[0], ", "); + PADDLE_ENFORCE_EQ( + pack_args.size(), + 2U, + phi::errors::InvalidArgument("the size of pack_args should be " + "equal to 2, but got %d.", + pack_args.size())); + std::string tensor_name = pack_args[1].operator std::string(); + ir::Tensor out = pe::Cast(tensor_A, out_type[0], tensor_name); + std::vector res; + res.push_back(CINNValue(out)); + PADDLE_ENFORCE_EQ(!out_type.empty(), + true, + phi::errors::InvalidArgument( + "Output type of Cast is empty! Please check.")); + *ret = CINNValuePack{res}; + }); auto strategy = std::make_shared(); strategy->AddImpl(cast_compute, lang::PackedFunc(), "strategy.cast.x86", 1); @@ -931,38 +1124,48 @@ std::shared_ptr StrategyForYieldStore( const std::vector &out_type, const std::vector> &output_shapes, const Target &target) { - framework::CINNCompute cast_compute( - [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input arguments of Cast compute is empty! Please check.\n"; - CINNValuePack pack_args = args[0]; - PADDLE_ENFORCE_GE(pack_args.size(), - 1U, - phi::errors::InvalidArgument( - "the size of pack_args should be greater than or " - "equal to 1, but got %d.", - pack_args.size())); - - Expr A = pack_args[0]; - CHECK(A.as_tensor()); - CHECK(!output_shapes.empty()); - auto tensor_A = A.as_tensor_ref(); - VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") - << ", output_shapes: " << utils::Join(output_shapes[0], ", "); - PADDLE_ENFORCE_EQ( - pack_args.size(), - 2U, - phi::errors::InvalidArgument("the size of pack_args should be " - "equal to 2, but got %d.", - pack_args.size())); - std::string tensor_name = pack_args[1].operator std::string(); - ir::Tensor out = pe::Store(tensor_A, tensor_name); - std::vector res; - res.push_back(CINNValue(out)); - CHECK(!out_type.empty()) - << "Output type of Cast is empty! Please check.\n"; - *ret = CINNValuePack{res}; - }); + framework::CINNCompute cast_compute([=](lang::Args args, + lang::RetValue *ret) { + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input arguments of Cast compute is empty! " + "Please check.")); + CINNValuePack pack_args = args[0]; + PADDLE_ENFORCE_GE(pack_args.size(), + 1U, + phi::errors::InvalidArgument( + "the size of pack_args should be greater than or " + "equal to 1, but got %d.", + pack_args.size())); + + Expr A = pack_args[0]; + PADDLE_ENFORCE(A.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] should be tensor! Please check.")); + PADDLE_ENFORCE_EQ(!output_shapes.empty(), + true, + phi::errors::InvalidArgument( + "The output_shapes of Cast is empty! Please check.")); + auto tensor_A = A.as_tensor_ref(); + VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") + << ", output_shapes: " << utils::Join(output_shapes[0], ", "); + PADDLE_ENFORCE_EQ( + pack_args.size(), + 2U, + phi::errors::InvalidArgument("the size of pack_args should be " + "equal to 2, but got %d.", + pack_args.size())); + std::string tensor_name = pack_args[1].operator std::string(); + ir::Tensor out = pe::Store(tensor_A, tensor_name); + std::vector res; + res.push_back(CINNValue(out)); + PADDLE_ENFORCE_EQ(!out_type.empty(), + true, + phi::errors::InvalidArgument( + "Output type of Cast is empty! Please check.")); + *ret = CINNValuePack{res}; + }); auto strategy = std::make_shared(); strategy->AddImpl(cast_compute, @@ -978,37 +1181,47 @@ std::shared_ptr StrategyForYieldStoreSymbolic( const std::vector &out_type, const std::vector> &output_shapes, const Target &target) { - framework::CINNCompute cast_compute( - [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input arguments of Cast compute is empty! Please check.\n"; - CINNValuePack pack_args = args[0]; - PADDLE_ENFORCE_GE(pack_args.size(), - 1U, - phi::errors::InvalidArgument( - "the size of pack_args should be greater than or " - "equal to 1, but got %d.", - pack_args.size())); - Expr A = pack_args[0]; - CHECK(A.as_tensor()); - CHECK(!output_shapes.empty()); - auto tensor_A = A.as_tensor_ref(); - VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") - << ", output_shapes: " << utils::Join(output_shapes[0], ", "); - PADDLE_ENFORCE_EQ( - pack_args.size(), - 2U, - phi::errors::InvalidArgument("the size of pack_args should be " - "equal to 2, but got %d.", - pack_args.size())); - std::string tensor_name = pack_args[1].operator std::string(); - ir::Tensor out = pe::Store(tensor_A, tensor_name); - std::vector res; - res.push_back(CINNValue(out)); - CHECK(!out_type.empty()) - << "Output type of Cast is empty! Please check.\n"; - *ret = CINNValuePack{res}; - }); + framework::CINNCompute cast_compute([=](lang::Args args, + lang::RetValue *ret) { + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input arguments of Cast compute is empty! " + "Please check.")); + CINNValuePack pack_args = args[0]; + PADDLE_ENFORCE_GE(pack_args.size(), + 1U, + phi::errors::InvalidArgument( + "the size of pack_args should be greater than or " + "equal to 1, but got %d.", + pack_args.size())); + Expr A = pack_args[0]; + PADDLE_ENFORCE(A.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] should be tensor! Please check.")); + PADDLE_ENFORCE_EQ(!output_shapes.empty(), + true, + phi::errors::InvalidArgument( + "The output_shapes of Cast is empty! Please check.")); + auto tensor_A = A.as_tensor_ref(); + VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") + << ", output_shapes: " << utils::Join(output_shapes[0], ", "); + PADDLE_ENFORCE_EQ( + pack_args.size(), + 2U, + phi::errors::InvalidArgument("the size of pack_args should be " + "equal to 2, but got %d.", + pack_args.size())); + std::string tensor_name = pack_args[1].operator std::string(); + ir::Tensor out = pe::Store(tensor_A, tensor_name); + std::vector res; + res.push_back(CINNValue(out)); + PADDLE_ENFORCE_EQ(!out_type.empty(), + true, + phi::errors::InvalidArgument( + "Output type of Cast is empty! Please check.")); + *ret = CINNValuePack{res}; + }); auto strategy = std::make_shared(); strategy->AddImpl(cast_compute, lang::PackedFunc(), "strategy.store.x86", 1); @@ -1127,10 +1340,26 @@ std::shared_ptr StrategyForArange( const std::vector> &output_shapes, const Target &target) { auto attr_store = attrs.attr_store; - CHECK(attr_store.count("start")); - CHECK(attr_store.count("stop")); - CHECK(attr_store.count("step")); - CHECK(attr_store.count("dtype")); + PADDLE_ENFORCE_EQ( + attr_store.count("start"), + true, + phi::errors::InvalidArgument( + "No start attribute in attrs.attr_store! Please check.")); + PADDLE_ENFORCE_EQ( + attr_store.count("stop"), + true, + phi::errors::InvalidArgument( + "No stop attribute in attrs.attr_store! Please check.")); + PADDLE_ENFORCE_EQ( + attr_store.count("step"), + true, + phi::errors::InvalidArgument( + "No step attribute in attrs.attr_store! Please check.")); + PADDLE_ENFORCE_EQ( + attr_store.count("dtype"), + true, + phi::errors::InvalidArgument( + "No dtype attribute in attrs.attr_store! Please check.")); auto start = absl::get(attr_store.at("start")); auto stop = absl::get(attr_store.at("stop")); @@ -1140,8 +1369,10 @@ std::shared_ptr StrategyForArange( framework::CINNCompute arange_compute( [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input argument of arange compute is empty! Please check.\n"; + PADDLE_ENFORCE(!args.empty(), + phi::errors::InvalidArgument( + "The input argument of arange compute is empty! " + "Please check.")); CINNValuePack pack_args = args[0]; PADDLE_ENFORCE_EQ( @@ -1230,51 +1461,53 @@ std::shared_ptr StrategyForTril( const std::vector &out_type, const std::vector> &output_shapes, const Target &target) { - framework::CINNCompute tril_compute( - [=](lang::Args args, lang::RetValue *ret) { - PADDLE_ENFORCE_EQ(args.size(), - size_t(1), - ::common::errors::InvalidArgument( - "The input arguments of tril compute is empty")); - CINNValuePack pack_args = args[0]; - PADDLE_ENFORCE_GE(pack_args.size(), - size_t(1), - ::common::errors::InvalidArgument( - "only 1 input tensor for tril compute")); - Expr A = pack_args[0]; - PADDLE_ENFORCE_NOT_NULL( - A.as_tensor(), - ::common::errors::InvalidArgument( - "first input argument in tril should be tensor")); - int diagonal = absl::get(attrs.attr_store.at("diagonal")); - auto tensor_A = A.as_tensor_ref(); - - PADDLE_ENFORCE_NE(output_shapes.size(), - size_t(0), - ::common::errors::InvalidArgument( - "output shape of tril should not be empty.")); - VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") - << ", output_shapes: " << utils::Join(output_shapes[0], ", "); + framework::CINNCompute tril_compute([=](lang::Args args, + lang::RetValue *ret) { + PADDLE_ENFORCE_EQ(args.size(), + size_t(1), + ::common::errors::InvalidArgument( + "The input arguments of tril compute is empty")); + CINNValuePack pack_args = args[0]; + PADDLE_ENFORCE_GE(pack_args.size(), + size_t(1), + ::common::errors::InvalidArgument( + "only 1 input tensor for tril compute")); + Expr A = pack_args[0]; + PADDLE_ENFORCE_NOT_NULL( + A.as_tensor(), + ::common::errors::InvalidArgument( + "first input argument in tril should be tensor")); + int diagonal = absl::get(attrs.attr_store.at("diagonal")); + auto tensor_A = A.as_tensor_ref(); - PADDLE_ENFORCE_EQ(pack_args.size(), - size_t(2), - ::common::errors::InvalidArgument( - "args of tril compute should be equal to 2")); - PADDLE_ENFORCE_EQ(pack_args[1].is_string(), - true, - ::common::errors::InvalidArgument( - "The second argument of tril should be string")); - std::string tensor_name = pack_args[1].operator std::string(); + PADDLE_ENFORCE_NE(output_shapes.size(), + size_t(0), + ::common::errors::InvalidArgument( + "output shape of tril should not be empty.")); + VLOG(3) << "A shape: " << utils::Join(tensor_A->shape, ", ") + << ", output_shapes: " << utils::Join(output_shapes[0], ", "); - ir::Tensor out = - pe::Tril(tensor_A, diagonal, output_shapes[0], tensor_name); - std::vector res; - res.push_back(CINNValue(out)); - CHECK(!out_type.empty()) - << "Output type of Reshape is empty! Please check.\n"; + PADDLE_ENFORCE_EQ(pack_args.size(), + size_t(2), + ::common::errors::InvalidArgument( + "args of tril compute should be equal to 2")); + PADDLE_ENFORCE_EQ(pack_args[1].is_string(), + true, + ::common::errors::InvalidArgument( + "The second argument of tril should be string")); + std::string tensor_name = pack_args[1].operator std::string(); - *ret = CINNValuePack{res}; - }); + ir::Tensor out = + pe::Tril(tensor_A, diagonal, output_shapes[0], tensor_name); + std::vector res; + res.push_back(CINNValue(out)); + PADDLE_ENFORCE_EQ(!out_type.empty(), + true, + phi::errors::InvalidArgument( + "Output type of Reshape is empty! Please check.\n")); + + *ret = CINNValuePack{res}; + }); auto strategy = std::make_shared(); strategy->AddImpl(tril_compute, lang::PackedFunc(), "strategy.tril.x86", 1); @@ -1289,8 +1522,11 @@ std::shared_ptr StrategyForAssignOutSymbolic( const Target &target) { framework::CINNCompute assign_out_compute([=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input arguments of AssignOut compute is empty! Please check.\n"; + PADDLE_ENFORCE_EQ(!args.empty(), + true, + phi::errors::InvalidArgument( + "The input arguments of AssignOut compute is empty! " + "Please check.")); CINNValuePack pack_args = args[0]; PADDLE_ENFORCE_EQ( pack_args.size(), @@ -1299,10 +1535,18 @@ std::shared_ptr StrategyForAssignOutSymbolic( "equal to 3, but got %d.", pack_args.size())); Expr x = pack_args[0]; - CHECK(x.as_tensor()); + PADDLE_ENFORCE(x.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] should be tensor! Please check.")); Expr out = pack_args[1]; - CHECK(out.as_tensor()); - CHECK(!output_shapes.empty()); + PADDLE_ENFORCE(out.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[1] should be tensor! Please check.")); + PADDLE_ENFORCE_EQ(!output_shapes.empty(), + true, + phi::errors::InvalidArgument( + "The output_shapes of AssignOut is empty! Please " + "check.")); auto tensor_x = x.as_tensor_ref(); auto tensor_out = out.as_tensor_ref(); @@ -1312,8 +1556,11 @@ std::shared_ptr StrategyForAssignOutSymbolic( [=](const std::vector &indice) { return tensor_x(indice); }, tensor_name); - CHECK(!out_type.empty()) - << "Output type of AssignOut is empty! Please check.\n"; + PADDLE_ENFORCE_EQ( + !out_type.empty(), + true, + phi::errors::InvalidArgument( + "Output type of AssignOut is empty! Please check.\n")); if (!tensor_out->buffer.defined()) { tensor_out->WithBuffer(out_type.front()); } @@ -1352,36 +1599,43 @@ std::shared_ptr StrategyForIsClose( equal_nan = absl::get(attrs.attr_store.at("equal_nan")); } - framework::CINNCompute isclose_compute( - [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input argument of isclose compute is empty! Please check."; - CINNValuePack pack_args = args[0]; - int input_size = pack_args.size(); - - // the last pack argument is the output tensor name - std::string tensor_name = pack_args.back().operator std::string(); - --input_size; - PADDLE_ENFORCE_EQ( - input_size, - 2, - phi::errors::InvalidArgument( - "the input_size should be 2, but got %d.", input_size)); - - // the input tensor are in front - Expr x_expr = pack_args[0]; - CHECK(x_expr.as_tensor()); - auto x_tensor = x_expr.as_tensor_ref(); - - Expr y_expr = pack_args[1]; - CHECK(y_expr.as_tensor()); - auto y_tensor = y_expr.as_tensor_ref(); + framework::CINNCompute isclose_compute([=](lang::Args args, + lang::RetValue *ret) { + PADDLE_ENFORCE_EQ( + !args.empty(), + true, + phi::errors::InvalidArgument( + "The input argument of isclose compute is empty! Please check.")); + CINNValuePack pack_args = args[0]; + int input_size = pack_args.size(); - auto out = pe::IsClose( - x_tensor, y_tensor, axis, rtol, atol, equal_nan, tensor_name); + // the last pack argument is the output tensor name + std::string tensor_name = pack_args.back().operator std::string(); + --input_size; + PADDLE_ENFORCE_EQ( + input_size, + 2, + phi::errors::InvalidArgument("the input_size should be 2, but got %d.", + input_size)); + + // the input tensor are in front + Expr x_expr = pack_args[0]; + PADDLE_ENFORCE(x_expr.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] should be tensor! Please check.")); + auto x_tensor = x_expr.as_tensor_ref(); + + Expr y_expr = pack_args[1]; + PADDLE_ENFORCE(y_expr.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[1] should be tensor! Please check.")); + auto y_tensor = y_expr.as_tensor_ref(); + + auto out = pe::IsClose( + x_tensor, y_tensor, axis, rtol, atol, equal_nan, tensor_name); - *ret = CINNValuePack{{CINNValue(out)}}; - }); + *ret = CINNValuePack{{CINNValue(out)}}; + }); auto strategy = std::make_shared(); strategy->AddImpl(isclose_compute, @@ -1415,36 +1669,43 @@ std::shared_ptr StrategyForIsCloseSymbolic( equal_nan = absl::get(attrs.attr_store.at("equal_nan")); } - framework::CINNCompute isclose_compute( - [=](lang::Args args, lang::RetValue *ret) { - CHECK(!args.empty()) - << "The input argument of isclose compute is empty! Please check."; - CINNValuePack pack_args = args[0]; - int input_size = pack_args.size(); - - // the last pack argument is the output tensor name - std::string tensor_name = pack_args.back().operator std::string(); - --input_size; - PADDLE_ENFORCE_EQ( - input_size, - 2, - phi::errors::InvalidArgument( - "the input_size should be 2, but got %d.", input_size)); - - // the input tensor are in front - Expr x_expr = pack_args[0]; - CHECK(x_expr.as_tensor()); - auto x_tensor = x_expr.as_tensor_ref(); - - Expr y_expr = pack_args[1]; - CHECK(y_expr.as_tensor()); - auto y_tensor = y_expr.as_tensor_ref(); + framework::CINNCompute isclose_compute([=](lang::Args args, + lang::RetValue *ret) { + PADDLE_ENFORCE_EQ( + !args.empty(), + true, + phi::errors::InvalidArgument( + "The input argument of isclose compute is empty! Please check.")); + CINNValuePack pack_args = args[0]; + int input_size = pack_args.size(); - auto out = pe::IsClose( - x_tensor, y_tensor, axis, rtol, atol, equal_nan, tensor_name); + // the last pack argument is the output tensor name + std::string tensor_name = pack_args.back().operator std::string(); + --input_size; + PADDLE_ENFORCE_EQ( + input_size, + 2, + phi::errors::InvalidArgument("the input_size should be 2, but got %d.", + input_size)); + + // the input tensor are in front + Expr x_expr = pack_args[0]; + PADDLE_ENFORCE(x_expr.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[0] should be tensor! Please check.")); + auto x_tensor = x_expr.as_tensor_ref(); + + Expr y_expr = pack_args[1]; + PADDLE_ENFORCE(y_expr.as_tensor(), + phi::errors::InvalidArgument( + "The pack_args[1] should be tensor! Please check.")); + auto y_tensor = y_expr.as_tensor_ref(); + + auto out = pe::IsClose( + x_tensor, y_tensor, axis, rtol, atol, equal_nan, tensor_name); - *ret = CINNValuePack{{CINNValue(out)}}; - }); + *ret = CINNValuePack{{CINNValue(out)}}; + }); auto strategy = std::make_shared(); strategy->AddImpl(