-
Notifications
You must be signed in to change notification settings - Fork 30
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
Support registering user-defined LibController
#137
Comments
I think this would be interesting to have this feature, as this would make it simpler to support various libs compared to having a centralized implems here. If anyone wanna give it a try, feel free to propose a PR. |
I also find this approach interesting for libraries that we're not likely to support directly. I'm checking if it would be easy to implement. |
@alugowski #138 was merged with a fix. Please let us know if that good enough for your use case. |
@ogrisel It should work, but my controller methods do not get called at all. I installed via My controller code: https://github.com/alugowski/fast_matrix_market/blob/954331f9d65e4ce8b56dc8009cd09cc70e93f08e/python/src/fast_matrix_market/__init__.py#L49 I copy/pasted the example then modified it to fit my usecase, which is to just modify a global variable that I already had. and I call it like this: >>> from fast_matrix_market import mmread
registered with threadpoolctl
>>>
>>> from threadpoolctl import threadpool_limits
>>>
>>> with threadpool_limits(limits=1, user_api='fast_matrix_market'):
... mmread("asdf.mtx")
...
parallelism: 0 Note that none of the controller print statements have printed. Not the version getter, and neither set or get num threads. |
It's important to specify the known filename prefixe(s) if the dynamic library (e.g. the beginning of the filename that ends in .so on linux, .dylib on masos, or .dll on windows) that holds the symbols. |
Looking at the list of loaded libraries when I import |
Ok, so adding the library name to But why is it necessary? My controller does not call any methods from the library, nor does it need to. The library itself is stateless, and I'd prefer to keep it that way. The thread control is purely on the Python side. How would a pure-Python library implement a controller? |
As explained here #134 (comment), this is not the purpose of threadpoolctl. threadpoolctl is essentially a tool to introspect the dynamic shared objects loaded by a python program in a robust and cross-platform manner, in order to call some functions from the libraries implementing their own threadpools, packaged in a simple python context manager. Libraries that can be controlled from python are not in the original scope of this project since for those it's already easy to provide such a context manager. |
That's fair. Note it's an argument for closing nearly all of the outstanding library support tickets, though. TF, Arrow, TBB, all have Python-accessible ways to control parallelism. A parallel library that exposes itself to Python but without parallelism control is an outlier, and you currently support most such outliers. My thoughts are echoed by your very next post in that thread:
That's very powerful. Powerful in several ways. The obvious one is a common interface for something that varies a lot. Some libraries accept an argument for each method (is it Another power is that some parallel methods are called as dependencies, and the middle layer may or may not expose a way to control parallelism of its dependencies. threadpoolctl may be the only way in such cases. For example, the library I linked earlier is currently under review for inclusion in SciPy. Nearly every parallel operation in SciPy is controlled by |
These are all valid points and I'm definitely not opposed to have threadpoolctl being used like that. My previous comment was more to explain the reason and give some context about why giving the name of the dso is necessary. In addition, the name of the dso is necessary to be able to figure out which shared libraries are actually loaded in order to instanciate their corresponding controller. Anyway, I don't think that having to provide the filename prefix is an issue for your controller. For this use case we can just see that as to provide a way for threadpoolctl to find out if the underlying shared library is loaded or not. |
Sounds good :) Thanks again for the new feature! |
Very useful library.
I've gotten a request for my own library to be able to be controlled via
threadpoolctl
, and I agree that would be a positive thing to support, but it's currently impossible. Whilethreadpoolctl
is well designed and it appears to be easy to support new parallel libraries, the list ofLibController
s is static.Would it be possible to add a feature where libraries could add support to register themselves with
threadpoolctl
?For example, something like
I imagine it's a big burden for the
threadpoolctl
authors to support all popular libraries out there, but with such a feature those library authors (or their users) could write such hooks ourselves.There are several open requests for Apple Accelerate, arrow, TensorFlow, and I would be interested in taskflow or Eigen's threadpool, too. Additionally there are many smaller libraries, or ones using Python threads, that could easily be supported by bespoke
LibController
s with no effort on your part.The text was updated successfully, but these errors were encountered: