Refactor IntelInstaller into IntelPackage base class (#4300)

* Refactor IntelInstaller into IntelPackage base class

* Move license attributes from __init__ to class-level

* Flake8 fixes: remove unused imports

* Fix logic that writes the silent.cfg file

* More specific version numbers for Intel MPI

* Rework logic that selects components to install

* Final changes necessary to get intel package working

* Various updates to intel-parallel-studio

* Add latest version of every Intel package

* Add environment variables for Intel packages

* Update env vars for intel package

* Finalize components for intel-parallel-studio package

Adds a +tbb variant to intel-parallel-studio.
The tbb package was renamed to intel-tbb.
Now both intel-tbb and intel-parallel-studio+tbb
provide tbb.

* Overhaul environment variables set by intel-parallel-studio

* Point dependent packages to the correct MPI wrappers

* Never default to intel-parallel-studio

* Gather env vars by sourcing setup scripts

* Use mpiicc instead of mpicc when using Intel compiler

* Undo change to ARCH

* Add changes from intel-mpi to intel-parallel-studio

* Add comment explaining mpicc vs mpiicc

* Prepend env vars containing 'PATH' or separators

* Flake8 fix

* Fix bugs in from_sourcing_file

* Indentation fix

* Prepend, not set if contains separator

* Fix license symlinking broken by changes to intel-parallel-studio

* Use comments instead of docstrings to document attributes

* Flake8 fixes

* Use a set instead of a list to prevent duplicate components

* Fix MKL and MPI library linking directories

* Remove +all variant from intel-parallel-studio

* It is not possible to build with MKL, GCC, and OpenMP at this time

* Found a workaround for locating GCC libraries

* Typos and variable names

* Fix initialization of empty LibraryList
This commit is contained in:
Adam J. Stewart
2017-08-16 12:21:07 -05:00
committed by GitHub
parent ad8c60239f
commit db657d938d
17 changed files with 937 additions and 597 deletions

View File

@@ -22,13 +22,13 @@
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *
import os
from spack.pkg.builtin.intel import IntelInstaller
from spack import *
from spack.environment import EnvironmentModifications
class IntelMkl(IntelInstaller):
class IntelMkl(IntelPackage):
"""Intel Math Kernel Library."""
homepage = "https://software.intel.com/en-us/intel-mkl"
@@ -50,12 +50,21 @@ class IntelMkl(IntelInstaller):
variant('ilp64', default=False, description='64 bit integers')
variant('openmp', default=False, description='OpenMP multithreading layer')
# virtual dependency
provides('blas')
provides('lapack')
provides('scalapack')
provides('mkl')
@property
def license_required(self):
# The Intel libraries are provided without requiring a license as of
# version 2017.2. Trying to specify the license will fail. See:
# https://software.intel.com/en-us/articles/free-ipsxe-tools-and-libraries
if self.version >= Version('2017.2'):
return False
else:
return True
@property
def blas_libs(self):
spec = self.spec
@@ -69,15 +78,27 @@ def blas_libs(self):
mkl_threading = ['libmkl_sequential']
omp_libs = LibraryList([])
if '+openmp' in spec:
if '%intel' in spec:
mkl_threading = ['libmkl_intel_thread', 'libiomp5']
else:
mkl_threading = ['libmkl_intel_thread']
omp_threading = ['libiomp5']
omp_root = prefix.compilers_and_libraries.linux.lib.intel64
omp_libs = find_libraries(
omp_threading, root=omp_root, shared=shared)
elif '%gcc' in spec:
mkl_threading = ['libmkl_gnu_thread']
gcc = Executable(self.compiler.cc)
libgomp = gcc('--print-file-name', 'libgomp.{0}'.format(
dso_suffix), output=str)
omp_libs = LibraryList(libgomp)
# TODO: TBB threading: ['libmkl_tbb_thread', 'libtbb', 'libstdc++']
mkl_root = join_path(prefix.lib, 'intel64')
mkl_root = prefix.compilers_and_libraries.linux.mkl.lib.intel64
mkl_libs = find_libraries(
mkl_integer + ['libmkl_core'] + mkl_threading,
@@ -91,7 +112,7 @@ def blas_libs(self):
shared=shared
)
return mkl_libs + system_libs
return mkl_libs + omp_libs + system_libs
@property
def lapack_libs(self):
@@ -120,30 +141,46 @@ def scalapack_libs(self):
elif '^intel-mpi' in root:
libnames.append('libmkl_blacs_intelmpi')
else:
raise InstallError("No MPI found for scalapack")
raise InstallError('No MPI found for scalapack')
shared = True if '+shared' in self.spec else False
integer = 'ilp64' if '+ilp64' in self.spec else 'lp64'
mkl_root = self.prefix.compilers_and_libraries.linux.mkl.lib.intel64
shared = True if '+shared' in self.spec else False
libs = find_libraries(
['{0}_{1}'.format(l, integer) for l in libnames],
root=join_path(self.prefix.lib, 'intel64'),
root=mkl_root,
shared=shared
)
return libs
def install(self, spec, prefix):
self.intel_prefix = os.path.join(prefix, "pkg")
IntelInstaller.install(self, spec, prefix)
mkl_dir = os.path.join(self.intel_prefix, "mkl")
for f in os.listdir(mkl_dir):
os.symlink(os.path.join(mkl_dir, f), os.path.join(self.prefix, f))
def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
# set up MKLROOT for everyone using MKL package
mkl_root = self.prefix.compilers_and_libraries.linux.mkl.lib.intel64
spack_env.set('MKLROOT', self.prefix)
spack_env.append_path('SPACK_COMPILER_EXTRA_RPATHS',
join_path(self.prefix.lib, 'intel64'))
spack_env.append_path('SPACK_COMPILER_EXTRA_RPATHS', mkl_root)
def setup_environment(self, spack_env, run_env):
run_env.set('MKLROOT', self.prefix)
"""Adds environment variables to the generated module file.
These environment variables come from running:
.. code-block:: console
$ source mkl/bin/mklvars.sh intel64
"""
# NOTE: Spack runs setup_environment twice, once pre-build to set up
# the build environment, and once post-installation to determine
# the environment variables needed at run-time to add to the module
# file. The script we need to source is only present post-installation,
# so check for its existence before sourcing.
# TODO: At some point we should split setup_environment into
# setup_build_environment and setup_run_environment to get around
# this problem.
mklvars = os.path.join(self.prefix.mkl.bin, 'mklvars.sh')
if os.path.isfile(mklvars):
run_env.extend(EnvironmentModifications.from_sourcing_file(
mklvars, 'intel64'))