(gpu_id, cfg_path)
| 809 | signal.signal(signal.SIGTERM, _shutdown) |
| 810 | |
| 811 | def dispatch(gpu_id, cfg_path): |
| 812 | name = _name_from_cfg(cfg_path) |
| 813 | out_json = os.path.join(args.outdir, "per_model", f"{name}.json") |
| 814 | log_path = os.path.join(args.outdir, "log", f"{name}.log") |
| 815 | heartbeat = out_json.replace(".json", ".heartbeat") |
| 816 | |
| 817 | # Remove the old heartbeat (if this is a resume) |
| 818 | try: |
| 819 | if os.path.isfile(heartbeat): |
| 820 | os.unlink(heartbeat) |
| 821 | except Exception: |
| 822 | pass |
| 823 | |
| 824 | env = {**os.environ, |
| 825 | "CUDA_VISIBLE_DEVICES": str(gpu_id), |
| 826 | "PYTORCH_CUDA_ALLOC_CONF": "expandable_segments:True"} |
| 827 | # Thread throttling: with multiple workers in parallel, prevent OpenMP / MKL / |
| 828 | # OpenBLAS / NumExpr / OpenCV from saturating the whole machine's CPUs. The |
| 829 | # driver reads args.cpus_per_worker for the cap, and it takes effect before |
| 830 | # the worker process starts (these env vars are read by the corresponding |
| 831 | # libraries at child-process import time). |
| 832 | if args.cpus_per_worker > 0: |
| 833 | n = str(args.cpus_per_worker) |
| 834 | env.update({ |
| 835 | "OMP_NUM_THREADS": n, |
| 836 | "MKL_NUM_THREADS": n, |
| 837 | "OPENBLAS_NUM_THREADS": n, |
| 838 | "NUMEXPR_NUM_THREADS": n, |
| 839 | "NUMEXPR_MAX_THREADS": n, |
| 840 | "VECLIB_MAXIMUM_THREADS": n, |
| 841 | "BENCH_WORKER_THREADS": n, # the worker reads this internally and then calls the torch/cv2 APIs |
| 842 | }) |
| 843 | log_fh = open(log_path, "w") |
| 844 | worker_cmd = [ |
| 845 | sys.executable, os.path.abspath(__file__), |
| 846 | "--worker", "--config", cfg_path, "--out-json", out_json, |
| 847 | "--batch-sizes", batch_sizes_arg, "--fixture", fixture_arg, |
| 848 | ] |
| 849 | if args.with_metrics: |
| 850 | worker_cmd.append("--with-metrics") |
| 851 | proc = subprocess.Popen( |
| 852 | worker_cmd, |
| 853 | env=env, stdout=log_fh, stderr=subprocess.STDOUT, |
| 854 | start_new_session=True, |
| 855 | ) |
| 856 | running[gpu_id] = { |
| 857 | "proc": proc, "config": cfg_path, "out_json": out_json, |
| 858 | "heartbeat": heartbeat, "log_fh": log_fh, |
| 859 | "started": time.time(), "name": name, |
| 860 | } |
| 861 | print(f"[{time.strftime('%H:%M:%S')}] [START] {name} -> GPU {gpu_id} " |
| 862 | f"pid={proc.pid} log={log_path}") |
| 863 | |
| 864 | def kill_timed_out(): |
| 865 | now = time.time() |
no test coverage detected