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

Unhandled ssa condition #244

Closed
andreasvarga opened this issue Mar 31, 2021 · 1 comment · Fixed by #247
Closed

Unhandled ssa condition #244

andreasvarga opened this issue Mar 31, 2021 · 1 comment · Fixed by #247

Comments

@andreasvarga
Copy link

I am trying to fix some compilation related issues in my package DescriptorSystems. After switching to Julia 1.6, the compilation times are much better. I think this can be also seen from the duration of tests with different Julia versions, which are now about 35% faster than with Julia 1.5 and more than 6 times faster compared to earlier versions. Still I wonder if the latency can be further reduced by clever tricks to arrive to better execution times also for earlier versions of Julia (but this is my problem).

In trying several changes, I got the following error message. I included the whole calling sequence (although the example is not reproducible, being produced with my local development version):

julia> using DescriptorSystems
julia> using SnoopCompile

julia> @time z = rtf('z');     # define the variable z as rational function
  0.171791 seconds (228.97 k allocations: 13.766 MiB, 12.49% gc time, 40.50% compilation time)

julia> @time Gd = [z^2 z/(z-2); 0 1/z];     # define the 2-by-2 improper Gd(z)
  8.056003 seconds (30.14 M allocations: 1.864 GiB, 7.23% gc time, 6.48% compilation time)

julia> tinf = @snoopi_deep sysd = dss(Gd,minimal = true,Ts = 1)
InferenceTimingNode: 15.006795/19.310407 on InferenceFrameInfo for Core.Compiler.Timings.ROOT() with 11 direct children

julia> itrigs = inference_triggers(tinf)
11-element Vector{InferenceTrigger}:
 Inference triggered to call MethodInstance for (NamedTuple{(:minimal, :Ts), T} where T<:Tuple)(::Tuple{Bool, Int64}) from eval (.\boot.jl:360) inlined into MethodInstance for repleval(::Module, ::Expr, ::String) (c:\Users\Andreas\.vscode\extensions\julialang.language-julia-1.1.38\scripts\packages\VSCodeServer\src\repl.jl:124)
 Inference triggered to call MethodInstance for (::DescriptorSystems.var"#dss##kw")(::NamedTuple{(:minimal, :Ts), Tuple{Bool, Int64}}, ::typeof(dss), ::Matrix{RationalTransferFunction{Int64, :z}}) from eval (.\boot.jl:360) inlined into MethodInstance for repleval(::Module, ::Expr, ::String) (c:\Users\Andreas\.vscode\extensions\julialang.language-julia-1.1.38\scripts\packages\VSCodeServer\src\repl.jl:124)
 Inference triggered to call MethodInstance for typed_hvcat(::Type{Float64}, ::Tuple{Int64, Int64}, ::Matrix{Float64}, ::Vararg{Matrix{Float64}, N} where N) from hvcat (C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\SparseArrays\src\sparsevector.jl:1122) inlined into MethodInstance for var"#rm2ls#139"(::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Float64, ::Float64, ::typeof(MatrixPencils.rm2ls), ::Array{Int64, 3}, ::Array{Int64, 3}) (C:\Users\Andreas\.julia\packages\MatrixPencils\K7lzh\src\rmtools.jl:314)
 Inference triggered to call MethodInstance for hvcat(::Tuple{Int64, Int64}, ::LinearAlgebra.UniformScaling{Bool}, ::Vararg{Union{LinearAlgebra.UniformScaling, AbstractVecOrMat{T} where T}, N} where N) from #rm2ls#139 (C:\Users\Andreas\.julia\packages\MatrixPencils\K7lzh\src\rmtools.jl:315) with specialization MethodInstance for var"#rm2ls#139"(::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Float64, ::Float64, ::typeof(MatrixPencils.rm2ls), ::Array{Int64, 3}, ::Array{Int64, 3})
 Inference triggered to call MethodInstance for require_one_based_indexing(::LinearAlgebra.UniformScaling{Bool}, ::Vararg{Any, N} where N) from hvcat (C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\uniformscaling.jl:408) with specialization MethodInstance 
for hvcat(::Tuple{Int64, Int64}, ::LinearAlgebra.UniformScaling{Bool}, ::Vararg{Union{LinearAlgebra.UniformScaling, AbstractVecOrMat{T} where T}, N} where N)
 Inference triggered to call MethodInstance for has_offset_axes(::LinearAlgebra.UniformScaling{Bool}, ::Matrix{Float64}, ::Vararg{Matrix{Float64}, 
N} where N) from require_one_based_indexing (.\abstractarray.jl:103) with specialization MethodInstance for require_one_based_indexing(::LinearAlgebra.UniformScaling{Bool}, ::Vararg{Any, N} where N)
 Inference triggered to call MethodInstance for _tuple_any(::typeof(Base.has_offset_axes), ::Bool, ::Matrix{Float64}, ::Matrix{Float64}, ::Vararg{Any, N} where N) from _tuple_any (.\tuple.jl:497) with specialization MethodInstance for _tuple_any(::typeof(Base.has_offset_axes), ::Bool, ::LinearAlgebra.UniformScaling{Bool}, ::Matrix{Float64}, ::Vararg{Matrix{Float64}, N} where N)
 Inference triggered to call MethodInstance for hvcat(::Tuple{Int64, Int64}, ::Matrix{Bool}, ::Vararg{Union{LinearAlgebra.AbstractTriangular{T, A} 
where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Adjoint{var"#s832", var"#s831"} where {var"#s832", var"#s831"<:(Vector{T} where T)}, LinearAlgebra.Hermitian{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Symmetric{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Transpose{var"#s830", var"#s829"} where {var"#s830", var"#s829"<:(Vector{T} where T)}, Matrix{T} where T, Vector{T} where T}, N} where N) from hvcat (C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\uniformscaling.jl:459) with specialization MethodInstance for hvcat(::Tuple{Int64, Int64}, ::LinearAlgebra.UniformScaling{Bool}, ::Vararg{Union{LinearAlgebra.UniformScaling, AbstractVecOrMat{T} where T}, N} where N)       
 Inference triggered to call MethodInstance for promote_eltype(::Matrix{Bool}, ::Matrix{Float64}, ::Vararg{Matrix{Float64}, N} where N) from hvcat 
(C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\SparseArrays\src\sparsevector.jl:1117) with specialization MethodInstance for hvcat(::Tuple{Int64, Int64}, ::Matrix{Bool}, ::Vararg{Union{LinearAlgebra.AbstractTriangular{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Adjoint{var"#s832", var"#s831"} where {var"#s832", var"#s831"<:(Vector{T} where T)}, LinearAlgebra.Hermitian{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Symmetric{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Transpose{var"#s830", var"#s829"} where {var"#s830", var"#s829"<:(Vector{T} where T)}, Matrix{T} where T, Vector{T} where T}, N} where N)
 Inference triggered to call MethodInstance for promote_eltype(::Matrix{Float64}, ::Matrix{Float64}, ::Vararg{Matrix{Float64}, N} where N) from promote_eltype (.\abstractarray.jl:1463) with specialization MethodInstance for promote_eltype(::Matrix{Bool}, ::Matrix{Float64}, ::Vararg{Matrix{Float64}, N} where N)
 Inference triggered to call MethodInstance for typed_hvcat(::Type{Float64}, ::Tuple{Int64, Int64}, ::Matrix{Bool}, ::Vararg{AbstractVecOrMat{T} where T, N} where N) from hvcat (C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\SparseArrays\src\sparsevector.jl:1117) with specialization MethodInstance for hvcat(::Tuple{Int64, Int64}, ::Matrix{Bool}, ::Vararg{Union{LinearAlgebra.AbstractTriangular{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Adjoint{var"#s832", var"#s831"} where {var"#s832", var"#s831"<:(Vector{T} where T)}, LinearAlgebra.Hermitian{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Symmetric{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Transpose{var"#s830", var"#s829"} where {var"#s830", var"#s829"<:(Vector{T} where T)}, Matrix{T} where T, Vector{T} where T}, N} where N)

julia> itree = trigger_tree(itrigs)
TriggerNode for root with 2 direct children

julia> suggest(itree.children[2])
ERROR: unhandled ssa condition on Inference triggered to call MethodInstance for promote_eltype(::Matrix{Bool}, ::Matrix{Float64}, ::Vararg{Matrix{Float64}, N} where N) from hvcat (C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\SparseArrays\src\sparsevector.jl:1117) with specialization MethodInstance for hvcat(::Tuple{Int64, Int64}, ::Matrix{Bool}, ::Vararg{Union{LinearAlgebra.AbstractTriangular{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Adjoint{var"#s832", var"#s831"} where {var"#s832", var"#s831"<:(Vector{T} where T)}, LinearAlgebra.Hermitian{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Symmetric{T, A} where {T, A<:(Matrix{T} where T)}, LinearAlgebra.Transpose{var"#s830", var"#s829"} where {var"#s830", var"#s829"<:(Vector{T} where T)}, Matrix{T} where T, Vector{T} where T}, N} where N)
Stacktrace:
 [1] error(::String, ::InferenceTrigger)
   @ Base .\error.jl:42
 [2] suggest(itrig::InferenceTrigger)
   @ SnoopCompile ~\.julia\packages\SnoopCompile\KNizC\src\parcel_snoopi_deep.jl:1463
 [3] suggest!(stree::AbstractTrees.AnnotationNode{Union{Nothing, SnoopCompile.Suggested}}, node::SnoopCompile.TriggerNode)
   @ SnoopCompile ~\.julia\packages\SnoopCompile\KNizC\src\parcel_snoopi_deep.jl:1636
 [4] suggest!(stree::AbstractTrees.AnnotationNode{Union{Nothing, SnoopCompile.Suggested}}, node::SnoopCompile.TriggerNode) (repeats 2 times)       
   @ SnoopCompile ~\.julia\packages\SnoopCompile\KNizC\src\parcel_snoopi_deep.jl:1638
 [5] suggest(node::SnoopCompile.TriggerNode)
   @ SnoopCompile ~\.julia\packages\SnoopCompile\KNizC\src\parcel_snoopi_deep.jl:1632
 [6] top-level scope
   @ REPL[9]:1

Here is a run which shows that the execution has no errors

julia> using DescriptorSystems

julia> @time z = rtf('z');     # define the variable z as rational function
  0.118549 seconds (221.53 k allocations: 13.317 MiB, 7.37% gc time, 99.84% compilation time)

julia> @time Gd = [z^2 z/(z-2); 0 1/z];
  7.564127 seconds (29.41 M allocations: 1.824 GiB, 6.85% gc time, 6.43% compilation time)

julia> @time sysd = dss(Gd,minimal = true,Ts = 1);
 19.071911 seconds (44.23 M allocations: 2.031 GiB, 4.13% gc time, 100.00% compilation time)

I wonder if the 6.43% compilation time above is the right value (see below).

The potential for improvements can be seen from the following slightly changed run (replaced 0 with zero(z))

julia> using DescriptorSystems

julia> @time z = rtf('z');     # define the variable z as rational function
  0.121656 seconds (221.53 k allocations: 13.317 MiB, 7.15% gc time, 99.83% compilation time)

julia> @time Gd = [z^2 z/(z-2); zero(z) 1/z];
  0.531033 seconds (2.94 M allocations: 174.207 MiB, 6.75% gc time, 99.90% compilation time)

julia> @time sysd = dss(Gd,minimal = true,Ts = 1);
 18.846532 seconds (45.11 M allocations: 2.084 GiB, 4.42% gc time, 100.00% compilation time)
timholy added a commit that referenced this issue Jul 18, 2021
The issue here is a call to
    hvcat(rows::Tuple{Vararg{Int}}, xs::_DenseConcatGroup...) = Base.typed_hvcat(promote_eltype(xs...), rows, xs...)
which has a couple of `Core._apply_iterate` and the matching fails
when it doesn't match the trigger `promote_eltype`.
I tried to come up with a MWE but failed.

Fixes #244
@timholy
Copy link
Owner

timholy commented Jul 18, 2021

Sorry for the delay. Hopefully this will be fixed by #247.

timholy added a commit that referenced this issue Jul 18, 2021
The issue here is a call to
    hvcat(rows::Tuple{Vararg{Int}}, xs::_DenseConcatGroup...) = Base.typed_hvcat(promote_eltype(xs...), rows, xs...)
which has a couple of `Core._apply_iterate` and the matching fails
when it doesn't match the trigger `promote_eltype`.
I tried to come up with a MWE but failed.

Fixes #244
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 a pull request may close this issue.

2 participants