Skip to content

Commit

Permalink
【Error Message No. 55,94,96,97,134,135,174,175,177BUAA】将CHECK宏进行替换 (#…
Browse files Browse the repository at this point in the history
…66953)

* 修改报错信息

* 修改错误的报错信息

* 完善报错信息

* 修改cpp语法错误

* 尝试增加头文件解决符号链接问题

* 重新修改以尝试通过ci测试

* 修改笔误

* 将phi修改为common
  • Loading branch information
Lans1ot authored Aug 7, 2024
1 parent fb41278 commit dfcc447
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ int GetMaxLen(const Context& dev_ctx,
max_len_tensor->data<int>(),
{batch_size},
{0});
PD_CHECK(r == 0, "baidu::xpu::api::reduce_max failed.");
PADDLE_ENFORCE_EQ(
r, 0, common::errors::Fatal("baidu::xpu::api::reduce_max failed."));
xpu_wait(dev_ctx.x_context()->xpu_stream);
r = xpu_memcpy(&max_len_cpu,
max_len_tensor->data<int>(),
sizeof(int),
XPUMemcpyKind::XPU_DEVICE_TO_HOST);
PD_CHECK(r == 0, "xpu_memcpy failed.");
PADDLE_ENFORCE_EQ(r, 0, common::errors::Fatal("xpu_memcpy failed."));
return max_len_cpu;
}

Expand Down Expand Up @@ -73,7 +74,8 @@ void qkv_split_rope_kernel(
{1, 1, 1},
1);
const_cast<DenseTensor*>(&qkv_input)->clear();
PD_CHECK(r == 0, "baidu::xpu::api::split failed.");
PADDLE_ENFORCE_EQ(
r, 0, common::errors::Fatal("baidu::xpu::api::split failed."));
r = baidu::xpu::api::vsl_rotary_neox_embedding<XPUType, float, int32_t>(
xpu_ctx.x_context(),
q_data,
Expand All @@ -90,7 +92,10 @@ void qkv_split_rope_kernel(
pos_emb_offset,
"NORMAL",
-1);
PD_CHECK(r == 0, "baidu::xpu::api::vsl_rotary_neox_embedding failed.");
PADDLE_ENFORCE_EQ(r,
0,
common::errors::Fatal(
"baidu::xpu::api::vsl_rotary_neox_embedding failed."));
}

template <typename T, typename Context>
Expand Down
12 changes: 8 additions & 4 deletions paddle/phi/kernels/fusion/xpu/fused_bias_act_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ static void ComputeImpl(const phi::XPUContext *xpu_ctx,
reinterpret_cast<XPUType *>(const_cast<T *>(x.data<T>())),
{rows, cols},
{1, cols});
PD_CHECK(r == 0, "baidu::xpu::api::broadcast_add failed.");
PADDLE_ENFORCE_EQ(
r, 0, common::errors::Fatal("baidu::xpu::api::broadcast_add failed."));
}
if (act_method == "geglu") {
PD_THROW(
Expand All @@ -70,21 +71,24 @@ static void ComputeImpl(const phi::XPUContext *xpu_ctx,
{rows, cols},
1,
true);
PD_CHECK(r == 0, "baidu::xpu::api::swiglu failed.");
PADDLE_ENFORCE_EQ(
r, 0, common::errors::Fatal("baidu::xpu::api::swiglu failed."));
} else if (act_method == "gelu") {
r = baidu::xpu::api::gelu<XPUType>(
xpu_ctx->x_context(),
reinterpret_cast<const XPUType *>(x.data<T>()),
reinterpret_cast<XPUType *>(out->data<T>()),
rows * cols);
PD_CHECK(r == 0, "baidu::xpu::api::gelu failed.");
PADDLE_ENFORCE_EQ(
r, 0, common::errors::Fatal("baidu::xpu::api::gelu failed."));
} else if (act_method == "relu") {
r = baidu::xpu::api::relu<XPUType>(
xpu_ctx->x_context(),
reinterpret_cast<const XPUType *>(x.data<T>()),
reinterpret_cast<XPUType *>(out->data<T>()),
rows * cols);
PD_CHECK(r == 0, "baidu::xpu::api::relu failed.");
PADDLE_ENFORCE_EQ(
r, 0, common::errors::Fatal("baidu::xpu::api::relu failed."));
} else {
PD_THROW(
"NOT supported. "
Expand Down
28 changes: 23 additions & 5 deletions paddle/pir/src/dialect/shape/utils/dim_expr_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ struct SortOperands {
}

bool IsSorted(const List<DimExpr>& operands) {
CHECK(!operands->empty());
PADDLE_ENFORCE_EQ(
!operands->empty(),
true,
common::errors::InvalidArgument("input op is empty, pleace check!"));
for (std::size_t i = 0; i < operands->size() - 1; ++i) {
if (IsLhsBeforeRhs(operands->at(i + 1), operands->at(i))) {
return false;
Expand All @@ -302,10 +305,18 @@ struct SortOperands {
std::int64_t GetInteger(const DimExpr& expr) {
if (expr.Has<Negative<DimExpr>>()) {
const auto& integer = expr.Get<Negative<DimExpr>>()->data;
CHECK(integer.Has<std::int64_t>());
PADDLE_ENFORCE_EQ(integer.Has<std::int64_t>(),
true,
common::errors::InvalidArgument(
"input expression's member `data` has no attribution "
"`int64_t`, maybe input dim is empty"));
return -integer.Get<std::int64_t>();
}
CHECK(expr.Has<std::int64_t>());
PADDLE_ENFORCE_EQ(
expr.Has<std::int64_t>(),
true,
common::errors::InvalidArgument(
"input has no attribution `int64_t`, maybe input dim is empty"));
return expr.Get<std::int64_t>();
}

Expand Down Expand Up @@ -658,7 +669,10 @@ ConstRational GetConstRational(const DimExpr& expr) {
return std::visit(
[&](const auto& impl) {
std::optional<ConstRational> opt_ret = GetConstRationalImpl(impl);
CHECK(opt_ret.has_value());
PADDLE_ENFORCE_EQ(
opt_ret.has_value(),
true,
common::errors::InvalidArgument("Input is empty, please check"));
return opt_ret.value();
},
expr.variant());
Expand Down Expand Up @@ -743,7 +757,11 @@ struct FoldOperandTrait<Broadcast> {

static const_value_type MakeUnit() { return 1; }
static void Accumulate(const_value_type* value, const DimExpr& expr) {
CHECK(expr.Has<std::int64_t>());
PADDLE_ENFORCE_EQ(expr.Has<std::int64_t>(),
true,
common::errors::InvalidArgument(
"Input constant `expr`(second argument) has no "
"attribution `int64_T`, please check"));
std::int64_t expr_value = expr.Get<std::int64_t>();
if (*value == 1) {
*value = expr_value;
Expand Down
32 changes: 26 additions & 6 deletions test/cpp/eager/data_structure_tests/autograd_meta_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ TEST(AutogradMeta, MemberFunction) {
et1.set_autograd_meta(auto_grad);
auto* tmp_auto = static_cast<egr::AutogradMeta*>(et1.get_autograd_meta());
VLOG(6) << "Test Grad";
CHECK(tmp_auto->Grad().defined() == false);
PADDLE_ENFORCE_EQ(tmp_auto->Grad().defined(),
false,
phi::errors::Fatal("grad shoule not be defined now"));
auto* grad_t = tmp_auto->MutableGrad();
phi::DenseTensorMeta meta =
phi::DenseTensorMeta(phi::DataType::FLOAT32, common::make_ddim({1, 2}));
Expand Down Expand Up @@ -75,11 +77,19 @@ TEST(AutogradMeta, MemberFunction) {
"The second element of grad tensor should be 10.0, but received %f.",
impl_ptr->data<float>()[1]));
VLOG(6) << "Test IsInitialized";
CHECK(tmp_auto->IsInitialized() == false);
PADDLE_ENFORCE_EQ(
tmp_auto->IsInitialized(),
false,
common::errors::Fatal(
"egr::AutogradMeta variable tmp_auto should not be initialized now"));
VLOG(6) << "Test GradNodeSetter Getter";
auto grad_node = std::make_shared<eager_test::GradTestNode>();
tmp_auto->SetGradNode(grad_node);
CHECK(tmp_auto->IsInitialized() == true);
PADDLE_ENFORCE_EQ(
tmp_auto->IsInitialized(),
true,
common::errors::Fatal(
"egr::AutogradMeta variable tmp_auto should be initialized now"));
auto tmp_grad_node = tmp_auto->GetMutableGradNode();
std::dynamic_pointer_cast<eager_test::GradTestNode>(tmp_grad_node)->val_ =
5.0;
Expand Down Expand Up @@ -123,9 +133,19 @@ TEST(AutogradMeta, MemberFunction) {
"The NumericStopGradient value should be -1, but received %d.",
tmp_auto->NumericStopGradient()));
tmp_auto->SetStopGradient(true);
CHECK(tmp_auto->StopGradient() == true);
PADDLE_ENFORCE_EQ(
tmp_auto->StopGradient(),
true,
common::errors::Fatal("tmp_auto->StopGradient() should be true now"));
VLOG(6) << "Test Persistable Setter Getter";
CHECK(tmp_auto->Persistable() == false);
PADDLE_ENFORCE_EQ(
tmp_auto->Persistable(),
false,
common::errors::Fatal("tmp_auto->Persistable() should be false now"));
tmp_auto->SetPersistable(true);
CHECK(tmp_auto->Persistable() == true);
PADDLE_ENFORCE_EQ(
tmp_auto->Persistable(),
true,
common::errors::Fatal(
"tmp_auto->Persistable() should be true now after SetPersistable()"));
}
76 changes: 61 additions & 15 deletions test/cpp/phi/core/test_intrusive_ptr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ TEST(intrusive_ref_counter, async) {

TEST(intrusive_ptr, default_ctor) {
intrusive_ptr<SharedObject> p;
CHECK(p == nullptr);
PADDLE_ENFORCE_EQ(
p == nullptr, true, phi::errors::Fatal("Input pointer is not a nullptr"));
}

TEST(intrusive_ptr, private_ctor) {
auto p = make_intrusive<SharedObject>();
const auto* ptr0 = p.get();
Expand Down Expand Up @@ -86,25 +86,71 @@ TEST(intrusive_ptr, reset_with_ptr) {
common::errors::InvalidArgument(
"Required (*p).i should be equal to ptr->i. "));
p.reset();
CHECK(p == nullptr);
PADDLE_ENFORCE_EQ(
p == nullptr,
true,
common::errors::Fatal(
"p is not a nullptr, something wrong with intrusive_ptr<T>.reset"));
}

TEST(intrusive_ptr, op_comp) {
auto p = make_intrusive<SharedObject>();
auto copy = copy_intrusive<SharedObject>(p);
auto null = intrusive_ptr<SharedObject>();
auto p1 = make_intrusive<SharedObject>();
CHECK(p == copy);
CHECK(p != p1);
CHECK(p == copy.get());
CHECK(p != p1.get());
CHECK(p.get() == copy);
CHECK(p.get() != p1);
CHECK(null == nullptr);
CHECK(nullptr == null);
CHECK(p != nullptr);
CHECK(nullptr != p);
PADDLE_ENFORCE_EQ(p == copy,
true,
common::errors::Fatal(
"intrusive_ptr p is not euqal to its copy, something "
"wrong with copy constructor "));
PADDLE_ENFORCE_EQ(
p != p1,
true,
common::errors::Fatal("intrusive_ptr p is equal to another pointer, "
"something wrong with constructor"));
PADDLE_ENFORCE_EQ(
p == copy.get(),
true,
common::errors::Fatal(
"blank intrusive_ptr p's content is not equal to its copy, something "
"wrong with constructor or get funtion"));
PADDLE_ENFORCE_EQ(
p != p1.get(),
true,
common::errors::Fatal(
"intrusive_ptr p's content is equal to another blank pointer, "
"something wrong with constructor or get function"));
PADDLE_ENFORCE_EQ(
p.get() == copy,
true,
common::errors::Fatal(
"blank intrusive_ptr p's content is not equal to its copy, something "
"wrong with constructor or get funtion"));
PADDLE_ENFORCE_EQ(
p.get() != p1,
true,
common::errors::Fatal(
"intrusive_ptr p's content is equal to another blank pointer, "
"something wrong with constructor or get function"));
PADDLE_ENFORCE_EQ(
null == nullptr,
true,
common::errors::Fatal("variable or constant whose name is null is not a "
"nullptr, something wrong with operator=="));
PADDLE_ENFORCE_EQ(
nullptr == null,
true,
common::errors::Fatal("variable or constant whose name is null is not a "
"nullptr, something wrong with operator=="));
PADDLE_ENFORCE_EQ(p != nullptr,
true,
common::errors::Fatal(
"intrusive_ptr p is not not_equal to null, something "
"wrong with constructor or operator!= "));
PADDLE_ENFORCE_EQ(nullptr != p,
true,
common::errors::Fatal(
"intrusive_ptr p is not not_equal to null, something "
"wrong with constructor or operator!= "));
}

} // namespace tests
} // namespace phi
11 changes: 10 additions & 1 deletion test/cpp/phi/core/test_sparse_coo_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,20 @@ TEST(sparse_coo_tensor, other_function) {

// Test shallow_copy
SparseCooTensor coo2(coo);
CHECK(coo.dims() == coo2.dims());
PADDLE_ENFORCE_EQ(
coo.dims(),
coo2.dims(),
common::errors::Fatal("`coo.dims()` is not equal to `coo2.dims()`, "
"something wrong with shallow copy assignment"));

// Test shallow_copy_assignment
SparseCooTensor coo3 = coo2;
CHECK(coo3.dims() == coo2.dims());
PADDLE_ENFORCE_EQ(
coo3.dims(),
coo2.dims(),
common::errors::Fatal("`coo3.dims()` is not equal to `coo2.dims()`, "
"something wrong with shallow copy assignment"));
}

} // namespace tests
Expand Down
13 changes: 10 additions & 3 deletions test/cpp/phi/core/test_sparse_csr_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ TEST(sparse_csr_tensor, construct) {
CHECK(sparse.place() == phi::CPUPlace());
CHECK(sparse.initialized() == true);
}

TEST(sparse_csr_tensor, other_function) {
auto fancy_allocator = std::unique_ptr<Allocator>(new FancyAllocator);
auto alloc = fancy_allocator.get();
Expand Down Expand Up @@ -107,11 +106,19 @@ TEST(sparse_csr_tensor, other_function) {

// Test shallow_copy
SparseCsrTensor csr2(csr);
CHECK(csr.dims() == csr2.dims());
PADDLE_ENFORCE_EQ(
csr.dims(),
csr2.dims(),
common::errors::Fatal("`csr.dims()` should be equal to `csr2.dims()`, "
"something wrong with shallow copy"));

// Test shallow_copy_assignment
SparseCsrTensor csr3 = csr2;
CHECK(csr3.dims() == csr2.dims());
PADDLE_ENFORCE_EQ(
csr3.dims(),
csr2.dims(),
common::errors::Fatal("``csr3.dims()` should be equal to `csr2.dims()`, "
"something wrong with shallow copy assignment"));
}

} // namespace tests
Expand Down
Loading

0 comments on commit dfcc447

Please sign in to comment.