Better blas/lapack and scipy packages: more robust, added shared variants.

- py-scipy now builds with netlib-lapack, openblas, and atlas.
- started a convention for passing lib info from blas/lapack implementations.

- Improved netlib-lapack:
  - Also build static libs when `shared` variant is enabled.
  - Enable CBLAS  build
    - needed minor patch to build correctly.

- Added `shared` variant to OpenBLAS.
  - Made OpenBLAS build properly shared and static.
This commit is contained in:
Todd Gamblin 2016-03-26 20:02:08 -07:00
parent cde3320582
commit 66bb71534b
3 changed files with 88 additions and 16 deletions

View file

@ -31,8 +31,16 @@ class NetlibLapack(Package):
depends_on('cmake') depends_on('cmake')
depends_on('blas', when='+external-blas') depends_on('blas', when='+external-blas')
def install(self, spec, prefix):
cmake_args = ['-DBUILD_SHARED_LIBS:BOOL=%s' % ('ON' if '+shared' in spec else 'OFF'), def patch(self):
# Fix cblas CMakeLists.txt -- has wrong case for subdirectory name.
filter_file('${CMAKE_CURRENT_SOURCE_DIR}/CMAKE/',
'${CMAKE_CURRENT_SOURCE_DIR}/cmake/', 'CBLAS/CMakeLists.txt', string=True)
def install_one(self, spec, prefix, shared):
cmake_args = ['-DBUILD_SHARED_LIBS:BOOL=%s' % ('ON' if shared else 'OFF'),
'-DCBLAS=ON', # always build CBLAS
'-DCMAKE_BUILD_TYPE:STRING=%s' % ('Debug' if '+debug' in spec else 'Release'), '-DCMAKE_BUILD_TYPE:STRING=%s' % ('Debug' if '+debug' in spec else 'Release'),
'-DLAPACKE:BOOL=%s' % ('ON' if '+lapacke' in spec else 'OFF')] '-DLAPACKE:BOOL=%s' % ('ON' if '+lapacke' in spec else 'OFF')]
if '+external-blas' in spec: if '+external-blas' in spec:
@ -45,7 +53,33 @@ def install(self, spec, prefix):
cmake_args.extend(std_cmake_args) cmake_args.extend(std_cmake_args)
with working_dir('spack-build', create=True): build_dir = 'spack-build' + ('-shared' if shared else '-static')
with working_dir(build_dir, create=True):
cmake('..', *cmake_args) cmake('..', *cmake_args)
make() make()
make("install") make("install")
def install(self, spec, prefix):
# Always build static libraries.
self.install_one(spec, prefix, False)
# Build shared libraries if requested.
if '+shared' in spec:
self.install_one(spec, prefix, True)
def setup_dependent_package(self, module, dspec):
# This is WIP for a prototype interface for virtual packages.
# We can update this as more builds start depending on BLAS/LAPACK.
libdir = find_library_path('libblas.a', self.prefix.lib64, self.prefix.lib)
self.spec.blas_static_lib = join_path(libdir, 'libblas.a')
self.spec.lapack_static_lib = join_path(libdir, 'liblapack.a')
if '+shared' in self.spec:
self.spec.blas_shared_lib = join_path(libdir, 'libblas.%s' % dso_suffix)
self.spec.lapack_shared_lib = join_path(libdir, 'liblapack.%s' % dso_suffix)

View file

@ -1,5 +1,6 @@
from spack import * from spack import *
import sys import sys
import os
class Openblas(Package): class Openblas(Package):
"""OpenBLAS: An optimized BLAS library""" """OpenBLAS: An optimized BLAS library"""
@ -10,29 +11,60 @@ class Openblas(Package):
version('0.2.16', 'fef46ab92463bdbb1479dcec594ef6dc') version('0.2.16', 'fef46ab92463bdbb1479dcec594ef6dc')
version('0.2.15', 'b1190f3d3471685f17cfd1ec1d252ac9') version('0.2.15', 'b1190f3d3471685f17cfd1ec1d252ac9')
variant('shared', default=True, description="Build shared libraries as well as static libs.")
# virtual dependency # virtual dependency
provides('blas') provides('blas')
provides('lapack') provides('lapack')
def install(self, spec, prefix): def install(self, spec, prefix):
extra=[] make_defs = ['CC=%s' % spack_cc,
'FC=%s' % spack_fc]
make_targets = ['libs', 'netlib']
# Build shared if variant is set.
if '+shared' in spec:
make_targets += ['shared']
else:
make_defs += ['NO_SHARED=1']
# fix missing _dggsvd_ and _sggsvd_
if spec.satisfies('@0.2.16'): if spec.satisfies('@0.2.16'):
extra.extend([ make_defs += ['BUILD_LAPACK_DEPRECATED=1']
'BUILD_LAPACK_DEPRECATED=1' # fix missing _dggsvd_ and _sggsvd_
])
make('libs', 'netlib', 'shared', 'CC=cc', 'FC=f77',*extra) make_args = make_defs + make_targets
make("tests") make(*make_args)
make('install', "PREFIX='%s'" % prefix)
make("tests", *make_defs)
# no quotes around prefix (spack doesn't use a shell)
make('install', "PREFIX=%s" % prefix, *make_defs)
lib_dsuffix = 'dylib' if sys.platform == 'darwin' else 'so'
# Blas virtual package should provide blas.a and libblas.a # Blas virtual package should provide blas.a and libblas.a
with working_dir(prefix.lib): with working_dir(prefix.lib):
symlink('libopenblas.a', 'blas.a') symlink('libopenblas.a', 'blas.a')
symlink('libopenblas.a', 'libblas.a') symlink('libopenblas.a', 'libblas.a')
symlink('libopenblas.%s' % lib_dsuffix, 'libblas.%s' % lib_dsuffix) if '+shared' in spec:
symlink('libopenblas.%s' % dso_suffix, 'libblas.%s' % dso_suffix)
# Lapack virtual package should provide liblapack.a # Lapack virtual package should provide liblapack.a
with working_dir(prefix.lib): with working_dir(prefix.lib):
symlink('libopenblas.a', 'liblapack.a') symlink('libopenblas.a', 'liblapack.a')
symlink('libopenblas.%s' % lib_dsuffix, 'liblapack.%s' % lib_dsuffix) if '+shared' in spec:
symlink('libopenblas.%s' % dso_suffix, 'liblapack.%s' % dso_suffix)
def setup_dependent_package(self, module, dspec):
# This is WIP for a prototype interface for virtual packages.
# We can update this as more builds start depending on BLAS/LAPACK.
libdir = find_library_path('libopenblas.a', self.prefix.lib64, self.prefix.lib)
self.spec.blas_static_lib = join_path(libdir, 'libopenblas.a')
self.spec.lapack_static_lib = self.spec.blas_static_lib
if '+shared' in self.spec:
self.spec.blas_shared_lib = join_path(libdir, 'libopenblas.%s' % dso_suffix)
self.spec.lapack_shared_lib = self.spec.blas_shared_lib

View file

@ -11,9 +11,15 @@ class PyScipy(Package):
extends('python') extends('python')
depends_on('py-nose') depends_on('py-nose')
depends_on('py-numpy') depends_on('py-numpy+blas+lapack')
depends_on('blas')
depends_on('lapack')
def install(self, spec, prefix): def install(self, spec, prefix):
if 'atlas' in spec:
# libatlas.so actually isn't always installed, but this
# seems to make the build autodetect things correctly.
env['ATLAS'] = join_path(spec['atlas'].prefix.lib, 'libatlas.' + dso_suffix)
else:
env['BLAS'] = spec['blas'].blas_shared_lib
env['LAPACK'] = spec['lapack'].lapack_shared_lib
python('setup.py', 'install', '--prefix=%s' % prefix) python('setup.py', 'install', '--prefix=%s' % prefix)