@@ -43,6 +43,51 @@ function ver2num() {
43
43
set +e
44
44
}
45
45
46
+ function cpu_config() {
47
+ # auto set KMP_AFFINITY and OMP_DYNAMIC from Hyper Threading Status
48
+ # only when MKLDNN or MKLML enabled
49
+ if [ " @WITH_MKLDNN@" == " OFF" ] && [ " @WITH_MKLML@" == " OFF" ]; then
50
+ return 0
51
+ fi
52
+ ht=` lscpu | grep " per core" | awk -F' :' ' {print $2}' | xargs`
53
+ if [ $ht -eq 1 ]; then # HT is OFF
54
+ if [ -z " $KMP_AFFINITY " ]; then
55
+ export KMP_AFFINITY=" granularity=fine,compact,0,0"
56
+ fi
57
+ if [ -z " $OMP_DYNAMIC " ]; then
58
+ export OMP_DYNAMIC=" FALSE"
59
+ fi
60
+ else # HT is ON
61
+ if [ -z " $KMP_AFFINITY " ]; then
62
+ export KMP_AFFINITY=" granularity=fine,compact,1,0"
63
+ fi
64
+ if [ -z " $OMP_DYNAMIC " ]; then
65
+ export OMP_DYNAMIC=" True"
66
+ fi
67
+ fi
68
+ }
69
+
70
+ function threads_config() {
71
+ # auto set OMP_NUM_THREADS and MKL_NUM_THREADS
72
+ # according to trainer_count and total processors
73
+ # only when MKLDNN or MKLML enabled
74
+ if [ " @WITH_MKLDNN@" == " OFF" ] && [ " @WITH_MKLML@" == " OFF" ]; then
75
+ return 0
76
+ fi
77
+ processors=` grep " processor" /proc/cpuinfo| sort -u| wc -l`
78
+ trainers=` grep -Eo ' trainer_count.[0-9]+' <<< " $@" | grep -Eo ' [0-9]+' | xargs`
79
+ if [ -z $trainers ]; then
80
+ trainers=1
81
+ fi
82
+ threads=$(( processors / trainers))
83
+ if [ -z " $OMP_NUM_THREADS " ]; then
84
+ export OMP_NUM_THREADS=$threads
85
+ fi
86
+ if [ -z " $MKL_NUM_THREADS " ]; then
87
+ export MKL_NUM_THREADS=$threads
88
+ fi
89
+ }
90
+
46
91
PADDLE_CONF_HOME=" $HOME /.config/paddle"
47
92
mkdir -p ${PADDLE_CONF_HOME}
48
93
@@ -92,9 +137,11 @@ else:
92
137
sys.exit(0)
93
138
EOF
94
139
140
+ cpu_config
95
141
96
142
case " $1 " in
97
143
" train" )
144
+ threads_config $@
98
145
${DEBUGGER} $PADDLE_BIN_PATH /paddle_trainer ${@: 2}
99
146
;;
100
147
" merge_model" )
0 commit comments