提交 da39d84a 编写于 作者: C chenweihang

refine by reviewer's advice

上级 b1dd4149
......@@ -263,7 +263,7 @@ inline void throw_on_error(T e) {
* PADDLE_ENFORCE_EQ(a, b);
*
* will raise an expression described as follows:
* "Data check failed. Expected input a == b, but received a(1) != b(2)."
* "Enforce failed. Expected input a == b, but received a(1) != b(2)."
* with detailed stack information.
*
* extra messages is also supported, for example:
......@@ -293,7 +293,7 @@ inline void throw_on_error(T e) {
#define __PADDLE_BINARY_COMPARE(__VAL0, __VAL1, __CMP, __INV_CMP, ...) \
do { \
if (UNLIKELY(!((__VAL0)__CMP(__VAL1)))) { \
PADDLE_THROW("Data check failed. Expected %s " #__CMP \
PADDLE_THROW("Enforce failed. Expected %s " #__CMP \
" %s, but received %s:%s " #__INV_CMP " %s:%s.\n%s", \
#__VAL0, #__VAL1, #__VAL0, \
paddle::string::to_string(__VAL0), #__VAL1, \
......
......@@ -56,7 +56,7 @@ TEST(ENFORCE_EQ, NO_EXTRA_MSG_FAIL) {
caught_exception = true;
HasPrefix(
StringPiece(error.what()),
"Data check failed. Expected a == 1 + 3, but received a:2 != 1 + 3:4.");
"Enforce failed. Expected a == 1 + 3, but received a:2 != 1 + 3:4.");
}
EXPECT_TRUE(caught_exception);
}
......@@ -69,7 +69,7 @@ TEST(ENFORCE_EQ, EXTRA_MSG_FAIL) {
} catch (paddle::platform::EnforceNotMet error) {
caught_exception = true;
HasPrefix(StringPiece(error.what()),
"Data check failed. Expected a == 1 + 3, but received a:2 != 1 + "
"Enforce failed. Expected a == 1 + 3, but received a:2 != 1 + "
"3:4.\ntheir size not match");
}
EXPECT_TRUE(caught_exception);
......@@ -89,7 +89,7 @@ TEST(ENFORCE_NE, FAIL) {
caught_exception = true;
EXPECT_TRUE(HasPrefix(
StringPiece(error.what()),
"Data check failed. Expected 1.0 != 1UL, but received 1.0:1 == 1UL:1."))
"Enforce failed. Expected 1.0 != 1UL, but received 1.0:1 == 1UL:1."))
<< error.what() << " does not have expected prefix";
}
EXPECT_TRUE(caught_exception);
......@@ -104,7 +104,7 @@ TEST(ENFORCE_GT, FAIL) {
caught_exception = true;
EXPECT_TRUE(HasPrefix(
StringPiece(error.what()),
"Data check failed. Expected 1 > 2UL, but received 1:1 <= 2UL:2."));
"Enforce failed. Expected 1 > 2UL, but received 1:1 <= 2UL:2."));
}
EXPECT_TRUE(caught_exception);
}
......@@ -123,7 +123,7 @@ TEST(ENFORCE_GE, FAIL) {
caught_exception = true;
EXPECT_TRUE(HasPrefix(
StringPiece(error.what()),
"Data check failed. Expected 1 >= 2UL, but received 1:1 < 2UL:2."));
"Enforce failed. Expected 1 >= 2UL, but received 1:1 < 2UL:2."));
}
EXPECT_TRUE(caught_exception);
}
......@@ -143,7 +143,7 @@ TEST(ENFORCE_LE, FAIL) {
caught_exception = true;
EXPECT_TRUE(HasPrefix(
StringPiece(error.what()),
"Data check failed. Expected 1 > 2UL, but received 1:1 <= 2UL:2."));
"Enforce failed. Expected 1 > 2UL, but received 1:1 <= 2UL:2."));
}
EXPECT_TRUE(caught_exception);
}
......@@ -160,7 +160,7 @@ TEST(ENFORCE_LT, FAIL) {
} catch (paddle::platform::EnforceNotMet error) {
caught_exception = true;
EXPECT_TRUE(HasPrefix(StringPiece(error.what()),
"Data check failed. Expected 1UL < 0.12, but "
"Enforce failed. Expected 1UL < 0.12, but "
"received 1UL:1 >= 0.12:0.12."));
}
EXPECT_TRUE(caught_exception);
......
......@@ -100,25 +100,26 @@ size_t GpuMinChunkSize() {
size_t GpuMaxChunkSize() {
size_t total = 0;
size_t available_memory = 0;
size_t available = 0;
GpuMemoryUsage(&available_memory, &total);
VLOG(10) << "GPU Usage " << available_memory / 1024 / 1024 << "M/"
GpuMemoryUsage(&available, &total);
VLOG(10) << "GPU Usage " << available / 1024 / 1024 << "M/"
<< total / 1024 / 1024 << "M";
size_t reserving = static_cast<size_t>(0.05 * total);
// If available less than minimum chunk size, no usable memory exists.
available_memory = std::min(
std::max(available_memory, GpuMinChunkSize()) - GpuMinChunkSize(),
available =
std::min(std::max(available, GpuMinChunkSize()) - GpuMinChunkSize(),
total - reserving);
// Reserving the rest memory for page tables, etc.
size_t allocating_memory = static_cast<size_t>(
FLAGS_fraction_of_gpu_memory_to_use * (total - reserving));
size_t allocating = static_cast<size_t>(FLAGS_fraction_of_gpu_memory_to_use *
(total - reserving));
PADDLE_ENFORCE_LE(allocating_memory, available_memory);
PADDLE_ENFORCE_LE(allocating, available,
"Insufficient GPU memory to allocation.");
return allocating_memory;
return allocating;
}
void GpuMemcpyAsync(void *dst, const void *src, size_t count,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册