Skip to content

Commit 61052cd

Browse files
committed
polish high frequency enforce error message
1 parent 88e47e1 commit 61052cd

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

paddle/fluid/platform/enforce.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ inline void throw_on_error(T e) {
263263
* PADDLE_ENFORCE_EQ(a, b);
264264
*
265265
* will raise an expression described as follows:
266-
* "enforce a == b failed, 1 != 2" with detailed stack information.
266+
* "Data check failed. Expected input a == b, but received a(1) != b(2)."
267+
* with detailed stack information.
267268
*
268269
* extra messages is also supported, for example:
269270
* PADDLE_ENFORCE(a, b, "some simple enforce failed between %d numbers", 2)
@@ -292,9 +293,10 @@ inline void throw_on_error(T e) {
292293
#define __PADDLE_BINARY_COMPARE(__VAL0, __VAL1, __CMP, __INV_CMP, ...) \
293294
do { \
294295
if (UNLIKELY(!((__VAL0)__CMP(__VAL1)))) { \
295-
PADDLE_THROW("enforce %s " #__CMP " %s failed, %s " #__INV_CMP \
296-
" %s\n%s", \
297-
#__VAL0, #__VAL1, paddle::string::to_string(__VAL0), \
296+
PADDLE_THROW("Data check failed. Expected %s " #__CMP \
297+
" %s, but received %s:%s " #__INV_CMP " %s:%s.\n%s", \
298+
#__VAL0, #__VAL1, #__VAL0, \
299+
paddle::string::to_string(__VAL0), #__VAL1, \
298300
paddle::string::to_string(__VAL1), \
299301
paddle::string::Sprintf("" __VA_ARGS__)); \
300302
} \

paddle/fluid/platform/gpu_info.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,25 @@ size_t GpuMinChunkSize() {
100100

101101
size_t GpuMaxChunkSize() {
102102
size_t total = 0;
103-
size_t available = 0;
103+
size_t available_memory = 0;
104104

105-
GpuMemoryUsage(&available, &total);
106-
VLOG(10) << "GPU Usage " << available / 1024 / 1024 << "M/"
105+
GpuMemoryUsage(&available_memory, &total);
106+
VLOG(10) << "GPU Usage " << available_memory / 1024 / 1024 << "M/"
107107
<< total / 1024 / 1024 << "M";
108108
size_t reserving = static_cast<size_t>(0.05 * total);
109109
// If available less than minimum chunk size, no usable memory exists.
110-
available =
111-
std::min(std::max(available, GpuMinChunkSize()) - GpuMinChunkSize(),
112-
total - reserving);
110+
available_memory = std::min(
111+
std::max(available_memory, GpuMinChunkSize()) - GpuMinChunkSize(),
112+
total - reserving);
113113

114114
// Reserving the rest memory for page tables, etc.
115115

116-
size_t allocating = static_cast<size_t>(FLAGS_fraction_of_gpu_memory_to_use *
117-
(total - reserving));
116+
size_t allocating_memory = static_cast<size_t>(
117+
FLAGS_fraction_of_gpu_memory_to_use * (total - reserving));
118118

119-
PADDLE_ENFORCE_LE(allocating, available);
119+
PADDLE_ENFORCE_LE(allocating_memory, available_memory);
120120

121-
return allocating;
121+
return allocating_memory;
122122
}
123123

124124
void GpuMemcpyAsync(void *dst, const void *src, size_t count,

0 commit comments

Comments
 (0)