Skip to content

Commit 41cb013

Browse files
committed
Integrate SIMDe to support cross-platform SIMD operations.
Add unit test
1 parent 01bca6b commit 41cb013

23 files changed

+1701
-529
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ data/
3939

4040
*.pyc
4141
.clang-*
42+
.vscode/
4243

4344
# macOS garbages
4445
.DS_Store

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "rabitqlib/third/simde"]
2+
path = rabitqlib/third/simde
3+
url = https://github.com/simd-everywhere/simde.git

CMakeLists.txt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,31 @@ project(RaBitQLib LANGUAGES CXX)
55
set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77

8+
include(cmake/cpu_features.cmake)
9+
10+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
11+
message(STATUS "Building in debug mode")
12+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
13+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
14+
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
15+
message(STATUS "Building in release mode")
16+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
17+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
18+
endif()
819

920
include_directories(${PROJECT_SOURCE_DIR}/rabitqlib)
21+
include_directories(${PROJECT_SOURCE_DIR}/rabitqlib/third/simde)
1022

1123
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1224

13-
SET(CMAKE_CXX_FLAGS "-Wall -Ofast -Wextra -lrt -march=native -fpic -fopenmp -ftree-vectorize -fexceptions")
25+
SET(CMAKE_CXX_FLAGS "-Wall -Ofast -Wextra -lrt -march=native -fpic -fopenmp -ftree-vectorize -fexceptions -w")
26+
SET(CMAKE_C_FLAGS "-Wall -Ofast -Wextra -lrt -march=native -fpic -fopenmp -ftree-vectorize -fexceptions -w")
27+
28+
add_subdirectory(sample)
29+
30+
option(BUILD_TESTS "Build tests" ON)
1431

15-
add_subdirectory(sample)
32+
if (BUILD_TESTS)
33+
add_subdirectory(contrib)
34+
add_subdirectory(tests)
35+
endif()

cmake/cpu_features.cmake

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# check if the cpu supports avx512
2+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
3+
execute_process(COMMAND lscpu OUTPUT_VARIABLE CPU_INFO)
4+
string(REGEX MATCH "avx512f" AVX512_SUPPORT "${CPU_INFO}")
5+
if(AVX512_SUPPORT)
6+
set(AVX512_SUPPORT ON)
7+
endif()
8+
9+
string(REGEX MATCH "avx2" AVX2_SUPPORT "${CPU_INFO}")
10+
if(AVX2_SUPPORT)
11+
set(AVX2_SUPPORT ON)
12+
endif()
13+
14+
string(REGEX MATCH "avx" AVX_SUPPORT "${CPU_INFO}")
15+
if(AVX_SUPPORT)
16+
set(AVX_SUPPORT ON)
17+
endif()
18+
19+
string(REGEX MATCH "sse4_2" SSE4_2_SUPPORT "${CPU_INFO}")
20+
if(SSE4_2_SUPPORT)
21+
set(SSE4_2_SUPPORT ON)
22+
endif()
23+
24+
string(REGEX MATCH "sse4_1" SSE4_1_SUPPORT "${CPU_INFO}")
25+
if(SSE4_1_SUPPORT)
26+
set(SSE4_1_SUPPORT ON)
27+
endif()
28+
endif()
29+
30+
31+
if(AVX512_SUPPORT)
32+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f")
33+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512f")
34+
endif()
35+
36+
if(AVX2_SUPPORT)
37+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")
38+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
39+
endif()
40+
41+
if(AVX_SUPPORT)
42+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
43+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
44+
endif()
45+
46+
if(SSE4_2_SUPPORT)
47+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
48+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2")
49+
endif()
50+
51+
if(SSE4_1_SUPPORT)
52+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
53+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1")
54+
endif()

contrib/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if (BUILD_TESTS)
2+
add_executable(dataset_example dataset_example.cpp)
3+
# target_link_libraries(dataset_example PRIVATE rabitqlib)
4+
target_include_directories(dataset_example PRIVATE ${PROJECT_SOURCE_DIR}/contrib)
5+
target_include_directories(dataset_example PRIVATE ${PROJECT_SOURCE_DIR}/)
6+
endif()

0 commit comments

Comments
 (0)