@@ -53,6 +53,10 @@ def cache_restore_key(version: str) -> str:
5353 return f"cuda-toolkit-{ version } -{ platform .system ().lower ()} -x64-"
5454
5555
56+ def windows_install_root (version : str ) -> Path :
57+ return Path (rf"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v{ major_minor (version )} " )
58+
59+
5660def emit_outputs () -> None :
5761 version = cuda_version ()
5862 lines = (
@@ -105,13 +109,43 @@ def verify() -> None:
105109 raise SystemExit (1 )
106110
107111
112+ def install () -> None :
113+ if platform .system () != "Windows" :
114+ raise SystemExit ("CUDA Toolkit install is only implemented for Windows CI." )
115+
116+ version = cuda_version ()
117+ install_root = windows_install_root (version )
118+ target_root = Path (cache_root (version ))
119+
120+ if verify_toolkit (target_root , version ):
121+ print (f"CUDA Toolkit { major_minor (version )} already restored at { target_root } ." )
122+ return
123+
124+ result = run (["choco" , "install" , "cuda" , "--version" , version , "--yes" , "--no-progress" ])
125+ if result .returncode != 0 :
126+ raise SystemExit (f"CUDA Toolkit { version } installation failed." )
127+
128+ if not verify_toolkit (install_root , version ):
129+ raise SystemExit (f"CUDA Toolkit { major_minor (version )} was not found at { install_root } after installation." )
130+
131+ target_root .mkdir (parents = True , exist_ok = True )
132+ result = run (["robocopy" , str (install_root ), str (target_root ), "/MIR" , "/R:2" , "/W:2" , "/NFL" , "/NDL" , "/NP" ])
133+ if result .returncode > 7 :
134+ raise SystemExit (f"Failed to mirror CUDA Toolkit into cache root. robocopy exit code: { result .returncode } " )
135+
136+ if not verify_toolkit (target_root , version ):
137+ raise SystemExit (f"CUDA Toolkit { major_minor (version )} was not found at { target_root } after installation." )
138+
139+
108140def main () -> None :
109141 parser = argparse .ArgumentParser ()
110- parser .add_argument ("command" , choices = ("outputs" , "verify" ))
142+ parser .add_argument ("command" , choices = ("outputs" , "install" , " verify" ))
111143 args = parser .parse_args ()
112144
113145 if args .command == "outputs" :
114146 emit_outputs ()
147+ elif args .command == "install" :
148+ install ()
115149 elif args .command == "verify" :
116150 verify ()
117151
0 commit comments