-
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
[MRG] ENH Add BLIS support #23
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8cc1bad
add blis support
jeremiedbb 2236f63
Add ci jobs to test BLIS
jeremiedbb 6803629
trigger-ci
jeremiedbb 059a142
sort module openmp last
jeremiedbb 4467ddd
azure install with blis displayname
jeremiedbb c7a7c4c
revert test
jeremiedbb 01d21de
cln
jeremiedbb e9fc241
cln
jeremiedbb 77e84fb
cln
jeremiedbb 145fc05
add blis single threaded ci build
jeremiedbb 7031a15
fix CC inner outer
jeremiedbb b6691e5
improve coverage
jeremiedbb 86548a6
Merge branch 'master' into blis-support
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
pushd .. | ||
ABS_PATH=$(pwd) | ||
popd | ||
|
||
# Assume Ubuntu: install a recent version of clang and libomp | ||
echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main" | sudo tee -a /etc/apt/sources.list.d/llvm.list | ||
echo "deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main" | sudo tee -a /etc/apt/sources.list.d/llvm.list | ||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - | ||
sudo apt update | ||
sudo apt install clang-8 libomp-8-dev | ||
|
||
# create conda env | ||
conda create -n $VIRTUALENV -q --yes python=$VERSION_PYTHON pip cython | ||
source activate $VIRTUALENV | ||
|
||
pushd .. | ||
|
||
# build & install blis | ||
mkdir BLIS_install | ||
git clone https://github.com/flame/blis.git | ||
pushd blis | ||
./configure --prefix=$ABS_PATH/BLIS_install --enable-cblas --enable-threading=openmp CC=$BLIS_CC auto | ||
make -j4 | ||
make install | ||
popd | ||
|
||
# build & install numpy | ||
git clone https://github.com/numpy/numpy.git | ||
pushd numpy | ||
echo "[blis] | ||
libraries = blis | ||
library_dirs = $ABS_PATH/BLIS_install/lib | ||
include_dirs = $ABS_PATH/BLIS_install/include/blis | ||
runtime_library_dirs = $ABS_PATH/BLIS_install/lib" > site.cfg | ||
python setup.py build_ext -i | ||
pip install -e . | ||
popd | ||
|
||
popd | ||
|
||
python -m pip install -q -r dev-requirements.txt | ||
CFLAGS=-I$ABS_PATH/BLIS_install/include/blis LDFLAGS=-L$ABS_PATH/BLIS_install/lib \ | ||
bash ./continuous_integration/build_test_ext.sh | ||
|
||
python --version | ||
python -c "import numpy; print('numpy %s' % numpy.__version__)" || echo "no numpy" | ||
python -c "import scipy; print('scipy %s' % scipy.__version__)" || echo "no scipy" | ||
|
||
python -m flit install --symlink |
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
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
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
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
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
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 |
---|---|---|
|
@@ -74,6 +74,11 @@ class _dl_phdr_info(ctypes.Structure): | |
"internal_api": "mkl", | ||
"filename_prefixes": ("libmkl_rt", "mkl_rt",), | ||
}, | ||
{ | ||
"user_api": "blas", | ||
"internal_api": "blis", | ||
"filename_prefixes": ("libblis",), | ||
}, | ||
] | ||
|
||
# map a internal_api (openmp, openblas, mkl) to set and get functions | ||
|
@@ -88,6 +93,9 @@ class _dl_phdr_info(ctypes.Structure): | |
"mkl": { | ||
"set_num_threads": "MKL_Set_Num_Threads", | ||
"get_num_threads": "MKL_Get_Max_Threads"}, | ||
"blis": { | ||
"set_num_threads": "bli_thread_set_num_threads", | ||
"get_num_threads": "bli_thread_get_num_threads"} | ||
} | ||
|
||
# Helpers for the doc and test names | ||
|
@@ -210,6 +218,10 @@ def threadpool_info(): | |
modules = _load_modules(user_api=_ALL_USER_APIS) | ||
for module in modules: | ||
module['num_threads'] = module['get_num_threads']() | ||
# by default BLIS is single-threaded and get_num_threads returns -1. | ||
# we map it to 1 for consistency with other libraries. | ||
if module['num_threads'] == -1 and module['internal_api'] == 'blis': | ||
module['num_threads'] = 1 | ||
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. This line is allegedly not covered by any test according to codecov. Do you think it would be possible to make sure it's covered? I believe the only way is to introduce a new build configuration without |
||
# Remove the wrapper for the module and its function | ||
del module['set_num_threads'], module['get_num_threads'] | ||
del module['dynlib'] | ||
|
@@ -227,6 +239,8 @@ def _get_version(dynlib, internal_api): | |
return None | ||
elif internal_api == "openblas": | ||
return _get_openblas_version(dynlib) | ||
elif internal_api == "blis": | ||
return _get_blis_version(dynlib) | ||
else: | ||
raise NotImplementedError("Unsupported API {}".format(internal_api)) | ||
|
||
|
@@ -257,6 +271,13 @@ def _get_openblas_version(openblas_dynlib): | |
return None | ||
|
||
|
||
def _get_blis_version(blis_dynlib): | ||
"""Return the BLIS version""" | ||
get_version = getattr(blis_dynlib, "bli_info_get_version_str") | ||
get_version.restype = ctypes.c_char_p | ||
return get_version().decode('utf-8') | ||
|
||
|
||
# Loading utilities for dynamically linked shared objects | ||
|
||
def _load_modules(prefixes=None, user_api=None): | ||
|
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.
I figured out what was the cause of the hanging. Note exactly the cause but at least which line of the code was faulty. It happens if we try to call
threadpool_info
in another thread than the main thread (I was doing that in a previous commit).I don't know why but it's probably related to the bad state of OpenMP threadpool in non main thread when there are multiple openmp loaded.
Anyway, it's unrelated to this PR and should be investigated separately.
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.
I agree. I see that you opened #27 to track this issue.