From 3294c495f59181fbd2e356be5376d4dd0d759f33 Mon Sep 17 00:00:00 2001 From: xuchen-amd Date: Tue, 25 Mar 2025 17:49:42 -0400 Subject: [PATCH] Improve readability. (#628) --- src/rocprof_compute_base.py | 6 +---- src/rocprof_compute_soc/soc_base.py | 1 - src/utils/utils.py | 40 +++++++++++++++-------------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/rocprof_compute_base.py b/src/rocprof_compute_base.py index 696e34be18..0869c38d79 100644 --- a/src/rocprof_compute_base.py +++ b/src/rocprof_compute_base.py @@ -157,10 +157,6 @@ class RocProfCompute: arch = self.__mspec.gpu_arch - # NB: This checker is a bit redundent. We already check this in specs module - if arch not in self.__supported_archs.keys(): - console_error("%s is an unsupported SoC" % arch) - soc_module = importlib.import_module("rocprof_compute_soc.soc_" + arch) soc_class = getattr(soc_module, arch + "_soc") self.__soc[arch] = soc_class(self.__args, self.__mspec) @@ -186,7 +182,7 @@ class RocProfCompute: sys.exit(0) parser.print_help(sys.stderr) console_error( - "rocprof-compute requires you pass a valid mode. Detected None." + "rocprof-compute requires you to pass a valid mode. Detected None." ) elif self.__args.mode == "profile": diff --git a/src/rocprof_compute_soc/soc_base.py b/src/rocprof_compute_soc/soc_base.py index 2e4a34e705..9f9a035ce1 100644 --- a/src/rocprof_compute_soc/soc_base.py +++ b/src/rocprof_compute_soc/soc_base.py @@ -103,7 +103,6 @@ class OmniSoC_Base: @demarcate def populate_mspec(self): - console_debug("[populate_mspec]") from utils.specs import run, search, total_sqc if not hasattr(self._mspec, "_rocminfo") or self._mspec._rocminfo is None: diff --git a/src/utils/utils.py b/src/utils/utils.py index af92be9403..33cbe3822c 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -691,7 +691,7 @@ def run_prof( if new_env and not using_v3() and not using_v1(): # flatten tcc for applicable mi300 input f = path(workload_dir + "/out/pmc_1/results_" + fbase + ".csv") - xcds = get_mi300_num_xcds(mspec.gpu_model, mspec.compute_partition) + xcds = total_xcds(mspec.gpu_model, mspec.compute_partition) df = flatten_tcc_info_across_xcds(f, xcds, int(mspec._l2_banks)) df.to_csv(f, index=False) @@ -746,38 +746,40 @@ def process_rocprofv3_output(rocprof_output, workload_dir, is_timestamps): csv_file = pathlib.Path(json_file).with_suffix(".csv") v3_json_to_csv(json_file, csv_file) results_files_csv = glob.glob(workload_dir + "/out/pmc_1/*/*.csv") + elif rocprof_output == "csv": counter_info_csvs = glob.glob( workload_dir + "/out/pmc_1/*/*_counter_collection.csv" ) existing_counter_files_csv = [d for d in counter_info_csvs if path(d).is_file()] - if len(existing_counter_files_csv) > 0: + if existing_counter_files_csv: for counter_file in existing_counter_files_csv: - current_dir = str(path(counter_file).parent) - agent_info_filepath = str( - path(current_dir).joinpath( - path(counter_file).name.replace( - "_counter_collection", "_agent_info" - ) - ) + counter_path = path(counter_file) + current_dir = counter_path.parent + + agent_info_filepath = current_dir / counter_path.name.replace( + "_counter_collection", "_agent_info" ) - if not path(agent_info_filepath).is_file(): + + if not agent_info_filepath.is_file(): raise ValueError( '{} has no coresponding "agent info" file'.format(counter_file) ) - converted_csv_file = str( - path(current_dir).joinpath( - path(counter_file).name.replace( - "_counter_collection", "_converted" - ) - ) + converted_csv_file = current_dir / counter_path.name.replace( + "_counter_collection", "_converted" ) - v3_counter_csv_to_v2_csv( - counter_file, agent_info_filepath, converted_csv_file - ) + try: + v3_counter_csv_to_v2_csv( + counter_file, str(agent_info_filepath), str(converted_csv_file) + ) + except Exception as e: + console_warning( + f"Error converting {counter_file} from v3 to v2 csv: {e}" + ) + return [] results_files_csv = glob.glob(workload_dir + "/out/pmc_1/*/*_converted.csv") elif is_timestamps: