diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 4a40c6bb..27519b76 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -24,7 +24,7 @@ jobs: git clone https://github.com/google/benchmark.git cd benchmark cmake -E make_directory "build" - cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../ + cmake -E chdir "build" cmake -DBENCHMARK_ENABLE_GTEST_TESTS=OFF -DBENCHMARK_ENABLE_TESTING=OFF -DCMAKE_BUILD_TYPE=Release ../ sudo cmake --build "build" --config Release --target install - name: Install Intel SDE @@ -86,7 +86,7 @@ jobs: cd benchmark pip3 install -r requirements.txt cmake -E make_directory "build" - cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../ + cmake -E chdir "build" cmake -DBENCHMARK_ENABLE_GTEST_TESTS=OFF -DBENCHMARK_ENABLE_TESTING=OFF -DCMAKE_BUILD_TYPE=Release ../ sudo cmake --build "build" --config Release --target install - name: Run bench-compare diff --git a/.gitignore b/.gitignore index 662440d4..adb72083 100644 --- a/.gitignore +++ b/.gitignore @@ -33,5 +33,6 @@ *.out *.app +# Build or IDE artifacts **/.vscode - +/builddir/ diff --git a/Makefile b/Makefile index 7d06d931..52a1c60d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,11 @@ CXX ?= g++-12 +CXXFLAGS += -I$(SRCDIR) -I$(UTILS) -O3 +GTESTCFLAGS = `pkg-config --cflags gtest_main` +GTESTLDFLAGS = `pkg-config --static --libs gtest_main` +GBENCHCFLAGS = `pkg-config --cflags benchmark` +GBENCHLDFLAGS = `pkg-config --static --libs benchmark` +MARCHFLAG = -march=sapphirerapids + SRCDIR = ./src TESTDIR = ./tests BENCHDIR = ./benchmarks @@ -8,13 +15,16 @@ TESTS = $(wildcard $(TESTDIR)/*.cpp) BENCHS = $(wildcard $(BENCHDIR)/*.cpp) TESTOBJS = $(patsubst $(TESTDIR)/%.cpp,$(TESTDIR)/%.o,$(TESTS)) BENCHOBJS = $(patsubst $(BENCHDIR)/%.cpp,$(BENCHDIR)/%.o,$(BENCHS)) -BENCHOBJS := $(filter-out $(BENCHDIR)/main.o ,$(BENCHOBJS)) -CXXFLAGS += -I$(SRCDIR) -I$(UTILS) -GTESTCFLAGS = `pkg-config --cflags gtest_main` -GTESTLDFLAGS = `pkg-config --libs gtest_main` -GBENCHCFLAGS = `pkg-config --cflags benchmark` -GBENCHLDFLAGS = `pkg-config --libs benchmark` -MARCHFLAG = -march=sapphirerapids -O3 + +# Compiling AVX512-FP16 instructions isn't possible for g++ < 12 +ifeq ($(shell expr `$(CXX) -dumpversion | cut -d '.' -f 1` \< 12), 1) + MARCHFLAG = -march=icelake-client + BENCHOBJS_SKIP += bench-qsortfp16.o + TESTOBJS_SKIP += test-qsortfp16.o +endif + +BENCHOBJS := $(filter-out $(addprefix $(BENCHDIR)/, $(BENCHOBJS_SKIP)) ,$(BENCHOBJS)) +TESTOBJS := $(filter-out $(addprefix $(TESTDIR)/, $(TESTOBJS_SKIP)) ,$(TESTOBJS)) all : test bench @@ -31,7 +41,7 @@ $(BENCHDIR)/%.o : $(BENCHDIR)/%.cpp $(SRCS) $(CXX) $(CXXFLAGS) $(MARCHFLAG) $(GBENCHCFLAGS) -c $< -o $@ bench: $(BENCHOBJS) $(UTILS)/cpuinfo.o - $(CXX) $(BENCHDIR)/main.cpp $(BENCHOBJS) $(MARCHFLAG) $(CXXFLAGS) $(GBENCHLDFLAGS) $(UTILS)/cpuinfo.o -o benchexe + $(CXX) $(BENCHOBJS) $(UTILS)/cpuinfo.o $(MARCHFLAG) $(CXXFLAGS) -lbenchmark_main $(GBENCHLDFLAGS) -o benchexe meson: meson setup --warnlevel 0 --buildtype plain builddir diff --git a/benchmarks/main.cpp b/benchmarks/main.cpp deleted file mode 100644 index 71fefa04..00000000 --- a/benchmarks/main.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -BENCHMARK_MAIN(); diff --git a/meson.build b/meson.build index 9193776d..b5a40cbc 100644 --- a/meson.build +++ b/meson.build @@ -6,8 +6,8 @@ src = include_directories('src') bench = include_directories('benchmarks') utils = include_directories('utils') tests = include_directories('tests') -gtest_dep = dependency('gtest_main', required : true) -gbench_dep = dependency('benchmark', required : true) +gtest_dep = dependency('gtest_main', required : true, static: true) +gbench_dep = dependency('benchmark', required : true, static: true) fp16code = '''#include int main() { @@ -28,9 +28,10 @@ testexe = executable('testexe', link_whole : [libtests, libcpuinfo] ) -benchexe = executable('benchexe', 'benchmarks/main.cpp', +benchexe = executable('benchexe', include_directories : [src, utils, bench], dependencies : [gbench_dep], + link_args: ['-lbenchmark_main'], link_whole : [libbench, libcpuinfo], )