Skip to content

Commit

Permalink
fix ascend profiler timeline precision issue (#940)
Browse files Browse the repository at this point in the history
* fix float precision issue

* del unnecessary decimal for speed consideration

* fix function return value's type annotation
  • Loading branch information
DoorKickers authored Sep 9, 2024
1 parent e3e151b commit 7ba97bd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions dipu/torch_dipu/profiler/ascend/ascend_profiler_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import subprocess
from typing import Union
from decimal import Decimal


class _PathManager:
Expand Down Expand Up @@ -191,7 +192,7 @@ def filter_event_condition(event: dict) -> bool:
self._msprof_profile_data.append(event)
if event["ph"] == "X" and event["pid"] == self._process_id["CANN"]:
self._msprof_cann_x_event.append(
(float(event["ts"]), float(event["ts"]) + float(event["dur"]))
(Decimal(event["ts"]), Decimal(event["ts"]) + Decimal(event["dur"]))
)

def _merge_msprof_profile_data(self, input_msprof_data: list) -> None:
Expand All @@ -213,7 +214,7 @@ def _adjust_HostToDevice_event_offset(self) -> None:
# msprof_cann_x_event is sorted by timestamp beforehand,
# and what we need to do is binary search for the event whose time interval contain this timestamp
# and move start flow event HostToDevice's timestamp to the cann event's begin timestamp
def find_wrap_acl_event(ts: float) -> float:
def find_wrap_acl_event(ts: float) -> Union[float, Decimal]:
if len(self._msprof_cann_x_event) == 0:
return ts
l = 0
Expand Down Expand Up @@ -270,15 +271,15 @@ def find_wrap_acl_event(ts: float) -> float:

def _merge_msprof_to_kineto(self) -> None:
# to make sure cann timestamp align to kineto timestamp
local_time_diff = (self._torch_time_diff - self._acl_time_diff) / 1000
local_time_diff = Decimal((self._torch_time_diff - self._acl_time_diff) / 1000)

for event in self._msprof_profile_data:
if event["pid"] == self._process_id["CANN"]:
event["pid"] = self._process_id["python3"]
if event["name"] == "process_sort_index":
event["args"]["sort_index"] += self._python3_sort_idx
if "ts" in event.keys():
event["ts"] = str(float(event["ts"]) + local_time_diff)
event["ts"] = str(Decimal(event["ts"]) + local_time_diff)
self._kineto_profile_data["traceEvents"].append(event)

def _export_to_json(self) -> None:
Expand Down

0 comments on commit 7ba97bd

Please sign in to comment.