Skip to content

Commit e71ee97

Browse files
authored
【Error Message BUAA No.35】fix error message (#66727)
* fix error message * fix phi * fix simple_jit * fix codestyle
1 parent c97f663 commit e71ee97

File tree

5 files changed

+77
-26
lines changed

5 files changed

+77
-26
lines changed

paddle/cinn/backends/function_prototype.cc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@ void FunctionProto::AssertMatch(const ir::Call *op) const {
9191

9292
void FunctionProto::CheckValid() {
9393
if (ret_type.is_void()) {
94-
CHECK(!mutable_arg_types.empty())
95-
<< "A void function should have at least one mutable argument to "
96-
"output something";
94+
PADDLE_ENFORCE_EQ(
95+
!mutable_arg_types.empty(),
96+
true,
97+
phi::errors::InvalidArgument(
98+
"A void function should have at least one mutable argument to "
99+
"output something."));
97100
} else {
98-
CHECK(mutable_arg_types.empty())
99-
<< "A function with return should not have mutable argument";
101+
PADDLE_ENFORCE_EQ(
102+
mutable_arg_types.empty(),
103+
true,
104+
phi::errors::InvalidArgument(
105+
"A function with return should not have mutable argument."));
100106
}
101107
}
102108

@@ -107,7 +113,10 @@ FunctionProto::shape_inference_t FunctionProto::ShapeFollowNthArgument(int n) {
107113
::common::errors::InvalidArgument(
108114
"The argument index is out of range"));
109115
auto x = args[n].as_tensor();
110-
CHECK(x);
116+
PADDLE_ENFORCE_NOT_NULL(
117+
x,
118+
phi::errors::InvalidArgument(
119+
"The argument at index (%d) must be a tensor.", n));
111120
return x->shape;
112121
};
113122
}

paddle/cinn/backends/llvm/simple_jit.cc

100755100644
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ void SimpleJIT::AddModule(std::unique_ptr<llvm::Module> module, bool optimize) {
4949
LOG(INFO) << "fn:\n" << DumpToString(fn);
5050
}
5151
*/
52-
CHECK(!llvm::verifyModule(*module, &llvm::errs()))
53-
<< "Transformation resulted in an invalid module\n\nmodule:\n";
52+
PADDLE_ENFORCE_EQ(
53+
!llvm::verifyModule(*module, &llvm::errs()),
54+
true,
55+
phi::errors::InvalidArgument(
56+
"Transformation resulted in an invalid module\n\nmodule:\n"));
5457

5558
bool debug = false;
5659
if (optimize) {
@@ -99,7 +102,8 @@ SimpleJIT::SimpleJIT() : context_(std::make_unique<llvm::LLVMContext>()) {
99102
llvm::InitializeAllAsmPrinters();
100103

101104
jit_ = llvm::cantFail(llvm::orc::LLJITBuilder().create());
102-
CHECK(jit_) << "JIT create failed";
105+
PADDLE_ENFORCE_NOT_NULL(jit_,
106+
phi::errors::InvalidArgument("JIT creation failed."));
103107

104108
auto proc_symbols_generator = llvm::cantFail(
105109
llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(
@@ -129,7 +133,9 @@ void SimpleJIT::Link(ir::Module module, bool optimize) {
129133
auto ir_emitter = std::make_unique<CodeGenT>(m.get(), b.get());
130134
ir_emitter->Compile(module);
131135

132-
CHECK(!llvm::verifyModule(*m, &llvm::errs())) << "Invalid module found";
136+
PADDLE_ENFORCE_EQ(!llvm::verifyModule(*m, &llvm::errs()),
137+
true,
138+
phi::errors::InvalidArgument("Invalid module found."));
133139

134140
AddModule(std::move(m), optimize);
135141
}

paddle/cinn/hlir/pe/reduction.cc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ using lang::Compute;
5151
void GetRealAxes(int ndim,
5252
const std::vector<int>& axes,
5353
std::vector<int>* real_axes) {
54-
CHECK(real_axes);
54+
PADDLE_ENFORCE_NOT_NULL(real_axes,
55+
phi::errors::InvalidArgument(
56+
"The 'real_axes' pointer must not be null."));
5557
if (axes.empty()) {
5658
for (int i = 0; i < ndim; ++i) {
5759
real_axes->push_back(i);
@@ -120,7 +122,9 @@ void GetOutputShape(const std::vector<int>& real_axes,
120122
std::vector<Expr>* output_shape,
121123
const Tensor& tensor,
122124
bool keep_dims) {
123-
CHECK(output_shape);
125+
PADDLE_ENFORCE_NOT_NULL(output_shape,
126+
phi::errors::InvalidArgument(
127+
"The 'output_shape' pointer must not be null."));
124128
auto ndim = tensor->shape.size();
125129
if (keep_dims) {
126130
for (size_t i = 0; i < ndim; ++i) {
@@ -141,7 +145,10 @@ void GetOutputShape(const std::vector<int>& real_axes,
141145
output_shape->push_back(cinn::common::make_one());
142146
}
143147

144-
CHECK(!tensor->shape.empty());
148+
PADDLE_ENFORCE_EQ(
149+
!tensor->shape.empty(),
150+
true,
151+
phi::errors::InvalidArgument("The 'tensor' shape must not be empty."));
145152
if (tensor->shape[0]->type() == Int(64)) {
146153
for (auto& shape_item : *output_shape) {
147154
shape_item->convert_int32_to_int64();
@@ -868,8 +875,10 @@ std::vector<ir::Tensor> TwoStepBlockReduceInternal(
868875
ReduceFunc reduce_func,
869876
BlockReduceFunc block_reduce_func,
870877
ir::Expr initial) {
871-
CHECK(!WithoutLastDimInReduce(A->shape, axes))
872-
<< "Can't find last axis in reduce!";
878+
PADDLE_ENFORCE_EQ(
879+
!WithoutLastDimInReduce(A->shape, axes),
880+
true,
881+
phi::errors::InvalidArgument("Can't find last axis in reduce!"));
873882
// If the number of current device SM is smaller than the number of SM
874883
// required by Warp Reduce, the performance of Warp Reduce is better.
875884
// Otherwise, use Block Reduce.

paddle/cinn/hlir/pe/schedule.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,21 @@ void GetConv2dFactors(absl::flat_hash_map<std::string, int> *factors,
261261
auto &params = ScheduleParam::get_x86_instance().GetParam();
262262
if (params.count(key)) {
263263
VLOG(3) << "find saved param, key is: " << key;
264-
CHECK(!params[key]["oc_bn"].empty());
265-
CHECK(!params[key]["ic_bn"].empty());
266-
CHECK(!params[key]["ow_bn"].empty());
264+
PADDLE_ENFORCE_EQ(
265+
!params[key]["oc_bn"].empty(),
266+
true,
267+
phi::errors::InvalidArgument(
268+
"The parameter 'oc_bn' for key '%s' must not be empty.", key));
269+
PADDLE_ENFORCE_EQ(
270+
!params[key]["ic_bn"].empty(),
271+
true,
272+
phi::errors::InvalidArgument(
273+
"The parameter 'ic_bn' for key '%s' must not be empty.", key));
274+
PADDLE_ENFORCE_EQ(
275+
!params[key]["ow_bn"].empty(),
276+
true,
277+
phi::errors::InvalidArgument(
278+
"The parameter 'ow_bn' for key '%s' must not be empty.", key));
267279
(*factors)["oc_bn"] = params[key]["oc_bn"].back();
268280
(*factors)["ic_bn"] = params[key]["ic_bn"].back();
269281
(*factors)["ow_bn"] = params[key]["ow_bn"].back();
@@ -495,8 +507,10 @@ inline void InputDirectConvCudaParam(
495507
schedule_data["f"] = int_data[3];
496508
schedule_data["y"] = int_data[4];
497509
schedule_data["x"] = int_data[5];
498-
CHECK(model_data.count(key) == 0)
499-
<< "Key " << key << "in conv cuda param already exists.";
510+
PADDLE_ENFORCE_EQ(model_data.count(key),
511+
0,
512+
phi::errors::InvalidArgument(
513+
"Key '%s' in conv CUDA param already exists.", key));
500514
model_data[key] = schedule_data;
501515
}
502516

paddle/cinn/pybind/ir/ir_context.cc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ void ElseContextNode::ExitWithContext() {
8484
}
8585

8686
Expr IRBuilderNode::GetResult() const {
87-
CHECK(result.defined()) << "No result generated in IRBuilder";
87+
PADDLE_ENFORCE_EQ(
88+
result.defined(),
89+
true,
90+
phi::errors::InvalidArgument("No result generated in IRBuilder."));
8891
return result;
8992
}
9093

@@ -100,22 +103,32 @@ IRBuilder::IRBuilder() {
100103
}
101104

102105
void IRBuilder::EnterWithContext() {
103-
CHECK(data_->contexts.empty())
104-
<< "There are still Contexts in IRBuilder that has not been fully "
105-
"converted. Please build a new IR with the new IRbuilder";
106+
PADDLE_ENFORCE_EQ(
107+
data_->contexts.empty(),
108+
true,
109+
phi::errors::InvalidArgument(
110+
"There are still contexts in IRBuilder that have not been fully "
111+
"converted. Please build a new IR with the new IRBuilder."));
112+
106113
data_->result.Reset();
107114
std::vector<IRBuilder>* st = IRBuilderStack();
108115
st->push_back(*this);
109116
}
110117

111118
void IRBuilder::ExitWithContext() {
112119
std::vector<IRBuilder>* st = IRBuilderStack();
113-
CHECK(!st->empty());
120+
PADDLE_ENFORCE_EQ(
121+
!st->empty(),
122+
true,
123+
phi::errors::InvalidArgument("The IRBuilder stack must not be empty."));
114124
st->pop_back();
115125
}
116126
IRBuilder IRBuilder::CurrentIRBuilder() {
117127
std::vector<IRBuilder>* st = IRBuilderStack();
118-
CHECK(!st->empty()) << "No IRBuilder Found";
128+
PADDLE_ENFORCE_EQ(
129+
!st->empty(),
130+
true,
131+
phi::errors::InvalidArgument("No IRBuilder found in the stack."));
119132
return st->back();
120133
}
121134
std::vector<IRBuilder>* IRBuilderStack() {

0 commit comments

Comments
 (0)