Skip to content

Commit 29fc94b

Browse files
committed
Merge branch 'develop' into l2_distance
2 parents 929efdc + 093c526 commit 29fc94b

File tree

156 files changed

+2760
-3706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+2760
-3706
lines changed

CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ include(simd)
3636
################################ Configurations #######################################
3737
option(WITH_GPU "Compile PaddlePaddle with NVIDIA GPU" ${CUDA_FOUND})
3838
option(WITH_AVX "Compile PaddlePaddle with AVX intrinsics" ${AVX_FOUND})
39-
option(WITH_MKLDNN "Compile PaddlePaddle with mkl-dnn support." ${AVX_FOUND})
40-
option(WITH_MKLML "Compile PaddlePaddle with mklml package." ${AVX_FOUND})
39+
option(WITH_MKL "Compile PaddlePaddle with MKL support." ${AVX_FOUND})
4140
option(WITH_DSO "Compile PaddlePaddle with dynamic linked CUDA" ON)
4241
option(WITH_TESTING "Compile PaddlePaddle with unit testing" ON)
4342
option(WITH_SWIG_PY "Compile PaddlePaddle with inference api" ON)
@@ -82,10 +81,8 @@ if(ANDROID OR IOS)
8281
"Disable PYTHON when cross-compiling for Android and iOS" FORCE)
8382
set(WITH_RDMA OFF CACHE STRING
8483
"Disable RDMA when cross-compiling for Android and iOS" FORCE)
85-
set(WITH_MKLDNN OFF CACHE STRING
86-
"Disable MKLDNN when cross-compiling for Android and iOS" FORCE)
87-
set(WITH_MKLML OFF CACHE STRING
88-
"Disable MKLML package when cross-compiling for Android and iOS" FORCE)
84+
set(WITH_MKL OFF CACHE STRING
85+
"Disable MKL when cross-compiling for Android and iOS" FORCE)
8986

9087
# Compile PaddlePaddle mobile inference library
9188
if (NOT WITH_C_API)
@@ -111,6 +108,17 @@ else()
111108
set(THIRD_PARTY_BUILD_TYPE Release)
112109
endif()
113110

111+
if(WITH_MKL)
112+
set(WITH_MKLML ON)
113+
set(WITH_MKLDNN ${AVX2_FOUND})
114+
if(NOT WITH_MKLDNN)
115+
message(WARNING "Do not have AVX2 intrinsics and disabled MKL-DNN")
116+
endif()
117+
else()
118+
set(WITH_MKLML OFF)
119+
set(WITH_MKLDNN OFF)
120+
endif()
121+
114122
########################################################################################
115123

116124
include(external/mklml) # download mklml package
@@ -164,8 +172,12 @@ if(WITH_GPU)
164172
endif(NOT WITH_DSO)
165173
endif(WITH_GPU)
166174

175+
if(WITH_MKLML)
176+
list(APPEND EXTERNAL_LIBS ${MKLML_IOMP_LIB})
177+
endif()
178+
167179
if(WITH_MKLDNN)
168-
list(APPEND EXTERNAL_LIBS ${MKLDNN_LIB} ${MKLDNN_IOMP_LIB})
180+
list(APPEND EXTERNAL_LIBS ${MKLDNN_LIB})
169181
endif()
170182

171183
if(USE_NNPACK)

benchmark/paddle/image/run_mkldnn.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
set -e
22

33
function train() {
4-
unset OMP_NUM_THREADS MKL_NUM_THREADS
5-
export OMP_DYNAMIC="FALSE"
6-
export KMP_AFFINITY="granularity=fine,compact,0,0"
4+
unset OMP_NUM_THREADS MKL_NUM_THREADS OMP_DYNAMIC KMP_AFFINITY
75
topology=$1
86
layer_num=$2
97
bs=$3
@@ -14,8 +12,6 @@ function train() {
1412
elif [ $4 == "False" ]; then
1513
thread=`nproc`
1614
# each trainer_count use only 1 core to avoid conflict
17-
export OMP_NUM_THREADS=1
18-
export MKL_NUM_THREADS=1
1915
log="logs/${topology}-${layer_num}-${thread}mklml-${bs}.log"
2016
else
2117
echo "Wrong input $3, use True or False."

cmake/configure.cmake

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,14 @@ else()
7676
include_directories(${CUDA_TOOLKIT_INCLUDE})
7777
endif(NOT WITH_GPU)
7878

79-
if(WITH_MKLDNN)
80-
add_definitions(-DPADDLE_USE_MKLDNN)
81-
if (WITH_MKLML AND MKLDNN_IOMP_DIR)
82-
message(STATUS "Enable Intel OpenMP at ${MKLDNN_IOMP_DIR}")
83-
set(OPENMP_FLAGS "-fopenmp")
84-
set(CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS ${OPENMP_FLAGS})
85-
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS ${OPENMP_FLAGS})
86-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENMP_FLAGS}")
87-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENMP_FLAGS}")
88-
else()
89-
find_package(OpenMP)
90-
if(OPENMP_FOUND)
91-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
92-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
93-
else()
94-
message(WARNING "Can not find OpenMP."
95-
"Some performance features in MKLDNN may not be available")
96-
endif()
97-
endif()
98-
99-
endif(WITH_MKLDNN)
79+
if (WITH_MKLML AND MKLML_IOMP_LIB)
80+
message(STATUS "Enable Intel OpenMP with ${MKLML_IOMP_LIB}")
81+
set(OPENMP_FLAGS "-fopenmp")
82+
set(CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS ${OPENMP_FLAGS})
83+
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS ${OPENMP_FLAGS})
84+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENMP_FLAGS}")
85+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENMP_FLAGS}")
86+
endif()
10087

10188
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SIMD_FLAG}")
10289
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_FLAG}")

cmake/cross_compiling/ios.cmake

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ set(IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
7676
# Set the architecture for iOS
7777
if(NOT DEFINED IOS_ARCH)
7878
if(IOS_PLATFORM STREQUAL "OS")
79-
# FIXME(liuyiqun): support "armv7;armv7s;arm64" future
80-
set(IOS_ARCH "arm64")
79+
set(IOS_ARCH "armv7;armv7s;arm64")
8180
elseif(IOS_PLATFORM STREQUAL "SIMULATOR")
82-
# FIXME(liuyiqun): support "i386;x86_64" future
83-
set(IOS_ARCH "x86_64")
81+
set(IOS_ARCH "i386;x86_64")
8482
endif()
8583
endif()
8684
set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
@@ -248,7 +246,7 @@ set(IOS_COMPILER_FLAGS "${XCODE_IOS_PLATFORM_VERSION_FLAGS} ${XCODE_IOS_BITCODE_
248246

249247
# Hidden visibilty is required for cxx on iOS
250248
set(CMAKE_C_FLAGS "${IOS_COMPILER_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING "C flags")
251-
set(CMAKE_CXX_FLAGS "${IOS_COMPILER_FLAGS} -fvisibility-inlines-hidden ${CMAKE_CXX_FLAGS}" CACHE STRING "CXX flags")
249+
set(CMAKE_CXX_FLAGS "${IOS_COMPILER_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden ${CMAKE_CXX_FLAGS}" CACHE STRING "CXX flags")
252250

253251
set(IOS_LINK_FLAGS "${XCODE_IOS_PLATFORM_VERSION_FLAGS} -Wl,-search_paths_first")
254252

cmake/external/mkldnn.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ INCLUDE_DIRECTORIES(${MKLDNN_INC_DIR})
4040

4141
IF(${CBLAS_PROVIDER} STREQUAL "MKLML")
4242
SET(MKLDNN_DEPENDS ${MKLML_PROJECT})
43-
SET(MKLDNN_MKLROOT ${MKLML_ROOT})
44-
SET(MKLDNN_IOMP_LIB ${MKLML_IOMP_LIB})
45-
SET(MKLDNN_IOMP_DIR ${MKLML_LIB_DIR})
46-
MESSAGE(STATUS "Build MKLDNN with ${MKLDNN_MKLROOT}")
43+
MESSAGE(STATUS "Build MKLDNN with MKLML ${MKLML_ROOT}")
44+
ELSE()
45+
MESSAGE(FATAL_ERROR "Should enable MKLML when build MKLDNN")
4746
ENDIF()
4847

4948
SET(MKLDNN_CFLAG "${CMAKE_C_FLAGS} -Wno-error=strict-overflow")
@@ -57,15 +56,16 @@ ExternalProject_Add(
5756
PREFIX ${MKLDNN_SOURCES_DIR}
5857
UPDATE_COMMAND ""
5958
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${MKLDNN_INSTALL_DIR}
60-
CMAKE_ARGS -DMKLROOT=${MKLDNN_MKLROOT}
59+
CMAKE_ARGS -DMKLROOT=${MKLML_ROOT}
6160
CMAKE_ARGS -DCMAKE_C_FLAGS=${MKLDNN_CFLAG}
6261
CMAKE_ARGS -DCMAKE_CXX_FLAGS=${MKLDNN_CXXFLAG}
6362
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MKLDNN_INSTALL_DIR}
64-
-DMKLROOT:PATH=${MKLDNN_MKLROOT}
63+
-DMKLROOT:PATH=${MKLML_ROOT}
6564
)
6665

6766
ADD_LIBRARY(mkldnn SHARED IMPORTED GLOBAL)
6867
SET_PROPERTY(TARGET mkldnn PROPERTY IMPORTED_LOCATION ${MKLDNN_LIB})
6968
ADD_DEPENDENCIES(mkldnn ${MKLDNN_PROJECT})
70-
MESSAGE(STATUS "Mkldnn library: ${MKLDNN_LIB}")
69+
MESSAGE(STATUS "MKLDNN library: ${MKLDNN_LIB}")
70+
add_definitions(-DPADDLE_USE_MKLDNN)
7171
LIST(APPEND external_project_dependencies mkldnn)

cmake/external/openblas.cmake

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ IF(NOT ${CBLAS_FOUND})
2929
"${CBLAS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}openblas${CMAKE_STATIC_LIBRARY_SUFFIX}"
3030
CACHE FILEPATH "openblas library." FORCE)
3131

32-
SET(OPENBLAS_CC "${CMAKE_C_COMPILER}")
32+
SET(OPENBLAS_CC "${CMAKE_C_COMPILER} -Wno-unused-but-set-variable -Wno-unused-variable")
3333

3434
IF(CMAKE_CROSSCOMPILING)
3535
SET(OPTIONAL_ARGS HOSTCC=${HOST_C_COMPILER})
@@ -45,15 +45,14 @@ IF(NOT ${CBLAS_FOUND})
4545
SET(OPTIONAL_ARGS ${OPTIONAL_ARGS} TARGET=ARMV8 BINARY=64 USE_THREAD=0)
4646
ENDIF()
4747
ELSEIF(IOS)
48-
# FIXME(liuyiqun): support multiple architectures
49-
SET(OPENBLAS_COMMIT "b5c96fcfcdc82945502a2303116a64d89985daf5")
50-
SET(OPENBLAS_CC "${OPENBLAS_CC} ${CMAKE_C_FLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
51-
IF(CMAKE_OSX_ARCHITECTURES MATCHES "armv7")
52-
SET(OPENBLAS_CC "${OPENBLAS_CC} -arch armv7")
53-
SET(OPTIONAL_ARGS ${OPTIONAL_ARGS} TARGET=ARMV7 ARM_SOFTFP_ABI=1 USE_THREAD=0)
54-
ELSEIF(CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
48+
IF(CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
49+
SET(OPENBLAS_COMMIT "b5c96fcfcdc82945502a2303116a64d89985daf5")
50+
SET(OPENBLAS_CC "${OPENBLAS_CC} ${CMAKE_C_FLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
5551
SET(OPENBLAS_CC "${OPENBLAS_CC} -arch arm64")
5652
SET(OPTIONAL_ARGS ${OPTIONAL_ARGS} TARGET=ARMV8 BINARY=64 USE_THREAD=0 CROSS_SUFFIX=${CROSS_SUFFIX})
53+
ELSE()
54+
MESSAGE(FATAL_ERROR "OpenBLAS only support arm64 architectures on iOS. "
55+
"You can set IOS_USE_VECLIB_FOR_BLAS=ON or USE_EIGEN_FOR_BLAS=ON to use other blas library instead.")
5756
ENDIF()
5857
ELSEIF(RPI)
5958
# use hardfp

cmake/external/warpctc.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
IF(MOBILE_INFERENCE)
16+
return()
17+
ENDIF()
18+
1519
INCLUDE(ExternalProject)
1620

1721
SET(WARPCTC_SOURCES_DIR ${THIRD_PARTY_PATH}/warpctc)

cmake/util.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ function(link_paddle_exe TARGET_NAME)
115115
target_link_libraries(${TARGET_NAME} log)
116116
endif(ANDROID)
117117

118-
if(WITH_MKLDNN AND WITH_MKLML AND MKLDNN_IOMP_DIR)
119-
target_link_libraries(${TARGET_NAME} "-L${MKLDNN_IOMP_DIR} -liomp5 -Wl,--as-needed")
118+
if(WITH_MKLML AND MKLML_LIB_DIR AND MKLML_IOMP_LIB)
119+
target_link_libraries(${TARGET_NAME} "-L${MKLML_LIB_DIR} -liomp5 -Wl,--as-needed")
120120
endif()
121121

122122
add_dependencies(${TARGET_NAME} ${external_project_dependencies})

doc/api/v2/config/layer.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ bilinear_interp
335335
.. autoclass:: paddle.v2.layer.bilinear_interp
336336
:noindex:
337337

338+
dot_prod
339+
---------
340+
.. autoclass:: paddle.v2.layer.dot_prod
341+
:noindex:
342+
343+
out_prod
344+
--------
345+
.. autoclass:: paddle.v2.layer.out_prod
346+
:noindex:
347+
338348
power
339349
-----
340350
.. autoclass:: paddle.v2.layer.power

doc/design/mkldnn/README.MD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ Figure 1. PaddlePaddle on IA.
3636
我们把集成方案大致分为了如下几个方面。
3737

3838
### CMake
39-
我们会在`CMakeLists.txt`中会添加`WITH_MKLDNN`的选项,当设置这个值为`ON`的时候会启用编译MKL-DNN功能。同时会自动开启OpenMP用于提高MKL-DNN的性能
39+
我们会在`CMakeLists.txt`中会给用户添加一个`WITH_MKL`的开关,他是负责`WITH_MKLML``WITH_MKLDNN`的总开关
4040

41-
同时,我们会引入`WITH_MKLML`选项,用于选择是否使用MKL-DNN自带的MKLML安装包。这个安装包可以独立于MKL-DNN使用,但是建议在开启MKL-DNN的同时也打开MKLML的开关,这样才能发挥最好的性能
41+
当打开`WITH_MKL`时,会开启MKLML的功能,作为PaddlePaddle的CBLAS和LAPACK库,同时会开启Intel OpenMP用于提高MKLML的性能。 如果系统支持AVX2指令集及以上,同时会开启MKL-DNN功能
4242

43-
所以,我们会在`cmake/external`目录新建`mkldnn.cmake``mklml.cmake`文件,它们会在编译PaddlePaddle的时候下载对应的软件包,并放到PaddlePaddle的third party目录中
43+
当关闭`WITH_MKL`时,MKLML和MKL-DNN功能会同时关闭
4444

45-
**备注**:当`WITH_MKLML=ON`的时候,会优先使用这个包作为PaddlePaddle的CBLAS和LAPACK库,所以会稍微改动`cmake/cblas.cmake`中的逻辑
45+
所以,我们会在`cmake/external`目录新建`mkldnn.cmake``mklml.cmake`文件,它们会在编译PaddlePaddle的时候下载对应的软件包,并放到PaddlePaddle的third party目录中
4646

4747
### Layers
4848
所有MKL-DNN相关的C++ layers,都会按照PaddlePaddle的目录结构存放在

0 commit comments

Comments
 (0)