Datasets:
Download code/robohome/src/engine/source/packages/adapters/source_device.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/source/packages/adapters/source_device.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome@86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/source/packages/adapters/source_device.py
-
curl -L -o source_device.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/source/packages/adapters/source_device.py
1.55 kB
| """Reserve one currently idle local GPU for a source Blender conversion.""" | |
| from contextlib import contextmanager | |
| from pathlib import Path | |
| import fcntl,os,subprocess,tempfile | |
| def blender_environment(output,requested=None): | |
| result=subprocess.run(['nvidia-smi','--query-gpu=index,uuid,memory.used','--format=csv,noheader,nounits'],capture_output=True,text=True,timeout=20) | |
| devices=[] | |
| for line in result.stdout.splitlines(): | |
| fields=[v.strip() for v in line.split(',')] | |
| if len(fields)!=3 or not fields[0].isdigit():continue | |
| index,uuid,used=fields | |
| if requested and requested not in (index,uuid):continue | |
| if float(used)<200:devices.append((index,uuid)) | |
| for index,uuid in devices: | |
| lock=open(Path(tempfile.gettempdir())/('rhg-source-'+uuid+'.lock'),'a+') | |
| try: | |
| fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB) | |
| except BlockingIOError: | |
| lock.close();continue | |
| try: | |
| used=float(subprocess.check_output(['nvidia-smi','-i',uuid,'--query-gpu=memory.used','--format=csv,noheader,nounits'],text=True,timeout=20)) | |
| if used>=200:continue | |
| cache=Path(output)/'source-blender-cache';cache.mkdir(exist_ok=False) | |
| yield dict(os.environ,CUDA_VISIBLE_DEVICES=uuid,OMP_NUM_THREADS='2',OPENBLAS_NUM_THREADS='1',XDG_CACHE_HOME=str(cache)) | |
| return | |
| finally: | |
| lock.close() | |
| raise RuntimeError('No idle local GPU for source Blender rendering/baking; queue on an available worker') | |