From 76dc96d87afe2b914c0ce8a7bbee3a25b32a62eb Mon Sep 17 00:00:00 2001 From: coleramos425 Date: Tue, 22 Aug 2023 11:25:06 -0500 Subject: [PATCH] Patch llvm-cxxfilt detection in atypical rocm installs Signed-off-by: coleramos425 [ROCm/rocprofiler-compute commit: 7187218ed94eb1ce72e77ed7139ca46157210985] --- projects/rocprofiler-compute/src/common.py | 26 +++++++++++++++++++ projects/rocprofiler-compute/src/omniperf | 24 +++-------------- .../src/utils/csv_processor.py | 19 +++++++++++++- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/projects/rocprofiler-compute/src/common.py b/projects/rocprofiler-compute/src/common.py index 70cdcd8239..e39a8c69cd 100644 --- a/projects/rocprofiler-compute/src/common.py +++ b/projects/rocprofiler-compute/src/common.py @@ -37,6 +37,32 @@ SOC_LIST = ["mi50", "mi100", "mi200", "vega10"] DISTRO_MAP = {"platform:el8": "rhel8", "15.3": "sle15sp3", "20.04": "ubuntu20_04"} +def resolve_rocprof(returnPath=False): + # ROCPROF INFO + if not "ROCPROF" in os.environ.keys(): + rocprof_cmd = "rocprof" + else: + rocprof_cmd = os.environ["ROCPROF"] + + rocprof_path = subprocess.run( + ["which", rocprof_cmd], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL + ) + if rocprof_path.returncode != 0: + print("\nError: Unable to resolve path to %s binary" % rocprof_cmd) + print( + "Please verify installation or set ROCPROF environment variable with full path." + ) + sys.exit(1) + else: + # Resolve any sym links in file path + rocprof_path = os.path.realpath(rocprof_path.stdout.decode("utf-8").rstrip("\n")) + print("ROC Profiler: ", rocprof_path) + if returnPath: + return rocprof_path + else: + return rocprof_cmd + + def getVersion(): # symantic version info version = os.path.join(OMNIPERF_HOME.parent, "VERSION") diff --git a/projects/rocprofiler-compute/src/omniperf b/projects/rocprofiler-compute/src/omniperf index 4aac533885..b63cf093bd 100755 --- a/projects/rocprofiler-compute/src/omniperf +++ b/projects/rocprofiler-compute/src/omniperf @@ -43,6 +43,7 @@ from utils import remove_workload from utils import csv_processor # Import workload from omniperf_analyze.omniperf_analyze import roofline_only # Standalone roofline from omniperf_analyze.omniperf_analyze import analyze # CLI analysis +from common import resolve_rocprof from common import ( OMNIPERF_HOME, @@ -102,26 +103,6 @@ def capture_subprocess_output(subprocess_args): return (success, output) -def resolve_rocprof(): - # ROCPROF INFO - global rocprof_cmd - if not "ROCPROF" in os.environ.keys(): - rocprof_cmd = "rocprof" - else: - rocprof_cmd = os.environ["ROCPROF"] - - rocprof_path = subprocess.run( - ["which", rocprof_cmd], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL - ) - if rocprof_path.returncode != 0: - print("\nError: Unable to resolve path to %s binary" % rocprof_cmd) - print( - "Please verify installation or set ROCPROF environment variable with full path." - ) - sys.exit(1) - - print("ROC Profiler: ", rocprof_path.stdout.decode("utf-8")) - def get_soc(): mspec = specs.get_machine_specs(0) @@ -747,7 +728,8 @@ def main(): if args.mode == "profile": Extractionlvl = args.kernelVerbose print("Resolving rocprof") - resolve_rocprof() + global rocprof_cmd + rocprof_cmd = resolve_rocprof() # Cannot access parent directories if ".." in str(args.path): throw_parse_error( diff --git a/projects/rocprofiler-compute/src/utils/csv_processor.py b/projects/rocprofiler-compute/src/utils/csv_processor.py index cc38804460..c61407bb64 100644 --- a/projects/rocprofiler-compute/src/utils/csv_processor.py +++ b/projects/rocprofiler-compute/src/utils/csv_processor.py @@ -33,6 +33,7 @@ import getpass from pymongo import MongoClient from tqdm import tqdm import glob +from common import resolve_rocprof cache = dict() @@ -40,6 +41,7 @@ supported_arch = {"gfx906": "mi50", "gfx908": "mi100", "gfx90a": "mi200"} MAX_SERVER_SEL_DELAY = 5000 # 5 sec connection timeout +# Note: shortener is now dependent on a rocprof install with llvm def kernel_name_shortener(workload_dir, level): def shorten_file(df, level): global cache @@ -57,7 +59,7 @@ def kernel_name_shortener(workload_dir, level): if original_name in cache: continue - cmd = ["/opt/rocm/llvm/bin/llvm-cxxfilt", original_name] + cmd = [llvm_filt, original_name] proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE @@ -125,6 +127,19 @@ def kernel_name_shortener(workload_dir, level): # Only shorten if valid shortening level if level < 5: + returnPath = True + rocprof_path = resolve_rocprof(returnPath) + # Given expected rocprof dir format (ie '/opt/rocm-x.x.x/bin/rocprof') navigate to llvm in parent + rocm_dir = os.path.abspath(os.path.join(rocprof_path, os.pardir, os.pardir)) + llvm_filt = os.path.join(rocm_dir, "llvm", "bin", "llvm-cxxfilt") + if not os.path.isfile(llvm_filt): + print( + "Error: Could not resolve llvm-cxxfilt in rocm install: {}".format( + llvm_filt + ) + ) + sys.exit(0) + for fpath in glob.glob(workload_dir + "/*.csv"): try: orig_df = pd.read_csv( @@ -137,6 +152,8 @@ def kernel_name_shortener(workload_dir, level): except pd.errors.EmptyDataError: print("Skipping empty csv " + str(fpath)) + print("KernelName shortening complete!") + # Verify target directory and setup connection def parse(args, profileAndExport):