75a4b51d0d
* Check that the minimum required Python (3.8) version is used. Prints a descriptive error message, rather than a cryptic import failure, if minimum Python version is not met. Internal ticket SWDEV-477233. * Disable the RPM mangling of shebangs. The are changing the `#!/usr/bin/python3` to `#!/usr/libexec/platform-python`. With this set, omniperf is always using the platform installed version of python, which is python 3.6 on RHEL 8. Using virtual environments, like conda, did not work. * Fix pylint issues --------- Signed-off-by: David Galiffi <David.Galiffi@amd.com>
154 satır
5.4 KiB
Python
Çalıştırılabilir Dosya
154 satır
5.4 KiB
Python
Çalıştırılabilir Dosya
#!/usr/bin/env python3
|
|
|
|
"""Main entry point for omniperf"""
|
|
|
|
##############################################################################bl
|
|
# MIT License
|
|
#
|
|
# Copyright (c) 2021 - 2024 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
|
|
import os
|
|
import sys
|
|
import re
|
|
|
|
try:
|
|
from pathlib import Path
|
|
from importlib import metadata
|
|
from omniperf_base import Omniperf
|
|
from utils.utils import console_error
|
|
except ImportError as e:
|
|
# print("Failed to import required modules: " + str(e))
|
|
pass
|
|
|
|
|
|
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
|
|
|
|
|
|
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."""
|
|
|
|
# Check which version of python is being used
|
|
if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 8):
|
|
print("[ERROR] Python 3.8 or higher is required to run omniperf."
|
|
f" The current version is {sys.version_info[0]}.{sys.version_info[1]}.")
|
|
sys.exit(1)
|
|
|
|
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):
|
|
with open(checkFile, "r", encoding="utf-8") as file_in:
|
|
dependencies = file_in.read().splitlines()
|
|
|
|
error = False
|
|
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(
|
|
f"[ERROR] The '{dependency}' package was not found "
|
|
"in the current execution environment."
|
|
)
|
|
|
|
# check version requirement
|
|
if not error:
|
|
if desiredVersion:
|
|
if not verify_deps_version(
|
|
localVersion, desiredVersion, operator
|
|
):
|
|
print(
|
|
f"[ERROR] the '{dependency}' distribution does "
|
|
"not meet version requirements to use omniperf."
|
|
)
|
|
print(" --> version installed :", localVersion)
|
|
error = True
|
|
|
|
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(f"See: {checkFile}")
|
|
sys.exit(1)
|
|
return
|
|
|
|
|
|
def main():
|
|
'''Main function for omniperf'''
|
|
|
|
# verify required python dependencies
|
|
verify_deps()
|
|
|
|
omniperf = Omniperf()
|
|
|
|
mode = omniperf.get_mode()
|
|
|
|
# major omniperf execution modes
|
|
if mode == "profile":
|
|
omniperf.run_profiler()
|
|
elif mode == "database":
|
|
omniperf.update_db()
|
|
elif mode == "analyze":
|
|
omniperf.run_analysis()
|
|
else:
|
|
console_error("Unsupported execution mode")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|