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

Upgrade MKL-DNN dependency to v1.0 #16555

Merged
merged 66 commits into from Oct 31, 2019
Merged

Upgrade MKL-DNN dependency to v1.0 #16555

merged 66 commits into from Oct 31, 2019

Conversation

TaoLv
Copy link
Member

@TaoLv TaoLv commented Oct 20, 2019

Description

This is an effort from the whole Intel MXNet team. Credits belong to everyone in the team.

This PR upgrades the 3rdparty/mkldnn dependency to it's v1.0.x release which has many API breaking changes and is not backward compatible to the previous v0.x versions. Hence this PR also changes the integration code in operators while keep the integration methodology and software architecture the same. Development has been done on the feature branch mkldnn-v1.0 and tracked via github project: https://github.com/apache/incubator-mxnet/projects/16.

Please see the discussion here: https://lists.apache.org/thread.html/f46ab920f18795496eafe713e6e9e561c684e06189085cec17b401dc@%3Cdev.mxnet.apache.org%3E
Please see MKL-DNN v1.0 RFC here: https://github.com/intel/mkl-dnn/tree/rfc-api-changes-v1.0/doc/rfc/api-v1.0

As mentioned in the dev@ thread, this PR also removes the mklml and iomp5 library which previously are distributed along with MXNet pip package. So it also fixes the license issue in #15544. It's a requirement for 1.6.0 release.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

TaoLv and others added 30 commits August 11, 2019 17:57
* update mkldnn to 1.0.1 release

* change makefile

* change cmake

* update ci build and pip package build

* fix typo in mkldnn.mk

* fix build for USE_BLAS=mkl & bump MKL version

* skip mkldnn unit tests

* remove iomp5 from mx_mkldnn_lib

* ci: skip test_mkldnn_install

* retrigger ci

* retrigger ci

* retrigger ci
Conflicts:
	ci/jenkins/Jenkins_steps.groovy
Conflicts:
	tests/python/mkl/test_subgraph.py
Conflicts:
	ci/jenkins/Jenkins_steps.groovy
* bump mkldnn to v1.0.2

* skip quantization unit test

* add useless build flag

* Fixes openblas installation for static build

* empty commit
* fix comments (#8)

* add base code for mkldnn 1.0

* fix comments

* Update mkldnn.mk

* add base code for mkldnn 1.0

* fix build

* fix lint

* fix lint
* add mkldnn conv

* revert unnecessary change

* fix testcase fail for cpu: test_convolution_independent_gradients

* fix failed testcase: test_reshape_transpose_6d&&test_weight_async_reorder

* fix comments

* change variable name from weights to weight in mkldnn_conv
Conflicts:
	src/operator/nn/mkldnn/mkldnn_base-inl.h
* add mkldnn act; pass lint; pass mnist training

* make bwd as private member
* add mkldnn bn

* add static_cast to transform data type

* change mkldnn_args_map_t

* retrigger CI
* add mkldnn transpose

* using mkldnn_args_map_t instead of std::unordered_map<int, mkldnn::memory>
Conflicts:
	3rdparty/mkldnn
	ci/docker/install/ubuntu_mkl.sh
	ci/docker/install/ubuntu_mklml.sh
	cmake/DownloadMKLML.cmake
	src/operator/nn/mkldnn/mkldnn_act-inl.h
	src/operator/nn/mkldnn/mkldnn_act.cc
* add mkldnn softmax

* trigger CI
* add mkldnn fc; pass lint; pass mnist training

* add TODO info for future debug
* add mkldnn deconv

* coding style

* trigger CI
* add mkldnn pooling

* add workaround for mkldnn v1.0 pooling fwd && bwd workspace mismatch

* code clean

* fix lint error

* trigger CI

* trigger CI

* add extra work_space check and fix some typo

* trigger CI
* Add mkldnn 1.0 support for reshape/flatten/expanddims ops

* improve log & modify definition location of args_map_

* fix comments

* rebase code

* trigger CI

* trigger CI

* trigger CI

* trigger CI
* Add mkldnn quantized activation/pooling/flatten

* int8 flatten
* int8 conv quantize dequantize requantize

Change-Id: Ibd9df97288a95c61d6d85ec3831fd18b626ca283

* Fix lint

* Fix clang build

Change-Id: I9468774d014c852901e4cc3bffabd8a3d8004519
* add mkldnn int8 elemwise_add

* add workaround to fix format any issue

* code clean
* Add mkldnn_v1.0 int8 fc

* trigger CI

* trigger CI
* use MSHADOW_USE_MKL to determine whther to use mkl optimized dropout

* rebase code
Conflicts:
	src/operator/nn/mkldnn/mkldnn_base-inl.h
	src/operator/nn/mkldnn/mkldnn_flatten-inl.h
	src/operator/nn/mkldnn/mkldnn_flatten.cc
	src/operator/nn/mkldnn/mkldnn_ops-inl.h
	src/operator/nn/mkldnn/mkldnn_reshape-inl.h
	src/operator/nn/mkldnn/mkldnn_reshape.cc
	src/operator/quantization/mkldnn/mkldnn_quantized_flatten.cc
	src/operator/tensor/matrix_op.cc
@pengzhao-intel
Copy link
Contributor

RNN has inconsistent output in training mode. The following script prints a nonzero array:

import mxnet as mx

sym = mx.sym.RNN(
	mx.symbol.Variable('input'),
	mx.symbol.Variable('weights'),
	mx.symbol.Variable('state'),
	state_size = 4,
	num_layers = 1,
	mode = 'gru'
)
ex = sym.bind(mx.cpu(),
	{
		"input": mx.ndarray.random.uniform(low = 0, high = 1, shape = (3, 1, 2)),
		"weights": mx.ndarray.random.uniform(low = 0, high = 1, shape = (96)),
		"state": mx.nd.zeros([1, 1, 4]),
	}
)

ex.forward(is_train=True)
res1 = ex.outputs[0].asnumpy()
ex.forward(is_train=True)
res2 = ex.outputs[0].asnumpy()

print(res1 - res2)

This also happens if MKL-DNN is disabled by env var, but it doesn't happen on master (built with MKL-DNN)

@zixuanweeei please take a look for this issue

@zixuanweeei
Copy link
Contributor

deeply appreciative of your work @matteosal. I can reproduce the inconsistency with "gru" mode. "lstm" and "rnn_*" could give consistent results. I will look into this. Thanks again. @pengzhao-intel

@zixuanweeei
Copy link
Contributor

@matteosal #16663 could fix the inconsistent of GRU.

@pengzhao-intel
Copy link
Contributor

@ALL, only one issue is left at now and we will fix it soon. I prefer to merge this PR in one or two days so that we have buffer time to test by the master or nightly build.

Please take a final review and feel free to raise the issue or concern :)

@pengzhao-intel
Copy link
Contributor

The only known issue is fixed by #16672

MKLDNN 1.0 upgrade automation moved this from In progress to Reviewer Approved Oct 30, 2019
Copy link
Contributor

@pengzhao-intel pengzhao-intel left a comment

Choose a reason for hiding this comment

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

LGTM

@pengzhao-intel
Copy link
Contributor

CI failure is not related to the change. Please retrigger the CI.

@TaoLv
Copy link
Member Author

TaoLv commented Oct 31, 2019

@samskalicky @apeforest @marcoabreu @mseth10 I hope your comments have been addressed. If so, could you please approve?

Copy link
Contributor

@mseth10 mseth10 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@samskalicky samskalicky left a comment

Choose a reason for hiding this comment

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

LGTM thanks for all of your hard work!

@pengzhao-intel
Copy link
Contributor

Thanks all of the efforts from the team :)
Merging now.

@pengzhao-intel pengzhao-intel merged commit aa1074d into master Oct 31, 2019
MKLDNN 1.0 upgrade automation moved this from Reviewer Approved to Done Oct 31, 2019
yajiedesign pushed a commit to yajiedesign/mxnet that referenced this pull request Nov 6, 2019
* [mkldnn-v1.0] Initiate the transition to MKL-DNN v1.0 (apache#15706)

* update mkldnn to 1.0.1 release

* change makefile

* change cmake

* update ci build and pip package build

* fix typo in mkldnn.mk

* fix build for USE_BLAS=mkl & bump MKL version

* skip mkldnn unit tests

* remove iomp5 from mx_mkldnn_lib

* ci: skip test_mkldnn_install

* retrigger ci

* retrigger ci

* retrigger ci

* [mkldnn-v1.0] Update MKL-DNN to v1.0.2 (apache#16012)

* bump mkldnn to v1.0.2

* skip quantization unit test

* add useless build flag

* Fixes openblas installation for static build

* empty commit

* [mkldnn-v1.0] Enable base code with new APIs. (apache#16064)

* fix comments (#8)

* add base code for mkldnn 1.0

* fix comments

* Update mkldnn.mk

* add base code for mkldnn 1.0

* fix build

* fix lint

* fix lint

* [mkldnn-v1.0] Add MKL-DNN Convolution (apache#16141)

* add mkldnn conv

* revert unnecessary change

* fix testcase fail for cpu: test_convolution_independent_gradients

* fix failed testcase: test_reshape_transpose_6d&&test_weight_async_reorder

* fix comments

* change variable name from weights to weight in mkldnn_conv

* [mkldnn-v1.0] Add MKL-DNN activation (apache#16195)

* add mkldnn act; pass lint; pass mnist training

* make bwd as private member

* [mkldnn-v1.0] Add MKL-DNN BN (apache#16199)

* add mkldnn bn

* add static_cast to transform data type

* change mkldnn_args_map_t

* retrigger CI

* add mkldnn lrn (apache#16223)

* [mkldnn-v1.0] Add MKL-DNN Transpose (apache#16250)

* add mkldnn transpose

* using mkldnn_args_map_t instead of std::unordered_map<int, mkldnn::memory>

* [mkldnn-v1.0] Add MKL-DNN softmax (apache#16246)

* add mkldnn softmax

* trigger CI

* [mkldnn-v1.0] Add MKL-DNN FC (apache#16221)

* add mkldnn fc; pass lint; pass mnist training

* add TODO info for future debug

* [mkldnn-v1.0] Add MKL-DNN  deconv (apache#16259)

* add mkldnn deconv

* coding style

* trigger CI

* add mkldnn softmax_output (apache#16222)

* [mkldnn-v1.0] Add MKL-DNN Pooling (apache#16272)

* add mkldnn pooling

* add workaround for mkldnn v1.0 pooling fwd && bwd workspace mismatch

* code clean

* fix lint error

* trigger CI

* trigger CI

* add extra work_space check and fix some typo

* trigger CI

* [mkldnn-v1.0] Add MKL-DNN reshape&flatten&expand_dims (apache#16258)

* Add mkldnn 1.0 support for reshape/flatten/expanddims ops

* improve log & modify definition location of args_map_

* fix comments

* rebase code

* trigger CI

* trigger CI

* trigger CI

* trigger CI

* [mkldnn-v1.0] Add MKL-DNN int8 activation&pooling&flatten (apache#16425)

* Add mkldnn quantized activation/pooling/flatten

* int8 flatten

* [mkldnn-1.0] int8 conv quantize dequantize requantize (apache#16283)

* int8 conv quantize dequantize requantize

Change-Id: Ibd9df97288a95c61d6d85ec3831fd18b626ca283

* Fix lint

* Fix clang build

Change-Id: I9468774d014c852901e4cc3bffabd8a3d8004519

* add mkldnn sum concat (apache#16263)

* [mkldnn-1.0] mkldnn int8 elemwise_add (apache#16454)

* add mkldnn int8 elemwise_add

* add workaround to fix format any issue

* code clean

* upgrade int8 bn to MKLDNN1.0 (apache#16458)

* [mkldnn-v1.0] Fused RNN Op (apache#16420)

* [mkldnn-v1.0] Add MKL-DNN int8 fc (apache#16457)

* Add mkldnn_v1.0 int8 fc

* trigger CI

* trigger CI

* [mkldnn-v1.0] Update enabling flag for MKL dropout (apache#16433)

* use MSHADOW_USE_MKL to determine whther to use mkl optimized dropout

* rebase code

* [mkldnn-1.0] upgrade int8 concat to MKLDNN1.0 (apache#16466)

* [mkldnn-1.0] upgrade int8 concat to MKLDNN1.0

* fix lint

* use mkldnn_args_map_t

* update dict usage style

* retrigger CI

* retrigger CI again

* retrigger CI again 2

* [mkldnn-v1.0] Add MKL-DNN slice (apache#16484)

* change slice to mkldnn v1.0

* fix lint

* [mkldnn-1.0] add mkldnn subgraph fc (apache#16468)

* add mkldnn subgraph fc

* code clean

* trigger CI

* [mkldnn-v1.0]enable mkldnn concat (apache#16507)

* enable mkldnn concat

* trigger CI

* trigger CI

* [mkldnn-v1.0] Enable mkldnn cpp-test, copy op, concat op (apache#16503)

* [mkldnn-v1.0] Enable mkldnn test, copy op, concat op

Exclude gpu topology via MXNET_USE_CUDA

nit

default format

Remove whitespace

* Unix-GPU Tensor-RT build timeout, re-trigger CI

* [mkldnn-1.0] add skipped case for mkldnn_v1.0 (apache#16470)

* add skipped case for mkldnn_v1.0

* enable mkl quantized testcase

* enable skipped testcase

* trigger CI

* trigger CI

* trigger CI

* trigger CI

* [mkldnn-1.0]enable mkldnn elemwise_sum (apache#16521)

* enable mkldnn elemwise_sum

* trigger CI

* trigger CI

* trigger CI

* [mkldnn-v1.0] Enable more checks for MXNET_USE_MKLDNN (apache#16520)

* open USE_MKLDNN check

* trigger ci

* ci

* [mkldnn-v1.0]Minor fix for leakyrelu compile flag (apache#16519)

* change to MXNET_USE_MKLDNN == 100

* trigger

* remove MKL license (apache#16534)

* change MXNET_USE_MKLDNN from 100 to 1 (apache#16551)

* re-enable unit tests (apache#16565)

* [mkldnn-v1.0] Skip flaky test for unidirectional rnn_relu (apache#16545)

Skip `test_rnnrelu_sym`, and add some issue tracking message

Add return

Revert test_rnnrelu_sym to origin

* Add some annotations and log strings, rename mem_desc variables (apache#16609)

* [mkldnn-v1.0]set fc weight layout as mkldnn v0.2x did (apache#16593)

* set fc weight layout as mkldnn v0.2x did

* fix lint

* [mkldnn-v1.0] Upgrade to MKL-DNN v1.0.4 patch release (apache#16592)

* upgrade to mkldnn v1.0.3 patch release

* retrigger ci

* mkldnn v1.0.4 patch release

* [mkldnn-1.0]Rebase to master (apache#16648)

* fixed broken links across multiple files (apache#16581)

* fix missing docs due to git add issues (apache#16496)

* Create SECURITY.md (apache#16573)

* Create SECURITY.md

* Update SECURITY.md

* [Numpy] Support N_D(N>=3) batch_dot (apache#16586)

* Support N_D(N>=3) batch_dot

* use 1E-4

* fix lint

* remove unnecessary comment

* Update test_numpy_op.py

* Large Vector tests for DGL Ops Part 2 (apache#16497)

* add hyperbolic, logical, sign and regression tests for large vector

* changed hyperbolic functions into existing trignometric functions

* fix trigo and simple bind needs shape as tuple

* fix logical ops, add with_seed

* fix arcosh in largearray, remove regression from largevector

* [Numpy] Loading numpy-incompatible NDArray in numpy-compatible mode (apache#16597)

* Make MXIsNumpyShape return enum

* address the comment

* Surpress subgraph log in CI (apache#16607)

Change-Id: Ia2ed6fdbb1d2cb5cc607a8856ca13ee338e27eac

* Fix dequantize memory corruption (apache#16606)

Change-Id: I51b62a32987bdbcf96f04b1bc6617e66796f648b

* [MKLDNN]Fix reorder2default (apache#16602)

* Fix reorder2default

Change-Id: I74c87af9535f6264e6d1ea7eaed089a6480a3358

* fix

Change-Id: I6d07b43b520a47e7c78bd4b4b6390f5fb95e6957

* Fix

Change-Id: Id72f25c34291be4711f55569c6d61467edd6113d

* Fix CI

Change-Id: I8c33a82555d5ace2d0b682c1e3eefa13f3a44768

* Run CI

Change-Id: Ie8a6dab80ef91c0337cafbae4e3db277e0c7ebf7

* second round of fixing broken links in multiple files (apache#16598)

* Python Docstring Convetion (apache#16550)

* Docstring convetnion for

* Docstring convention for

* Docstring convention for

* Docstring convention for

* Docstring convention for

* Docstring convention for

* Docstring convention

* Revert removing new line

* Remove white space

* [MXNET-1434] Fix a broken link for basic C++ tutorial (apache#16461)

* Fix for wrong reqs set after switching from training to inference (apache#16553)

* Debugging reqs

* Move literal strings to const static members

* Fix lint

* julia/docs: more DRY on page rendering (apache#16396)

* [mkldnn-v1.0]rebase with master (apache#16649)

* fixed broken links across multiple files (apache#16581)

* fix missing docs due to git add issues (apache#16496)

* Create SECURITY.md (apache#16573)

* Create SECURITY.md

* Update SECURITY.md

* [Numpy] Support N_D(N>=3) batch_dot (apache#16586)

* Support N_D(N>=3) batch_dot

* use 1E-4

* fix lint

* remove unnecessary comment

* Update test_numpy_op.py

* Large Vector tests for DGL Ops Part 2 (apache#16497)

* add hyperbolic, logical, sign and regression tests for large vector

* changed hyperbolic functions into existing trignometric functions

* fix trigo and simple bind needs shape as tuple

* fix logical ops, add with_seed

* fix arcosh in largearray, remove regression from largevector

* [Numpy] Loading numpy-incompatible NDArray in numpy-compatible mode (apache#16597)

* Make MXIsNumpyShape return enum

* address the comment

* Surpress subgraph log in CI (apache#16607)

Change-Id: Ia2ed6fdbb1d2cb5cc607a8856ca13ee338e27eac

* Fix dequantize memory corruption (apache#16606)

Change-Id: I51b62a32987bdbcf96f04b1bc6617e66796f648b

* [MKLDNN]Fix reorder2default (apache#16602)

* Fix reorder2default

Change-Id: I74c87af9535f6264e6d1ea7eaed089a6480a3358

* fix

Change-Id: I6d07b43b520a47e7c78bd4b4b6390f5fb95e6957

* Fix

Change-Id: Id72f25c34291be4711f55569c6d61467edd6113d

* Fix CI

Change-Id: I8c33a82555d5ace2d0b682c1e3eefa13f3a44768

* Run CI

Change-Id: Ie8a6dab80ef91c0337cafbae4e3db277e0c7ebf7

* second round of fixing broken links in multiple files (apache#16598)

* Python Docstring Convetion (apache#16550)

* Docstring convetnion for

* Docstring convention for

* Docstring convention for

* Docstring convention for

* Docstring convention for

* Docstring convention for

* Docstring convention

* Revert removing new line

* Remove white space

* [MXNET-1434] Fix a broken link for basic C++ tutorial (apache#16461)

* Fix for wrong reqs set after switching from training to inference (apache#16553)

* Debugging reqs

* Move literal strings to const static members

* Fix lint

* julia/docs: more DRY on page rendering (apache#16396)

* Disables test_bulking_operator_gpu due to flakiness (apache#16611)

* C Api for simplebind, fix comment for trigoops, add atol to assert (apache#16585)

* C Api for simplebind, fix comment for trigoops, add atol to assert

* fix build issues

* fix lint and add regression test

* fix indent

* api doc and function name change

* fix lint and add infer shape test

* Imagenet inference to nightly fix (apache#16599)

* split to cd and shell

* comment

* lots of prints

* copy binary at correct location

* remove comments

* add mkl lib

* update docker run build function

* set nvidia docker true to run imagenet inference on GPU

* Revert "set nvidia docker true to run imagenet inference on GPU"

This reverts commit 98f8eef.
As we don't need GPU for compilation.

* Fix python doc build issue (apache#16630)

* pin the pip versions

* remove nbconvert comment

* Faster general take (apache#16615)

* Sped up perf of take op when axis != 0

* Formatting and syntax fixes

* Rename Take to specify axis

* Fix line length lint errors

* [Gluon] Don't serialize shared parameters twice (apache#16582)

Add deduplicate argument (default of False) to save_parameters.

* Fix index overflow bug in einsum (apache#16589)

* fix index overflow

* check index overflow

* fix index overflow in einsum path

* fix indent

* reduce NPY_MAXARGS

* safe accumulate

* Move some subgraph verbose to MXNET_SUBGRAPH_VERBOSE=2 (apache#16622)

* Move subgraph pass log to verbose=2

* Run CI

* add npx reshape (apache#16640)

* RNNOp only call cuda/cudnn if GPU ctx is requested (apache#16632)

* fix bad encode (apache#16641)

* [Perl] - ndarray to native array conversion fix (apache#16635)

* fixing broken links in multiple files - round 3 (apache#16634)

* add type switch to weight tensor (apache#16543)

* numpy doc enhancement (apache#16637)

* Change NDArray to ndarray for npx ops

Add nonzero

boolean mask supports boolean ndarray

Add argmin op and interoperability test for nonzero

Fix vdot, inner, outter docs

Add nonzero to mx.nd.np

Add docs

Fix

* Fix lint

* Fix

* Fix

* Fix get_constant

* Disable float16 test (apache#16643)

* Fix GetMKLDNNData for delay alloc (apache#16618)

* Fix GetMKLDNNData for delay alloc

* Run CI

* Run CI

* Run CI

* Run CI

* Run CI

Change-Id: I7ac2796e0ee8439c92fd2bd7a70a23a359b76b12

* Revert "[mkldnn-1.0]Rebase to master (apache#16648)"

This reverts commit dea3dd2.

* [mkldnn-v1.0] Minor fix of mkldnn-v1.0 transition (apache#16644)

mk and rm directory in mkldnn.mk

ndarray.cc redundant whitespace

mkldnn_act rename variables of bwd primitives

mkldnn_rnn.cc iterator -> const_iterator

Use != instead of < for iterator in for-loop

Code comment for explaining the reason why excludes the last layer

* [mkldnn-v1.0]rm int8 sum workaround (apache#16623)

* rm int8 sum workaround due to mkldnn lib update

* simple dims asignments in mkldnn_quantized_elemwise_add.cc

* make MKLDNN macro simple for imperative_utils.h (apache#16652)

* fix ci jenkins step groovy (apache#16659)

* Adopt autograd.record() context to RNNOp (apache#16657)

* Use memcopy instead of set_handle when num_layer=0, direction=1 (apache#16663)

* fallback mkldnn fc bwd in imperative mode (apache#16672)

* disable MKLDNN FC backward

* [mkldnn-v1.0] Must reorder and emplace weights for inference primitives (apache#16682)

* add default parameter for mkldnn rnn
@szha szha deleted the mkldnn-v1.0 branch September 19, 2020 03:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet