-
Notifications
You must be signed in to change notification settings - Fork 14
/
meson.build
323 lines (305 loc) · 9.88 KB
/
meson.build
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# Copyright 2023-2024 National Research Foundation (SARAO)
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
project(
'spead2',
'cpp',
meson_version : '>=1.2.0',
version : files('VERSION.txt'),
license : 'LGPL-3.0-or-later',
license_files : ['COPYING', 'COPYING.LESSER'],
default_options : [
'cpp_std=c++17',
'cuda_std=c++17',
'b_ndebug=if-release',
'buildtype=release',
'default_library=static',
'warning_level=2',
'b_staticpic=false', # The default of true harms performance
]
)
shared_lib_version = '9.0.0'
compiler = meson.get_compiler('cpp')
py = import('python').find_installation(pure : false, modules : ['jinja2', 'pycparser', 'packaging'])
# Required dependencies
boost_dep = dependency('boost', version : '>=1.69')
dl_dep = dependency('dl')
thread_dep = dependency('threads')
compiler.check_header('libdivide.h', required : true)
# Optional libraries
boost_program_options_dep = dependency(
'boost',
modules : ['program_options'],
required : get_option('tools'),
disabler : true
)
boost_unit_test_framework_dep = dependency(
'boost',
modules : ['unit_test_framework'],
required : get_option('unit_test'),
disabler : true
)
if add_languages('cuda', required : get_option('cuda'), native : false)
# Empty but found dependency; the compiler takes care of CUDA so we don't
# need to explicitly link to anything.
cuda_dep = declare_dependency()
else
cuda_dep = disabler()
endif
# Meson doesn't support has_function for cuda, so we have to check manually
gdrapi_dep = disabler() # Assume not found until proven otherwise
gdrapi_opt = get_option('gdrapi').require(cuda_dep.found())
gdrapi_test_dep = declare_dependency(link_args : '-lgdrapi')
if gdrapi_opt.allowed() and meson.get_compiler('cuda').links(
'''
#include <gdrapi.h>
int main() { (void) gdr_open(); }
''',
name : 'gdrapi library',
# Workaround for https://github.com/mesonbuild/meson/issues/12169
args : get_option('cuda_args'),
dependencies : [gdrapi_test_dep],
no_builtin_args : false,
)
gdrapi_dep = gdrapi_test_dep
endif
gdrapi_opt.require(gdrapi_dep.found())
# The rdma-core libraries have pkgconfig files in newer versions, but older
# versions did not and we still want to support those. This unfortunately
# requires more complex logic.
libraries = [
{
'name': 'ibv',
'option': 'ibv',
'dep_name': 'libibverbs',
'header': 'infiniband/verbs.h',
'lib': 'ibverbs',
'function': 'ibv_create_wq',
},
{
'name': 'rdmacm',
'option': 'ibv',
'dep_name': 'librdmacm',
'header': 'rdma/rdma_cma.h',
'lib': 'rdmacm',
'function': 'rdma_create_event_channel',
},
{
'name': 'mlx5',
'option': 'mlx5dv',
'dep_name': 'libmlx5',
'header': 'infiniband/mlx5dv.h',
'lib': 'mlx5',
'function': 'mlx5dv_create_cq',
'prereq': ['ibv_dep', 'rdmacm_dep'],
},
]
foreach lib : libraries
opt = get_option(lib['option'])
foreach prereq : lib.get('prereq', [])
opt = opt.require(get_variable(prereq).found())
endforeach
if opt.allowed()
lib_dep = dependency(lib['dep_name'], required : false)
if not lib_dep.found() and compiler.has_function(
lib['function'],
args : '-l' + lib['lib'],
prefix : '#include <' + lib['header'] + '>',
)
lib_dep = declare_dependency(link_args : '-l' + lib['lib'])
endif
else
lib_dep = dependency('', required : false) # A not-found dependency
endif
opt.require(lib_dep.found())
set_variable(lib['name'] + '_dep', lib_dep)
endforeach
use_ibv = ibv_dep.found() and rdmacm_dep.found()
# Note: pass 'pcap' not 'libpcap' to dependency, to trigger the special
# handling that uses pcap-config if pkgconfig doesn't find it.
pcap_dep = dependency('pcap', required : get_option('pcap'))
cap_dep = dependency('libcap', required : get_option('cap'), disabler : true)
# Optional features
use_ibv_hw_rate_limit = use_ibv and get_option('ibv_hw_rate_limit').require(
compiler.has_function(
'ibv_modify_qp_rate_limit',
dependencies : [ibv_dep, rdmacm_dep],
prefix : '#include <infiniband/verbs.h>'
)
).allowed()
use_recvmmsg = get_option('recvmmsg').require(
compiler.has_function(
'recvmmsg',
args : '-D_GNU_SOURCE',
prefix : '#include <sys/socket.h>'
)
).allowed()
use_sendmmsg = get_option('sendmmsg').require(
compiler.has_function(
'sendmmsg',
args : '-D_GNU_SOURCE',
prefix : '#include <sys/socket.h>'
)
).allowed()
use_gso = get_option('gso').require(
compiler.get_define(
'UDP_SEGMENT',
args : '-D_GNU_SOURCE',
prefix : '#include <netinet/udp.h>'
) != ''
).allowed()
use_gro = get_option('gro').require(
compiler.get_define(
'UDP_GRO',
args : '-D_GNU_SOURCE',
prefix : '#include <netinet/udp.h>'
) != ''
).allowed()
use_eventfd = get_option('eventfd').require(
compiler.has_function(
'eventfd',
prefix : '#include <sys/eventfd.h>'
)
).allowed()
use_posix_semaphores = get_option('posix_semaphores').require(
compiler.has_function(
'sem_init',
prefix : '''
#include <unistd.h>
#include <semaphore.h>
#if defined(__APPLE__)
# error "POSIX semaphores do not work on OS X"
#endif
#if !defined(_POSIX_SEMAPHORES) || _POSIX_SEMAPHORES < 0
# error "POSIX semaphores marked unsupported"
#endif
''',
dependencies : thread_dep
)
).allowed()
use_pthread_setaffinity_np = get_option('pthread_setaffinity_np').require(
compiler.has_function(
'pthread_setaffinity_np',
args : '-D_GNU_SOURCE',
prefix : '#include <pthread.h>',
dependencies : thread_dep
)
).allowed()
# While clang implements function multi-versioning, it's currently buggy e.g.
# https://github.com/llvm/llvm-project/issues/54549
# https://github.com/llvm/llvm-project/issues/45833
# https://github.com/mesonbuild/meson/issues/12413
#
# So we explicitly disallow it.
use_fmv = get_option('fmv').require(
compiler.has_function_attribute('ifunc')
).require(compiler.get_id() != 'clang').allowed()
# has_function doesn't work for _mm_stream_si128 and friends, because they
# are inline-only functions in GCC without external definitions.
use_sse2_stream = get_option('sse2_stream').require(
compiler.compiles(
'''
#include <emmintrin.h>
[[gnu::target("sse2")]]
void foo()
{
(void) __builtin_cpu_supports("sse2");
_mm_stream_si128((__m128i *) NULL, __m128i());
}
''',
name : 'SSE2 streaming intrinsic'
)
).allowed()
use_avx_stream = get_option('avx_stream').require(
compiler.compiles(
'''
#include <immintrin.h>
[[gnu::target("avx")]]
void foo()
{
(void) __builtin_cpu_supports("avx");
_mm256_stream_si256((__m256i *) NULL, __m256i());
}
''',
name : 'AVX streaming intrinsic'
)
).allowed()
use_avx512_stream = get_option('avx512_stream').require(
compiler.compiles(
'''
#include <immintrin.h>
[[gnu::target("avx512f")]]
void foo()
{
(void) __builtin_cpu_supports("avx512f");
_mm512_stream_si512((__m512i *) NULL, __m512i());
}
''',
name : 'AVX-512 streaming intrinsic'
)
).allowed()
use_sve_stream = get_option('sve_stream').require(
compiler.compiles(
'''
#include <arm_sve.h>
#include <sys/auxv.h>
[[gnu::target("+sve")]]
void foo()
{
bool have_sve = getauxval(AT_HWCAP) & HWCAP_SVE;
svldnt1_u8(svptrue_b8(), (const unsigned char *) 0);
}
''',
name : 'SVE streaming intrinsic'
)
).allowed()
# Write configuration data
conf = configuration_data()
conf.set('SPEAD2_VERSION', meson.project_version())
get_version = files('gen/get_version.py')
conf.set('SPEAD2_MAJOR', run_command(py, get_version, 'major', meson.project_version(), check : true).stdout().strip())
conf.set('SPEAD2_MINOR', run_command(py, get_version, 'minor', meson.project_version(), check : true).stdout().strip())
conf.set('SPEAD2_PATCH', run_command(py, get_version, 'patch', meson.project_version(), check : true).stdout().strip())
conf.set10('SPEAD2_USE_IBV', use_ibv)
conf.set10('SPEAD2_USE_IBV_HW_RATE_LIMIT', use_ibv_hw_rate_limit)
conf.set10('SPEAD2_USE_MLX5DV', mlx5_dep.found())
conf.set10('SPEAD2_USE_RECVMMSG', use_recvmmsg)
conf.set10('SPEAD2_USE_SENDMMSG', use_sendmmsg)
conf.set10('SPEAD2_USE_GSO', use_gso)
conf.set10('SPEAD2_USE_GRO', use_gro)
conf.set10('SPEAD2_USE_EVENTFD', use_eventfd)
conf.set10('SPEAD2_USE_POSIX_SEMAPHORES', use_posix_semaphores)
conf.set10('SPEAD2_USE_PTHREAD_SETAFFINITY_NP', use_pthread_setaffinity_np)
conf.set10('SPEAD2_USE_FMV', use_fmv)
conf.set10('SPEAD2_USE_SSE2_STREAM', use_sse2_stream)
conf.set10('SPEAD2_USE_AVX_STREAM', use_avx_stream)
conf.set10('SPEAD2_USE_AVX512_STREAM', use_avx512_stream)
conf.set10('SPEAD2_USE_SVE_STREAM', use_sve_stream)
conf.set10('SPEAD2_USE_PCAP', pcap_dep.found())
conf.set('SPEAD2_MAX_LOG_LEVEL', '(spead2::log_level::' + get_option('max_log_level') + ')')
gen_loader = files('gen/gen_loader.py')
gen_templates = files('gen/template.cpp', 'gen/template.h')
loader_modules = ['rdmacm', 'ibv', 'mlx5dv']
subdir('include/spead2') # Generates include/spead2/common_features.h and common_loader_*.h
include_dir = include_directories('include')
subdir('src') # Defines the targets
if not get_option('python')
subdir('examples')
pkg = import('pkgconfig')
pkg.generate(
st_lib,
description : 'Library for sending and receiving data in the SPEAD protocol',
filebase : 'spead2',
)
endif