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

Latency analysis with SnoopCompile #877

Open
IanButterworth opened this issue Jan 9, 2021 · 0 comments
Open

Latency analysis with SnoopCompile #877

IanButterworth opened this issue Jan 9, 2021 · 0 comments

Comments

@IanButterworth
Copy link
Contributor

IanButterworth commented Jan 9, 2021

I thought I'd see what the new SnoopCompile tooling shows for Zygote. If I can figure out any fixes I'll start a PR. Tips/suggestions welcome!

julia % ./julia --startup-file=no
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.0-DEV.241 (2021-01-09)
 _/ |\__'_|_|_|\__'_|  |  Commit 1393310fc7 (0 days old master)
|__/                   |

julia> versioninfo()
Julia Version 1.7.0-DEV.241
Commit 1393310fc7 (2021-01-09 20:02 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin20.2.0)
  CPU: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.0 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 6

(@v1.7) pkg> st
Status `~/.julia/environments/v1.7/Project.toml`
  [aa65fe97] SnoopCompile v2.3.0
  [e2b509da] SnoopCompileCore v2.3.0
  [e88e6eb3] Zygote v0.6.0 `~/.julia/dev/Zygote`

julia> using SnoopCompileCore

julia> invalidations = @snoopr using Zygote;

julia> using SnoopCompile

julia> trees = invalidation_trees(invalidations)
14-element Vector{SnoopCompile.MethodInvalidations}:
 inserting convert(::Type{var"#s4"} where var"#s4"<:Tuple, comp::ChainRulesCore.Composite{var"#s3", var"#s2"} where var"#s2"<:Tuple where var"#s3") in ChainRulesCore at /Users/ian/.julia/packages/ChainRulesCore/cpHLu/src/differentials/composite.jl:68 invalidated:
   mt_backedges: 1: signature Tuple{typeof(convert), Type{Tuple{DataType, DataType, DataType}}, Any} triggered MethodInstance for Pair{DataType, Tuple{DataType, DataType, DataType}}(::Any, ::Any) (0 children)
                 2: signature Tuple{typeof(convert), Type{NTuple{8, DataType}}, Any} triggered MethodInstance for Pair{DataType, NTuple{8, DataType}}(::Any, ::Any) (0 children)
                 3: signature Tuple{typeof(convert), Type{NTuple{7, DataType}}, Any} triggered MethodInstance for Pair{DataType, NTuple{7, DataType}}(::Any, ::Any) (0 children)
                 4: signature Tuple{typeof(convert), Type{Tuple{Symbol, Any, Symbol, Symbol}}, Any} triggered MethodInstance for setindex!(::Vector{Tuple{Symbol, Any, Symbol, Symbol}}, ::Any, ::Int64) (0 children)
                 5: signature Tuple{typeof(convert), Type{Tuple{Base.UUID, String}}, Any} triggered MethodInstance for setindex!(::Vector{Tuple{Base.UUID, String}}, ::Any, ::Int64) (0 children)
                 6: signature Tuple{typeof(convert), Type{Tuple{Any, String}}, Any} triggered MethodInstance for setindex!(::Vector{Tuple{Any, String}}, ::Any, ::Int64) (0 children)

 inserting *(s, comp::ChainRulesCore.Composite) in ChainRulesCore at /Users/ian/.julia/packages/ChainRulesCore/cpHLu/src/differential_arithmetic.jl:138 invalidated:
   mt_backedges: 1: signature Tuple{typeof(*), Union{Regex, String}, Any} triggered MethodInstance for *(::Any, ::Char, ::Any) (0 children)

 inserting getproperty(::StaticArrays.SOneTo{n}, s::Symbol) where n in StaticArrays at /Users/ian/.julia/packages/StaticArrays/LJQEe/src/SOneTo.jl:57 invalidated:
   backedges: 1: superseding getproperty(x, f::Symbol) in Base at Base.jl:33 with MethodInstance for getproperty(::AbstractUnitRange, ::Symbol) (1 children)
   7 mt_cache

 inserting prewalk(f, ir::Union{IRTools.Inner.Block, IRTools.Inner.IR}) in IRTools.Inner at /Users/ian/.julia/packages/IRTools/aSVI5/src/ir/utils.jl:53 invalidated:
   backedges: 1: superseding prewalk(f, x) in MacroTools at /Users/ian/.julia/packages/MacroTools/gME9C/src/utils.jl:134 with MethodInstance for MacroTools.prewalk(::typeof(MacroTools.rmlines), ::Any) (1 children)
   19 mt_cache

 inserting mightalias(x::AbstractArray, y::ForwardDiff.Partials) in ForwardDiff at /Users/ian/.julia/packages/ForwardDiff/qTmqf/src/partials.jl:31 invalidated:
   backedges: 1: superseding mightalias(A::AbstractArray, B::AbstractArray) in Base at abstractarray.jl:1378 with MethodInstance for Base.mightalias(::Vector{Pair{DataType, Function}}, ::AbstractArray) (1 children)

 inserting Base.IteratorSize(::Type{var"#s45"} where var"#s45"<:(Zygote.Buffer{var"#s44", A} where var"#s44")) where A in Zygote at /Users/ian/.julia/dev/Zygote/src/tools/buffer.jl:79 invalidated:
   backedges: 1: superseding Base.IteratorSize(::Type) in Base at generator.jl:92 with MethodInstance for Base.IteratorSize(::Type{var"#s445"} where var"#s445"<:LinearAlgebra.Factorization{T} where T) (3 children)
   42 mt_cache

 inserting (::Type{SSC})(a::AbstractVector{T} where T) where SSC<:StaticArrays.SHermitianCompact in StaticArrays at /Users/ian/.julia/packages/StaticArrays/LJQEe/src/SHermitianCompact.jl:87 invalidated:
   backedges: 1: superseding Union{}(a...) in Core at boot.jl:260 with MethodInstance for Union{}(::AbstractArray) (2 children)
              2: superseding Union{}(a...) in Core at boot.jl:260 with MethodInstance for Union{}(::Vector{var"#s122"} where var"#s122"<:Union{Float32, Float64}) (2 children)
   1 mt_cache

 inserting similar(::Type{A}, shape::Tuple{Union{Integer, Base.OneTo, StaticArrays.SOneTo}, Vararg{Union{Integer, Base.OneTo, StaticArrays.SOneTo}}}) where A<:AbstractArray in StaticArrays at /Users/ian/.julia/packages/StaticArrays/LJQEe/src/abstractarray.jl:153 invalidated:
   mt_backedges: 1: signature Tuple{typeof(similar), Type{Array{Any, _A}} where _A, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Type{Array{Any, _A}}, ::Union{Integer, AbstractUnitRange}) where _A (0 children)
                 2: signature Tuple{typeof(similar), Type{Array{_A, _B}} where _B where _A, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Type{Array{_A, _B}}, ::Union{Integer, AbstractUnitRange}) where {_A, _B} (0 children)
                 3: signature Tuple{typeof(similar), Type{Array{String, _A}} where _A, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Type{Array{String, _A}}, ::Union{Integer, AbstractUnitRange}) where _A (0 children)
                 4: signature Tuple{typeof(similar), Type{Array{Expr, _A}} where _A, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Type{Array{Expr, _A}}, ::Union{Integer, AbstractUnitRange}) where _A (0 children)
                 5: signature Tuple{typeof(similar), Type{Array{Any, _A}} where _A, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Type{Array{Any, _A}}, ::Tuple{Union{Integer, Base.OneTo}}) where _A (2 children)
                 6: signature Tuple{typeof(similar), Type{Array{_A, _B}} where _B where _A, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Type{Array{_A, _B}}, ::Tuple{Union{Integer, Base.OneTo}}) where {_A, _B} (2 children)
                 7: signature Tuple{typeof(similar), Type{Array{String, _A}} where _A, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Type{Array{String, _A}}, ::Tuple{Union{Integer, Base.OneTo}}) where _A (2 children)
                 8: signature Tuple{typeof(similar), Type{Array{Expr, _A}} where _A, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Type{Array{Expr, _A}}, ::Tuple{Union{Integer, Base.OneTo}}) where _A (2 children)

 inserting similar(A::AbstractArray, ::Type{T}, shape::Tuple{Union{Integer, Base.OneTo, StaticArrays.SOneTo}, Vararg{Union{Integer, Base.OneTo, StaticArrays.SOneTo}}}) where T in StaticArrays at /Users/ian/.julia/packages/StaticArrays/LJQEe/src/abstractarray.jl:152 invalidated:
   mt_backedges: 1: signature Tuple{typeof(similar), Vector{Union{Int64, Symbol}}, Type{Union{Int64, Symbol}}, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Vector{Union{Int64, Symbol}}, ::Type{Union{Int64, Symbol}}, ::Union{Integer, AbstractUnitRange}) (0 children)
                 2: signature Tuple{typeof(similar), Vector{T} where T, Type, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Vector{T} where T, ::Type{T}, ::Union{Integer, AbstractUnitRange}) where T (0 children)
                 3: signature Tuple{typeof(similar), Vector{T} where T, DataType, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Vector{T} where T, ::DataType, ::Union{Integer, AbstractUnitRange}) (0 children)
                 4: signature Tuple{typeof(similar), Vector{Symbol}, Type{Symbol}, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Vector{Symbol}, ::Type{Symbol}, ::Union{Integer, AbstractUnitRange}) (0 children)
                 5: signature Tuple{typeof(similar), Vector{Union{Int64, Symbol}}, Type{Union{Int64, Symbol}}, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Vector{Union{Int64, Symbol}}, ::Type{Union{Int64, Symbol}}, ::Tuple{Union{Integer, Base.OneTo}}) (2 children)
                 6: signature Tuple{typeof(similar), Vector{T} where T, Type, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Vector{T} where T, ::Type{T}, ::Tuple{Union{Integer, Base.OneTo}}) where T (2 children)
                 7: signature Tuple{typeof(similar), Vector{T} where T, DataType, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Vector{T} where T, ::DataType, ::Tuple{Union{Integer, Base.OneTo}}) (2 children)
                 8: signature Tuple{typeof(similar), Vector{Symbol}, Type{Symbol}, Tuple{Union{Integer, AbstractUnitRange}}} triggered MethodInstance for similar(::Vector{Symbol}, ::Type{Symbol}, ::Tuple{Union{Integer, Base.OneTo}}) (2 children)

 inserting show(io::IO, P::Type{var"#s65"} where var"#s65"<:(typeof(∂(λ)))) where S<:Tuple in Zygote at /Users/ian/.julia/dev/Zygote/src/compiler/show.jl:13 invalidated:
   backedges: 1: superseding show(io::IO, x::Type) in Base at show.jl:769 with MethodInstance for show(::IOContext{Base.TTY}, ::Type) (1 children)
              2: superseding show(io::IO, x::Type) in Base at show.jl:769 with MethodInstance for show(::IOBuffer, ::Type) (2 children)
              3: superseding show(io::IO, x::Type) in Base at show.jl:769 with MethodInstance for show(::IOContext{IOBuffer}, ::Type) (8 children)
   3 mt_cache

 inserting isassigned(a::StaticArrays.StaticArray, i::Int64...) in StaticArrays at /Users/ian/.julia/packages/StaticArrays/LJQEe/src/abstractarray.jl:28 invalidated:
   backedges: 1: superseding isassigned(a::AbstractArray, i::Integer...) in Base at abstractarray.jl:505 with MethodInstance for isassigned(::AbstractVecOrMat{T} where T, ::Int64, ::Int64) (14 children)

 inserting convert(::Type{var"#s4"} where var"#s4"<:Dict, comp::ChainRulesCore.Composite{var"#s3", var"#s2"} where var"#s2"<:Dict where var"#s3"<:Dict) in ChainRulesCore at /Users/ian/.julia/packages/ChainRulesCore/cpHLu/src/differentials/composite.jl:69 invalidated:
   mt_backedges: 1: signature Tuple{typeof(convert), Type{Dict{String, Any}}, Any} triggered MethodInstance for setindex!(::Dict{Base.BinaryPlatforms.AbstractPlatform, Dict{String, Any}}, ::Any, ::Base.BinaryPlatforms.Platform) (0 children)
                 2: signature Tuple{typeof(convert), Type{Dict{Symbol, Any}}, Any} triggered MethodInstance for setindex!(::IdDict{Function, Dict{Symbol, Any}}, ::Any, ::Any) (8 children)
                 3: signature Tuple{typeof(convert), Type{Dict{Char, Any}}, Any} triggered MethodInstance for REPL.LineEdit.Prompt(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) (18 children)
   10 mt_cache

 inserting *(::ChainRulesCore.Zero, ::Any) in ChainRulesCore at /Users/ian/.julia/packages/ChainRulesCore/cpHLu/src/differential_arithmetic.jl:68 invalidated:
   mt_backedges: 1: signature Tuple{typeof(*), Any, String} triggered MethodInstance for Pkg.REPLMode.promptf() (0 children)
                 2: signature Tuple{typeof(*), Any, String} triggered MethodInstance for Pkg.API.var"#precompile#195"(::Bool, ::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Pkg.API.precompile), ::Pkg.Types.Context) (15 children)
                 3: signature Tuple{typeof(*), Any, Char} triggered MethodInstance for *(::Any, ::Char, ::Any) (16 children)

 inserting promote_rule(::Type{R}, ::Type{ForwardDiff.Dual{T, V, N}}) where {R<:Real, T, V, N} in ForwardDiff at /Users/ian/.julia/packages/ForwardDiff/qTmqf/src/dual.jl:357 invalidated:
   backedges: 1: superseding promote_rule(::Type{var"#s79"} where var"#s79", ::Type{var"#s78"} where var"#s78") in Base at promotion.jl:244 with MethodInstance for promote_rule(::Type{Int64}, ::Type{T} where T<:Real) (2 children)
              2: superseding promote_rule(::Type{var"#s79"} where var"#s79", ::Type{var"#s78"} where var"#s78") in Base at promotion.jl:244 with MethodInstance for promote_rule(::Type{UInt8}, ::Type) (7 children)
              3: superseding promote_rule(::Type{var"#s79"} where var"#s79", ::Type{var"#s78"} where var"#s78") in Base at promotion.jl:244 with MethodInstance for promote_rule(::Type{Int64}, ::Type) (25 children)
   19 mt_cache

It's easier to parse with the highlighting:
Screen Shot 2021-01-09 at 5 49 05 PM

Note that there are only two sources in Zygote

 inserting Base.IteratorSize(::Type{var"#s45"} where var"#s45"<:(Zygote.Buffer{var"#s44", A} where var"#s44")) where A in Zygote at /Users/ian/.julia/dev/Zygote/src/tools/buffer.jl:79 invalidated:
   backedges: 1: superseding Base.IteratorSize(::Type) in Base at generator.jl:92 with MethodInstance for Base.IteratorSize(::Type{var"#s445"} where var"#s445"<:LinearAlgebra.Factorization{T} where T) (3 children)
   42 mt_cache

 inserting show(io::IO, P::Type{var"#s65"} where var"#s65"<:(typeof(∂(λ)))) where S<:Tuple in Zygote at /Users/ian/.julia/dev/Zygote/src/compiler/show.jl:13 invalidated:
   backedges: 1: superseding show(io::IO, x::Type) in Base at show.jl:769 with MethodInstance for show(::IOContext{Base.TTY}, ::Type) (1 children)
              2: superseding show(io::IO, x::Type) in Base at show.jl:769 with MethodInstance for show(::IOBuffer, ::Type) (2 children)
              3: superseding show(io::IO, x::Type) in Base at show.jl:769 with MethodInstance for show(::IOContext{IOBuffer}, ::Type) (8 children)
   3 mt_cache
@IanButterworth IanButterworth changed the title Latency analysis Latency analysis with SnoopCompile Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants