Files
rocm-systems/src/omniperf_base.py
T

268 lines
9.6 KiB
Python
Raw Normal View History

##############################################################################bl
# MIT License
#
# Copyright (c) 2021 - 2023 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
##############################################################################el
import argparse
import logging
import sys
import os
2023-10-31 15:11:17 -05:00
from pathlib import Path
import shutil
from utils.specs import get_machine_specs
2023-12-11 09:55:15 -06:00
from utils.utils import demarcate, trace_logger, get_version, get_version_display, detect_rocprof, error
2023-10-31 15:11:17 -05:00
from argparser import omniarg_parser
import config
import pandas as pd
class Omniperf:
def __init__(self):
self.__args = None
self.__profiler_mode = None
self.__analyze_mode = None
self.__soc_name = set() #TODO: Should we make this a list? To accommodate analyze mode
self.__soc = dict() # set of key, value pairs. Where arch->OmniSoc() obj
2023-10-31 15:11:17 -05:00
self.__version = {
"ver": None,
"ver_pretty": None,
}
self.__options = {}
self.setup_logging()
2023-10-31 15:11:17 -05:00
self.set_version()
self.parse_args()
2023-10-31 15:11:17 -05:00
self.__mode = self.__args.mode
2023-10-31 15:11:17 -05:00
if self.__mode == "profile":
self.detect_profiler()
elif self.__mode == "analyze":
self.detect_analyze()
2023-10-31 15:11:17 -05:00
logging.info("Execution mode = %s" % self.__mode)
2023-10-31 15:11:17 -05:00
def print_graphic(self):
"""Log program name as ascii art to terminal.
2023-10-31 15:11:17 -05:00
"""
ascii_art = '''
___ _ __
/ _ \ _ __ ___ _ __ (_)_ __ ___ _ __ / _|
| | | | '_ ` _ \| '_ \| | '_ \ / _ \ '__| |_
| |_| | | | | | | | | | | |_) | __/ | | _|
\___/|_| |_| |_|_| |_|_| .__/ \___|_| |_|
|_|
'''
2023-10-31 15:11:17 -05:00
logging.info(ascii_art)
def setup_logging(self):
# register a trace level logger
logging.TRACE = logging.DEBUG - 5
logging.addLevelName(logging.TRACE, "TRACE")
setattr(logging, "TRACE", logging.TRACE)
setattr(logging, "trace", trace_logger)
# demonstrate override of default loglevel via env variable
loglevel=logging.INFO
if "OMNIPERF_LOGLEVEL" in os.environ.keys():
loglevel = os.environ['OMNIPERF_LOGLEVEL']
if loglevel in {"DEBUG","debug"}:
loglevel = logging.DEBUG
elif loglevel in {"TRACE","trace"}:
loglevel = logging.TRACE
elif loglevel in {"INFO","info"}:
loglevel = logging.INFO
elif loglevel in {"ERROR","error"}:
loglevel = logging.ERROR
else:
print("Ignoring unsupported OMNIPERF_LOGLEVEL setting (%s)" % loglevel)
sys.exit(1)
logging.basicConfig(format="%(message)s", level=loglevel, stream=sys.stdout)
def get_mode(self):
return self.__mode
2023-10-31 15:11:17 -05:00
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
2023-10-31 15:11:17 -05:00
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
def detect_analyze(self):
if self.__args.gui:
self.__analyze_mode = "web_ui"
else:
self.__analyze_mode = "cli"
return
2023-10-31 15:11:17 -05:00
@demarcate
def detect_soc(self, arch=None):
"""Load OmniSoC instance for Omniperf run
"""
# in case of analyze mode, we can explicitly specify an arch
# rather than detect from rocminfo
if not arch:
mspec = get_machine_specs(0)
arch = mspec.GPU
2023-10-31 15:11:17 -05:00
target=""
if arch == "gfx906":
2023-10-31 15:11:17 -05:00
target = "mi50"
elif arch == "gfx908":
2023-10-31 15:11:17 -05:00
target = "mi100"
elif arch == "gfx90a":
2023-10-31 15:11:17 -05:00
target = "mi200"
else:
2023-12-11 09:55:15 -06:00
error("Unsupported SoC -> %s" % arch)
2023-10-31 15:11:17 -05:00
self.__soc_name.add(target)
if hasattr(self.__args, 'target'):
self.__args.target = target
# instantiate underlying SoC support class
2023-12-07 15:14:26 -06:00
# in case of analyze mode, __soc can accommodate multiple archs
if target == "mi50":
2023-10-31 15:11:17 -05:00
from omniperf_soc.soc_gfx906 import gfx906_soc
self.__soc[arch] = gfx906_soc(self.__args)
elif target == "mi100":
2023-10-31 15:11:17 -05:00
from omniperf_soc.soc_gfx908 import gfx908_soc
self.__soc[arch] = gfx908_soc(self.__args)
elif target == "mi200":
2023-10-31 15:11:17 -05:00
from omniperf_soc.soc_gfx90a import gfx90a_soc
self.__soc[arch] = gfx90a_soc(self.__args)
else:
logging.error("Unsupported SoC")
sys.exit(1)
logging.info("SoC = %s" % self.__soc_name)
return arch
2023-10-31 15:11:17 -05:00
@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)
2023-12-11 09:55:15 -06:00
error("Omniperf requires a valid mode.")
2023-10-31 15:11:17 -05:00
return
@demarcate
def run_profiler(self):
2023-10-31 15:11:17 -05:00
self.print_graphic()
targ_arch = self.detect_soc()
2023-10-31 15:11:17 -05:00
# 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
2023-10-31 15:11:17 -05:00
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":
2023-10-31 15:11:17 -05:00
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)
#-----------------------
# run profiling workflow
#-----------------------
self.__soc[targ_arch].profiling_setup()
profiler.pre_processing()
2023-10-31 15:11:17 -05:00
profiler.run_profiling(self.__version["ver"], config.prog)
profiler.post_processing()
self.__soc[targ_arch].post_profiling()
return
@demarcate
def update_DB(self):
2023-10-31 15:11:17 -05:00
self.print_graphic()
#TODO: Add a DB workflow
return
@demarcate
def run_analysis(self):
2023-10-31 15:11:17 -05:00
self.print_graphic()
logging.info("Analysis mode = %s" % self.__analyze_mode)
if self.__analyze_mode == "cli":
from omniperf_analyze.analysis_cli import cli_analysis
analyzer = cli_analysis(self.__args,self.__options)
elif self.__analyze_mode == "webui":
from omniperf_analyze.analysis_webui import webui_analysis
analyzer = webui_analysis(self.__args,self.__options)
else:
2023-12-11 09:55:15 -06:00
error("Unsupported anlaysis mode -> %s" % self.__analyze_mode)
#-----------------------
# run analysis workflow
#-----------------------
analyzer.sanitize()
# Load required SoC(s) from input
for d in analyzer.get_args().path:
sys_info = pd.read_csv(Path(d[0], "sysinfo.csv"))
arch = sys_info.iloc[0]["gpu_soc"]
# Create and load new SoC object
self.detect_soc(arch)
analyzer.pre_processing(self.__soc)
analyzer.run_analysis()
return