Skip to content

Commit

Permalink
shortening now in analyze also
Browse files Browse the repository at this point in the history
-  add extraction level flag in profile
-  overwrite old csv with new demangled csv
-  demangling occurs in kernel_name_shortner

Signed-off-by: josantos <josantos@amd.com>
  • Loading branch information
JoseSantosAMD committed Aug 9, 2023
1 parent 2948f73 commit 8aad380
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/omniperf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/omniperf_analyze/omniperf_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
26 changes: 16 additions & 10 deletions src/utils/csv_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import argparse
import collections
import os
import subprocess
import sys
import re
import pandas as pd
Expand All @@ -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
Expand All @@ -55,22 +56,28 @@ 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 = ""

names_and_args = re.compile(r"(?P<name>[( )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<name>[( )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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8aad380

Please sign in to comment.