From 8aad3803a759a2df84b25e01ae73f2b517c94769 Mon Sep 17 00:00:00 2001 From: josantos Date: Wed, 9 Aug 2023 15:40:10 -0500 Subject: [PATCH] shortening now in analyze also - add extraction level flag in profile - overwrite old csv with new demangled csv - demangling occurs in kernel_name_shortner Signed-off-by: josantos --- src/omniperf | 2 +- src/omniperf_analyze/omniperf_analyze.py | 11 ++++++++++ src/parser.py | 9 ++++++++ src/utils/csv_converter.py | 26 +++++++++++++++--------- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/omniperf b/src/omniperf index acdfbc3bf..41856244c 100755 --- a/src/omniperf +++ b/src/omniperf @@ -739,7 +739,7 @@ def main(): # PROFILE MODE ############## if args.mode == "profile": - Extractionlvl = 3 #args.extraction_level + Extractionlvl = args.kernelVerbose print("Resolving rocprof") resolve_rocprof() # Cannot access parent directories diff --git a/src/omniperf_analyze/omniperf_analyze.py b/src/omniperf_analyze/omniperf_analyze.py index 87fac064d..53f404492 100644 --- a/src/omniperf_analyze/omniperf_analyze.py +++ b/src/omniperf_analyze/omniperf_analyze.py @@ -45,6 +45,8 @@ from pathlib import Path from omniperf_analyze.utils import parser, file_io from omniperf_analyze.utils.gui_components.roofline import get_roofline +from utils import csv_converter +import pandas as pd archConfigs = {} @@ -220,7 +222,16 @@ def run_cli(args, runs): # If we assume the panel layout for all archs are similar, it doesn't matter # which archConfig passed into show_all function. # After decide to how to manage kernels display patterns, we can revisit it. + cache =dict() for d in args.path: + #demangle + for filename in os.listdir(d[0]): + if filename.endswith('.csv'): + df = pd.read_csv(os.path.join(d[0],filename)) + new_df = csv_converter.kernel_name_shortener(df, cache, args.kernelVerbose) + # new_filename = filename[:filename.rfind(".")]+"_new.csv" + new_df.to_csv(os.path.join(d[0],filename)) + file_io.create_df_kernel_top_stats( d[0], runs[d[0]].filter_gpu_ids, diff --git a/src/parser.py b/src/parser.py index 9d6dd8f6f..dcb9be0c3 100644 --- a/src/parser.py +++ b/src/parser.py @@ -514,3 +514,12 @@ def parse(my_parser): action="store_true", help="\t\tRandomly generate a port to launch GUI application.\n\t\tRegistered Ports range inclusive (1024-49151).", ) + analyze_group.add_argument( + "-f", + "--kernelVerbose", + required=False, + metavar="", + help="\t\t\t\tSpecify Kernel Name verbose level 1-5. Lower the level, shorter the kernel name. (DEFAULT: 2) (DISABLE: 5)", + default=2, + type=int, + ) diff --git a/src/utils/csv_converter.py b/src/utils/csv_converter.py index 34f2e8261..35bc5a649 100644 --- a/src/utils/csv_converter.py +++ b/src/utils/csv_converter.py @@ -25,6 +25,7 @@ import argparse import collections import os +import subprocess import sys import re import pandas as pd @@ -33,11 +34,11 @@ from tqdm import tqdm import shutil + cache = dict() supported_arch = {"gfx906": "mi50", "gfx908": "mi100", "gfx90a": "mi200"} MAX_SERVER_SEL_DELAY = 5000 # 5 sec connection timeout - def kernel_name_shortener(df, cache, level): if level >= 5: return df @@ -55,6 +56,13 @@ def kernel_name_shortener(df, cache, level): if original_name in cache: continue + cmd = ["llvm-cxxfilt", original_name] + + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + demangled_name, e = proc.communicate() + demangled_name = str(demangled_name, "UTF-8").strip() + # cache miss, add the shortened name to the dictionary new_name = "" matches = "" @@ -62,15 +70,14 @@ def kernel_name_shortener(df, cache, level): names_and_args = re.compile(r"(?P[( )A-Za-z0-9_]+)([ ,*<>()]+)(::)?") # works for name Kokkos::namespace::init_lock_array_kernel_threadid(int) [clone .kd] - if names_and_args.search(original_name): - matches = names_and_args.findall(original_name) + if names_and_args.search(demangled_name): + matches = names_and_args.findall(demangled_name) else: # Works for first case '__amd_rocclr_fillBuffer.kd' - # remove .kd and then parse through original regex - first_case = re.compile(r"([^\s]+)(.kd)") - Mod_name_and_args = re.compile(r"(?P[( )A-Za-z0-9_]+)([ ,*<>()]*)") - interim_name = first_case.search(original_name).group(1) - matches = Mod_name_and_args.findall(interim_name) + cache[original_name] = new_name + if new_name == None or new_name == "": + cache[original_name] = demangled_name + continue current_level = 0 for name in matches: @@ -103,13 +110,12 @@ def kernel_name_shortener(df, cache, level): cache[original_name] = new_name if new_name == None or new_name == "": - cache[original_name] = original_name + cache[original_name] = demangled_name df[columnName] = df[columnName].map(cache) return df - # Verify target directory and setup connection def parse(args, profileAndExport): host = args.host