|
30 | 30 | import importlib.machinery # requires Python >= 3.4
|
31 | 31 | from distutils.dep_util import newer
|
32 | 32 |
|
| 33 | +from numpy.distutils.ccompiler import new_compiler |
| 34 | +from distutils.sysconfig import customize_compiler |
| 35 | +import platform |
| 36 | +from numpy import get_include as get_numpy_include |
| 37 | +from distutils.sysconfig import get_python_inc as get_python_include |
| 38 | + |
| 39 | +def ensure_Intel_compiler(): |
| 40 | + ccompiler = new_compiler() |
| 41 | + customize_compiler(ccompiler) |
| 42 | + if hasattr(ccompiler, 'compiler'): |
| 43 | + compiler_name = ccompiler.compiler[0] |
| 44 | + else: |
| 45 | + compiler_name = ccompiler.__class__.__name__ |
| 46 | + |
| 47 | + assert ('icl' in compiler_name or 'icc' in compiler_name), \ |
| 48 | + "Intel(R) C Compiler is required to build mkl_umath, found {}".format(compiler_name) |
| 49 | + |
| 50 | + |
33 | 51 | def load_module(name, fn):
|
34 | 52 | """
|
35 | 53 | Credit: numpy.compat.npy_load_module
|
@@ -63,6 +81,7 @@ def configuration(parent_package='',top_path=None):
|
63 | 81 | else:
|
64 | 82 | mkl_info = get_info('mkl')
|
65 | 83 |
|
| 84 | + print(mkl_info) |
66 | 85 | mkl_include_dirs = mkl_info.get('include_dirs', [])
|
67 | 86 | mkl_library_dirs = mkl_info.get('library_dirs', [])
|
68 | 87 | mkl_libraries = mkl_info.get('libraries', ['mkl_rt'])
|
@@ -91,30 +110,45 @@ def generate_umath_c(ext, build_dir):
|
91 | 110 | return []
|
92 | 111 |
|
93 | 112 | sources = [generate_umath_c]
|
94 |
| -# try: |
95 |
| -# from Cython.Build import cythonize |
96 |
| -# sources = [join(pdir, '_pydfti.pyx')] |
97 |
| -# have_cython = True |
98 |
| -# except ImportError as e: |
99 |
| -# have_cython = False |
100 |
| -# sources = [join(pdir, '_pydfti.c')] |
101 |
| -# if not exists(sources[0]): |
102 |
| -# raise ValueError(str(e) + '. ' + |
103 |
| -# 'Cython is required to build the initial .c file.') |
104 | 113 |
|
105 |
| - config.add_extension( |
106 |
| - name = '_ufuncs', |
| 114 | + # ensure_Intel_compiler() |
| 115 | + |
| 116 | + if platform.system() == "Windows": |
| 117 | + eca = ['/fp:fast=2', '/Qimf-precision=high', '/Qprec-sqrt', '/Qstd=c99', '/Qprotect-parens'] |
| 118 | + else: |
| 119 | + eca = ['-fp-model', 'fast=2', '-fimf-precision=high', '-prec-sqrt', '-fprotect-parens'] |
| 120 | + |
| 121 | + numpy_include_dir = get_numpy_include() |
| 122 | + python_include_dir = get_python_include() |
| 123 | + config.add_library( |
| 124 | + 'loops_intel', |
107 | 125 | sources = [
|
108 | 126 | join(wdir, 'loops_intel.h.src'),
|
109 | 127 | join(wdir, 'loops_intel.c.src'),
|
110 |
| - join(wdir, 'ufuncsmodule.c'), |
111 |
| - ] + sources, |
| 128 | + ], |
| 129 | + include_dirs = [wdir] + mkl_include_dirs + [numpy_include_dir, python_include_dir], |
112 | 130 | depends = [
|
113 | 131 | join(wdir, 'blocking_utils.h'),
|
114 | 132 | join(wdir, 'fast_loop_macros.h'),
|
| 133 | + join(numpy_include_dir, 'numpy', '*object.h'), |
| 134 | + join(python_include_dir, "Python.h") |
| 135 | + ], |
| 136 | + libraries=mkl_libraries, |
| 137 | + extra_compiler_args=eca, |
| 138 | + macros=getattr(config, 'define_macros', getattr(config.get_distribution(), 'define_macros', [])) |
| 139 | + ) |
| 140 | + |
| 141 | + config.add_extension( |
| 142 | + name = '_ufuncs', |
| 143 | + sources = [ |
| 144 | + join(wdir, 'ufuncsmodule.c'), |
| 145 | + ] + sources, |
| 146 | + depends = [ |
| 147 | + join(wdir, 'loops_intel.c.src'), |
| 148 | + join(wdir, 'loops_intel.h.src'), |
115 | 149 | ],
|
116 | 150 | include_dirs = [wdir] + mkl_include_dirs,
|
117 |
| - libraries = mkl_libraries, |
| 151 | + libraries = mkl_libraries + ['loops_intel'], |
118 | 152 | library_dirs = mkl_library_dirs,
|
119 | 153 | extra_compile_args = [
|
120 | 154 | # '-DNDEBUG',
|
|
0 commit comments