Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5962290

Browse files
authored
Merge pull request #13158 from zerothi/linalg-flame
BLD: Add libflame as a LAPACK back-end
2 parents 9b89cfd + ae34b54 commit 5962290

File tree

4 files changed

+145
-4
lines changed

4 files changed

+145
-4
lines changed

doc/release/1.17.0-notes.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,38 @@ C API changes
121121
New Features
122122
============
123123

124+
libFLAME
125+
--------
126+
Support for building NumPy with the libFLAME linear algebra package as the LAPACK,
127+
implementation, see
128+
`libFLAME <https://www.cs.utexas.edu/~flame/web/libFLAME.html>`_ for details.
129+
130+
User-defined BLAS detection order
131+
---------------------------------
132+
``numpy.distutils`` now uses an environment variable, comma-separated and case
133+
insensitive, to determine the detection order for BLAS libraries.
134+
By default ``NPY_BLAS_ORDER=mkl,blis,openblas,atlas,accelerate,blas``.
135+
However, to force the use of OpenBLAS simply do::
136+
137+
NPY_BLAS_ORDER=openblas python setup.py build
138+
139+
which forces the use of OpenBLAS.
140+
This may be helpful for users which have a MKL installation but wishes to try
141+
out different implementations.
142+
143+
User-defined LAPACK detection order
144+
-----------------------------------
145+
``numpy.distutils`` now uses an environment variable, comma-separated and case
146+
insensitive, to determine the detection order for LAPAK libraries.
147+
By default ``NPY_BLAS_ORDER=mkl,openblas,flame,atlas,accelerate,lapack``.
148+
However, to force the use of OpenBLAS simply do::
149+
150+
NPY_LAPACK_ORDER=openblas python setup.py build
151+
152+
which forces the use of OpenBLAS.
153+
This may be helpful for users which have a MKL installation but wishes to try
154+
out different implementations.
155+
124156
``np.ufunc.reduce`` and related functions now accept a ``where`` mask
125157
---------------------------------------------------------------------
126158
``np.ufunc.reduce``, ``np.sum``, ``np.prod``, ``np.min``, ``np.max`` all

doc/source/user/building.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ The default order for the libraries are:
155155

156156
1. MKL
157157
2. OpenBLAS
158-
3. ATLAS
159-
4. Accelerate (MacOS)
160-
5. LAPACK (NetLIB)
158+
3. libFLAME
159+
4. ATLAS
160+
5. Accelerate (MacOS)
161+
6. LAPACK (NetLIB)
161162

162163

163164
If you wish to build against OpenBLAS but you also have MKL available one

numpy/distutils/system_info.py

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
atlas_3_10_blas_threads_info,
1818
lapack_atlas_3_10_info
1919
lapack_atlas_3_10_threads_info
20+
flame_info
2021
blas_info
2122
lapack_info
2223
openblas_info
@@ -389,6 +390,7 @@ def get_info(name, notfound_action=0):
389390
'atlas_3_10_blas_threads': atlas_3_10_blas_threads_info,
390391
'lapack_atlas_3_10': lapack_atlas_3_10_info, # use lapack_opt instead
391392
'lapack_atlas_3_10_threads': lapack_atlas_3_10_threads_info, # ditto
393+
'flame': flame_info, # use lapack_opt instead
392394
'mkl': mkl_info,
393395
# openblas which may or may not have embedded lapack
394396
'openblas': openblas_info, # use blas_opt instead
@@ -464,6 +466,13 @@ class AtlasNotFoundError(NotFoundError):
464466
the ATLAS environment variable."""
465467

466468

469+
class FlameNotFoundError(NotFoundError):
470+
"""
471+
FLAME (http://www.cs.utexas.edu/~flame/web/) libraries not found.
472+
Directories to search for the libraries can be specified in the
473+
numpy/distutils/site.cfg file (section [flame])."""
474+
475+
467476
class LapackNotFoundError(NotFoundError):
468477
"""
469478
Lapack (http://www.netlib.org/lapack/) libraries not found.
@@ -1591,7 +1600,7 @@ class lapack_opt_info(system_info):
15911600

15921601
notfounderror = LapackNotFoundError
15931602
# Default order of LAPACK checks
1594-
lapack_order = ['mkl', 'openblas', 'atlas', 'accelerate', 'lapack']
1603+
lapack_order = ['mkl', 'openblas', 'flame', 'atlas', 'accelerate', 'lapack']
15951604

15961605
def _calc_info_mkl(self):
15971606
info = get_info('lapack_mkl')
@@ -1611,6 +1620,13 @@ def _calc_info_openblas(self):
16111620
return True
16121621
return False
16131622

1623+
def _calc_info_flame(self):
1624+
info = get_info('flame')
1625+
if info:
1626+
self.set_info(**info)
1627+
return True
1628+
return False
1629+
16141630
def _calc_info_atlas(self):
16151631
info = get_info('atlas_3_10_threads')
16161632
if not info:
@@ -2043,6 +2059,82 @@ def calc_info(self):
20432059
include_dirs=incl_dirs)
20442060
self.set_info(**info)
20452061

2062+
2063+
class flame_info(system_info):
2064+
""" Usage of libflame for LAPACK operations
2065+
2066+
This requires libflame to be compiled with lapack wrappers:
2067+
2068+
./configure --enable-lapack2flame ...
2069+
2070+
Be aware that libflame 5.1.0 has some missing names in the shared library, so
2071+
if you have problems, try the static flame library.
2072+
"""
2073+
section = 'flame'
2074+
_lib_names = ['flame']
2075+
notfounderror = FlameNotFoundError
2076+
2077+
def check_embedded_lapack(self, info):
2078+
""" libflame does not necessarily have a wrapper for fortran LAPACK, we need to check """
2079+
c = customized_ccompiler()
2080+
2081+
tmpdir = tempfile.mkdtemp()
2082+
s = """void zungqr_();
2083+
int main(int argc, const char *argv[])
2084+
{
2085+
zungqr_();
2086+
return 0;
2087+
}"""
2088+
src = os.path.join(tmpdir, 'source.c')
2089+
out = os.path.join(tmpdir, 'a.out')
2090+
# Add the additional "extra" arguments
2091+
extra_args = info.get('extra_link_args', [])
2092+
try:
2093+
with open(src, 'wt') as f:
2094+
f.write(s)
2095+
obj = c.compile([src], output_dir=tmpdir)
2096+
try:
2097+
c.link_executable(obj, out, libraries=info['libraries'],
2098+
library_dirs=info['library_dirs'],
2099+
extra_postargs=extra_args)
2100+
return True
2101+
except distutils.ccompiler.LinkError:
2102+
return False
2103+
finally:
2104+
shutil.rmtree(tmpdir)
2105+
2106+
def calc_info(self):
2107+
lib_dirs = self.get_lib_dirs()
2108+
flame_libs = self.get_libs('libraries', self._lib_names)
2109+
2110+
info = self.check_libs2(lib_dirs, flame_libs, [])
2111+
if info is None:
2112+
return
2113+
2114+
if self.check_embedded_lapack(info):
2115+
# check if the user has supplied all information required
2116+
self.set_info(**info)
2117+
else:
2118+
# Try and get the BLAS lib to see if we can get it to work
2119+
blas_info = get_info('blas_opt')
2120+
if not blas_info:
2121+
# since we already failed once, this ain't going to work either
2122+
return
2123+
2124+
# Now we need to merge the two dictionaries
2125+
for key in blas_info:
2126+
if isinstance(blas_info[key], list):
2127+
info[key] = info.get(key, []) + blas_info[key]
2128+
elif isinstance(blas_info[key], tuple):
2129+
info[key] = info.get(key, ()) + blas_info[key]
2130+
else:
2131+
info[key] = info.get(key, '') + blas_info[key]
2132+
2133+
# Now check again
2134+
if self.check_embedded_lapack(info):
2135+
self.set_info(**info)
2136+
2137+
20462138
class accelerate_info(system_info):
20472139
section = 'accelerate'
20482140
_lib_names = ['accelerate', 'veclib']

site.cfg.example

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,22 @@
153153
# include_dirs = /home/username/blis/include/blis
154154
# runtime_library_dirs = /home/username/blis/lib
155155

156+
# libFLAME
157+
# --------
158+
# libFLAME (https://www.cs.utexas.edu/~flame/web/libFLAME.html) provides a
159+
# LAPACK interface. It's a relatively new library, its performance in some
160+
# cases seems to match that of MKL and OpenBLAS.
161+
# It hasn't been benchmarked with NumPy or SciPy yet.
162+
#
163+
# Notes on compiling libFLAME itself:
164+
# - the LAPACK interface (needed by NumPy) isn't built by default; please
165+
# configure with ``./configure --enable-lapack2flame``.
166+
#
167+
# [flame]
168+
# libraries = flame
169+
# library_dirs = /home/username/flame/lib
170+
# runtime_library_dirs = /home/username/flame/lib
171+
156172
# MKL
157173
#----
158174
# Intel MKL is Intel's very optimized yet proprietary implementation of BLAS and

0 commit comments

Comments
 (0)