Skip to content

use SIMD.jl directly instead of LV.jl for fast_findmin() - #84

Closed
Moelf wants to merge 5 commits into
mainfrom
exorcise_lv
Closed

use SIMD.jl directly instead of LV.jl for fast_findmin()#84
Moelf wants to merge 5 commits into
mainfrom
exorcise_lv

Conversation

@Moelf

@Moelf Moelf commented Oct 27, 2024

Copy link
Copy Markdown
Member

fix #83

@codecov

codecov Bot commented Oct 27, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.14%. Comparing base (82f1a80) to head (1e20f7b).
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #84      +/-   ##
==========================================
+ Coverage   73.81%   74.14%   +0.33%     
==========================================
  Files          18       18              
  Lines        1245     1261      +16     
==========================================
+ Hits          919      935      +16     
  Misses        326      326              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@graeme-a-stewart

Copy link
Copy Markdown
Member

I will test this, but initial indications are that the performance on Apple silicon is rather bad

@Moelf

Moelf commented Oct 28, 2024

Copy link
Copy Markdown
Member Author

hmm, I don't have access to Apple Silicon, but luckily we don't run JetReco on aarch64 in HEP yet

@graeme-a-stewart

Copy link
Copy Markdown
Member

Yeah, but it's where I develop! And people testing FCC workflows, for example, do use their Mac laptops...

@graeme-a-stewart

graeme-a-stewart commented Oct 28, 2024

Copy link
Copy Markdown
Member

Yeah, it's quite a significant regression on Apple silicon. On my M2...

main

~/.julia/dev/JetReconstruction/examples/ [main*] julia --project instrumented-jetreco.jl --algorithm=AntiKt -R 0.4 ../test/data/events.pp13TeV.hepmc3.gz -m 32
Processed 100 events 32 times
Average time per event 170.6484634375 ± 4.057617987022607 μs
Lowest time per event 166.17292 μs

exorcise_lv

~/.julia/dev/JetReconstruction/examples/ [exorcise_lv] julia --project instrumented-jetreco.jl --algorithm=AntiKt -R 0.4 ../test/data/events.pp13TeV.hepmc3.gz -m 32
Processed 100 events 32 times
Average time per event 201.44234250000002 ± 3.8225514883321954 μs
Lowest time per event 197.07167 μs

I need to test also on x86 and follow-up with further benchmarks of suggestions which came up in the Discourse thread.

@graeme-a-stewart

Copy link
Copy Markdown
Member

Benchmarks for x86_64, AMD Ryzen 7 5700G.

main

pc-sft-fa-0a :: dev/JetReconstruction/examples ‹main› » julia --project instrumented-jetreco.jl --algorithm=AntiKt -R 0.4 ../test/data/events.pp13TeV.hepmc3.gz -m 32
Processed 100 events 32 times
Average time per event 184.5104475 ± 6.358035705629633 μs
Lowest time per event 176.97703 μs

exorcise_lv

pc-sft-fa-0a :: dev/JetReconstruction/examples ‹exorcise_lv› » julia --project instrumented-jetreco.jl --algorithm=AntiKt -R 0.4 ../test/data/events.pp13TeV.hepmc3.gz -m 32
Processed 100 events 32 times
Average time per event 184.13992875 ± 6.5172848018939655 μs
Lowest time per event 177.66260999999997 μs

So it's really doing a good job on x86. We just have to find a way to make it also work well on Apple silicon.

@Moelf

Moelf commented Oct 28, 2024

Copy link
Copy Markdown
Member Author

do you ever have NaN in this function? because:

julia> @fastmath foldl(min, [1.0, NaN, 0.5])
0.5

julia> foldl(min, [1.0, NaN, 0.5])
NaN

@graeme-a-stewart

graeme-a-stewart commented Oct 28, 2024

Copy link
Copy Markdown
Member

No, there can't be a NaN there. I think if you can have NaN then fast math's assumptions are violated and bad things happen.

@Moelf

Moelf commented Oct 28, 2024

Copy link
Copy Markdown
Member Author

ok yeah if you don't have NaN and don't care about -0.0 vs. 0.0 I think you can use ~fastmath

@graeme-a-stewart

Copy link
Copy Markdown
Member

ok yeah if you don't have NaN and don't care about -0.0 vs. 0.0 I think you can use ~fastmath

There shouldn't be any zeros at all, so -0.0 vs. +0.0 should be moot!

@Moelf

Moelf commented Oct 29, 2024

Copy link
Copy Markdown
Member Author

honestly, I might need to buy a Mac Mini just so I can test aarch64 performance....

@graeme-a-stewart

Copy link
Copy Markdown
Member

honestly, I might need to buy a Mac Mini just so I can test aarch64 performance....

They are quite sweet little machines (especially now they have M4s) - I am thinking about getting one myself!

@graeme-a-stewart

graeme-a-stewart commented Oct 30, 2024

Copy link
Copy Markdown
Member

So I was thinking that if we do not find a generic solution, we can tolerate two ways to implement fast_findmin, switching on Sys.KERNEL (specifically isapple() and friends).

Though it would be good to understand if it's OS we should switch on or CPU arch - @aoanla would be able to help us run a few tests.

@carstenbauer

Copy link
Copy Markdown

honestly, I might need to buy a Mac Mini just so I can test aarch64 performance....

Poor man's workaround: ssh to a aarch64 MacOS GitHub Runner. ;)

@graeme-a-stewart
graeme-a-stewart self-requested a review November 4, 2024 16:11
@graeme-a-stewart
graeme-a-stewart marked this pull request as draft November 22, 2024 09:10
@graeme-a-stewart graeme-a-stewart added the Internals Changes that affect the internals of the package, but not the public API label Nov 22, 2024
@Moelf

Moelf commented Nov 22, 2024

Copy link
Copy Markdown
Member Author

btw, here's what LV.jl is doing:
https://gist.github.com/Moelf/7432073603f10d7718ef82552d5362dd

@Moelf

Moelf commented Jan 6, 2025

Copy link
Copy Markdown
Member Author

I know have a M4 mac mini to play with, and I can see the difference:

(thisPR) [1]> julia --project src/benchmark.jl --backend Julia --repeats 30  data/events-pp-13TeV-20GeV.hepmc3.gz
1×5 DataFrame
 Row │ File_path                          File                             mean_particles  n_samples  time_per_event
     │ Any                                String                           Int64           Int64      Float64
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 │ data/events-pp-13TeV-20GeV.hepmc…  events-pp-13TeV-20GeV.hepmc3.gz              -1         16         143.213

(main)> julia --project src/benchmark.jl --backend Julia --repeats 30  data/events-pp-13TeV-20GeV.hepmc3.gz
1×5 DataFrame
 Row │ File_path                          File                             mean_particles  n_samples  time_per_event
     │ Any                                String                           Int64           Int64      Float64
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 │ data/events-pp-13TeV-20GeV.hepmc…  events-pp-13TeV-20GeV.hepmc3.gz              -1         16         131.523

@graeme-a-stewart

Copy link
Copy Markdown
Member

Just rebased onto the head of main to take a look at this again

@Moelf

Moelf commented May 14, 2025

Copy link
Copy Markdown
Member Author

superceeded by #151

@Moelf Moelf closed this May 14, 2025
@giordano
giordano deleted the exorcise_lv branch May 19, 2025 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Internals Changes that affect the internals of the package, but not the public API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test removal of LoopVectorization.jl

3 participants