diff --git a/profiler/advisor/advisor_backend/compute_advice/compute_advice_base.py b/profiler/advisor/advisor_backend/compute_advice/compute_advice_base.py index cca97c1e77739c08d11dbaa9e03494936d16b382..25189e90e7800b9d4fc9f5ce936c43976a488f58 100644 --- a/profiler/advisor/advisor_backend/compute_advice/compute_advice_base.py +++ b/profiler/advisor/advisor_backend/compute_advice/compute_advice_base.py @@ -16,10 +16,13 @@ from abc import abstractmethod from collections import defaultdict import os +import logging from advice_base import AdviceBase from profiler.prof_common.file_manager import FileManager +logger=logging.getLogger() + class ComputeAdviceBase(AdviceBase): ASCEND_PT = 'ascend_pt' @@ -40,22 +43,22 @@ class ComputeAdviceBase(AdviceBase): check whether input path is valid """ if not os.path.exists(self.collection_path): - print("[ERROR] Path: {} is not exist.".format(self.collection_path)) + logger.error("Path: {} is not exist.".format(self.collection_path)) return False if os.path.isdir(self.collection_path) and \ (self.collection_path.endswith("ascend_pt") or self.collection_path.endswith("ascend_ms")): self.kernel_details_path = os.path.join(self.collection_path, "ASCEND_PROFILER_OUTPUT", "kernel_details.csv") if not os.path.exists(self.kernel_details_path): - print("[ERROR] kernel_details.csv is not exist in the Path: {}.".format( + logger.error("kernel_details.csv is not exist in the Path: {}.".format( os.path.join(self.collection_path, "ASCEND_PROFILER_OUTPUT"))) return False elif os.path.isfile(self.collection_path) and os.path.basename(self.collection_path) == "kernel_details.csv": self.kernel_details_path = self.collection_path else: - print("[ERROR] Please input ascend_pt or kernel_details.csv") + logger.error("Please input ascend_pt or kernel_details.csv") return False - print("[INFO] Start to analyse the target file: {}".format(self.kernel_details_path)) + logger.info("Start to analyse the target file: {}".format(self.kernel_details_path)) self.preparse() return True diff --git a/profiler/advisor/advisor_backend/compute_advice/npu_fused/json_analyzer.py b/profiler/advisor/advisor_backend/compute_advice/npu_fused/json_analyzer.py index fd2a72ffa39bfde1b3e59450c6d76f51d98110d9..458da572bbdc491ad0b1dd2ea7f21047a756772b 100644 --- a/profiler/advisor/advisor_backend/compute_advice/npu_fused/json_analyzer.py +++ b/profiler/advisor/advisor_backend/compute_advice/npu_fused/json_analyzer.py @@ -13,10 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging + import pandas as pd from common_func_advisor.trace_view_json import TraceViewJson +logger=logging.getLogger() + class JSONAnalyzer(object): def __init__(self, path): @@ -28,18 +32,18 @@ class JSONAnalyzer(object): for i, row in data.iterrows(): if ts_col not in data.columns.tolist(): - print("[ERROR] No {} col found in data columns.".format(ts_col)) + logger.error("No {} col found in data columns.".format(ts_col)) return callstacks timestamp = row[ts_col] flow_event = trace_json.get_torch_2_npu_flow_event(timestamp) if not flow_event.valid(): - print("[ERROR] Get flow event failed for pattern {}.".format(row['pattern'])) + logger.error("Get flow event failed for pattern {}.".format(row['pattern'])) callstacks.loc[i] = "" continue flow_event_s_key = flow_event.s_point_ts python_dur_events = trace_json.get_python_dur_events_contain_ts(flow_event_s_key) if not python_dur_events: - print("[ERROR] No python dur event found for pattern {}.".format(row['pattern'])) + logger.error("No python dur event found for pattern {}.".format(row['pattern'])) callstacks.loc[i] = "" continue # 保持新老版本callstack兼容性 diff --git a/profiler/advisor/advisor_backend/compute_advice/npu_fused/op_perf.py b/profiler/advisor/advisor_backend/compute_advice/npu_fused/op_perf.py index 7bcbed5a75807b57a55787c743cfaaff55a68589..4b37b6a2d6a55c95aa7b14229a14c9a7285e09c6 100644 --- a/profiler/advisor/advisor_backend/compute_advice/npu_fused/op_perf.py +++ b/profiler/advisor/advisor_backend/compute_advice/npu_fused/op_perf.py @@ -14,11 +14,14 @@ # limitations under the License. import functools from typing import Dict +import logging from common_func_advisor.constant import Constant from common_func_advisor.constant import CoreType from common_func_advisor.constant import PerfColor +logger=logging.getLogger() + class OpPerfFactory: @classmethod @@ -129,7 +132,7 @@ class OpPerf: shapes = self.shape_to_tuple(shapes_str) dtypes = self.dtype_to_tuple(dtypes_str) if len(shapes) > len(dtypes): - print(f"[ERROR] The size of shape is greater than that of dtypes.") + logger.error("The size of shape is greater than that of dtypes.") return 0 if len(shapes) < len(dtypes): shapes = list(shapes) @@ -144,7 +147,7 @@ class OpPerf: def get_calc_size(self): # input and output bytes (MB) if not self.input_shapes or not self.output_shapes: - print("[ERROR] There is no tensor data, do not assess vector op performance.") + logger.error("There is no tensor data, do not assess vector op performance.") return 0 intput_size = self.get_size(self.input_shapes, self.input_data_types) output_size = self.get_size(self.output_shapes, self.output_data_types) @@ -153,7 +156,7 @@ class OpPerf: def get_throughput(self): # throughput(GB/s) if not self.task_duration or abs(self.task_duration) < 1e-6: - print("[ERROR] There is no task_duration, do not assess vector op performance.") + logger.error("There is no task_duration, do not assess vector op performance.") return 0 return self.row[Constant.TITLE.SIZE] / Constant.BYTE_UNIT_TRANS / self.task_duration * Constant.UNIT_TRANS * Constant.UNIT_TRANS @@ -186,7 +189,7 @@ class CubeOpPerf(OpPerf): def get_perf_color(self) -> PerfColor: aic_mac_ratio = self.get_mac_ratio() if not aic_mac_ratio: - print("[WARNING] There is no aic_mac_ratio, do not assess cube op performance.") + logger.warning("There is no aic_mac_ratio, do not assess cube op performance.") return PerfColor.WHITE elif aic_mac_ratio < 0.6: return PerfColor.RED diff --git a/profiler/advisor/advisor_backend/compute_advice/npu_fused_advice.py b/profiler/advisor/advisor_backend/compute_advice/npu_fused_advice.py index fd5610bbbbb98d15fbab22bb646b2dd7de36ac3d..3abfdb725de4df46c1d78e53ad794de773f9aab9 100644 --- a/profiler/advisor/advisor_backend/compute_advice/npu_fused_advice.py +++ b/profiler/advisor/advisor_backend/compute_advice/npu_fused_advice.py @@ -14,6 +14,7 @@ # limitations under the License. import os +import logging from abc import ABC import pandas as pd @@ -22,6 +23,8 @@ from compute_advice.compute_advice_base import ComputeAdviceBase from compute_advice.npu_fused.csv_analyzer import CSVAnalyzer from compute_advice.npu_fused.json_analyzer import JSONAnalyzer +logger=logging.getLogger() + class NpuFusedAdvice(ComputeAdviceBase, ABC): @@ -46,7 +49,7 @@ class NpuFusedAdvice(ComputeAdviceBase, ABC): all_pattern_data = all_pattern_data.sort_values(by='duration sum(us)', ascending=False) filter_data = all_pattern_data.get(all_pattern_data.get("duration sum(us)", 0) > 0) if not self.has_callstack(): - print("[Warning] No call stack info found, advice will be incomplete") + logger.warning("No call stack info found, advice will be incomplete") self.cur_data = filter_data else: json_analyzer = JSONAnalyzer(self.trace_view_path) diff --git a/profiler/advisor/advisor_backend/compute_advice/npu_slow_advice.py b/profiler/advisor/advisor_backend/compute_advice/npu_slow_advice.py index 48522cf55a4cfb3f89083c3ac69ec7b22b295195..fc271e035e97d8eda74a00b125c93f5b8e98dfee 100644 --- a/profiler/advisor/advisor_backend/compute_advice/npu_slow_advice.py +++ b/profiler/advisor/advisor_backend/compute_advice/npu_slow_advice.py @@ -15,6 +15,7 @@ from abc import ABC import os import multiprocessing +import logging import pandas as pd @@ -64,7 +65,7 @@ class NpuSlowAdvice(ComputeAdviceBase, ABC): def get_call_stack(self, data: pd.DataFrame, index_id: int, ts_col: str) -> str: if not self.has_callstack(): - print("There is no call stack info, please set 'with_stack=True'") + logging.warning("There is no call stack info, please set 'with_stack=True'") return "" trace_json = TraceViewJson(self.trace_view_path) return trace_json.get_call_stack(data, index_id, ts_col) diff --git a/profiler/advisor/advisor_backend/overall_advice/overall_summary_advice.py b/profiler/advisor/advisor_backend/overall_advice/overall_summary_advice.py index effa9099e2bffbd3e36858218b6271ba3fab851e..3cc3b1a1ca39fdb369017431057253cafebd5b6f 100644 --- a/profiler/advisor/advisor_backend/overall_advice/overall_summary_advice.py +++ b/profiler/advisor/advisor_backend/overall_advice/overall_summary_advice.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import os +import logging from advisor_backend.advice_base import AdviceBase @@ -23,6 +24,8 @@ from compare_interface.comparison_interface import ComparisonInterface from profiler.prof_common.additional_args_manager import AdditionalArgsManager +logger=logging.getLogger() + class OverallSummaryAdvice(AdviceBase): @@ -56,7 +59,7 @@ class OverallSummaryAdvice(AdviceBase): try: duration = float(split_data[0]) except ValueError: - print(f"[WARNING] Invalid time value: {time_value}.") + logger.warning(f"Invalid time value: {time_value}.") return duration, num @staticmethod @@ -77,7 +80,7 @@ class OverallSummaryAdvice(AdviceBase): if os.path.exists(self.base_collection_path): self._has_base_collection = True else: - print(f"[WARNING] Invalid path which not exists: {self.base_collection_path}.") + logger.warning(f"Invalid path which not exists: {self.base_collection_path}.") return os.path.exists(self.collection_path) def process(self):