forked from ROCm/omniperf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addition of new files to demonstrate top-level data structure refacto…
…ring for 2.x version. Introduces an Omniperf class as the primary structure to organize work elements and allows for a simple main() which is highlighted in a omniperf2 example. Demonstrates desired logger functionality including a custom trace loglevel that can be used to provide more verbosity beyond the debug level. Also introduces three abstract base classes to organize flexibility for alternative implementations of key elements within omniperf: * underlying profiler tool (e.g. rocprof, rocscope, etc) * supported GPU architectures (SoC) * analysis environments (e.g. CLI, web-based, etc) Stub examples for child classes relevant to currently supported options within omniperf are included in separate files. Signed-off-by: Karl W. Schulz <karl.schulz@amd.com>
- Loading branch information
Showing
14 changed files
with
764 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
##############################################################################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 | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
class OmniAnalyze_Base(): | ||
def __init__(self,args,options): | ||
self.__args = args | ||
self.__options = options | ||
|
||
# Required methods to be implemented by child classes | ||
@abstractmethod | ||
def pre_processing(self): | ||
"""Perform initialization prior to analysis. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def run_analysis(self): | ||
"""Run analysis. | ||
""" | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
##############################################################################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 logging | ||
from analysis_base import OmniAnalyze_Base | ||
from utils.utils import demarcate | ||
|
||
class cli_analysis(OmniAnalyze_Base): | ||
|
||
# Required child methods | ||
@demarcate | ||
def pre_processing(self): | ||
"""Perform any pre-processing steps prior to analysis. | ||
""" | ||
logging.debug("[analysis] prepping to do some analysis") | ||
|
||
@demarcate | ||
def run_analysis(self): | ||
"""Run CLI analysis. | ||
""" | ||
logging.debug("[analysis] check out this wicked cli ascii art") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
##############################################################################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 logging | ||
from analysis_base import OmniAnalyze_Base | ||
from utils.utils import demarcate | ||
|
||
class webui_analysis(OmniAnalyze_Base): | ||
|
||
# Required child methods | ||
@demarcate | ||
def pre_processing(self): | ||
"""Perform any pre-processing steps prior to analysis. | ||
""" | ||
logging.debug("[analysis] prepping to do some analysis") | ||
|
||
@demarcate | ||
def run_analysis(self): | ||
"""Run CLI analysis. | ||
""" | ||
logging.debug("[analysis] would you like to check out a groovy profiling web site?") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
|
||
##############################################################################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 | ||
|
||
from omniperf_base import Omniperf | ||
|
||
def main(): | ||
|
||
omniperf2 = Omniperf() | ||
omniperf2.parseArgs() | ||
|
||
mode = omniperf2.get_mode() | ||
|
||
# major omniperf execution modes | ||
if mode == "profile": | ||
omniperf2.run_profiler() | ||
elif mode == "database": | ||
omniperf2.update_DB() | ||
elif mode == "analyze": | ||
omniperf2.run_analysis() | ||
else: | ||
omniperf2.error("Unsupported execution mode") | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
##############################################################################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 | ||
from utils.utils import demarcate, trace_logger | ||
|
||
|
||
class Omniperf: | ||
def __init__(self): | ||
self.__args = None | ||
self.__profiler_mode = None | ||
self.__soc_name = None | ||
self.__soc = None | ||
self.__options = {} | ||
|
||
self.setup_logging() | ||
self.parseArgs() | ||
|
||
# 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" | ||
|
||
logging.info("Execution mode = %s" % self.__mode) | ||
|
||
|
||
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 | ||
|
||
def error(self,message): | ||
logging.error("") | ||
logging.error("[ERROR]: " + message) | ||
logging.error("") | ||
sys.exit(1) | ||
|
||
@demarcate | ||
def detectSoC(self): | ||
# hard-coded example | ||
self.__soc_name = "gfx906" | ||
self.__soc_name = "gfx908" | ||
self.__soc_name = "gfx90a" | ||
|
||
# instantiate underlying SoC support class | ||
if self.__soc_name == "gfx906": | ||
from soc_gfx906 import gfx906_soc | ||
self.__soc = gfx906_soc(self.__args) | ||
elif self.__soc_name == "gfx908": | ||
from soc_gfx908 import gfx908_soc | ||
self.__soc = gfx908_soc(self.__args) | ||
elif self.__soc_name == "gfx90a": | ||
from soc_gfx90a import gfx90a_soc | ||
self.__soc = gfx90a_soc(self.__args) | ||
else: | ||
logging.error("Unsupported SoC") | ||
sys.exit(1) | ||
|
||
logging.info("SoC = %s" % self.__soc_name) | ||
return | ||
|
||
def parseArgs(self): | ||
self.__args = "some arguments" | ||
return | ||
|
||
@demarcate | ||
def run_profiler(self): | ||
self.detectSoC() | ||
|
||
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) | ||
elif self.__profiler_mode == "rocscope": | ||
from profiler_rocscope import rocscope_profiler | ||
profiler = rocscope_profiler(self.__soc, self.__args) | ||
else: | ||
logging.error("Unsupported profiler") | ||
sys.exit(1) | ||
|
||
#----------------------- | ||
# run profiling workflow | ||
#----------------------- | ||
|
||
self.__soc.profiling_setup() | ||
profiler.pre_processing() | ||
profiler.run_profiling() | ||
profiler.post_processing() | ||
|
||
return | ||
|
||
@demarcate | ||
def update_DB(self): | ||
return | ||
|
||
@demarcate | ||
def run_analysis(self): | ||
|
||
self.detectSoC() | ||
|
||
logging.info("Analysis mode choie = %s" % self.__analyze_mode) | ||
|
||
if self.__analyze_mode == "cli": | ||
from analysis_cli import cli_analysis | ||
analyzer = cli_analysis(self.__args,self.__options) | ||
elif self.__analyze_mode == "webui": | ||
from analysis_webui import webui_analysis | ||
analyzer = webui_analysis(self.__args,self.__options) | ||
else: | ||
self.error("Unsupported anlaysis mode -> %s" % self.__analyze_mode) | ||
|
||
#----------------------- | ||
# run analysis workflow | ||
#----------------------- | ||
|
||
self.__soc.analysis_setup() | ||
analyzer.pre_processing() | ||
analyzer.run_analysis() | ||
|
||
return |
Oops, something went wrong.