Comments (1)
Thanks for the report @itzsimpl. I've not tried to reproduce as the reported output is sufficiently detailed and it is also what I would guess would happen based on the description.
Some explanation as to what is happening... when a call is made to numba.get_num_threads()
or numba.set_num_threads()
if Numba hasn't launched a threading layer already, the first thing it will do is try and launch a threading layer based on availability and user preference (there are 3 to choose from). The threading layer will "read" the number of threads required indirectly from the environment variable NUMBA_NUM_THREADS
and if that is not present it will typically use max(1, len(os.sched_getaffinity(0)))
. At this point the threading layer will launch and initialize, in the case of the OpenMP threading layer, as demonstrabily used in the example above, this will include setting the number of threads available to the OpenMP library to NUMBA_NUM_THREADS
i.e. the OpenMP ICV nthreads-var
ends up with the value NUMBA_NUM_THREADS
. It so happens in the example above that torch
is also using OpenMP and will pick up this change as a result of launching Numba's OpenMP based threading layer (they are clearly sharing the OpenMP ICV as only one OpenMP library is realistically ever going to be in process).
This explanation was discussed at the Numba maintainer's meeting on 2024-01-16 and it wasn't clear what the expectation is for torch
and Numba interacting. Altering Numba's OpenMP threading layer to check the current thread-pool size, compare that to NUMBA_NUM_THREADS
or sched_getaffinity[0]
and then take some action based on it would lead to a deviation in behaviour of the Numba OpenMP threading layer in comparison to the TBB and workqueue threading layers. One thing that might work would be to set NUMBA_NUM_THREADS
to the same value as whatever is being used to set the number of threads in torch
, if that's the desired behaviour i.e.
NUMBA_NUM_THREADS = HOW_TORCH_SETS_MAX_THREADS = <value>
.
It should also be noted that the reason for Numba having its own method for setting a thread count (NUMBA_NUM_THREADS
env var) is that Numba has three threading layers and for ease of use it was decided that the method of setting a thread count needed to be invariant of the layer used (e.g. NUMBA_NUM_THREADS
works for all of Numba's threading layers contrary to OpenMP specific env var OMP_NUM_THREADS
which has no impact on the TBB
or workqueue
threading layer).
I hope this explanation helps, please do share your thoughts. Many thanks.
from numba.
Related Issues (20)
- NUMBA CUDA Unknown memory "error" HOT 1
- Broadcasting of matmul does not work with parallel HOT 2
- In some cases, Numba 0.57.1 (can also be reproduced in 0.59.0) does not assign values to a NumPy array HOT 1
- Shall we consider using an envvar to disable refct atomic instructions HOT 2
- Elapsed running time of parallel jit for the logistic regression documentation example is dozens of seconds HOT 3
- Add ability to @jit to disable auto-vectorization HOT 3
- CUDA: Providing a signature for a function reference when eagerly compiling does not work
- Numba confuses float32 and float64 in numpy-array causing compilation failure HOT 5
- Some array methods much slower with non-C-order arrays HOT 2
- how to accelerate a for loop which consists by vector computation HOT 2
- New Type System/NumPy 2 support tracking
- Numba 0.59.0 Final Checklist HOT 2
- debuginfo issues with parallel functions: file names are not identified HOT 5
- Python 3.13
- Inconsistent support of log2 HOT 3
- module 'numpy' has no attribute 'typeDict' with numpy 1.24.4 HOT 9
- Structured array scalar slices: `iadd`, `isub`, etc, not able to compile (simple example code) HOT 2
- Outdated Python support list on numba.pydata.org HOT 2
- Tuple of functions (with identical signature) does not compile for CUDA HOT 2
- Support for Definition of Numpy Arrays of Complex Type Within njit-ed Functions? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from numba.