Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor edits to meet formatting requirements #259

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions src/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import shutil
import os


def print_avail_arch(avail_arch: list):
ret_str = "\t\tList all available metrics for analysis on specified arch:"
for arch in avail_arch:
ret_str += "\n\t\t {}".format(arch)
return ret_str


def omniarg_parser(parser, omniperf_home, supported_archs, omniperf_version):
# -----------------------------------------
# Parse arguments (dependent on mode)
Expand All @@ -42,8 +44,12 @@ def omniarg_parser(parser, omniperf_home, supported_archs, omniperf_version):
general_group = parser.add_argument_group("General Options")
parser._positionals.title = "Modes"
parser._optionals.title = "Help"
general_group.add_argument("-v", "--version", action="version", version=omniperf_version["ver_pretty"])
general_group.add_argument("-s", "--specs", action="store_true", help="Print system specs.")
general_group.add_argument(
"-v", "--version", action="version", version=omniperf_version["ver_pretty"]
)
general_group.add_argument(
"-s", "--specs", action="store_true", help="Print system specs."
)

subparsers = parser.add_subparsers(
dest="mode", help="Select mode of interaction with the target application:"
Expand Down Expand Up @@ -78,7 +84,9 @@ def omniarg_parser(parser, omniperf_home, supported_archs, omniperf_version):
profile_group = profile_parser.add_argument_group("Profile Options")
roofline_group = profile_parser.add_argument_group("Standalone Roofline Options")

general_group.add_argument("-v", "--version", action="version", version=omniperf_version["ver_pretty"])
general_group.add_argument(
"-v", "--version", action="version", version=omniperf_version["ver_pretty"]
)
general_group.add_argument(
"-V", "--verbose", help="Increase output verbosity", action="count", default=0
)
Expand Down Expand Up @@ -283,11 +291,15 @@ def omniarg_parser(parser, omniperf_home, supported_archs, omniperf_version):
interaction_group = db_parser.add_argument_group("Interaction Type")
connection_group = db_parser.add_argument_group("Connection Options")

general_group.add_argument("-v", "--version", action="version", version=omniperf_version["ver_pretty"])
general_group.add_argument(
"-v", "--version", action="version", version=omniperf_version["ver_pretty"]
)
general_group.add_argument(
"-V", "--verbose", help="Increase output verbosity", action="count", default=0
)
general_group.add_argument("-s", "--specs", action="store_true", help="Print system specs.")
general_group.add_argument(
"-s", "--specs", action="store_true", help="Print system specs."
)

interaction_group.add_argument(
"-i",
Expand Down Expand Up @@ -374,11 +386,15 @@ def omniarg_parser(parser, omniperf_home, supported_archs, omniperf_version):
analyze_group = analyze_parser.add_argument_group("Analyze Options")
analyze_advanced_group = analyze_parser.add_argument_group("Advanced Options")

general_group.add_argument("-v", "--version", action="version", version=omniperf_version["ver_pretty"])
general_group.add_argument(
"-v", "--version", action="version", version=omniperf_version["ver_pretty"]
)
general_group.add_argument(
"-V", "--verbose", help="Increase output verbosity", action="count", default=0
)
general_group.add_argument("-s", "--specs", action="store_true", help="Print system specs.")
general_group.add_argument(
"-s", "--specs", action="store_true", help="Print system specs."
)

analyze_group.add_argument(
"-p",
Expand All @@ -398,7 +414,7 @@ def omniarg_parser(parser, omniperf_home, supported_archs, omniperf_version):
analyze_group.add_argument(
"--list-metrics",
metavar="",
choices=supported_archs.keys(),#["gfx906", "gfx908", "gfx90a"],
choices=supported_archs.keys(), # ["gfx906", "gfx908", "gfx90a"],
help=print_avail_arch(supported_archs.keys()),
)
analyze_group.add_argument(
Expand Down Expand Up @@ -460,7 +476,7 @@ def omniarg_parser(parser, omniperf_home, supported_archs, omniperf_version):
metavar="",
type=int,
default=10,
help="\t\tSpecify the maximum number of stats shown in \"Top Stats\" tables (DEFAULT: 10)",
help='\t\tSpecify the maximum number of stats shown in "Top Stats" tables (DEFAULT: 10)',
)
analyze_advanced_group.add_argument(
"-n",
Expand Down Expand Up @@ -508,7 +524,9 @@ def omniarg_parser(parser, omniperf_home, supported_archs, omniperf_version):
nargs="+",
help="\t\tSpecify column indices to display.",
)
analyze_advanced_group.add_argument("-g", dest="debug", action="store_true", help="\t\tDebug single metric.")
analyze_advanced_group.add_argument(
"-g", dest="debug", action="store_true", help="\t\tDebug single metric."
)
analyze_advanced_group.add_argument(
"--dependency", action="store_true", help="\t\tList the installation dependency."
)
Expand All @@ -527,5 +545,5 @@ def omniarg_parser(parser, omniperf_home, supported_archs, omniperf_version):
"--specs-correction",
type=str,
metavar="",
help="\t\tSpecify the specs to correct."
)
help="\t\tSpecify the specs to correct.",
)
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@

# NB: Creating a new module to share global vars across modules
omniperf_home = Path(__file__).resolve().parent
prog = "omniperf"
prog = "omniperf"
2 changes: 1 addition & 1 deletion src/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def install(package):
html_static_path = ["_static"]

latex_elements = {
"sphinxsetup": 'verbatimwrapslines=true, verbatimforcewraps=true',
"sphinxsetup": "verbatimwrapslines=true, verbatimforcewraps=true",
}


Expand Down
96 changes: 57 additions & 39 deletions src/omniperf_analyze/analysis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,31 @@
import pandas as pd
from tabulate import tabulate

class OmniAnalyze_Base():
def __init__(self,args,supported_archs):

class OmniAnalyze_Base:
def __init__(self, args, supported_archs):
self.__args = args
self._runs = OrderedDict()
self._arch_configs = {}
self._runs = OrderedDict()
self._arch_configs = {}
self.__supported_archs = supported_archs
self._output = None
self.__socs = None # available OmniSoC objs
self._output = None
self.__socs = None # available OmniSoC objs

def get_args(self):
return self.__args

def set_soc(self, omni_socs):
self.__socs = omni_socs

def get_socs(self):
return self.__socs

@demarcate
def generate_configs(self, arch, config_dir, list_stats, filter_metrics, sys_info):
single_panel_config = file_io.is_single_panel_config(Path(config_dir), self.__supported_archs)

single_panel_config = file_io.is_single_panel_config(
Path(config_dir), self.__supported_archs
)

ac = schema.ArchConfig()
if list_stats:
ac.panel_configs = file_io.top_stats_build_in_config
Expand All @@ -66,22 +71,26 @@ def generate_configs(self, arch, config_dir, list_stats, filter_metrics, sys_inf
# TODO: filter_metrics should/might be one per arch
# print(ac)

parser.build_dfs(
archConfigs=ac,
filter_metrics=filter_metrics,
sys_info=sys_info
)
parser.build_dfs(archConfigs=ac, filter_metrics=filter_metrics, sys_info=sys_info)
self._arch_configs[arch] = ac
return self._arch_configs

@demarcate
def list_metrics(self):
args = self.__args
if args.list_metrics in self.__supported_archs.keys():
arch = args.list_metrics
if arch not in self._arch_configs.keys():
sys_info = file_io.load_sys_info(Path(self.__args.path[0][0], "sysinfo.csv"))
self.generate_configs(arch, args.config_dir, args.list_stats, args.filter_metrics, sys_info.iloc[0])
sys_info = file_io.load_sys_info(
Path(self.__args.path[0][0], "sysinfo.csv")
)
self.generate_configs(
arch,
args.config_dir,
args.list_stats,
args.filter_metrics,
sys_info.iloc[0],
)

for key, value in self._arch_configs[args.list_metrics].metric_list.items():
prefix = ""
Expand All @@ -100,39 +109,51 @@ def list_metrics(self):
def load_options(self, normalization_filter):
if not normalization_filter:
for k, v in self._arch_configs.items():
parser.build_metric_value_string(v.dfs, v.dfs_type, self.__args.normal_unit)
parser.build_metric_value_string(
v.dfs, v.dfs_type, self.__args.normal_unit
)
else:
for k, v in self._arch_configs.items():
parser.build_metric_value_string(v.dfs, v.dfs_type, normalization_filter)

args = self.__args
# Error checking for multiple runs and multiple gpu_kernel filters
if args.gpu_kernel and (len(args.path) != len(args.gpu_kernel)):
if len(args.gpu_kernel) == 1:
for i in range(len(args.path) - 1):
args.gpu_kernel.extend(args.gpu_kernel)
else:
error("Error: the number of --filter-kernels doesn't match the number of --dir.")

error(
"Error: the number of --filter-kernels doesn't match the number of --dir."
)

@demarcate
def initalize_runs(self, normalization_filter=None):
if self.__args.list_metrics:
self.list_metrics()

# load required configs
for d in self.__args.path:
sys_info = file_io.load_sys_info(Path(d[0], "sysinfo.csv"))
arch = sys_info.iloc[0]["gpu_soc"]
args = self.__args
self.generate_configs(arch, args.config_dir, args.list_stats, args.filter_metrics, sys_info.iloc[0])
self.generate_configs(
arch,
args.config_dir,
args.list_stats,
args.filter_metrics,
sys_info.iloc[0],
)

self.load_options(normalization_filter)

for d in self.__args.path:
w = schema.Workload()
w.sys_info = file_io.load_sys_info(Path(d[0], "sysinfo.csv"))
if self.__args.specs_correction:
w.sys_info = parser.correct_sys_info(w.sys_info, self.__args.specs_correction)
w.sys_info = parser.correct_sys_info(
w.sys_info, self.__args.specs_correction
)
w.avail_ips = w.sys_info["ip_blocks"].item().split("|")
arch = w.sys_info.iloc[0]["gpu_soc"]
w.dfs = copy.deepcopy(self._arch_configs[arch].dfs)
Expand All @@ -142,11 +163,9 @@ def initalize_runs(self, normalization_filter=None):

return self._runs


@demarcate
def sanitize(self):
"""Perform sanitization of inputs
"""
"""Perform sanitization of inputs"""
if not self.__args.path:
error("The following arguments are required: -p/--path")
# verify not accessing parent directories
Expand All @@ -160,23 +179,23 @@ def sanitize(self):
error("Invalid directory {}\nPlease try again.".format(dir[0]))
# validate profiling data
is_workload_empty(dir[0])


#----------------------------------------------------

# ----------------------------------------------------
# Required methods to be implemented by child classes
#----------------------------------------------------
# ----------------------------------------------------
@abstractmethod
def pre_processing(self):
"""Perform initialization prior to analysis.
"""
"""Perform initialization prior to analysis."""
logging.debug("[analysis] prepping to do some analysis")
logging.info("[analysis] deriving Omniperf metrics...")
# initalize output file
self._output = open(self.__args.output_file, "w+") if self.__args.output_file else sys.stdout

self._output = (
open(self.__args.output_file, "w+") if self.__args.output_file else sys.stdout
)

# initalize runs
self._runs = self.initalize_runs()

# set filters
if self.__args.gpu_kernel:
for d, gk in zip(self.__args.path, self.__args.gpu_kernel):
Expand All @@ -196,6 +215,5 @@ def pre_processing(self):

@abstractmethod
def run_analysis(self):
"""Run analysis.
"""
"""Run analysis."""
logging.debug("[analysis] generating analysis")
35 changes: 18 additions & 17 deletions src/omniperf_analyze/analysis_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@
from utils import file_io, parser, tty
from utils.kernel_name_shortener import kernel_name_shortener

class cli_analysis(OmniAnalyze_Base):

#-----------------------
class cli_analysis(OmniAnalyze_Base):
# -----------------------
# Required child methods
#-----------------------
# -----------------------
@demarcate
def pre_processing(self):
"""Perform any pre-processing steps prior to analysis.
"""
"""Perform any pre-processing steps prior to analysis."""
super().pre_processing()
if self.get_args().random_port:
error("--gui flag is required to enable --random-port")
Expand All @@ -48,38 +47,40 @@ def pre_processing(self):
filter_gpu_ids=self._runs[d[0]].filter_gpu_ids,
filter_dispatch_ids=self._runs[d[0]].filter_dispatch_ids,
time_unit=self.get_args().time_unit,
max_stat_num=self.get_args().max_stat_num
max_stat_num=self.get_args().max_stat_num,
)
# create 'mega dataframe'
self._runs[d[0]].raw_pmc = file_io.create_df_pmc(
d[0], self.get_args().verbose
)
# create the loaded table
parser.load_table_data(
workload=self._runs[d[0]],
dir=d[0],
workload=self._runs[d[0]],
dir=d[0],
is_gui=False,
debug=self.get_args().debug,
verbose=self.get_args().verbose
debug=self.get_args().debug,
verbose=self.get_args().verbose,
)


@demarcate
def run_analysis(self):
"""Run CLI analysis.
"""
"""Run CLI analysis."""
super().run_analysis()
if self.get_args().list_stats:
tty.show_kernel_stats(
self.get_args(),
self._runs,
self._arch_configs[self._runs[self.get_args().path[0][0]].sys_info.iloc[0]["gpu_soc"]],
self._output
self._arch_configs[
self._runs[self.get_args().path[0][0]].sys_info.iloc[0]["gpu_soc"]
],
self._output,
)
else:
tty.show_all(
self.get_args(),
self._runs,
self._arch_configs[self._runs[self.get_args().path[0][0]].sys_info.iloc[0]["gpu_soc"]],
self._output
self._arch_configs[
self._runs[self.get_args().path[0][0]].sys_info.iloc[0]["gpu_soc"]
],
self._output,
)
Loading
Loading