-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
100 lines (85 loc) · 2.44 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.1...3.27)
project(
Aerobus
VERSION 1.2
LANGUAGES CXX
)
find_package(OpenMP REQUIRED)
find_package(benchmark)
include(CheckCXXSourceRuns)
set(AVX_FLAGS)
set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
FetchContent_MakeAvailable(googletest)
enable_testing()
add_executable(
lib_tests
src/lib_tests.cpp
)
target_link_libraries(
lib_tests
GTest::gtest_main
)
include(GoogleTest)
gtest_discover_tests(lib_tests)
set(CMAKE_REQUIRED_FLAGS_SAVED, "${CMAKE_REQUIRED_FLAGS}")
if(MSVC)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} /arch:AVX512")
else()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mavx512f -mavx512vl")
endif()
check_cxx_source_runs("
#include <immintrin.h>
int main()
{
__m512d a, b, c;
const double src[8] = { 1., 2., 3., 4., 5., 6., 7., 8. };
double dst[8];
a = _mm512_loadu_pd(reinterpret_cast<const __m512d*>(src));
b = _mm512_loadu_pd(reinterpret_cast<const __m512d*>(src));
c = _mm512_add_pd(a, b);
_mm512_storeu_pd(reinterpret_cast<__m512d*>(dst), c);
for(int i = 0; i < 8; i++) {
if((src[i] + src[i]) != dst[i]) {
return -1;
}
}
return 0;
}"
HAVE_AVX512_EXTENSIONS)
set(CMAKE_REQUIRED_FLAGS, "${CMAKE_REQUIRED_FLAGS_SAVED}")
if(MSVC)
set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} /O2 /we4309 /we4756 /D_USE_MATH_DEFINES /Wall /wd4711 /wd4710 /wd4127 /wd4577 /wd4100")
else()
set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} -O3 -ftemplate-depth=30000 -ftemplate-backtrace-limit=0 -Werror=overflow -Wall")
endif()
if(HAVE_AVX512_EXTENSIONS)
message("AVX512 detected, adding benchmarks")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX512")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -mavx512vl")
endif()
include_directories(
benchmarks
benchmark/include
)
add_executable(benchmarks src/benchmarks.cpp src/aerobus.h)
link_directories(
benchmarks
benchmark/build/src
)
target_link_libraries(
benchmarks
benchmark
pthread
)
else()
message("AVX512 not detected, benchmarks need manual configuration")
endif()