3 #include "caffe2/core/common.h" 6 #include "caffe2/core/common_omp.h" 11 #endif // CAFFE2_USE_MKL 13 #include "caffe2/core/init.h" 16 caffe2_omp_num_threads,
18 "The number of openmp threads. 0 to use default value. " 19 "Does not have effect if OpenMP is disabled.");
21 caffe2_mkl_num_threads,
23 "The number of mkl threads. 0 to use default value. If set, " 24 "this overrides the caffe2_omp_num_threads flag if both are set. " 25 "Does not have effect if MKL is not used.");
30 bool Caffe2SetOpenMPThreads(
int*,
char***) {
31 if (!getenv(
"OMP_NUM_THREADS")) {
34 VLOG(1) <<
"OMP_NUM_THREADS not passed, defaulting to 1 thread";
35 omp_set_num_threads(1);
38 if (FLAGS_caffe2_omp_num_threads > 0) {
39 VLOG(1) <<
"Setting omp_num_threads to " << FLAGS_caffe2_omp_num_threads;
40 omp_set_num_threads(FLAGS_caffe2_omp_num_threads);
42 VLOG(1) <<
"Caffe2 running with " << omp_get_max_threads() <<
" OMP threads";
45 REGISTER_CAFFE2_INIT_FUNCTION(Caffe2SetOpenMPThreads,
46 &Caffe2SetOpenMPThreads,
47 "Set OpenMP threads.");
51 bool Caffe2SetMKLThreads(
int*,
char***) {
52 if (!getenv(
"MKL_NUM_THREADS")) {
53 VLOG(1) <<
"MKL_NUM_THREADS not passed, defaulting to 1 thread";
54 mkl_set_num_threads(1);
58 if (FLAGS_caffe2_omp_num_threads > 0) {
59 VLOG(1) <<
"Setting mkl_num_threads to " << FLAGS_caffe2_omp_num_threads
60 <<
" as inherited from omp_num_threads.";
61 mkl_set_num_threads(FLAGS_caffe2_omp_num_threads);
65 if (FLAGS_caffe2_mkl_num_threads > 0) {
66 VLOG(1) <<
"Setting mkl_num_threads to " << FLAGS_caffe2_mkl_num_threads;
67 mkl_set_num_threads(FLAGS_caffe2_mkl_num_threads);
69 VLOG(1) <<
"Caffe2 running with " << mkl_get_max_threads() <<
" MKL threads";
72 REGISTER_CAFFE2_INIT_FUNCTION(
76 #endif // CAFFE2_USE_MKL A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...