2022-11-04 14:49:36 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
2023-02-13 09:26:12 -06:00
|
|
|
##############################################################################bl
|
2023-02-13 13:47:11 -06:00
|
|
|
# MIT License
|
2023-02-13 14:50:24 -06:00
|
|
|
#
|
2024-01-24 17:11:39 -06:00
|
|
|
# Copyright (c) 2021 - 2024 Advanced Micro Devices, Inc. All Rights Reserved.
|
2023-02-13 14:50:24 -06:00
|
|
|
#
|
2022-11-04 14:49:36 -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:
|
2023-02-13 14:50:24 -06:00
|
|
|
#
|
2023-02-13 13:47:11 -06:00
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
# copies or substantial portions of the Software.
|
2023-02-13 14:50:24 -06:00
|
|
|
#
|
2022-11-04 14:49:36 -05:00
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
2023-02-13 13:47:11 -06:00
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
2022-11-04 14:49:36 -05:00
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
2023-02-13 13:47:11 -06:00
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
# SOFTWARE.
|
2023-02-13 09:26:12 -06:00
|
|
|
##############################################################################el
|
2022-11-04 14:49:36 -05:00
|
|
|
|
2024-03-06 17:01:07 -06:00
|
|
|
import logging
|
2024-05-03 12:21:22 -05:00
|
|
|
import os
|
|
|
|
|
import sys
|
2024-05-20 15:00:50 -05:00
|
|
|
from pip._internal.req import parse_requirements
|
2024-05-03 12:21:22 -05:00
|
|
|
from pathlib import Path
|
2024-05-20 15:00:50 -05:00
|
|
|
from importlib import import_module, metadata
|
|
|
|
|
import re
|
2024-05-03 12:21:22 -05:00
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from omniperf_base import Omniperf
|
|
|
|
|
from utils.utils import console_error
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2024-05-20 15:00:50 -05:00
|
|
|
def verify_deps_version(localVer, desiredVer, operator):
|
|
|
|
|
"""Check package version strings with simple operators used in companion requirements.txt file"""
|
|
|
|
|
if operator == "==":
|
|
|
|
|
return localVer == desiredVer
|
|
|
|
|
elif operator == ">=":
|
|
|
|
|
return localVer >= desiredVer
|
|
|
|
|
elif operator == "<=":
|
|
|
|
|
return localVer <= desiredVer
|
|
|
|
|
elif operator == ">":
|
|
|
|
|
return localVer > desiredVer
|
|
|
|
|
elif operator == "<":
|
|
|
|
|
return localVer < desiredVer
|
|
|
|
|
else:
|
|
|
|
|
return True
|
|
|
|
|
|
2024-05-03 12:21:22 -05:00
|
|
|
|
2024-05-20 15:00:50 -05:00
|
|
|
def verify_deps():
|
|
|
|
|
"""Utility to read library dependencies from requirements.txt and endeavor to load them within current execution environment.
|
|
|
|
|
Used in top-level omniperf to provide error messages if necessary dependencies are not available. """
|
2024-05-03 12:21:22 -05:00
|
|
|
bindir = Path(__file__).resolve().parent
|
|
|
|
|
depsLocation = ["requirements.txt", "../requirements.txt"]
|
|
|
|
|
|
|
|
|
|
for location in depsLocation:
|
|
|
|
|
checkFile = os.path.join(bindir, location)
|
|
|
|
|
if os.path.exists(checkFile):
|
2024-05-23 17:49:45 +00:00
|
|
|
with open(checkFile, "r") as file_in:
|
|
|
|
|
dependencies = file_in.read().splitlines()
|
2024-05-03 12:21:22 -05:00
|
|
|
|
2024-05-23 17:49:45 +00:00
|
|
|
error = False
|
2024-05-20 15:00:50 -05:00
|
|
|
version_pattern = r"^([^=<>]+)([=<>]+)(.*)$"
|
|
|
|
|
|
|
|
|
|
for dependency in dependencies:
|
|
|
|
|
desiredVersion = None
|
|
|
|
|
match = re.match(version_pattern, dependency)
|
|
|
|
|
if match:
|
|
|
|
|
package = match.group(1)
|
|
|
|
|
operator = match.group(2) or None
|
|
|
|
|
desiredVersion = match.group(3) or None
|
|
|
|
|
else:
|
|
|
|
|
package = dependency
|
|
|
|
|
try:
|
|
|
|
|
localVersion = metadata.distribution(package).version
|
|
|
|
|
except metadata.PackageNotFoundError:
|
|
|
|
|
error = True
|
|
|
|
|
print(
|
|
|
|
|
"[ERROR] The '%s' package was not found in the current execution environment."
|
|
|
|
|
% dependency
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# check version requirement
|
|
|
|
|
if not error:
|
|
|
|
|
if desiredVersion:
|
|
|
|
|
if not verify_deps_version(
|
|
|
|
|
localVersion, desiredVersion, operator
|
|
|
|
|
):
|
|
|
|
|
print(
|
|
|
|
|
"[ERROR] the '%s' distribution does not meet version requirements to use omniperf."
|
|
|
|
|
% dependency
|
|
|
|
|
)
|
|
|
|
|
print(" --> version installed :", localVersion)
|
|
|
|
|
error = True
|
2024-05-03 12:21:22 -05:00
|
|
|
|
|
|
|
|
if error:
|
|
|
|
|
print("")
|
|
|
|
|
print(
|
|
|
|
|
"Please verify all of the python dependencies called out in the requirements file"
|
|
|
|
|
)
|
|
|
|
|
print("are installed locally prior to running omniperf.")
|
|
|
|
|
print("")
|
|
|
|
|
print("See: %s" % checkFile)
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
return
|
2022-11-04 14:49:36 -05:00
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
2024-05-03 12:21:22 -05:00
|
|
|
# verify required python dependencies
|
|
|
|
|
verify_deps()
|
|
|
|
|
|
2023-10-31 15:11:17 -05:00
|
|
|
omniperf = Omniperf()
|
2024-03-08 17:20:08 -06:00
|
|
|
|
2023-10-31 15:11:17 -05:00
|
|
|
mode = omniperf.get_mode()
|
2024-03-08 17:20:08 -06:00
|
|
|
|
2023-10-31 15:11:17 -05:00
|
|
|
# major omniperf execution modes
|
|
|
|
|
if mode == "profile":
|
|
|
|
|
omniperf.run_profiler()
|
|
|
|
|
elif mode == "database":
|
2024-01-30 10:43:30 -06:00
|
|
|
omniperf.update_db()
|
2023-10-31 15:11:17 -05:00
|
|
|
elif mode == "analyze":
|
|
|
|
|
omniperf.run_analysis()
|
|
|
|
|
else:
|
2024-01-30 17:25:16 -06:00
|
|
|
console_error("Unsupported execution mode")
|
2022-11-04 14:49:36 -05:00
|
|
|
|
2023-12-07 14:40:07 -06:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
2024-05-03 12:21:22 -05:00
|
|
|
|
2022-11-04 14:49:36 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|