Skip to content

Commit eebe507

Browse files
authored
Merge pull request #5089 from Flamefire/nvhpc_compat
Add back `easybuild.toolchains.compiler.nvhpc`
2 parents fffc9a7 + 5aceccb commit eebe507

File tree

4 files changed

+106
-8
lines changed

4 files changed

+106
-8
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
##
2+
# Copyright 2026 Ghent University
3+
#
4+
# This file is part of EasyBuild,
5+
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
6+
# with support of Ghent University (http://ugent.be/hpc),
7+
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
8+
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
9+
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
10+
#
11+
# https://github.com/easybuilders/easybuild
12+
#
13+
# EasyBuild is free software: you can redistribute it and/or modify
14+
# it under the terms of the GNU General Public License as published by
15+
# the Free Software Foundation v2.
16+
#
17+
# EasyBuild is distributed in the hope that it will be useful,
18+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
# GNU General Public License for more details.
21+
#
22+
# You should have received a copy of the GNU General Public License
23+
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
24+
##
25+
"""Compatibility module such that compiler.nvhpc.NVHPC and compiler.compiler.nvidia_compilers.NvidiaCompilers
26+
can be used interchangeably
27+
"""
28+
29+
import abc
30+
from easybuild.base import fancylogger
31+
from easybuild.toolchains.compiler.nvidia_compilers import NvidiaCompilers
32+
33+
_log = fancylogger.getLogger('compiler.nvhpc', fname=False)
34+
_log.deprecated("easybuild.toolchains.compiler.nvhpc was replaced by "
35+
"easybuild.toolchains.compiler.nvidia_compilers in EasyBuild 5.2.0", '6.0')
36+
37+
38+
# Former name used in EasyBuild until 5.2.0, now a DEPRECATED alias
39+
class NVHPC(metaclass=abc.ABCMeta): # pylint: disable=too-few-public-methods
40+
"""DEPRECATED alias for NvidiaCompilers."""
41+
def __new__(cls, *args, **kwargs):
42+
if cls is NVHPC:
43+
inst = NvidiaCompilers(*args, **kwargs)
44+
inst.log.deprecated(
45+
"easybuild.toolchains.compiler.nvhpc was replaced by "
46+
"easybuild.toolchains.compiler.nvidia_compilers in EasyBuild 5.2.0", '6.0')
47+
return inst
48+
return super().__new__(cls)
49+
50+
51+
NVHPC.register(NvidiaCompilers)
52+
53+
# TODO EasyBuild 6.0: Remove NVHPC name from NvidiaCompilers.COMPILER_MODULE_NAME

easybuild/toolchains/compiler/nvidia_compilers.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
class NvidiaCompilers(Compiler):
4646
"NVHPC compiler class"
4747

48-
COMPILER_MODULE_NAME = ['nvidia-compilers']
48+
# TODO EasyBuild 6.0: Remove NVHPC name
49+
COMPILER_MODULE_NAME = ['nvidia-compilers', 'NVHPC']
4950

5051
COMPILER_FAMILY = TC_CONSTANT_NVHPC
5152

@@ -100,7 +101,3 @@ def _set_compiler_flags(self):
100101
if not self.options.get('optarch', False):
101102
self.variables.nextend('OPTFLAGS', ['tp=x64'])
102103
super()._set_compiler_flags()
103-
104-
def _set_compiler_vars(self):
105-
"""Set the compiler variables"""
106-
super()._set_compiler_vars()

easybuild/toolchains/nvhpc.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* Andreas Herten (Forschungszentrum Juelich)
3232
* Alex Domingo (Vrije Universiteit Brussel)
3333
"""
34+
import abc
3435
from easybuild.toolchains.gcccore import GCCcore
3536
from easybuild.toolchains.linalg.nvblas import NVBLAS
3637
from easybuild.toolchains.linalg.nvscalapack import NVScaLAPACK
@@ -45,3 +46,16 @@ class NVHPC(NvidiaCompilersToolchain, NVHPCX, NVBLAS, NVScaLAPACK):
4546
# GCCcore and system need to be listed as subtoolchains here only for legacy reasons;
4647
# recent NVHPC toolchains (versions >= 25.0) only have nvidia-compilers are subtoolchain
4748
SUBTOOLCHAIN = [NvidiaCompilersToolchain.NAME, GCCcore.NAME, SYSTEM_TOOLCHAIN_NAME]
49+
50+
51+
class NVHPCToolchain(metaclass=abc.ABCMeta): # pylint: disable=too-few-public-methods
52+
"""DEPRECATED alias for NvidiaCompilersToolchain."""
53+
def __new__(cls, *args, **kwargs):
54+
if cls is NVHPCToolchain:
55+
inst = NvidiaCompilersToolchain(*args, **kwargs)
56+
inst.log.deprecated("NVHPCToolchain was replaced by NvidiaCompilersToolchain in EasyBuild 5.2.0", '6.0')
57+
return inst
58+
return super().__new__(cls)
59+
60+
61+
NVHPCToolchain.register(NvidiaCompilersToolchain)

test/framework/toolchain.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def test_validate_pass_by_value(self):
528528

529529
pass_by_value = True
530530
ids = []
531-
for k, v in tc.variables.items():
531+
for _, v in tc.variables.items():
532532
for x in v:
533533
idx = id(x)
534534
if idx not in ids:
@@ -908,8 +908,6 @@ def test_misc_flags_unique_fortran(self):
908908
flag = tc.COMPILER_UNIQUE_OPTION_MAP[opt]
909909
if isinstance(flag, list):
910910
flag = ' '.join(flag)
911-
else:
912-
flag = flag
913911
for var in flag_vars:
914912
flags = tc.get_variable(var)
915913
if enable:
@@ -3389,6 +3387,42 @@ def test_get_flag(self):
33893387
tc.options.options_map['openmp'] = flags
33903388
self.assertEqual(tc.get_flag('openmp'), flagstring)
33913389

3390+
def test_nvhpc_compatibility(self):
3391+
"""Test that software using EasyBuild before 5.2.0 continues working
3392+
the compiler.nvhpc toolchain being renamed to NvidiaCompilers"""
3393+
from easybuild.toolchains.nvompi import Nvompi
3394+
from easybuild.toolchains.compiler.nvidia_compilers import NvidiaCompilers
3395+
from easybuild.toolchains.nvhpc import NvidiaCompilersToolchain, NVHPCToolchain
3396+
3397+
# test deprecation of NVHPC in v5.2.0
3398+
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stdout_stderr():
3399+
from easybuild.toolchains.compiler.nvhpc import NVHPC
3400+
self.assertIn("nvhpc was replaced by easybuild.toolchains.compiler.nvidia_compilers", self.get_stderr())
3401+
3402+
# load NVidiaCompilers, deprecated NVHPC corresponds to it
3403+
tc = NvidiaCompilers(name='NvidiaCompilers', version='2024a') # Common usage
3404+
# Might be checked by pre-5.2.0 users
3405+
self.assertIsInstance(tc, NVHPC)
3406+
3407+
# load deprecated NVHPC, NvidiaCompilers corresponds to it
3408+
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stdout_stderr():
3409+
tc = NVHPC(name='NVHPC', version='2024a') # Might be used by pre-5.2.0 users
3410+
self.assertIn("nvhpc was replaced by easybuild.toolchains.compiler.nvidia_compilers", self.get_stderr())
3411+
self.assertIsInstance(tc, NvidiaCompilers)
3412+
3413+
# load deprecated NVHPCToolchain, it corresponds to NvidiaCompilersToolchain
3414+
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stdout_stderr():
3415+
tc = NVHPCToolchain(name='NVHPC', version='2024a') # Might be used by pre-5.2.0 users
3416+
self.assertIn("NVHPCToolchain was replaced by NvidiaCompilersToolchain", self.get_stderr())
3417+
self.assertIsInstance(tc, NvidiaCompilersToolchain)
3418+
3419+
tc = Nvompi(version='2024a') # Common usage
3420+
self.assertIsInstance(tc, NvidiaCompilers)
3421+
self.assertIsInstance(tc, NvidiaCompilersToolchain)
3422+
self.assertIsInstance(tc, NVHPCToolchain)
3423+
# compiler toolchain NVHPC is deprecated in 5.2.0, but might still be checked by existing code
3424+
self.assertIsInstance(tc, NVHPC)
3425+
33923426

33933427
def suite(loader=None):
33943428
""" return all the tests"""

0 commit comments

Comments
 (0)