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

RFC: Track queued FFTW thread count to aid profiling #235

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IanButterworth
Copy link
Contributor

@IanButterworth IanButterworth commented Mar 27, 2022

This demo tracks the number of queued FFTW threads (#234).

The idea being that it could be monitored in profiling tooling to identify poor balancing of nthreads() vs. FFTW.get_num_threads(), for instance within a Threads.@threads for loop.

julia> FFTW.set_num_threads(Threads.nthreads())

julia> @time begin
	         @show Threads.nthreads() FFTW.get_num_threads()
	         t = Timer(0, interval = 0.01) do t
	             print(FFTW.num_queued_threads[], " ")
	         end
	         x = rand(1000,1000,10)
	         Threads.@threads for i in 1:(Threads.nthreads() * 10)
	             fft(x)
	         end
	         close(t); println()
       end
Threads.nthreads() = 6
FFTW.get_num_threads() = 6
10 20 22 25 23 21 20 11 11 15 19 16 12 13 14 8 4 12 21 26 25 16 3 3 1 12 28 27 25 20 20 13 2 1 0 16 25 26 25 22 19 17 12 10 0 28 23 16 11 10 8 7 6 3 2 2 1 1 0 29 26 23 19 15 14 11 5 9 11 22 22 21 19 6 7 6 8 19 24 20 15 11 10 7 6 3 2 2 1 0 18 23 23 18 13 0 3 
  7.885598 seconds (48.46 k allocations: 17.959 GiB, 10.47% gc time, 0.51% compilation time)

In a simple loop example like above, it should be pretty obvious to the user that they should balance nthreads() and FFTW threads.

But in the case where FFTW is used deep inside a library function, it may not be obvious when FFTW is being used, and poor balancing might be impeding performance.

One idea might be to do a @warn "..." maxlog=1 with advice about checking load balancing if significantly more queued FFTW threads are detected than Sys.CPU_THREADS, but it seems @warn doesn't work within a @cfunction. It would probably be too opinionated though.

@codecov
Copy link

codecov bot commented Mar 27, 2022

Codecov Report

Merging #235 (19f7f37) into master (17bc81a) will increase coverage by 0.31%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #235      +/-   ##
==========================================
+ Coverage   61.07%   61.39%   +0.31%     
==========================================
  Files           5        5              
  Lines         483      487       +4     
==========================================
+ Hits          295      299       +4     
  Misses        188      188              
Impacted Files Coverage Δ
src/providers.jl 45.16% <100.00%> (+8.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 17bc81a...19f7f37. Read the comment docs.

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.

1 participant