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

Add primitive cache for MKL-DNN sum(elemwise_add operator #14914

Merged
merged 2 commits into from May 15, 2019

Conversation

ciyongch
Copy link
Contributor

@ciyongch ciyongch commented May 8, 2019

Description

This PR cached the created sum primitive to reduce the creation overhead, which is helpful to improve the performance of current MKL-DNN sum (elemwise_add) 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://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

@pengzhao-intel @TaoLv

@pengzhao-intel
Copy link
Contributor

Thanks for the improvements. Could you share the performance data?

@vandanavk
Copy link
Contributor

@mxnet-label-bot add [pr-awaiting-review, MKLDNN]

@ciyongch
Copy link
Contributor Author

ciyongch commented May 9, 2019

Here's some performance data I collected based on a customer case, primitive cached brings ~1.6x speedup for elemwise_add operator, which help to reduce the overall percentage:

1) Don't cached sum primitive (current code base)

Op name total time(ms) ave time (ms) ncalls percentage
elemwise_add 382.533 0.4 920 24.96%

2) cached sum primitive

Op name total time(ms) ave time (ms) ncalls percentage
elemwise_add 230.243 0.25 920 18.29%

int ndim = input.shape().ndim();
return input.dtype() == mshadow::kFloat32 && (ndim >= 1 && ndim <= 4) &&
input.storage_type() == kDefaultStorage;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't put this function into mkldnn_base-inl.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, some MKLDNN ops supports ndim [1, 4], while some ops still doesn't support ndim=3.
For now, there would be several such support check functions for different ops.
But indeed, we can combine all the similar function when all the ops are finalized.

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.

This is the common approach for MKL-DNN integration so it looks good.

CPU Performance and Quantization automation moved this from Review in progress to Reviewer approved May 9, 2019
@pengzhao-intel
Copy link
Contributor

Merging now. Thanks for your contribution.

@pengzhao-intel pengzhao-intel merged commit c5265fb into apache:master May 15, 2019
CPU Performance and Quantization automation moved this from Reviewer approved to Done May 15, 2019
eric-haibin-lin pushed a commit that referenced this pull request May 22, 2019
* Add primitive cache for mkldnn sum

* fix cpp test failure
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
* Add primitive cache for mkldnn sum

* fix cpp test failure
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
MKLDNN pr-awaiting-review PR is waiting for code review
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants