-
Notifications
You must be signed in to change notification settings - Fork 9
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
StackOverflowError in broadcasting #62
Comments
Reduced: julia> using StrideArrays
julia> foo(x, f) = f(x)
foo (generic function with 1 method)
julia> src1 = rand(10); dst = zero(src1);
julia> src1_ptr = PtrArray(src1); dst_ptr = PtrArray(dst);
julia> @. dst = foo(src1, abs)
10-element Vector{Float64}:
0.4497752365375052
0.234212713779973
0.8718344166425321
0.1169076748948169
0.12774646887625019
0.41850986610044205
0.017042548453313433
0.9246865917682306
0.4249229606273417
0.7560184865926094
julia> @. dst_ptr = foo(src1_ptr, abs)
ERROR: StackOverflowError:
Stacktrace:
[1] macro expansion
@ ~/.julia/packages/LoopVectorization/DDH6Z/src/broadcast.jl:530 [inlined]
[2] vmaterialize!(dest::PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, bc::Base.Broadcast.Broadcasted{StrideArrays.CartesianStyle{Tuple{Int64}, 1}, Nothing, typeof(foo), Tuple{PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, Base.RefValue{typeof(abs)}}}, #unused#::Val{:StrideArrays}, #unused#::Val{(true, 0, 0, 0, true, 4, 32, 15, 64, 0x0000000000000001, 0, true)}, #unused#::Val{((true,), ())})
@ LoopVectorization ~/.julia/packages/LoopVectorization/DDH6Z/src/broadcast.jl:530
[3] vmaterialize!(dest::PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, bc::Base.Broadcast.Broadcasted{StrideArrays.CartesianStyle{Tuple{Int64}, 1}, Nothing, typeof(foo), Tuple{PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, Base.RefValue{typeof(abs)}}}, #unused#::Val{:StrideArrays}, #unused#::Val{(true, 0, 0, 0, true, 4, 32, 15, 64, 0x0000000000000001, 0, true)})
@ LoopVectorization ~/.julia/packages/LoopVectorization/DDH6Z/src/broadcast.jl:664
[4] _materialize!(dest::PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, bc::Base.Broadcast.Broadcasted{StrideArrays.CartesianStyle{Tuple{Int64}, 1}, Nothing, typeof(foo), Tuple{PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, Base.RefValue{typeof(abs)}}}, #unused#::Val{(true, 0, 0, 0, true, 4, 32, 15, 64, 0x0000000000000001, 0, true)})
@ StrideArrays ~/.julia/dev/StrideArrays/src/broadcast.jl:178
[5] materialize!(dest::PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, bc::Base.Broadcast.Broadcasted{StrideArrays.CartesianStyle{Tuple{Int64}, 1}, Nothing, typeof(foo), Tuple{PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, Base.RefValue{typeof(abs)}}})
@ StrideArrays ~/.julia/dev/StrideArrays/src/broadcast.jl:185
--- the last 5 lines are repeated 19994 more times ---
[99976] macro expansion
@ ~/.julia/packages/LoopVectorization/DDH6Z/src/broadcast.jl:530 [inlined]
[99977] vmaterialize!(dest::PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, bc::Base.Broadcast.Broadcasted{StrideArrays.CartesianStyle{Tuple{Int64}, 1}, Nothing, typeof(foo), Tuple{PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, Base.RefValue{typeof(abs)}}}, #unused#::Val{:StrideArrays}, #unused#::Val{(true, 0, 0, 0, true, 4, 32, 15, 64, 0x0000000000000001, 0, true)}, #unused#::Val{((true,), ())})
@ LoopVectorization ~/.julia/packages/LoopVectorization/DDH6Z/src/broadcast.jl:530
[99978] vmaterialize!(dest::PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, bc::Base.Broadcast.Broadcasted{StrideArrays.CartesianStyle{Tuple{Int64}, 1}, Nothing, typeof(foo), Tuple{PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, Base.RefValue{typeof(abs)}}}, #unused#::Val{:StrideArrays}, #unused#::Val{(true, 0, 0, 0, true, 4, 32, 15, 64, 0x0000000000000001, 0, true)})
@ LoopVectorization ~/.julia/packages/LoopVectorization/DDH6Z/src/broadcast.jl:664
[99979] _materialize!(dest::PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, bc::Base.Broadcast.Broadcasted{StrideArrays.CartesianStyle{Tuple{Int64}, 1}, Nothing, typeof(foo), Tuple{PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}, Base.RefValue{typeof(abs)}}}, #unused#::Val{(true, 0, 0, 0, true, 4, 32, 15, 64, 0x0000000000000001, 0, true)})
@ StrideArrays ~/.julia/dev/StrideArrays/src/broadcast.jl:178 |
As far as I understand, StrideArrays.jl prepares everything and hands it over to LoopVectorization.jl. In |
Is there a temporary workaround for this? |
I am not sure but I think this used to work with some version of StrideArrays/StrideArraysCore/LoopVectorization. Do you have the bandwidth to bisect the versions of these packages to find the problematic change, @efaulhaber? |
I can try and see how far I come before I run out of bandwidth. |
Okay, here is what I found:
This doesn't change when I update LoopVectorization to the latest version while keeping StrideArrays at v0.1.19. |
So it was the change JuliaSIMD/LoopVectorization.jl@v0.12.128...v0.12.129 The MWE above works again if we set julia> begin
using StrideArrays
foo(x, f) = f(x)
StrideArrays.LoopVectorization.can_turbo(::typeof(foo), ::Val{2}) = true
src1 = rand(10); dst = zero(src1);
src1_ptr = PtrArray(src1); dst_ptr = PtrArray(dst);
@. dst = foo(src1, abs)
@. dst_ptr = foo(src1_ptr, abs)
end
10-element PtrArray{Tuple{Int64}, (true,), Float64, 1, 1, 0, (1,), Tuple{StaticInt{8}}, Tuple{StaticInt{1}}}:
0.21757498850961488
0.08772365981125829
0.9338368308540324
0.47094465360632565
0.6707104502974711
0.20925363260701946
0.628131138456404
0.013161734404078751
0.5928102226448883
0.6575575585083866 |
@chriselrod What is the recommended way to get |
Does that mean that we will always run into a stack overflow whenever we do something like this without setting |
Yes |
Sorry for dragging my feet on this. I'll take a look in a couple hours. |
I've implemented a hotfix in #62 by disabling the change ( I do think If someone wants to re-enable or improve See the relevant code here: julia> using LoopVectorization, VectorizationBase
julia> Base.promote_op(+, Vec{2,Int}, Vec{2,Int}) !== Union{}
true
julia> foo(x, f) = f(x)
foo (generic function with 1 method)
julia> Base.promote_op(foo, Vec{2,Int}, Vec{2,Int}) !== Union{}
false
julia> Base.promote_op(foo, Vec{2,Int}, typeof(abs)) !== Union{}
true Obviously, calling But that's a pretty naive guess, to put it mildly. I think there's at least two approaches that would work.
julia> ls.operations # ls is a LoopSet object
4-element Vector{LoopVectorization.Operation}:
var"###temp###9###" = var"######arg###8######10###"[var"###n###1###"]
var"######arg###11######13###" = 0
destination = var"###func###6###"(var"###temp###9###", var"######arg###11######13###")
dest[var"###n###1###"] = destination
julia> ls.operations[3]
destination = var"###func###6###"(var"###temp###9###", var"######arg###11######13###")
julia> ls.operations[3]. # tab to look at completion candidates
children dependencies elementbytes identifier instruction
mangledvariable node_type parents reduced_children reduced_deps
ref rejectcurly rejectinterleave u₁unrolled u₂unrolled
variable vectorized
julia> ls.operations[3].parents
2-element Vector{LoopVectorization.Operation}:
var"###temp###9###" = var"######arg###8######10###"[var"###n###1###"]
var"######arg###11######13###" = 0
julia> ls.operations[3].parents[2]
var"######arg###11######13###" = 0 The three easiest ways to get a
Anyway, you should be able to just iterate over the arguments to a function call, and then decide what to do. A simple approach would be:
"3." will be what fixes the problem here, as you can see above where |
Thanks a lot for the hotfix, @chriselrod! I can confirm that it fixes the original issue reported in #60 (comment) |
Feel free to close this - or leave it open as a reference to the better fix described above |
Reported by @efaulhaber in #60 (comment)
The text was updated successfully, but these errors were encountered: