MCPcopy Create free account
hub / github.com/VCIP-RGBD/DFormer / setup_multi_processes

Function setup_multi_processes

mmseg/utils/set_env.py:11–55  ·  view source on GitHub ↗

Setup multi-processing environment variables.

(cfg)

Source from the content-addressed store, hash-verified

9
10
11def setup_multi_processes(cfg):
12 """Setup multi-processing environment variables."""
13 logger = get_root_logger()
14
15 # set multi-process start method
16 if platform.system() != "Windows":
17 mp_start_method = cfg.get("mp_start_method", None)
18 current_method = mp.get_start_method(allow_none=True)
19 if mp_start_method in ("fork", "spawn", "forkserver"):
20 logger.info(
21 f"Multi-processing start method `{mp_start_method}` is "
22 f"different from the previous setting `{current_method}`."
23 f"It will be force set to `{mp_start_method}`."
24 )
25 mp.set_start_method(mp_start_method, force=True)
26 else:
27 logger.info(f"Multi-processing start method is `{mp_start_method}`")
28
29 # disable opencv multithreading to avoid system being overloaded
30 opencv_num_threads = cfg.get("opencv_num_threads", None)
31 if isinstance(opencv_num_threads, int):
32 logger.info(f"OpenCV num_threads is `{opencv_num_threads}`")
33 cv2.setNumThreads(opencv_num_threads)
34 else:
35 logger.info(f"OpenCV num_threads is `{cv2.getNumThreads()}")
36
37 if cfg.data.workers_per_gpu > 1:
38 # setup OMP threads
39 # This code is referred from https://github.com/pytorch/pytorch/blob/master/torch/distributed/run.py # noqa
40 omp_num_threads = cfg.get("omp_num_threads", None)
41 if "OMP_NUM_THREADS" not in os.environ:
42 if isinstance(omp_num_threads, int):
43 logger.info(f"OMP num threads is {omp_num_threads}")
44 os.environ["OMP_NUM_THREADS"] = str(omp_num_threads)
45 else:
46 logger.info(f"OMP num threads is {os.environ['OMP_NUM_THREADS']}")
47
48 # setup MKL threads
49 if "MKL_NUM_THREADS" not in os.environ:
50 mkl_num_threads = cfg.get("mkl_num_threads", None)
51 if isinstance(mkl_num_threads, int):
52 logger.info(f"MKL num threads is {mkl_num_threads}")
53 os.environ["MKL_NUM_THREADS"] = str(mkl_num_threads)
54 else:
55 logger.info(f"MKL num threads is {os.environ['MKL_NUM_THREADS']}")

Callers

nothing calls this directly

Calls 1

get_root_loggerFunction · 0.85

Tested by

no test coverage detected