Skip to content

Commit a8c2ff3

Browse files
committed
refine the initial cpu memory flag for mkldnn
1 parent 3a25f21 commit a8c2ff3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

paddle/fluid/platform/cpu_info.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ DEFINE_double(fraction_of_cpu_memory_to_use, 1,
2828
"Default use 100% of CPU memory for PaddlePaddle,"
2929
"reserve the rest for page tables, etc");
3030

31-
DEFINE_uint64(
32-
initial_cpu_memory_in_mb, 500,
33-
"Default initial 500MB of CPU memory for PaddlePaddle, in MD unit.");
31+
DEFINE_uint64(initial_cpu_memory_in_mb,
32+
#ifdef PADDLE_WITH_MKLDNN
33+
1000,
34+
#else
35+
500,
36+
#endif
37+
"Initial CPU memory for PaddlePaddle, in MD unit.");
3438

3539
DEFINE_double(
3640
fraction_of_cuda_pinned_memory_to_use, 0.5,
@@ -59,10 +63,7 @@ inline size_t CpuTotalPhysicalMemory() {
5963
size_t CpuMaxAllocSize() {
6064
// For distributed systems, it requires configuring and limiting
6165
// the fraction of memory to use.
62-
return std::min(
63-
static_cast<size_t>(FLAGS_fraction_of_cpu_memory_to_use *
64-
CpuTotalPhysicalMemory()),
65-
static_cast<size_t>(FLAGS_initial_cpu_memory_in_mb * 1 << 20));
66+
return FLAGS_fraction_of_cpu_memory_to_use * CpuTotalPhysicalMemory();
6667
}
6768

6869
size_t CpuMinChunkSize() {
@@ -71,8 +72,11 @@ size_t CpuMinChunkSize() {
7172
}
7273

7374
size_t CpuMaxChunkSize() {
74-
// Allow to allocate the maximum chunk size is roughly 3% of CPU memory.
75-
return CpuMaxAllocSize() / 32;
75+
// Allow to allocate the maximum chunk size is roughly 3% of CPU memory,
76+
// or the initial_cpu_memory_in_mb.
77+
return std::min(
78+
static_cast<size_t>(CpuMaxAllocSize() / 32),
79+
static_cast<size_t>(FLAGS_initial_cpu_memory_in_mb * 1 << 20));
7680
}
7781

7882
size_t CUDAPinnedMaxAllocSize() {

0 commit comments

Comments
 (0)