From 6852d2d6e80e1fe7b162cc0ee2cc7679e5c91976 Mon Sep 17 00:00:00 2001 From: Giovanni LB Date: Thu, 12 Oct 2023 18:32:08 -0300 Subject: [PATCH] SWDEV-427013: Fixing ATT parser for tensile kernels and network mode Change-Id: I07cd34f5606c0aaf718d9e3ffabd5a407523a943 [ROCm/rocprofiler commit: 60197d0f20b2a0a70f06da5c57c232745e717ec3] --- projects/rocprofiler/plugin/att/drawing.py | 21 +++++++-------- projects/rocprofiler/plugin/att/stitch.py | 31 +++++++++++++++------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/projects/rocprofiler/plugin/att/drawing.py b/projects/rocprofiler/plugin/att/drawing.py index 945ab30e50..db0d3a2aeb 100644 --- a/projects/rocprofiler/plugin/att/drawing.py +++ b/projects/rocprofiler/plugin/att/drawing.py @@ -210,7 +210,6 @@ def draw_occupancy_per_dispatch(selections, normalize, OCCUPANCY, dispatchnames) for k in range(len(OCCUPANCY)): if len(OCCUPANCY[k]) <= 16: continue - OCCUPANCY[k] = [(16*int(u>>23), (u>>12) & 0x7F, (u>>19) & 0xF, u&0xFFF) for u in OCCUPANCY[k]] maxtime = max(maxtime, OCCUPANCY[k][-1][0]) NUM_DOTS = 1600 @@ -265,17 +264,12 @@ def draw_occupancy_per_dispatch(selections, normalize, OCCUPANCY, dispatchnames) def draw_occupancy(selections, normalize, OCCUPANCY, shadernames, numdispatchid): plt.figure(figsize=(15, 4)) names = [] - if len(OCCUPANCY) == 1: # If single SE, do occupancy per CU/WGP - percu = [[u for u in OCCUPANCY[0] if (u>>19) & 0xF == k] for k in range(16)] - shadernames = shadernames + [['CU'+str(k),''] for k in range(16) if len(percu[k]) > 0] - OCCUPANCY = OCCUPANCY + [occ for occ in percu if len(occ) > 0] + g_maxtime = 1 + g_delta = 1 for name, occ in zip(shadernames, OCCUPANCY): if len(occ) <= 16: continue - maxtime = 1 - delta = 1 - occ = [(16*int(u >> 23), (u >> 12) & 0x7F, (u>>19) & 0xF, u&0xFFF) for u in occ] current_occ = [[0 for m in range(16)] for k in range(numdispatchid)] current_occ[0] = [m[1] for m in occ[:16]] @@ -294,6 +288,8 @@ def draw_occupancy(selections, normalize, OCCUPANCY, shadernames, numdispatchid) NUM_DOTS = 1500 maxtime = occ_times[-1]+1 delta = max(1, maxtime // NUM_DOTS) + g_maxtime = max(g_maxtime, maxtime) + g_delta = max(g_delta, delta) chart = np.zeros((maxtime // delta + 1), dtype=np.float32) norm_fact = np.zeros_like(chart) norm_fact += 1E-6 @@ -317,7 +313,7 @@ def draw_occupancy(selections, normalize, OCCUPANCY, shadernames, numdispatchid) plt.ylabel("Occupancy total") plt.xlabel("Cycle") plt.ylim(-1) - plt.xlim(-maxtime // 200, maxtime + maxtime // 200 + delta + 1) + plt.xlim(-g_maxtime // 200, g_maxtime + g_maxtime // 200 + g_delta + 1) plt.subplots_adjust(left=0.04, right=1, top=1, bottom=0.1) figure_bytes = BytesIO() plt.savefig(figure_bytes, dpi=150) @@ -330,11 +326,14 @@ def GeneratePIC(drawinfo, selections=[True for k in range(16)], normalize=False) response = {} figures = {} - states, figure = draw_occupancy(selections, normalize, drawinfo["OCCUPANCY"], drawinfo["ShaderNames"], len(drawinfo["DispatchNames"])) + OCCUPANCY = drawinfo["OCCUPANCY"] + OCCUPANCY = [[(16*int(u>>23), (u>>12) & 0x7F, (u>>19) & 0xF, u&0xFFF) for u in OCCUPANCY[k]] for k in range(len(OCCUPANCY))] + + states, figure = draw_occupancy(selections, normalize, OCCUPANCY, drawinfo["ShaderNames"], len(drawinfo["DispatchNames"])) response["occupancy.png"] = states figures["occupancy.png"] = figure - states, figure = draw_occupancy_per_dispatch(selections, normalize, drawinfo["OCCUPANCY"], drawinfo["DispatchNames"]) + states, figure = draw_occupancy_per_dispatch(selections, normalize, OCCUPANCY, drawinfo["DispatchNames"]) response["dispatches.png"] = states figures["dispatches.png"] = figure diff --git a/projects/rocprofiler/plugin/att/stitch.py b/projects/rocprofiler/plugin/att/stitch.py index 74efe39a26..698d9fcb7a 100644 --- a/projects/rocprofiler/plugin/att/stitch.py +++ b/projects/rocprofiler/plugin/att/stitch.py @@ -56,7 +56,7 @@ WaveInstCategory = { class RegisterWatchList: def __init__(self, labels): self.registers = {"v" + str(k): [[] for m in range(64)] for k in range(64)} - for k in range(64): + for k in range(128): self.registers["s" + str(k)] = [] self.labels = labels @@ -83,9 +83,23 @@ class RegisterWatchList: # print('Get pc:', line) try: dst = line.split(" ")[1].strip() - label_dest = next_line.split(", ")[-1].split("@")[0] - for reg in self.range(dst): - self.registers[reg].append(deepcopy(self.labels[label_dest])) + label_dests = [] + try: + label_dests = next_line.split(", ") + except: + pass + try: + label_dests.append(next_line.split(", ")[-1].split("@")[0]) + except: + pass + + for label_dst in label_dests: + try: + cur_label = self.labels[label_dst] + for reg in self.range(dst): + self.registers[reg].append(deepcopy(cur_label)) + except: + pass except: pass @@ -219,17 +233,16 @@ def stitch(insts, raw_code, jumps, gfxv, bIsAuto): for c in raw_code[1:]: c = list(c) c[0] = c[0].split(";")[0].split("//")[0].strip() + jump_map.append(len(code)) if c[1] != 100: code.append(c) elif ":" in c[0]: labels[c[0].split(":")[0]] = len(code) - jump_map.append(len(code) - 1) - reverse_map = [] + reverse_map = {} for k, v in enumerate(jump_map): - if v >= len(reverse_map): - reverse_map.append(k) + reverse_map[v] = k jumps = {jump_map[j] + 1: j for j in jumps} @@ -260,7 +273,7 @@ def stitch(insts, raw_code, jumps, gfxv, bIsAuto): i += 1 continue - #print(line, i, WaveInstCategory[insts[i].type], insts[i].num_waves, insts[i].cycles) + #print(line, i, WaveInstCategory[insts[i].type], insts[i].num_waves, insts[i].cycles, code[line]) loops += 1 if line >= len(code) or loops > MAX_STITCHED_TOKENS \