Skip to content

Commit

Permalink
refine the initial cpu memory flag for mkldnn
Browse files Browse the repository at this point in the history
  • Loading branch information
tensor-tang committed Jun 16, 2018
1 parent 3a25f21 commit a8c2ff3
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions paddle/fluid/platform/cpu_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ DEFINE_double(fraction_of_cpu_memory_to_use, 1,
"Default use 100% of CPU memory for PaddlePaddle,"
"reserve the rest for page tables, etc");

DEFINE_uint64(
initial_cpu_memory_in_mb, 500,
"Default initial 500MB of CPU memory for PaddlePaddle, in MD unit.");
DEFINE_uint64(initial_cpu_memory_in_mb,
#ifdef PADDLE_WITH_MKLDNN
1000,
#else
500,
#endif
"Initial CPU memory for PaddlePaddle, in MD unit.");

DEFINE_double(
fraction_of_cuda_pinned_memory_to_use, 0.5,
Expand Down Expand Up @@ -59,10 +63,7 @@ inline size_t CpuTotalPhysicalMemory() {
size_t CpuMaxAllocSize() {
// For distributed systems, it requires configuring and limiting
// the fraction of memory to use.
return std::min(
static_cast<size_t>(FLAGS_fraction_of_cpu_memory_to_use *
CpuTotalPhysicalMemory()),
static_cast<size_t>(FLAGS_initial_cpu_memory_in_mb * 1 << 20));
return FLAGS_fraction_of_cpu_memory_to_use * CpuTotalPhysicalMemory();
}

size_t CpuMinChunkSize() {
Expand All @@ -71,8 +72,11 @@ size_t CpuMinChunkSize() {
}

size_t CpuMaxChunkSize() {
// Allow to allocate the maximum chunk size is roughly 3% of CPU memory.
return CpuMaxAllocSize() / 32;
// Allow to allocate the maximum chunk size is roughly 3% of CPU memory,
// or the initial_cpu_memory_in_mb.
return std::min(
static_cast<size_t>(CpuMaxAllocSize() / 32),
static_cast<size_t>(FLAGS_initial_cpu_memory_in_mb * 1 << 20));
}

size_t CUDAPinnedMaxAllocSize() {
Expand Down

0 comments on commit a8c2ff3

Please sign in to comment.