Conversation
This commit adds `get_num_threads`, which returns the number of threads used by the planner, and is the complement to `set_num_threads`. This simply wraps the function `fftw_planner_nthreads`, which was [newly added to fftw in version 3.3.9](https://github.com/FFTW/fftw3/blob/34082eb5d6ed7dc9436915df69f376c06fc39762/NEWS#L3).
|
This is now working locally for me, and tests are passing, when used with FFTW_jll v3.3.9+7. |
|
Can you bump the version requirement on FFTW_jll in Project.toml? |
|
Yeah I wasn't sure what to do about that... I don't think you can specify a build number in Project.toml. If I just change the As long as people update their packages this should work since they will get the most recent build of I can update the version requirement for FFTW_jll to be |
`get_num_threads` requires FFTW_jll v3.3.9+7, but it doesn't seem possible to specify a particular build in the compat section of Project.toml files. However, this should work in most cases, as the most recent build of `FFTW_jll` should be downloaded upon updating.
That's another reason why we want to change the versioning system of JLL package (and the reason why I was waiting to merge the PR, I knew we'd have had this situation) |
|
I imagine that not being able to specify the build number will not be a problem for people, unless they have pinned or dev'd In order to make sure that it works, it seems like you would need to create a new FFTW_jll version v3.3.10 that corresponds to fftw3 v3.3.9, because FFTW_jll v.3.3.9 has been wrapping a pre-release version of fftw v3.3.9 for a while (likely for a good reason), meaning that there is currently no way to specify the released fftw 3.3.9 artifact with FFTW_jll's version. I'm still not clear on how package maintainers will be able to specify which artifact version they want if the _jll package version number is not the same as the underlying artifact, even though I understand why it is necessary for them to not be the same. Will there be a lookup table in the README of each _jll github project page? Or will there be some other programmatic way to do it, which might even have Pkg support? |
There are weird situations where users may end up updating
We haven't worked this out yet because it isn't a trivial problem. If you have some ideas please share in Yggdrasil. |
Exactly, it seems like a pretty unlikely problem. I think that this PR should be merged before there is both consensus about, and implementation of, and improved version system in Yggdrasil—which may take quite some time. The change here simply provides access to a function in the most recent version of fftw. I have updated the Project.toml for this package so that it requires that version of fftw (3.3.9), which should just work for the vast majority of users, and indeed worked for CI here. The potential downside of adding this function is that due to their local Pkg state, it's possible that a user will have a fftw library that reflects the state of fftw around Sep 17 2019, instead of the released 3.3.9 version, causing this new function to error. However, this Pkg state seems unlikely, even though it is possible. The fix for any affected users would be to simply run Furthermore, it seems like the reason that FFTW_jll was shipping a pre-released version of fftw was to provide access to |
No equivalent function for mkl
|
I added the vendor check. It occurs to me that the way I would want to use this would benefit from support in this package. I would want to acquire the The function would look something like: @exclusive function set_num_threads(f, nthreads::Integer)
orig_nthreads = get_num_threads()
try
ccall((:fftw_plan_with_nthreads,libfftw3), Cvoid, (Int32,), nthreads)
ccall((:fftwf_plan_with_nthreads,libfftw3f), Cvoid, (Int32,), nthreads)
f()
finally
ccall((:fftw_plan_with_nthreads,libfftw3), Cvoid, (Int32,), orig_nthreads)
ccall((:fftwf_plan_with_nthreads,libfftw3f), Cvoid, (Int32,), orig_nthreads)
end
endand would enable planning like: plan = FFTW.set_num_threads(4) do
plan_rfft(...)
endThe function argument would have to be careful to avoid a context switch, e.g. no IO. However, it seems like you would want to hold the lock while making plans to ensure that the plans were made with the intended number of threads. |
Why? |
|
Yeah I guess it wouldn't be a big deal for the thread to block on io with the lock.
…On Sat, Dec 26, 2020, at 17:47, Steven G. Johnson wrote:
> The function argument would have to be careful to avoid a context switch, e.g. no IO.
Why?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#171 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABUDZT5QGEA34QF3H7Y6HOLSWZRZPANCNFSM4VDJYVFQ>.
|
|
Yes, adding that (You wouldn't need to |
|
Or we could add an |
Wouldn't
That also sounds great |
Additionally, separate previous `set_num_threads` method into a base function, `_set_num_threads`, that wraps the `ccalls`, and `set_num_threads`, which will acquire the `fftwlock`.
While MKL's FFTW does not provide access to the number of threads available to the planner, this can be simulated by caching the value last passed to `set_num_threads` and returning it with `get_num_threads` if `fftw_vendor == :mkl`.
Codecov Report
@@ Coverage Diff @@
## master #171 +/- ##
==========================================
- Coverage 63.24% 61.07% -2.17%
==========================================
Files 5 5
Lines 438 483 +45
==========================================
+ Hits 277 295 +18
- Misses 161 188 +27
Continue to review full report at Codecov.
|
…s.nthreads Since FFTW uses `Base.Threads`, and `nthreads` is a function defined in `Base.Threads`, then the function argument `nthreads` shadows a function already in the namespace of every function. While there is no inherent issue with this, it can make debugging this code more confusing.
As suggested by @stevengj, I have add a `num_threads` keyword to the `plan_...` functions. My approach here is fairly naive, and adds a bunch of redundant boiler plate code to every `plan_` function.
|
I have implemented the suggestions in your code reviews, as well as your suggestion to add a |
|
Gentle bump on this. Not sure what's left to be done but I would love to see this merged. |
|
|
||
| """ | ||
| plan_dct!(A [, dims [, flags [, timelimit]]]) | ||
| plan_dct!(A [, dims [, flags [, timelimit [, num_threads]]]]) |
There was a problem hiding this comment.
Why aren't these keyword arguments?
There was a problem hiding this comment.
I was just following the existing style for the keyword arguments flags and timelimit. Happy to change the documentation style (and probably flags and timelimit too?) if you'd prefer.
|
bump. The depending package NFFT.jl is multi-threaded and it would be nice to chose the same number of threads all operations without changing global state. |
|
Another friendly bump 🙏. |
|
I merged |
This commit adds
get_num_threads, which returns the number of threads used by the planner, and is the complement toset_num_threads. This simply wraps the functionfftw_planner_nthreads, which was newly added to fftw in version 3.3.9.This PR will not work until JuliaPackaging/Yggdrasil#2291 is merged, and the resulting artifact is used for testing.
Closes #117