Skip to content

Commit

Permalink
Merge pull request #3642 from jseabold/openblas-install
Browse files Browse the repository at this point in the history
BLD: Allow easy use of openblas.
  • Loading branch information
charris committed Sep 5, 2013
2 parents 573b3b0 + fb0c7bd commit b5dab6d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 61 deletions.
70 changes: 51 additions & 19 deletions numpy/distutils/system_info.py
Expand Up @@ -12,6 +12,7 @@
lapack_atlas_info
blas_info
lapack_info
openblas_info
blas_opt_info # usage recommended
lapack_opt_info # usage recommended
fftw_info,dfftw_info,sfftw_info
Expand Down Expand Up @@ -119,7 +120,6 @@
import warnings
from glob import glob
from functools import reduce

if sys.version_info[0] < 3:
from ConfigParser import NoOptionError, ConfigParser
else:
Expand Down Expand Up @@ -298,6 +298,7 @@ def get_info(name, notfound_action=0):
'lapack_atlas': lapack_atlas_info, # use lapack_opt instead
'lapack_atlas_threads': lapack_atlas_threads_info, # ditto
'mkl': mkl_info,
'openblas': openblas_info, # use blas_opt instead
'lapack_mkl': lapack_mkl_info, # use lapack_opt instead
'blas_mkl': blas_mkl_info, # use blas_opt instead
'x11': x11_info,
Expand Down Expand Up @@ -1366,7 +1367,22 @@ class lapack_opt_info(system_info):

def calc_info(self):

if sys.platform == 'darwin' and not os.environ.get('ATLAS', None):
openblas_info = get_info('openblas')
if openblas_info:
self.set_info(**openblas_info)
return

lapack_mkl_info = get_info('lapack_mkl')
if lapack_mkl_info:
self.set_info(**lapack_mkl_info)
return

atlas_info = get_info('atlas_threads')
if not atlas_info:
atlas_info = get_info('atlas')

if sys.platform == 'darwin' and not atlas_info:
# Use the system lapack from Accelerate or vecLib under OSX
args = []
link_args = []
if get_platform()[-4:] == 'i386' or 'intel' in get_platform() or \
Expand Down Expand Up @@ -1394,14 +1410,6 @@ def calc_info(self):
define_macros=[('NO_ATLAS_INFO', 3)])
return

lapack_mkl_info = get_info('lapack_mkl')
if lapack_mkl_info:
self.set_info(**lapack_mkl_info)
return

atlas_info = get_info('atlas_threads')
if not atlas_info:
atlas_info = get_info('atlas')
#atlas_info = {} ## uncomment for testing
need_lapack = 0
need_blas = 0
Expand Down Expand Up @@ -1455,7 +1463,22 @@ class blas_opt_info(system_info):

def calc_info(self):

if sys.platform == 'darwin' and not os.environ.get('ATLAS', None):
blas_mkl_info = get_info('blas_mkl')
if blas_mkl_info:
self.set_info(**blas_mkl_info)
return

openblas_info = get_info('openblas')
if openblas_info:
self.set_info(**openblas_info)
return

atlas_info = get_info('atlas_blas_threads')
if not atlas_info:
atlas_info = get_info('atlas_blas')

if sys.platform == 'darwin'and not atlas_info:
# Use the system BLAS from Accelerate or vecLib under OSX
args = []
link_args = []
if get_platform()[-4:] == 'i386' or 'intel' in get_platform() or \
Expand Down Expand Up @@ -1487,14 +1510,6 @@ def calc_info(self):
define_macros=[('NO_ATLAS_INFO', 3)])
return

blas_mkl_info = get_info('blas_mkl')
if blas_mkl_info:
self.set_info(**blas_mkl_info)
return

atlas_info = get_info('atlas_blas_threads')
if not atlas_info:
atlas_info = get_info('atlas_blas')
need_blas = 0
info = {}
if atlas_info:
Expand Down Expand Up @@ -1537,6 +1552,23 @@ def calc_info(self):
self.set_info(**info)


class openblas_info(blas_info):
section = 'openblas'
dir_env_var = 'OPENBLAS'
_lib_names = ['openblas']
notfounderror = BlasNotFoundError

def calc_info(self):
lib_dirs = self.get_lib_dirs()

openblas_libs = self.get_libs('openblas_libs', self._lib_names)
info = self.check_libs(lib_dirs, openblas_libs, [])
if info is None:
return
info['language'] = 'f77' # XXX: is it generally true?
self.set_info(**info)


class blas_src_info(system_info):
section = 'blas_src'
dir_env_var = 'BLAS_SRC'
Expand Down
81 changes: 39 additions & 42 deletions site.cfg.example
Expand Up @@ -63,33 +63,46 @@
#library_dirs = /usr/local/lib
#include_dirs = /usr/local/include

# Optimized BLAS and LAPACK
# -------------------------
# Use the blas_opt and lapack_opt sections to give any settings that are
# required to link against your chosen BLAS and LAPACK, including the regular
# FORTRAN reference BLAS and also ATLAS. Some other sections still exist for
# linking against certain optimized libraries (e.g. [atlas], [lapack_atlas]),
# however, they are now deprecated and should not be used.
#
# These are typical configurations for ATLAS (assuming that the library and
# include directories have already been set in [DEFAULT]; the include directory
# is important for the BLAS C interface):
#
#[blas_opt]
#libraries = f77blas, cblas, atlas
#
#[lapack_opt]
#libraries = lapack, f77blas, cblas, atlas
#
# If your ATLAS was compiled with pthreads, the names of the libraries might be
# different:
#
#[blas_opt]
#libraries = ptf77blas, ptcblas, atlas
#
#[lapack_opt]
#libraries = lapack, ptf77blas, ptcblas, atlas
# Atlas
# -----
# Atlas is an open source optimized implementation of the BLAS and Lapack
# routines. Numpy will try to build against Atlas by default when available in
# the system library dirs. To build numpy against a custom installation of
# Atlas you can add an explicit section such as the following. Here we assume
# that Atlas was configured with ``prefix=/opt/atlas``.
#
# [atlas]
# library_dirs = /opt/atlas/lib
# include_dirs = /opt/atlas/include

# OpenBLAS
# --------
# OpenBLAS is another open source optimized implementation of BLAS and Lapack
# and can be seen as an alternative to Atlas. To build numpy against OpenBLAS
# instead of Atlas, use this section instead of the above, adjusting as needed
# for your configuration (in the following example we installed OpenBLAS with
# ``make install PREFIX=/opt/OpenBLAS``.
#
# [openblas]
# libraries = openblas
# library_dirs = /opt/OpenBLAS/lib
# include_dirs = /opt/OpenBLAS/include

# MKL
#----
# MKL is Intel's very optimized yet proprietary implementation of BLAS and
# Lapack.
# For recent (9.0.21, for example) mkl, you need to change the names of the
# lapack library. Assuming you installed the mkl in /opt, for a 32 bits cpu:
# [mkl]
# library_dirs = /opt/intel/mkl/9.1.023/lib/32/
# lapack_libs = mkl_lapack
#
# For 10.*, on 32 bits machines:
# [mkl]
# library_dirs = /opt/intel/mkl/10.0.1.014/lib/32/
# lapack_libs = mkl_lapack
# mkl_libs = mkl, guide

# UMFPACK
# -------
Expand All @@ -110,7 +123,6 @@
#[umfpack]
#umfpack_libs = umfpack


# FFT libraries
# -------------
# There are two FFT libraries that we can configure here: FFTW (2 and 3) and djbfft.
Expand All @@ -128,18 +140,3 @@
#[djbfft]
#include_dirs = /usr/local/djbfft/include
#library_dirs = /usr/local/djbfft/lib


# MKL
#----
# For recent (9.0.21, for example) mkl, you need to change the names of the
# lapack library. Assuming you installed the mkl in /opt, for a 32 bits cpu:
# [mkl]
# library_dirs = /opt/intel/mkl/9.1.023/lib/32/
# lapack_libs = mkl_lapack
#
# For 10.*, on 32 bits machines:
# [mkl]
# library_dirs = /opt/intel/mkl/10.0.1.014/lib/32/
# lapack_libs = mkl_lapack
# mkl_libs = mkl, guide

0 comments on commit b5dab6d

Please sign in to comment.