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

Analysis report block based filtering for profiling #566

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
45 changes: 39 additions & 6 deletions src/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import os
import shutil
from pathlib import Path
import re


def print_avail_arch(avail_arch: list):
Expand Down Expand Up @@ -114,7 +115,6 @@ def omniarg_parser(
type=str,
metavar="",
dest="name",
required=True,
help="\t\t\tAssign a name to workload.",
)
profile_group.add_argument("--target", type=str, default=None, help=argparse.SUPPRESS)
Expand Down Expand Up @@ -176,16 +176,49 @@ def omniarg_parser(
required=False,
help="\t\t\tDispatch ID filtering.",
)
def validate_block(value):
# Metric id regex, for example, 10, 4, 4.3
metric_id_pattern = re.compile(r'^\d+$|^\d+\.\d+$')
hardware_block_pattern = re.compile(r'^(SQ|SQC|TA|TD|TCP|TCC|SPI|CPC|CPF)$')
if metric_id_pattern.match(value):
return (str(value), "metric_id")
if hardware_block_pattern.match(value):
return (str(value), "hardware_block")
raise argparse.ArgumentTypeError(f"Invalid hardware block or metric id: {value}")
profile_group.add_argument(
"-b",
"--block",
type=str,
dest="ipblocks",
type=validate_block,
dest="filter_blocks",
metavar="",
nargs="+",
required=False,
choices=["SQ", "SQC", "TA", "TD", "TCP", "TCC", "SPI", "CPC", "CPF"],
help="\t\t\tHardware block filtering:\n\t\t\t SQ\n\t\t\t SQC\n\t\t\t TA\n\t\t\t TD\n\t\t\t TCP\n\t\t\t TCC\n\t\t\t SPI\n\t\t\t CPC\n\t\t\t CPF",
default=[],
help="""\t\t\tSpecify metric id(s) from --list-metrics for filtering (e.g. 10, 4, 4.3).
\t\t\tCan provide multiple space separated arguments. Can also accept Hardware blocks.
\t\t\tHardware block filtering (will be deprecated in next release):
\t\t\t SQ
\t\t\t SQC
\t\t\t TA
\t\t\t TD
\t\t\t TCP
\t\t\t TCC
\t\t\t SPI
\t\t\t CPC
\t\t\t CPF""",)
profile_group.add_argument(
"--list-metrics",
metavar="",
nargs="?",
const="",
help=print_avail_arch(supported_archs.keys()),
)
profile_group.add_argument(
"--config-dir",
dest="config_dir",
metavar="",
help="\t\tSpecify the directory of customized report section configs.",
default=rocprof_compute_home.joinpath("rocprof_compute_soc/analysis_configs/"),
)

result = shutil.which("rocscope")
Expand Down Expand Up @@ -486,7 +519,7 @@ def omniarg_parser(
dest="filter_metrics",
metavar="",
nargs="+",
help="\t\tSpecify hardware block/metric id(s) from --list-metrics for filtering.",
help="\t\tSpecify metric id(s) from --list-metrics for filtering.",
)
analyze_group.add_argument(
"--gpu-id",
Expand Down
4 changes: 4 additions & 0 deletions src/rocprof_compute_analyze/analysis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, args, supported_archs):
self.__args = args
self._runs = OrderedDict()
self._arch_configs = {}
self._profiling_config = dict()
self.__supported_archs = supported_archs
self._output = None
self.__socs: dict = None # available OmniSoC objs
Expand Down Expand Up @@ -254,6 +255,9 @@ def pre_processing(self):
open(self.__args.output_file, "w+") if self.__args.output_file else sys.stdout
)

# Read profiling config
self._profiling_config = file_io.load_profiling_config(self.__args.path[0][0])

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

Expand Down
1 change: 1 addition & 0 deletions src/rocprof_compute_analyze/analysis_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ def run_analysis(self):
self._runs[self.get_args().path[0][0]].sys_info.iloc[0]["gpu_arch"]
],
self._output,
self._profiling_config,
)
14 changes: 10 additions & 4 deletions src/rocprof_compute_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from pathlib import Path

import pandas as pd
import yaml

import config
from argparser import omniarg_parser
Expand Down Expand Up @@ -250,25 +251,25 @@ def run_profiler(self):
from rocprof_compute_profile.profiler_rocprof_v1 import rocprof_v1_profiler

profiler = rocprof_v1_profiler(
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch]
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch], self.__supported_archs
)
elif self.__profiler_mode == "rocprofv2":
from rocprof_compute_profile.profiler_rocprof_v2 import rocprof_v2_profiler

profiler = rocprof_v2_profiler(
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch]
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch], self.__supported_archs
)
elif self.__profiler_mode == "rocprofv3":
from rocprof_compute_profile.profiler_rocprof_v3 import rocprof_v3_profiler

profiler = rocprof_v3_profiler(
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch]
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch], self.__supported_archs
)
elif self.__profiler_mode == "rocscope":
from rocprof_compute_profile.profiler_rocscope import rocscope_profiler

profiler = rocscope_profiler(
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch]
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch], self.__supported_archs
)
else:
console_error("Unsupported profiler")
Expand All @@ -278,6 +279,11 @@ def run_profiler(self):
# -----------------------

self.__soc[self.__mspec.gpu_arch].profiling_setup()
# Write profiling configuration as yaml file
with open(Path(self.__args.path).joinpath("profiling_config.yaml"), "w") as f:
args_dict = vars(self.__args)
args_dict["config_dir"] = str(args_dict["config_dir"])
yaml.dump(args_dict, f)
# enable file-based logging
setup_file_handler(self.__args.loglevel, self.__args.path)

Expand Down
46 changes: 42 additions & 4 deletions src/rocprof_compute_profile/profiler_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from tqdm import tqdm

import config
from utils import file_io, parser, schema
from utils.utils import (
capture_subprocess_output,
console_debug,
Expand All @@ -51,15 +52,18 @@


class RocProfCompute_Base:
def __init__(self, args, profiler_mode, soc):
def __init__(self, args, profiler_mode, soc, supported_archs):
self.__args = args
self.__profiler = profiler_mode
self.__supported_archs = supported_archs
self._soc = soc # OmniSoC obj
self.__perfmon_dir = str(
Path(str(config.rocprof_compute_home)).joinpath(
"rocprof_compute_soc", "profile_configs"
)
)
self.__filter_hardware_blocks = [block[0] for block in args.filter_blocks if block[1] == "hardware_block"]
self.__filter_metric_ids = [block[0] for block in args.filter_blocks if block[1] == "metric_id"]

def get_args(self):
return self.__args
Expand Down Expand Up @@ -260,6 +264,27 @@ def join_prof(self, out=None):
else:
return df

@demarcate
def list_metrics(self):
args = self.__args
if args.list_metrics in self.__supported_archs.keys():
ac = schema.ArchConfig()
ac.panel_configs = file_io.top_stats_build_in_config
sys_info = self._soc._mspec.get_class_members().iloc[0],
parser.build_dfs(archConfigs=ac, filter_metrics=[], sys_info=sys_info)
for key, value in ac[args.list_metrics].metric_list.items():
prefix = ""
if "." not in str(key):
prefix = ""
elif str(key).count(".") == 1:
prefix = "\t"
else:
prefix = "\t\t"
print(prefix + key, "->", value)
sys.exit(0)
else:
console_error("Unsupported arch")

# ----------------------------------------------------
# Required methods to be implemented by child classes
# ----------------------------------------------------
Expand All @@ -268,6 +293,15 @@ def pre_processing(self):
"""Perform any pre-processing steps prior to profiling."""
console_debug("profiling", "pre-processing using %s profiler" % self.__profiler)

if self.__args.list_metrics is not None:
if not self.__args.list_metrics:
arch = self._soc.__arch
else:
arch = self.__args.list_metrics
self.list_metrics(arch)
elif self.__args.name is None:
sys.exit("Either --list-name or --name is required")

# verify soc compatibility
if self.__profiler not in self._soc.get_compatible_profilers():
console_error(
Expand Down Expand Up @@ -320,10 +354,14 @@ def run_profiling(self, version: str, prog: str):
console_log("Command: " + str(self.__args.remaining))
console_log("Kernel Selection: " + str(self.__args.kernel))
console_log("Dispatch Selection: " + str(self.__args.dispatch))
if self.__args.ipblocks == None:
if self.__filter_hardware_blocks == None:
console_log("Hardware Blocks: All")
else:
console_log("Hardware Blocks: " + str(self.__args.ipblocks))
console_log("Hardware Blocks: " + str(self.__filter_hardware_blocks))
if self.__filter_metric_ids == None:
console_log("Report Sections: All")
else:
console_log("Report Sections: " + str(self.__filter_metric_ids))

msg = "Collecting Performance Counters"
(
Expand Down Expand Up @@ -424,7 +462,7 @@ def post_processing(self):
gen_sysinfo(
workload_name=self.__args.name,
workload_dir=self.get_args().path,
ip_blocks=self.__args.ipblocks,
ip_blocks=[block[0] for block in self.__args.filter_blocks if block[1] == "hardware_block"],
app_cmd=self.__args.remaining,
skip_roof=self.__args.no_roof,
roof_only=self.__args.roof_only,
Expand Down
4 changes: 2 additions & 2 deletions src/rocprof_compute_profile/profiler_rocprof_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@


class rocprof_v1_profiler(RocProfCompute_Base):
def __init__(self, profiling_args, profiler_mode, soc):
super().__init__(profiling_args, profiler_mode, soc)
def __init__(self, profiling_args, profiler_mode, soc, supported_archs):
super().__init__(profiling_args, profiler_mode, soc, supported_archs)
self.ready_to_profile = (
self.get_args().roof_only
and not Path(self.get_args().path).joinpath("pmc_perf.csv").is_file()
Expand Down
4 changes: 2 additions & 2 deletions src/rocprof_compute_profile/profiler_rocprof_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@


class rocprof_v2_profiler(RocProfCompute_Base):
def __init__(self, profiling_args, profiler_mode, soc):
super().__init__(profiling_args, profiler_mode, soc)
def __init__(self, profiling_args, profiler_mode, soc, supported_archs):
super().__init__(profiling_args, profiler_mode, soc, supported_archs)
self.ready_to_profile = (
self.get_args().roof_only
and not Path(self.get_args().path).joinpath("pmc_perf.csv").is_file()
Expand Down
4 changes: 2 additions & 2 deletions src/rocprof_compute_profile/profiler_rocprof_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@


class rocprof_v3_profiler(RocProfCompute_Base):
def __init__(self, profiling_args, profiler_mode, soc):
super().__init__(profiling_args, profiler_mode, soc)
def __init__(self, profiling_args, profiler_mode, soc, supported_archs):
super().__init__(profiling_args, profiler_mode, soc, supported_archs)
self.ready_to_profile = (
self.get_args().roof_only
and not Path(self.get_args().path).joinpath("pmc_perf.csv").is_file()
Expand Down
4 changes: 2 additions & 2 deletions src/rocprof_compute_profile/profiler_rocscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@


class rocscope_profiler(RocProfCompute_Base):
def __init__(self, profiling_args, profiler_mode, soc):
super().__init__(profiling_args, profiler_mode, soc)
def __init__(self, profiling_args, profiler_mode, soc, supported_archs):
super().__init__(profiling_args, profiler_mode, soc, supported_archs)

# -----------------------
# Required child methods
Expand Down
Loading
Loading