Skip to content

Commit 575bc57

Browse files
authored
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
1 parent dd4b29c commit 575bc57

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

python/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ set(FLUID_CORE_NAME "core")
1414
if(WITH_AVX AND AVX_FOUND)
1515
set(FLUID_CORE_NAME "${FLUID_CORE_NAME}_avx")
1616
if(NOT DEFINED NOAVX_CORE_FILE OR NOAVX_CORE_FILE STREQUAL "")
17-
message(WARNING "You are building AVX version without NOAVX core, \
18-
and the wheel package may fail on NOAVX machine.")
17+
message(STATUS "WARNING: This is just a warning for publishing release.
18+
You are building AVX version without NOAVX core.
19+
So the wheel package may fail on NOAVX machine.
20+
You can add -DFLUID_CORE_NAME=/path/to/your/core_noavx.* in cmake command
21+
to get a full wheel package to resolve this warning.
22+
While, this version will still work on local machine.")
1923
endif()
2024

2125
if(NOAVX_CORE_FILE AND NOT EXISTS "${NOAVX_CORE_FILE}")

python/paddle/fluid/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414

1515
from __future__ import print_function
1616
import os
17+
import sys
18+
19+
# The legacy core need to be removed before "import core",
20+
# in case of users installing paddlepadde without -U option
21+
core_suffix = 'so'
22+
if os.name == 'nt':
23+
core_suffix = 'pyd'
24+
25+
legacy_core = os.path.abspath(os.path.dirname(
26+
__file__)) + os.sep + 'core.' + core_suffix
27+
if os.path.exists(legacy_core):
28+
sys.stderr.write('Deleting legacy file ' + legacy_core + '\n')
29+
try:
30+
os.remove(legacy_core)
31+
except Exception as e:
32+
raise e
33+
1734
# import all class inside framework into fluid module
1835
from . import framework
1936
from .framework import *

python/paddle/fluid/core.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,23 @@
1818
import os
1919
from cpuinfo import get_cpu_info
2020

21+
core_suffix = 'so'
22+
if os.name == 'nt':
23+
core_suffix = 'pyd'
24+
25+
has_avx_core = False
26+
has_noavx_core = False
27+
28+
current_path = os.path.abspath(os.path.dirname(__file__))
29+
if os.path.exists(current_path + os.sep + 'core_avx.' + core_suffix):
30+
has_avx_core = True
31+
32+
if os.path.exists(current_path + os.sep + 'core_noavx.' + core_suffix):
33+
has_noavx_core = True
34+
2135
try:
2236
if os.name == 'nt':
23-
third_lib_path = os.path.abspath(os.path.dirname(
24-
__file__)) + os.sep + '..' + os.sep + 'libs'
37+
third_lib_path = current_path + os.sep + '..' + os.sep + 'libs'
2538
os.environ['path'] += ';' + third_lib_path
2639
sys.path.append(third_lib_path)
2740

@@ -59,12 +72,17 @@
5972
from .core_avx import _set_fuse_parameter_memory_size
6073
from .core_avx import _is_dygraph_debug_enabled
6174
from .core_avx import _dygraph_debug_level
62-
except ImportError:
63-
sys.stderr.write(
64-
'WARNING: Can not import avx core. You may not build with AVX, '
65-
'but AVX is supported on local machine, you could build paddle '
66-
'WITH_AVX=ON to get better performance. ')
67-
load_noavx = True
75+
except ImportError as e:
76+
if has_avx_core:
77+
raise e
78+
else:
79+
sys.stderr.write(
80+
'WARNING: Do not have avx core. You may not build with AVX, '
81+
'but AVX is supported on local machine.\n You could build paddle '
82+
'WITH_AVX=ON to get better performance.\n')
83+
load_noavx = True
84+
except Exception as e:
85+
raise e
6886
else:
6987
load_noavx = True
7088

@@ -82,7 +100,11 @@
82100
from .core_noavx import _set_fuse_parameter_memory_size
83101
from .core_noavx import _is_dygraph_debug_enabled
84102
from .core_noavx import _dygraph_debug_level
85-
except ImportError as error:
86-
sys.exit("Error: Can not load core_noavx.* ." +
87-
error.__class__.__name__)
88-
load_noavx = True
103+
except ImportError as e:
104+
if has_noavx_core:
105+
sys.stderr.write(
106+
'Error: Can not import noavx core while this file exists ' +
107+
current_path + os.sep + 'core_noavx.' + core_suffix + '\n')
108+
raise e
109+
except Exception as e:
110+
raise e

0 commit comments

Comments
 (0)