Skip to content

Commit 2f079a6

Browse files
committed
Change unit of cuda-cache-size to MiB and add cuda_cache_dir
1 parent 26b0ef0 commit 2f079a6

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

easybuild/framework/easyblock.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,24 @@ def make_dir(self, dir_name, clean, dontcreateinstalldir=False):
10271027

10281028
mkdir(dir_name, parents=True)
10291029

1030+
def setup_cuda_cache(self):
1031+
cuda_cache_maxsize = build_option('cuda_cache_maxsize')
1032+
if cuda_cache_maxsize is None:
1033+
cuda_cache_maxsize = 1 * 1024 # 1 GiB default value
1034+
else:
1035+
cuda_cache_maxsize = int(cuda_cache_maxsize)
1036+
if cuda_cache_maxsize == 0:
1037+
self.log.info('Disabling CUDA PTX cache as per request')
1038+
env.setvar('CUDA_CACHE_DISABLE', '1')
1039+
else:
1040+
cuda_cache_dir = build_option('cuda_cache_dir')
1041+
if not cuda_cache_dir:
1042+
cuda_cache_dir = os.path.join(self.builddir, 'eb-cuda-cache')
1043+
self.log.info('Enabling CUDA PTX cache of size %s MiB at %s', cuda_cache_maxsize, cuda_cache_dir)
1044+
env.setvar('CUDA_CACHE_DISABLE', '0')
1045+
env.setvar('CUDA_CACHE_PATH', cuda_cache_dir)
1046+
env.setvar('CUDA_CACHE_MAXSIZE', str(cuda_cache_maxsize * 1024 * 1024))
1047+
10301048
#
10311049
# MODULE UTILITY FUNCTIONS
10321050
#
@@ -2152,19 +2170,7 @@ def prepare_step(self, start_dir=True, load_tc_deps_modules=True):
21522170

21532171
# Setup CUDA cache if required. If we don't do this, CUDA will use the $HOME for its cache files
21542172
if get_software_root('CUDA') or get_software_root('CUDAcore'):
2155-
cuda_cache_maxsize = build_option('cuda_cache_maxsize')
2156-
if cuda_cache_maxsize is None:
2157-
cuda_cache_maxsize = 1 * 1024 * 1024 * 1024 # 1 GB default value
2158-
if cuda_cache_maxsize == 0:
2159-
self.log.info('Disabling CUDA PTX cache as per request')
2160-
env.setvar('CUDA_CACHE_DISABLE', '1')
2161-
else:
2162-
cuda_cache_dir = os.path.join(self.builddir, 'eb-cuda-cache')
2163-
self.log.info('Enabling CUDA PTX cache of size %s MB at %s',
2164-
cuda_cache_maxsize / 1024 / 1024, cuda_cache_dir)
2165-
env.setvar('CUDA_CACHE_DISABLE', '0')
2166-
env.setvar('CUDA_CACHE_PATH', cuda_cache_dir)
2167-
env.setvar('CUDA_CACHE_MAXSIZE', str(cuda_cache_maxsize))
2173+
self.setup_cuda_cache()
21682174

21692175
# guess directory to start configure/build/install process in, and move there
21702176
if start_dir:

easybuild/tools/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def mk_full_default_path(name, prefix=DEFAULT_PREFIX):
169169
'container_image_name',
170170
'container_template_recipe',
171171
'container_tmpdir',
172+
'cuda_cache_dir',
172173
'cuda_cache_maxsize',
173174
'cuda_compute_capabilities',
174175
'download_timeout',

easybuild/tools/options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ def override_options(self):
357357
'consider-archived-easyconfigs': ("Also consider archived easyconfigs", None, 'store_true', False),
358358
'containerize': ("Generate container recipe/image", None, 'store_true', False, 'C'),
359359
'copy-ec': ("Copy specified easyconfig(s) to specified location", None, 'store_true', False),
360-
'cuda-cache-maxsize': ("Maximum size of the CUDA cache (in bytes) used for JIT compilation of PTX code. "
360+
'cuda-cache-dir': ("Path to CUDA cache dir to use if enabled. Defaults to a path inside the build dir.",
361+
str, 'store', None, {'metavar': "PATH"}),
362+
'cuda-cache-maxsize': ("Maximum size of the CUDA cache (in MiB) used for JIT compilation of PTX code. "
361363
"Leave value empty to let EasyBuild choose a value or '0' to disable the cache",
362364
int, 'store_or_None', None),
363365
'cuda-compute-capabilities': ("List of CUDA compute capabilities to use when building GPU software; "

test/framework/easyblock.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ def test_prepare_step_hmns(self):
17621762
self.assertEqual(loaded_modules[0]['mod_name'], 'GCC/6.4.0-2.28')
17631763

17641764
def test_prepare_step_cuda_cache(self):
1765-
"""Test handling cuda-cache-maxsize option."""
1765+
"""Test handling cuda-cache-* options."""
17661766

17671767
init_config(build_options={'cuda_cache_maxsize': None}) # Automatic mode
17681768

@@ -1803,14 +1803,17 @@ def test_prepare_step_cuda_cache(self):
18031803
self.assertNotIn('Enabling CUDA PTX cache', logtxt)
18041804
self.assertEqual(os.environ['CUDA_CACHE_DISABLE'], '1')
18051805

1806-
init_config(build_options={'cuda_cache_maxsize': 1234567890}) # Specified size
1806+
# Specified size and location
1807+
cuda_cache_dir = os.path.join(self.test_prefix, 'custom-cuda-cache')
1808+
init_config(build_options={'cuda_cache_maxsize': 1234, 'cuda_cache_dir': cuda_cache_dir})
18071809
write_file(eb.logfile, '')
18081810
eb.prepare_step(start_dir=False)
18091811
logtxt = read_file(eb.logfile)
18101812
self.assertNotIn('Disabling CUDA PTX cache', logtxt)
18111813
self.assertIn('Enabling CUDA PTX cache', logtxt)
18121814
self.assertEqual(os.environ['CUDA_CACHE_DISABLE'], '0')
1813-
self.assertEqual(os.environ['CUDA_CACHE_MAXSIZE'], '1234567890')
1815+
self.assertEqual(os.environ['CUDA_CACHE_MAXSIZE'], str(1234 * 1024 * 1024))
1816+
self.assertEqual(os.environ['CUDA_CACHE_PATH'], cuda_cache_dir)
18141817

18151818
def test_checksum_step(self):
18161819
"""Test checksum step"""

0 commit comments

Comments
 (0)