diff --git a/easybuild/toolchains/compiler/nvhpc.py b/easybuild/toolchains/compiler/nvhpc.py new file mode 100644 index 0000000000..222e9bc277 --- /dev/null +++ b/easybuild/toolchains/compiler/nvhpc.py @@ -0,0 +1,53 @@ +## +# Copyright 2026 Ghent University +# +# This file is part of EasyBuild, +# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en), +# with support of Ghent University (http://ugent.be/hpc), +# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be), +# Flemish Research Foundation (FWO) (http://www.fwo.be/en) +# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en). +# +# https://github.com/easybuilders/easybuild +# +# EasyBuild is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation v2. +# +# EasyBuild is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with EasyBuild. If not, see . +## +"""Compatibility module such that compiler.nvhpc.NVHPC and compiler.compiler.nvidia_compilers.NvidiaCompilers +can be used interchangeably +""" + +import abc +from easybuild.base import fancylogger +from easybuild.toolchains.compiler.nvidia_compilers import NvidiaCompilers + +_log = fancylogger.getLogger('compiler.nvhpc', fname=False) +_log.deprecated("easybuild.toolchains.compiler.nvhpc was replaced by " + "easybuild.toolchains.compiler.nvidia_compilers in EasyBuild 5.2.0", '6.0') + + +# Former name used in EasyBuild until 5.2.0, now a DEPRECATED alias +class NVHPC(metaclass=abc.ABCMeta): # pylint: disable=too-few-public-methods + """DEPRECATED alias for NvidiaCompilers.""" + def __new__(cls, *args, **kwargs): + if cls is NVHPC: + inst = NvidiaCompilers(*args, **kwargs) + inst.log.deprecated( + "easybuild.toolchains.compiler.nvhpc was replaced by " + "easybuild.toolchains.compiler.nvidia_compilers in EasyBuild 5.2.0", '6.0') + return inst + return super().__new__(cls) + + +NVHPC.register(NvidiaCompilers) + +# TODO EasyBuild 6.0: Remove NVHPC name from NvidiaCompilers.COMPILER_MODULE_NAME diff --git a/easybuild/toolchains/compiler/nvidia_compilers.py b/easybuild/toolchains/compiler/nvidia_compilers.py index 1a4e617a7e..62ed37f7c8 100644 --- a/easybuild/toolchains/compiler/nvidia_compilers.py +++ b/easybuild/toolchains/compiler/nvidia_compilers.py @@ -45,7 +45,8 @@ class NvidiaCompilers(Compiler): "NVHPC compiler class" - COMPILER_MODULE_NAME = ['nvidia-compilers'] + # TODO EasyBuild 6.0: Remove NVHPC name + COMPILER_MODULE_NAME = ['nvidia-compilers', 'NVHPC'] COMPILER_FAMILY = TC_CONSTANT_NVHPC @@ -100,7 +101,3 @@ def _set_compiler_flags(self): if not self.options.get('optarch', False): self.variables.nextend('OPTFLAGS', ['tp=x64']) super()._set_compiler_flags() - - def _set_compiler_vars(self): - """Set the compiler variables""" - super()._set_compiler_vars() diff --git a/easybuild/toolchains/nvhpc.py b/easybuild/toolchains/nvhpc.py index 21307a30e9..5156183685 100644 --- a/easybuild/toolchains/nvhpc.py +++ b/easybuild/toolchains/nvhpc.py @@ -31,6 +31,7 @@ * Andreas Herten (Forschungszentrum Juelich) * Alex Domingo (Vrije Universiteit Brussel) """ +import abc from easybuild.toolchains.gcccore import GCCcore from easybuild.toolchains.linalg.nvblas import NVBLAS from easybuild.toolchains.linalg.nvscalapack import NVScaLAPACK @@ -45,3 +46,16 @@ class NVHPC(NvidiaCompilersToolchain, NVHPCX, NVBLAS, NVScaLAPACK): # GCCcore and system need to be listed as subtoolchains here only for legacy reasons; # recent NVHPC toolchains (versions >= 25.0) only have nvidia-compilers are subtoolchain SUBTOOLCHAIN = [NvidiaCompilersToolchain.NAME, GCCcore.NAME, SYSTEM_TOOLCHAIN_NAME] + + +class NVHPCToolchain(metaclass=abc.ABCMeta): # pylint: disable=too-few-public-methods + """DEPRECATED alias for NvidiaCompilersToolchain.""" + def __new__(cls, *args, **kwargs): + if cls is NVHPCToolchain: + inst = NvidiaCompilersToolchain(*args, **kwargs) + inst.log.deprecated("NVHPCToolchain was replaced by NvidiaCompilersToolchain in EasyBuild 5.2.0", '6.0') + return inst + return super().__new__(cls) + + +NVHPCToolchain.register(NvidiaCompilersToolchain) diff --git a/test/framework/toolchain.py b/test/framework/toolchain.py index e306e9df30..fe500b3bc5 100644 --- a/test/framework/toolchain.py +++ b/test/framework/toolchain.py @@ -528,7 +528,7 @@ def test_validate_pass_by_value(self): pass_by_value = True ids = [] - for k, v in tc.variables.items(): + for _, v in tc.variables.items(): for x in v: idx = id(x) if idx not in ids: @@ -908,8 +908,6 @@ def test_misc_flags_unique_fortran(self): flag = tc.COMPILER_UNIQUE_OPTION_MAP[opt] if isinstance(flag, list): flag = ' '.join(flag) - else: - flag = flag for var in flag_vars: flags = tc.get_variable(var) if enable: @@ -3389,6 +3387,42 @@ def test_get_flag(self): tc.options.options_map['openmp'] = flags self.assertEqual(tc.get_flag('openmp'), flagstring) + def test_nvhpc_compatibility(self): + """Test that software using EasyBuild before 5.2.0 continues working + the compiler.nvhpc toolchain being renamed to NvidiaCompilers""" + from easybuild.toolchains.nvompi import Nvompi + from easybuild.toolchains.compiler.nvidia_compilers import NvidiaCompilers + from easybuild.toolchains.nvhpc import NvidiaCompilersToolchain, NVHPCToolchain + + # test deprecation of NVHPC in v5.2.0 + with self.temporarily_allow_deprecated_behaviour(), self.mocked_stdout_stderr(): + from easybuild.toolchains.compiler.nvhpc import NVHPC + self.assertIn("nvhpc was replaced by easybuild.toolchains.compiler.nvidia_compilers", self.get_stderr()) + + # load NVidiaCompilers, deprecated NVHPC corresponds to it + tc = NvidiaCompilers(name='NvidiaCompilers', version='2024a') # Common usage + # Might be checked by pre-5.2.0 users + self.assertIsInstance(tc, NVHPC) + + # load deprecated NVHPC, NvidiaCompilers corresponds to it + with self.temporarily_allow_deprecated_behaviour(), self.mocked_stdout_stderr(): + tc = NVHPC(name='NVHPC', version='2024a') # Might be used by pre-5.2.0 users + self.assertIn("nvhpc was replaced by easybuild.toolchains.compiler.nvidia_compilers", self.get_stderr()) + self.assertIsInstance(tc, NvidiaCompilers) + + # load deprecated NVHPCToolchain, it corresponds to NvidiaCompilersToolchain + with self.temporarily_allow_deprecated_behaviour(), self.mocked_stdout_stderr(): + tc = NVHPCToolchain(name='NVHPC', version='2024a') # Might be used by pre-5.2.0 users + self.assertIn("NVHPCToolchain was replaced by NvidiaCompilersToolchain", self.get_stderr()) + self.assertIsInstance(tc, NvidiaCompilersToolchain) + + tc = Nvompi(version='2024a') # Common usage + self.assertIsInstance(tc, NvidiaCompilers) + self.assertIsInstance(tc, NvidiaCompilersToolchain) + self.assertIsInstance(tc, NVHPCToolchain) + # compiler toolchain NVHPC is deprecated in 5.2.0, but might still be checked by existing code + self.assertIsInstance(tc, NVHPC) + def suite(loader=None): """ return all the tests"""