未验证 提交 2babd6ff 编写于 作者: C Chen Weihang 提交者: GitHub

Add compile limit for PADDLE_ENFORCE without error message (#28221)

* add compile limit for paddle enforce

* polish elementwise_op_function.cu.h

* fix failed unittest

* fix windows compile failed

* detail polish

* revert no type constructor
上级 4ea23307
......@@ -108,7 +108,9 @@ void FindWhileOp(Graph* graph) {
GraphSafeRemoveNodes(graph, marked_nodes);
}
#define CHECK_P1(x) PADDLE_ENFORCE_NOT_NULL(x);
#define CHECK_P1(x) \
PADDLE_ENFORCE_NOT_NULL( \
x, platform::errors::NotFound("%s is a null pointer.", #x))
#define CHECK_P2(x0, x1) \
CHECK_P1(x0); \
CHECK_P1(x1);
......
......@@ -158,8 +158,8 @@ Allocation* BestFitAllocator::AllocateImpl(size_t size) {
}
}
if (UNLIKELY(highest_set_bit == free_chunks_.size())) {
PADDLE_THROW_BAD_ALLOC("Cannot allocate %d, All fragments size is %d", size,
FreeSize());
PADDLE_THROW_BAD_ALLOC(platform::errors::ResourceExhausted(
"Cannot allocate %d, All fragments size is %d.", size, FreeSize()));
}
auto chunk_it = SplitChunk(size, highest_set_bit, map_it);
return new BestFitAllocation(this, chunk_it);
......
......@@ -105,7 +105,8 @@ class DummyAllocator : public Allocator {
protected:
Allocation *AllocateImpl(size_t size) override {
PADDLE_THROW_BAD_ALLOC("Always BadAlloc");
PADDLE_THROW_BAD_ALLOC(platform::errors::ResourceExhausted(
"Here is a test exception, always BadAlloc."));
}
void FreeImpl(Allocation *) override {}
......@@ -120,7 +121,7 @@ TEST(RetryAllocator, RetryAllocatorLastAllocFailure) {
ASSERT_TRUE(false);
allocation.reset();
} catch (BadAlloc &ex) {
ASSERT_TRUE(std::string(ex.what()).find("Always BadAlloc") !=
ASSERT_TRUE(std::string(ex.what()).find("always BadAlloc") !=
std::string::npos);
}
}
......
......@@ -28,10 +28,9 @@ class CUDNNAffineGridOpKernel : public framework::OpKernel<T> {
void Compute(const framework::ExecutionContext& ctx) const override {
PADDLE_ENFORCE_EQ(
platform::is_gpu_place(ctx.GetPlace()), true,
platform::errors::InvalidArgument("Only "
"support for CUDAPlace.Please switch "
"your context from CPUPlace to "
"CUDAPlace or update your cudnn."));
platform::errors::InvalidArgument(
"Only support for CUDAPlace.Please switch your context from "
"CPUPlace to CUDAPlace or update your cudnn."));
auto& dev_ctx = ctx.template device_context<platform::CUDADeviceContext>();
auto handle = dev_ctx.cudnn_handle();
auto* theta = ctx.Input<Tensor>("Theta");
......@@ -106,12 +105,9 @@ class CUDNNAffineGridGradOpKernel : public framework::OpKernel<T> {
const T* output_grad_data = output_grad->data<T>();
T* theta_grad_data = theta_grad->mutable_data<T>(ctx.GetPlace());
PADDLE_ENFORCE_EQ(
PADDLE_ENFORCE_CUDA_SUCCESS(
platform::dynload::cudnnSpatialTfGridGeneratorBackward(
handle, cudnn_st_desc, output_grad_data, theta_grad_data),
0,
"Some errors "
"has occurred during forward computation in cudnn;");
handle, cudnn_st_desc, output_grad_data, theta_grad_data));
}
};
......
......@@ -133,7 +133,8 @@ class ClipKernel : public framework::OpKernel<T> {
trans(context.template device_context<DeviceContext>(), out_data,
out_data + numel, out_data, ClipFunctor<T>(min, max));
} else {
PADDLE_THROW("ClipOp only supports LoDTensor and SelectedRows");
PADDLE_THROW(platform::errors::Unavailable(
"ClipOp only supports LoDTensor and SelectedRows."));
}
}
};
......
......@@ -30,33 +30,22 @@ typedef ::paddle::platform::error::Code Code;
class ErrorSummary {
public:
// Note(chenweihang): Final deprecated constructor
// This constructor is only used to be compatible with
// current existing no error message PADDLE_ENFORCE_*
ErrorSummary() {
code_ = paddle::platform::error::LEGACY;
msg_ =
"An error occurred here. There is no accurate error hint for this "
"error yet. We are continuously in the process of increasing hint for "
"this kind of error check. It would be helpful if you could inform us "
"of how this conversion went by opening a github issue. And we will "
"resolve it with high priority.\n"
" - New issue link: "
"https://github.com/PaddlePaddle/Paddle/issues/new\n"
" - Recommended issue content: all error stack information";
}
// Note(chenweihang): Final deprecated constructor
// This constructor is used to be compatible with
// current existing untyped PADDLE_ENFORCE_*
// PADDLE_ENFORCE
// Note(chenweihang): Windows openblas need this
// constructor for compiling PADDLE_ENFORCE in *.cu,
// this is a bug cause we can't remove this
// constructor now.
template <typename... Args>
explicit ErrorSummary(Args... args) {
code_ = paddle::platform::error::LEGACY;
msg_ = paddle::string::Sprintf(args...);
}
// Note(chenweihang): Recommended constructor
// Note(chenweihang): Only recommended constructor
// No longer supports PADDLE_ENFORCE without type or without error message
explicit ErrorSummary(Code code, std::string msg) : code_(code), msg_(msg) {}
Code code() const { return code_; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册