[rocprof-compute] Update Formatting (#671)

* updated rocprof-compute formatting

* fixed ammolite peak variables in parser.py

* format parser.py

* update formatting rocprof_compute_base
This commit is contained in:
jamessiddeley-amd
2025-08-22 12:22:17 -04:00
committed by GitHub
parent e9e98daf24
commit 5deeea71df
13 changed files with 112 additions and 70 deletions
@@ -74,7 +74,8 @@ def load_panel_configs(dirs):
if f.endswith(".yaml"):
with open(Path(root) / f) as file:
config_yml = yaml.safe_load(file)
# metric key can be None due to some metric tables not having any metrics
# metric key can be None due to some metric-
# tables not having any metrics
# metric key should be empty dict instead of None
for data_source in config_yml["Panel Config"]["data source"]:
metric_table = data_source.get("metric_table")
@@ -160,9 +161,9 @@ def create_df_kernel_top_stats(
axis=1,
)
grouped = time_stats.groupby(by=["Kernel_Name"]).agg(
{"ExeTime": ["count", "sum", "mean", "median"]}
)
grouped = time_stats.groupby(by=["Kernel_Name"]).agg({
"ExeTime": ["count", "sum", "mean", "median"]
})
time_unit_str = "(" + time_unit + ")"
grouped.columns = [
@@ -996,7 +996,8 @@ def eval_metric(dfs, dfs_type, sys_info, empirical_peaks_df, raw_pmc_df, debug,
except TypeError:
console_warning(
"Skipping entry. Encountered a missing "
"counter\n{} has been assigned to None\n{}".format(
"counter\n"
"{} has been assigned to None\n{}".format(
expr,
np.nan,
)
@@ -1024,11 +1025,10 @@ def eval_metric(dfs, dfs_type, sys_info, empirical_peaks_df, raw_pmc_df, debug,
except (TypeError, NameError) as e:
if "empirical_peak" in str(e):
console_warning(
f"Missing empirical peak data: {e}. Using empty value."
f"Missing empirical peak data: {e}. "
"Using empty value."
)
row[expr] = ""
else:
row[expr] = ""
row[expr] = ""
except AttributeError as ae:
if (
str(ae)
@@ -1086,7 +1086,8 @@ def apply_filters(workload, dir, is_gui, debug):
for kernel_id in workload.filter_kernel_ids:
if kernel_id >= len(kernels_df["Kernel_Name"]):
console_error(
"{} is an invalid kernel id. Please enter an id between 0-{}".format(
"{} is an invalid kernel id. "
"Please enter an id between 0-{}".format(
kernel_id,
len(kernels_df["Kernel_Name"]) - 1,
)
@@ -30,7 +30,7 @@ from pathlib import Path
import pandas as pd
from utils.logger import console_debug
from utils.logger import console_debug, console_warning
from utils.parser import apply_filters, eval_metric
################################################
@@ -158,7 +158,8 @@ def get_color(catagory):
# Plot BW at each cache level
# -------------------------------------------------------------------------------------
def calc_ceilings(roofline_parameters, dtype, benchmark_data):
"""Given benchmarking data, calculate ceilings (or peak performance) for empirical roofline"""
"""Given benchmarking data, calculate ceilings (or peak performance) for
empirical roofline"""
# TODO: This is where filtering by memory level will need to occur for standalone
graphPoints = {"hbm": [], "l2": [], "l1": [], "lds": [], "valu": [], "mfma": []}
@@ -189,7 +190,7 @@ def calc_ceilings(roofline_parameters, dtype, benchmark_data):
if dtype in PEAK_OPS_DATATYPES:
x2 = peakOps / peakBw
y2 = peakOps
y2 = peakOps # noqa
# Plot MFMA lines (NOTE: Assuming MI200 soc)
x1_mfma = peakOps / peakBw
@@ -223,9 +224,9 @@ def calc_ceilings(roofline_parameters, dtype, benchmark_data):
graphPoints[cacheHierarchy[i].lower()].append([y1, peakY])
graphPoints[cacheHierarchy[i].lower()].append(peakBw)
# -------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------
# Plot computing roof
# -------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------
if dtype in PEAK_OPS_DATATYPES:
# Plot FMA roof
x0 = XMAX
@@ -356,7 +357,11 @@ def calc_ai_analyze(workload, mspec, sort_type, config, arch_config):
console_debug(
"roofline",
f"Kernel {kernel_id}: AI_HBM={ai_hbm:.2f}, AI_L2={ai_l2:.2f}, AI_L1={ai_l1:.2f}, Performance={performance:.2e} GFLOP/s",
f"Kernel {kernel_id}: "
f"AI_HBM={ai_hbm:.2f}, "
f"AI_L2={ai_l2:.2f}, "
f"AI_L1={ai_l1:.2f}, "
f"Performance={performance:.2e} GFLOP/s",
)
# add to plot points if we have valid data
@@ -393,11 +398,11 @@ def calc_ai_analyze(workload, mspec, sort_type, config, arch_config):
def calc_ai_profile(mspec, sort_type, ret_df):
"""Given counter data, calculate arithmetic intensity for each kernel in the application.
Leverage hard-coded equations to calculate AI values.
"""Given counter data, calculate arithmetic intensity for each kernel
in the application. Leverage hard-coded equations to calculate AI values.
Used during profiling stage to generate roofline PDF, since Roofline yamls are not available
in the profiling stage."""
Used during profiling stage to generate roofline PDF, since Roofline yamls
are not available in the profiling stage."""
console_debug(
"calc_ai_profile: Starting legacy roofline calculation (from roofline_calc)"
@@ -608,9 +613,7 @@ def calc_ai_profile(mspec, sort_type, ret_df):
calls += 1
if sort_type == "kernels" and (
at_end == True or (kernelName != next_kernelName)
):
if sort_type == "kernels" and (at_end or (kernelName != next_kernelName)):
myList.append(
AI_Data(
kernelName,
@@ -685,9 +688,8 @@ def calc_ai_profile(mspec, sort_type, ret_df):
while i < TOP_N and i != len(myList):
if myList[i].total_flops == 0:
console_debug(
"No flops counted for {}, arithmetic intensities will not display on plots.".format(
myList[i].KernelName
)
f"No flops counted for {myList[i].KernelName}, "
"arithmetic intensities will not display on plots."
)
kernelNames.append(myList[i].KernelName)
@@ -696,28 +698,28 @@ def calc_ai_profile(mspec, sort_type, ret_df):
if myList[i].L1cache_data
else intensities["ai_l1"].append(0)
)
# print("cur_ai_L1", myList[i].total_flops/myList[i].L1cache_data) if myList[i].L1cache_data else print("null")
# print("cur_ai_L1", myList[i].total_flops/myList[i].L1cache_data) if myList[i].L1cache_data else print("null") #noqa
# print()
(
intensities["ai_l2"].append(myList[i].total_flops / myList[i].L2cache_data)
if myList[i].L2cache_data
else intensities["ai_l2"].append(0)
)
# print("cur_ai_L2", myList[i].total_flops/myList[i].L2cache_data) if myList[i].L2cache_data else print("null")
# print("cur_ai_L2", myList[i].total_flops/myList[i].L2cache_data) if myList[i].L2cache_data else print("null") #noqa
# print()
(
intensities["ai_hbm"].append(myList[i].total_flops / myList[i].hbm_data)
if myList[i].hbm_data
else intensities["ai_hbm"].append(0)
)
# print("cur_ai_hbm", myList[i].total_flops/myList[i].hbm_data) if myList[i].hbm_data else print("null")
# print("cur_ai_hbm", myList[i].total_flops/myList[i].hbm_data) if myList[i].hbm_data else print("null") #noqa
# print()
(
curr_perf.append(myList[i].total_flops / myList[i].avgDuration)
if myList[i].avgDuration
else curr_perf.append(0)
)
# print("cur_perf", myList[i].total_flops/myList[i].avgDuration) if myList[i].avgDuration else print("null")
# print("cur_perf", myList[i].total_flops/myList[i].avgDuration) if myList[i].avgDuration else print("null") #noqa
i += 1
@@ -726,7 +728,7 @@ def calc_ai_profile(mspec, sort_type, ret_df):
for i in intensities:
values = intensities[i]
color = get_color(i)
color = get_color(i) # noqa
x = []
y = []
for entryIndx in range(0, len(values)):
@@ -758,7 +760,8 @@ def constuct_roof(roofline_parameters, dtype):
# -----------------------------------------------------
# Initialize roofline data dictionary from roofline.csv
# -----------------------------------------------------
benchmark_data = {} # TODO: consider changing this to an ordered dict for consistency over py versions
# TODO: consider changing this to an ordered dict for consistency over py versions
benchmark_data = {}
headers = []
try:
with open(benchmark_results, "r") as csvfile:
@@ -776,7 +779,7 @@ def constuct_roof(roofline_parameters, dtype):
rowCount += 1
csvfile.close()
except:
except Exception:
graphPoints = {
"hbm": [None, None, None],
"l2": [None, None, None],
@@ -167,7 +167,8 @@ def show_all(args, runs, archConfigs, output, profiling_config, roof_plot=None):
and workload.roofline_metrics
):
print(
"\n(4.1) Per-Kernel Roofline Metrics and (4.2) AI Plot Points",
"\n(4.1) Per-Kernel Roofline Metrics and "
"(4.2) AI Plot Points",
file=output,
)
print("-" * 80, file=output)
@@ -201,7 +202,9 @@ def show_all(args, runs, archConfigs, output, profiling_config, roof_plot=None):
else kernel_name
)
print(
f"\nKernel {kernel_id}: {display_name} ({kernel_pct:.1f}%)",
f"\nKernel {kernel_id}: "
f"{display_name} "
f"({kernel_pct:.1f}%)",
file=output,
)