You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: get multithreading status at runtime #362
maybe it's already there but I haven't found any way to know at runtime what is the status of multithreading, i.e. openmp, pthreads or no multithreading. I could be nice to have that for runtime introspection.
Also, when built with no multithreading, the functions bli_thread_get(set)_num_threads act as if multithreading was enabled. For instance
maybe it's already there but I haven't found any way to know at runtime what is the status of multithreading, i.e. openmp, pthreads or no multithreading. I could be nice to have that for runtime introspection.
This more or less exists. The following code snippet is taken from the testsuite to show how it can be done:
Also, when built with no multithreading, the functions bli_thread_get(set)_num_threads act as if multithreading was enabled.
This is actually a more complicated topic than it may appear.
First, let's start with the fact that, even when multithreading is enabled, bli_thread_set_num_threads() does not return the number of threads actively running, but rather [something whose meaning is closer to] the number that will be requested when multithreading is engaged. If you look at it through that lens, the current behavior is more understandable: your example code requests two threads, but the implementation is ignoring your request (because it can't comply).
Second, even with this knowledge in mind, you would be forgiven for thinking that bli_thread_get_num_threads() returns the number of threads previously requested to execute. But that's not quite right. It's merely the value that was most recently submitted via bli_thread_set_num_threads(). So what's the nuance? BLIS exposes the individual ways of parallelism to extract for each loop in the matrix multiplication algorithm it employs. You can set these individual ways of parallelism without setting the total number via bli_thread_set_num_threads(). So what happens when you set both (ie: the manual way and the automatic way)? The manual, individual loop-specific values take priority, and the total number, whatever it may have been set to, is ignored. But in the interim, you can still query the parameters corresponding to both manual and automatic ways, and they may appear contradictory.
Going back to your original question, I can understand why someone new to BLIS might be confused by the behavior of these APIs. One could imagine a patch to narrowly address your concern in the case of a single-threaded build of BLIS, one that disallows the changing of the internal data structure if multithreading is disabled. To recycle your example code, this would result in:
// printf() of bli_thread_get_num_threads();-1bli_thread_set_num_threads(2);
// printf() of bli_thread_get_num_threads();-1
We would probably also need to do the same for the individual loop-level parameters:
// printf() of bli_thread_get_jc_nt();1bli_thread_set_ways( 2, 1, 1, 1, 1 );
// printf() of bli_thread_get_jc_nt();1
The status quo asserts that, for single-threaded builds of BLIS, setting the number of threads has a visible effect (i.e., querying via bli_thread_get_num_threads() suggests your change was applied), but that effect is ignored by the implementation during execution of multithreading-eligible operations (e.g. currently level-3 operations).
A possible alternative (described in the previous post) asserts that, for single-threaded builds of BLIS, setting the number of threads has no visible effect (i.e., querying via bli_thread_get_num_threads() suggests your change was not applied) because the request to change/set the number of threads itself is ignored.
bli_thread_get_num_threads() returns the number of threads previously requested to execute
My confusion might come from me trying to compare with other blas implementations. For instance mkl_get_max_threads is documented as number of threads available to use. So for mkl it makes sense that when using the sequential threading layer, mkl_set_num_threads has no effect on mkl_get_max_threads.
I think your proposition would be less confusing for newbie users like me :)
But maybe just mentioning it the multithreading documentation would be enough.
Note: Please be aware of what happens if you try to specify both the automatic and manual ways, as it could otherwise confuse new users. Here are the important points:
Regardless of which broad method is used, if multithreading is specified via both the automatic and manual ways, the values set via the manual way will always take precedence.
Specifying parallelism for even one loop counts as specifying the manual way (in which case the ways of parallelism for the remaining loops will be assumed to be 1).
If you have specified multithreading via both the automatic and manual ways, BLIS will not complain if the values are inconsistent with one another. (For example, you may request 8 total threads be used while also specifing 4 ways of parallelism within each of two matrix multiplication loops, for a total of 16 ways.) Furthermore, you will be able to query these inconsistent values via the runtime API both before and after multithreading executes.
If multithreading is disabled, you may still specify multithreading values via either the manual or automatic ways. However, BLIS will silently ignore all of these values. A BLIS library that is built with multithreading disabled at configure-time will always run sequentially (from the prespective of a single application thread).
Activity
fgvanzee commentedon Nov 8, 2019
This more or less exists. The following code snippet is taken from the testsuite to show how it can be done:
I'll address this in a subsequent post.
fgvanzee commentedon Nov 8, 2019
This is actually a more complicated topic than it may appear.
First, let's start with the fact that, even when multithreading is enabled,
bli_thread_set_num_threads()does not return the number of threads actively running, but rather [something whose meaning is closer to] the number that will be requested when multithreading is engaged. If you look at it through that lens, the current behavior is more understandable: your example code requests two threads, but the implementation is ignoring your request (because it can't comply).Second, even with this knowledge in mind, you would be forgiven for thinking that
bli_thread_get_num_threads()returns the number of threads previously requested to execute. But that's not quite right. It's merely the value that was most recently submitted viabli_thread_set_num_threads(). So what's the nuance? BLIS exposes the individual ways of parallelism to extract for each loop in the matrix multiplication algorithm it employs. You can set these individual ways of parallelism without setting the total number viabli_thread_set_num_threads(). So what happens when you set both (ie: the manual way and the automatic way)? The manual, individual loop-specific values take priority, and the total number, whatever it may have been set to, is ignored. But in the interim, you can still query the parameters corresponding to both manual and automatic ways, and they may appear contradictory.Going back to your original question, I can understand why someone new to BLIS might be confused by the behavior of these APIs. One could imagine a patch to narrowly address your concern in the case of a single-threaded build of BLIS, one that disallows the changing of the internal data structure if multithreading is disabled. To recycle your example code, this would result in:
We would probably also need to do the same for the individual loop-level parameters:
@devinamatthews @jeffhammond @dnparikh What do you think?
fgvanzee commentedon Nov 8, 2019
@devinamatthews @jeffhammond @dnparikh Just to review, here are the options currently on the table:
bli_thread_get_num_threads()suggests your change was applied), but that effect is ignored by the implementation during execution of multithreading-eligible operations (e.g. currently level-3 operations).jeremiedbb commentedon Nov 12, 2019
Great thanks !
jeremiedbb commentedon Nov 12, 2019
My confusion might come from me trying to compare with other blas implementations. For instance
mkl_get_max_threadsis documented as number of threads available to use. So for mkl it makes sense that when using the sequential threading layer,mkl_set_num_threadshas no effect onmkl_get_max_threads.I think your proposition would be less confusing for newbie users like me :)
But maybe just mentioning it the multithreading documentation would be enough.
Tweaked/added notes to docs/Multithreading.md.
fgvanzee commentedon Nov 12, 2019
@jeremiedbb I've updated the language in the Multithreading.md document in 8f399c8:
Note: Please be aware of what happens if you try to specify both the automatic and manual ways, as it could otherwise confuse new users. Here are the important points:
jeremiedbb commentedon Nov 13, 2019
That's great, thanks a lot !
Pack B matrix for zgemm conjugate input in SUP path (flame#362)