-
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
[WIP] ENH: add TBB support #47
Closed
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
16c0278
tbb support
jeremiedbb fef1066
cln
jeremiedbb dea8a49
cln
jeremiedbb 4335172
status field
jeremiedbb 16f3d7f
set_limits warn raise
jeremiedbb 4d2bb5d
add version
jeremiedbb 3301e94
run tests with tbb as threading layer
jeremiedbb dafa444
Merge remote-tracking branch 'upstream/master' into tbb-support
jeremiedbb 6e33419
merge master
jeremiedbb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,15 @@ class _dl_phdr_info(ctypes.Structure): | |
_RTLD_NOLOAD = ctypes.DEFAULT_MODE | ||
|
||
|
||
# TBB's api to globally control the threadpool is a C++ class `global_control` | ||
# which can't be accessed using ctypes. It can be accessed through tbb4py, | ||
# pythons wrappers for TBB. | ||
try: | ||
import tbb | ||
except ImportError: | ||
tbb = None | ||
|
||
|
||
# List of the supported implementations. The items hold the prefix of loaded | ||
# shared objects, the name of the internal_api to call, matching the | ||
# MAP_API_TO_FUNC keys and the name of the user_api, in {"blas", "openmp"}. | ||
|
@@ -89,6 +98,11 @@ class _dl_phdr_info(ctypes.Structure): | |
"internal_api": "blis", | ||
"filename_prefixes": ("libblis",), | ||
}, | ||
{ | ||
"user_api": "tbb", | ||
"internal_api": "tbb", | ||
"filename_prefixes": ("libtbb",), | ||
}, | ||
] | ||
|
||
# map a internal_api (openmp, openblas, mkl) to set and get functions | ||
|
@@ -262,6 +276,9 @@ def _get_version(dynlib, internal_api): | |
return _get_openblas_version(dynlib) | ||
elif internal_api == "blis": | ||
return _get_blis_version(dynlib) | ||
elif internal_api == "tbb": | ||
# tbb does not expose it's version | ||
return None | ||
else: | ||
raise NotImplementedError("Unsupported API {}".format(internal_api)) | ||
|
||
|
@@ -337,12 +354,26 @@ def _make_module_info(filepath, module_info, prefix): | |
filepath = os.path.normpath(filepath) | ||
dynlib = ctypes.CDLL(filepath, mode=_RTLD_NOLOAD) | ||
internal_api = module_info['internal_api'] | ||
set_func = getattr(dynlib, | ||
_MAP_API_TO_FUNC[internal_api]['set_num_threads'], | ||
lambda num_threads: None) | ||
get_func = getattr(dynlib, | ||
_MAP_API_TO_FUNC[internal_api]['get_num_threads'], | ||
lambda: None) | ||
|
||
if module_info['user_api'] == 'tbb': | ||
# tbb's api can't be accessed with ctypes. We access it through | ||
# tbb4py. | ||
def set_func(max_threads): | ||
if tbb is not None: | ||
tbb.global_control( | ||
tbb.global_control.max_allowed_parallelism, max_threads) | ||
def get_func(): | ||
if tbb is not None: | ||
return tbb.global_control.active_value( | ||
tbb.global_control.max_allowed_parallelism) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe move the definition outside of the function scope (something like |
||
else: | ||
set_func = getattr(dynlib, | ||
_MAP_API_TO_FUNC[internal_api]['set_num_threads'], | ||
lambda num_threads: None) | ||
get_func = getattr(dynlib, | ||
_MAP_API_TO_FUNC[internal_api]['get_num_threads'], | ||
lambda: None) | ||
|
||
module_info = module_info.copy() | ||
module_info.update(dynlib=dynlib, filepath=filepath, prefix=prefix, | ||
set_num_threads=set_func, get_num_threads=get_func, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm.. that's an interesting question. adding an issue oneapi-src/oneTBB#189
There is no way to get ready-to-use version in python package release format like 2019.2. TBB has TBB_runtime_interface_version() which return internal version which is not connected to release versions. Would that be enough or you want it to be the same as the package version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we need the version of libtbb DSO. So I guess TBB_runtime_interface_version() is what we want. Is that right ?
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I believe so.