-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
95 lines (86 loc) · 3.7 KB
/
Copy pathsetup.py
File metadata and controls
95 lines (86 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
from setuptools import Extension, setup
from Cython.Build import cythonize
from Cython.Compiler import Options
import numpy as np
Options.docstrings = True
Options.embed_pos_in_docstring = True
Options.fast_fail = True
ENV_PREFIX = os.environ['CONDA_PREFIX']
include_dirs = []
library_dirs = []
define_macros = []
extra_link_args = []
include_dirs.append(np.get_include())
include_dirs.append(f'{ENV_PREFIX}/include/')
library_dirs.append(f'{ENV_PREFIX}/lib/')
define_macros.append(("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"))
extra_link_args.append('-fopenmp')
# TODO: comment on what these do and why they're used
extra_compile_args = [
'-fopenmp',
'-O3',
'-Wno-unused',
'-march=native',
'-mfpmath=sse',
'-mavx',
# '-mdaz-ftz', #Why does GCC not seem to recognize this?
]
# Use the ILP64 interface libraries directly to avoid conflicts with Numpy /
# Scipy et. al. - when they load MKL for blas/lapack they load `mkl_rt`, the
# single dynamic library (SDL). The SDL can be configured to use either 32-bit
# or 64-bit MKL_INTs, but if we set it to 64-bit then
# (1) The setting is only respected if made before the first MKL call, so our
# code must always be imported _prior_ to numpy, scipy, etc or we'll be
# locked into 32-bit MKL_INT (NB: it needs to be imported first
# _anyways_, no matter which lib we link against, or we lose 64-bit
# capability. But linking against mkl_intel_ilp64 at least leaves scipy
# alone.)
# (2) Even if we successfully set to 64-bit, scipy.linalg is hard-coded to
# expect 32-bit: eigh and other functions will flat-out break entirely.
# Therefore, we *must* always link against `mkl_intel_ilp64` (and hence also
# `mkl_intel_thread`, `mkl_core`, `iomp5`, and `pthread`, _in that order_),
# rather than against `mkl_rt`. The macro and other args are also needed.
libraries = ['mkl_intel_ilp64', 'mkl_intel_thread', 'mkl_core',
'iomp5', 'pthread', 'm', 'dl']
define_macros.append(("MKL_ILP64", 1))
extra_link_args.append('-Wl,--no-as-needed')
extra_compile_args.append('-m64')
# Reference for Extension arguments:
# https://setuptools.pypa.io/en/latest/userguide/ext_modules.html#extension-api-reference
module = Extension("fastica", ['fastica.pyx'],
language='c++',
include_dirs=include_dirs,
define_macros=define_macros,
libraries=libraries,
library_dirs=library_dirs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)
# Cythonize argument reference:
# https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#cythonize-arguments
ext_modules = cythonize([module],
nthreads=32,
annotate=True,
force=False,
compiler_directives={
'binding': True,
'boundscheck': False,
'cdivision': True,
'embedsignature': True,
'emit_code_comments': True,
'initializedcheck': False,
'language_level': 3,
'wraparound': False,
# Enable these for debugging
#'profile': True,
#'linetrace': True,
})
setup(name="fastica",
version='0.1',
ext_modules=ext_modules,
package_data={'fastica': ['mkl_wrapper.pxd']},
entry_points={
'console_scripts': ['fastica=fastica:cli'],
},
include_package_data=True,
zip_safe=False)