|
18 | 18 | import os
|
19 | 19 | from cpuinfo import get_cpu_info
|
20 | 20 |
|
| 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 | + |
21 | 35 | try:
|
22 | 36 | 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' |
25 | 38 | os.environ['path'] += ';' + third_lib_path
|
26 | 39 | sys.path.append(third_lib_path)
|
27 | 40 |
|
|
59 | 72 | from .core_avx import _set_fuse_parameter_memory_size
|
60 | 73 | from .core_avx import _is_dygraph_debug_enabled
|
61 | 74 | 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 |
68 | 86 | else:
|
69 | 87 | load_noavx = True
|
70 | 88 |
|
|
82 | 100 | from .core_noavx import _set_fuse_parameter_memory_size
|
83 | 101 | from .core_noavx import _is_dygraph_debug_enabled
|
84 | 102 | 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