Skip to content

Commit

Permalink
Fix macOS x86_64 vectorized CPU tests (#28656)
Browse files Browse the repository at this point in the history
### Details:
- Regression after
#27088
- AVX512 flags are used when they are disabled via cmake's
`ENABLE_AVX512F`

Co-authored-by: Ilya Lavrenov <[email protected]>

---------

Signed-off-by: Tomasz Jankowski <[email protected]>
Co-authored-by: Ilya Lavrenov <[email protected]>
  • Loading branch information
t-jankowski and ilya-lavrenov authored Jan 24, 2025
1 parent 59cc460 commit 174869c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ jobs:
-DENABLE_NCC_STYLE=OFF \
-DENABLE_TESTS=ON \
-DENABLE_WHEEL=OFF \
-DENABLE_AVX512F=OFF \
-DCMAKE_COMPILE_WARNING_AS_ERROR=OFF \
-DENABLE_STRICT_DEPENDENCIES=OFF \
-DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CMAKE_CXX_COMPILER_LAUNCHER }} \
Expand Down
30 changes: 27 additions & 3 deletions cmake/developer_package/compile_flags/os_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ macro(ov_check_compiler_supports_sve flags)

# If the compilation test is successful, set appropriate variables indicating support
if(CXX_HAS_SVE)
set(CXX_SVE_FOUND TRUE CACHE BOOL "SVE available on host")
set(CXX_SVE_FOUND TRUE CACHE BOOL "CXX SVE support")
set(CXX_SVE_FOUND ON CACHE BOOL "SVE available on host")
set(CXX_SVE_FOUND ON CACHE BOOL "CXX SVE support")
set(CXX_SVE_FLAGS "${flags}" CACHE STRING "CXX SVE flags")
endif()

Expand All @@ -129,7 +129,7 @@ macro(ov_check_compiler_supports_sve flags)

# If the compilation test fails, indicate that the support is not found
if(NOT CXX_SVE_FOUND)
set(CXX_SVE_FOUND FALSE CACHE BOOL "CXX SVE support")
set(CXX_SVE_FOUND OFF CACHE BOOL "CXX SVE support")
set(CXX_SVE_FLAGS "" CACHE STRING "CXX SVE flags")
endif()

Expand All @@ -143,6 +143,10 @@ endmacro()
# Provides SSE4.2 compilation flags depending on an OS and a compiler
#
macro(ov_sse42_optimization_flags flags)
if(NOT ENABLE_SSE42)
message(FATAL_ERROR "Internal error: ENABLE_SSE42 if OFF and 'ov_sse42_optimization_flags' must not be called")
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# No such option for MSVC 2019
elseif(OV_COMPILER_IS_INTEL_LLVM)
Expand All @@ -167,6 +171,10 @@ endmacro()
# Provides AVX2 compilation flags depending on an OS and a compiler
#
macro(ov_avx2_optimization_flags flags)
if(NOT ENABLE_AVX2)
message(FATAL_ERROR "Internal error: ENABLE_AVX2 if OFF and 'ov_avx2_optimization_flags' must not be called")
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(${flags} /arch:AVX2)
elseif(OV_COMPILER_IS_INTEL_LLVM)
Expand All @@ -189,6 +197,10 @@ endmacro()
# depending on an OS and a compiler
#
macro(ov_avx512_optimization_flags flags)
if(NOT ENABLE_AVX512F)
message(FATAL_ERROR "Internal error: ENABLE_AVX512F if OFF and 'ov_avx512_optimization_flags' must not be called")
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(${flags} /arch:AVX512)
elseif(OV_COMPILER_IS_INTEL_LLVM AND WIN32)
Expand All @@ -204,6 +216,10 @@ endmacro()
# ov_arm_neon_optimization_flags(<output flags>)
#
macro(ov_arm_neon_optimization_flags flags)
if(NOT (AARCH64 OR ARM))
message(FATAL_ERROR "Internal error: platform is not ARM or AARCH64 and 'ov_arm_neon_optimization_flags' must not be called")
endif()

if(OV_COMPILER_IS_INTEL_LLVM)
message(WARNING "Unsupported CXX compiler ${CMAKE_CXX_COMPILER_ID}")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
Expand Down Expand Up @@ -234,6 +250,10 @@ endmacro()
# ov_arm_neon_fp16_optimization_flags(<output flags>)
#
macro(ov_arm_neon_fp16_optimization_flags flags)
if(NOT ENABLE_NEON_FP16)
message(FATAL_ERROR "Internal error: ENABLE_NEON_FP16 if OFF and 'ov_arm_neon_fp16_optimization_flags' must not be called")
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(WARNING "Unsupported CXX compiler ${CMAKE_CXX_COMPILER_ID} for arm64 platform")
elseif(ANDROID)
Expand All @@ -258,6 +278,10 @@ endmacro()
# ov_arm_sve_optimization_flags(<output flags>)
#
macro(ov_arm_sve_optimization_flags flags)
if(NOT ENABLE_SVE)
message(FATAL_ERROR "Internal error: ENABLE_SVE if OFF and 'ov_arm_sve_optimization_flags' must not be called")
endif()

# Check for compiler SVE support
ov_check_compiler_supports_sve("-march=armv8-a+sve")
if(OV_COMPILER_IS_INTEL_LLVM)
Expand Down
2 changes: 1 addition & 1 deletion cmake/developer_package/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ if(ENABLE_SVE)
if(NOT CXX_HAS_SVE)
set(ENABLE_SVE OFF CACHE BOOL "" FORCE)
endif()
endif()
endif()
4 changes: 1 addition & 3 deletions src/core/reference/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME reference)
if(ENABLE_AVX2)
ov_avx2_optimization_flags(avx2_flags)

set(OV_REFERENCE_X86_AVX2_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/op/convert_x86_intrinsics.cpp
)
set(OV_REFERENCE_X86_AVX2_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/op/convert_x86_intrinsics.cpp)
set_source_files_properties(${OV_REFERENCE_X86_AVX2_SRC} PROPERTIES COMPILE_OPTIONS "${avx2_flags}"
SKIP_UNITY_BUILD_INCLUSION ON
SKIP_PRECOMPILE_HEADERS ON)
Expand Down
18 changes: 13 additions & 5 deletions src/plugins/intel_cpu/tests/unit/vectorized/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,20 @@ if (ENABLE_SNIPPETS_LIBXSMM_TPP)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $<TARGET_PROPERTY:xsmm,INCLUDE_DIRECTORIES>)
endif()

if (X86_64)
ov_avx2_optimization_flags(avx2_flags)
ov_avx512_optimization_flags(avx512_flags)
if(X86_64)
if(ENABLE_AVX2)
ov_avx2_optimization_flags(avx2_flags)
list(APPEND compile_flags ${avx2_flags})
list(APPEND definitions HAVE_AVX2)
endif()
if(ENABLE_AVX512F)
ov_avx512_optimization_flags(avx512_flags)
list(APPEND compile_flags ${avx512_flags})
list(APPEND definitions HAVE_AVX512F)
endif()

target_compile_options(${TARGET_NAME} PRIVATE "${avx2_flags};${avx512_flags}")
target_compile_definitions(${TARGET_NAME} PRIVATE HAVE_AVX2 HAVE_AVX512F)
target_compile_options(${TARGET_NAME} PRIVATE "${compile_flags}")
target_compile_definitions(${TARGET_NAME} PRIVATE ${definitions})
endif()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ class CacheRotationKernelInstructionParameterizedTest

switch (instruction_set) {
using namespace ov::Extensions::Cpu::XARCH;
#if defined(HAVE_AVX2)
case TargetInstructionSet::AVX2:
rotate_kv_cache_chunk_avx2(chunk_x.data(),
chunk_y.data(),
Expand All @@ -424,6 +425,8 @@ class CacheRotationKernelInstructionParameterizedTest
num_elements_to_process,
/* is_tail = */ num_elements_to_process < vec_len_f32_avx2);
break;
#endif
#if defined(HAVE_AVX512F)
case TargetInstructionSet::AVX512:
rotate_kv_cache_chunk_avx512(chunk_x.data(),
chunk_y.data(),
Expand All @@ -432,6 +435,7 @@ class CacheRotationKernelInstructionParameterizedTest
num_elements_to_process,
/* is_tail = */ num_elements_to_process < vec_len_f32_avx512);
break;
#endif
default:
FAIL() << "unknown target instruction set";
}
Expand All @@ -454,6 +458,7 @@ TEST_P(CacheRotationKernelInstructionParameterizedTest, OptChunkRotationGivesRef
test_chunk_rotation_for_type<ov::bfloat16>();
}

#if defined(HAVE_AVX2) || defined(HAVE_AVX512F)
auto TEST_STRUCT_TO_NAME_FN =
[](const testing::TestParamInfo<CacheRotationKernelInstructionParameterizedTest::ParamType>& info) {
size_t num_elts = std::get<1>(info.param);
Expand All @@ -465,19 +470,24 @@ auto TEST_STRUCT_TO_NAME_FN =
}
return std::string("unknown");
};
#endif

#if defined(HAVE_AVX2)
INSTANTIATE_TEST_SUITE_P(AVX2,
CacheRotationKernelInstructionParameterizedTest,
::testing::Combine(::testing::Values(TargetInstructionSet::AVX2),
::testing::Range(size_t(0),
ov::Extensions::Cpu::XARCH::vec_len_f32_avx2 + 1)),
TEST_STRUCT_TO_NAME_FN);
#endif
#if defined(HAVE_AVX512F)
INSTANTIATE_TEST_SUITE_P(AVX512,
CacheRotationKernelInstructionParameterizedTest,
::testing::Combine(::testing::Values(TargetInstructionSet::AVX512),
::testing::Range(size_t(0),
ov::Extensions::Cpu::XARCH::vec_len_f32_avx512 + 1)),
TEST_STRUCT_TO_NAME_FN);
#endif

TYPED_TEST_P(CacheRotationKernelInputTypeParameterizedTest, OptBlockRotationGivesReferenceResults) {
auto raw_cache_mem_ptr = this->cache_mem.data();
Expand Down

0 comments on commit 174869c

Please sign in to comment.