Suppress OpenMP debug messages when running Tensorflow on CPU

蹲街弑〆低调 提交于 2019-12-10 18:23:54

问题


When running a Python program on Linux that includes import tensorflow (installed without GPU support), a bunch of OpenMP debug messages are written to stdout, even when no functions from the tensorflow module are ever called. Here's an excerpt:

OMP: Info #212: KMP_AFFINITY: decoding x2APIC ids.
OMP: Info #210: KMP_AFFINITY: Affinity capable, using global cpuid leaf 11 info
OMP: Info #154: KMP_AFFINITY: Initial OS proc set respected: 0-3
OMP: Info #156: KMP_AFFINITY: 4 available OS procs
OMP: Info #157: KMP_AFFINITY: Uniform topology

Setting os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' before importing tensorflow does not get rid of these messages, how can I suppress them (from Python)?


回答1:


Bottom line: Set KMP_WARNINGS envvar to a false value (0,FALSE, off or no).

(If you use a multiple process setup, make sure to do this before you spawn child processes so that they inherit it.)


Googling "Affinity capable, using global cpuid leaf" (with quotes -- i.e. as a full phrase) finds https://github.com/catboost/catboost/blob/master/contrib/libs/cxxsupp/openmp/i18n/en_US.txt . It's a part of an OpenMP implementation. This code is not a part of tensorflow (and searching within https://github.com/tensorflow/tensorflow specifically for the phrase or a submodule reference named "openmp" finds nothing) but this is understandable because OpenMP is a part of a compiler implementation (this file specifically claims to be a part of LLVM -- i.e. clang). This code may not be exactly what your program is using but another version of it, but we can assume that the general logic is the same, so we can use this code for navigation.

Now, searching for references to the entity containing this phrase (namely, AffUseGlobCpuidL11 -- this is the ID of the message), then for a definition of KMP_INFORM, then for a definition of __kmp_msg ultimately finds the code doing the logging. It says that it only silences a message if ( severity != kmp_ms_fatal && __kmp_generate_warnings == kmp_warnings_off ). Looking through references to __kmp_generate_warnings to find where it's assigned finds https://github.com/catboost/catboost/blob/15712cfa704413d51618455326c30f5764956be5/contrib/libs/cxxsupp/openmp/kmp_settings.c#L944 and looking for __kmp_stg_parse_warnings finds https://github.com/catboost/catboost/blob/15712cfa704413d51618455326c30f5764956be5/contrib/libs/cxxsupp/openmp/kmp_settings.c#L4514 which suggests that name is "KMP_WARNINGS".

At this point, I assumed that this name should be documented. So googling for it will tell me faster how that "KMP_WARNINGS" is supposed to be set by the user and what the allowed values for it are. I was disappointed -- no official documentation comes up. Another result suggests though that it's an envvar, and valid values are: "Use "0", "FALSE". ".F.", "off", "no" as false values, "1", "TRUE", ".T.", "on", "yes" as true values." The source code also uses kmp_warnings_low as a possible value but the name __kmp_stg_parse_bool suggests that no, the user can only provide a "true" and "false" value, nothing else. The above filter criterion says that nothing but kmp_warnings_off would have an effect anyway, and https://github.com/catboost/catboost/blob/15712cfa704413d51618455326c30f5764956be5/contrib/libs/cxxsupp/openmp/kmp_global.c#L116 says that low is the default if nothing is provided by the user.



来源:https://stackoverflow.com/questions/56085015/suppress-openmp-debug-messages-when-running-tensorflow-on-cpu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!