Skip to content

Commit e956161

Browse files
loops is now a separate library, like in patched NumPy
1 parent d9d6d1d commit e956161

File tree

1 file changed

+49
-15
lines changed

1 file changed

+49
-15
lines changed

mkl_umath/setup.py

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@
3030
import importlib.machinery # requires Python >= 3.4
3131
from distutils.dep_util import newer
3232

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+
3351
def load_module(name, fn):
3452
"""
3553
Credit: numpy.compat.npy_load_module
@@ -63,6 +81,7 @@ def configuration(parent_package='',top_path=None):
6381
else:
6482
mkl_info = get_info('mkl')
6583

84+
print(mkl_info)
6685
mkl_include_dirs = mkl_info.get('include_dirs', [])
6786
mkl_library_dirs = mkl_info.get('library_dirs', [])
6887
mkl_libraries = mkl_info.get('libraries', ['mkl_rt'])
@@ -91,30 +110,45 @@ def generate_umath_c(ext, build_dir):
91110
return []
92111

93112
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.')
104113

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',
107125
sources = [
108126
join(wdir, 'loops_intel.h.src'),
109127
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],
112130
depends = [
113131
join(wdir, 'blocking_utils.h'),
114132
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'),
115149
],
116150
include_dirs = [wdir] + mkl_include_dirs,
117-
libraries = mkl_libraries,
151+
libraries = mkl_libraries + ['loops_intel'],
118152
library_dirs = mkl_library_dirs,
119153
extra_compile_args = [
120154
# '-DNDEBUG',

0 commit comments

Comments
 (0)