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

how to use @snoopi #25

Closed
maartenvd opened this issue Apr 2, 2019 · 4 comments
Closed

how to use @snoopi #25

maartenvd opened this issue Apr 2, 2019 · 4 comments

Comments

@maartenvd
Copy link

Sorry if this is not the right place to post usage questions, but I'm really excited to try out the new snoopi macro (because inference is what I'm having problems with). However, when I try to snoopi on a call that takes 1+seconds to infer, I get the following trace:

 (4.100799560546875e-5, MethodInstance for eltype(::Type{Array{Expr,2}}))                                                                                                                                                                                         
...                                    
 (0.0013608932495117188, MethodInstance for methods(::Any, ::Any))                                                                                                                                                                                                
 (1.1331579685211182, MethodInstance for *(::StridedView{Float64,2,Array{Float64,1},typeof(identity)}, ::StridedView{Float64,2,Array{Float64,1},typeof(identity)}))   

The call I'm curious about is the multiplication, but also in how long all methods called by multiplication take. The problem is that the sum of all timings given by snoopi does not equal the time it takes to infer the multiplication call. There seems to be function calls missing, which perhaps got inlined, but even with --inline=no there is no change.

to be clear, I ran:

using SnoopCompile,Stridedc
a = StridedView(rand(5,5))
vs = @snoopi a*a
@timholy
Copy link
Owner

timholy commented Apr 2, 2019

Usage questions are fine. It reports only the "top-level" method; if foo(::Int) calls bar(::Int), foo cannot be inferred without first inferring bar. But only the inference of foo gets reported.

It may help to look at how it works: there's nothing to intercept recursive calls, only the entry point.

If you can turn your confusion into improved documentation via a pull request, I'd be very grateful!

@maartenvd
Copy link
Author

Oh, I assumed that by calling
jl_set_typeinf_func
inference would from now on use your supplied function to do everything, so therefore I expected to see a recursive trace.

I can take a look at the documentation :)

@timholy
Copy link
Owner

timholy commented Apr 2, 2019

Oh, I assumed that by calling jl_set_typeinf_func inference would from now on use your supplied function to do everything

It does, but it only intercepts calls to typeinf_ext. That's the "entry point" from Julia's C side; the C code doesn't handle the recursion, that's all done by the Julia side from typeinf_ext. To intercept recursive calls we'd have to intercept abstract_call as well, and that involves more rewriting/overwriting the methods in the compiler. This is the only place I've found that you can observe without substantial disruption.

@timholy
Copy link
Owner

timholy commented Nov 24, 2019

Fixed by #35

@timholy timholy closed this as completed Nov 24, 2019
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

No branches or pull requests

2 participants