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

[MKLDNN] reorder the mem format for the AddBack mode in case src & dst is different #11095

Closed
wants to merge 1 commit into from

Conversation

pengzhao-intel
Copy link
Contributor

Description

For MKL-DNN backend, the case is not covered that the src format is not as same as dst format for the AddBack mode. So the crash is observed in example/reinforcement-learning/a3c.

Therefore, the fix is to reorder the src format to dst format when the difference is detected.

The A3C case can pass with the fix. And verified the performance by benchmark_score.py, there's no performance effect.

@zheng-da @TaoLv

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

  • 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

@@ -128,8 +128,14 @@ void CommitOutput(const NDArray &arr, const mkldnn_output_t &res) {
if (res.first == CopyBack) {
const_cast<NDArray &>(arr).CopyFrom(*res.second);
} else if (res.first == AddBack) {
auto mem = arr.GetMKLDNNData(res.second->get_primitive_desc());
CHECK(mem != nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder whether it works if we just use GetMKLDNNDataReorder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it can work but it will be a little confusion to call reorder API for all cases.

@zheng-da
Copy link
Contributor

could you please add a test case?

@pengzhao-intel
Copy link
Contributor Author

The crash happens in the backward of convolution when updating the weights.

It's not easy to create the python level test case w/ the different memory format of the ndarray.

Maybe we can add a CPP case along with @juliusshufan 's CPP cases.

@pengzhao-intel
Copy link
Contributor Author

The fix and test will be merged by #11129
Close this one.

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.

2 participants