Skip to content

Commit 0047019

Browse files
authored
Merge pull request #3807 from boegel/get_cuda_cc_template_value
add get_cuda_cc_template_value method to EasyConfig class
2 parents 4ac730d + f9db177 commit 0047019

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

easybuild/framework/easyconfig/easyconfig.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
from easybuild.framework.easyconfig.licenses import EASYCONFIG_LICENSES_DICT
6060
from easybuild.framework.easyconfig.parser import DEPRECATED_PARAMETERS, REPLACED_PARAMETERS
6161
from easybuild.framework.easyconfig.parser import EasyConfigParser, fetch_parameters_from_easyconfig
62-
from easybuild.framework.easyconfig.templates import TEMPLATE_CONSTANTS, template_constant_dict
62+
from easybuild.framework.easyconfig.templates import TEMPLATE_CONSTANTS, TEMPLATE_NAMES_DYNAMIC, template_constant_dict
6363
from easybuild.tools.build_log import EasyBuildError, print_warning, print_msg
6464
from easybuild.tools.config import GENERIC_EASYBLOCK_PKG, LOCAL_VAR_NAMING_CHECK_ERROR, LOCAL_VAR_NAMING_CHECK_LOG
6565
from easybuild.tools.config import LOCAL_VAR_NAMING_CHECK_WARN
@@ -1803,6 +1803,25 @@ def asdict(self):
18031803
res[key] = value
18041804
return res
18051805

1806+
def get_cuda_cc_template_value(self, key):
1807+
"""
1808+
Get template value based on --cuda-compute-capabilities EasyBuild configuration option
1809+
and cuda_compute_capabilities easyconfig parameter.
1810+
Returns user-friendly error message in case neither are defined,
1811+
or if an unknown key is used.
1812+
"""
1813+
if key.startswith('cuda_') and any(x[0] == key for x in TEMPLATE_NAMES_DYNAMIC):
1814+
try:
1815+
return self.template_values[key]
1816+
except KeyError:
1817+
error_msg = "Template value '%s' is not defined!\n"
1818+
error_msg += "Make sure that either the --cuda-compute-capabilities EasyBuild configuration "
1819+
error_msg += "option is set, or that the cuda_compute_capabilities easyconfig parameter is defined."
1820+
raise EasyBuildError(error_msg, key)
1821+
else:
1822+
error_msg = "%s is not a template value based on --cuda-compute-capabilities/cuda_compute_capabilities"
1823+
raise EasyBuildError(error_msg, key)
1824+
18061825

18071826
def det_installversion(version, toolchain_name, toolchain_version, prefix, suffix):
18081827
"""Deprecated 'det_installversion' function, to determine exact install version, based on supplied parameters."""

test/framework/easyconfig.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4483,6 +4483,56 @@ def test_easyconfig_import(self):
44834483
error_pattern = r"Failed to copy '.*' easyconfig parameter"
44844484
self.assertErrorRegex(EasyBuildError, error_pattern, EasyConfig, test_ec)
44854485

4486+
def test_get_cuda_cc_template_value(self):
4487+
"""
4488+
Test getting template value based on --cuda-compute-capabilities / cuda_compute_capabilities.
4489+
"""
4490+
self.contents = '\n'.join([
4491+
'easyblock = "ConfigureMake"',
4492+
'name = "pi"',
4493+
'version = "3.14"',
4494+
'homepage = "http://example.com"',
4495+
'description = "test easyconfig"',
4496+
'toolchain = SYSTEM',
4497+
])
4498+
self.prep()
4499+
ec = EasyConfig(self.eb_file)
4500+
4501+
error_pattern = "foobar is not a template value based on --cuda-compute-capabilities/cuda_compute_capabilities"
4502+
self.assertErrorRegex(EasyBuildError, error_pattern, ec.get_cuda_cc_template_value, 'foobar')
4503+
4504+
error_pattern = r"Template value '%s' is not defined!\n"
4505+
error_pattern += r"Make sure that either the --cuda-compute-capabilities EasyBuild configuration "
4506+
error_pattern += "option is set, or that the cuda_compute_capabilities easyconfig parameter is defined."
4507+
cuda_template_values = {
4508+
'cuda_compute_capabilities': '6.5,7.0',
4509+
'cuda_cc_space_sep': '6.5 7.0',
4510+
'cuda_cc_semicolon_sep': '6.5;7.0',
4511+
'cuda_sm_comma_sep': 'sm_65,sm_70',
4512+
'cuda_sm_space_sep': 'sm_65 sm_70',
4513+
}
4514+
for key in cuda_template_values:
4515+
self.assertErrorRegex(EasyBuildError, error_pattern % key, ec.get_cuda_cc_template_value, key)
4516+
4517+
update_build_option('cuda_compute_capabilities', ['6.5', '7.0'])
4518+
ec = EasyConfig(self.eb_file)
4519+
4520+
for key in cuda_template_values:
4521+
self.assertEqual(ec.get_cuda_cc_template_value(key), cuda_template_values[key])
4522+
4523+
update_build_option('cuda_compute_capabilities', None)
4524+
ec = EasyConfig(self.eb_file)
4525+
4526+
for key in cuda_template_values:
4527+
self.assertErrorRegex(EasyBuildError, error_pattern % key, ec.get_cuda_cc_template_value, key)
4528+
4529+
self.contents += "\ncuda_compute_capabilities = ['6.5', '7.0']"
4530+
self.prep()
4531+
ec = EasyConfig(self.eb_file)
4532+
4533+
for key in cuda_template_values:
4534+
self.assertEqual(ec.get_cuda_cc_template_value(key), cuda_template_values[key])
4535+
44864536

44874537
def suite():
44884538
""" returns all the testcases in this module """

0 commit comments

Comments
 (0)