@@ -1894,6 +1894,60 @@ def test_prepare_step_hmns(self):
18941894 self .assertEqual (len (loaded_modules ), 1 )
18951895 self .assertEqual (loaded_modules [0 ]['mod_name' ], 'GCC/6.4.0-2.28' )
18961896
1897+ def test_prepare_step_cuda_cache (self ):
1898+ """Test handling cuda-cache-* options."""
1899+
1900+ init_config (build_options = {'cuda_cache_maxsize' : None }) # Automatic mode
1901+
1902+ test_ecs = os .path .join (os .path .abspath (os .path .dirname (__file__ )), 'easyconfigs' , 'test_ecs' )
1903+ toy_ec = os .path .join (test_ecs , 't' , 'toy' , 'toy-0.0.eb' )
1904+ ec = process_easyconfig (toy_ec )[0 ]
1905+ eb = EasyBlock (ec ['ec' ])
1906+ eb .silent = True
1907+ eb .make_builddir ()
1908+
1909+ eb .prepare_step (start_dir = False )
1910+ logtxt = read_file (eb .logfile )
1911+ self .assertNotIn ('Disabling CUDA PTX cache' , logtxt )
1912+ self .assertNotIn ('Enabling CUDA PTX cache' , logtxt )
1913+
1914+ # Now with CUDA
1915+ test_ec = os .path .join (self .test_prefix , 'test.eb' )
1916+ test_ectxt = re .sub ('^toolchain = .*' , "toolchain = {'name': 'gcccuda', 'version': '2018a'}" ,
1917+ read_file (toy_ec ), flags = re .M )
1918+ write_file (test_ec , test_ectxt )
1919+ ec = process_easyconfig (test_ec )[0 ]
1920+ eb = EasyBlock (ec ['ec' ])
1921+ eb .silent = True
1922+ eb .make_builddir ()
1923+
1924+ write_file (eb .logfile , '' )
1925+ eb .prepare_step (start_dir = False )
1926+ logtxt = read_file (eb .logfile )
1927+ self .assertNotIn ('Disabling CUDA PTX cache' , logtxt )
1928+ self .assertIn ('Enabling CUDA PTX cache' , logtxt )
1929+ self .assertEqual (os .environ ['CUDA_CACHE_DISABLE' ], '0' )
1930+
1931+ init_config (build_options = {'cuda_cache_maxsize' : 0 }) # Disable
1932+ write_file (eb .logfile , '' )
1933+ eb .prepare_step (start_dir = False )
1934+ logtxt = read_file (eb .logfile )
1935+ self .assertIn ('Disabling CUDA PTX cache' , logtxt )
1936+ self .assertNotIn ('Enabling CUDA PTX cache' , logtxt )
1937+ self .assertEqual (os .environ ['CUDA_CACHE_DISABLE' ], '1' )
1938+
1939+ # Specified size and location
1940+ cuda_cache_dir = os .path .join (self .test_prefix , 'custom-cuda-cache' )
1941+ init_config (build_options = {'cuda_cache_maxsize' : 1234 , 'cuda_cache_dir' : cuda_cache_dir })
1942+ write_file (eb .logfile , '' )
1943+ eb .prepare_step (start_dir = False )
1944+ logtxt = read_file (eb .logfile )
1945+ self .assertNotIn ('Disabling CUDA PTX cache' , logtxt )
1946+ self .assertIn ('Enabling CUDA PTX cache' , logtxt )
1947+ self .assertEqual (os .environ ['CUDA_CACHE_DISABLE' ], '0' )
1948+ self .assertEqual (os .environ ['CUDA_CACHE_MAXSIZE' ], str (1234 * 1024 * 1024 ))
1949+ self .assertEqual (os .environ ['CUDA_CACHE_PATH' ], cuda_cache_dir )
1950+
18971951 def test_checksum_step (self ):
18981952 """Test checksum step"""
18991953 testdir = os .path .abspath (os .path .dirname (__file__ ))
0 commit comments