2018-10-08 04:52:23 +08:00
|
|
|
# Copyright 2013-2018 Lawrence Livermore National Security, LLC and other
|
|
|
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
2016-05-12 12:22:25 +08:00
|
|
|
#
|
2018-10-08 04:52:23 +08:00
|
|
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
|
|
|
2017-10-23 20:23:00 +08:00
|
|
|
import os
|
|
|
|
|
2015-11-24 05:48:06 +08:00
|
|
|
from spack import *
|
2017-10-23 20:23:00 +08:00
|
|
|
from spack.package_test import compare_output_file, compile_c_and_execute
|
2017-06-15 19:38:24 +08:00
|
|
|
import spack.architecture
|
2016-05-11 21:45:57 +08:00
|
|
|
|
2015-11-24 05:48:06 +08:00
|
|
|
|
2016-12-16 02:15:52 +08:00
|
|
|
class Openblas(MakefilePackage):
|
2015-11-24 05:48:06 +08:00
|
|
|
"""OpenBLAS: An optimized BLAS library"""
|
2018-07-24 09:55:17 +08:00
|
|
|
|
2016-12-16 02:15:52 +08:00
|
|
|
homepage = 'http://www.openblas.net'
|
2018-07-24 09:55:17 +08:00
|
|
|
url = 'http://github.com/xianyi/OpenBLAS/archive/v0.2.19.tar.gz'
|
|
|
|
git = 'https://github.com/xianyi/OpenBLAS.git'
|
2015-11-24 05:48:06 +08:00
|
|
|
|
2018-07-24 09:55:17 +08:00
|
|
|
version('develop', branch='develop')
|
2018-09-01 02:14:37 +08:00
|
|
|
version('0.3.3', sha256='49d88f4494ae780e3d7fa51769c00d982d7cdb73e696054ac3baa81d42f13bab')
|
2018-08-02 08:14:48 +08:00
|
|
|
version('0.3.2', sha256='e8ba64f6b103c511ae13736100347deb7121ba9b41ba82052b1a018a65c0cb15')
|
2018-09-04 09:49:45 +08:00
|
|
|
version('0.3.1', sha256='1f5e956f35f3acdd3c74516e955d797a320c2e0135e31d838cbdb3ea94d0eb33')
|
2018-06-15 02:43:05 +08:00
|
|
|
version('0.3.0', '42cde2c1059a8a12227f1e6551c8dbd2')
|
2017-07-27 21:51:39 +08:00
|
|
|
version('0.2.20', '48637eb29f5b492b91459175dcc574b1')
|
2016-09-20 17:13:25 +08:00
|
|
|
version('0.2.19', '28c998054fd377279741c6f0b9ea7941')
|
2016-04-20 16:06:49 +08:00
|
|
|
version('0.2.18', '805e7f660877d588ea7e3792cda2ee65')
|
2016-03-24 02:40:16 +08:00
|
|
|
version('0.2.17', '664a12807f2a2a7cda4781e3ab2ae0e1')
|
2016-03-18 01:55:45 +08:00
|
|
|
version('0.2.16', 'fef46ab92463bdbb1479dcec594ef6dc')
|
2015-11-24 05:48:06 +08:00
|
|
|
version('0.2.15', 'b1190f3d3471685f17cfd1ec1d252ac9')
|
2017-02-21 07:40:46 +08:00
|
|
|
|
2016-12-16 02:15:52 +08:00
|
|
|
variant(
|
|
|
|
'shared',
|
|
|
|
default=True,
|
|
|
|
description='Build shared libraries as well as static libs.'
|
|
|
|
)
|
2017-09-12 14:40:28 +08:00
|
|
|
variant('ilp64', default=False, description='64 bit integers')
|
2016-12-16 02:15:52 +08:00
|
|
|
variant('pic', default=True, description='Build position independent code')
|
2016-03-27 11:02:08 +08:00
|
|
|
|
2017-09-22 03:28:24 +08:00
|
|
|
variant('cpu_target', default='',
|
|
|
|
description='Set CPU target architecture (leave empty for '
|
|
|
|
'autodetection; GENERIC, SSE_GENERIC, NEHALEM, ...)')
|
|
|
|
|
2017-09-24 04:27:42 +08:00
|
|
|
variant(
|
|
|
|
'threads', default='none',
|
|
|
|
description='Multithreading support',
|
|
|
|
values=('pthreads', 'openmp', 'none'),
|
|
|
|
multi=False
|
|
|
|
)
|
|
|
|
|
2017-11-16 02:32:02 +08:00
|
|
|
variant(
|
|
|
|
'virtual_machine',
|
|
|
|
default=False,
|
|
|
|
description="Adding options to build openblas on Linux virtual machine"
|
|
|
|
)
|
|
|
|
|
2015-11-24 05:48:06 +08:00
|
|
|
# virtual dependency
|
|
|
|
provides('blas')
|
|
|
|
provides('lapack')
|
|
|
|
|
2017-02-18 04:03:43 +08:00
|
|
|
patch('make.patch', when='@0.2.16:')
|
2016-10-26 02:12:22 +08:00
|
|
|
# This patch is in a pull request to OpenBLAS that has not been handled
|
|
|
|
# https://github.com/xianyi/OpenBLAS/pull/915
|
2017-08-04 22:34:58 +08:00
|
|
|
# UPD: the patch has been merged starting version 0.2.20
|
|
|
|
patch('openblas_icc.patch', when='@:0.2.19%intel')
|
2018-07-04 05:25:12 +08:00
|
|
|
patch('openblas_icc_openmp.patch', when='@:0.2.20%intel@16.0:')
|
2017-04-29 03:54:59 +08:00
|
|
|
patch('openblas_icc_fortran.patch', when='%intel@16.0:')
|
2017-11-23 22:28:35 +08:00
|
|
|
patch('openblas_icc_fortran2.patch', when='%intel@18.0:')
|
2016-03-27 11:02:08 +08:00
|
|
|
|
2017-08-06 01:56:04 +08:00
|
|
|
# Fixes compilation error on POWER8 with GCC 7
|
|
|
|
# https://github.com/xianyi/OpenBLAS/pull/1098
|
|
|
|
patch('power8.patch', when='@0.2.18:0.2.19 %gcc@7.1.0: target=ppc64')
|
|
|
|
|
2017-04-17 22:16:18 +08:00
|
|
|
# Change file comments to work around clang 3.9 assembler bug
|
|
|
|
# https://github.com/xianyi/OpenBLAS/pull/982
|
|
|
|
patch('openblas0.2.19.diff', when='@0.2.19')
|
|
|
|
|
2018-09-04 09:49:45 +08:00
|
|
|
# Fix CMake export symbol error
|
|
|
|
# https://github.com/xianyi/OpenBLAS/pull/1703
|
|
|
|
patch('openblas-0.3.2-cmake.patch', when='@0.3.1:0.3.2')
|
|
|
|
|
2018-10-11 09:58:47 +08:00
|
|
|
# Disable experimental TLS code that lead to many threading issues
|
|
|
|
# https://github.com/xianyi/OpenBLAS/issues/1735#issuecomment-422954465
|
|
|
|
# https://github.com/xianyi/OpenBLAS/issues/1761#issuecomment-421039174
|
|
|
|
# https://github.com/xianyi/OpenBLAS/pull/1765
|
|
|
|
patch('https://github.com/xianyi/OpenBLAS/commit/4d183e5567346f80f2ef97eb98f8601c47f8cb56.patch',
|
|
|
|
sha256='714aea33692304a50bd0ccde42590c176c82ded4a8ac7f06e573dc8071929c33',
|
|
|
|
when='@0.3.3')
|
|
|
|
|
2016-12-18 09:04:59 +08:00
|
|
|
parallel = False
|
|
|
|
|
2017-04-03 02:40:09 +08:00
|
|
|
conflicts('%intel@16', when='@0.2.15:0.2.19')
|
|
|
|
|
2017-01-25 23:57:01 +08:00
|
|
|
@run_before('edit')
|
2016-12-16 02:15:52 +08:00
|
|
|
def check_compilers(self):
|
2016-06-19 17:59:10 +08:00
|
|
|
# As of 06/2016 there is no mechanism to specify that packages which
|
|
|
|
# depends on Blas/Lapack need C or/and Fortran symbols. For now
|
|
|
|
# require both.
|
2017-11-24 14:15:01 +08:00
|
|
|
if self.compiler.fc is None:
|
2016-12-16 02:15:52 +08:00
|
|
|
raise InstallError(
|
|
|
|
'OpenBLAS requires both C and Fortran compilers!'
|
|
|
|
)
|
2017-11-24 14:15:01 +08:00
|
|
|
|
2016-12-16 02:15:52 +08:00
|
|
|
# Add support for OpenMP
|
2017-09-24 04:27:42 +08:00
|
|
|
if (self.spec.satisfies('threads=openmp') and
|
|
|
|
self.spec.satisfies('%clang')):
|
2017-08-16 05:57:11 +08:00
|
|
|
if str(self.spec.compiler.version).endswith('-apple'):
|
|
|
|
raise InstallError("Apple's clang does not support OpenMP")
|
|
|
|
if '@:0.2.19' in self.spec:
|
|
|
|
# Openblas (as of 0.2.19) hardcoded that OpenMP cannot
|
|
|
|
# be used with any (!) compiler named clang, bummer.
|
|
|
|
raise InstallError(
|
|
|
|
'OpenBLAS @:0.2.19 does not support OpenMP with clang!'
|
|
|
|
)
|
2016-06-19 17:59:10 +08:00
|
|
|
|
2016-12-16 02:15:52 +08:00
|
|
|
@property
|
|
|
|
def make_defs(self):
|
2017-11-24 14:15:01 +08:00
|
|
|
# Configure fails to pick up fortran from FC=/abs/path/to/fc, but
|
2016-05-13 16:10:38 +08:00
|
|
|
# works fine with FC=/abs/path/to/gfortran.
|
|
|
|
# When mixing compilers make sure that
|
|
|
|
# $SPACK_ROOT/lib/spack/env/<compiler> have symlinks with reasonable
|
|
|
|
# names and hack them inside lib/spack/spack/compilers/<compiler>.py
|
2016-12-18 09:04:59 +08:00
|
|
|
|
2016-12-16 02:15:52 +08:00
|
|
|
make_defs = [
|
|
|
|
'CC={0}'.format(spack_cc),
|
2017-11-24 14:15:01 +08:00
|
|
|
'FC={0}'.format(spack_fc),
|
2016-12-16 02:15:52 +08:00
|
|
|
'MAKE_NO_J=1'
|
|
|
|
]
|
2017-11-16 02:32:02 +08:00
|
|
|
|
|
|
|
if self.spec.variants['virtual_machine'].value:
|
|
|
|
make_defs += [
|
|
|
|
'DYNAMIC_ARCH=1',
|
|
|
|
'NO_AVX2=1'
|
|
|
|
]
|
|
|
|
|
2017-09-22 03:28:24 +08:00
|
|
|
if self.spec.variants['cpu_target'].value:
|
|
|
|
make_defs += [
|
|
|
|
'TARGET={0}'.format(self.spec.variants['cpu_target'].value)
|
|
|
|
]
|
2017-06-15 19:38:24 +08:00
|
|
|
# invoke make with the correct TARGET for aarch64
|
2017-09-22 03:28:24 +08:00
|
|
|
elif 'aarch64' in spack.architecture.sys_type():
|
2017-06-15 19:38:24 +08:00
|
|
|
make_defs += [
|
|
|
|
'TARGET=PILEDRIVER',
|
|
|
|
'TARGET=ARMV8'
|
|
|
|
]
|
2016-12-18 09:04:59 +08:00
|
|
|
if self.spec.satisfies('%gcc@:4.8.4'):
|
|
|
|
make_defs += ['NO_AVX2=1']
|
2016-12-16 02:15:52 +08:00
|
|
|
if '~shared' in self.spec:
|
|
|
|
if '+pic' in self.spec:
|
|
|
|
make_defs.extend([
|
|
|
|
'CFLAGS={0}'.format(self.compiler.pic_flag),
|
|
|
|
'FFLAGS={0}'.format(self.compiler.pic_flag)
|
|
|
|
])
|
2016-03-27 11:02:08 +08:00
|
|
|
make_defs += ['NO_SHARED=1']
|
|
|
|
# fix missing _dggsvd_ and _sggsvd_
|
2016-12-16 02:15:52 +08:00
|
|
|
if self.spec.satisfies('@0.2.16'):
|
2016-03-27 11:02:08 +08:00
|
|
|
make_defs += ['BUILD_LAPACK_DEPRECATED=1']
|
2017-09-24 04:27:42 +08:00
|
|
|
|
|
|
|
# Add support for multithreading
|
|
|
|
if self.spec.satisfies('threads=openmp'):
|
|
|
|
make_defs += ['USE_OPENMP=1', 'USE_THREAD=1']
|
|
|
|
elif self.spec.satisfies('threads=pthreads'):
|
|
|
|
make_defs += ['USE_OPENMP=0', 'USE_THREAD=1']
|
|
|
|
else:
|
|
|
|
make_defs += ['USE_OPENMP=0', 'USE_THREAD=0']
|
2016-04-12 05:28:30 +08:00
|
|
|
|
2017-09-12 14:40:28 +08:00
|
|
|
# 64bit ints
|
|
|
|
if '+ilp64' in self.spec:
|
|
|
|
make_defs += ['INTERFACE64=1']
|
|
|
|
|
2016-12-16 02:15:52 +08:00
|
|
|
return make_defs
|
2016-03-24 02:40:16 +08:00
|
|
|
|
2016-12-16 02:15:52 +08:00
|
|
|
@property
|
|
|
|
def build_targets(self):
|
|
|
|
targets = ['libs', 'netlib']
|
2016-03-27 11:02:08 +08:00
|
|
|
|
2016-12-16 02:15:52 +08:00
|
|
|
# Build shared if variant is set.
|
|
|
|
if '+shared' in self.spec:
|
|
|
|
targets += ['shared']
|
2015-11-24 05:48:06 +08:00
|
|
|
|
2016-12-16 02:15:52 +08:00
|
|
|
return self.make_defs + targets
|
|
|
|
|
2017-01-25 23:57:01 +08:00
|
|
|
@run_after('build')
|
2017-04-22 01:15:39 +08:00
|
|
|
@on_package_attributes(run_tests=True)
|
2016-12-16 02:15:52 +08:00
|
|
|
def check_build(self):
|
|
|
|
make('tests', *self.make_defs)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def install_targets(self):
|
|
|
|
make_args = [
|
|
|
|
'install',
|
|
|
|
'PREFIX={0}'.format(self.prefix),
|
|
|
|
]
|
|
|
|
return make_args + self.make_defs
|
|
|
|
|
2017-01-25 23:57:01 +08:00
|
|
|
@run_after('install')
|
2017-04-22 01:15:39 +08:00
|
|
|
@on_package_attributes(run_tests=True)
|
2016-12-16 02:15:52 +08:00
|
|
|
def check_install(self):
|
|
|
|
spec = self.spec
|
2016-04-25 15:57:48 +08:00
|
|
|
# Openblas may pass its own test but still fail to compile Lapack
|
2016-05-11 21:45:57 +08:00
|
|
|
# symbols. To make sure we get working Blas and Lapack, do a small
|
|
|
|
# test.
|
2016-04-27 17:57:48 +08:00
|
|
|
source_file = join_path(os.path.dirname(self.module.__file__),
|
|
|
|
'test_cblas_dgemm.c')
|
2016-05-11 21:02:14 +08:00
|
|
|
blessed_file = join_path(os.path.dirname(self.module.__file__),
|
|
|
|
'test_cblas_dgemm.output')
|
2016-04-27 17:57:48 +08:00
|
|
|
|
Python command, libraries, and headers (#3367)
## Motivation
Python installations are both important and unfortunately inconsistent. Depending on the Python version, OS, and the strength of the Earth's magnetic field when it was installed, the name of the Python executable, directory containing its libraries, library names, and the directory containing its headers can vary drastically.
I originally got into this mess with #3274, where I discovered that Boost could not be built with Python 3 because the executable is called `python3` and we were telling it to use `python`. I got deeper into this mess when I started hacking on #3140, where I discovered just how difficult it is to find the location and name of the Python libraries and headers.
Currently, half of the packages that depend on Python and need to know this information jump through hoops to determine the correct information. The other half are hard-coded to use `python`, `spec['python'].prefix.lib`, and `spec['python'].prefix.include`. Obviously, none of these packages would work for Python 3, and there's no reason to duplicate the effort. The Python package itself should contain all of the information necessary to use it properly. This is in line with the recent work by @alalazo and @davydden with respect to `spec['blas'].libs` and friends.
## Prefix
For most packages in Spack, we assume that the installation directory is `spec['python'].prefix`. This generally works for anything installed with Spack, but gets complicated when we include external packages. Python is a commonly used external package (it needs to be installed just to run Spack). If it was installed with Homebrew, `which python` would return `/usr/local/bin/python`, and most users would erroneously assume that `/usr/local` is the installation directory. If you peruse through #2173, you'll immediately see why this is not the case. Homebrew actually installs Python in `/usr/local/Cellar/python/2.7.12_2` and symlinks the executable to `/usr/local/bin/python`. `PYTHONHOME` (and presumably most things that need to know where Python is installed) needs to be set to the actual installation directory, not `/usr/local`.
Normally I would say, "sounds like user error, make sure to use the real installation directory in your `packages.yaml`". But I think we can make a special case for Python. That's what we decided in #2173 anyway. If we change our minds, I would be more than happy to simplify things.
To solve this problem, I created a `spec['python'].home` attribute that works the same way as `spec['python'].prefix` but queries Python to figure out where it was actually installed. @tgamblin Is there any way to overwrite `spec['python'].prefix`? I think it's currently immutable.
## Command
In general, Python 2 comes with both `python` and `python2` commands, while Python 3 only comes with a `python3` command. But this is up to the OS developers. For example, `/usr/bin/python` on Gentoo is actually Python 3. Worse yet, if someone is using an externally installed Python, all 3 commands may exist in the same directory! Here's what I'm thinking:
If the spec is for Python 3, try searching for the `python3` command.
If the spec is for Python 2, try searching for the `python2` command.
If neither are found, try searching for the `python` command.
## Libraries
Spack installs Python libraries in `spec['python'].prefix.lib`. Except on openSUSE 13, where it installs to `spec['python'].prefix.lib64` (see #2295 and #2253). On my CentOS 6 machine, the Python libraries are installed in `/usr/lib64`. Both need to work.
The libraries themselves change name depending on OS and Python version. For Python 2.7 on macOS, I'm seeing:
```
lib/libpython2.7.dylib
```
For Python 3.6 on CentOS 6, I'm seeing:
```
lib/libpython3.so
lib/libpython3.6m.so.1.0
lib/libpython3.6m.so -> lib/libpython3.6m.so.1.0
```
Notice the `m` after the version number. Yeah, that's a thing.
## Headers
In Python 2.7, I'm seeing:
```
include/python2.7/pyconfig.h
```
In Python 3.6, I'm seeing:
```
include/python3.6m/pyconfig.h
```
It looks like all Python 3 installations have this `m`. Tested with Python 3.2 and 3.6 on macOS and CentOS 6
Spack has really nice support for libraries (`find_libraries` and `LibraryList`), but nothing for headers. Fixed.
2017-04-30 08:24:13 +08:00
|
|
|
include_flags = spec['openblas'].headers.cpp_flags
|
2017-03-04 09:30:35 +08:00
|
|
|
link_flags = spec['openblas'].libs.ld_flags
|
2016-10-26 02:12:22 +08:00
|
|
|
if self.compiler.name == 'intel':
|
2017-03-03 02:01:29 +08:00
|
|
|
link_flags += ' -lifcore'
|
2017-09-24 04:27:42 +08:00
|
|
|
if self.spec.satisfies('threads=pthreads'):
|
|
|
|
link_flags += ' -lpthread'
|
|
|
|
if spec.satisfies('threads=openmp'):
|
|
|
|
link_flags += ' -lpthread ' + self.compiler.openmp_flag
|
2016-05-11 21:02:14 +08:00
|
|
|
|
2017-03-03 02:01:29 +08:00
|
|
|
output = compile_c_and_execute(
|
|
|
|
source_file, [include_flags], link_flags.split()
|
|
|
|
)
|
2016-05-11 21:45:57 +08:00
|
|
|
compare_output_file(output, blessed_file)
|