Skip to content

Commit

Permalink
[ARM] Enable OpenMP on ARM platforms (#25329)
Browse files Browse the repository at this point in the history
### Details:

Apple's `llvm` does not support `-fopenmp`. Brew's `llvm` avoids this
issue on OpenVINO build, however ACL build fails with the error `clang:
error: unsupported argument 'libomp' to option '-fopenmp='`. The
solution is to use `gcc` on Apple:
```
CXX=/opt/homebrew/Cellar/gcc/14.1.0_1/bin/g++-14 CC=/opt/homebrew/Cellar/gcc/14.1.0_1/bin/gcc-14 cmake -DTHREADING=OMP ..
```
On Linux compiler issues were not observed.

`ACLScheduler` uses only 1 thread if OpenMP is used because
`parallel_get_num_threads()` returns 1 in non-parallel section. The fix
is suggested in #25335

### Tickets:
 - *ticket-id*
  • Loading branch information
alvoron authored Jul 30, 2024
1 parent 6b4b54e commit c67dce1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
15 changes: 14 additions & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ if(THREADING STREQUAL "OMP")
SHA256 "591ea4a7e08bbe0062648916f42bded71d24c27f00af30a8f31a29b5878ea0cc"
USE_NEW_LOCATION TRUE)
else()
message(FATAL_ERROR "Intel OMP is not available on current platform")
message(WARNING "Pre-built Intel OMP is not available on current platform. System OMP will be used.")
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
foreach(OpenMP_LIB ${OpenMP_CXX_LIBRARIES})
string(FIND ${OpenMP_LIB} "omp" OpenMP_LIB_OMP_INDEX)
if(NOT OpenMP_LIB_OMP_INDEX EQUAL -1)
cmake_path(GET OpenMP_LIB PARENT_PATH OpenMP_LIB_DIR)
set(OMP_LIB ${OpenMP_LIB} CACHE FILEPATH "Path to OMP library")
set(OMP ${OpenMP_LIB_DIR} CACHE FILEPATH "Path to OMP root folder")
return()
endif()
endforeach()
endif()
message(FATAL_ERROR "System OpenMP has not been found")
endif()
update_deps_cache(OMP "${OMP}" "Path to OMP root folder")
debug_message(STATUS "intel_omp=" ${OMP})
Expand Down
2 changes: 1 addition & 1 deletion cmake/developer_package/compile_flags/sdl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG OR OV_COMPILER_IS_INTEL_LLVM
# Remove all symbol table and relocation information from the executable
set(OV_C_CXX_FLAGS "${OV_C_CXX_FLAGS} -s")
endif()
if(NOT MINGW)
if(NOT MINGW AND NOT APPLE)
set(OV_LINKER_FLAGS "${OV_LINKER_FLAGS} -z noexecstack -z relro -z now")
endif()
elseif(OV_COMPILER_IS_CLANG OR OV_COMPILER_IS_INTEL_LLVM)
Expand Down
6 changes: 5 additions & 1 deletion cmake/developer_package/plugins/plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ function(ov_add_plugin)
endif()

if(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CROSSCOMPILING)
target_link_options(${OV_PLUGIN_NAME} PRIVATE -Wl,--unresolved-symbols=ignore-in-shared-libs)
if (APPLE)
target_link_options(${OV_PLUGIN_NAME} PRIVATE -Wl,-undefined,dynamic_lookup)
else()
target_link_options(${OV_PLUGIN_NAME} PRIVATE -Wl,--unresolved-symbols=ignore-in-shared-libs)
endif()
endif()

set(custom_filter "")
Expand Down
5 changes: 1 addition & 4 deletions cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ else()
set(THREADING_DEFAULT "TBB")
endif()

set(THREADING_OPTIONS "TBB" "TBB_AUTO" "SEQ")
if(NOT APPLE)
list(APPEND THREADING_OPTIONS "OMP")
endif()
set(THREADING_OPTIONS "TBB" "TBB_AUTO" "SEQ" "OMP")

set(THREADING "${THREADING_DEFAULT}" CACHE STRING "Threading")
set_property(CACHE THREADING PROPERTY STRINGS ${THREADING_OPTIONS})
Expand Down
11 changes: 10 additions & 1 deletion src/cmake/ov_parallel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ function(ov_set_threading_interface_for TARGET_NAME)
elseif (THREADING STREQUAL "OMP")
if (WIN32)
set(omp_lib_name libiomp5md)
elseif (ARM OR AARCH64)
get_filename_component(OpenMP_CXX_LIB_NAME ${OMP_LIB} NAME)
string(REGEX REPLACE "^lib" "" OpenMP_CXX_LIB_NAME ${OpenMP_CXX_LIB_NAME})
string(REGEX REPLACE "\\.[^.]*$" "" OpenMP_CXX_LIB_NAME ${OpenMP_CXX_LIB_NAME})
set(omp_lib_name ${OpenMP_CXX_LIB_NAME})
else ()
set(omp_lib_name iomp5)
endif ()
Expand All @@ -343,7 +348,11 @@ function(ov_set_threading_interface_for TARGET_NAME)
set(lib_dbg_path ${lib_rel_path})
endif ()
else ()
set(lib_rel_path ${OMP}/lib)
if (ARM OR AARCH64)
set(lib_rel_path ${OMP})
else()
set(lib_rel_path ${OMP}/lib)
endif ()
set(lib_dbg_path ${lib_rel_path})
endif ()

Expand Down
15 changes: 13 additions & 2 deletions src/plugins/intel_cpu/thirdparty/ACLConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ elseif(NOT TARGET arm_compute::arm_compute)
get_filename_component(toolchain_prefix "${CMAKE_CXX_COMPILER}" DIRECTORY)
list(APPEND ARM_COMPUTE_OPTIONS toolchain_prefix="${toolchain_prefix}/")
elseif(APPLE)
# we need to bypass this information in case of custom compiler is passed
# to cmake call. Such compiler and compiler prefix need to be passed to scons
get_filename_component(cxx_compiler "${CMAKE_CXX_COMPILER}" NAME)
get_filename_component(c_compiler "${CMAKE_C_COMPILER}" NAME)
get_filename_component(compiler_prefix "${CMAKE_CXX_COMPILER}" DIRECTORY)

set(cmake_build_env
CC=${c_compiler}
CXX=${cxx_compiler})

if(CMAKE_OSX_DEPLOYMENT_TARGET)
set(extra_cxx_flags "${extra_cxx_flags} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
set(minos_added ON)
Expand All @@ -275,8 +285,9 @@ elseif(NOT TARGET arm_compute::arm_compute)
endif()
set(extra_cxx_flags "${extra_cxx_flags} --sysroot ${CMAKE_OSX_SYSROOT}")
endif()

set(extra_cxx_flags "${extra_cxx_flags} -Wno-error=return-stack-address")
if(OV_COMPILER_IS_CLANG)
set(extra_cxx_flags "${extra_cxx_flags} -Wno-error=return-stack-address")
endif()
get_filename_component(compiler_prefix "${CMAKE_CXX_COMPILER}" DIRECTORY)
list(APPEND ARM_COMPUTE_OPTIONS compiler_prefix="${compiler_prefix}/")

Expand Down

0 comments on commit c67dce1

Please sign in to comment.