Skip to content

Commit 748fa74

Browse files
author
Raghuveer Devulapalli
committed
Add new meson options to build with std threads
1 parent a3d22a5 commit 748fa74

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ test_openmp:
66
meson setup -Dbuild_tests=true -Duse_openmp=true --warnlevel 2 --werror --buildtype release builddir
77
cd builddir && ninja
88

9+
test_stdthreads:
10+
meson setup -Dbuild_tests=true -Duse_stdthreads=true --warnlevel 2 --werror --buildtype release builddir
11+
cd builddir && ninja
12+
913
test_asan:
1014
meson setup -Dbuild_tests=true -Duse_openmp=true -Db_sanitize=address,undefined -Dfatal_sanitizers=true -Db_lundef=false -Dasan_ci_dont_validate=true --warnlevel 0 --buildtype debugoptimized builddir
1115
cd builddir && ninja

lib/meson.build

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
libtargets = []
22

3-
# Add compile flags for OpenMP if enabled
4-
openmpflags = []
5-
if get_option('use_openmp')
6-
openmpflags = ['-DXSS_USE_OPENMP=true', '-fopenmp']
7-
endif
8-
93
if cpp.has_argument('-march=haswell')
104
libtargets += static_library('libavx',
115
files(
126
'x86simdsort-avx2.cpp',
137
),
148
include_directories : [src],
15-
cpp_args : ['-march=haswell', openmpflags],
9+
cpp_args : ['-march=haswell', stdthreadsflag],
10+
dependencies: [omp_dep],
1611
gnu_symbol_visibility : 'inlineshidden',
1712
)
1813
endif
@@ -23,7 +18,8 @@ if cpp.has_argument('-march=skylake-avx512')
2318
'x86simdsort-skx.cpp',
2419
),
2520
include_directories : [src],
26-
cpp_args : ['-march=skylake-avx512', openmpflags],
21+
cpp_args : ['-march=skylake-avx512', stdthreadsflag],
22+
dependencies: [omp_dep],
2723
gnu_symbol_visibility : 'inlineshidden',
2824
)
2925
endif
@@ -34,7 +30,8 @@ if cpp.has_argument('-march=icelake-client')
3430
'x86simdsort-icl.cpp',
3531
),
3632
include_directories : [src],
37-
cpp_args : ['-march=icelake-client', openmpflags],
33+
cpp_args : ['-march=icelake-client', stdthreadsflag],
34+
dependencies: [omp_dep],
3835
gnu_symbol_visibility : 'inlineshidden',
3936
)
4037
endif
@@ -45,7 +42,8 @@ if cancompilefp16
4542
'x86simdsort-spr.cpp',
4643
),
4744
include_directories : [src],
48-
cpp_args : ['-march=sapphirerapids', openmpflags],
45+
cpp_args : ['-march=sapphirerapids', stdthreadsflag],
46+
dependencies: [omp_dep],
4947
gnu_symbol_visibility : 'inlineshidden',
5048
)
5149
endif

meson.build

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ if get_option('build_vqsortbench')
2929
benchvq = true
3030
endif
3131

32+
# build with openmp
33+
omp = []
34+
omp_dep = []
35+
if get_option('use_openmp')
36+
omp = dependency('openmp', required : true)
37+
omp_dep = declare_dependency(dependencies: omp, compile_args: ['-DXSS_USE_OPENMP'])
38+
endif
39+
40+
# build with std::threads
41+
stdthreadsflag = []
42+
if get_option('use_stdthreads')
43+
stdthreadsflag += ['-DXSS_BUILD_WITH_STD_THREADS']
44+
endif
45+
3246
fp16code = '''#include<immintrin.h>
3347
int main() {
3448
__m512h temp = _mm512_set1_ph(1.0f);
@@ -43,8 +57,8 @@ if get_option('lib_type') == 'shared'
4357
libsimdsort = shared_library('x86simdsortcpp',
4458
'lib/x86simdsort.cpp',
4559
include_directories : [src, utils, lib],
46-
link_args : [openmpflags],
4760
link_with : [libtargets],
61+
dependencies: [omp],
4862
gnu_symbol_visibility : 'inlineshidden',
4963
install : true,
5064
soversion : 1,
@@ -53,7 +67,7 @@ else
5367
libsimdsort = static_library('x86simdsortcpp',
5468
'lib/x86simdsort.cpp',
5569
include_directories : [src, utils, lib],
56-
link_args : [openmpflags],
70+
dependencies: [omp],
5771
link_with : [libtargets],
5872
gnu_symbol_visibility : 'inlineshidden',
5973
install : true,

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ option('build_vqsortbench', type : 'boolean', value : true,
88
description : 'Add google vqsort to benchmarks (default: "true").')
99
option('use_openmp', type : 'boolean', value : false,
1010
description : 'Use OpenMP to accelerate key-value sort (default: "false").')
11+
option('use_stdthreads', type : 'boolean', value : false,
12+
description : 'Use std::threads to accelerate qsort (default: "false").')
1113
option('lib_type', type : 'string', value : 'shared',
1214
description : 'Library type: shared or static (default: "shared").')
1315
option('fatal_sanitizers', type : 'boolean', value : 'false',

tests/meson.build

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
libtests = []
22

3-
if get_option('use_openmp')
4-
openmpflags = ['-DXSS_USE_OPENMP=true']
5-
endif
6-
73
# Add compile flags when needed for the ASAN CI run
84
testargs = []
95
if get_option('asan_ci_dont_validate')
@@ -16,21 +12,21 @@ endif
1612

1713
libtests += static_library('tests_qsort',
1814
files('test-qsort.cpp', ),
19-
dependencies: gtest_dep,
15+
dependencies: [gtest_dep, omp],
2016
include_directories : [src, lib, utils],
21-
cpp_args : [testargs, openmpflags],
17+
cpp_args : [testargs, stdthreadsflag],
2218
)
2319

2420
libtests += static_library('tests_kvsort',
2521
files('test-keyvalue.cpp', ),
26-
dependencies: gtest_dep,
22+
dependencies: [gtest_dep, omp],
2723
include_directories : [src, lib, utils],
28-
cpp_args : [testargs, openmpflags],
24+
cpp_args : [testargs, stdthreadsflag],
2925
)
3026

3127
libtests += static_library('tests_objsort',
3228
files('test-objqsort.cpp', ),
33-
dependencies: gtest_dep,
29+
dependencies: [gtest_dep, omp],
3430
include_directories : [src, lib, utils],
35-
cpp_args : [testargs, openmpflags],
31+
cpp_args : [testargs, stdthreadsflag],
3632
)

0 commit comments

Comments
 (0)