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

[MXNET-486] Create CPP test for concat MKLDNN operator #11371

Merged
merged 91 commits into from
Jun 29, 2018

Conversation

azai91
Copy link
Contributor

@azai91 azai91 commented Jun 22, 2018

Description

Add test for MKLDNN concat forward / backward operator

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

  • Add test for MKLDNN concat forward / backward operator
  • Modify GetTestInputArrays / GetOutputInputArrays to support num_inputs / dim so that the inputs / outputs can be scaled (used to create larger ndarrays scaled by num_inputs on dim)

Comments

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

@azai91
Copy link
Contributor Author

azai91 commented Jun 28, 2018

@pengzhao-intel

@pengzhao-intel
Copy link
Contributor

LGTM :) Thanks for the test and fix.

@@ -804,6 +1014,24 @@ TEST(IMPERATIVE, SumBackwardsOp) {
TestOp(attrs, VerifySumBackwardsResult);
}

TEST(IMPERATIVE, ConcatOp) {
for (int num_inputs = 2; num_inputs < 3; num_inputs++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you only test num_inputs=2 and write the code like this?

for (auto &dispatch : dispatches) {
std::vector<std::vector<NDArrayAttrs>> out_arrs(attrs.num_outputs);
for (int i = 0; i < attrs.num_outputs; i++)
out_arrs[i] = GetTestOutputArrays(in_arr.arr.shape(), pds);
Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't seem out_arrs generated here is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted dup.

}

TEST(IMPERATIVE, ConcatBackwardsOp) {
for (int num_inputs = 2; num_inputs < 3; num_inputs++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the same comment for here.

@szha szha merged commit af4a600 into apache:master Jun 29, 2018
XinYao1994 pushed a commit to XinYao1994/incubator-mxnet that referenced this pull request Aug 29, 2018
* create func to generate new outputs for concat output

* provide type for vectors

* fix concat dict

* change value to string

* use different datatype

* create GetExpandedMemPD helper

* update input num

* fix dim range

* use only new shape

* add comments

* replace all with new_shape

* consolidate testop

* remove init interface

* use GetTestOutputArraysConcat for concat op

* out arrays in correct scope

* add VerifyConcatResult

* noop for kWriteInPlace for concat

* refactor GetTestOutputArrays and GetTestOutputArraysConcat into one method

* create temp ndarrays in same scope as assert

* add message for GetTestOutputArraysConcat

* filter when dim too large

* fix print message

* reshape concat output so it can be read

* check concat on diff dim

* add VerifyConcatBackwardsResult bp

* reshape if view and mkldnn

* finish VerifyConcatBackwardsResult

* reverse input output for concat backwards

* do not rand output for concat backwards

* make mulitple copies of inputs for ops that need mult unique inputs

* swap input/output msg

* create test inputs can create expanded inputs

* add verify msg to test

* fix slice of input

* remove unused test

* missing assignment

* fix slice amount for diff dim concat

* shrink outputs for concat backwards

* revert switching input/output for concat/backwards

* create multiple copies of output

* reorder concat input grad

* increase num of input for concat backwards

* concat dst is smaller array

* use output vs input mem to determine shape and as tmp storage

* do not support mkldnn concat if mkl layout diff from nd layout

* reorder if view /mkldnn

* exclude views from concat

* remove unused header

* remove check for view in mkldnn_concat

* remove unused heaeder

* skip test

* rename target_shape to shape

* remove rand var and default outputs to rand

* rename target_pd to pd

* fix lint issues

* add space to error msg

* do not use mkldnn for forward concat if layout mismatch

* create temp shape var

* do not check if view in concat

* convert dim to unsigned int

* fix lint

* check view first

* check type before creating mem

* check all inputs for concat mkldnn

* remove getshapestring

* add comments for verify concat helpres

* revert adding USE_MKLDNN flag

* use reference for arrays in concat mkldnn check

* fix indent

* set default num_inputs to 1

* revert change to test_ctc_loss_train

* add error message to check

* use reference of arr in loops

* remove extra space

* use default num_inputs

* use reference for all loops

* fix lint

* use separate concat test

* remove reference from pd

* do not use reference for shape

* change conditional in gettestinputarray

* remove reference

* fix lint

* increase num_inputs to 3

* remove extra out_arr var

* retrigger

* increase num_inputs
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants