-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Optimize view_as_complex and view_as_real #44908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
aten/src/ATen/native/ComplexHelper.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious if there's a reason why back() is more preferable thank emplace_back()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterbell10 pre-allocated the size of res to avoid a (possible) reallocation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, emplace_back inserts a new element while back is just a shorthand for indexing the last element.
anjali411
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thank you!
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anjali411 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@peterbell10 I see some internal test failures which are probably unrelated. can you rebase this PR? |
Avoid unnecessary memory allocations by not constructing a new storage object and using DimVector to store new sizes and strides.
ab856e7 to
a7ec88f
Compare
💊 CI failures summary and remediationsAs of commit a7ec88f (more details on the Dr. CI page):
XLA failureJob pytorch_xla_linux_bionic_py3_6_clang9_build is failing. Please create an issue with title prefixed by 🚧 1 fixed upstream failure:These were probably caused by upstream breakages that were already fixed.
Please rebase on the
|
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anjali411 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@anjali411 merged this pull request in 0806c58. |
This avoids unnecessary memory allocations in
view_as_complexandview_as_real. I construct the new tensor directly with the existing storage to avoid creating a new storage object and also useDimVectors to avoid allocating for the sizes and strides. Overall, this saves about 2 us of overhead fromtorch.fft.fftwhich currently has to callview_as_realandview_as_complexfor every call.I've used this simple benchmark to measure the overhead:
Results before:
and after: