From ab07692692ade6bdda873260d5aa3a80e2fdf39b Mon Sep 17 00:00:00 2001 From: huguoheng Date: Tue, 5 Sep 2023 09:13:39 +0000 Subject: [PATCH 1/2] update ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/utils.py. fix cpu device error Signed-off-by: huguoheng --- .../src/python/ptdbg_ascend/online_dispatch/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/utils.py b/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/utils.py index 149eca3c..aa6874a0 100644 --- a/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/utils.py +++ b/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/utils.py @@ -4,6 +4,14 @@ import logging import psutil import torch import numpy as np + +try: + import torch_npu +except ImportError: + pta_cpu_device = None +else: + pta_cpu_device = torch.device("cpu") + from ..common.utils import print_error_log, CompareConst cpu_device = torch._C.device("cpu") @@ -72,7 +80,7 @@ def data_to_cpu(data, deep, data_cpu): global cpu_device list_cpu = [] if isinstance(data, torch.Tensor): - if data.device == cpu_device: + if data.device == cpu_device or data.device == pta_cpu_device: tensor_copy = data.clone().detach() else: tensor_copy = data.cpu() -- Gitee From faa0f949a6bd0a25a3e70f0f5a4d6823ce5a84ce Mon Sep 17 00:00:00 2001 From: huguoheng Date: Tue, 5 Sep 2023 09:15:22 +0000 Subject: [PATCH 2/2] update ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/dump_compare.py. add debug log Signed-off-by: huguoheng --- .../src/python/ptdbg_ascend/online_dispatch/dump_compare.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/dump_compare.py b/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/dump_compare.py index 9eb6da28..54d7211f 100644 --- a/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/dump_compare.py +++ b/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/dump_compare.py @@ -44,11 +44,13 @@ class TimeStatistics: def __enter__(self): if self.debug: self.time = datetime.now() + logger_debug(f'Time[{self.tag}]-ENTER: Dev[{self.device}], Pid[{os.getpid()}], Fun[{self.fun}], ' \ + f'Id[{self.index}]') def __exit__(self, exc_type, exc_val, exc_tb): if self.debug: cost_time = datetime.now() - self.time - time_cost = f'Time[{self.tag}]: Dev[{self.device}], Pid[{os.getpid()}], Fun[{self.fun}], ' \ + time_cost = f'Time[{self.tag}]-EXIT: Dev[{self.device}], Pid[{os.getpid()}], Fun[{self.fun}], ' \ f'Id[{self.index}], time[{cost_time}]' hot_time_cost = "Hotspot " + time_cost -- Gitee