-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmeson.build
More file actions
224 lines (198 loc) · 6.28 KB
/
Copy pathmeson.build
File metadata and controls
224 lines (198 loc) · 6.28 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
project(
'mkl_umath',
['c', 'cython'],
version: run_command(
find_program('python3', 'python'),
['-c', 'exec(open("mkl_umath/_version.py").read()); print(__version__)'],
check: true
).stdout().strip(),
meson_version: '>=1.8.3',
default_options: [
'c_std=c99',
'buildtype=release',
'b_ndebug=if-release'
]
)
py = import('python').find_installation(pure: false)
# get includes
# numpy includes
np_dir = run_command(py,
['-c', 'import numpy; print(numpy.get_include())'],
check: true
).stdout().strip()
inc_np = include_directories(np_dir, 'mkl_umath/src')
# Python headers needed for loops
py_dep = py.dependency()
# compiler/linker
cc = meson.get_compiler('c')
c_args = []
link_args = []
if get_option('opt_report')
if cc.get_id().startswith('intel')
if cc.get_argument_syntax() == 'msvc'
c_args += '/Qopt-report=3'
else
c_args += '-qopt-report=3'
endif
else
warning('Optimization report requested with non-Intel compiler')
endif
endif
if cc.get_argument_syntax() == 'msvc'
c_args += [
'-Wall', '-Wextra', '-Winit-self', '-Wunused-function',
'-Wuninitialized', '-Wmissing-declarations', '-Wstrict-prototypes',
'-Wno-unused-parameter', '-Wno-implicit-function-declaration',
'/GS', '/DynamicBase', '/fp:precise'
]
link_args = ['/NXCompat', '/DynamicBase']
if cc.get_id().startswith('intel')
# workaround for icx _Dcomplex regression, see numpy/numpy#31337
npy_complex_check = '''
#include <Python.h>
#include <numpy/npy_math.h>
'''
undef_llvm = '/U__INTEL_LLVM_COMPILER'
if not cc.compiles(
npy_complex_check,
name: 'numpy complex helpers build with icx',
dependencies: py_dep,
include_directories: inc_np
)
if cc.compiles(
npy_complex_check,
name: 'numpy complex helpers build with ' + undef_llvm,
args: undef_llvm,
dependencies: py_dep,
include_directories: inc_np
)
c_args += undef_llvm
else
error(
'numpy headers do not compile with icx on Windows: '
+ 'npy_cdouble conflicts with UCRT complex.h and '
+ undef_llvm + ' does not resolve it. '
+ 'See numpy/numpy#31337.'
)
endif
endif
c_args += [
'/Qimf-precision=high', '/Qprotect-parens',
'/clang:-fveclib=SVML', '/clang:-fvectorize'
]
endif
elif cc.get_argument_syntax() == 'gcc'
c_args += [
'-Wall', '-Wextra', '-Winit-self', '-Wunused-function',
'-Wuninitialized', '-Wmissing-declarations', '-Wstrict-prototypes',
'-Wno-unused-parameter', '-fdiagnostics-color=auto',
'-fstack-protector', '-fstack-protector-all', '-fpic', '-fPIC',
'-D_FORTIFY_SOURCE=2', '-Wformat', '-Wformat-security',
'-fno-delete-null-pointer-checks', '-fwrapv', '-fno-fast-math',
'-Wno-incompatible-function-pointer-types'
]
link_args += ['-Wl,-z,noexecstack', '-Wl,-z,relro', '-Wl,-z,now']
if cc.get_id().startswith('intel')
c_args += [
'-fimf-precision=high', '-fprotect-parens', '-fveclib=SVML',
'-fvectorize'
]
endif
else
error('Unsupported system.')
endif
mkl_dep = dependency('MKL', method: 'cmake',
modules: ['MKL::MKL'],
cmake_args: [
'-DMKL_ARCH=intel64',
'-DMKL_LINK=dynamic',
'-DMKL_THREADING=' + get_option('mkl_threading'),
'-DMKL_INTERFACE=lp64'
],
required: true
)
# generate loops, similar to numpy
src_file_cli = find_program('_vendored/process_src_template.py')
src_file = generator(
src_file_cli,
arguments: ['@INPUT@', '-o', '@OUTPUT@'],
output: '@BASENAME@'
)
gen_loops_c = src_file.process('mkl_umath/src/mkl_umath_loops.c.src')
gen_umath_c = custom_target(
'__umath_generated',
output: '__umath_generated.c',
input: 'mkl_umath/generate_umath.py',
command: [py, '@INPUT@', '-o', '@OUTPUT@']
)
gen_loops_h = custom_target(
'mkl_umath_loops_h',
output: ['mkl_umath_loops.h'],
input: 'mkl_umath/src/mkl_umath_loops.h.src',
command: [src_file_cli, '@INPUT@', '-o', '@OUTPUT@'],
depends: gen_umath_c
)
rpath_link_args = []
if host_machine.system() != 'windows'
if host_machine.system() == 'darwin'
origin = '@loader_path'
else
origin = '$ORIGIN'
endif
rpath_link_args = [
'-Wl,-rpath,' + origin / '../..',
'-Wl,-rpath,' + origin / '../../..',
]
endif
# define <target>_EXPORTS for Windows dllexport
mkl_umath_loops = shared_library(
'mkl_umath_loops',
sources: [gen_loops_c, gen_loops_h],
include_directories: inc_np,
dependencies: [mkl_dep, py_dep],
c_args: c_args + ['-Dmkl_umath_loops_EXPORTS'],
link_args: link_args + rpath_link_args,
install: true,
install_dir: py.get_install_dir() / 'mkl_umath'
)
loops_dep = declare_dependency(link_with: mkl_umath_loops)
# extension modules
py.extension_module(
'_ufuncs',
sources: ['mkl_umath/src/ufuncsmodule.c', gen_umath_c, gen_loops_h],
include_directories: inc_np,
dependencies: [mkl_dep, loops_dep],
c_args: c_args + ['-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION'],
link_args: link_args + rpath_link_args,
install: true,
subdir: 'mkl_umath'
)
py.extension_module(
'_patch_numpy',
sources: ['mkl_umath/src/_patch_numpy.pyx'],
include_directories: inc_np,
dependencies: [loops_dep],
c_args: c_args + ['-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION'],
cython_args: ['-3', '--fast-fail'],
link_args: link_args + rpath_link_args,
install: true,
subdir: 'mkl_umath'
)
# install python sources
py.install_sources(
[
'mkl_umath/__init__.py',
'mkl_umath/__main__.py',
'mkl_umath/_init_helper.py',
'mkl_umath/_patch_startup.py',
'mkl_umath/_version.py',
'mkl_umath/patch.py',
'mkl_umath/with_patch.py',
],
subdir: 'mkl_umath'
)
install_subdir(
'mkl_umath/tests',
install_dir: py.get_install_dir() / 'mkl_umath',
exclude_files: ['AGENTS.md']
)