@@ -471,10 +471,9 @@ ExprTransformer UnsqueezeForTransformer(
471
471
schedule_block->body =
472
472
WrapForTransformer (to_append_var)(schedule_block->body );
473
473
} else {
474
- PADDLE_THROW (
474
+ PADDLE_THROW (:: common::errors::PreconditionNotMet (
475
475
" UnsqueezeForTransformer: only support insert after a (For / "
476
- " ScheduleBlockRealizer): %s" ,
477
- followed_expr);
476
+ " ScheduleBlockRealizer)" ));
478
477
}
479
478
VLOG (6 ) << " UnsqueezeForTransformer: After changed: " << copied_e;
480
479
return copied_e;
@@ -547,19 +546,24 @@ ExprTransformer RemoveVarInScheduleBlockRealize(const ir::Var& target_vars,
547
546
VLOG (4 ) << " Start RemoveVarInScheduleBlockRealize(" << target_vars << " , "
548
547
<< replaced_expr << " )" ;
549
548
VLOG (4 ) << " Input is " << e;
550
- PADDLE_ENFORCE (e.As <ir::ScheduleBlockRealize>() != nullptr ,
551
- " RemoveVarInScheduleBlockRealize: input expr is not a "
552
- " ScheduleBlockRealize." );
549
+ PADDLE_ENFORCE_NE (
550
+ e.As <ir::ScheduleBlockRealize>(),
551
+ nullptr ,
552
+ ::common::errors::InvalidArgument (
553
+ " RemoveVarInScheduleBlockRealize: input expr is not a "
554
+ " ScheduleBlockRealize." ));
553
555
auto copied_ir = ir::ir_utils::IRCopy (e);
554
556
auto schedule_block_iter_vars =
555
557
copied_ir.As <ir::ScheduleBlockRealize>()->iter_values ;
556
558
auto block_bound_vars = copied_ir.As <ir::ScheduleBlockRealize>()
557
559
->schedule_block .As <ir::ScheduleBlock>()
558
560
->iter_vars ;
559
561
for (const auto & i_var : schedule_block_iter_vars) {
560
- PADDLE_ENFORCE (
562
+ PADDLE_ENFORCE_EQ (
561
563
i_var.is_var (),
562
- " RemoveVarInScheduleBlockRealize: axes.bind rhs is is not a Var." );
564
+ true ,
565
+ ::common::errors::InvalidArgument (" RemoveVarInScheduleBlockRealize: "
566
+ " axes.bind rhs is is not a Var." ));
563
567
}
564
568
// find replace idx
565
569
int target_idx = -1 ;
@@ -686,10 +690,11 @@ ExprTransformer RemoveOneTransformer(int one) {
686
690
VLOG (4 ) << " RemoveOneTransformer: father block is root realize" ;
687
691
ir::Expr shedule_block =
688
692
target_block.As <ir::ScheduleBlockRealize>()->schedule_block ;
689
- PADDLE_ENFORCE_EQ (shedule_block.As <ir::ScheduleBlock>()->body ,
690
- target_for,
691
- ::common::errors::PreconditionNotMet (
692
- " Root realize body should be equal to target for" ));
693
+ PADDLE_ENFORCE_EQ (
694
+ shedule_block.As <ir::ScheduleBlock>()->body ,
695
+ target_for,
696
+ ::common::errors::InvalidArgument (
697
+ " Root realize body should be equal to target for." ));
693
698
const auto for_body = target_for.As <ir::For>()->body ;
694
699
const auto for_body_stmts = for_body.As <ir::Block>()->stmts ;
695
700
if (for_body_stmts.size () == 1 &&
@@ -747,12 +752,17 @@ ExprTransformer RemoveOnesTransformer(const std::vector<int32_t>& ones) {
747
752
ExprTransformer TransposeForsTransformer (const std::vector<int32_t >& perm) {
748
753
const auto & f = [=](const ir::Expr& root) -> ir::Expr {
749
754
const auto & iters = GetNonReduceLoopVars (root);
750
- PADDLE_ENFORCE_EQ (iters.size (),
751
- perm.size (),
752
- " Transposed iters size and perm size should be equal." );
755
+ PADDLE_ENFORCE_EQ (
756
+ iters.size (),
757
+ perm.size (),
758
+ ::common::errors::InvalidArgument (
759
+ " Transposed iters size and perm size should be equal." ));
753
760
for (size_t i = 0 ; i < perm.size (); ++i) {
754
761
if (iters[i]->is_reduce_axis ) {
755
- PADDLE_ENFORCE_EQ (i, perm[i], " Can only transpose non reduce iters." );
762
+ PADDLE_ENFORCE_EQ (i,
763
+ perm[i],
764
+ ::common::errors::InvalidArgument (
765
+ " Can only transpose non reduce iters." ));
756
766
}
757
767
}
758
768
const auto transposed_iters = cinn::fusion::TransposeVector (iters, perm);
@@ -773,7 +783,7 @@ ExprTransformer InsertForsTransformer(const std::vector<int32_t>& axis,
773
783
axis.size (),
774
784
vars.size (),
775
785
::common::errors::InvalidArgument (
776
- " The number of axis to insert and vars should be equal" ));
786
+ " The number of axis to insert and vars should be equal. " ));
777
787
const size_t reduce_size =
778
788
std::count_if (iters.begin (), iters.end (), [](const ir::Var& v) {
779
789
return v->is_reduce_axis ;
@@ -782,7 +792,7 @@ ExprTransformer InsertForsTransformer(const std::vector<int32_t>& axis,
782
792
PADDLE_ENFORCE_LE (axis[i],
783
793
iters.size () - reduce_size,
784
794
::common::errors::OutOfRange (
785
- " Insert axis should not be behind reduce axis" ));
795
+ " Insert axis should not be behind reduce axis. " ));
786
796
iters.insert (iters.begin () + axis[i], vars[i]);
787
797
}
788
798
const auto non_reduce_iters =
@@ -837,7 +847,7 @@ int InplaceMutateSingleExpr(ir::Expr* root,
837
847
PADDLE_ENFORCE_EQ (
838
848
source.size (),
839
849
1 ,
840
- ::common::errors::InvalidArgument (" Only one expr should be found" ));
850
+ ::common::errors::InvalidArgument (" Only one expr should be found. " ));
841
851
const auto & target = transformer (source[0 ]);
842
852
ComposeUtils::MappingTargetExprToDestExprMutator (source[0 ], target)(root);
843
853
return 1 ; // operation number.
@@ -880,7 +890,10 @@ void CheckFusionInputValid(const std::vector<ir::Expr>& op_compute_bodies,
880
890
VLOG (4 ) << " op_patterns.size() = " << op_compute_bodies.size ();
881
891
VLOG (4 ) << " op_compute_bodies.size() = " << op_patterns.size ();
882
892
PADDLE_ENFORCE_EQ (
883
- op_patterns.size (), op_compute_bodies.size (), " ops and size not equal" );
893
+ op_patterns.size (),
894
+ op_compute_bodies.size (),
895
+ ::common::errors::InvalidArgument (
896
+ " The number of op_compute_bodies and op_patterns should be equal." ));
884
897
}
885
898
886
899
std::vector<ir::Var> AppendBound (const std::vector<ir::Var> vars,
0 commit comments