2023-09-06 16:29:48 -05:00
|
|
|
##############################################################################bl
|
|
|
|
|
# MIT License
|
|
|
|
|
#
|
2024-01-24 17:11:39 -06:00
|
|
|
# Copyright (c) 2021 - 2024 Advanced Micro Devices, Inc. All Rights Reserved.
|
2023-09-06 16:29:48 -05:00
|
|
|
#
|
|
|
|
|
# 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
|
2024-03-08 09:38:02 -06:00
|
|
|
import logging
|
2023-09-06 16:29:48 -05:00
|
|
|
import sys
|
|
|
|
|
import os
|
2023-10-31 15:11:17 -05:00
|
|
|
from pathlib import Path
|
|
|
|
|
import shutil
|
2024-02-08 12:23:20 -06:00
|
|
|
from utils.specs import MachineSpecs, generate_machine_specs
|
2024-03-04 12:57:25 -06:00
|
|
|
from utils.utils import (
|
|
|
|
|
demarcate,
|
|
|
|
|
get_version,
|
|
|
|
|
get_version_display,
|
|
|
|
|
detect_rocprof,
|
|
|
|
|
get_submodules,
|
2024-03-08 15:08:12 -06:00
|
|
|
console_debug,
|
2024-03-04 12:57:25 -06:00
|
|
|
console_log,
|
|
|
|
|
console_error,
|
2024-03-08 17:20:08 -06:00
|
|
|
set_locale_encoding,
|
2024-03-04 12:57:25 -06:00
|
|
|
)
|
2024-11-01 12:20:21 -04:00
|
|
|
from utils.logger import (
|
|
|
|
|
setup_console_handler,
|
|
|
|
|
setup_logging_priority,
|
|
|
|
|
setup_file_handler,
|
|
|
|
|
)
|
2023-10-31 15:11:17 -05:00
|
|
|
from argparser import omniarg_parser
|
|
|
|
|
import config
|
2023-12-04 15:47:03 -06:00
|
|
|
import pandas as pd
|
2023-12-11 16:35:09 -06:00
|
|
|
import importlib
|
2023-09-06 16:29:48 -05:00
|
|
|
|
2024-01-24 12:44:42 -06:00
|
|
|
SUPPORTED_ARCHS = {
|
|
|
|
|
"gfx906": {"mi50": ["MI50", "MI60"]},
|
|
|
|
|
"gfx908": {"mi100": ["MI100"]},
|
|
|
|
|
"gfx90a": {"mi200": ["MI210", "MI250", "MI250X"]},
|
|
|
|
|
"gfx940": {"mi300": ["MI300A_A0"]},
|
|
|
|
|
"gfx941": {"mi300": ["MI300X_A0"]},
|
|
|
|
|
"gfx942": {"mi300": ["MI300A_A1", "MI300X_A1"]},
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-24 16:53:36 -04:00
|
|
|
MI300_CHIP_IDS = {
|
|
|
|
|
"29856": "MI300A_A1",
|
|
|
|
|
"29857": "MI300X_A1",
|
|
|
|
|
"29858": "MI308X",
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-16 15:34:28 -06:00
|
|
|
|
2024-11-01 12:20:21 -04:00
|
|
|
class RocProfCompute:
|
2023-09-06 16:29:48 -05:00
|
|
|
def __init__(self):
|
|
|
|
|
self.__args = None
|
|
|
|
|
self.__profiler_mode = None
|
2023-12-04 15:47:03 -06:00
|
|
|
self.__analyze_mode = None
|
2024-02-16 15:34:28 -06:00
|
|
|
self.__soc_name = (
|
|
|
|
|
set()
|
|
|
|
|
) # gpu name, or in case of analyze mode, all loaded gpu name(s)
|
|
|
|
|
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,
|
|
|
|
|
}
|
2023-09-06 16:29:48 -05:00
|
|
|
self.__options = {}
|
2024-01-24 12:44:42 -06:00
|
|
|
self.__supported_archs = SUPPORTED_ARCHS
|
2024-03-01 11:52:31 -06:00
|
|
|
self.__mspec: MachineSpecs = None # to be initalized in load_soc_specs()
|
2024-03-08 15:08:12 -06:00
|
|
|
setup_console_handler()
|
2023-10-31 15:11:17 -05:00
|
|
|
self.set_version()
|
|
|
|
|
self.parse_args()
|
|
|
|
|
self.__mode = self.__args.mode
|
2024-03-08 15:08:12 -06:00
|
|
|
self.__loglevel = setup_logging_priority(
|
|
|
|
|
self.__args.verbose, self.__args.quiet, self.__mode
|
|
|
|
|
)
|
|
|
|
|
setattr(self.__args, "loglevel", self.__loglevel)
|
2024-03-11 12:02:31 -05:00
|
|
|
set_locale_encoding()
|
2023-09-06 16:29:48 -05:00
|
|
|
|
2023-10-31 15:11:17 -05:00
|
|
|
if self.__mode == "profile":
|
|
|
|
|
self.detect_profiler()
|
2023-12-04 15:47:03 -06:00
|
|
|
elif self.__mode == "analyze":
|
|
|
|
|
self.detect_analyze()
|
2024-03-04 12:57:25 -06:00
|
|
|
|
2024-03-08 15:08:12 -06:00
|
|
|
console_debug("Execution mode = %s" % self.__mode)
|
2024-03-04 12:57:25 -06:00
|
|
|
|
2023-10-31 15:11:17 -05:00
|
|
|
def print_graphic(self):
|
2024-03-01 11:52:31 -06:00
|
|
|
"""Log program name as ascii art to terminal."""
|
2024-02-28 10:08:11 -05:00
|
|
|
ascii_art = r"""
|
2024-11-01 12:20:21 -04:00
|
|
|
__ _
|
|
|
|
|
_ __ ___ ___ _ __ _ __ ___ / _| ___ ___ _ __ ___ _ __ _ _| |_ ___
|
|
|
|
|
| '__/ _ \ / __| '_ \| '__/ _ \| |_ _____ / __/ _ \| '_ ` _ \| '_ \| | | | __/ _ \
|
|
|
|
|
| | | (_) | (__| |_) | | | (_) | _|_____| (_| (_) | | | | | | |_) | |_| | || __/
|
|
|
|
|
|_| \___/ \___| .__/|_| \___/|_| \___\___/|_| |_| |_| .__/ \__,_|\__\___|
|
|
|
|
|
|_| |_|
|
2024-02-16 15:34:28 -06:00
|
|
|
"""
|
2024-01-30 17:25:16 -06:00
|
|
|
print(ascii_art)
|
2023-09-06 16:29:48 -05:00
|
|
|
|
|
|
|
|
def get_mode(self):
|
|
|
|
|
return self.__mode
|
2024-02-16 15:34:28 -06:00
|
|
|
|
2023-10-31 15:11:17 -05:00
|
|
|
def set_version(self):
|
2024-11-01 12:20:21 -04:00
|
|
|
vData = get_version(config.rocprof_compute_home)
|
2023-10-31 15:11:17 -05:00
|
|
|
self.__version["ver"] = vData["version"]
|
2024-02-16 15:34:28 -06:00
|
|
|
self.__version["ver_pretty"] = get_version_display(
|
|
|
|
|
vData["version"], vData["sha"], vData["mode"]
|
|
|
|
|
)
|
2023-10-31 15:11:17 -05:00
|
|
|
return
|
2024-03-04 12:57:25 -06:00
|
|
|
|
2023-10-31 15:11:17 -05:00
|
|
|
def detect_profiler(self):
|
2024-02-16 15:34:28 -06:00
|
|
|
if (
|
|
|
|
|
self.__args.lucky == True
|
|
|
|
|
or self.__args.summaries == True
|
|
|
|
|
or self.__args.use_rocscope
|
|
|
|
|
):
|
2023-10-31 15:11:17 -05:00
|
|
|
if not shutil.which("rocscope"):
|
2024-01-30 17:25:16 -06:00
|
|
|
console_error("Rocscope must be in PATH")
|
2023-10-31 15:11:17 -05:00
|
|
|
else:
|
|
|
|
|
self.__profiler_mode = "rocscope"
|
|
|
|
|
else:
|
|
|
|
|
rocprof_cmd = detect_rocprof()
|
2024-01-19 11:02:52 -06:00
|
|
|
if str(rocprof_cmd).endswith("rocprof"):
|
|
|
|
|
self.__profiler_mode = "rocprofv1"
|
|
|
|
|
elif str(rocprof_cmd).endswith("rocprofv2"):
|
|
|
|
|
self.__profiler_mode = "rocprofv2"
|
|
|
|
|
else:
|
2024-03-04 12:57:25 -06:00
|
|
|
console_error(
|
|
|
|
|
"Incompatible profiler: %s. Supported profilers include: %s"
|
2024-11-01 12:20:21 -04:00
|
|
|
% (rocprof_cmd, get_submodules("rocprof_compute_profile"))
|
2024-03-04 12:57:25 -06:00
|
|
|
)
|
2023-10-31 15:11:17 -05:00
|
|
|
return
|
2024-02-16 15:34:28 -06:00
|
|
|
|
2023-12-04 15:47:03 -06:00
|
|
|
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
|
|
|
|
2023-09-06 16:29:48 -05:00
|
|
|
@demarcate
|
2024-03-01 11:52:31 -06:00
|
|
|
def load_soc_specs(self, sysinfo: dict = None):
|
2024-11-01 12:20:21 -04:00
|
|
|
"""Load OmniSoC instance for RocProfCompute run"""
|
2024-02-29 10:21:29 -05:00
|
|
|
self.__mspec = generate_machine_specs(self.__args, sysinfo)
|
2024-02-21 15:58:07 -06:00
|
|
|
if self.__args.specs:
|
|
|
|
|
print(self.__mspec)
|
|
|
|
|
sys.exit(0)
|
2024-02-20 13:34:56 -06:00
|
|
|
|
2024-02-21 15:58:07 -06:00
|
|
|
arch = self.__mspec.gpu_arch
|
2023-10-31 15:11:17 -05:00
|
|
|
|
2024-02-20 13:34:56 -06:00
|
|
|
# NB: This checker is a bit redundent. We already check this in specs module
|
2023-12-11 16:35:09 -06:00
|
|
|
if arch not in self.__supported_archs.keys():
|
2024-02-08 12:23:20 -06:00
|
|
|
console_error("%s is an unsupported SoC" % arch)
|
2023-12-11 16:35:09 -06:00
|
|
|
|
2024-11-01 12:20:21 -04:00
|
|
|
soc_module = importlib.import_module("rocprof_compute_soc.soc_" + arch)
|
2024-03-01 11:52:31 -06:00
|
|
|
soc_class = getattr(soc_module, arch + "_soc")
|
2024-02-20 13:34:56 -06:00
|
|
|
self.__soc[arch] = soc_class(self.__args, self.__mspec)
|
|
|
|
|
return
|
2024-01-30 17:25:16 -06:00
|
|
|
|
2023-10-31 15:11:17 -05:00
|
|
|
def parse_args(self):
|
|
|
|
|
parser = argparse.ArgumentParser(
|
2024-11-01 12:20:21 -04:00
|
|
|
description="Command line interface for AMD's GPU profiler, ROCm Compute Profiler",
|
2024-02-16 15:34:28 -06:00
|
|
|
prog="tool",
|
|
|
|
|
formatter_class=lambda prog: argparse.RawTextHelpFormatter(
|
2023-10-31 15:11:17 -05:00
|
|
|
prog, max_help_position=30
|
|
|
|
|
),
|
2024-11-01 12:20:21 -04:00
|
|
|
usage="rocprof-compute [mode] [options]",
|
2023-10-31 15:11:17 -05:00
|
|
|
)
|
2024-02-16 15:34:28 -06:00
|
|
|
omniarg_parser(
|
2024-11-01 12:20:21 -04:00
|
|
|
parser, config.rocprof_compute_home, self.__supported_archs, self.__version
|
2024-02-16 15:34:28 -06:00
|
|
|
)
|
2023-10-31 15:11:17 -05:00
|
|
|
self.__args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
if self.__args.mode == None:
|
2024-02-21 15:58:07 -06:00
|
|
|
if self.__args.specs:
|
2024-02-29 10:21:29 -05:00
|
|
|
print(generate_machine_specs(self.__args))
|
2024-02-21 15:58:07 -06:00
|
|
|
sys.exit(0)
|
2023-10-31 15:11:17 -05:00
|
|
|
parser.print_help(sys.stderr)
|
2024-11-01 12:20:21 -04:00
|
|
|
console_error(
|
|
|
|
|
"rocprof-compute requires you pass a valid mode. Detected None."
|
|
|
|
|
)
|
2023-09-06 16:29:48 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
@demarcate
|
|
|
|
|
def run_profiler(self):
|
2023-10-31 15:11:17 -05:00
|
|
|
self.print_graphic()
|
2024-02-20 13:34:56 -06:00
|
|
|
self.load_soc_specs()
|
2023-10-31 15:11:17 -05:00
|
|
|
|
|
|
|
|
# Update default path
|
|
|
|
|
if self.__args.path == os.path.join(os.getcwd(), "workloads"):
|
2024-03-01 11:52:31 -06:00
|
|
|
self.__args.path = os.path.join(
|
|
|
|
|
self.__args.path, self.__args.name, self.__mspec.gpu_model
|
|
|
|
|
)
|
2023-09-06 16:29:48 -05:00
|
|
|
|
|
|
|
|
# instantiate desired profiler
|
2023-10-31 15:11:17 -05:00
|
|
|
if self.__profiler_mode == "rocprofv1":
|
2024-11-01 12:20:21 -04:00
|
|
|
from rocprof_compute_profile.profiler_rocprof_v1 import rocprof_v1_profiler
|
2024-03-01 11:52:31 -06:00
|
|
|
|
|
|
|
|
profiler = rocprof_v1_profiler(
|
|
|
|
|
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch]
|
|
|
|
|
)
|
2023-10-31 15:11:17 -05:00
|
|
|
elif self.__profiler_mode == "rocprofv2":
|
2024-11-01 12:20:21 -04:00
|
|
|
from rocprof_compute_profile.profiler_rocprof_v2 import rocprof_v2_profiler
|
2024-03-01 11:52:31 -06:00
|
|
|
|
|
|
|
|
profiler = rocprof_v2_profiler(
|
|
|
|
|
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch]
|
|
|
|
|
)
|
2023-09-06 16:29:48 -05:00
|
|
|
elif self.__profiler_mode == "rocscope":
|
2024-11-01 12:20:21 -04:00
|
|
|
from rocprof_compute_profile.profiler_rocscope import rocscope_profiler
|
2024-03-01 11:52:31 -06:00
|
|
|
|
|
|
|
|
profiler = rocscope_profiler(
|
|
|
|
|
self.__args, self.__profiler_mode, self.__soc[self.__mspec.gpu_arch]
|
|
|
|
|
)
|
2023-09-06 16:29:48 -05:00
|
|
|
else:
|
2024-01-30 17:25:16 -06:00
|
|
|
console_error("Unsupported profiler")
|
2023-09-06 16:29:48 -05:00
|
|
|
|
2024-02-16 15:34:28 -06:00
|
|
|
# -----------------------
|
2023-09-06 16:29:48 -05:00
|
|
|
# run profiling workflow
|
2024-03-01 11:52:31 -06:00
|
|
|
# -----------------------
|
2024-03-08 15:08:12 -06:00
|
|
|
|
2024-02-21 15:58:07 -06:00
|
|
|
self.__soc[self.__mspec.gpu_arch].profiling_setup()
|
2024-03-08 15:08:12 -06:00
|
|
|
# enable file-based logging
|
|
|
|
|
setup_file_handler(self.__args.loglevel, self.__args.path)
|
|
|
|
|
|
2023-09-06 16:29:48 -05:00
|
|
|
profiler.pre_processing()
|
2023-10-31 15:11:17 -05:00
|
|
|
profiler.run_profiling(self.__version["ver"], config.prog)
|
2023-09-06 16:29:48 -05:00
|
|
|
profiler.post_processing()
|
2024-02-21 15:58:07 -06:00
|
|
|
self.__soc[self.__mspec.gpu_arch].post_profiling()
|
2023-09-06 16:29:48 -05:00
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
@demarcate
|
2024-01-30 10:43:30 -06:00
|
|
|
def update_db(self):
|
2023-10-31 15:11:17 -05:00
|
|
|
self.print_graphic()
|
2024-01-30 10:43:30 -06:00
|
|
|
from utils.db_connector import DatabaseConnector
|
2024-02-16 15:34:28 -06:00
|
|
|
|
2024-01-30 10:43:30 -06:00
|
|
|
db_connection = DatabaseConnector(self.__args)
|
2024-02-16 15:34:28 -06:00
|
|
|
|
|
|
|
|
# -----------------------
|
2024-01-30 10:43:30 -06:00
|
|
|
# run database workflow
|
2024-02-16 15:34:28 -06:00
|
|
|
# -----------------------
|
2024-01-30 10:43:30 -06:00
|
|
|
db_connection.pre_processing()
|
|
|
|
|
if self.__args.upload:
|
|
|
|
|
db_connection.db_import()
|
|
|
|
|
else:
|
|
|
|
|
db_connection.db_remove()
|
2024-02-16 15:34:28 -06:00
|
|
|
|
2023-09-06 16:29:48 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
@demarcate
|
|
|
|
|
def run_analysis(self):
|
2023-10-31 15:11:17 -05:00
|
|
|
self.print_graphic()
|
2023-09-06 16:29:48 -05:00
|
|
|
|
2024-03-04 12:57:25 -06:00
|
|
|
console_log("Analysis mode = %s" % self.__analyze_mode)
|
2023-09-06 16:29:48 -05:00
|
|
|
|
|
|
|
|
if self.__analyze_mode == "cli":
|
2024-11-01 12:20:21 -04:00
|
|
|
from rocprof_compute_analyze.analysis_cli import cli_analysis
|
2024-02-16 15:34:28 -06:00
|
|
|
|
2023-12-18 16:37:01 -06:00
|
|
|
analyzer = cli_analysis(self.__args, self.__supported_archs)
|
|
|
|
|
elif self.__analyze_mode == "web_ui":
|
2024-11-01 12:20:21 -04:00
|
|
|
from rocprof_compute_analyze.analysis_webui import webui_analysis
|
2024-02-16 15:34:28 -06:00
|
|
|
|
2023-12-18 16:37:01 -06:00
|
|
|
analyzer = webui_analysis(self.__args, self.__supported_archs)
|
2023-09-06 16:29:48 -05:00
|
|
|
else:
|
2024-03-11 11:14:45 -05:00
|
|
|
console_error("Unsupported analysis mode -> %s" % self.__analyze_mode)
|
2023-09-06 16:29:48 -05:00
|
|
|
|
2024-02-16 15:34:28 -06:00
|
|
|
# -----------------------
|
2023-09-06 16:29:48 -05:00
|
|
|
# run analysis workflow
|
2024-02-16 15:34:28 -06:00
|
|
|
# -----------------------
|
2023-12-04 15:47:03 -06:00
|
|
|
analyzer.sanitize()
|
2024-02-16 15:34:28 -06:00
|
|
|
|
2023-12-04 15:47:03 -06:00
|
|
|
# Load required SoC(s) from input
|
|
|
|
|
for d in analyzer.get_args().path:
|
|
|
|
|
sys_info = pd.read_csv(Path(d[0], "sysinfo.csv"))
|
2024-03-01 11:52:31 -06:00
|
|
|
sys_info = sys_info.to_dict("list")
|
2024-02-29 10:21:29 -05:00
|
|
|
sys_info = {key: value[0] for key, value in sys_info.items()}
|
2024-02-20 13:34:56 -06:00
|
|
|
self.load_soc_specs(sys_info)
|
2023-12-04 15:47:03 -06:00
|
|
|
|
2023-12-18 16:37:01 -06:00
|
|
|
analyzer.set_soc(self.__soc)
|
|
|
|
|
analyzer.pre_processing()
|
2023-09-06 16:29:48 -05:00
|
|
|
analyzer.run_analysis()
|
|
|
|
|
|
|
|
|
|
return
|