File size: 1,193 Bytes
68eed61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Fail before rollout if legacy SAPIEN maps CUDA to the wrong physical GPU."""
import argparse
import os
import subprocess


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--expected-uuid', required=True)
    args = parser.parse_args()
    import sapien.core as sapien
    engine = sapien.Engine()
    renderer = sapien.SapienRenderer(device='cuda:0', offscreen_only=True)
    engine.set_renderer(renderer)
    lines = subprocess.check_output([
        'nvidia-smi', '--query-compute-apps=gpu_uuid,pid', '--format=csv,noheader'
    ], text=True).splitlines()
    actual = {uuid.strip() for uuid, pid in (line.split(',') for line in lines)
              if pid.strip() == str(os.getpid())}
    if actual != {args.expected_uuid}:
        raise RuntimeError(
            f'SAPIEN physical GPU mismatch: expected {args.expected_uuid}, got {sorted(actual)}. '
            'This legacy renderer can confuse equal PCI bus numbers in different domains. '
            'No rollout was started; choose a verified free renderer GPU.'
        )
    print(f'SAPIEN_GPU_VERIFIED uuid={args.expected_uuid}', flush=True)


if __name__ == '__main__':
    main()