"""Install a private, hash-pinned CUDA 13 toolkit. Never installs a driver.""" import hashlib,json,os,shutil,tarfile,urllib.request from pathlib import Path BASE='https://developer.download.nvidia.com/compute/cuda/redist/' def toolkit(root): root=Path(root);lock=json.loads((Path(__file__).parent/'strata-cuda13.lock.json').read_text());identity=hashlib.sha256(json.dumps(lock,sort_keys=True).encode()).hexdigest() nested=root/'nvvm/nvvm' if nested.is_dir(): shutil.copytree(nested,root/'nvvm',dirs_exist_ok=True,symlinks=True);shutil.rmtree(nested) if (root/'lib').is_dir() and not (root/'lib64').exists():(root/'lib64').symlink_to('lib',target_is_directory=True) if (root/'ready').is_file() and (root/'ready').read_text()==identity:return root/'bin/nvcc' root.mkdir(parents=True,exist_ok=True) for name,item in lock.items(): archive=root/(name+'.tar.xz');h=hashlib.sha256() with urllib.request.urlopen(BASE+item['relative_path'],timeout=60) as r,archive.open('wb') as f: while block:=r.read(4*1024**2):h.update(block);f.write(block) if h.hexdigest()!=item['sha256']:raise ValueError('CUDA-Komponente hat falsche Prüfsumme: '+name) temp=root/('extract-'+name);temp.mkdir(exist_ok=True) with tarfile.open(archive) as t:t.extractall(temp,filter='data') component=next(temp.iterdir()) # NVIDIA redist archives already preserve toolkit-relative directories, target=root shutil.copytree(component,target,dirs_exist_ok=True,symlinks=True) shutil.rmtree(temp);archive.unlink() if (root/'lib').is_dir() and not (root/'lib64').exists():(root/'lib64').symlink_to('lib',target_is_directory=True) (root/'ready').write_text(identity) if not (root/'bin/nvcc').is_file():raise ValueError('CUDA nvcc fehlt nach Installation.') return root/'bin/nvcc'