summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLevi Baber <baberlevi@gmail.com>2019-02-20 20:52:15 -0600
committerPeter Scheibel <scheibel1@llnl.gov>2019-02-20 20:52:15 -0600
commit040b65876bea73c761aaaf32cf7886fb790f496c (patch)
tree02ae6ab7f16eeb5bfba02e9ec6e175d760bbcf72
parentaf8d84197d669c574b63ca8e22f53d02c0e9a777 (diff)
downloadspack-040b65876bea73c761aaaf32cf7886fb790f496c.tar.gz
spack-040b65876bea73c761aaaf32cf7886fb790f496c.tar.bz2
spack-040b65876bea73c761aaaf32cf7886fb790f496c.tar.xz
spack-040b65876bea73c761aaaf32cf7886fb790f496c.zip
gcc: add nvptx offload capability (#9406)
Add optional support for Nvidia PTX
-rw-r--r--var/spack/repos/builtin/packages/gcc/package.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/var/spack/repos/builtin/packages/gcc/package.py b/var/spack/repos/builtin/packages/gcc/package.py
index ddeb95d3ba..57d3ece2c8 100644
--- a/var/spack/repos/builtin/packages/gcc/package.py
+++ b/var/spack/repos/builtin/packages/gcc/package.py
@@ -18,9 +18,11 @@ class Gcc(AutotoolsPackage):
homepage = 'https://gcc.gnu.org'
url = 'https://ftpmirror.gnu.org/gcc/gcc-7.1.0/gcc-7.1.0.tar.bz2'
+ svn = 'svn://gcc.gnu.org/svn/gcc/'
list_url = 'http://ftp.gnu.org/gnu/gcc/'
list_depth = 1
+ version('develop', svn=svn + 'trunk')
version('8.2.0', '64898a165f67e136d802a92e7633bf1b06c85266027e52127ea025bf5fc2291b5e858288aac0bdba246e6cdf7c6ec88bc8e0e7f3f6f1985f4297710cafde56ed')
version('8.1.0', '65f7c65818dc540b3437605026d329fc')
@@ -74,6 +76,9 @@ class Gcc(AutotoolsPackage):
variant('strip',
default=False,
description='Strip executables to reduce installation size')
+ variant('nvptx',
+ default=False,
+ description='Target nvptx offloading to NVIDIA GPUs')
# https://gcc.gnu.org/install/prerequisites.html
depends_on('gmp@4.3.2:')
@@ -92,6 +97,25 @@ class Gcc(AutotoolsPackage):
depends_on('gnat', when='languages=ada')
depends_on('binutils~libiberty', when='+binutils')
depends_on('zip', type='build', when='languages=java')
+ depends_on('cuda', when='+nvptx')
+
+ resource(
+ name='newlib',
+ url='ftp://sourceware.org/pub/newlib/newlib-3.0.0.20180831.tar.gz',
+ sha256='3ad3664f227357df15ff34e954bfd9f501009a647667cd307bf0658aefd6eb5b',
+ destination='newlibsource',
+ when='+nvptx'
+ )
+
+ # nvptx-tools does not seem to work as a dependency,
+ # but does fine when the source is inside the gcc build directory
+ # nvptx-tools doesn't have any releases, so grabbing the last commit
+ resource(
+ name='nvptx-tools',
+ git='https://github.com/MentorEmbedded/nvptx-tools',
+ commit='5f6f343a302d620b0868edab376c00b15741e39e',
+ when='+nvptx'
+ )
# TODO: integrate these libraries.
# depends_on('ppl')
@@ -148,6 +172,16 @@ class Gcc(AutotoolsPackage):
# See https://gcc.gnu.org/gcc-5/changes.html
conflicts('languages=jit', when='@:4')
+ # NVPTX offloading supported in 7 and later by limited languages
+ conflicts('+nvptx', when='@:6', msg='NVPTX only supported in gcc 7 and above')
+ conflicts('languages=ada', when='+nvptx')
+ conflicts('languages=brig', when='+nvptx')
+ conflicts('languages=go', when='+nvptx')
+ conflicts('languages=java', when='+nvptx')
+ conflicts('languages=jit', when='+nvptx')
+ conflicts('languages=objc', when='+nvptx')
+ conflicts('languages=obj-c++', when='+nvptx')
+
if sys.platform == 'darwin':
# Fix parallel build on APFS filesystem
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81797
@@ -267,8 +301,75 @@ class Gcc(AutotoolsPackage):
if sys.platform == 'darwin':
options.append('--with-build-config=bootstrap-debug')
+ # nvptx-none offloading for host compiler
+ if spec.satisfies('+nvptx'):
+ options.extend(['--enable-offload-targets=nvptx-none',
+ '--with-cuda-driver-include={0}'.format(
+ spec['cuda'].prefix.include),
+ '--with-cuda-driver-lib={0}'.format(
+ spec['cuda'].libs.directories[0]),
+ '--disable-bootstrap',
+ '--disable-multilib'])
+
return options
+ # run configure/make/make(install) for the nvptx-none target
+ # before running the host compiler phases
+ @when('+nvptx')
+ @run_before('configure')
+ def nvptx_install(self):
+ spec = self.spec
+ prefix = self.prefix
+
+ # config.guess returns the host triple, e.g. "x86_64-pc-linux-gnu"
+ guess = Executable('./config.guess')
+ targetguess = guess(output=str).rstrip('\n')
+
+ options = getattr(self, 'configure_flag_args', [])
+ options += ['--prefix={0}'.format(prefix)]
+
+ options += [
+ '--with-cuda-driver-include={0}'.format(
+ spec['cuda'].prefix.include),
+ '--with-cuda-driver-lib={0}'.format(
+ spec['cuda'].libs.directories[0]),
+ ]
+
+ with working_dir('nvptx-tools'):
+ configure = Executable("./configure")
+ configure(*options)
+ make()
+ make('install')
+
+ pattern = join_path(self.stage.source_path, 'newlibsource', '*')
+ files = glob.glob(pattern)
+
+ if files:
+ symlink(join_path(files[0], 'newlib'), 'newlib')
+
+ # self.build_directory = 'spack-build-nvptx'
+ with working_dir('spack-build-nvptx', create=True):
+
+ options = ['--prefix={0}'.format(prefix),
+ '--enable-languages={0}'.format(
+ ','.join(spec.variants['languages'].value)),
+ '--with-mpfr={0}'.format(spec['mpfr'].prefix),
+ '--with-gmp={0}'.format(spec['gmp'].prefix),
+ '--target=nvptx-none',
+ '--with-build-time-tools={0}'.format(
+ join_path(prefix,
+ 'nvptx-none', 'bin')),
+ '--enable-as-accelerator-for={0}'.format(
+ targetguess),
+ '--disable-sjlj-exceptions',
+ '--enable-newlib-io-long-long',
+ ]
+
+ configure = Executable("../configure")
+ configure(*options)
+ make()
+ make('install')
+
@property
def build_targets(self):
if sys.platform == 'darwin':