From ff9348c3de62bab248f858e56e7a0720d9b26f88 Mon Sep 17 00:00:00 2001 From: maochen Date: Thu, 30 Nov 2023 11:03:02 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90Bugfix=E3=80=91Solve=20the=20problem?= =?UTF-8?q?=20that=20the=20profiling=20is=20stuck=20in=20specific=20scenar?= =?UTF-8?q?ios.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torch_npu/profiler/analysis/npu_profiler.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/torch_npu/profiler/analysis/npu_profiler.py b/torch_npu/profiler/analysis/npu_profiler.py index f6b136be76..f99b734151 100644 --- a/torch_npu/profiler/analysis/npu_profiler.py +++ b/torch_npu/profiler/analysis/npu_profiler.py @@ -24,9 +24,20 @@ from ...utils.path_manager import PathManager class NpuProfiler: - @classmethod def analyse(cls, input_path: str, analysis_type: str = Constant.TENSORBOARD_TRACE_HANDLER, output_path: str = None, + **kwargs): + """ Muti-process in parsing use fork to generate child processes for better performance, while forking from a + muti-threaded process may cause deadlock. So spawn a pure process to be public parent process for parsing. + """ + mp = multiprocessing.get_context("spawn") + p = mp.Process(target=NpuProfiler._analyse, args=(input_path, analysis_type, output_path), + kwargs=kwargs) + p.start() + p.join() + + @classmethod + def _analyse(cls, input_path: str, analysis_type: str = Constant.TENSORBOARD_TRACE_HANDLER, output_path: str = None, **kwargs): input_path = ProfilerPathManager.get_realpath(input_path) cls._check_input_path(input_path) -- Gitee