-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Refactor operators & MKLDNN #8302
Changes from 30 commits
3a90190
4ecf3a1
709ec84
d625b31
3cb6606
197fff2
785fa5f
09eca97
8af167e
5752525
853a28f
c76d3ed
8ba9736
6c7f2de
d3dac5f
e015f11
386dc55
cb1d630
399ff52
62995b6
4c3f112
1078898
c5de4ed
fce31ed
7e8537c
4723054
8cb1970
2f8028a
682cec6
619fe85
d2181d4
4b84308
46a7209
26ecfb8
839441a
b9cc3d9
4d781a1
10619fe
2ac3918
7caa0db
5a037bd
9560775
06e0ab6
e4b4fc5
6668727
b5e210d
7c8456e
050b95c
5b3f647
e22b2e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's libiomp5? What's libmklml_gnu used for if this is about mkldnn? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. libiomp5 is the "commercial build" of Intel's OMP library There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These libraries are provided by Intel people. They link the library in such a way. But you are right. Maybe we shouldn't link both Intel's OMP library and GNU OMP library. |
||
// command to start a docker container | ||
docker_run = 'tests/ci_build/ci_build.sh' | ||
// timeout in minutes | ||
|
@@ -143,15 +144,15 @@ def python3_gpu_ut(docker_type) { | |
} | ||
|
||
// Python 2 | ||
def python2_mklml_ut(docker_type) { | ||
def python2_mkldnn_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/ nosetests-2.7 --with-timer --verbose tests/python/cpu" | ||
} | ||
} | ||
|
||
// Python 3 | ||
def python3_mklml_ut(docker_type) { | ||
def python3_mkldnn_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/ nosetests-3.4 --with-timer --verbose tests/python/cpu" | ||
|
@@ -225,21 +226,20 @@ try { | |
} | ||
} | ||
}, | ||
'CPU: MKLML': { | ||
'CPU: MKLDNN': { | ||
node('mxnetlinux-cpu') { | ||
ws('workspace/build-mklml-cpu') { | ||
ws('workspace/build-mkldnn-cpu') { | ||
init_git() | ||
def flag = """ \ | ||
DEV=1 \ | ||
USE_PROFILER=1 \ | ||
USE_CPP_PACKAGE=1 \ | ||
USE_BLAS=openblas \ | ||
USE_MKL2017=1 \ | ||
USE_MKL2017_EXPERIMENTAL=1 \ | ||
USE_MKLDNN=1 \ | ||
-j\$(nproc) | ||
""" | ||
make("cpu_mklml", flag) | ||
pack_lib('mklml_cpu') | ||
pack_lib('mkldnn_cpu', mx_mkldnn_lib) | ||
} | ||
} | ||
}, | ||
|
@@ -260,24 +260,23 @@ try { | |
} | ||
} | ||
}, | ||
'GPU: MKLML': { | ||
'GPU: MKLDNN': { | ||
node('mxnetlinux-cpu') { | ||
ws('workspace/build-mklml-gpu') { | ||
ws('workspace/build-mkldnn-gpu') { | ||
init_git() | ||
def flag = """ \ | ||
DEV=1 \ | ||
USE_PROFILER=1 \ | ||
USE_CPP_PACKAGE=1 \ | ||
USE_BLAS=openblas \ | ||
USE_MKL2017=1 \ | ||
USE_MKL2017_EXPERIMENTAL=1 \ | ||
USE_MKLDNN=1 \ | ||
USE_CUDA=1 \ | ||
USE_CUDA_PATH=/usr/local/cuda \ | ||
USE_CUDNN=1 \ | ||
-j\$(nproc) | ||
""" | ||
make("build_cuda", flag) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So have you been able to use MKLDNN without the need of a separate dockerfile? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it works fine. except that using MKLDNN and GPU in Jenkins still fails. It's not a linking problem. It's most likely caused by the conflict of MKLDNN and GPU in Jenkins. |
||
pack_lib('mklml_gpu') | ||
pack_lib('mkldnn_gpu', mx_mkldnn_lib) | ||
} | ||
} | ||
}, | ||
|
@@ -424,43 +423,43 @@ try { | |
} | ||
} | ||
}, | ||
'Python2: MKLML-CPU': { | ||
'Python2: MKLDNN-CPU': { | ||
node('mxnetlinux-cpu') { | ||
ws('workspace/ut-python2-mklml-cpu') { | ||
ws('workspace/ut-python2-mkldnn-cpu') { | ||
init_git() | ||
unpack_lib('mklml_cpu') | ||
unpack_lib('mkldnn_cpu', mx_mkldnn_lib) | ||
python2_ut('cpu_mklml') | ||
python2_mklml_ut('cpu_mklml') | ||
python2_mkldnn_ut('cpu_mklml') | ||
} | ||
} | ||
}, | ||
'Python2: MKLML-GPU': { | ||
'Python2: MKLDNN-GPU': { | ||
node('mxnetlinux-gpu') { | ||
ws('workspace/ut-python2-mklml-gpu') { | ||
ws('workspace/ut-python2-mkldnn-gpu') { | ||
init_git() | ||
unpack_lib('mklml_gpu') | ||
unpack_lib('mkldnn_gpu', mx_mkldnn_lib) | ||
python2_gpu_ut('gpu_mklml') | ||
python2_mklml_ut('gpu_mklml') | ||
python2_mkldnn_ut('gpu_mklml') | ||
} | ||
} | ||
}, | ||
'Python3: MKLML-CPU': { | ||
'Python3: MKLDNN-CPU': { | ||
node('mxnetlinux-cpu') { | ||
ws('workspace/ut-python3-mklml-cpu') { | ||
ws('workspace/ut-python3-mkldnn-cpu') { | ||
init_git() | ||
unpack_lib('mklml_cpu') | ||
unpack_lib('mkldnn_cpu', mx_mkldnn_lib) | ||
python3_ut('cpu_mklml') | ||
python3_mklml_ut('cpu_mklml') | ||
python3_mkldnn_ut('cpu_mklml') | ||
} | ||
} | ||
}, | ||
'Python3: MKLML-GPU': { | ||
'Python3: MKLDNN-GPU': { | ||
node('mxnetlinux-gpu') { | ||
ws('workspace/ut-python3-mklml-gpu') { | ||
ws('workspace/ut-python3-mkldnn-gpu') { | ||
init_git() | ||
unpack_lib('mklml_gpu') | ||
unpack_lib('mkldnn_gpu', mx_mkldnn_lib) | ||
python3_gpu_ut('gpu_mklml') | ||
python3_mklml_ut('gpu_mklml') | ||
python3_mkldnn_ut('gpu_mklml') | ||
} | ||
} | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,11 @@ endif | |
# use customized config file | ||
include $(config) | ||
|
||
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)) | ||
ifeq ($(USE_MKLDNN), 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is cmake also adjusted for this type of build? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet. I'll update. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have changed cmake to compile with MKLDNN. |
||
RETURN_STRING := $(shell ./prepare_mkldnn.sh $(MKLDNN_ROOT)) | ||
MKLDNNROOT := $(firstword $(RETURN_STRING)) | ||
MKLROOT := $(lastword $(RETURN_STRING)) | ||
export USE_MKLML = 1 | ||
endif | ||
|
||
include mshadow/make/mshadow.mk | ||
|
@@ -114,23 +114,16 @@ ifeq ($(USE_NNPACK), 1) | |
LDFLAGS += -lnnpack | ||
endif | ||
|
||
ifeq ($(USE_MKL2017), 1) | ||
CFLAGS += -DMXNET_USE_MKL2017=1 | ||
ifeq ($(USE_MKLDNN), 1) | ||
CFLAGS += -DMXNET_USE_MKLDNN=1 | ||
CFLAGS += -DUSE_MKL=1 | ||
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 | ||
CFLAGS += -I$(ROOTDIR)/src/operator/nn/mkldnn/ | ||
ifneq ($(MKLDNNROOT), $(MKLROOT)) | ||
CFLAGS += -I$(MKLROOT)/include | ||
LDFLAGS += -L$(MKLROOT)/lib | ||
endif | ||
LDFLAGS += -liomp5 | ||
CFLAGS += -I$(MKLDNNROOT)/include | ||
LDFLAGS += -L$(MKLDNNROOT)/lib -lmkldnn -Wl,-rpath,'$${ORIGIN}' | ||
endif | ||
|
||
ifeq ($(USE_OPERATOR_TUNING), 1) | ||
|
@@ -144,7 +137,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)) | ||
ifeq ($(USE_BLAS),$(filter $(USE_BLAS),blas openblas atlas mkl)) | ||
ifeq (,$(wildcard /lib/liblapack.a)) | ||
ifeq (,$(wildcard /usr/lib/liblapack.a)) | ||
ifeq (,$(wildcard /usr/lib64/liblapack.a)) | ||
|
@@ -162,7 +155,7 @@ ifeq ($(USE_LAPACK), 1) | |
ifneq ($(USE_LAPACK_PATH), ) | ||
LDFLAGS += -L$(USE_LAPACK_PATH) | ||
endif | ||
ifeq ($(USE_BLAS),$(filter $(USE_BLAS),blas openblas atlas)) | ||
ifeq ($(USE_BLAS),$(filter $(USE_BLAS),blas openblas atlas mkl)) | ||
LDFLAGS += -llapack | ||
endif | ||
CFLAGS += -DMXNET_USE_LAPACK | ||
|
@@ -552,7 +545,8 @@ 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 | ||
R-package/inst R-package/src/image_recordio.h R-package/src/*.o R-package/src/*.so mxnet_*.tar.gz \ | ||
external/mkldnn/install/* | ||
cd $(DMLC_CORE); $(MAKE) clean; cd - | ||
cd $(PS_PATH); $(MAKE) clean; cd - | ||
cd $(NNVM_PATH); $(MAKE) clean; cd - | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,7 +112,8 @@ 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, 500, np.float32) | ||
train = SyntheticDataIter(args.num_classes, data_shape, | ||
args.num_examples / args.batch_size, np.float32) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change related to this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really. It seems to me this is a bug, so I fixed it. |
||
return (train, None) | ||
if kv: | ||
(rank, nworker) = (kv.rank, kv.num_workers) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, MKL-DNN moved to https://github.com/intel/mkl-dnn and 01org will be redirected but will continue to work.
It's better to update the link.