Initial overhaul of Profile mode

Signed-off-by: colramos-amd <colramos@amd.com>
This commit is contained in:
colramos-amd
2023-10-31 15:11:17 -05:00
parent c15ec38eca
commit 87388227ca
421 changed files with 16949 additions and 1912 deletions
+116 -44
View File
@@ -26,8 +26,13 @@ import argparse
import logging
import sys
import os
from utils.utils import demarcate, trace_logger
from pathlib import Path
import shutil
from utils.specs import get_machine_specs
from utils.utils import demarcate, trace_logger, get_version, get_version_display, detect_rocprof
from argparser import omniarg_parser
import config
import pyfiglet
class Omniperf:
def __init__(self):
@@ -35,28 +40,33 @@ class Omniperf:
self.__profiler_mode = None
self.__soc_name = None
self.__soc = None
self.__version = {
"ver": None,
"ver_pretty": None,
}
self.__options = {}
self.setup_logging()
self.parseArgs()
self.set_version()
self.parse_args()
# hard-coding dummy examples (comment/uncomment below to instantiate different implementations)
self.__profiler_mode = "rocprof_v1"
self.__profiler_mode = "rocprof_v2"
#self.__profiler_mode = "rocscope"
self.__analyze_mode = "cli"
self.__analyze_mode = "webui"
# hard-code execution mode
self.__mode = "profile"
#self.__mode = "analyze"
self.__mode = self.__args.mode
if self.__mode == "profile":
self.detect_profiler()
# self.__analyze_mode = "cli"
# self.__analyze_mode = "webui"
logging.info("Execution mode = %s" % self.__mode)
def print_graphic(self):
"""Read program name and log ascii art to terminal.
"""
ascii_art = pyfiglet.figlet_format(config.prog.capitalize())
logging.info(ascii_art)
def setup_logging(self):
# register a trace level logger
logging.TRACE = logging.DEBUG - 5
logging.addLevelName(logging.TRACE, "TRACE")
@@ -83,6 +93,12 @@ class Omniperf:
def get_mode(self):
return self.__mode
def set_version(self):
vData = get_version(config.omniperf_home)
self.__version["ver"] = vData["version"]
self.__version["ver_pretty"] = get_version_display(vData["version"], vData["sha"], vData["mode"])
return
def error(self,message):
logging.error("")
@@ -90,50 +106,103 @@ class Omniperf:
logging.error("")
sys.exit(1)
def detect_profiler(self):
#TODO:
# Currently this will only be called in profile mode
# could we also utilize this function to detect "profiler origin" in analyze mode,
# or is there a better place to do this?
if self.__args.lucky == True or self.__args.summaries == True or self.__args.use_rocscope:
if not shutil.which("rocscope"):
logging.error("Rocscope must be in PATH")
sys.exit(1)
else:
self.__profiler_mode = "rocscope"
else:
#TODO: Add detection logic for rocprofv2
rocprof_cmd = detect_rocprof()
self.__profiler_mode = "rocprofv1"
return
@demarcate
def detectSoC(self):
# hard-coded example
self.__soc_name = "gfx906"
self.__soc_name = "gfx908"
self.__soc_name = "gfx90a"
def detect_soc(self):
mspec = get_machine_specs(0)
target=""
if mspec.GPU == "gfx900":
target = "vega10"
elif mspec.GPU == "gfx906":
target = "mi50"
elif mspec.GPU == "gfx908":
target = "mi100"
elif mspec.GPU == "gfx90a":
target = "mi200"
else:
self.error("Unsupported SoC -> %s" % mspec.GPU)
self.__soc_name = target
self.__args.target = target
# instantiate underlying SoC support class
if self.__soc_name == "gfx906":
from soc_gfx906 import gfx906_soc
if self.__soc_name == "vega10":
from omniperf_soc.soc_gfx900 import gfx900_soc
self.__soc = gfx900_soc(self.__args)
elif self.__soc_name == "mi50":
from omniperf_soc.soc_gfx906 import gfx906_soc
self.__soc = gfx906_soc(self.__args)
elif self.__soc_name == "gfx908":
from soc_gfx908 import gfx908_soc
elif self.__soc_name == "mi100":
from omniperf_soc.soc_gfx908 import gfx908_soc
self.__soc = gfx908_soc(self.__args)
elif self.__soc_name == "gfx90a":
from soc_gfx90a import gfx90a_soc
elif self.__soc_name == "mi200":
from omniperf_soc.soc_gfx90a import gfx90a_soc
self.__soc = gfx90a_soc(self.__args)
else:
logging.error("Unsupported SoC")
self.error("Unsupported SoC")
sys.exit(1)
logging.info("SoC = %s" % self.__soc_name)
return
def parseArgs(self):
self.__args = "some arguments"
@demarcate
def parse_args(self):
parser = argparse.ArgumentParser(
description="Command line interface for AMD's GPU profiler, Omniperf",
prog="tool",
formatter_class=lambda prog: argparse.RawTextHelpFormatter(
prog, max_help_position=30
),
usage="omniperf [mode] [options]",
)
omniarg_parser(parser, config.omniperf_home, self.__version)
self.__args = parser.parse_args()
if self.__args.mode == None:
parser.print_help(sys.stderr)
self.error("Omniperf requires a valid mode.")
return
@demarcate
def run_profiler(self):
self.detectSoC()
self.print_graphic()
self.detect_soc()
# Update default path
if self.__args.path == os.path.join(os.getcwd(), "workloads"):
self.__args.path = os.path.join(self.__args.path, self.__args.name, self.__args.target)
logging.info("Profiler choice = %s" % self.__profiler_mode)
# instantiate desired profiler
if self.__profiler_mode == "rocprof_v1":
from profiler_rocprof import rocprof_v1_profiler
profiler = rocprof_v1_profiler(self.__soc, self.__args)
elif self.__profiler_mode == "rocprof_v2":
from profiler_rocprof_v2 import rocprof_v2_profiler
profiler = rocprof_v2_profiler(self.__soc, self.__args)
if self.__profiler_mode == "rocprofv1":
from omniperf_profile.profiler_rocprof_v1 import rocprof_v1_profiler
profiler = rocprof_v1_profiler(self.__args, self.__profiler_mode, self.__soc)
elif self.__profiler_mode == "rocprofv2":
from omniperf_profile.profiler_rocprof_v2 import rocprof_v2_profiler
profiler = rocprof_v2_profiler(self.__args, self.__profiler_mode, self.__soc)
elif self.__profiler_mode == "rocscope":
from profiler_rocscope import rocscope_profiler
profiler = rocscope_profiler(self.__soc, self.__args)
from omniperf_profile.profiler_rocscope import rocscope_profiler
profiler = rocscope_profiler(self.__args, self.__profiler_mode, self.__soc)
else:
logging.error("Unsupported profiler")
sys.exit(1)
@@ -144,27 +213,30 @@ class Omniperf:
self.__soc.profiling_setup()
profiler.pre_processing()
profiler.run_profiling()
profiler.run_profiling(self.__version["ver"], config.prog)
profiler.post_processing()
self.__soc.post_profiling()
return
@demarcate
def update_DB(self):
self.print_graphic()
#TODO: Add a DB workflow
return
@demarcate
def run_analysis(self):
self.detectSoC()
self.print_graphic()
self.detect_soc() #NB: See comment in detect_profiler() to explain why this is here
logging.info("Analysis mode choie = %s" % self.__analyze_mode)
if self.__analyze_mode == "cli":
from analysis_cli import cli_analysis
from analyze.analysis_cli import cli_analysis
analyzer = cli_analysis(self.__args,self.__options)
elif self.__analyze_mode == "webui":
from analysis_webui import webui_analysis
from analyze.analysis_webui import webui_analysis
analyzer = webui_analysis(self.__args,self.__options)
else:
self.error("Unsupported anlaysis mode -> %s" % self.__analyze_mode)