Skip to content

Commit

Permalink
【Error Message No. 31、40、41、126 BUAA】modify error messages (PaddlePad…
Browse files Browse the repository at this point in the history
…dle#66707)

* Update llvm_intrin_rule.h

* Update map_expr_to_ir.cc

* Update buffer.cc

* Update ir_mutator.h
  • Loading branch information
Guanhuachen2003 authored and inaomIIsfarell committed Jul 31, 2024
1 parent e8fed1d commit c54b1f3
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 66 deletions.
126 changes: 102 additions & 24 deletions paddle/cinn/backends/llvm/llvm_intrin_rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,34 @@ namespace codegen {

template <int id, int arg_nums, bool add_float_suffix = true>
inline void MakeFloatIntrinOp(lang::Args args, lang::RetValue *rv) {
PADDLE_ENFORCE_GE(args.size(),
1U,
::common::errors::InvalidArgument(
"The number of args should be greater than 1."));
PADDLE_ENFORCE_GE(
args.size(),
1U,
phi::errors::InvalidArgument(
"The number of arguments should be at least 1. Received: %d",
args.size()));

Expr arg = args[0];
ir::Call *node = arg->as<ir::Call>();
CHECK(node);

PADDLE_ENFORCE_NOT_NULL(node,
phi::errors::InvalidArgument(
"The argument must be a valid call expression."));

PADDLE_ENFORCE_GE(
node->read_args.size(),
arg_nums,
::common::errors::InvalidArgument(
"The number of read args should be greater than arg_nums."));
phi::errors::InvalidArgument(
"The number of read arguments should be at least %d. Received: %d",
arg_nums,
node->read_args.size()));

if (add_float_suffix) {
CHECK(node->type().is_float());
PADDLE_ENFORCE_EQ(node->type().is_float(),
true,
phi::errors::InvalidArgument(
"The node type should be float. Received: %s",
node->type().to_string().c_str()));
*rv = ir::intrinsics::BuiltinIntrin::Make(
node->name + "f", node->read_args, id, arg_nums, node->type());
} else {
Expand Down Expand Up @@ -98,8 +112,16 @@ void RegisterCpuIntrinRule() {
"The number of args should be greater than 1."));
Expr arg0 = args[0];
ir::Call *node = arg0->as<ir::Call>();
CHECK(node);
CHECK(!node->read_args.empty());
PADDLE_ENFORCE_NOT_NULL(
node,
phi::errors::InvalidArgument(
"The argument must be a valid call expression."));
PADDLE_ENFORCE_EQ(
!node->read_args.empty(),
true,
phi::errors::InvalidArgument(
"The read_args of the node should not be empty."));

Expr arg = node->read_args[0];
*rv = !(lang::IsInf(arg)) && !(lang::IsNan(arg));
});
Expand All @@ -112,8 +134,16 @@ void RegisterCpuIntrinRule() {
"The number of args should be greater than 1."));
Expr arg0 = args[0];
ir::Call *node = arg0->as<ir::Call>();
CHECK(node);
CHECK(!node->read_args.empty());
PADDLE_ENFORCE_NOT_NULL(
node,
phi::errors::InvalidArgument("The argument must be a valid call "
"expression. Received null."));
PADDLE_ENFORCE_EQ(!node->read_args.empty(),
true,
phi::errors::InvalidArgument(
"The read_args of the node should not be empty. "
"The provided read_args are empty."));

Expr arg = node->read_args[0];
Type type = arg->type();
if (type.is_int() || type.is_uint()) {
Expand All @@ -132,8 +162,16 @@ void RegisterCpuIntrinRule() {
"The number of args should be greater than 1."));
Expr arg0 = args[0];
ir::Call *node = arg0->as<ir::Call>();
CHECK(node);
CHECK(!node->read_args.empty());
PADDLE_ENFORCE_NOT_NULL(
node,
phi::errors::InvalidArgument("The argument must be a valid call "
"expression. Received null."));
PADDLE_ENFORCE_EQ(!node->read_args.empty(),
true,
phi::errors::InvalidArgument(
"The read_args of the node should not be empty. "
"Received empty read_args."));

Expr arg = node->read_args[0];
*rv = make_const(arg->type(), 1) / lang::Sqrt(arg);
});
Expand All @@ -146,8 +184,16 @@ void RegisterCpuIntrinRule() {
"The number of args should be greater than 1."));
Expr arg0 = args[0];
ir::Call *node = arg0->as<ir::Call>();
CHECK(node);
CHECK(!node->read_args.empty());
PADDLE_ENFORCE_NOT_NULL(
node,
phi::errors::InvalidArgument("The argument must be a valid call "
"expression. Received null."));
PADDLE_ENFORCE_EQ(!node->read_args.empty(),
true,
phi::errors::InvalidArgument(
"The read_args of the node should not be empty. "
"Received empty read_args."));

Expr arg = node->read_args[0];
Expr ln10 = make_const(arg->type(), 2.302585093);
*rv = lang::Exp(arg * ln10);
Expand All @@ -161,8 +207,16 @@ void RegisterCpuIntrinRule() {
"The number of args should be greater than 1."));
Expr arg0 = args[0];
ir::Call *node = arg0->as<ir::Call>();
CHECK(node);
CHECK(!node->read_args.empty());
PADDLE_ENFORCE_NOT_NULL(
node,
phi::errors::InvalidArgument("The argument must be a valid call "
"expression. Received null."));
PADDLE_ENFORCE_EQ(!node->read_args.empty(),
true,
phi::errors::InvalidArgument(
"The read_args of the node should not be empty. "
"Received empty read_args."));

Expr arg = node->read_args[0];
*rv = lang::Sin(arg) / lang::Cos(arg);
});
Expand All @@ -175,8 +229,16 @@ void RegisterCpuIntrinRule() {
"The number of args should be greater than 1."));
Expr arg0 = args[0];
ir::Call *node = arg0->as<ir::Call>();
CHECK(node);
CHECK(!node->read_args.empty());
PADDLE_ENFORCE_NOT_NULL(
node,
phi::errors::InvalidArgument("The argument must be a valid call "
"expression. Received null."));
PADDLE_ENFORCE_EQ(!node->read_args.empty(),
true,
phi::errors::InvalidArgument(
"The read_args of the node should not be empty. "
"Received empty read_args."));

Expr arg = node->read_args[0];
Expr zero = make_const(arg->type(), 0);
Expr one = make_const(arg->type(), 1);
Expand All @@ -199,8 +261,16 @@ void RegisterCpuIntrinRule() {
"The number of args should be greater than 1."));
Expr arg0 = args[0];
ir::Call *node = arg0->as<ir::Call>();
CHECK(node);
CHECK(!node->read_args.empty());
PADDLE_ENFORCE_NOT_NULL(
node,
phi::errors::InvalidArgument("The argument must be a valid call "
"expression. Received null."));
PADDLE_ENFORCE_EQ(!node->read_args.empty(),
true,
phi::errors::InvalidArgument(
"The read_args of the node should not be empty. "
"Received empty read_args."));

Expr arg = node->read_args[0];
*rv = (lang::Exp(arg) + lang::Exp(arg * make_const(arg->type(), -1))) /
make_const(arg->type(), 2);
Expand All @@ -214,8 +284,16 @@ void RegisterCpuIntrinRule() {
"The number of args should be greater than 1."));
Expr arg0 = args[0];
ir::Call *node = arg0->as<ir::Call>();
CHECK(node);
CHECK(!node->read_args.empty());
PADDLE_ENFORCE_NOT_NULL(
node,
phi::errors::InvalidArgument("The argument must be a valid call "
"expression. Received null."));
PADDLE_ENFORCE_EQ(!node->read_args.empty(),
true,
phi::errors::InvalidArgument(
"The read_args of the node should not be empty. "
"Received empty read_args."));

Expr arg = node->read_args[0];
*rv = (lang::Exp(arg) - lang::Exp(arg * make_const(arg->type(), -1))) /
make_const(arg->type(), 2);
Expand Down
Loading

0 comments on commit c54b1f3

Please sign in to comment.