Whether MKLDNN should be built under native arch should respect USE_NATIVE_ARCH (#23445)

Summary:
Currently there is no way to build MKLDNN more optimized than sse4. This commit let MKLDNN build respect USE_NATIVE_ARCH.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/23445

Differential Revision: D16542275

Pulled By: ezyang

fbshipit-source-id: 550976531d6a52db9128c0e3d4589a33715feee2
This commit is contained in:
Hong Xu
2019-07-29 08:05:29 -07:00
committed by Facebook Github Bot
parent b335f3910f
commit 09ba4df031
2 changed files with 12 additions and 5 deletions

View File

@ -7,6 +7,10 @@
# MKLDNN_FOUND : set to true if mkl-dnn is found.
# MKLDNN_INCLUDE_DIR : path to mkl-dnn include dir.
# MKLDNN_LIBRARIES : list of libraries for mkl-dnn
#
# The following variables are used:
# MKLDNN_USE_NATIVE_ARCH : Whether native CPU instructions should be used in MKLDNN. This should be turned off for
# general packaging to avoid incompatible CPU instructions. Default: OFF.
IF (NOT MKLDNN_FOUND)
@ -118,11 +122,12 @@ ENDIF()
SET(WITH_TEST FALSE CACHE BOOL "" FORCE)
SET(WITH_EXAMPLE FALSE CACHE BOOL "" FORCE)
SET(MKLDNN_LIBRARY_TYPE STATIC CACHE STRING "" FORCE)
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# To avoid binary compatibility issue by disabling HostOpts in MKl-DNN
SET(ARCH_OPT_FLAGS "-msse4" CACHE STRING "" FORCE)
ELSE()
SET(ARCH_OPT_FLAGS "" CACHE STRING "" FORCE)
IF(NOT MKLDNN_USE_NATIVE_ARCH) # Disable HostOpts in MKL-DNN.
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
SET(ARCH_OPT_FLAGS "-msse4" CACHE STRING "" FORCE)
ELSE()
SET(ARCH_OPT_FLAGS "" CACHE STRING "" FORCE)
ENDIF()
ENDIF()
ADD_SUBDIRECTORY(${MKLDNN_ROOT})
IF(NOT TARGET mkldnn)