Skip to content

Commit

Permalink
Cmake: generalized THREADING=OMP to work on supported platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov committed Aug 22, 2024
1 parent 486fd0b commit 784c734
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 105 deletions.
46 changes: 17 additions & 29 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,41 @@ ov_set_temp_directory(TEMP "${CMAKE_SOURCE_DIR}")
if(THREADING STREQUAL "OMP")
reset_deps_cache(OMP)
if(WIN32 AND X86_64)
RESOLVE_DEPENDENCY(OMP
RESOLVE_DEPENDENCY(INTEL_OMP
ARCHIVE_WIN "iomp.zip"
TARGET_PATH "${TEMP}/omp"
ENVIRONMENT "OMP"
ENVIRONMENT "INTEL_OMP"
VERSION_REGEX ".*_([a-z]*_([a-z0-9]+\\.)*[0-9]+).*"
SHA256 "62c68646747fb10f19b53217cb04a1e10ff93606f992e6b35eb8c31187c68fbf"
USE_NEW_LOCATION TRUE)
elseif(LINUX AND X86_64 AND OPENVINO_GNU_LIBC)
RESOLVE_DEPENDENCY(OMP
RESOLVE_DEPENDENCY(INTEL_OMP
ARCHIVE_LIN "iomp.tgz"
TARGET_PATH "${TEMP}/omp"
ENVIRONMENT "OMP"
ENVIRONMENT "INTEL_OMP"
VERSION_REGEX ".*_([a-z]*_([a-z0-9]+\\.)*[0-9]+).*"
SHA256 "7832b16d82513ee880d97c27c7626f9525ebd678decf6a8fe6c38550f73227d9"
USE_NEW_LOCATION TRUE)
elseif(APPLE AND X86_64)
RESOLVE_DEPENDENCY(OMP
RESOLVE_DEPENDENCY(INTEL_OMP
ARCHIVE_MAC "iomp_20190130_mac.tgz"
TARGET_PATH "${TEMP}/omp"
ENVIRONMENT "OMP"
ENVIRONMENT "INTEL_OMP"
VERSION_REGEX ".*_([a-z]*_([a-z0-9]+\\.)*[0-9]+).*"
SHA256 "591ea4a7e08bbe0062648916f42bded71d24c27f00af30a8f31a29b5878ea0cc"
USE_NEW_LOCATION TRUE)
else()
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})

ov_cpack_add_component(omp HIDDEN)
file(GLOB_RECURSE source_list "${OMP}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*")
install(FILES ${source_list}
DESTINATION ${OV_CPACK_RUNTIMEDIR}
COMPONENT omp)

if(INTEL_OMP)
update_deps_cache(INTEL_OMP "${INTEL_OMP}" "Path to OMP root folder")
debug_message(STATUS "intel_omp=" ${INTEL_OMP})

ov_cpack_add_component(omp HIDDEN)
file(GLOB_RECURSE source_list "${INTEL_OMP}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*")
install(FILES ${source_list}
DESTINATION ${OV_CPACK_RUNTIMEDIR}
COMPONENT intel_omp)
endif()
endif()

## TBB package
Expand Down
2 changes: 1 addition & 1 deletion cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if(RISCV64)
# oneDNN does not support non-SEQ for RISC-V architecture
set(THREADING_DEFAULT "SEQ")
else()
set(THREADING_DEFAULT "TBB")
set(THREADING_DEFAULT "OMP")
endif()

set(THREADING_OPTIONS "TBB" "TBB_AUTO" "SEQ" "OMP")
Expand Down
6 changes: 6 additions & 0 deletions src/bindings/python/wheel/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@
"rpath": LIBS_RPATH,
"binary_dir": OPENVINO_BINARY_DIR,
},
"intel_openmp_libs": {
"name": "intel_omp",
"prefix": f"{BUILD_BASE}/libs.intel_omp",
"install_dir": OV_RUNTIME_LIBS_DIR,
"binary_dir": OPENVINO_BINARY_DIR,
},
"pugixml_libs": {
"name": "pugixml",
"prefix": f"{BUILD_BASE}/libs.pugixml",
Expand Down
139 changes: 66 additions & 73 deletions src/cmake/ov_parallel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -316,95 +316,88 @@ function(ov_set_threading_interface_for TARGET_NAME)

set(OV_THREAD_DEFINE "OV_THREAD_SEQ")

if (THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO")
if (TBB_FOUND)
if(THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO")
if(TBB_FOUND)
set(OV_THREAD_DEFINE "OV_THREAD_TBB")
_ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} TBB::tbb)
target_compile_definitions(${TARGET_NAME} ${COMPILE_DEF_TYPE} TBB_PREVIEW_WAITING_FOR_WORKERS=1)
else ()
else()
set(THREADING "SEQ" PARENT_SCOPE)
message(WARNING "TBB was not found by the configured TBB_DIR path.\
SEQ method will be used for ${TARGET_NAME}")
endif ()
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 ()

if (NOT OpenVINO_SOURCE_DIR)
# TODO: dead code since ov_parallel.cmake is not used outside of OpenVINO build
if (WIN32)
set(lib_rel_path ${IE_LIB_REL_DIR})
set(lib_dbg_path ${IE_LIB_DBG_DIR})
else ()
set(lib_rel_path ${IE_EXTERNAL_DIR}/omp/lib)
set(lib_dbg_path ${lib_rel_path})
endif ()
else ()
if (ARM OR AARCH64)
set(lib_rel_path ${OMP})
endif()
elseif(THREADING STREQUAL "OMP")
# check if Intel OpenMP is downloaded
if(INTEL_OMP)
if(WIN32)
set(iomp_lib_name libiomp5md)
else()
set(lib_rel_path ${OMP}/lib)
endif ()
set(iomp_lib_name iomp5)
endif()

set(lib_rel_path ${INTEL_OMP}/lib)
set(lib_dbg_path ${lib_rel_path})
endif ()

if (NOT OMP_LIBRARIES_RELEASE)
find_library(OMP_LIBRARIES_RELEASE ${omp_lib_name} ${lib_rel_path} NO_DEFAULT_PATH)
message(STATUS "OMP Release lib: ${OMP_LIBRARIES_RELEASE}")
if (NOT LINUX)
find_library(OMP_LIBRARIES_DEBUG ${omp_lib_name} ${lib_dbg_path} NO_DEFAULT_PATH)
if (OMP_LIBRARIES_DEBUG)
message(STATUS "OMP Debug lib: ${OMP_LIBRARIES_DEBUG}")
else ()

find_library(INTEL_OMP_LIBRARIES_RELEASE NAMES ${iomp_lib_name} PATHS ${lib_rel_path} REQUIRED NO_DEFAULT_PATH)
list(APPEND iomp_imported_configurations RELEASE)

# try to find debug libraries as well
if(NOT LINUX)
find_library(INTEL_OMP_LIBRARIES_DEBUG NAMES ${iomp_lib_name} PATHS ${lib_dbg_path} NO_DEFAULT_PATH)
if(INTEL_OMP_LIBRARIES_DEBUG)
list(APPEND iomp_imported_configurations DEBUG)
set(iomp_imported_location_debug IMPORTED_LOCATION_DEBUG "${INTEL_OMP_LIBRARIES_DEBUG}")
else()
set(iomp_map_imported_debug_configuration MAP_IMPORTED_CONFIG_DEBUG Release)
message(WARNING "OMP Debug binaries are missed.")
endif ()
endif ()
endif ()
endif()
endif()

# create imported target
if(NOT TARGET IntelOpenMP::OpenMP_CXX)
add_library(IntelOpenMP::OpenMP_CXX SHARED IMPORTED)
set_property(TARGET IntelOpenMP::OpenMP_CXX APPEND PROPERTY
IMPORTED_CONFIGURATIONS ${iomp_imported_configurations})
set_target_properties(IntelOpenMP::OpenMP_CXX PROPERTIES
IMPORTED_LOCATION_RELEASE "${INTEL_OMP_LIBRARIES_RELEASE}"
${iomp_imported_location_debug})
set_target_properties(IntelOpenMP::OpenMP_CXX PROPERTIES
${iomp_map_imported_debug_configuration}
MAP_IMPORTED_CONFIG_MINSIZEREL Release
MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release)

if(WIN32)
set_target_properties(IntelOpenMP::OpenMP_CXX PROPERTIES
INTERFACE_COMPILE_OPTIONS /openmp
# avoid linking default OpenMP
# https://learn.microsoft.com/en-us/cpp/parallel/openmp/reference/openmp-library-reference?view=msvc-170
INTERFACE_LINK_OPTIONS -nodefaultlib:vcomp)
else()
set_target_properties(IntelOpenMP::OpenMP_CXX PROPERTIES
INTERFACE_COMPILE_OPTIONS -fopenmp)
endif()
endif()

if (NOT OMP_LIBRARIES_RELEASE)
message(WARNING "Intel OpenMP not found. Intel OpenMP support will be disabled. ${OV_THREAD_DEFINE} is defined")
set(THREADING "SEQ" PARENT_SCOPE)
else ()
set(OV_THREAD_DEFINE "OV_THREAD_OMP")
_ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} IntelOpenMP::OpenMP_CXX)
endif()

if (WIN32)
target_compile_options(${TARGET_NAME} ${LINK_TYPE} ${OpenMP_CXX_FLAGS} /openmp)
target_compile_options(${TARGET_NAME} ${LINK_TYPE} ${OpenMP_CXX_FLAGS} /Qopenmp)
_ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} "-nodefaultlib:vcomp")
else()
target_compile_options(${TARGET_NAME} ${LINK_TYPE} ${OpenMP_CXX_FLAGS} -fopenmp)
endif ()
if(NOT TARGET IntelOpenMP::OpenMP_CXX)
message(WARNING "Intel OpenMP is not found. Trying to find system OpenMP implementation")

# Debug binaries are optional.
if (OMP_LIBRARIES_DEBUG AND NOT LINUX)
if (WIN32)
_ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} "$<$<CONFIG:DEBUG>:${OMP_LIBRARIES_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${OMP_LIBRARIES_RELEASE}>")
else()
# TODO: handle multi-config generators case
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
_ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${OMP_LIBRARIES_DEBUG})
else()
_ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${OMP_LIBRARIES_RELEASE})
endif ()
endif ()
else ()
# Link Release library to all configurations.
_ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${OMP_LIBRARIES_RELEASE})
endif ()
endif ()
endif ()
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
_ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} OpenMP::OpenMP_CXX)
set(OV_THREAD_DEFINE "OV_THREAD_OMP")
else()
message(WARNING "System OpenMP is not found. Falling back to SEQ threading")
endif()
endif()
endif()

target_compile_definitions(${TARGET_NAME} ${COMPILE_DEF_TYPE} -DOV_THREAD=${OV_THREAD_DEFINE})

if (NOT THREADING STREQUAL "SEQ")
if(NOT THREADING STREQUAL "SEQ")
find_package(Threads REQUIRED)
_ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} Threads::Threads)
endif()
Expand Down
4 changes: 2 additions & 2 deletions src/common/util/src/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void ov::util::convert_path_win_style(std::string& path) {

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT

# ifdef __APPLE__
# ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
# endif
Expand Down Expand Up @@ -372,7 +372,7 @@ std::wstring ov::util::string_to_wstring(const std::string& string) {
# endif
}

# ifdef __APPLE__
# ifdef __clang__
# pragma clang diagnostic pop
# endif

Expand Down

0 comments on commit 784c734

Please sign in to comment.