mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Simplify OpenMP detection in CMake (#91576)
We greatly simplify the handing of OpenMP in CMake by using caffe2::openmp target thoroughly. We follow the old behavior by defaulting to MKL OMP library and detecting OMP flags otherwise. Pull Request resolved: https://github.com/pytorch/pytorch/pull/91576 Approved by: https://github.com/malfet
This commit is contained in:
@ -6,11 +6,6 @@ if(USE_VULKAN)
|
|||||||
include(../cmake/VulkanCodegen.cmake)
|
include(../cmake/VulkanCodegen.cmake)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# ---[ MSVC OpenMP modification
|
|
||||||
if(MSVC)
|
|
||||||
include(../cmake/public/utils.cmake)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Debug messages - if you want to get a list of source files and examine
|
# Debug messages - if you want to get a list of source files and examine
|
||||||
# target information, enable the following by -DPRINT_CMAKE_DEBUG_INFO=ON.
|
# target information, enable the following by -DPRINT_CMAKE_DEBUG_INFO=ON.
|
||||||
set(PRINT_CMAKE_DEBUG_INFO FALSE CACHE BOOL "print cmake debug information")
|
set(PRINT_CMAKE_DEBUG_INFO FALSE CACHE BOOL "print cmake debug information")
|
||||||
@ -1219,29 +1214,6 @@ if(NOT NO_API)
|
|||||||
$<BUILD_INTERFACE:${TORCH_SRC_DIR}/csrc/api/include>)
|
$<BUILD_INTERFACE:${TORCH_SRC_DIR}/csrc/api/include>)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if(USE_OPENMP)
|
|
||||||
find_package(OpenMP QUIET)
|
|
||||||
endif()
|
|
||||||
if(USE_OPENMP AND OPENMP_FOUND)
|
|
||||||
if(MSVC AND OpenMP_CXX_LIBRARIES MATCHES "libiomp5md\\.lib")
|
|
||||||
set(AT_MKL_MT 1)
|
|
||||||
else()
|
|
||||||
set(AT_MKL_MT 0)
|
|
||||||
endif()
|
|
||||||
message(STATUS "pytorch is compiling with OpenMP. \n"
|
|
||||||
"OpenMP CXX_FLAGS: ${OpenMP_CXX_FLAGS}. \n"
|
|
||||||
"OpenMP libraries: ${OpenMP_CXX_LIBRARIES}.")
|
|
||||||
if(UNIX)
|
|
||||||
separate_arguments(OpenMP_CXX_OPTIONS UNIX_COMMAND "${OpenMP_CXX_FLAGS}")
|
|
||||||
else()
|
|
||||||
separate_arguments(OpenMP_CXX_OPTIONS WINDOWS_COMMAND "${OpenMP_CXX_FLAGS}")
|
|
||||||
endif()
|
|
||||||
target_compile_options(torch_cpu PRIVATE ${OpenMP_CXX_OPTIONS})
|
|
||||||
target_link_libraries(torch_cpu PRIVATE ${OpenMP_CXX_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
if(USE_ROCM)
|
if(USE_ROCM)
|
||||||
target_compile_definitions(torch_hip PRIVATE
|
target_compile_definitions(torch_hip PRIVATE
|
||||||
USE_ROCM
|
USE_ROCM
|
||||||
@ -1332,13 +1304,6 @@ if(NOT INTERN_BUILD_MOBILE)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(USE_OPENMP AND OPENMP_FOUND)
|
|
||||||
message(STATUS "Caffe2 is compiling with OpenMP. \n"
|
|
||||||
"OpenMP CXX_FLAGS: ${OpenMP_CXX_FLAGS}. \n"
|
|
||||||
"OpenMP libraries: ${OpenMP_CXX_LIBRARIES}.")
|
|
||||||
target_link_libraries(torch_cpu PRIVATE ${OpenMP_CXX_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if($ENV{TH_BINARY_BUILD})
|
if($ENV{TH_BINARY_BUILD})
|
||||||
if(NOT MSVC AND USE_CUDA AND NOT APPLE)
|
if(NOT MSVC AND USE_CUDA AND NOT APPLE)
|
||||||
# Note [Extra MKL symbols for MAGMA in torch_cpu]
|
# Note [Extra MKL symbols for MAGMA in torch_cpu]
|
||||||
@ -1375,9 +1340,6 @@ target_link_libraries(torch_cpu PRIVATE ${Caffe2_DEPENDENCY_WHOLE_LINK_LIBS})
|
|||||||
target_include_directories(torch_cpu INTERFACE $<INSTALL_INTERFACE:include>)
|
target_include_directories(torch_cpu INTERFACE $<INSTALL_INTERFACE:include>)
|
||||||
target_include_directories(torch_cpu PRIVATE ${Caffe2_CPU_INCLUDE})
|
target_include_directories(torch_cpu PRIVATE ${Caffe2_CPU_INCLUDE})
|
||||||
target_include_directories(torch_cpu SYSTEM PRIVATE "${Caffe2_DEPENDENCY_INCLUDE}")
|
target_include_directories(torch_cpu SYSTEM PRIVATE "${Caffe2_DEPENDENCY_INCLUDE}")
|
||||||
# Set standard properties on the target
|
|
||||||
torch_set_target_props(torch_cpu)
|
|
||||||
|
|
||||||
|
|
||||||
target_compile_options(torch_cpu PRIVATE "-DCAFFE2_BUILD_MAIN_LIB")
|
target_compile_options(torch_cpu PRIVATE "-DCAFFE2_BUILD_MAIN_LIB")
|
||||||
if(USE_CUDA)
|
if(USE_CUDA)
|
||||||
@ -1711,11 +1673,6 @@ if(BUILD_TEST)
|
|||||||
get_filename_component(test_name ${test_src} NAME_WE)
|
get_filename_component(test_name ${test_src} NAME_WE)
|
||||||
add_executable(${test_name} "${test_src}")
|
add_executable(${test_name} "${test_src}")
|
||||||
target_link_libraries(${test_name} torch_library gtest_main)
|
target_link_libraries(${test_name} torch_library gtest_main)
|
||||||
if(USE_OPENMP)
|
|
||||||
# -fopenmp is a compile time flag and as result not guaranteed
|
|
||||||
# to link executable against OpenMP runtime library
|
|
||||||
target_link_libraries(${test_name} ${OpenMP_CXX_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
|
target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
|
||||||
target_include_directories(${test_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)
|
target_include_directories(${test_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)
|
||||||
target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE})
|
target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE})
|
||||||
@ -1911,7 +1868,6 @@ if(BUILD_PYTHON)
|
|||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
set_target_properties(caffe2_pybind11_state PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
|
set_target_properties(caffe2_pybind11_state PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
|
||||||
endif()
|
endif()
|
||||||
torch_set_target_props(caffe2_pybind11_state)
|
|
||||||
set_target_properties(caffe2_pybind11_state PROPERTIES PREFIX "" DEBUG_POSTFIX "")
|
set_target_properties(caffe2_pybind11_state PROPERTIES PREFIX "" DEBUG_POSTFIX "")
|
||||||
set_target_properties(caffe2_pybind11_state PROPERTIES SUFFIX ${PY_EXT_SUFFIX})
|
set_target_properties(caffe2_pybind11_state PROPERTIES SUFFIX ${PY_EXT_SUFFIX})
|
||||||
set_target_properties(caffe2_pybind11_state PROPERTIES LINK_FLAGS "${_caffe2_pybind11_state_linker_flags}")
|
set_target_properties(caffe2_pybind11_state PROPERTIES LINK_FLAGS "${_caffe2_pybind11_state_linker_flags}")
|
||||||
@ -1947,7 +1903,6 @@ if(BUILD_PYTHON)
|
|||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
|
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
|
||||||
endif()
|
endif()
|
||||||
torch_set_target_props(caffe2_pybind11_state_gpu)
|
|
||||||
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES PREFIX "" DEBUG_POSTFIX "")
|
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES PREFIX "" DEBUG_POSTFIX "")
|
||||||
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES SUFFIX ${PY_EXT_SUFFIX})
|
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES SUFFIX ${PY_EXT_SUFFIX})
|
||||||
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES LINK_FLAGS "${_caffe2_pybind11_state_linker_flags}")
|
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES LINK_FLAGS "${_caffe2_pybind11_state_linker_flags}")
|
||||||
@ -1979,7 +1934,6 @@ if(BUILD_PYTHON)
|
|||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
target_compile_options(caffe2_pybind11_state_hip PRIVATE ${HIP_CXX_FLAGS} -fvisibility=hidden)
|
target_compile_options(caffe2_pybind11_state_hip PRIVATE ${HIP_CXX_FLAGS} -fvisibility=hidden)
|
||||||
endif()
|
endif()
|
||||||
torch_set_target_props(caffe2_pybind11_state_hip)
|
|
||||||
set_target_properties(caffe2_pybind11_state_hip PROPERTIES PREFIX "")
|
set_target_properties(caffe2_pybind11_state_hip PROPERTIES PREFIX "")
|
||||||
set_target_properties(caffe2_pybind11_state_hip PROPERTIES SUFFIX ${PY_EXT_SUFFIX})
|
set_target_properties(caffe2_pybind11_state_hip PROPERTIES SUFFIX ${PY_EXT_SUFFIX})
|
||||||
set_target_properties(caffe2_pybind11_state_hip PROPERTIES LINK_FLAGS "${_caffe2_pybind11_state_linker_flags}")
|
set_target_properties(caffe2_pybind11_state_hip PROPERTIES LINK_FLAGS "${_caffe2_pybind11_state_linker_flags}")
|
||||||
|
@ -257,7 +257,6 @@ endif()
|
|||||||
if(NOT INTERN_BUILD_MOBILE)
|
if(NOT INTERN_BUILD_MOBILE)
|
||||||
set(AT_MKL_ENABLED 0)
|
set(AT_MKL_ENABLED 0)
|
||||||
set(AT_MKL_SEQUENTIAL 0)
|
set(AT_MKL_SEQUENTIAL 0)
|
||||||
set(AT_MKL_MT 0)
|
|
||||||
set(USE_BLAS 1)
|
set(USE_BLAS 1)
|
||||||
if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR VECLIB_FOUND OR FlexiBLAS_FOUND))
|
if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR VECLIB_FOUND OR FlexiBLAS_FOUND))
|
||||||
message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
|
message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
|
||||||
@ -271,10 +270,6 @@ if(NOT INTERN_BUILD_MOBILE)
|
|||||||
if("${MKL_THREADING}" STREQUAL "SEQ")
|
if("${MKL_THREADING}" STREQUAL "SEQ")
|
||||||
set(AT_MKL_SEQUENTIAL 1)
|
set(AT_MKL_SEQUENTIAL 1)
|
||||||
endif()
|
endif()
|
||||||
if(MSVC AND MKL_LIBRARIES MATCHES ".*libiomp5md\\.lib.*")
|
|
||||||
add_definitions(-D_OPENMP_NOFORCE_MANIFEST)
|
|
||||||
set(AT_MKL_MT 1)
|
|
||||||
endif()
|
|
||||||
set(AT_MKL_ENABLED 1)
|
set(AT_MKL_ENABLED 1)
|
||||||
endif()
|
endif()
|
||||||
elseif(INTERN_USE_EIGEN_BLAS)
|
elseif(INTERN_USE_EIGEN_BLAS)
|
||||||
@ -1183,72 +1178,20 @@ if(USE_MPI)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# ---[ OpenMP
|
# ---[ OpenMP
|
||||||
if(USE_OPENMP)
|
if(USE_OPENMP AND NOT TARGET caffe2::openmp)
|
||||||
# OpenMP support?
|
include(${CMAKE_CURRENT_LIST_DIR}/Modules/FindOpenMP.cmake)
|
||||||
set(WITH_OPENMP ON CACHE BOOL "OpenMP support if available?")
|
|
||||||
|
|
||||||
# macOS + GCC
|
|
||||||
if(APPLE AND CMAKE_COMPILER_IS_GNUCC)
|
|
||||||
exec_program(uname ARGS -v OUTPUT_VARIABLE DARWIN_VERSION)
|
|
||||||
string(REGEX MATCH "[0-9]+" DARWIN_VERSION ${DARWIN_VERSION})
|
|
||||||
message(STATUS "macOS Darwin version: ${DARWIN_VERSION}")
|
|
||||||
if(DARWIN_VERSION GREATER 9)
|
|
||||||
set(APPLE_OPENMP_SUCKS 1)
|
|
||||||
endif(DARWIN_VERSION GREATER 9)
|
|
||||||
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
|
|
||||||
OUTPUT_VARIABLE GCC_VERSION)
|
|
||||||
if(APPLE_OPENMP_SUCKS AND GCC_VERSION VERSION_LESS 4.6.2)
|
|
||||||
message(WARNING "Disabling OpenMP (unstable with this version of GCC). "
|
|
||||||
"Install GCC >= 4.6.2 or change your OS to enable OpenMP.")
|
|
||||||
add_compile_options(-Wno-unknown-pragmas)
|
|
||||||
set(WITH_OPENMP OFF CACHE BOOL "OpenMP support if available?" FORCE)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC"
|
|
||||||
AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
||||||
message(STATUS "Setting OpenMP flags for clang-cl")
|
|
||||||
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
|
|
||||||
set(OpenMP_C_FLAGS "-Xclang -fopenmp")
|
|
||||||
set(CHECKED_OPENMP ON CACHE BOOL "already checked for OpenMP")
|
|
||||||
set(OPENMP_FOUND ON CACHE BOOL "OpenMP Support found")
|
|
||||||
if(NOT MKL_FOUND)
|
|
||||||
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_version_output)
|
|
||||||
string(REGEX REPLACE ".*InstalledDir: ([^\n]+).*" "\\1" CLANG_BINDIR ${clang_version_output})
|
|
||||||
|
|
||||||
get_filename_component(CLANG_ROOT ${CLANG_BINDIR} DIRECTORY)
|
|
||||||
set(CLANG_OPENMP_LIBRARY "${CLANG_ROOT}/lib/libiomp5md.lib")
|
|
||||||
|
|
||||||
if(NOT TARGET caffe2::openmp)
|
|
||||||
add_library(caffe2::openmp INTERFACE IMPORTED)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set_property(
|
|
||||||
TARGET caffe2::openmp PROPERTY INTERFACE_LINK_LIBRARIES
|
|
||||||
${CLANG_OPENMP_LIBRARY})
|
|
||||||
|
|
||||||
list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS caffe2::openmp)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(WITH_OPENMP AND NOT CHECKED_OPENMP)
|
|
||||||
find_package(OpenMP QUIET)
|
|
||||||
set(CHECKED_OPENMP ON CACHE BOOL "already checked for OpenMP")
|
|
||||||
|
|
||||||
# OPENMP_FOUND is not cached in FindOpenMP.cmake (all other variables are cached)
|
|
||||||
# see https://github.com/Kitware/CMake/blob/master/Modules/FindOpenMP.cmake
|
|
||||||
set(OPENMP_FOUND ${OPENMP_FOUND} CACHE BOOL "OpenMP Support found")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(OPENMP_FOUND)
|
if(OPENMP_FOUND)
|
||||||
message(STATUS "Adding OpenMP CXX_FLAGS: " ${OpenMP_CXX_FLAGS})
|
message(STATUS "Adding OpenMP CXX_FLAGS: " ${OpenMP_CXX_FLAGS})
|
||||||
if("${OpenMP_CXX_LIBRARIES}" STREQUAL "")
|
if(OpenMP_CXX_LIBRARIES)
|
||||||
message(STATUS "No OpenMP library needs to be linked against")
|
|
||||||
else()
|
|
||||||
message(STATUS "Will link against OpenMP libraries: ${OpenMP_CXX_LIBRARIES}")
|
message(STATUS "Will link against OpenMP libraries: ${OpenMP_CXX_LIBRARIES}")
|
||||||
endif()
|
endif()
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
add_library(caffe2::openmp INTERFACE IMPORTED)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
target_link_libraries(caffe2::openmp INTERFACE OpenMP::OpenMP_CXX)
|
||||||
|
list(APPEND Caffe2_DEPENDENCY_LIBS caffe2::openmp)
|
||||||
|
if(MSVC AND OpenMP_CXX_LIBRARIES MATCHES ".*libiomp5md\\.lib.*")
|
||||||
|
target_compile_definitions(caffe2::openmp INTERFACE _OPENMP_NOFORCE_MANIFEST)
|
||||||
|
target_link_options(caffe2::openmp INTERFACE "/NODEFAULTLIB:vcomp")
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
message(WARNING "Not compiling with OpenMP. Suppress this warning with -DUSE_OPENMP=OFF")
|
message(WARNING "Not compiling with OpenMP. Suppress this warning with -DUSE_OPENMP=OFF")
|
||||||
caffe2_update_option(USE_OPENMP OFF)
|
caffe2_update_option(USE_OPENMP OFF)
|
||||||
@ -1256,6 +1199,7 @@ if(USE_OPENMP)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ---[ Android specific ones
|
# ---[ Android specific ones
|
||||||
if(ANDROID)
|
if(ANDROID)
|
||||||
list(APPEND Caffe2_DEPENDENCY_LIBS log)
|
list(APPEND Caffe2_DEPENDENCY_LIBS log)
|
||||||
@ -1979,7 +1923,7 @@ if(USE_KINETO)
|
|||||||
include(CheckCXXSourceRuns)
|
include(CheckCXXSourceRuns)
|
||||||
# rt is handled by the CMAKE_REQUIRED_LIBRARIES set above
|
# rt is handled by the CMAKE_REQUIRED_LIBRARIES set above
|
||||||
if(NOT APPLE)
|
if(NOT APPLE)
|
||||||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "dl")
|
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "dl" "pthread")
|
||||||
endif()
|
endif()
|
||||||
set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--whole-archive,${CUPTI_LIBRARY_PATH},--no-whole-archive")
|
set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--whole-archive,${CUPTI_LIBRARY_PATH},--no-whole-archive")
|
||||||
check_cxx_source_runs("#include <stdexcept>
|
check_cxx_source_runs("#include <stdexcept>
|
||||||
|
@ -41,6 +41,12 @@ IF (WIN32)
|
|||||||
ELSE (WIN32)
|
ELSE (WIN32)
|
||||||
SET(DEFAULT_INTEL_COMPILER_DIR "/opt/intel")
|
SET(DEFAULT_INTEL_COMPILER_DIR "/opt/intel")
|
||||||
SET(DEFAULT_INTEL_MKL_DIR "/opt/intel/mkl")
|
SET(DEFAULT_INTEL_MKL_DIR "/opt/intel/mkl")
|
||||||
|
if (EXISTS "/opt/intel/oneapi")
|
||||||
|
SET(DEFAULT_INTEL_COMPILER_DIR "/opt/intel/oneapi")
|
||||||
|
if (EXISTS "/opt/intel/oneapi/mkl/latest")
|
||||||
|
SET(DEFAULT_INTEL_MKL_DIR "/opt/intel/oneapi/mkl/latest")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
ENDIF (WIN32)
|
ENDIF (WIN32)
|
||||||
|
|
||||||
# Intel Compiler Suite
|
# Intel Compiler Suite
|
||||||
|
@ -249,11 +249,14 @@ function(_OPENMP_GET_FLAGS LANG FLAG_MODE OPENMP_FLAG_VAR OPENMP_LIB_NAMES_VAR)
|
|||||||
|
|
||||||
if(NOT "${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "GNU")
|
if(NOT "${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "GNU")
|
||||||
find_package(MKL QUIET)
|
find_package(MKL QUIET)
|
||||||
if(MKL_FOUND AND (NOT "${MKL_OPENMP_LIBRARY}" STREQUAL ""))
|
if(MKL_FOUND AND MKL_OPENMP_LIBRARY)
|
||||||
# If we already link OpenMP via MKL, use that. Otherwise at run-time
|
# If we already link OpenMP via MKL, use that. Otherwise at run-time
|
||||||
# OpenMP will complain about being initialized twice (OMP: Error #15),
|
# OpenMP will complain about being initialized twice (OMP: Error #15),
|
||||||
# can may cause incorrect behavior.
|
# can may cause incorrect behavior.
|
||||||
set(OpenMP_libomp_LIBRARY "${MKL_OPENMP_LIBRARY}" CACHE STRING "libomp location for OpenMP")
|
set(OpenMP_libomp_LIBRARY "${MKL_OPENMP_LIBRARY}" CACHE STRING "libomp location for OpenMP")
|
||||||
|
if("-fopenmp=libiomp5" IN_LIST OpenMP_${LANG}_FLAG_CANDIDATES)
|
||||||
|
set(OPENMP_FLAG "-fopenmp=libiomp5")
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
find_library(OpenMP_libomp_LIBRARY
|
find_library(OpenMP_libomp_LIBRARY
|
||||||
NAMES omp gomp iomp5
|
NAMES omp gomp iomp5
|
||||||
@ -271,7 +274,12 @@ function(_OPENMP_GET_FLAGS LANG FLAG_MODE OPENMP_FLAG_VAR OPENMP_LIB_NAMES_VAR)
|
|||||||
)
|
)
|
||||||
if(OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG})
|
if(OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG})
|
||||||
set("${OPENMP_FLAG_VAR}" "${OPENMP_FLAG}" PARENT_SCOPE)
|
set("${OPENMP_FLAG_VAR}" "${OPENMP_FLAG}" PARENT_SCOPE)
|
||||||
|
if(MKL_OPENMP_LIBRARY)
|
||||||
|
set(OpenMP_libiomp5_LIBRARY "${MKL_OPENMP_LIBRARY}" CACHE STRING "libomp location for OpenMP")
|
||||||
|
set("${OPENMP_LIB_NAMES_VAR}" "libiomp5" PARENT_SCOPE)
|
||||||
|
else()
|
||||||
set("${OPENMP_LIB_NAMES_VAR}" "libomp" PARENT_SCOPE)
|
set("${OPENMP_LIB_NAMES_VAR}" "libomp" PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
@ -461,17 +461,6 @@ if(MSVC)
|
|||||||
list(APPEND CUDA_NVCC_FLAGS "--no-host-device-move-forward")
|
list(APPEND CUDA_NVCC_FLAGS "--no-host-device-move-forward")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# OpenMP flags for NVCC with Clang-cl
|
|
||||||
if("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC"
|
|
||||||
AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
||||||
list(APPEND CUDA_PROPAGATE_HOST_FLAGS_BLOCKLIST "-Xclang" "-fopenmp")
|
|
||||||
if(MSVC_TOOLSET_VERSION LESS 142)
|
|
||||||
list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-openmp")
|
|
||||||
else()
|
|
||||||
list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-openmp:experimental")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Debug and Release symbol support
|
# Debug and Release symbol support
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
if(${CAFFE2_USE_MSVC_STATIC_RUNTIME})
|
if(${CAFFE2_USE_MSVC_STATIC_RUNTIME})
|
||||||
|
@ -512,26 +512,6 @@ function(torch_compile_options libname)
|
|||||||
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
# Set standard target properties.
|
|
||||||
# Usage:
|
|
||||||
# torch_set_target_props(lib_name)
|
|
||||||
function(torch_set_target_props libname)
|
|
||||||
if(MSVC AND AT_MKL_MT)
|
|
||||||
set(VCOMP_LIB "vcomp")
|
|
||||||
set_target_properties(${libname} PROPERTIES LINK_FLAGS_MINSIZEREL "/NODEFAULTLIB:${VCOMP_LIB}")
|
|
||||||
set_target_properties(${libname} PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/NODEFAULTLIB:${VCOMP_LIB}")
|
|
||||||
set_target_properties(${libname} PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB:${VCOMP_LIB}")
|
|
||||||
set_target_properties(${libname} PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB:${VCOMP_LIB}d")
|
|
||||||
set_target_properties(${libname} PROPERTIES STATIC_LIBRARY_FLAGS_MINSIZEREL "/NODEFAULTLIB:${VCOMP_LIB}")
|
|
||||||
set_target_properties(${libname} PROPERTIES STATIC_LIBRARY_FLAGS_RELWITHDEBINFO "/NODEFAULTLIB:${VCOMP_LIB}")
|
|
||||||
set_target_properties(${libname} PROPERTIES STATIC_LIBRARY_FLAGS_RELEASE "/NODEFAULTLIB:${VCOMP_LIB}")
|
|
||||||
set_target_properties(${libname} PROPERTIES STATIC_LIBRARY_FLAGS_DEBUG "/NODEFAULTLIB:${VCOMP_LIB}d")
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Set old-style FindCuda.cmake compile flags from modern CMake cuda flags.
|
# Set old-style FindCuda.cmake compile flags from modern CMake cuda flags.
|
||||||
# Usage:
|
# Usage:
|
||||||
|
@ -3,10 +3,6 @@ file(GLOB Detectron_GPU_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cu)
|
|||||||
file(GLOB_RECURSE Detectron_HIP_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.hip)
|
file(GLOB_RECURSE Detectron_HIP_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.hip)
|
||||||
|
|
||||||
if(BUILD_CAFFE2_OPS)
|
if(BUILD_CAFFE2_OPS)
|
||||||
if(USE_OPENMP AND OPENMP_FOUND)
|
|
||||||
Set(OpenMP_link ${OpenMP_CXX_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Note(ilijar): Since Detectron ops currently have no
|
# Note(ilijar): Since Detectron ops currently have no
|
||||||
# CPU implementation, we only build GPU ops for now.
|
# CPU implementation, we only build GPU ops for now.
|
||||||
if(USE_CUDA)
|
if(USE_CUDA)
|
||||||
@ -15,8 +11,11 @@ if(BUILD_CAFFE2_OPS)
|
|||||||
${Detectron_CPU_SRCS}
|
${Detectron_CPU_SRCS}
|
||||||
${Detectron_GPU_SRCS})
|
${Detectron_GPU_SRCS})
|
||||||
|
|
||||||
torch_set_target_props(caffe2_detectron_ops_gpu)
|
target_link_libraries(caffe2_detectron_ops_gpu PRIVATE torch)
|
||||||
target_link_libraries(caffe2_detectron_ops_gpu PRIVATE torch ${OpenMP_link})
|
if(USE_OPENMP)
|
||||||
|
target_link_libraries(caffe2_detectron_ops_gpu PRIVATE caffe2::openmp)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(USE_MKLDNN)
|
if(USE_MKLDNN)
|
||||||
target_link_libraries(caffe2_detectron_ops_gpu PRIVATE caffe2::mkldnn)
|
target_link_libraries(caffe2_detectron_ops_gpu PRIVATE caffe2::mkldnn)
|
||||||
endif()
|
endif()
|
||||||
@ -31,7 +30,6 @@ if(BUILD_CAFFE2_OPS)
|
|||||||
caffe2_detectron_ops_hip SHARED
|
caffe2_detectron_ops_hip SHARED
|
||||||
${Detectron_CPU_SRCS}
|
${Detectron_CPU_SRCS}
|
||||||
${Detectron_HIP_SRCS})
|
${Detectron_HIP_SRCS})
|
||||||
torch_set_target_props(caffe2_detectron_ops_hip)
|
|
||||||
target_compile_options(caffe2_detectron_ops_hip PRIVATE ${HIP_CXX_FLAGS})
|
target_compile_options(caffe2_detectron_ops_hip PRIVATE ${HIP_CXX_FLAGS})
|
||||||
if(USE_MKLDNN)
|
if(USE_MKLDNN)
|
||||||
target_link_libraries(caffe2_detectron_ops_hip PRIVATE caffe2::mkldnn)
|
target_link_libraries(caffe2_detectron_ops_hip PRIVATE caffe2::mkldnn)
|
||||||
@ -44,8 +42,10 @@ if(BUILD_CAFFE2_OPS)
|
|||||||
set_target_properties(caffe2_detectron_ops PROPERTIES
|
set_target_properties(caffe2_detectron_ops PROPERTIES
|
||||||
VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION})
|
VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION})
|
||||||
endif()
|
endif()
|
||||||
torch_set_target_props(caffe2_detectron_ops)
|
target_link_libraries(caffe2_detectron_ops PRIVATE torch)
|
||||||
target_link_libraries(caffe2_detectron_ops PRIVATE torch ${OpenMP_link})
|
if(USE_OPENMP)
|
||||||
|
target_link_libraries(caffe2_detectron_ops PRIVATE caffe2::openmp)
|
||||||
|
endif()
|
||||||
if(USE_MKLDNN)
|
if(USE_MKLDNN)
|
||||||
target_link_libraries(caffe2_detectron_ops PRIVATE caffe2::mkldnn)
|
target_link_libraries(caffe2_detectron_ops PRIVATE caffe2::mkldnn)
|
||||||
endif()
|
endif()
|
||||||
|
Reference in New Issue
Block a user