From 3374ead0a9a85bf8efc91a0a929d959dd1e28ea7 Mon Sep 17 00:00:00 2001 From: colramos-amd Date: Mon, 11 Dec 2023 16:35:09 -0600 Subject: [PATCH] Add a supported_archs property to Omniperf base class Signed-off-by: colramos-amd [ROCm/rocprofiler-compute commit: 97c5b2c0a15bbbbb393be084cfa6a34d10fa8ebc] --- projects/rocprofiler-compute/src/argparser.py | 23 ++-------- .../src/omniperf_analyze/analysis_base.py | 6 +-- .../rocprofiler-compute/src/omniperf_base.py | 46 ++++++++----------- .../rocprofiler-compute/src/utils/file_io.py | 17 ++----- 4 files changed, 30 insertions(+), 62 deletions(-) diff --git a/projects/rocprofiler-compute/src/argparser.py b/projects/rocprofiler-compute/src/argparser.py index 6a6f299309..8525a30fc4 100644 --- a/projects/rocprofiler-compute/src/argparser.py +++ b/projects/rocprofiler-compute/src/argparser.py @@ -25,29 +25,14 @@ import argparse import shutil import os -import glob -def load_avail_arch(omniperf_home): - ''' - Load list of avail archs by checking against defined implementations - ''' - matching_files=glob.glob(os.path.join(omniperf_home, 'omniperf_soc', 'soc_*.py')) - supported_arch=[] - # Load list of supported archs - for filepath in matching_files: - filename=os.path.basename(filepath) - postfix=filename[len('soc_'):-len('.py')] - # print(f"File: {filename}, Postfix: {postfix}") - if postfix != "base": - supported_arch.append(postfix) - return supported_arch -def print_avail_arch(avail_arch): +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, omniperf_version): +def omniarg_parser(parser, omniperf_home, supported_archs, omniperf_version): # ----------------------------------------- # Parse arguments (dependent on mode) # ----------------------------------------- @@ -410,8 +395,8 @@ def omniarg_parser(parser, omniperf_home, omniperf_version): analyze_group.add_argument( "--list-metrics", metavar="", - choices=load_avail_arch(omniperf_home),#["gfx906", "gfx908", "gfx90a"], - help=print_avail_arch(load_avail_arch(omniperf_home)), + choices=supported_archs.keys(),#["gfx906", "gfx908", "gfx90a"], + help=print_avail_arch(supported_archs.keys()), ) analyze_group.add_argument( "-k", diff --git a/projects/rocprofiler-compute/src/omniperf_analyze/analysis_base.py b/projects/rocprofiler-compute/src/omniperf_analyze/analysis_base.py index 5a0fbaa56a..fc8a0a976d 100644 --- a/projects/rocprofiler-compute/src/omniperf_analyze/analysis_base.py +++ b/projects/rocprofiler-compute/src/omniperf_analyze/analysis_base.py @@ -35,11 +35,11 @@ import pandas as pd from tabulate import tabulate class OmniAnalyze_Base(): - def __init__(self,args,options): + def __init__(self,args,supported_archs): self.__args = args self._runs = OrderedDict() #NB: I made this public so children can modify/add to obj properties self._arch_configs = {} #NB: I made this public so children can modify/add to obj properties - self.__options = options + self.__supported_archs = supported_archs self._output = None #NB: I made this public so children can modify/add to obj properties def get_args(self): @@ -47,7 +47,7 @@ class OmniAnalyze_Base(): @demarcate def generate_configs(self, arch, config_dir, list_kernels, filter_metrics): - single_panel_config = file_io.is_single_panel_config(Path(config_dir)) + single_panel_config = file_io.is_single_panel_config(Path(config_dir), self.__supported_archs) ac = schema.ArchConfig() if list_kernels: diff --git a/projects/rocprofiler-compute/src/omniperf_base.py b/projects/rocprofiler-compute/src/omniperf_base.py index 1e213b1974..ae18f1d9a3 100644 --- a/projects/rocprofiler-compute/src/omniperf_base.py +++ b/projects/rocprofiler-compute/src/omniperf_base.py @@ -33,6 +33,7 @@ from utils.utils import demarcate, trace_logger, get_version, get_version_displa from argparser import omniarg_parser import config import pandas as pd +import importlib class Omniperf: def __init__(self): @@ -46,6 +47,11 @@ class Omniperf: "ver_pretty": None, } self.__options = {} + self.__supported_archs = { + "gfx906": {"mi50": ["MI50", "MI60"]}, + "gfx908": {"mi100": ["MI100"]}, + "gfx90a": {"mi200": ["MI210", "MI250", "MI250X"]}, + } self.setup_logging() self.set_version() @@ -140,34 +146,20 @@ class Omniperf: mspec = get_machine_specs(0) arch = mspec.GPU - target="" - if arch == "gfx906": - target = "mi50" - elif arch == "gfx908": - target = "mi100" - elif arch == "gfx90a": - target = "mi200" - else: - error("Unsupported SoC -> %s" % arch) - - self.__soc_name.add(target) - if hasattr(self.__args, 'target'): - self.__args.target = target - # instantiate underlying SoC support class # in case of analyze mode, __soc can accommodate multiple archs - if target == "mi50": - from omniperf_soc.soc_gfx906 import gfx906_soc - self.__soc[arch] = gfx906_soc(self.__args) - elif target == "mi100": - from omniperf_soc.soc_gfx908 import gfx908_soc - self.__soc[arch] = gfx908_soc(self.__args) - elif target == "mi200": - from omniperf_soc.soc_gfx90a import gfx90a_soc - self.__soc[arch] = gfx90a_soc(self.__args) - else: + if arch not in self.__supported_archs.keys(): logging.error("Unsupported SoC") sys.exit(1) + else: + target = list(self.__supported_archs[arch].keys())[0] + self.__soc_name.add(target) + if hasattr(self.__args, 'target'): + self.__args.target = target + + soc_module = importlib.import_module('omniperf_soc.soc_'+arch) + soc_class = getattr(soc_module, arch+'_soc') + self.__soc[arch] = soc_class(self.__args) logging.info("SoC = %s" % self.__soc_name) return arch @@ -182,7 +174,7 @@ class Omniperf: ), usage="omniperf [mode] [options]", ) - omniarg_parser(parser, config.omniperf_home, self.__version) + omniarg_parser(parser, config.omniperf_home, self.__supported_archs ,self.__version) self.__args = parser.parse_args() if self.__args.mode == None: @@ -241,10 +233,10 @@ class Omniperf: if self.__analyze_mode == "cli": from omniperf_analyze.analysis_cli import cli_analysis - analyzer = cli_analysis(self.__args,self.__options) + analyzer = cli_analysis(self.__args,self.__supported_archs) elif self.__analyze_mode == "webui": from omniperf_analyze.analysis_webui import webui_analysis - analyzer = webui_analysis(self.__args,self.__options) + analyzer = webui_analysis(self.__args,self.__supported_archs) else: error("Unsupported anlaysis mode -> %s" % self.__analyze_mode) diff --git a/projects/rocprofiler-compute/src/utils/file_io.py b/projects/rocprofiler-compute/src/utils/file_io.py index e00c72f0a8..3c889738e5 100644 --- a/projects/rocprofiler-compute/src/utils/file_io.py +++ b/projects/rocprofiler-compute/src/utils/file_io.py @@ -214,29 +214,20 @@ def collect_wave_occu_per_cu(in_dir, out_dir, numSE): all.to_csv(Path(out_dir, "wave_occu_per_cu.csv"), index=False) -def is_single_panel_config(root_dir): +def is_single_panel_config(root_dir, supported_archs): """ Check the root configs dir structure to decide using one config set for all archs, or one for each arch. """ - matching_files=glob.glob(os.path.join(config.omniperf_home, 'omniperf_soc', 'soc_*.py')) - supported_arch=[] - # Load list of supported archs - for filepath in matching_files: - filename=os.path.basename(filepath) - postfix=filename[len('soc_'):-len('.py')] - # print(f"File: {filename}, Postfix: {postfix}") - if postfix != "base": - supported_arch.append(postfix) - # If not single config, verify all supported archs have defined configs + supported_archs = supported_archs.keys() counter = 0 - for arch in supported_arch: + for arch in supported_archs: if root_dir.joinpath(arch).exists(): counter += 1 if counter == 0: return True - elif counter == len(supported_arch): + elif counter == len(supported_archs): return False else: logging.error("Found multiple panel config sets but incomplete for all archs!")