Skip to content

Commit

Permalink
Revert "Refactor operators & MKLDNN (apache#8302)"
Browse files Browse the repository at this point in the history
This reverts commit 2cc2aa2.
  • Loading branch information
cjolivier01 committed Feb 1, 2018
1 parent 2cc2aa2 commit 6802961
Show file tree
Hide file tree
Showing 117 changed files with 8,234 additions and 9,732 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,3 @@
[submodule "3rdparty/googletest"]
path = 3rdparty/googletest
url = https://github.com/google/googletest.git
[submodule "3rdparty/mkldnn"]
path = 3rdparty/mkldnn
url = https://github.com/intel/mkl-dnn.git
branch = master
1 change: 0 additions & 1 deletion 3rdparty/mkldnn
Submodule mkldnn deleted from 3e1f8f
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ mxnet_option(USE_OPENMP "Build with Openmp support" ON)
mxnet_option(USE_CUDNN "Build with cudnn support" ON) # one could set CUDNN_ROOT for search path
mxnet_option(USE_LAPACK "Build with lapack support" ON IF NOT MSVC)
mxnet_option(USE_MKL_IF_AVAILABLE "Use MKL if found" ON)
mxnet_option(USE_MKLDNN "Use MKLDNN variant of MKL (if MKL found)" ON IF USE_MKL_IF_AVAILABLE AND UNIX AND (NOT APPLE))
mxnet_option(USE_MKLML_MKL "Use MKLDNN variant of MKL (if MKL found)" ON IF USE_MKL_IF_AVAILABLE AND UNIX AND (NOT APPLE))
mxnet_option(USE_MKLML_MKL "Use MKLML variant of MKL (if MKL found)" ON IF USE_MKL_IF_AVAILABLE AND UNIX AND (NOT APPLE))
mxnet_option(USE_MKL_EXPERIMENTAL "Use experimental MKL (if MKL enabled and found)" OFF)
mxnet_option(USE_OPERATOR_TUNING "Enable auto-tuning of operators" ON AND NOT MSVC)
mxnet_option(USE_GPERFTOOLS "Build with GPerfTools support (if found)" ON)
mxnet_option(USE_JEMALLOC "Build with Jemalloc support" ON)
Expand Down Expand Up @@ -138,11 +138,14 @@ if(USE_VTUNE)
endif()

if(USE_MKL_IF_AVAILABLE)
if(USE_MKL_EXPERIMENTAL AND NOT USE_MKLML_MKL)
message(ERROR " USE_MKL_EXPERIMENTAL can only be used when USE_MKL_EXPERIMENTAL is enabled")
endif()
find_package(MKL)
if(MKL_FOUND)
include_directories(${MKL_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/operator/mkl)
add_definitions(-DMXNET_USE_MKLDNN=1)
add_definitions(-DMXNET_USE_MKL2017=1)
add_definitions(-DUSE_MKL=1)
add_definitions(-DCUB_MKL=1)
list(APPEND mxnet_LINKER_LIBS ${MKL_LIBRARIES})
Expand All @@ -151,6 +154,11 @@ if(USE_MKL_IF_AVAILABLE)
endif()
# If using MKL, use the Intel OMP libraries
list(APPEND mxnet_LINKER_LIBS iomp5)
if(USE_MKL_EXPERIMENTAL)
add_definitions(-DMKL_EXPERIMENTAL=1)
else()
add_definitions(-DMKL_EXPERIMENTAL=0)
endif()
else()
message(STATUS " MKL not found")
endif()
Expand Down
59 changes: 30 additions & 29 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
mx_lib = 'lib/libmxnet.so, lib/libmxnet.a, dmlc-core/libdmlc.a, nnvm/lib/libnnvm.a'
// mxnet cmake libraries, in cmake builds we do not produce a libnvvm static library by default.
mx_cmake_lib = 'build/libmxnet.so, build/libmxnet.a, build/dmlc-core/libdmlc.a'
mx_mkldnn_lib = 'lib/libmxnet.so, lib/libmxnet.a, lib/libiomp5.so, lib/libmklml_gnu.so, lib/libmkldnn.so, lib/libmkldnn.so.0, lib/libmklml_intel.so, dmlc-core/libdmlc.a, nnvm/lib/libnnvm.a'
// command to start a docker container
docker_run = 'tests/ci_build/ci_build.sh'
// timeout in minutes
Expand Down Expand Up @@ -162,18 +161,18 @@ def python3_gpu_ut(docker_type) {
}

// Python 2
def python2_mkldnn_ut(docker_type) {
def python2_mklml_ut(docker_type) {
timeout(time: max_time, unit: 'MINUTES') {
sh "${docker_run} ${docker_type} find . -name '*.pyc' -type f -delete"
sh "${docker_run} ${docker_type} PYTHONPATH=./python/ MXNET_MKLDNN_DEBUG=1 nosetests-2.7 --with-timer --verbose tests/python/cpu"
sh "${docker_run} ${docker_type} PYTHONPATH=./python/ nosetests-2.7 --with-timer --verbose tests/python/cpu"
}
}

// Python 3
def python3_mkldnn_ut(docker_type) {
def python3_mklml_ut(docker_type) {
timeout(time: max_time, unit: 'MINUTES') {
sh "${docker_run} ${docker_type} find . -name '*.pyc' -type f -delete"
sh "${docker_run} ${docker_type} PYTHONPATH=./python/ MXNET_MKLDNN_DEBUG=1 nosetests-3.4 --with-timer --verbose tests/python/cpu"
sh "${docker_run} ${docker_type} PYTHONPATH=./python/ nosetests-3.4 --with-timer --verbose tests/python/cpu"
}
}

Expand Down Expand Up @@ -244,20 +243,21 @@ try {
}
}
},
'CPU: MKLDNN': {
'CPU: MKLML': {
node('mxnetlinux-cpu') {
ws('workspace/build-mkldnn-cpu') {
ws('workspace/build-mklml-cpu') {
init_git()
def flag = """ \
DEV=1 \
USE_PROFILER=1 \
USE_CPP_PACKAGE=1 \
USE_BLAS=openblas \
USE_MKLDNN=1 \
USE_MKL2017=1 \
USE_MKL2017_EXPERIMENTAL=1 \
-j\$(nproc)
"""
make("cpu_mklml", flag)
pack_lib('mkldnn_cpu', mx_mkldnn_lib)
pack_lib('mklml_cpu')
}
}
},
Expand All @@ -278,23 +278,24 @@ try {
}
}
},
'GPU: MKLDNN': {
'GPU: MKLML': {
node('mxnetlinux-cpu') {
ws('workspace/build-mkldnn-gpu') {
ws('workspace/build-mklml-gpu') {
init_git()
def flag = """ \
DEV=1 \
USE_PROFILER=1 \
USE_CPP_PACKAGE=1 \
USE_BLAS=openblas \
USE_MKLDNN=1 \
USE_MKL2017=1 \
USE_MKL2017_EXPERIMENTAL=1 \
USE_CUDA=1 \
USE_CUDA_PATH=/usr/local/cuda \
USE_CUDNN=1 \
-j\$(nproc)
"""
make("build_cuda", flag)
pack_lib('mkldnn_gpu', mx_mkldnn_lib)
pack_lib('mklml_gpu')
}
}
},
Expand Down Expand Up @@ -441,43 +442,43 @@ try {
}
}
},
'Python2: MKLDNN-CPU': {
'Python2: MKLML-CPU': {
node('mxnetlinux-cpu') {
ws('workspace/ut-python2-mkldnn-cpu') {
ws('workspace/ut-python2-mklml-cpu') {
init_git()
unpack_lib('mkldnn_cpu', mx_mkldnn_lib)
unpack_lib('mklml_cpu')
python2_ut('cpu_mklml')
python2_mkldnn_ut('cpu_mklml')
python2_mklml_ut('cpu_mklml')
}
}
},
'Python2: MKLDNN-GPU': {
'Python2: MKLML-GPU': {
node('mxnetlinux-gpu') {
ws('workspace/ut-python2-mkldnn-gpu') {
ws('workspace/ut-python2-mklml-gpu') {
init_git()
unpack_lib('mkldnn_gpu', mx_mkldnn_lib)
unpack_lib('mklml_gpu')
python2_gpu_ut('gpu_mklml')
python2_mkldnn_ut('gpu_mklml')
python2_mklml_ut('gpu_mklml')
}
}
},
'Python3: MKLDNN-CPU': {
'Python3: MKLML-CPU': {
node('mxnetlinux-cpu') {
ws('workspace/ut-python3-mkldnn-cpu') {
ws('workspace/ut-python3-mklml-cpu') {
init_git()
unpack_lib('mkldnn_cpu', mx_mkldnn_lib)
unpack_lib('mklml_cpu')
python3_ut('cpu_mklml')
python3_mkldnn_ut('cpu_mklml')
python3_mklml_ut('cpu_mklml')
}
}
},
'Python3: MKLDNN-GPU': {
'Python3: MKLML-GPU': {
node('mxnetlinux-gpu') {
ws('workspace/ut-python3-mkldnn-gpu') {
ws('workspace/ut-python3-mklml-gpu') {
init_git()
unpack_lib('mkldnn_gpu', mx_mkldnn_lib)
unpack_lib('mklml_gpu')
python3_gpu_ut('gpu_mklml')
python3_mkldnn_ut('gpu_mklml')
python3_mklml_ut('gpu_mklml')
}
}
},
Expand Down
40 changes: 23 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ endif
# use customized config file
include $(config)

ifeq ($(USE_MKLDNN), 1)
RETURN_STRING := $(shell ./prepare_mkldnn.sh $(MKLDNN_ROOT))
MKLDNNROOT := $(firstword $(RETURN_STRING))
MKLROOT := $(lastword $(RETURN_STRING))
export USE_MKLML = 1
ifeq ($(USE_MKL2017), 1)
# must run ./prepare_mkl before including mshadow.mk
RETURN_STRING := $(shell ./prepare_mkl.sh $(MKLML_ROOT))
MKLROOT := $(firstword $(RETURN_STRING))
export USE_MKLML = $(lastword $(RETURN_STRING))
endif

include mshadow/make/mshadow.mk
Expand Down Expand Up @@ -131,16 +131,23 @@ ifeq ($(USE_NNPACK), 1)
LDFLAGS += -lnnpack
endif

ifeq ($(USE_MKLDNN), 1)
CFLAGS += -DMXNET_USE_MKLDNN=1
ifeq ($(USE_MKL2017), 1)
CFLAGS += -DMXNET_USE_MKL2017=1
CFLAGS += -DUSE_MKL=1
CFLAGS += -I$(ROOTDIR)/src/operator/nn/mkldnn/
ifneq ($(MKLDNNROOT), $(MKLROOT))
CFLAGS += -I$(MKLROOT)/include
LDFLAGS += -L$(MKLROOT)/lib
CFLAGS += -I$(ROOTDIR)/src/operator/mkl/
CFLAGS += -I$(MKLML_ROOT)/include
LDFLAGS += -L$(MKLML_ROOT)/lib
ifeq ($(USE_MKL2017_EXPERIMENTAL), 1)
CFLAGS += -DMKL_EXPERIMENTAL=1
else
CFLAGS += -DMKL_EXPERIMENTAL=0
endif
ifeq ($(UNAME_S), Darwin)
LDFLAGS += -lmklml
else
LDFLAGS += -Wl,--as-needed -lmklml_intel -lmklml_gnu
endif
CFLAGS += -I$(MKLDNNROOT)/include
LDFLAGS += -L$(MKLDNNROOT)/lib -lmkldnn -Wl,-rpath,'$${ORIGIN}'
LDFLAGS += -liomp5
endif

ifeq ($(USE_OPERATOR_TUNING), 1)
Expand All @@ -154,7 +161,7 @@ endif
# - for Ubuntu, installing atlas will not automatically install the atlas provided lapack library
# silently switching lapack off instead of letting the build fail because of backward compatibility
ifeq ($(USE_LAPACK), 1)
ifeq ($(USE_BLAS),$(filter $(USE_BLAS),blas openblas atlas mkl))
ifeq ($(USE_BLAS),$(filter $(USE_BLAS),blas openblas atlas))
ifeq (,$(wildcard /lib/liblapack.a))
ifeq (,$(wildcard /usr/lib/liblapack.a))
ifeq (,$(wildcard /usr/lib64/liblapack.a))
Expand All @@ -172,7 +179,7 @@ ifeq ($(USE_LAPACK), 1)
ifneq ($(USE_LAPACK_PATH), )
LDFLAGS += -L$(USE_LAPACK_PATH)
endif
ifeq ($(USE_BLAS),$(filter $(USE_BLAS),blas openblas atlas mkl))
ifeq ($(USE_BLAS),$(filter $(USE_BLAS),blas openblas atlas))
LDFLAGS += -llapack
endif
CFLAGS += -DMXNET_USE_LAPACK
Expand Down Expand Up @@ -562,8 +569,7 @@ clean: cyclean $(EXTRA_PACKAGES_CLEAN)
else
clean: cyclean testclean $(EXTRA_PACKAGES_CLEAN)
$(RM) -r build lib bin *~ */*~ */*/*~ */*/*/*~ R-package/NAMESPACE R-package/man R-package/R/mxnet_generated.R \
R-package/inst R-package/src/image_recordio.h R-package/src/*.o R-package/src/*.so mxnet_*.tar.gz \
external/mkldnn/install/*
R-package/inst R-package/src/image_recordio.h R-package/src/*.o R-package/src/*.so mxnet_*.tar.gz
cd $(DMLC_CORE); $(MAKE) clean; cd -
cd $(PS_PATH); $(MAKE) clean; cd -
cd $(NNVM_PATH); $(MAKE) clean; cd -
Expand Down
2 changes: 1 addition & 1 deletion amalgamation/mxnet_predict0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#include "src/operator/operator_util.cc"
#include "src/operator/nn/activation.cc"
#include "src/operator/nn/batch_norm.cc"
#include "src/operator/nn/concat.cc"
#include "src/operator/concat.cc"
#include "src/operator/nn/convolution.cc"
#include "src/operator/nn/deconvolution.cc"
#include "src/operator/nn/dropout.cc"
Expand Down
4 changes: 2 additions & 2 deletions cmake/ChooseBlas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if(USE_MKL_IF_AVAILABLE)
find_package(MKL)
endif()
if(MKL_FOUND)
if(USE_MKLDNN)
if(USE_MKLML_MKL)
set(BLAS "open")
else()
set(BLAS "MKL")
Expand Down Expand Up @@ -55,4 +55,4 @@ elseif(BLAS STREQUAL "apple")
list(APPEND mshadow_LINKER_LIBS ${Accelerate_LIBRARIES})
add_definitions(-DMSHADOW_USE_MKL=0)
add_definitions(-DMSHADOW_USE_CBLAS=1)
endif()
endif()
18 changes: 9 additions & 9 deletions cmake/Modules/FindMKL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#
# Options:
#
# USE_MKLDNN : Search for MKL:ML library variant
# USE_MKLML_MKL : Search for MKL:ML library variant
#
# MKL_USE_SINGLE_DYNAMIC_LIBRARY : use single dynamic library interface
# MKL_USE_STATIC_LIBS : use static libraries
Expand All @@ -33,7 +33,7 @@
# MKL_INCLUDE_DIR : unclude directory
# MKL_LIBRARIES : the libraries to link against.
#
# cjolivier01: Changed to also look for MKLDNN library (subset of mkl) instead of standard MKL package
# cjolivier01: Changed to also look for MKLML library (subset of mkl) instead of standard MKL package
#

if(MKL_FOUND)
Expand All @@ -43,7 +43,7 @@ endif()
# ---[ Root folders
set(INTEL_ROOT "/opt/intel" CACHE PATH "Folder contains intel libs")

if(USE_MKLDNN)
if(USE_MKLML_MKL)

find_path(MKL_ROOT include/mkl_blas.h
PATHS $ENV{MKL_ROOT}
Expand All @@ -66,14 +66,13 @@ if(USE_MKLDNN)
set(__mkl_libs "")

if(WIN32)
list(APPEND __mkl_libs mklml_intel)
list(APPEND __mkl_libs intel)
else()
list(APPEND __mkl_libs mklml_gnu)
list(APPEND __mkl_libs gnu)
endif()
list(APPEND __mkl_libs mkldnn)

foreach (__lib ${__mkl_libs})
set(__mkl_lib "${__lib}")
set(__mkl_lib "mklml_${__lib}")
string(TOUPPER ${__mkl_lib} __mkl_lib_upper)

if(MKL_USE_STATIC_LIBS)
Expand All @@ -91,7 +90,8 @@ if(USE_MKLDNN)
list(APPEND MKL_LIBRARIES ${${__mkl_lib_upper}_LIBRARY})
endforeach()

else(USE_MKLDNN)

else(USE_MKLML_MKL)

# ---[ Options
mxnet_option(MKL_USE_SINGLE_DYNAMIC_LIBRARY "Use single dynamic library interface" ON)
Expand Down Expand Up @@ -193,7 +193,7 @@ else(USE_MKLDNN)
list(APPEND MKL_LIBRARIES ${MKL_RTL_LIBRARY})
endif()

endif(USE_MKLDNN)
endif(USE_MKLML_MKL)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MKL DEFAULT_MSG ${__looked_for})
Expand Down
3 changes: 1 addition & 2 deletions example/image-classification/common/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def get_rec_iter(args, kv=None):
image_shape = tuple([int(l) for l in args.image_shape.split(',')])
if 'benchmark' in args and args.benchmark:
data_shape = (args.batch_size,) + image_shape
train = SyntheticDataIter(args.num_classes, data_shape,
args.num_examples / args.batch_size, np.float32)
train = SyntheticDataIter(args.num_classes, data_shape, 500, np.float32)
return (train, None)
if kv:
(rank, nworker) = (kv.rank, kv.num_workers)
Expand Down
Loading

0 comments on commit 6802961

Please sign in to comment.