[rocprof-compute] added f4f6 description and VALU FLOPS split for empirical peaks (#739)

* added f4f6 description and VALU FLOPS split

* changed peak ammolite vars to local

* reverted to dict peak initialization

* ruff check format

* updated VALU descriptions

* updated VALU descriptions

* Update parser.py

* Update parser.py

Added gracefull NameError handling
Moved globals() update to init_metric_evaluation with ammolite__ vars and raw pmc_df

* update formatting
This commit is contained in:
jamessiddeley-amd
2025-08-27 12:46:41 -04:00
committed by GitHub
parent 5201efe050
commit f0955f5a83
9 changed files with 420 additions and 148 deletions
@@ -771,7 +771,7 @@ def build_metric_value_string(dfs, dfs_type, normal_unit, profiling_config):
def init_metric_evaluator(
raw_pmc_df: Union[pd.DataFrame, dict], ammolite_vars: dict
raw_pmc_df: Union[pd.DataFrame, dict], ammolite_vars: dict, empirical_peaks: dict
) -> None:
if isinstance(raw_pmc_df, dict):
raw_pmc_df_keys = set(raw_pmc_df.keys())
@@ -790,6 +790,7 @@ def init_metric_evaluator(
# The process-local globals are used for performance optimization.
globals().update(raw_pmc_df_items)
globals().update(ammolite_vars)
globals().update(empirical_peaks)
def run_metric_evaluator(row_expr: str) -> str:
@@ -821,6 +822,38 @@ def run_metric_evaluator(row_expr: str) -> str:
console_error("analysis", str(ae))
def create_empirical_peaks_dict(empirical_peaks_df):
"""Create empirical peaks dictionary"""
empirical_peaks = {}
if not empirical_peaks_df.empty:
peak_data_row = empirical_peaks_df.iloc[0]
for col in empirical_peaks_df.columns:
empirical_peaks[f"ammolite__{col}_empirical_peak"] = peak_data_row[col]
else:
peak_names = [
"FP16Flops",
"FP32Flops",
"FP64Flops",
"MFMAF64Flops",
"MFMAF32Flops",
"MFMAF16Flops",
"MFMABF16Flops",
"MFMAF8Flops",
"MFMAI8Ops",
"HBMBw",
"L2Bw",
"L1Bw",
"LDSBw",
"MFMA_FLOPs_F6F4",
]
# initialize peaks to 0
for peak_name in peak_names:
empirical_peaks[f"ammolite__{peak_name}_empirical_peak"] = 0
return empirical_peaks
@demarcate
def eval_metric(dfs, dfs_type, sys_info, empirical_peaks_df, raw_pmc_df, debug, config):
"""
@@ -927,32 +960,10 @@ def eval_metric(dfs, dfs_type, sys_info, empirical_peaks_df, raw_pmc_df, debug,
"wave_size is not available in sysinfo.csv, please provide the correct "
"value using --specs-correction"
)
if not empirical_peaks_df.empty:
peak_data_row = empirical_peaks_df.iloc[0]
for metric_name in empirical_peaks_df.columns:
var_name = f"ammolite__{metric_name}_empirical_peak"
locals()[var_name] = peak_data_row[metric_name]
else:
default_peaks = [
"MFMAF64Flops",
"MFMAF32Flops",
"MFMAF16Flops",
"MFMABF16Flops",
"MFMAF8Flops",
"MFMAI8Ops",
"HBMBw",
"L2Bw",
"L1Bw",
"LDSBw",
"MFMA_FLOPs_F6F4",
]
# set values to 0 if no no empirical peaks from roofline.csv are provided
for peak_name in default_peaks:
var_name = f"ammolite__{peak_name}_empirical_peak"
exec(f"{var_name} = 0", globals(), locals())
empirical_peaks = create_empirical_peaks_dict(empirical_peaks_df)
# TODO: fix all $normUnit in Unit column or title
# build and eval all derived build-in global variables
ammolite__build_in = {}
@@ -966,6 +977,8 @@ def eval_metric(dfs, dfs_type, sys_info, empirical_peaks_df, raw_pmc_df, debug,
ammolite__build_in[key] = eval(compile(s, "<string>", "eval"))
except TypeError:
ammolite__build_in[key] = None
except NameError:
ammolite__build_in[key] = None
except KeyError:
ammolite__build_in[key] = None
except AttributeError as ae:
@@ -1022,12 +1035,32 @@ def eval_metric(dfs, dfs_type, sys_info, empirical_peaks_df, raw_pmc_df, debug,
)
if matched_vars:
for v in matched_vars:
print(
"Var ",
v,
":",
eval(compile(v, "<string>", "eval")),
)
try:
value = eval(
compile(v, "<string>", "eval")
)
print("Var ", v, ":", value)
except NameError:
if "_empirical_peak" in v:
if v in empirical_peaks:
print(
"Var ",
v,
":",
empirical_peaks[v],
)
else:
print(
"Var ",
v,
": [empirical peak not found]", # noqa
)
else:
print(
"Var ",
v,
": [not available in main thread]", # noqa
)
matched_cols = re.findall(
r"raw_pmc_df\['\w+'\]\['\w+'\]", row[expr]
)
@@ -1063,6 +1096,21 @@ def eval_metric(dfs, dfs_type, sys_info, empirical_peaks_df, raw_pmc_df, debug,
eval(compile(row[expr], "<string>", "eval"))
)
print("~" * 40)
except NameError as ne:
if "empirical_peak" in str(ne):
console_warning(
"Skipping debug evaluation. Empirical peak variables " # noqa
"not available in main thread: {}".format( # noqa
str(ne)
)
)
else:
console_warning(
"Skipping debug evaluation. Variable not available: {}".format( # noqa
str(ne)
)
)
print("~" * 40)
except TypeError:
console_warning(
"Skipping entry. Encountered a missing "
@@ -1100,7 +1148,6 @@ def eval_metric(dfs, dfs_type, sys_info, empirical_peaks_df, raw_pmc_df, debug,
ammolite_vars = {
key: val for key, val in locals().items() if key.startswith("ammolite__")
}
# Empirically, 16 is about as much as we need.
processes = min(16, multiprocessing.cpu_count() // 2)
@@ -1108,7 +1155,7 @@ def eval_metric(dfs, dfs_type, sys_info, empirical_peaks_df, raw_pmc_df, debug,
with multiprocessing.Pool(
processes=processes,
initializer=init_metric_evaluator,
initargs=(raw_pmc_df, ammolite_vars),
initargs=(raw_pmc_df, ammolite_vars, empirical_peaks),
) as pool:
outs = pool.map(run_metric_evaluator, row_exprs)