Пример #1
0
class CudaPackage(PackageBase):
    """Auxiliary class which contains CUDA variant, dependencies and conflicts
    and is meant to unify and facilitate its usage.

    Maintainers: ax3l, Rombur, davidbeckingsale
    """

    # https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#gpu-feature-list
    # https://developer.nvidia.com/cuda-gpus
    # https://en.wikipedia.org/wiki/CUDA#GPUs_supported
    cuda_arch_values = ('10', '11', '12', '13', '20', '21', '30', '32', '35',
                        '37', '50', '52', '53', '60', '61', '62', '70', '72',
                        '75', '80', '86')

    # FIXME: keep cuda and cuda_arch separate to make usage easier until
    # Spack has depends_on(cuda, when='cuda_arch!=None') or alike
    variant('cuda', default=False, description='Build with CUDA')

    variant('cuda_arch',
            description='CUDA architecture',
            values=spack.variant.any_combination_of(*cuda_arch_values),
            when='+cuda')

    # https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#nvcc-examples
    # https://llvm.org/docs/CompileCudaWithLLVM.html#compiling-cuda-code
    @staticmethod
    def cuda_flags(arch_list):
        return [('--generate-code arch=compute_{0},code=sm_{0} '
                 '--generate-code arch=compute_{0},code=compute_{0}').format(s)
                for s in arch_list]

    depends_on('cuda', when='+cuda')

    # CUDA version vs Architecture
    # https://en.wikipedia.org/wiki/CUDA#GPUs_supported
    # https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#deprecated-features
    depends_on('cuda@:6.0', when='cuda_arch=10')
    depends_on('cuda@:6.5', when='cuda_arch=11')
    depends_on('[email protected]:6.5', when='cuda_arch=12')
    depends_on('[email protected]:6.5', when='cuda_arch=13')

    depends_on('[email protected]:8.0', when='cuda_arch=20')
    depends_on('[email protected]:8.0', when='cuda_arch=21')

    depends_on('[email protected]:10.2', when='cuda_arch=30')
    depends_on('[email protected]:10.2', when='cuda_arch=32')
    depends_on('[email protected]:', when='cuda_arch=35')
    depends_on('[email protected]:', when='cuda_arch=37')

    depends_on('[email protected]:', when='cuda_arch=50')
    depends_on('[email protected]:', when='cuda_arch=52')
    depends_on('[email protected]:', when='cuda_arch=53')

    depends_on('[email protected]:', when='cuda_arch=60')
    depends_on('[email protected]:', when='cuda_arch=61')
    depends_on('[email protected]:', when='cuda_arch=62')

    depends_on('[email protected]:', when='cuda_arch=70')
    depends_on('[email protected]:', when='cuda_arch=72')
    depends_on('[email protected]:', when='cuda_arch=75')

    depends_on('[email protected]:', when='cuda_arch=80')
    depends_on('[email protected]:', when='cuda_arch=86')

    # From the NVIDIA install guide we know of conflicts for particular
    # platforms (linux, darwin), architectures (x86, powerpc) and compilers
    # (gcc, clang). We don't restrict %gcc and %clang conflicts to
    # platform=linux, since they should also apply to platform=cray, and may
    # apply to platform=darwin. We currently do not provide conflicts for
    # platform=darwin with %apple-clang.

    # Linux x86_64 compiler conflicts from here:
    # https://gist.github.com/ax3l/9489132
    with when('^cuda~allow-unsupported-compilers'):
        # GCC
        # According to
        # https://github.com/spack/spack/pull/25054#issuecomment-886531664
        # these conflicts are valid independently from the architecture

        # minimum supported versions
        conflicts('%gcc@:4', when='+cuda ^[email protected]:')
        conflicts('%gcc@:5', when='+cuda ^[email protected]:')

        # maximum supported version
        # NOTE:
        # in order to not constrain future cuda version to old gcc versions,
        # it has been decided to use an upper bound for the latest version.
        # This implies that the last one in the list has to be updated at
        # each release of a new cuda minor version.
        conflicts('%gcc@10:', when='+cuda ^cuda@:11.0')
        conflicts('%gcc@11:', when='+cuda ^cuda@:11.4.0')
        conflicts('%gcc@12:', when='+cuda ^cuda@:11.6')
        conflicts('%clang@12:', when='+cuda ^cuda@:11.4.0')
        conflicts('%clang@13:', when='+cuda ^cuda@:11.5')
        conflicts('%clang@14:', when='+cuda ^cuda@:11.6')

        # https://gist.github.com/ax3l/9489132#gistcomment-3860114
        conflicts('%gcc@10', when='+cuda ^cuda@:11.4.0')
        conflicts('%gcc@5:', when='+cuda ^cuda@:7.5 target=x86_64:')
        conflicts('%gcc@6:', when='+cuda ^cuda@:8 target=x86_64:')
        conflicts('%gcc@7:', when='+cuda ^cuda@:9.1 target=x86_64:')
        conflicts('%gcc@8:', when='+cuda ^cuda@:10.0.130 target=x86_64:')
        conflicts('%gcc@9:', when='+cuda ^cuda@:10.2.89 target=x86_64:')
        conflicts('%pgi@:14.8', when='+cuda ^cuda@:7.0.27 target=x86_64:')
        conflicts('%pgi@:15.3,15.5:', when='+cuda ^[email protected] target=x86_64:')
        conflicts('%pgi@:16.2,16.0:16.3', when='+cuda ^cuda@8 target=x86_64:')
        conflicts('%pgi@:15,18:', when='+cuda ^[email protected]:9.1 target=x86_64:')
        conflicts('%pgi@:16,19:', when='+cuda ^[email protected]:10 target=x86_64:')
        conflicts('%pgi@:17,20:',
                  when='+cuda ^[email protected]:10.2.89 target=x86_64:')
        conflicts('%pgi@:17,21:',
                  when='+cuda ^[email protected]:11.1.0 target=x86_64:')
        conflicts('%clang@:3.4', when='+cuda ^cuda@:7.5 target=x86_64:')
        conflicts('%clang@:3.7,4:', when='+cuda ^[email protected]:9.0 target=x86_64:')
        conflicts('%clang@:3.7,4.1:', when='+cuda ^[email protected] target=x86_64:')
        conflicts('%clang@:3.7,5.1:', when='+cuda ^[email protected] target=x86_64:')
        conflicts('%clang@:3.7,6.1:',
                  when='+cuda ^[email protected] target=x86_64:')
        conflicts('%clang@:3.7,7.1:',
                  when='+cuda ^[email protected] target=x86_64:')
        conflicts('%clang@:3.7,8.1:',
                  when='+cuda ^[email protected]:10.1.243 target=x86_64:')
        conflicts('%clang@:3.2,9:', when='+cuda ^[email protected] target=x86_64:')
        conflicts('%clang@:5', when='+cuda ^[email protected]: target=x86_64:')
        conflicts('%clang@10:', when='+cuda ^cuda@:11.0.3 target=x86_64:')
        conflicts('%clang@11:', when='+cuda ^cuda@:11.1.0 target=x86_64:')

        # x86_64 vs. ppc64le differ according to NVidia docs
        # Linux ppc64le compiler conflicts from Table from the docs below:
        # https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
        # https://docs.nvidia.com/cuda/archive/9.2/cuda-installation-guide-linux/index.html
        # https://docs.nvidia.com/cuda/archive/9.1/cuda-installation-guide-linux/index.html
        # https://docs.nvidia.com/cuda/archive/9.0/cuda-installation-guide-linux/index.html
        # https://docs.nvidia.com/cuda/archive/8.0/cuda-installation-guide-linux/index.html

        # information prior to CUDA 9 difficult to find
        conflicts('%gcc@6:', when='+cuda ^cuda@:9 target=ppc64le:')
        conflicts('%gcc@8:', when='+cuda ^cuda@:10.0.130 target=ppc64le:')
        conflicts('%gcc@9:', when='+cuda ^cuda@:10.1.243 target=ppc64le:')
        # officially, CUDA 11.0.2 only supports the system GCC 8.3 on ppc64le
        conflicts('%pgi', when='+cuda ^cuda@:8 target=ppc64le:')
        conflicts('%pgi@:16', when='+cuda ^cuda@:9.1.185 target=ppc64le:')
        conflicts('%pgi@:17', when='+cuda ^cuda@:10 target=ppc64le:')
        conflicts('%clang@4:', when='+cuda ^cuda@:9.0.176 target=ppc64le:')
        conflicts('%clang@5:', when='+cuda ^cuda@:9.1 target=ppc64le:')
        conflicts('%clang@6:', when='+cuda ^cuda@:9.2 target=ppc64le:')
        conflicts('%clang@7:', when='+cuda ^[email protected] target=ppc64le:')
        conflicts('%[email protected]:', when='+cuda ^cuda@:10.1.105 target=ppc64le:')
        conflicts('%[email protected]:', when='+cuda ^cuda@:10.2.89 target=ppc64le:')
        conflicts('%clang@:5', when='+cuda ^[email protected]: target=ppc64le:')
        conflicts('%clang@10:', when='+cuda ^cuda@:11.0.2 target=ppc64le:')
        conflicts('%clang@11:', when='+cuda ^cuda@:11.1.0 target=ppc64le:')

        # Intel is mostly relevant for x86_64 Linux, even though it also
        # exists for Mac OS X. No information prior to CUDA 3.2 or Intel 11.1
        conflicts('%intel@:11.0', when='+cuda ^cuda@:3.1')
        conflicts('%intel@:12.0', when='+cuda ^[email protected]:')
        conflicts('%intel@:13.0', when='+cuda ^[email protected]:')
        conflicts('%intel@:13.2', when='+cuda ^[email protected]:')
        conflicts('%intel@:14.9', when='+cuda ^cuda@7:')
        # Intel 15.x is compatible with CUDA 7 thru current CUDA
        conflicts('%[email protected]:', when='+cuda ^cuda@:8.0.43')
        conflicts('%[email protected]:', when='+cuda ^cuda@:8.0.60')
        conflicts('%[email protected]:', when='+cuda ^cuda@:9.9')
        conflicts('%[email protected]:', when='+cuda ^cuda@:10.0')
        conflicts('%[email protected]:', when='+cuda ^cuda@:10.1')
        conflicts('%[email protected]:', when='+cuda ^cuda@:11.1.0')

        # XL is mostly relevant for ppc64le Linux
        conflicts('%xl@:12,14:', when='+cuda ^cuda@:9.1')
        conflicts('%xl@:12,14:15,17:', when='+cuda ^[email protected]')
        conflicts('%xl@:12,17:', when='+cuda ^cuda@:11.1.0')

        # Darwin.
        # TODO: add missing conflicts for %apple-clang cuda@:10
        conflicts('platform=darwin', when='+cuda ^[email protected]: ')
Пример #2
0
class LuaPackage(PackageBase):
    """Specialized class for lua packages"""

    phases = ['unpack', 'generate_luarocks_config', 'preprocess', 'install']
    #: This attribute is used in UI queries that need to know the build
    #: system base class
    build_system_class = 'LuaPackage'

    list_depth = 1  # LuaRocks requires at least one level of spidering to find versions
    depends_on('lua-lang')
    extends('lua', when='^lua')
    with when('^lua-luajit'):
        extends('lua-luajit')
        depends_on('luajit')
        depends_on('lua-luajit+lualinks')
    with when('^lua-luajit-openresty'):
        extends('lua-luajit-openresty')
        depends_on('luajit')
        depends_on('lua-luajit-openresty+lualinks')

    def unpack(self, spec, prefix):
        if os.path.splitext(self.stage.archive_file)[1] == '.rock':
            directory = self.luarocks('unpack',
                                      self.stage.archive_file,
                                      output=str)
            dirlines = directory.split('\n')
            # TODO: figure out how to scope this better
            os.chdir(dirlines[2])

    def _generate_tree_line(self, name, prefix):
        return """{{ name = "{name}", root = "{prefix}" }};""".format(
            name=name,
            prefix=prefix,
        )

    def _luarocks_config_path(self):
        return os.path.join(self.stage.source_path, 'spack_luarocks.lua')

    def generate_luarocks_config(self, spec, prefix):
        spec = self.spec
        table_entries = []
        for d in spec.traverse(deptypes=("build", "run"), deptype_query="run"):
            if d.package.extends(self.extendee_spec):
                table_entries.append(self._generate_tree_line(
                    d.name, d.prefix))

        path = self._luarocks_config_path()
        with open(path, 'w') as config:
            config.write("""
                deps_mode="all"
                rocks_trees={{
                {}
                }}
                """.format("\n".join(table_entries)))
        return path

    def setup_build_environment(self, env):
        env.set('LUAROCKS_CONFIG', self._luarocks_config_path())

    def preprocess(self, spec, prefix):
        """Override this to preprocess source before building with luarocks"""
        pass

    @property
    def lua(self):
        return Executable(self.spec['lua-lang'].prefix.bin.lua)

    @property
    def luarocks(self):
        lr = Executable(self.spec['lua-lang'].prefix.bin.luarocks)
        return lr

    def luarocks_args(self):
        return []

    def install(self, spec, prefix):
        rock = '.'
        specs = find('.', '*.rockspec', recursive=False)
        if specs:
            rock = specs[0]
        rocks_args = self.luarocks_args()
        rocks_args.append(rock)
        self.luarocks('--tree=' + prefix, 'make', *rocks_args)