Skip to content

Commit

Permalink
[CMAKE] Fix warnings in CPU cmake code (#28243)
Browse files Browse the repository at this point in the history
### Details:
Fix the following warnings
```
CMake Warning at cmake/developer_package/compile_flags/os_flags.cmake:252 (message):
  fp16 is not supported by architecture x86_64
Call Stack (most recent call first):
  cmake/developer_package/cross_compile/cross_compiled_func.cmake:29 (ov_arm_neon_fp16_optimization_flags)
  cmake/developer_package/OpenVINODeveloperScriptsConfig.cmake:261 (include)
  CMakeLists.txt:49 (find_package)


CMake Warning at cmake/developer_package/compile_flags/os_flags.cmake:294 (message):
  SVE is not supported by architecture x86_64
Call Stack (most recent call first):
  cmake/developer_package/cross_compile/cross_compiled_func.cmake:30 (ov_arm_sve_optimization_flags)
  cmake/developer_package/OpenVINODeveloperScriptsConfig.cmake:261 (include)
  CMakeLists.txt:49 (find_package)
```
  • Loading branch information
ilya-lavrenov authored Jan 7, 2025
1 parent 66f1b24 commit e56624a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 72 deletions.
8 changes: 4 additions & 4 deletions cmake/developer_package/compile_flags/os_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,22 @@ endmacro()
#
macro(ov_arm_neon_fp16_optimization_flags flags)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(WARNING "Unsupported CXX compiler ${CMAKE_CXX_COMPILER_ID}")
message(WARNING "Unsupported CXX compiler ${CMAKE_CXX_COMPILER_ID} for arm64 platform")
elseif(ANDROID)
if(ANDROID_ABI STREQUAL "arm64-v8a")
set(${flags} -march=armv8.2-a+fp16 -Wno-unused-command-line-argument)
else()
message(WARNING "fp16 is not supported by Android armv7")
message(WARNING "ARM64 fp16 is not supported by Android armv7")
endif()
elseif(AARCH64)
set(${flags} -O2 -march=armv8.2-a+fp16)
if(NOT CMAKE_CL_64)
list(APPEND ${flags} -ftree-vectorize)
endif()
elseif(ARM)
message(WARNING "fp16 is not supported by 32-bit ARM")
message(WARNING "ARM64 fp16 is not supported by 32-bit ARM")
else()
message(WARNING "fp16 is not supported by architecture ${CMAKE_SYSTEM_PROCESSOR}")
message(WARNING "ARM64 fp16 is not supported by architecture ${CMAKE_SYSTEM_PROCESSOR}")
endif()
endmacro()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,32 @@ function(_generate_dispatcher)
")

foreach(_namespace ${PARENT_NAMESPACES})
foreach(_namespace IN LISTS PARENT_NAMESPACES)
string(APPEND DISP_CONTENT
"namespace ${_namespace} {\n")
endforeach()

foreach(_func_name ${XARCH_FUNC_NAMES})
foreach(_func_name IN LISTS XARCH_FUNC_NAMES)
_find_signature_in_file(${XARCH_API_HEADER} ${_func_name} SIGNATURE)
_generate_call_line_from_signature("${SIGNATURE}" CALL_LINE)

foreach(_arch ${XARCH_SET})
foreach(_arch IN LISTS XARCH_SET)
string(APPEND DISP_CONTENT
"namespace ${_arch} {\n ${SIGNATURE}\; \n}\n")
endforeach()

string(APPEND DISP_CONTENT
"namespace ${XARCH_CURRENT_NAMESPACE} {\n\n${SIGNATURE} {\n")

foreach(_arch ${XARCH_SET})
foreach(_arch IN LISTS XARCH_SET)
string(APPEND DISP_CONTENT
" if (${_CPU_CHECK_${_arch}}) {\n return ${_arch}::${CALL_LINE}\;\n }\n")
endforeach()

string(APPEND DISP_CONTENT "}\n\n}\n")
endforeach()

foreach(_namespace ${PARENT_NAMESPACES})
foreach(_namespace IN LISTS PARENT_NAMESPACES)
string(APPEND DISP_CONTENT "} // namespace ${_namespace}\n")
endforeach()

Expand Down
84 changes: 41 additions & 43 deletions cmake/developer_package/cross_compile/cross_compiled_func.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@
#

## list of available instruction sets
set(_ARCH_LIST ANY SSE42 AVX AVX2 AVX512F NEON_FP16 SVE)
set(_AVAILABLE_ARCHS_LIST ANY SSE42 AVX AVX2 AVX512F NEON_FP16 SVE)

set(_ACCEPTED_ARCHS_ANY "^(ANY)$")
set(_ACCEPTED_ARCHS_SSE42 "^(ANY|SSE42)$")
set(_ACCEPTED_ARCHS_AVX "^(ANY|SSE42|AVX)$")
set(_ACCEPTED_ARCHS_AVX2 "^(ANY|SSE42|AVX|AVX2)$")
set(_ACCEPTED_ARCHS_AVX512F "^(ANY|SSE42|AVX|AVX2|AVX512F)$")
set(_ACCEPTED_ARCHS_NEON_FP16 "^(ANY|NEON_FP16)$")
set(_ACCEPTED_ARCHS_SVE "^(ANY|NEON_FP16|SVE)$")
if(ENABLE_SVE)
list(APPEND _ENABLED_ARCHS_LIST SVE)
endif()
if(ENABLE_NEON_FP16)
list(APPEND _ENABLED_ARCHS_LIST NEON_FP16)
endif()
if(ENABLE_AVX512F)
list(APPEND _ENABLED_ARCHS_LIST AVX512F)
endif()
if(ENABLE_AVX2)
list(APPEND _ENABLED_ARCHS_LIST AVX2)
endif()
if(ENABLE_SSE42)
list(APPEND _ENABLED_ARCHS_LIST SSE42)
endif()
list(APPEND _ENABLED_ARCHS_LIST ANY)

## Arch specific definitions
set(_DEFINE_ANY "")
Expand All @@ -23,11 +32,21 @@ set(_DEFINE_NEON_FP16 "HAVE_NEON_FP16" ${_DEFINE_ANY})
set(_DEFINE_SVE "HAVE_SVE" ${_DEFINE_SVE})

## Arch specific compile options
ov_avx512_optimization_flags(_FLAGS_AVX512F)
ov_avx2_optimization_flags (_FLAGS_AVX2)
ov_sse42_optimization_flags (_FLAGS_SSE42)
ov_arm_neon_fp16_optimization_flags(_FLAGS_NEON_FP16)
ov_arm_sve_optimization_flags(_FLAGS_SVE)
if(ENABLE_AVX512F)
ov_avx512_optimization_flags(_FLAGS_AVX512F)
endif()
if(ENABLE_AVX2)
ov_avx2_optimization_flags(_FLAGS_AVX2)
endif()
if(ENABLE_SSE42)
ov_sse42_optimization_flags(_FLAGS_SSE42)
endif()
if(ENABLE_NEON_FP16)
ov_arm_neon_fp16_optimization_flags(_FLAGS_NEON_FP16)
endif()
if(ENABLE_SVE)
ov_arm_sve_optimization_flags(_FLAGS_SVE)
endif()
set(_FLAGS_AVX "") ## TBD is not defined for OV project yet
set(_FLAGS_ANY "") ##

Expand Down Expand Up @@ -75,18 +94,15 @@ function(cross_compiled_file TARGET)
message(FATAL_ERROR "Unknown argument: " ${X_UNPARSED_ARGUMENTS})
endif()
if((NOT TARGET) OR (NOT X_NAME) OR (NOT X_NAMESPACE) OR (NOT X_API) OR (NOT X_ARCH))
message(FATAL_ERROR "Missed arguments")
message(FATAL_ERROR "Missed arguments in 'cross_compiled_file'")
endif()

_currently_requested_top_arch(TOP_ARCH)
set(_CURRENT_ARCH_FILTER "${_ACCEPTED_ARCHS_${TOP_ARCH}}")

## format: ARCH1 ARCH2 <src1> ARCH3 <src2> ...
foreach(_it ${X_ARCH})
if (_it IN_LIST _ARCH_LIST)
foreach(_it IN LISTS X_ARCH)
if(_it IN_LIST _AVAILABLE_ARCHS_LIST)
## that is arch ID
set(_arch ${_it})
if(_arch MATCHES ${_CURRENT_ARCH_FILTER})
if(_arch IN_LIST _ENABLED_ARCHS_LIST)
# make non/less-optimized version coming first
list(INSERT _CUR_ARCH_SET 0 ${_arch})
list(APPEND _FULL_ARCH_SET ${_arch})
Expand All @@ -95,8 +111,11 @@ function(cross_compiled_file TARGET)
## that is source file name
set(_src_name ${_it})
_remove_source_from_target(${TARGET} ${_src_name})
_clone_source_to_target(${TARGET} ${_src_name} "${_CUR_ARCH_SET}")
set(_CUR_ARCH_SET "")

if(_CUR_ARCH_SET)
_clone_source_to_target(${TARGET} ${_src_name} "${_CUR_ARCH_SET}")
unset(_CUR_ARCH_SET)
endif()
endif()
endforeach()

Expand Down Expand Up @@ -181,27 +200,6 @@ function(_add_dispatcher_to_target TARGET HEADER FUNC_NAME NAMESPACE ARCH_SET)
target_sources(${TARGET} PRIVATE ${DISPATCHER_SOURCE})
endfunction()

#######################################
#
# Return currently requested ARCH id
#
function(_currently_requested_top_arch VAR)
if(ENABLE_SVE)
set(RES SVE)
elseif(ENABLE_NEON_FP16)
set(RES NEON_FP16)
elseif(ENABLE_AVX512F)
set(RES AVX512F)
elseif(ENABLE_AVX2)
set(RES AVX2)
elseif(ENABLE_SSE42)
set(RES SSE42)
else()
set(RES ANY)
endif()
set (${VAR} "${RES}" PARENT_SCOPE)
endfunction()

#####################################
#
# Utils to handle with cmake target
Expand Down
22 changes: 2 additions & 20 deletions src/plugins/intel_cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,6 @@ target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $<TARGET_PROPERTY:dnnl,
# is not (yet) needed.
target_include_directories(${TARGET_NAME} PRIVATE $<TARGET_PROPERTY:openvino::reference,INTERFACE_INCLUDE_DIRECTORIES>)

# ARCH lists for softmax.cpp and mha_single_token.cpp
# Based on result of above calls, decide whether to add SVE
set(SOFTMAX_ARCH_LIST AVX512F AVX2)
set(MHA_SINGLE_TOKEN_ARCH_LIST AVX512F AVX2)

if(ENABLE_SVE)
list(APPEND SOFTMAX_ARCH_LIST SVE)
list(APPEND MHA_SINGLE_TOKEN_ARCH_LIST SVE)
endif()

if(ENABLE_NEON_FP16)
list(APPEND SOFTMAX_ARCH_LIST NEON_FP16)
list(APPEND MHA_SINGLE_TOKEN_ARCH_LIST NEON_FP16)
endif()

list(APPEND SOFTMAX_ARCH_LIST ANY)
list(APPEND MHA_SINGLE_TOKEN_ARCH_LIST ANY)

# Cross compiled function
# TODO: The same for proposal, proposalONNX, topk
cross_compiled_file(${TARGET_NAME}
Expand All @@ -306,14 +288,14 @@ cross_compiled_file(${TARGET_NAME}
NAMESPACE ov::Extensions::Cpu::XARCH
)
cross_compiled_file(${TARGET_NAME}
ARCH ${SOFTMAX_ARCH_LIST}
ARCH AVX512F AVX2 SVE NEON_FP16 ANY
src/nodes/kernels/scaled_attn/softmax.cpp
API src/nodes/kernels/scaled_attn/softmax.hpp
NAME attn_softmax
NAMESPACE ov::Extensions::Cpu::XARCH
)
cross_compiled_file(${TARGET_NAME}
ARCH ${MHA_SINGLE_TOKEN_ARCH_LIST}
ARCH AVX512F AVX2 SVE NEON_FP16 ANY
src/nodes/kernels/scaled_attn/mha_single_token.cpp
API src/nodes/kernels/scaled_attn/mha_single_token.hpp
NAME mha_single_token
Expand Down

0 comments on commit e56624a

Please sign in to comment.