Skip to content

Commit 63b46f2

Browse files
committed
Update build configuration to reduce friction
On systems with glibc < 2.34, the `-lpthread` option needs to be included when linking with Google's benchmark and test frameworks. However, the `pkg-config` command for `benchmark` needs to be explicitly given the `--static` flag for this to be included. The static inclusion has also been added to the Meson configuration. I've also included some rudimentary logic to allow the Makefile to shrink the scope of its compilation targets when an older compiler is being used. I changed the benchmarks to run using `benchmark_main` in the same way that the tests use `gtest_main`. Finally, I turned off compilation of the package-internal tests for Google Benchmarks when running in GitHub actions.
1 parent 6283f24 commit 63b46f2

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

.github/workflows/c-cpp.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
git clone https://github.com/google/benchmark.git
2525
cd benchmark
2626
cmake -E make_directory "build"
27-
cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../
27+
cmake -E chdir "build" cmake -DBENCHMARK_ENABLE_GTEST_TESTS=OFF -DBENCHMARK_ENABLE_TESTING=OFF -DCMAKE_BUILD_TYPE=Release ../
2828
sudo cmake --build "build" --config Release --target install
2929
3030
- name: Install Intel SDE
@@ -86,7 +86,7 @@ jobs:
8686
cd benchmark
8787
pip3 install -r requirements.txt
8888
cmake -E make_directory "build"
89-
cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../
89+
cmake -E chdir "build" cmake -DBENCHMARK_ENABLE_GTEST_TESTS=OFF -DBENCHMARK_ENABLE_TESTING=OFF -DCMAKE_BUILD_TYPE=Release ../
9090
sudo cmake --build "build" --config Release --target install
9191
9292
- name: Run bench-compare

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@
3333
*.out
3434
*.app
3535

36+
# Build or IDE artifacts
3637
**/.vscode
37-
38+
/builddir/

Makefile

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
CXX ?= g++-12
2+
CXXFLAGS += -I$(SRCDIR) -I$(UTILS) -O3
3+
GTESTCFLAGS = `pkg-config --cflags gtest_main`
4+
GTESTLDFLAGS = `pkg-config --static --libs gtest_main`
5+
GBENCHCFLAGS = `pkg-config --cflags benchmark`
6+
GBENCHLDFLAGS = `pkg-config --static --libs benchmark`
7+
MARCHFLAG = -march=sapphirerapids
8+
29
SRCDIR = ./src
310
TESTDIR = ./tests
411
BENCHDIR = ./benchmarks
@@ -8,13 +15,16 @@ TESTS = $(wildcard $(TESTDIR)/*.cpp)
815
BENCHS = $(wildcard $(BENCHDIR)/*.cpp)
916
TESTOBJS = $(patsubst $(TESTDIR)/%.cpp,$(TESTDIR)/%.o,$(TESTS))
1017
BENCHOBJS = $(patsubst $(BENCHDIR)/%.cpp,$(BENCHDIR)/%.o,$(BENCHS))
11-
BENCHOBJS := $(filter-out $(BENCHDIR)/main.o ,$(BENCHOBJS))
12-
CXXFLAGS += -I$(SRCDIR) -I$(UTILS)
13-
GTESTCFLAGS = `pkg-config --cflags gtest_main`
14-
GTESTLDFLAGS = `pkg-config --libs gtest_main`
15-
GBENCHCFLAGS = `pkg-config --cflags benchmark`
16-
GBENCHLDFLAGS = `pkg-config --libs benchmark`
17-
MARCHFLAG = -march=sapphirerapids -O3
18+
19+
# Compiling AVX512-FP16 instructions isn't possible for g++ < 12
20+
ifeq ($(shell expr `$(CXX) -dumpversion | cut -d '.' -f 1` \< 12), 1)
21+
MARCHFLAG = -march=icelake-client
22+
BENCHOBJS_SKIP += bench-qsortfp16.o
23+
TESTOBJS_SKIP += test-qsortfp16.o
24+
endif
25+
26+
BENCHOBJS := $(filter-out $(addprefix $(BENCHDIR)/, $(BENCHOBJS_SKIP)) ,$(BENCHOBJS))
27+
TESTOBJS := $(filter-out $(addprefix $(TESTDIR)/, $(TESTOBJS_SKIP)) ,$(TESTOBJS))
1828

1929
all : test bench
2030

@@ -31,7 +41,7 @@ $(BENCHDIR)/%.o : $(BENCHDIR)/%.cpp $(SRCS)
3141
$(CXX) $(CXXFLAGS) $(MARCHFLAG) $(GBENCHCFLAGS) -c $< -o $@
3242

3343
bench: $(BENCHOBJS) $(UTILS)/cpuinfo.o
34-
$(CXX) $(BENCHDIR)/main.cpp $(BENCHOBJS) $(MARCHFLAG) $(CXXFLAGS) $(GBENCHLDFLAGS) $(UTILS)/cpuinfo.o -o benchexe
44+
$(CXX) $(BENCHOBJS) $(UTILS)/cpuinfo.o $(MARCHFLAG) $(CXXFLAGS) -lbenchmark_main $(GBENCHLDFLAGS) -o benchexe
3545

3646
meson:
3747
meson setup --warnlevel 0 --buildtype plain builddir

benchmarks/main.cpp

-3
This file was deleted.

meson.build

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ src = include_directories('src')
66
bench = include_directories('benchmarks')
77
utils = include_directories('utils')
88
tests = include_directories('tests')
9-
gtest_dep = dependency('gtest_main', required : true)
10-
gbench_dep = dependency('benchmark', required : true)
9+
gtest_dep = dependency('gtest_main', required : true, static: true)
10+
gbench_dep = dependency('benchmark', required : true, static: true)
1111

1212
fp16code = '''#include<immintrin.h>
1313
int main() {
@@ -28,9 +28,10 @@ testexe = executable('testexe',
2828
link_whole : [libtests, libcpuinfo]
2929
)
3030

31-
benchexe = executable('benchexe', 'benchmarks/main.cpp',
31+
benchexe = executable('benchexe',
3232
include_directories : [src, utils, bench],
3333
dependencies : [gbench_dep],
34+
link_args: ['-lbenchmark_main'],
3435
link_whole : [libbench, libcpuinfo],
3536
)
3637

0 commit comments

Comments
 (0)