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
revert-27871-prv-conv-grad-opt
Chen Weihang 5 years ago committed by GitHub
parent 4ea2330759
commit 2babd6ff67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -108,7 +108,9 @@ void FindWhileOp(Graph* graph) {
GraphSafeRemoveNodes(graph, marked_nodes); 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) \ #define CHECK_P2(x0, x1) \
CHECK_P1(x0); \ CHECK_P1(x0); \
CHECK_P1(x1); CHECK_P1(x1);

@ -158,8 +158,8 @@ Allocation* BestFitAllocator::AllocateImpl(size_t size) {
} }
} }
if (UNLIKELY(highest_set_bit == free_chunks_.size())) { if (UNLIKELY(highest_set_bit == free_chunks_.size())) {
PADDLE_THROW_BAD_ALLOC("Cannot allocate %d, All fragments size is %d", size, PADDLE_THROW_BAD_ALLOC(platform::errors::ResourceExhausted(
FreeSize()); "Cannot allocate %d, All fragments size is %d.", size, FreeSize()));
} }
auto chunk_it = SplitChunk(size, highest_set_bit, map_it); auto chunk_it = SplitChunk(size, highest_set_bit, map_it);
return new BestFitAllocation(this, chunk_it); return new BestFitAllocation(this, chunk_it);

@ -105,7 +105,8 @@ class DummyAllocator : public Allocator {
protected: protected:
Allocation *AllocateImpl(size_t size) override { 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 {} void FreeImpl(Allocation *) override {}
@ -120,7 +121,7 @@ TEST(RetryAllocator, RetryAllocatorLastAllocFailure) {
ASSERT_TRUE(false); ASSERT_TRUE(false);
allocation.reset(); allocation.reset();
} catch (BadAlloc &ex) { } catch (BadAlloc &ex) {
ASSERT_TRUE(std::string(ex.what()).find("Always BadAlloc") != ASSERT_TRUE(std::string(ex.what()).find("always BadAlloc") !=
std::string::npos); std::string::npos);
} }
} }

@ -28,10 +28,9 @@ class CUDNNAffineGridOpKernel : public framework::OpKernel<T> {
void Compute(const framework::ExecutionContext& ctx) const override { void Compute(const framework::ExecutionContext& ctx) const override {
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
platform::is_gpu_place(ctx.GetPlace()), true, platform::is_gpu_place(ctx.GetPlace()), true,
platform::errors::InvalidArgument("Only " platform::errors::InvalidArgument(
"support for CUDAPlace.Please switch " "Only support for CUDAPlace.Please switch your context from "
"your context from CPUPlace to " "CPUPlace to CUDAPlace or update your cudnn."));
"CUDAPlace or update your cudnn."));
auto& dev_ctx = ctx.template device_context<platform::CUDADeviceContext>(); auto& dev_ctx = ctx.template device_context<platform::CUDADeviceContext>();
auto handle = dev_ctx.cudnn_handle(); auto handle = dev_ctx.cudnn_handle();
auto* theta = ctx.Input<Tensor>("Theta"); 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>(); const T* output_grad_data = output_grad->data<T>();
T* theta_grad_data = theta_grad->mutable_data<T>(ctx.GetPlace()); T* theta_grad_data = theta_grad->mutable_data<T>(ctx.GetPlace());
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_CUDA_SUCCESS(
platform::dynload::cudnnSpatialTfGridGeneratorBackward( platform::dynload::cudnnSpatialTfGridGeneratorBackward(
handle, cudnn_st_desc, output_grad_data, theta_grad_data), handle, cudnn_st_desc, output_grad_data, theta_grad_data));
0,
"Some errors "
"has occurred during forward computation in cudnn;");
} }
}; };

@ -133,7 +133,8 @@ class ClipKernel : public framework::OpKernel<T> {
trans(context.template device_context<DeviceContext>(), out_data, trans(context.template device_context<DeviceContext>(), out_data,
out_data + numel, out_data, ClipFunctor<T>(min, max)); out_data + numel, out_data, ClipFunctor<T>(min, max));
} else { } 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 { class ErrorSummary {
public: 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 // Note(chenweihang): Final deprecated constructor
// This constructor is used to be compatible with // This constructor is used to be compatible with
// current existing untyped PADDLE_ENFORCE_* // current existing untyped PADDLE_ENFORCE_*
// 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> template <typename... Args>
explicit ErrorSummary(Args... args) { explicit ErrorSummary(Args... args) {
code_ = paddle::platform::error::LEGACY; code_ = paddle::platform::error::LEGACY;
msg_ = paddle::string::Sprintf(args...); 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) {} explicit ErrorSummary(Code code, std::string msg) : code_(code), msg_(msg) {}
Code code() const { return code_; } Code code() const { return code_; }

Loading…
Cancel
Save