Skip to content

Commit f942ac6

Browse files
[0.8] Enable cpu_features for Apple silicon (#448)
* enable cpu_features code for M1 (cherry picked from commit 3a73990) * cpu feature tag update (cherry picked from commit 3533000) * fix include (cherry picked from commit 39e7a36) * whitespace alignment (cherry picked from commit 65eff3b) * includes cleanup (cherry picked from commit 8d87b46) --------- Co-authored-by: GuyAv46 <guy.avimor@gmail.com>
1 parent 0ca9b98 commit f942ac6

File tree

7 files changed

+8
-37
lines changed

7 files changed

+8
-37
lines changed

cmake/cpu_features.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ option(CMAKE_POSITION_INDEPENDENT_CODE "" ON)
44
FetchContent_Declare(
55
cpu_features
66
GIT_REPOSITORY https://github.com/google/cpu_features.git
7-
GIT_TAG 438a66e41807cd73e0c403966041b358f5eafc68
7+
GIT_TAG v0.9.0
88
)
99
FetchContent_MakeAvailable(cpu_features)

src/VecSim/spaces/CMakeLists.txt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@ add_library(VectorSimilaritySpaces_no_optimization
66
)
77

88
include(CheckCXXCompilerFlag)
9+
include(${root}/cmake/cpu_features.cmake)
910

1011
project(VectorSimilarity_Spaces)
1112

12-
# TODO: Remove this once cpu_features get support for M1
13-
if((NOT APPLE) OR (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64"))
14-
include(${root}/cmake/cpu_features.cmake)
15-
else()
16-
add_definitions(-DM1)
17-
endif()
18-
1913
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall")
2014

2115
set(OPTIMIZATIONS "")
@@ -59,8 +53,4 @@ add_library(VectorSimilaritySpaces
5953
${OPTIMIZATIONS}
6054
)
6155

62-
target_link_libraries(VectorSimilaritySpaces VectorSimilaritySpaces_no_optimization)
63-
64-
if((NOT APPLE) OR (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64"))
65-
target_link_libraries(VectorSimilaritySpaces cpu_features)
66-
endif()
56+
target_link_libraries(VectorSimilaritySpaces VectorSimilaritySpaces_no_optimization cpu_features)

src/VecSim/spaces/IP_space.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
#include "VecSim/spaces/IP_space.h"
88
#include "VecSim/spaces/IP/IP.h"
9-
#if defined(__x86_64__)
109
#include "VecSim/spaces/functions/AVX512.h"
1110
#include "VecSim/spaces/functions/AVX.h"
1211
#include "VecSim/spaces/functions/SSE.h"
13-
#endif
1412

1513
namespace spaces {
1614
dist_func_t<float> IP_FP32_GetDistFunc(size_t dim, const Arch_Optimization arch_opt,
@@ -25,8 +23,7 @@ dist_func_t<float> IP_FP32_GetDistFunc(size_t dim, const Arch_Optimization arch_
2523
if (dim < 16) {
2624
return ret_dist_func;
2725
}
28-
#if defined(M1)
29-
#elif defined(__x86_64__)
26+
#ifdef CPU_FEATURES_ARCH_X86_64
3027

3128
switch (arch_opt) {
3229
case ARCH_OPT_AVX512_F:
@@ -70,8 +67,7 @@ dist_func_t<double> IP_FP64_GetDistFunc(size_t dim, const Arch_Optimization arch
7067
if (dim < 8) {
7168
return ret_dist_func;
7269
}
73-
#if defined(M1)
74-
#elif defined(__x86_64__)
70+
#ifdef CPU_FEATURES_ARCH_X86_64
7571

7672
switch (arch_opt) {
7773
case ARCH_OPT_AVX512_F:

src/VecSim/spaces/L2_space.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
#include "VecSim/spaces/L2_space.h"
88
#include "VecSim/spaces/L2/L2.h"
9-
#if defined(__x86_64__)
109
#include "VecSim/spaces/functions/AVX512.h"
1110
#include "VecSim/spaces/functions/AVX.h"
1211
#include "VecSim/spaces/functions/SSE.h"
13-
#endif
1412

1513
namespace spaces {
1614

@@ -26,8 +24,7 @@ dist_func_t<float> L2_FP32_GetDistFunc(size_t dim, const Arch_Optimization arch_
2624
if (dim < 16) {
2725
return ret_dist_func;
2826
}
29-
#if defined(M1)
30-
#elif defined(__x86_64__)
27+
#ifdef CPU_FEATURES_ARCH_X86_64
3128

3229
switch (arch_opt) {
3330
case ARCH_OPT_AVX512_F:
@@ -71,8 +68,7 @@ dist_func_t<double> L2_FP64_GetDistFunc(size_t dim, const Arch_Optimization arch
7168
if (dim < 8) {
7269
return ret_dist_func;
7370
}
74-
#if defined(M1)
75-
#elif defined(__x86_64__)
71+
#ifdef CPU_FEATURES_ARCH_X86_64
7672

7773
switch (arch_opt) {
7874
case ARCH_OPT_AVX512_F:

src/VecSim/spaces/space_aux.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
*/
66

77
#include "space_aux.h"
8-
#if defined(M1)
9-
10-
#elif defined(__x86_64__)
11-
#include "cpu_features_macros.h"
12-
#endif
138

149
#ifdef CPU_FEATURES_ARCH_X86_64
1510
#include "cpuinfo_x86.h"
@@ -18,7 +13,6 @@
1813
Arch_Optimization getArchitectureOptimization() {
1914

2015
#ifdef CPU_FEATURES_ARCH_X86_64
21-
#include "cpuinfo_x86.h"
2216
cpu_features::X86Features features = cpu_features::GetX86Info().features;
2317
if (features.avx512f) {
2418
return ARCH_OPT_AVX512_F;

src/VecSim/spaces/space_aux.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#pragma once
8+
#include "cpu_features_macros.h"
89

910
enum Arch_Optimization {
1011
ARCH_OPT_NONE,

tests/unit/test_spaces.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ TEST_F(SpacesTest, double_ip_no_optimization_func_test) {
8484
ASSERT_NEAR(dist, 0.0, 0.00000001);
8585
}
8686

87-
#if defined(M1)
88-
89-
#elif defined(__x86_64)
90-
#include "cpu_features_macros.h"
9187
#ifdef CPU_FEATURES_ARCH_X86_64
9288

9389
using namespace spaces;
@@ -235,5 +231,3 @@ TEST_P(FP64SpacesOptimizationTest, FP64InnerProductTest) {
235231
INSTANTIATE_TEST_SUITE_P(FP64OptFuncs, FP64SpacesOptimizationTest, testing::Range(1UL, 8 * 2UL));
236232

237233
#endif // CPU_FEATURES_ARCH_X86_64
238-
239-
#endif // M1/X86_64

0 commit comments

Comments
 (0)