-
Notifications
You must be signed in to change notification settings - Fork 2
/
tasks.py
55 lines (47 loc) · 1.61 KB
/
tasks.py
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
import os
import sys
import warnings
from shutil import rmtree
from pathlib import Path
from cffi import FFI
from invoke import task
@task
def clean(c):
"Clean up build products"
print('removing build dir', file=sys.stderr)
rmtree('build')
print('removing dist dir', file=sys.stderr)
rmtree('dist')
pkg_dir = Path(__file__).parent / 'csr' / 'kernels' / 'mkl'
for f in pkg_dir.glob('_mkl_ops.*'):
print('removing', f, file=sys.stderr)
f.unlink(True)
@task
def build_mkl(c, trace=False):
"Build the Intel MKL helper module."
pkg_dir = Path(__file__).parent / 'csr' / 'kernels' / 'mkl'
src_path = pkg_dir / 'mkl_ops.c'
hdr_path = pkg_dir / 'mkl_ops.h'
if 'CONDA_PREFIX' in os.environ:
base = Path(os.environ['CONDA_PREFIX'])
else:
warnings.warn('No CONDA_PREFIX set, trying to buil MKL with sys.prefix')
base = Path(sys.prefix)
i_dirs = [os.fspath(pkg_dir)]
l_dirs = []
if os.name == 'nt':
lib = base / 'Library'
i_dirs.append(os.fspath(lib / 'include'))
l_dirs.append(os.fspath(lib / 'lib'))
else:
i_dirs.append(os.fspath(base / 'include'))
l_dirs.append(os.fspath(base / 'lib'))
ffibuilder = FFI()
ffibuilder.cdef(hdr_path.read_text().replace('EXPORT ', ''))
defines = []
if trace:
defines.append(('LK_TRACE', None))
ffibuilder.set_source("csr.kernels.mkl._mkl_ops", src_path.read_text(),
include_dirs=i_dirs, define_macros=defines,
libraries=['mkl_rt'], library_dirs=l_dirs)
ffibuilder.compile(verbose=True)