Fix threading - #707
Conversation
|
Can you clarify what the implications of this are (performance?), and whether we fallback in practice (production) — and if so, how we can avoid that. It seems like this might silently introduce performance regressions, depending on environment. |
The implications are that in environments that don't have This will lead to a regression in environments without those libraries, because those will fall back to the slower The required libraries should be available on all our production platforms. It might of course fall back in some user environment that we don't control. Alternatives:
|
|
Have you looked into our actual envs — when you say "should be available", does that mean can be installed or are installed? What environments do not have |
I mean "can be installed". |
Maybe, but then we don't catch issues like this. |
|
I don't really think this is a big change. The code already falls back to the non-numba implementation if |
Hmm, does seems odd. Isn't it what the wavelength-LUT code wants to rely on @nvaytet? Should it be added, for
Knowing "I have to install numba to get the fast implementation" is relatively easy, knowing that there might be a silent fallback to a slow implementation if some threading library (the user may have never heard of) is not available is arguably worse. |
Right now the user still has to remember to install some threading library, or they might see random crashes. |
In other words, it is not silent, that is my point. I think not silently degrading performance is better. |
|
I've now added a workflow parameter for selecting the wavelength unwrapping backend. If the value of that parameter is |
| try: | ||
| from numba import config, get_num_threads, threading_layer | ||
|
|
||
| config.THREADING_LAYER = 'threadsafe' |
There was a problem hiding this comment.
I don't like that this sets a global variable. It will be hard to debug threading behaviour in code that uses the workflow.
Is this strictly required here?
There was a problem hiding this comment.
Instead of modifying THREADING_LAYER we could just check that it is one of the threadsafe ones.
I think numba will by default select a threadsafe layer if there is one available.
|
|
||
| def interpolate_after_barrier(_): | ||
| barrier.wait() | ||
| return numba_interp(times, distances) |
There was a problem hiding this comment.
I think you need a second barrier after the call to numba_interp. Otherwise, one thread can call the interpolator and finish before the other calls the interpolator.
But in general, there is no guarantee that both threads will be in the interpolator at the same time.
There was a problem hiding this comment.
I don't think the second barrier will help with that because, like you note, the threads will not be in the interpolator at the same time, and I think that is required for the crash to occur.
There's no guarantee the threads will be in the interpolator at the same time, but I think it is quite likely, we could increase the number of points to make it more likely.
We could also just remove the test.
| python = "3.11.*" | ||
|
|
||
| [target.osx-arm64.dependencies] | ||
| llvm-openmp = "*" |
There was a problem hiding this comment.
Why is this required? And how does this map onto the wheel and conda package dependencies?
There was a problem hiding this comment.
It is required because the osx-arm64 platform does not have tbb or openmp available by default, and then numba will use a non-thread safe backend, and the tests in essreduce will fall back to using the scipy interpolator.
There was a problem hiding this comment.
Given that most of ESS is using Macs, should we add this to our package requirements?
There was a problem hiding this comment.
But this only affects dev environments. The package deps are in pyproject.toml.
There was a problem hiding this comment.
pyproject.toml cannot install a conda package, so as I understand it we can not make this part of the dependencies of essreduce?
However, we can make sure to add this to the ESS environment that is deployed on VISA and that users can download to reproduce the environment locally.
There was a problem hiding this comment.
@MridulS What do you think? We'd also need to make sure this is installed in the ESSlivedata backends for example, which just use pip.
There was a problem hiding this comment.
This shouldn't have any affect on visa or livedata as they are anyway running on linux boxes, but I'm not a 100% sure if this is going in the right direction. Something seems off, where is windows/linux getting tbb/openmp from then? Discussing this with Johannes.
There was a problem hiding this comment.
I think the cleaner solution here for now is to add this to our pixi.toml
[feature.essreduce.dependencies]
numba = ">=0.63" # Prefer conda-forge Numba as it installs thread safe backends for all platforms
pixi solves the conda packages first, so this numba should take precedence over the one defined by the test optional deps in essreduce pyproject.toml
3dd99e7 to
6ed2221
Compare
|
https://github.com/scipp/ess/blob/main/pixi.lock does have _openmp_mutex for win64, and linux-64. Not for macos .... |
|
After some digging found this numba/numba#10492, looks like putting |
8b762f8 to
9a8ceb4
Compare
Fixes the failing weekly tests on MacOS: #705