Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[mkldnn-v1.0] Initiate the transition to MKL-DNN v1.0 #15706

Merged
merged 12 commits into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 3rdparty/mkldnn
20 changes: 8 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ mxnet_option(USE_SSE "Build with x86 SSE instruction support" ON IF
mxnet_option(USE_F16C "Build with x86 F16C instruction support" ON) # autodetects support if ON
mxnet_option(USE_LAPACK "Build with lapack support" ON)
mxnet_option(USE_MKL_IF_AVAILABLE "Use MKL if found" ON)
mxnet_option(USE_MKLML_MKL "Use MKLDNN variant of MKL (if MKL found)" ON IF USE_MKL_IF_AVAILABLE AND (NOT APPLE) AND (NOT MSVC) )
mxnet_option(USE_MKLDNN "Use MKLDNN variant of MKL (if MKL found)" ON IF USE_MKL_IF_AVAILABLE AND (NOT APPLE) AND (NOT MSVC) AND (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") AND (NOT CMAKE_CROSSCOMPILING))
mxnet_option(USE_MKLDNN "Build with MKL-DNN support" ON IF USE_MKL_IF_AVAILABLE AND (NOT APPLE) AND (NOT MSVC) AND (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") AND (NOT CMAKE_CROSSCOMPILING))
mxnet_option(USE_OPERATOR_TUNING "Enable auto-tuning of operators" ON IF NOT MSVC)
mxnet_option(USE_GPERFTOOLS "Build with GPerfTools support" OFF)
mxnet_option(USE_JEMALLOC "Build with Jemalloc support" ON)
Expand Down Expand Up @@ -247,26 +246,23 @@ if(ENABLE_TESTCOVERAGE)
endif()

if(USE_MKLDNN)
include(cmake/DownloadMKLML.cmake)
# CPU architecture (e.g., C5) can't run on another architecture (e.g., g3).
if(NOT MSVC)
set(ARCH_OPT_FLAGS "-mtune=generic")
else()
if(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /EHsc")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /EHsc /Gy")
endif()

set(WITH_TEST OFF CACHE INTERNAL "" FORCE)
set(WITH_EXAMPLE OFF CACHE INTERNAL "" FORCE)
set(ARCH_OPT_FLAGS "" CACHE INTERNAL "" FORCE)
set(MKLDNN_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
set(MKLDNN_BUILD_EXAMPLES OFF CACHE INTERNAL "" FORCE)
set(MKLDNN_ARCH_OPT_FLAGS "" CACHE INTERNAL "" FORCE)
set(MKLDNN_USE_MKL NONE CACHE INTERNAL "" FORCE)
set(MKLDNN_ENABLE_JIT_PROFILING OFF CACHE INTERNAL "" FORCE)

add_subdirectory(3rdparty/mkldnn)

include_directories(3rdparty/mkldnn/include)
include_directories(${PROJECT_BINARY_DIR}/3rdparty/mkldnn/include)
add_definitions(-DUSE_MKL=1)
add_definitions(-DCUB_MKL=1)
add_definitions(-DMXNET_USE_MKLDNN=1)
add_definitions(-DMXNET_USE_MKLDNN=100)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elabroate where the 100 comes from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simply take it as v1.0.0 of MKL-DNN. But actually this PR upgrades MKL-DNN dependency to the 1.0.1 patch release.
Anyway, by changing this, I want to skip the compilation of those code wrapped with #if MXNET_USE_MKLDNN == 1 in the current code base as they are not compatible with the new MKL-DNN. Once a piece of the code (eg. the implementation of an operator) is changed to MKL-DNN 1.0 compatible, the PR author can change the check to #if MXNET_USE_MKLDNN == 100 to make the new code can compile and link with the new MKL-DNN. That will happen incrementally.
Hope I make it clear for you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After all the integration is done, if we feel not comfortable with this MXNET_USE_MKLDNN=100, we can change it back to MXNET_USE_MKLDNN=1 by search and replace.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit unintuitive it you're asking me. Especially because the term "USE" sounds like a Boolean flag. But what you're actually looking for here is a version check, right?

Do you have a timeline until everything has been migrated and what's the plan here exactly? It seems like his PR leaves the master branch in a kinda unusable state. So may I propose to instead have a separate branch to which you make all the changes and then merge that to master once everything has been migrated to 1.0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nevermind, this is already a separate branch. It didn't show that on mobile, sorry. Go ahead :)

list(APPEND mxnet_LINKER_LIBS mkldnn)
endif()

Expand Down
21 changes: 5 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ endif

ifeq ($(USE_MKLDNN), 1)
MKLDNNROOT = $(ROOTDIR)/3rdparty/mkldnn/build/install
MKLROOT = $(ROOTDIR)/3rdparty/mkldnn/build/install
export USE_MKLML = 1
endif

include $(TPARTYDIR)/mshadow/make/mshadow.mk
Expand Down Expand Up @@ -146,15 +144,10 @@ ifndef LINT_LANG
endif

ifeq ($(USE_MKLDNN), 1)
CFLAGS += -DMXNET_USE_MKLDNN=1
CFLAGS += -DUSE_MKL=1
CFLAGS += -DMXNET_USE_MKLDNN=100
CFLAGS += -I$(ROOTDIR)/src/operator/nn/mkldnn/
ifneq ($(MKLDNNROOT), $(MKLROOT))
CFLAGS += -I$(MKLROOT)/include
LDFLAGS += -L$(MKLROOT)/lib
endif
CFLAGS += -I$(MKLDNNROOT)/include
LDFLAGS += -L$(MKLDNNROOT)/lib -lmkldnn -Wl,-rpath,'$${ORIGIN}'
LDFLAGS += -L$(MKLDNNROOT)/lib -L$(MKLDNNROOT)/lib64 -lmkldnn -Wl,-rpath,'$${ORIGIN}'
endif

# setup opencv
Expand Down Expand Up @@ -581,9 +574,7 @@ lib/libmxnet.so: $(ALLX_DEP)
-Wl,${WHOLE_ARCH} $(filter %libnnvm.a, $^) -Wl,${NO_WHOLE_ARCH}
ifeq ($(USE_MKLDNN), 1)
ifeq ($(UNAME_S), Darwin)
install_name_tool -change '@rpath/libmklml.dylib' '@loader_path/libmklml.dylib' $@
install_name_tool -change '@rpath/libiomp5.dylib' '@loader_path/libiomp5.dylib' $@
install_name_tool -change '@rpath/libmkldnn.0.dylib' '@loader_path/libmkldnn.0.dylib' $@
install_name_tool -change '@rpath/libmkldnn.1.dylib' '@loader_path/libmkldnn.1.dylib' $@
endif
endif

Expand Down Expand Up @@ -691,10 +682,8 @@ rpkg:
cp src/io/image_recordio.h R-package/src
cp -rf lib/libmxnet.so R-package/inst/libs

if [ -e "lib/libmkldnn.so.0" ]; then \
cp -rf lib/libmkldnn.so.0 R-package/inst/libs; \
cp -rf lib/libiomp5.so R-package/inst/libs; \
cp -rf lib/libmklml_intel.so R-package/inst/libs; \
if [ -e "lib/libmkldnn.so.1" ]; then \
cp -rf lib/libmkldnn.so.1 R-package/inst/libs; \
fi

mkdir -p R-package/inst/include
Expand Down
2 changes: 0 additions & 2 deletions ci/docker/Dockerfile.build.centos7_cpu
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ COPY install/centos7_python.sh /work/
RUN /work/centos7_python.sh
COPY install/centos7_scala.sh /work/
RUN /work/centos7_scala.sh
COPY install/ubuntu_mklml.sh /work/
RUN /work/ubuntu_mklml.sh

ARG USER_ID=0
COPY install/centos7_adduser.sh /work/
Expand Down
2 changes: 0 additions & 2 deletions ci/docker/Dockerfile.build.ubuntu_build_cuda
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ COPY install/ubuntu_perl.sh /work/
RUN /work/ubuntu_perl.sh
COPY install/ubuntu_clang.sh /work/
RUN /work/ubuntu_clang.sh
COPY install/ubuntu_mklml.sh /work/
RUN /work/ubuntu_mklml.sh
COPY install/ubuntu_ar.sh /work/
RUN /work/ubuntu_ar.sh

Expand Down
3 changes: 0 additions & 3 deletions ci/docker/Dockerfile.build.ubuntu_cpu
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ RUN /work/ubuntu_gcc8.sh
COPY install/ubuntu_mkl.sh /work/
RUN /work/ubuntu_mkl.sh

COPY install/ubuntu_mklml.sh /work/
RUN /work/ubuntu_mklml.sh

COPY install/ubuntu_caffe.sh /work/
RUN /work/ubuntu_caffe.sh

Expand Down
3 changes: 0 additions & 3 deletions ci/docker/Dockerfile.build.ubuntu_gpu_cu100
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ RUN /work/ubuntu_perl.sh
COPY install/ubuntu_clang.sh /work/
RUN /work/ubuntu_clang.sh

COPY install/ubuntu_mklml.sh /work/
RUN /work/ubuntu_mklml.sh

COPY install/ubuntu_tvm.sh /work/
RUN /work/ubuntu_tvm.sh

Expand Down
3 changes: 0 additions & 3 deletions ci/docker/Dockerfile.build.ubuntu_gpu_cu101
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ RUN /work/ubuntu_perl.sh
COPY install/ubuntu_clang.sh /work/
RUN /work/ubuntu_clang.sh

COPY install/ubuntu_mklml.sh /work/
RUN /work/ubuntu_mklml.sh

COPY install/ubuntu_tvm.sh /work/
RUN /work/ubuntu_tvm.sh

Expand Down
3 changes: 0 additions & 3 deletions ci/docker/Dockerfile.build.ubuntu_gpu_cu80
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ RUN /work/ubuntu_perl.sh
COPY install/ubuntu_clang.sh /work/
RUN /work/ubuntu_clang.sh

COPY install/ubuntu_mklml.sh /work/
RUN /work/ubuntu_mklml.sh

COPY install/ubuntu_tvm.sh /work/
RUN /work/ubuntu_tvm.sh

Expand Down
3 changes: 0 additions & 3 deletions ci/docker/Dockerfile.build.ubuntu_gpu_cu90
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ RUN /work/ubuntu_perl.sh
COPY install/ubuntu_clang.sh /work/
RUN /work/ubuntu_clang.sh

COPY install/ubuntu_mklml.sh /work/
RUN /work/ubuntu_mklml.sh

COPY install/ubuntu_tvm.sh /work/
RUN /work/ubuntu_tvm.sh

Expand Down
3 changes: 0 additions & 3 deletions ci/docker/Dockerfile.build.ubuntu_gpu_cu92
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ RUN /work/ubuntu_perl.sh
COPY install/ubuntu_clang.sh /work/
RUN /work/ubuntu_clang.sh

COPY install/ubuntu_mklml.sh /work/
RUN /work/ubuntu_mklml.sh

COPY install/ubuntu_tvm.sh /work/
RUN /work/ubuntu_tvm.sh

Expand Down
3 changes: 0 additions & 3 deletions ci/docker/Dockerfile.build.ubuntu_nightly_cpu
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ RUN /work/ubuntu_perl.sh
COPY install/ubuntu_clang.sh /work/
RUN /work/ubuntu_clang.sh

COPY install/ubuntu_mklml.sh /work/
RUN /work/ubuntu_mklml.sh

COPY install/ubuntu_caffe.sh /work/
RUN /work/ubuntu_caffe.sh

Expand Down
3 changes: 0 additions & 3 deletions ci/docker/Dockerfile.build.ubuntu_nightly_gpu
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ RUN /work/ubuntu_perl.sh
COPY install/ubuntu_clang.sh /work/
RUN /work/ubuntu_clang.sh

COPY install/ubuntu_mklml.sh /work/
RUN /work/ubuntu_mklml.sh

COPY install/ubuntu_tvm.sh /work/
RUN /work/ubuntu_tvm.sh

Expand Down
2 changes: 1 addition & 1 deletion ci/docker/install/ubuntu_mkl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ apt-get update || true
wget -qO - wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB | apt-key add - && \
sh -c 'echo deb https://apt.repos.intel.com/mkl all main > /etc/apt/sources.list.d/intel-mkl.list' && \
apt-get update && \
apt-get install -y intel-mkl-2019.1-053
apt-get install -y intel-mkl-2019.4-070
25 changes: 0 additions & 25 deletions ci/docker/install/ubuntu_mklml.sh

This file was deleted.

7 changes: 4 additions & 3 deletions ci/docker/runtime_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ build_ubuntu_cpu_mkldnn_mkl() {
USE_CPP_PACKAGE=1 \
USE_BLAS=mkl \
USE_SIGNAL_HANDLER=1 \
USE_INTEL_PATH=/opt/intel/ \
-j$(nproc)
}

Expand Down Expand Up @@ -741,9 +742,9 @@ build_ubuntu_gpu_cmake_mkldnn() {
/work/mxnet

ninja -v
# libmkldnn.so.0 is a link file. We need an actual binary file named libmkldnn.so.0.
cp 3rdparty/mkldnn/src/libmkldnn.so.0 3rdparty/mkldnn/src/libmkldnn.so.0.tmp
mv 3rdparty/mkldnn/src/libmkldnn.so.0.tmp 3rdparty/mkldnn/src/libmkldnn.so.0
# libmkldnn.so.1 is a link file. We need an actual binary file named libmkldnn.so.1.
cp 3rdparty/mkldnn/src/libmkldnn.so.1 3rdparty/mkldnn/src/libmkldnn.so.1.tmp
mv 3rdparty/mkldnn/src/libmkldnn.so.1.tmp 3rdparty/mkldnn/src/libmkldnn.so.1
}

build_ubuntu_gpu_cmake() {
Expand Down
4 changes: 2 additions & 2 deletions ci/jenkins/Jenkins_steps.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ mx_cmake_lib = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/li
mx_cmake_lib_cython = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, build/3rdparty/openmp/runtime/src/libomp.so, python/mxnet/_cy2/*.so, python/mxnet/_cy3/*.so'
// mxnet cmake libraries, in cmake builds we do not produce a libnvvm static library by default.
mx_cmake_lib_debug = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests'
mx_cmake_mkldnn_lib = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, build/3rdparty/openmp/runtime/src/libomp.so, build/3rdparty/mkldnn/src/libmkldnn.so.0'
mx_mkldnn_lib = 'lib/libmxnet.so, lib/libmxnet.a, lib/libiomp5.so, lib/libmkldnn.so.0, lib/libmklml_intel.so, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a'
mx_cmake_mkldnn_lib = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, build/3rdparty/openmp/runtime/src/libomp.so, build/3rdparty/mkldnn/src/libmkldnn.so.1'
mx_mkldnn_lib = 'lib/libmxnet.so, lib/libmxnet.a, lib/libmkldnn.so.1, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a'
mx_tensorrt_lib = 'build/libmxnet.so, lib/libnvonnxparser_runtime.so.0, lib/libnvonnxparser.so.0, lib/libonnx_proto.so, lib/libonnx.so'
mx_lib_cpp_examples = 'lib/libmxnet.so, lib/libmxnet.a, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a, 3rdparty/ps-lite/build/libps.a, deps/lib/libprotobuf-lite.a, deps/lib/libzmq.a, build/cpp-package/example/*, python/mxnet/_cy2/*.so, python/mxnet/_cy3/*.so'
mx_lib_cpp_examples_cpu = 'build/libmxnet.so, build/cpp-package/example/*'
Expand Down
78 changes: 0 additions & 78 deletions cmake/DownloadMKLML.cmake

This file was deleted.

25 changes: 10 additions & 15 deletions mkldnn.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ ifeq ($(USE_MKLDNN), 1)
MXNET_LIBDIR = $(ROOTDIR)/lib
MXNET_INCLDIR = $(ROOTDIR)/include
ifeq ($(UNAME_S), Darwin)
OMP_LIBFILE = $(MKLDNNROOT)/lib/libiomp5.dylib
MKLML_LIBFILE = $(MKLDNNROOT)/lib/libmklml.dylib
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.0.dylib
MKLDNN_LIB64FILE = $(MKLDNNROOT)/lib64/libmkldnn.0.dylib
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.1.dylib
MKLDNN_LIB64FILE = $(MKLDNNROOT)/lib64/libmkldnn.1.dylib
else
OMP_LIBFILE = $(MKLDNNROOT)/lib/libiomp5.so
MKLML_LIBFILE = $(MKLDNNROOT)/lib/libmklml_intel.so
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.so.0
MKLDNN_LIB64FILE = $(MKLDNNROOT)/lib64/libmkldnn.so.0
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.so.1
MKLDNN_LIB64FILE = $(MKLDNNROOT)/lib64/libmkldnn.so.1
endif
endif

Expand All @@ -39,18 +35,17 @@ mkldnn_build: $(MKLDNN_LIBFILE)

$(MKLDNN_LIBFILE):
mkdir -p $(MKLDNNROOT)
cd $(MKLDNN_SUBMODDIR) && rm -rf external && cd scripts && ./prepare_mkl.sh && cd .. && cp -a external/*/* $(MKLDNNROOT)/.
cmake $(MKLDNN_SUBMODDIR) -DCMAKE_INSTALL_PREFIX=$(MKLDNNROOT) -B$(MKLDNN_BUILDDIR) -DARCH_OPT_FLAGS="-mtune=generic" -DWITH_TEST=OFF -DWITH_EXAMPLE=OFF
cmake $(MKLDNN_SUBMODDIR) -DCMAKE_INSTALL_PREFIX=$(MKLDNNROOT) -B$(MKLDNN_BUILDDIR) -DMKLDNN_ARCH_OPT_FLAGS="" -DMKLDNN_BUILD_TESTS=OFF -DMKLDNN_BUILD_EXAMPLES=OFF -DMKLDNN_ENABLE_JIT_PROFILING=OFF -DMKLDNN_USE_MKL=NONE
$(MAKE) -C $(MKLDNN_BUILDDIR) VERBOSE=1
$(MAKE) -C $(MKLDNN_BUILDDIR) install
mkdir -p $(MXNET_LIBDIR)
if [ -f "$(MKLDNN_LIB64FILE)" ]; then \
mv $(MKLDNNROOT)/lib64/libmkldnn* $(MKLDNNROOT)/lib/; \
cp $(MKLDNNROOT)/lib64/libmkldnn* $(MXNET_LIBDIR); \
else \
cp $(MKLDNNROOT)/lib/libmkldnn* $(MXNET_LIBDIR); \
fi
mkdir -p $(MXNET_LIBDIR)
cp $(OMP_LIBFILE) $(MXNET_LIBDIR)
cp $(MKLML_LIBFILE) $(MXNET_LIBDIR)
cp $(MKLDNN_LIBFILE) $(MXNET_LIBDIR)
cp $(MKLDNN_BUILDDIR)/include/mkldnn_version.h $(MXNET_INCLDIR)/mkldnn/.

mkldnn_clean:
$(RM) -r 3rdparty/mkldnn/build
$(RM) -r $(MKLDNNROOT)
Expand Down
8 changes: 2 additions & 6 deletions scala-package/assembly/src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@
<include>libmxnet.so</include>
<include>libgfortran.so.3</include>
<include>libquadmath.so.0</include>
<include>libiomp5.so</include>
<include>libiomp5.dylib</include>
<include>libmklml_intel.so</include>
<include>libmklml.dylib</include>
<include>libmkldnn.so.0</include>
<include>libmkldnn.0.dylib</include>
<include>libmkldnn.so.1</include>
<include>libmkldnn.1.dylib</include>
</includes>
<outputDirectory>lib/native</outputDirectory>
</fileSet>
Expand Down
Loading