Skip to content
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

Unwrap contiguous views in copyto! #56657

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Nov 22, 2024

In copyto!(A, B) where both the arrays use linear indexing, if one or both the arrays are contiguous linear views, we may forward the copyto! to the parents. This ensures that we hit optimized copyto! implementations for the parent, if any. Similarly, for the 5-argument version. In fact, in this PR, we call the 5-argument version within the 2-argument copyto! if both the arrays use linear indexing.

An example of a performance improvement:

julia> v1 = view(rand(4000, 4000), :, :);

julia> B = similar(v1);

julia> @btime copyto!($B, $v1);
  14.257 ms (0 allocations: 0 bytes) # nightly v"1.12.0-DEV.1677"
  8.596 ms (0 allocations: 0 bytes) # this PR

In this case, we dispatch to the optimized copyto!(::Array, ::Integer, ::Array, ::Integer, ::Integer) method by unwrapping the view. This method uses memmove, which is faster than the fallback implementation that uses loops.

@jishnub jishnub added performance Must go faster arrays [a, r, r, a, y, s] labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant