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

ReinterpretArray and IndexStyle #27909

Merged
merged 1 commit into from
Jul 4, 2018
Merged

ReinterpretArray and IndexStyle #27909

merged 1 commit into from
Jul 4, 2018

Conversation

timholy
Copy link
Sponsor Member

@timholy timholy commented Jul 2, 2018

Cartesian indexing has some overhead:

julia> a = rand(3,3,3,3,3,3);

julia> v1 = view(a,:,:,:,:,:,:);

julia> v2 = view(a,1:3,:,:,:,:,:);

julia> IndexStyle(v1)
IndexLinear()

julia> IndexStyle(v2)
IndexCartesian()

julia> using BenchmarkTools

julia> @btime fill!(v1, 0);
  79.435 ns (0 allocations: 0 bytes)

julia> @btime fill!(v2, 0);
  1.813 μs (0 allocations: 0 bytes)

This is why we set IndexStyle(a) == IndexLinear() whenever possible. This PR turns on IndexLinear() for appropriate (I hope!) ReinterpretArrays. Demo:

julia> r = reinterpret(Int64, a);

julia> @btime fill!(r, 0);       # on current master
  34.229 μs (0 allocations: 0 bytes)

julia> Revise.track(Base)        # this PR

julia> @btime fill!(r, 0);
  83.182 ns (0 allocations: 0 bytes)

That's a 400× improvement. Some of this seems likely to be due to the performance optimizations planned in #27213, but as the example above illustrates, I suspect we'd be seeing some substantial performance gains even if all the LLVM optimizations had been applied.

@Keno
Copy link
Member

Keno commented Jul 2, 2018

I think we should be able to turn on IndexLinear for any array as long as the parent is IndexLinear.

@timholy timholy force-pushed the teh/indexlinear_reinterpret branch from e83f4b6 to 735afa9 Compare July 3, 2018 12:16
@timholy
Copy link
Sponsor Member Author

timholy commented Jul 3, 2018

Yeah, makes sense. Try this one.

@Keno Keno merged commit ac5228a into master Jul 4, 2018
@martinholters martinholters deleted the teh/indexlinear_reinterpret branch July 4, 2018 17:46
timholy added a commit that referenced this pull request Jul 12, 2018
Not sure whether we had this and lost it as a consequence of #27909,
or whether we never had it. At any rate, this adds tests so it should
be easy to keep henceforth.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants