-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmeson.build
More file actions
205 lines (174 loc) · 6.23 KB
/
meson.build
File metadata and controls
205 lines (174 loc) · 6.23 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
project('numpy_quaddtype', 'c', 'cpp',
default_options : ['cpp_std=c++20', 'b_pie=true'],
meson_version: '>=1.1')
py_mod = import('python')
py = py_mod.find_installation()
py_dep = py.dependency()
c = meson.get_compiler('c')
cpp = meson.get_compiler('cpp')
is_windows = build_machine.system() == 'windows'
if is_windows
add_project_arguments('-DWIN32', '-D_WINDOWS', language : ['c', 'cpp'])
endif
qblas_dep = dependency('qblas', fallback: ['qblas', 'qblas_dep'])
# Try to find SLEEF system-wide first, fall back to subproject if not found
# Required SLEEF version (must match sleef.wrap revision)
required_sleef_version = '3.9.0'
# Don't use fallback here - we need to call subproject() explicitly later with disable_fma option
sleef_dep = dependency('sleef', version: '>=' + required_sleef_version, required: false)
use_system_sleef = false
fallback_reason = ''
if sleef_dep.found() and sleef_dep.version().startswith(required_sleef_version)
# SLEEF found system-wide - verify quad-precision support
cpp = meson.get_compiler('cpp')
sleefquad_lib = cpp.find_library('sleefquad', required: false)
if sleefquad_lib.found()
sleefquad_test_code = '''
#include <sleefquad.h>
int main(void) {
Sleef_quad q1 = Sleef_cast_from_doubleq1(1.0);
Sleef_quad q2 = Sleef_cast_from_doubleq1(2.0);
Sleef_quad result = Sleef_addq1_u05(q1, q2);
return 0;
}
'''
# this should compile and link
quad_works = cpp.links(
sleefquad_test_code,
dependencies: [sleef_dep, sleefquad_lib],
name: 'SLEEF quad-precision support'
)
if quad_works
sleefquad_dep = declare_dependency(
dependencies: [sleef_dep, sleefquad_lib]
)
use_system_sleef = true
else
fallback_reason = 'System-wide SLEEF installation found but a test for quad precision support failed.'
endif
else
fallback_reason = 'System-wide SLEEF installation does not have the sleefquad library.'
endif
else
if sleef_dep.found() and sleef_dep.type_name() != 'internal'
fallback_reason = 'System SLEEF version @0@ does not match required version @1@'.format(sleef_dep.version(), required_sleef_version)
else
fallback_reason = 'Cannot find system-wide SLEEF installation.'
endif
endif
if use_system_sleef
message('Using system-wide SLEEF installation with quad-precision support')
else
# Pass disable_fma option to sleef subproject for x86-64-v2 compatibility
message('SLEEF FMA disable option: ' + get_option('disable_fma').to_string())
sleef_subproj = subproject('sleef', default_options: ['disable_fma=' + get_option('disable_fma').to_string()])
sleef_dep = sleef_subproj.get_variable('sleef_dep')
sleefquad_dep = sleef_subproj.get_variable('sleefquad_dep')
warning(fallback_reason)
message('Proceeding with vendored SLEEF subproject instead')
endif
incdir_numpy = run_command(py,
['-c', 'import numpy; print(numpy.get_include())'],
check : true
).stdout().strip()
# pythoncapi-compat for portable C API usage across Python versions
pythoncapi_compat_subproj = subproject('pythoncapi-compat')
pythoncapi_compat_inc = pythoncapi_compat_subproj.get_variable('incdir')
# print numpy version used
numpy_version = run_command(py,
['-c', 'import numpy; print(numpy.__version__)'],
check : true
).stdout().strip()
message('Using NumPy version: @0@'.format(numpy_version))
npymath_path = incdir_numpy / '..' / 'lib'
npymath_lib = c.find_library('npymath', dirs: npymath_path)
dependencies = [py_dep, qblas_dep, sleef_dep, sleefquad_dep, npymath_lib]
# Add OpenMP dependency (optional, for threading)
openmp_dep = dependency('openmp', required: false, static: false)
if openmp_dep.found()
dependencies += openmp_dep
endif
# compiler flags for QBLAS compatibility
if not is_windows
# QBLAS requires extended numeric literals for Q suffix support
# if compiler supports (usually gcc)
if cpp.has_argument('-fext-numeric-literals')
add_project_arguments('-fext-numeric-literals', language: 'cpp')
endif
# Suppress warnings from system headers (sleefquad.h has many unused inline functions)
if cpp.has_argument('-Wno-unused-function')
add_project_arguments('-Wno-unused-function', language: ['c', 'cpp'])
endif
endif
# Thread-local storage detection (borrowed from NumPy)
optional_variable_attributes = [
['thread_local', 'HAVE_THREAD_LOCAL'], # C23
['_Thread_local', 'HAVE__THREAD_LOCAL'], # C11/C17
['__thread', 'HAVE___THREAD'], # GCC/Clang
['__declspec(thread)', 'HAVE___DECLSPEC_THREAD_'] # MSVC
]
if not is_variable('cdata')
cdata = configuration_data()
endif
foreach optional_attr: optional_variable_attributes
attr = optional_attr[0]
code = '''
#pragma GCC diagnostic error "-Wattributes"
#pragma clang diagnostic error "-Wattributes"
int @0@ foo;
int main() {
return 0;
}
'''.format(attr)
if c.compiles(code, name: optional_attr[0])
cdata.set10(optional_attr[1], true)
message('Thread-local storage support found: @0@'.format(attr))
endif
endforeach
configure_file(
output: 'quaddtype_config.h',
configuration: cdata
)
build_includes = include_directories('.') # compile time generated headers as per system
includes = include_directories(
[
incdir_numpy,
'src/include',
]
)
pythoncapi_includes = pythoncapi_compat_inc
srcs = [
'src/csrc/casts.cpp',
'src/csrc/scalar.c',
'src/csrc/dtype.c',
'src/csrc/quaddtype_main.c',
'src/csrc/scalar_ops.cpp',
'src/csrc/dragon4.c',
'src/csrc/quadblas_interface.cpp',
'src/csrc/umath/umath.cpp',
'src/csrc/umath/binary_ops.cpp',
'src/csrc/umath/unary_ops.cpp',
'src/csrc/umath/unary_props.cpp',
'src/csrc/umath/comparison_ops.cpp',
'src/csrc/umath/matmul.cpp',
'src/csrc/lock.c',
'src/csrc/utilities.c',
]
py.install_sources(
[
'src/numpy_quaddtype/__init__.py',
'src/numpy_quaddtype/__init__.pyi',
'src/numpy_quaddtype/_quaddtype_main.pyi',
'src/numpy_quaddtype/py.typed',
],
subdir: 'numpy_quaddtype',
pure: false
)
py.extension_module('_quaddtype_main',
srcs,
link_language: 'cpp',
dependencies: dependencies,
install: true,
subdir: 'numpy_quaddtype',
include_directories: [includes, build_includes, pythoncapi_includes],
)