From 4b2d9e54994482049e67b4499c6a61de37f76d0e Mon Sep 17 00:00:00 2001 From: maochen Date: Thu, 30 Nov 2023 11:03:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90Bugfix=E3=80=91Solve=20the=20probl?= =?UTF-8?q?em=20that=20the=20profiling=20is=20stuck=20in=20specific=20scen?= =?UTF-8?q?arios.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torch_npu/profiler/analysis/npu_profiler.py | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/torch_npu/profiler/analysis/npu_profiler.py b/torch_npu/profiler/analysis/npu_profiler.py index fa1d220b78..b5006ddebc 100644 --- a/torch_npu/profiler/analysis/npu_profiler.py +++ b/torch_npu/profiler/analysis/npu_profiler.py @@ -2,7 +2,7 @@ import multiprocessing import os from multiprocessing.pool import Pool -from .prof_common_func.constant import Constant +from .prof_common_func.constant import Constant, print_warn_msg from .prof_common_func.path_manager import ProfilerPathManager from .prof_common_func.prof_process import ProfProcess from .profiling_parser import ProfilingParser @@ -10,10 +10,29 @@ 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. + """ + print_warn_msg("analyse start") + os.environ["ASCEND_LAUNCH_BLOCKING"] = "1" + try: + mp = multiprocessing.get_context("spawn") + p = mp.Process(target=NpuProfiler._analyse, args=(input_path, analysis_type, output_path), + kwargs=kwargs) + p.start() + p.join() + except Exception as e: + print_warn_msg(f"analyse error {e}") + + @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. + """ input_path = ProfilerPathManager.get_realpath(input_path) cls._check_input_path(input_path) profiler_path_list = ProfilerPathManager.get_profiler_path_list(input_path) -- Gitee From 1dd1b5d00bb4cff994afd5f135c16aa9420fe4dd Mon Sep 17 00:00:00 2001 From: maochen Date: Fri, 23 Feb 2024 10:53:15 +0800 Subject: [PATCH 2/2] xxxxxxxxxx --- setup.cfg | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index a83fd20df3..1bb39cd35f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,6 @@ -[metadata] +[ + + +4114445metadata] url = https://gitee.com/ascend/pytorch download_url = https://gitee.com/ascend/pytorch/tags -- Gitee