Skip to content

Commit da39d84

Browse files
committed
refine by reviewer's advice
1 parent b1dd414 commit da39d84

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

paddle/fluid/platform/enforce.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ inline void throw_on_error(T e) {
263263
* PADDLE_ENFORCE_EQ(a, b);
264264
*
265265
* will raise an expression described as follows:
266-
* "Data check failed. Expected input a == b, but received a(1) != b(2)."
266+
* "Enforce failed. Expected input a == b, but received a(1) != b(2)."
267267
* with detailed stack information.
268268
*
269269
* extra messages is also supported, for example:
@@ -293,7 +293,7 @@ inline void throw_on_error(T e) {
293293
#define __PADDLE_BINARY_COMPARE(__VAL0, __VAL1, __CMP, __INV_CMP, ...) \
294294
do { \
295295
if (UNLIKELY(!((__VAL0)__CMP(__VAL1)))) { \
296-
PADDLE_THROW("Data check failed. Expected %s " #__CMP \
296+
PADDLE_THROW("Enforce failed. Expected %s " #__CMP \
297297
" %s, but received %s:%s " #__INV_CMP " %s:%s.\n%s", \
298298
#__VAL0, #__VAL1, #__VAL0, \
299299
paddle::string::to_string(__VAL0), #__VAL1, \

paddle/fluid/platform/enforce_test.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ TEST(ENFORCE_EQ, NO_EXTRA_MSG_FAIL) {
5656
caught_exception = true;
5757
HasPrefix(
5858
StringPiece(error.what()),
59-
"Data check failed. Expected a == 1 + 3, but received a:2 != 1 + 3:4.");
59+
"Enforce failed. Expected a == 1 + 3, but received a:2 != 1 + 3:4.");
6060
}
6161
EXPECT_TRUE(caught_exception);
6262
}
@@ -69,7 +69,7 @@ TEST(ENFORCE_EQ, EXTRA_MSG_FAIL) {
6969
} catch (paddle::platform::EnforceNotMet error) {
7070
caught_exception = true;
7171
HasPrefix(StringPiece(error.what()),
72-
"Data check failed. Expected a == 1 + 3, but received a:2 != 1 + "
72+
"Enforce failed. Expected a == 1 + 3, but received a:2 != 1 + "
7373
"3:4.\ntheir size not match");
7474
}
7575
EXPECT_TRUE(caught_exception);
@@ -89,7 +89,7 @@ TEST(ENFORCE_NE, FAIL) {
8989
caught_exception = true;
9090
EXPECT_TRUE(HasPrefix(
9191
StringPiece(error.what()),
92-
"Data check failed. Expected 1.0 != 1UL, but received 1.0:1 == 1UL:1."))
92+
"Enforce failed. Expected 1.0 != 1UL, but received 1.0:1 == 1UL:1."))
9393
<< error.what() << " does not have expected prefix";
9494
}
9595
EXPECT_TRUE(caught_exception);
@@ -104,7 +104,7 @@ TEST(ENFORCE_GT, FAIL) {
104104
caught_exception = true;
105105
EXPECT_TRUE(HasPrefix(
106106
StringPiece(error.what()),
107-
"Data check failed. Expected 1 > 2UL, but received 1:1 <= 2UL:2."));
107+
"Enforce failed. Expected 1 > 2UL, but received 1:1 <= 2UL:2."));
108108
}
109109
EXPECT_TRUE(caught_exception);
110110
}
@@ -123,7 +123,7 @@ TEST(ENFORCE_GE, FAIL) {
123123
caught_exception = true;
124124
EXPECT_TRUE(HasPrefix(
125125
StringPiece(error.what()),
126-
"Data check failed. Expected 1 >= 2UL, but received 1:1 < 2UL:2."));
126+
"Enforce failed. Expected 1 >= 2UL, but received 1:1 < 2UL:2."));
127127
}
128128
EXPECT_TRUE(caught_exception);
129129
}
@@ -143,7 +143,7 @@ TEST(ENFORCE_LE, FAIL) {
143143
caught_exception = true;
144144
EXPECT_TRUE(HasPrefix(
145145
StringPiece(error.what()),
146-
"Data check failed. Expected 1 > 2UL, but received 1:1 <= 2UL:2."));
146+
"Enforce failed. Expected 1 > 2UL, but received 1:1 <= 2UL:2."));
147147
}
148148
EXPECT_TRUE(caught_exception);
149149
}
@@ -160,7 +160,7 @@ TEST(ENFORCE_LT, FAIL) {
160160
} catch (paddle::platform::EnforceNotMet error) {
161161
caught_exception = true;
162162
EXPECT_TRUE(HasPrefix(StringPiece(error.what()),
163-
"Data check failed. Expected 1UL < 0.12, but "
163+
"Enforce failed. Expected 1UL < 0.12, but "
164164
"received 1UL:1 >= 0.12:0.12."));
165165
}
166166
EXPECT_TRUE(caught_exception);

paddle/fluid/platform/gpu_info.cc

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

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

105-
GpuMemoryUsage(&available_memory, &total);
106-
VLOG(10) << "GPU Usage " << available_memory / 1024 / 1024 << "M/"
105+
GpuMemoryUsage(&available, &total);
106+
VLOG(10) << "GPU Usage " << available / 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_memory = std::min(
111-
std::max(available_memory, GpuMinChunkSize()) - GpuMinChunkSize(),
112-
total - reserving);
110+
available =
111+
std::min(std::max(available, GpuMinChunkSize()) - GpuMinChunkSize(),
112+
total - reserving);
113113

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

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

119-
PADDLE_ENFORCE_LE(allocating_memory, available_memory);
119+
PADDLE_ENFORCE_LE(allocating, available,
120+
"Insufficient GPU memory to allocation.");
120121

121-
return allocating_memory;
122+
return allocating;
122123
}
123124

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

0 commit comments

Comments
 (0)