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

Specialize MI if necessary #553

Merged
merged 10 commits into from
Mar 13, 2024
Merged

Specialize MI if necessary #553

merged 10 commits into from
Mar 13, 2024

Conversation

vchuravy
Copy link
Member

@vchuravy vchuravy commented Mar 7, 2024

@vtjnash is there a way to speedup this query? For identity(::Int) this currently takes ~500ns

The goal here is to compute the mi we would have invoked.

src/jlgen.jl Outdated Show resolved Hide resolved
src/jlgen.jl Outdated Show resolved Hide resolved
@vchuravy
Copy link
Member Author

So this is now ~70ns

Copy link
Contributor

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!isdispatchtuple(mi.specTypes) is true, you are guaranteed to get back the exact same mi object

@vchuravy
Copy link
Member Author

vchuravy commented Mar 11, 2024

Okay using !== instead of != gets me the performance back.

julia> @benchmark GPUCompiler.methodinstance(typeof(identity), Tuple{Int,})
BenchmarkTools.Trial: 10000 samples with 968 evaluations.
 Range (min … max):  78.574 ns … 118.419 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     84.008 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   83.506 ns ±   2.955 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▅                        █▄ ▂▂      ▂                         
  █▁▂▂▁▁▂▄▂▃▂▁▁▂▃▆▂▅▄▂▂▃▃▂▃██▂██▅▂▂▂▂▂█▂▄▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▃ ▃
  78.6 ns         Histogram: frequency by time         90.7 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark GPUCompiler.methodinstance(typeof(+), Tuple{Int,Int})
BenchmarkTools.Trial: 10000 samples with 999 evaluations.
 Range (min … max):  12.633 ns … 31.822 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     12.893 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   12.903 ns ±  0.353 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

                                 █             ▅ ▁             
  ▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂▃█▄▁▂▁▁▁▁▃█▂▇▁▄█▂█▁▃▃▁▃▂▂▁▁▂▂ ▃
  12.6 ns         Histogram: frequency by time          13 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

With != it was:

julia> @benchmark GPUCompiler.methodinstance(typeof(identity), Tuple{Int,})
BenchmarkTools.Trial: 10000 samples with 759 evaluations.
 Range (min … max):  154.545 ns … 283.768 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     171.700 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   174.559 ns ±  14.674 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

         ▁▅▄▅█                                                   
  ▁▁▁▁▂▁▄█████▇▇▃▂▁▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
  155 ns           Histogram: frequency by time          256 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

@vtjnash
Copy link
Contributor

vtjnash commented Mar 11, 2024

With isdispatchtuple, that should not be reachable

@maleadt maleadt merged commit c145ea3 into master Mar 13, 2024
11 of 15 checks passed
@maleadt maleadt deleted the vc/spec_mi branch March 13, 2024 12:25
@vtjnash
Copy link
Contributor

vtjnash commented Mar 13, 2024

Could I interest you in fixing this in JuliaInterpreter, now that you know all of the secrets?

@vchuravy
Copy link
Member Author

I could fix this in Base for Base.method_instance, but other than that I currently trying to not do code development and focus on my thesis

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.

3 participants