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

[MXNET-483] C++ tests for mkldnn convolution/deconvolution operator #11778

Merged
merged 98 commits into from
Nov 20, 2018

Conversation

azai91
Copy link
Contributor

@azai91 azai91 commented Jul 17, 2018

Description

Add tests for MKLDNN convolution / deconvolution operator. Need to convert MKLDNN conv/deconv inputs if they are views (#12303).

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 http://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

  • Add tests for MKLDNN convolution / deconvolution operator
  • Reorder inputs of conv / deconv mkldnn inputs if MKLDNN and view.

Comments

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

@azai91 azai91 requested a review from anirudh2290 as a code owner July 17, 2018 07:02
@azai91 azai91 changed the title [MXNET-483] C++ tests for convolution operator [MXNET-483] C++ tests for mkldnn convolution operator Jul 19, 2018
@azai91
Copy link
Contributor Author

azai91 commented Jul 19, 2018

@zheng-da can you review

@zheng-da
Copy link
Contributor

can you test both conv and deconv? these two operators have almost the same inputs.

@azai91 azai91 force-pushed the test/mkldnn-conv-op branch 5 times, most recently from 1cb5052 to 6750e75 Compare July 31, 2018 00:55
@azai91
Copy link
Contributor Author

azai91 commented Aug 1, 2018

@mseth10 please take a look as well

backwards_ex_outputs[2] = &tmp_bias2;

for (int i = 0; i < backwards_attrs.num_outputs; i++)
back_req[0] = kWriteTo;
Copy link
Contributor

Choose a reason for hiding this comment

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

only WriteTo? I think you should test AddTo as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@azai91 azai91 force-pushed the test/mkldnn-conv-op branch 2 times, most recently from 0bba2a0 to d1a6fdb Compare August 2, 2018 21:06
continue;
shape[dim] = shape[dim] * num_inputs;

for (int dim = 0; dim < scale.size(); dim++)
Copy link
Contributor

Choose a reason for hiding this comment

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

right type is size_t, ++dim (pre-increment) is standard C++ idiom


// Type 1.
NDArray arr(shape, Context());
in_arrs.emplace_back(arr, "Normal NDArray");
InitDefaultArray(&in_arrs.back().arr, rand);
for (auto pd : pds) {
if (num_inputs > 1) {
for (int dim = 0; dim < scale.size(); dim++) {
Copy link
Contributor

@larroy larroy Aug 2, 2018

Choose a reason for hiding this comment

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

size_t, otherwise signed vs unsigned comparison warning

@azai91 azai91 force-pushed the test/mkldnn-conv-op branch 4 times, most recently from 56f575d to 6cfd95f Compare August 3, 2018 02:36
@eric-haibin-lin
Copy link
Member

@TaoLv this PR already got many reviews and one approval. Is it okay to merge this PR, or you have further unaddressed comments?

@TaoLv
Copy link
Member

TaoLv commented Nov 14, 2018

@eric-haibin-lin, need @azai91 's inputs about the difference of this PR and #13084.

@azai91
Copy link
Contributor Author

azai91 commented Nov 14, 2018

#13084 is a branch off of this PR that includes the BN unit tests. we should merge this one first and then we can more easily review #13084. @TaoLv @eric-haibin-lin


inline NDArray CreateKernelNDArray(TShape kernel, int num_filters, TShape input,
bool is_deconv = false) {
CHECK(kernel.ndim() == 2) << "mkldnn only supports 2d filters on 4d inputs";
Copy link
Member

Choose a reason for hiding this comment

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

CHECK_EQ

@TaoLv
Copy link
Member

TaoLv commented Nov 14, 2018

  • Please make sure that weight format NDAarray is not send to MKL-DNN operators as input data.
  • Take care of the performance. I have the same concern as @zheng-da .
  • Please clean compile warnings of MKL-DNN cpp tests.

cc @pengzhao-intel

@azai91
Copy link
Contributor Author

azai91 commented Nov 15, 2018

@TaoLv I checked that this PR does not cause regression.

@azai91
Copy link
Contributor Author

azai91 commented Nov 15, 2018

what MKL-DNN warnings? are they introduced in this PR or were they always present? if they were already present, then let's file an issue and tackle in a separate PR.

@TaoLv
Copy link
Member

TaoLv commented Nov 18, 2018

Thanks, @azai91 . I noticed that there were many warnings when built mkldnn cpp test with Makefile. It would be great if you can take a look and fix them. Not necessarily in this PR.

@lupesko
Copy link
Contributor

lupesko commented Nov 19, 2018

@TaoLv and @pengzhao-intel if you are good with this PR, please approve.
This is critical to allow @azai91 to finally get this merged.

} else {
weight_mem = weight.GetMKLDNNData();
CHECK(weight_mem->get_primitive_desc() == fwd_pd.weights_primitive_desc());
}
weight_mem = weight.GetMKLDNNData();
CHECK(weight_mem->get_primitive_desc() == fwd_pd.weights_primitive_desc());
Copy link
Member

Choose a reason for hiding this comment

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

do we need else if these two lines are going to execute irrespective

@anirudh2290
Copy link
Member

The warnings are related to batch norm test and implicit_gemm in mshadow. Since they are not being modified in this PR, I think its fine if they are not fixed in this PR.

@anirudh2290 anirudh2290 merged commit 91c536d into apache:master Nov 20, 2018
@pengzhao-intel
Copy link
Contributor

@azai91 @anirudh2290 thanks for the help and great works to improve the quality of MKL-DNN.

lanking520 added a commit that referenced this pull request Nov 21, 2018
@azai91 azai91 mentioned this pull request Nov 28, 2018
6 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
MKLDNN pr-awaiting-response PR is reviewed and waiting for contributor to respond pr-awaiting-testing PR is reviewed and waiting CI build and test
Projects
None yet
Development

Successfully merging this pull request may close these issues.