Skip to content

Commit

Permalink
#14961: Ops post processor does not check device FW start and end ali…
Browse files Browse the repository at this point in the history
…gnment for each op
  • Loading branch information
mo-tenstorrent committed Nov 12, 2024
1 parent 16123a1 commit d62b3ca
Showing 1 changed file with 35 additions and 55 deletions.
90 changes: 35 additions & 55 deletions tt_metal/tools/profiler/process_device_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,46 +297,6 @@ def sort_timeseries_and_find_min(devicesData):
return devicesData, doOpsDetection


def is_new_op_core(tsRisc):
timerID, tsValue, statData, risc = tsRisc
if risc == "BRISC" and timerID["zone_name"] == "BRISC-FW" and timerID["zone_phase"] == "begin":
return True
if risc == "ERISC" and timerID["zone_name"] == "ERISC-FW" and timerID["zone_phase"] == "begin":
return True
return False


def is_new_op_device(tsCore, coreOpMap):
timerID, tsValue, statData, risc, core = tsCore
appendTs = False
isNewOp = False
isNewOpFinished = False
if timerID["id"] != 0:
appendTs = True
if (risc == "BRISC" and timerID["zone_name"] == "BRISC-FW" and timerID["zone_phase"] == "begin") or (
risc == "ERISC" and timerID["zone_name"] == "ERISC-FW" and timerID["zone_phase"] == "begin"
):
assert (
core not in coreOpMap.keys()
), f"Unexpected BRISC start in {tsCore} {coreOpMap[core]}, this could be caused by soft resets"
if not coreOpMap:
isNewOp = True
coreOpMap[core] = (tsValue,)
elif (risc == "BRISC" and timerID["zone_name"] == "BRISC-FW" and timerID["zone_phase"] == "end") or (
risc == "ERISC" and timerID["zone_name"] == "ERISC-FW" and timerID["zone_phase"] == "end"
):
assert core in coreOpMap.keys() and len(coreOpMap[core]) == 1, "Unexpected BRISC end"
coreOpMap[core] = (coreOpMap[core][0], tsValue)
isNewOpFinished = True
for opDuration in coreOpMap.values():
pairSize = len(opDuration)
assert pairSize == 1 or pairSize == 2, "Wrong op duration"
if pairSize == 1:
isNewOpFinished = False
break
return appendTs, isNewOp, isNewOpFinished


def risc_to_core_timeseries(devicesData, detectOps):
for chipID, deviceData in devicesData["devices"].items():
for core, coreData in deviceData["cores"].items():
Expand All @@ -348,15 +308,27 @@ def risc_to_core_timeseries(devicesData, detectOps):

tmpTimeseries.sort(key=lambda x: x[1])

ops = []
opsDict = {}
if detectOps:
for ts in tmpTimeseries:
timerID, tsValue, statData, risc = ts
if is_new_op_core(ts):
ops.append({"timeseries": [ts]})
else:
if len(ops) > 0:
ops[-1]["timeseries"].append(ts)
if "run_host_id" in timerID:
opID = timerID["run_host_id"]
if opID not in opsDict:
opsDict[opID] = [ts]
else:
opsDict[opID].append(ts)

ordered_ops = list(opsDict.keys())
ordered_ops.sort(key=lambda x: opsDict[x][0][1])

ops = []

for opID in ordered_ops:
op = opsDict[opID]
ops.append({"timeseries": []})
for ts in op:
ops[-1]["timeseries"].append(ts)

coreData["riscs"]["TENSIX"] = {"timeseries": tmpTimeseries, "ops": ops}

Expand All @@ -382,16 +354,24 @@ def core_to_device_timeseries(devicesData, detectOps):

ops = []
if detectOps:
coreOpMap = {}
opsDict = {}
for ts in tmpTimeseries["riscs"]["TENSIX"]["timeseries"]:
appendTs, isNewOp, isNewOpFinished = is_new_op_device(ts, coreOpMap)
if appendTs:
if isNewOp:
ops.append({"timeseries": []})
if len(ops) > 0:
ops[-1]["timeseries"].append(ts)
if isNewOpFinished:
coreOpMap = {}
timerID, tsValue, statData, risc, core = ts
if "run_host_id" in timerID:
opID = timerID["run_host_id"]
if opID not in opsDict:
opsDict[opID] = [ts]
else:
opsDict[opID].append(ts)

ordered_ops = list(opsDict.keys())
ordered_ops.sort(key=lambda x: opsDict[x][0][1])

for opID in ordered_ops:
op = opsDict[opID]
ops.append({"timeseries": []})
for ts in op:
ops[-1]["timeseries"].append(ts)

tmpTimeseries["riscs"]["TENSIX"]["ops"] = ops
deviceData["cores"]["DEVICE"] = tmpTimeseries
Expand Down

0 comments on commit d62b3ca

Please sign in to comment.