-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Move bounds checks on copyto!(dst, n, src)
#43517
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b50992f
faster copyto
mcabbott 8597c9a
update to N5N3's suggestion
mcabbott 559bcb6
method for copyto!(dest, src) too
mcabbott 05b055d
Revert "update to N5N3's suggestion"
mcabbott 58ad472
replace nextind with i+1
mcabbott 7131982
revert copyto!(dest, src)
mcabbott 1d0bfdb
fix an empty case, add tests
mcabbott 79de34d
Merge branch 'master' into copyto
KristofferC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How about replace this with
Might be faster for
IndexCartesian
cases.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.
And it seems reasonable to improve
copyto!(dest::AbstractArray, src)
(L893) in this PR.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.
Using
eachindex(dest)[i]
doesn't seem to help, on things I tried.But I agree that the whole-array method just above has room for comparable improvement.
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.
I could see some difference in the following example:
For longer
src
or higher dimension, the gain might be bigger?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 when I thought I'd convinced myself... these give me:
This does not affect the 2-arg method?
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.
As for 2-arg version on
M1 native, master
.I think the problem is
firstindex
always return1
ifndims != 1
. Usefirst(eachindex(dest))
should make things consistent.On the other hand, just notice that
nextind(A, ind::Base.SCartesianIndex2)
is not defined, sodest
can't bereinterpret(reshape, args...)
...Not sure is it ok to add related definition in this PR? Or just use
eachindex(IndexStyle(dest) isa IndexLinear ? IndexLinear() : IndexCartesian(), dest)
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.
Ok, good point re firstindex. So that's just handling offsets right now.
On the xeon, "g" is still an improvement on
Base.copyto!
, even if slower than "f" there. Is that true on your computer too?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.
Well that's true, at least we eliminated the
boundscheck
within the loop.I have no M1 machine, so I can't test myself.
Would you mind to bench the following?
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.
Sure:
vs xeon:
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.
On my machine, the result is
Is this some "dark magic" of M1? (Maybe we don't need
IndexCartesian
on M1?)Something might related: M1 10x faster than Intel at integral division, throughput one 64-bit divide in two cycles
If this is true, I guess
reshape
would be faster if we omit the current optimization viaMultiplicativeInverse