From 575bc5727230e0278ed6fff229d4e809c9e30237 Mon Sep 17 00:00:00 2001 From: tensor-tang Date: Sat, 22 Jun 2019 13:35:47 +0800 Subject: [PATCH] cherry pick refine core cmake warning and print more info (#18248) (#18267) * refine core cmake warning and print more info * fix comments test=release/1.5 --- python/CMakeLists.txt | 8 ++++-- python/paddle/fluid/__init__.py | 17 ++++++++++++ python/paddle/fluid/core.py | 46 ++++++++++++++++++++++++--------- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index ec6c19cf098..62fd81aa54c 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -14,8 +14,12 @@ set(FLUID_CORE_NAME "core") if(WITH_AVX AND AVX_FOUND) set(FLUID_CORE_NAME "${FLUID_CORE_NAME}_avx") if(NOT DEFINED NOAVX_CORE_FILE OR NOAVX_CORE_FILE STREQUAL "") - message(WARNING "You are building AVX version without NOAVX core, \ - and the wheel package may fail on NOAVX machine.") + message(STATUS "WARNING: This is just a warning for publishing release. + You are building AVX version without NOAVX core. + So the wheel package may fail on NOAVX machine. + You can add -DFLUID_CORE_NAME=/path/to/your/core_noavx.* in cmake command + to get a full wheel package to resolve this warning. + While, this version will still work on local machine.") endif() if(NOAVX_CORE_FILE AND NOT EXISTS "${NOAVX_CORE_FILE}") diff --git a/python/paddle/fluid/__init__.py b/python/paddle/fluid/__init__.py index 1a3a1dd5096..3b19e9f210d 100644 --- a/python/paddle/fluid/__init__.py +++ b/python/paddle/fluid/__init__.py @@ -14,6 +14,23 @@ from __future__ import print_function import os +import sys + +# The legacy core need to be removed before "import core", +# in case of users installing paddlepadde without -U option +core_suffix = 'so' +if os.name == 'nt': + core_suffix = 'pyd' + +legacy_core = os.path.abspath(os.path.dirname( + __file__)) + os.sep + 'core.' + core_suffix +if os.path.exists(legacy_core): + sys.stderr.write('Deleting legacy file ' + legacy_core + '\n') + try: + os.remove(legacy_core) + except Exception as e: + raise e + # import all class inside framework into fluid module from . import framework from .framework import * diff --git a/python/paddle/fluid/core.py b/python/paddle/fluid/core.py index 80a14ca08d0..23827f5677a 100644 --- a/python/paddle/fluid/core.py +++ b/python/paddle/fluid/core.py @@ -18,10 +18,23 @@ import sys import os from cpuinfo import get_cpu_info +core_suffix = 'so' +if os.name == 'nt': + core_suffix = 'pyd' + +has_avx_core = False +has_noavx_core = False + +current_path = os.path.abspath(os.path.dirname(__file__)) +if os.path.exists(current_path + os.sep + 'core_avx.' + core_suffix): + has_avx_core = True + +if os.path.exists(current_path + os.sep + 'core_noavx.' + core_suffix): + has_noavx_core = True + try: if os.name == 'nt': - third_lib_path = os.path.abspath(os.path.dirname( - __file__)) + os.sep + '..' + os.sep + 'libs' + third_lib_path = current_path + os.sep + '..' + os.sep + 'libs' os.environ['path'] += ';' + third_lib_path sys.path.append(third_lib_path) @@ -59,12 +72,17 @@ if 'avx' in get_cpu_info()['flags']: from .core_avx import _set_fuse_parameter_memory_size from .core_avx import _is_dygraph_debug_enabled from .core_avx import _dygraph_debug_level - except ImportError: - sys.stderr.write( - 'WARNING: Can not import avx core. You may not build with AVX, ' - 'but AVX is supported on local machine, you could build paddle ' - 'WITH_AVX=ON to get better performance. ') - load_noavx = True + except ImportError as e: + if has_avx_core: + raise e + else: + sys.stderr.write( + 'WARNING: Do not have avx core. You may not build with AVX, ' + 'but AVX is supported on local machine.\n You could build paddle ' + 'WITH_AVX=ON to get better performance.\n') + load_noavx = True + except Exception as e: + raise e else: load_noavx = True @@ -82,7 +100,11 @@ if load_noavx: from .core_noavx import _set_fuse_parameter_memory_size from .core_noavx import _is_dygraph_debug_enabled from .core_noavx import _dygraph_debug_level - except ImportError as error: - sys.exit("Error: Can not load core_noavx.* ." + - error.__class__.__name__) - load_noavx = True + except ImportError as e: + if has_noavx_core: + sys.stderr.write( + 'Error: Can not import noavx core while this file exists ' + + current_path + os.sep + 'core_noavx.' + core_suffix + '\n') + raise e + except Exception as e: + raise e -- GitLab