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

Conversation

@asitstands
Copy link
Contributor

@asitstands asitstands commented Mar 31, 2018

Description

For multidimensional arrays on CPU, mx.random.shuffle implements Fisher-Yates algorithm which needs n number of swaps of two memory ranges where n is the length of the first axis. Previously the swap is performed by std::swap_ranges. This PR replaces it with a manual swap using std::memcpy. This brings a good performance gain. For example, shuffling of arrays with shape (1000, 10000) is almost ten times faster in linux/g++-6.4.1 and linux/clang++-6.0. (1D arrays on CPU and arrays on GPU are not in the scope of this PR.)

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

@asitstands asitstands requested a review from cjolivier01 as a code owner March 31, 2018 09:30
@asitstands
Copy link
Contributor Author

@reminisce @marcoabreu

@marcoabreu marcoabreu requested a review from reminisce March 31, 2018 12:22
CHECK_GT(first_axis_len, 0U);
const size_t stride_bytes = sizeof(DType) * stride;
Tensor<cpu, 1, char> buf =
ctx.requested[1].get_space_typed<cpu, 1, char>(Shape1(stride_bytes), ctx.get_stream<cpu>());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to add Fresources to operator registration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is there because the GPU version already needed a temp space.

@piiswrong piiswrong merged commit b37b3f5 into apache:master Apr 2, 2018
lanking520 pushed a commit to lanking520/incubator-mxnet that referenced this pull request Apr 2, 2018
@asitstands asitstands deleted the shuffle_memcpy branch May 22, 2018 07:16
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
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.

3 participants