Skip to content

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Jan 16, 2025

Adds 4 new Float16 fields to CodeInstance to replace Compiler.Timings with continually collected and available measurements.

Sample results on a novel method signature:

julia> @time code_native(devnull, ÷, dump_module=false, (Int32, UInt16));
  0.006262 seconds (3.62 k allocations: 186.641 KiB, 75.53% compilation time)

julia> b = which(÷, (Int32, UInt16)).specializations[6].cache
CodeInstance for MethodInstance for div(::Int32, ::UInt16)

julia> reinterpret(Float16, b.time_infer_self)
Float16(0.0002766)

julia> reinterpret(Float16, b.time_infer_total)
Float16(0.00049)

julia> reinterpret(Float16, b.time_infer_cache_saved)
Float16(0.02774)

julia> reinterpret(Float16, b.time_compile)
Float16(0.003773)

Closes #56115

@vtjnash vtjnash added compiler:codegen Generation of LLVM IR and native code compiler:inference Type inference observability metrics, timing, understandability, reflection, logging, ... labels Jan 16, 2025
@vtjnash vtjnash requested a review from timholy January 16, 2025 19:58
@gbaraldi
Copy link
Member

gbaraldi commented Jan 16, 2025

Are float32s too awful to use here? I really would like to avoid depending on Float16 to work in C correctly (The ABI horrors it caused have scarred me). Maybe we do fixed point or something.

@vtjnash
Copy link
Member Author

vtjnash commented Jan 16, 2025

Fixed point won't work (insufficient range), though exponential would (at a significant loss of accuracy compared to Float16). I avoided using any of the Float16 in C, just calling our emulation functions directly using the uint16_t ABI to avoid any issues. All math is explicitly done using Float64 or double, so here we are just using it as a storage format (as IEEE intended).

@topolarity
Copy link
Member

This is awesome. I've wanted something like this for a long time.

@IanButterworth
Copy link
Member

IanButterworth commented Mar 6, 2025

The issue this fixes is already on the 1.12 milestone but just to highlight that without it, if I understand correctly, PrecompileTools.@compile_workload is broken, and TTFX on 1.12 is back to the olden times.

@vtjnash vtjnash force-pushed the jn/codeinstance-add-timings branch from 2e238e7 to de14a3c Compare March 14, 2025 16:57
@vtjnash vtjnash added merge me PR is reviewed. Merge when all tests are passing backport 1.12 Change should be backported to release-1.12 labels Mar 14, 2025
@vtjnash vtjnash marked this pull request as ready for review March 14, 2025 16:58
Adds 4 new Float16 fields to CodeInstance to replace Compiler.Timings
with continually collected and available measurements.

Sample results on a novel method signature:

    julia> @time code_native(devnull, ÷, dump_module=false, (Int32, UInt16));
      0.006262 seconds (3.62 k allocations: 186.641 KiB, 75.53% compilation time)

    julia> b = which(÷, (Int32, UInt16)).specializations[6].cache
    CodeInstance for MethodInstance for div(::Int32, ::UInt16)

    julia> reinterpret(Float16, b.time_infer_self)
    Float16(0.0002766)

    julia> reinterpret(Float16, b.time_infer_total)
    Float16(0.00049)

    julia> reinterpret(Float16, b.time_infer_cache_saved)
    Float16(0.02774)

    julia> reinterpret(Float16, b.time_compile)
    Float16(0.003773)
@vtjnash vtjnash force-pushed the jn/codeinstance-add-timings branch from de14a3c to b234b22 Compare March 14, 2025 19:03
@IanButterworth IanButterworth merged commit 18b5d8f into master Mar 17, 2025
7 checks passed
@IanButterworth IanButterworth deleted the jn/codeinstance-add-timings branch March 17, 2025 03:02
aviatesk added a commit to JuliaDebug/Cthulhu.jl that referenced this pull request Mar 18, 2025
aviatesk added a commit to JuliaDebug/Cthulhu.jl that referenced this pull request Mar 18, 2025
timholy added a commit to JuliaLang/PrecompileTools.jl that referenced this pull request Mar 18, 2025
xref JuliaLang/julia#57074

The old `Compiler.Timings` infrastructure is disabled, so here we
leverage the same `newly_compiled` infrastructure used during
precompilation.
serenity4 added a commit to serenity4/Diffractor.jl that referenced this pull request Mar 18, 2025
timholy added a commit that referenced this pull request Mar 19, 2025
With the "classic" inference timing disabled, PrecompileTools and
SnoopCompile are non-functional on 1.12 & master. #57074 added timing
data to the CodeInstances themselves, which should help restore
SnoopCompile. However, without the tree structure provided by the old
inference timing system, we still need a way to tag MethodInstances that
get inferred inside `PrecompileTools.@compile_workload` blocks.

This adds a simple mechanism modeled after `@trace_compile` that
switching to tagging MethodInstances in `jl_push_newly_inferred`.
JuliaLang/PrecompileTools.jl#47 contains the
corresponding changes to PrecompileTools.jl.
JeffBezanson pushed a commit that referenced this pull request Mar 20, 2025
With the "classic" inference timing disabled, PrecompileTools and
SnoopCompile are non-functional on 1.12 & master. #57074 added timing
data to the CodeInstances themselves, which should help restore
SnoopCompile. However, without the tree structure provided by the old
inference timing system, we still need a way to tag MethodInstances that
get inferred inside `PrecompileTools.@compile_workload` blocks.

This adds a simple mechanism modeled after `@trace_compile` that
switches to tagging MethodInstances in `jl_push_newly_inferred`.
JuliaLang/PrecompileTools.jl#47 contains (or
will contain) the corresponding changes to PrecompileTools.jl.
KristofferC pushed a commit that referenced this pull request Mar 20, 2025
With the "classic" inference timing disabled, PrecompileTools and
SnoopCompile are non-functional on 1.12 & master. #57074 added timing
data to the CodeInstances themselves, which should help restore
SnoopCompile. However, without the tree structure provided by the old
inference timing system, we still need a way to tag MethodInstances that
get inferred inside `PrecompileTools.@compile_workload` blocks.

This adds a simple mechanism modeled after `@trace_compile` that
switches to tagging MethodInstances in `jl_push_newly_inferred`.
JuliaLang/PrecompileTools.jl#47 contains (or
will contain) the corresponding changes to PrecompileTools.jl.

(cherry picked from commit c89b1ff)
KristofferC pushed a commit that referenced this pull request Mar 21, 2025
Adds 4 new Float16 fields to CodeInstance to replace Compiler.Timings
with continually collected and available measurements.

Sample results on a novel method signature:

julia> @time code_native(devnull, ÷, dump_module=false, (Int32,
UInt16));
0.006262 seconds (3.62 k allocations: 186.641 KiB, 75.53% compilation
time)

    julia> b = which(÷, (Int32, UInt16)).specializations[6].cache
    CodeInstance for MethodInstance for div(::Int32, ::UInt16)

    julia> reinterpret(Float16, b.time_infer_self)
    Float16(0.0002766)

    julia> reinterpret(Float16, b.time_infer_total)
    Float16(0.00049)

    julia> reinterpret(Float16, b.time_infer_cache_saved)
    Float16(0.02774)

    julia> reinterpret(Float16, b.time_compile)
    Float16(0.003773)

Closes #56115

(cherry picked from commit 18b5d8f)
@giordano giordano removed the merge me PR is reviewed. Merge when all tests are passing label Mar 21, 2025
@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label Mar 24, 2025
timholy added a commit to JuliaLang/PrecompileTools.jl that referenced this pull request Mar 24, 2025
xref JuliaLang/julia#57074

The old `Compiler.Timings` infrastructure is disabled, so here we
leverage the same `newly_compiled` infrastructure used during
precompilation.

Because the implementation is so fundamentally different,
this makes the upcoming Julia 1.12 the minimum required
version for new development in this package.

---------

Co-authored-by: Jameson Nash <[email protected]>
Co-authored-by: Kristoffer <[email protected]>
Keno pushed a commit to JuliaDiff/Diffractor.jl that referenced this pull request Apr 28, 2025
Co-authored-by: Cédric Belmant <[email protected]>
serenity4 pushed a commit to serenity4/julia that referenced this pull request May 1, 2025
Adds 4 new Float16 fields to CodeInstance to replace Compiler.Timings
with continually collected and available measurements.

Sample results on a novel method signature:

julia> @time code_native(devnull, ÷, dump_module=false, (Int32,
UInt16));
0.006262 seconds (3.62 k allocations: 186.641 KiB, 75.53% compilation
time)

    julia> b = which(÷, (Int32, UInt16)).specializations[6].cache
    CodeInstance for MethodInstance for div(::Int32, ::UInt16)

    julia> reinterpret(Float16, b.time_infer_self)
    Float16(0.0002766)

    julia> reinterpret(Float16, b.time_infer_total)
    Float16(0.00049)

    julia> reinterpret(Float16, b.time_infer_cache_saved)
    Float16(0.02774)

    julia> reinterpret(Float16, b.time_compile)
    Float16(0.003773)

Closes JuliaLang#56115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code compiler:inference Type inference observability metrics, timing, understandability, reflection, logging, ...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

snoop_inference is broken on latest after stackless inference change
6 participants