Skip to content

Commit e8f5757

Browse files
authored
Merge pull request #11525 from tensor-tang/refine/mem
refine the initial cpu memory flag for mkldnn
2 parents 69827f3 + 9a25f28 commit e8f5757

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

paddle/fluid/platform/cpu_info.cc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ 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+
/* Aligned with mozga-intel, MKLDNN need at least 5000 MB
34+
* to obtain the best performance*/
35+
5000,
36+
#else
37+
500,
38+
#endif
39+
"Initial CPU memory for PaddlePaddle, in MD unit.");
3440

3541
DEFINE_double(
3642
fraction_of_cuda_pinned_memory_to_use, 0.5,
@@ -59,10 +65,7 @@ inline size_t CpuTotalPhysicalMemory() {
5965
size_t CpuMaxAllocSize() {
6066
// For distributed systems, it requires configuring and limiting
6167
// 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));
68+
return FLAGS_fraction_of_cpu_memory_to_use * CpuTotalPhysicalMemory();
6669
}
6770

6871
size_t CpuMinChunkSize() {
@@ -71,8 +74,11 @@ size_t CpuMinChunkSize() {
7174
}
7275

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

7884
size_t CUDAPinnedMaxAllocSize() {

paddle/testing/paddle_gtest_main.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ int main(int argc, char** argv) {
3030
new_argv.push_back(
3131
strdup("--tryfromenv=fraction_of_gpu_memory_to_use,use_pinned_memory"));
3232
#else
33-
new_argv.push_back(strdup("--tryfromenv=use_pinned_memory,use_mkldnn"));
34-
new_argv.push_back(strdup("--undefok=use_mkldnn"));
33+
new_argv.push_back(strdup(
34+
"--tryfromenv=use_pinned_memory,use_mkldnn,initial_cpu_memory_in_mb"));
35+
new_argv.push_back(strdup("--undefok=use_mkldnn,initial_cpu_memory_in_mb"));
3536
#endif
3637
int new_argc = static_cast<int>(new_argv.size());
3738
char** new_argv_address = new_argv.data();

python/paddle/fluid/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __bootstrap__():
117117

118118
read_env_flags = [
119119
'use_pinned_memory', 'check_nan_inf', 'benchmark', 'warpctc_dir',
120-
'eager_delete_scope', 'use_mkldnn'
120+
'eager_delete_scope', 'use_mkldnn', 'initial_cpu_memory_in_mb'
121121
]
122122
if core.is_compiled_with_cuda():
123123
read_env_flags += [

0 commit comments

Comments
 (0)