Skip to content

Commit 1752450

Browse files
Fix nightly CI issues when rocprof is disabled (#2057)
* Fallback to benchmarking with rocprof if perfConfig is empty and fix tuning-driver output parsing.
1 parent 964983e commit 1752450

File tree

2 files changed

+38
-41
lines changed

2 files changed

+38
-41
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// RUN: rocmlir-gen --operation gemm --arch %arch -t f32 -out_datatype f32 -transA=false -transB=false -g 1 -m 384 -n 768 -k 3072 --perf_config="v3:32,64,8,32,16,8,1,1,2,1,1" | rocmlir-tuning-driver --benchmark-config="v3:32,64,8,32,16,8,1,1,2,1,1" | FileCheck %s
2-
// CHECK: {{v3:32,64,8,32,16,8,1,1,2,1,1[\t ].*}}
1+
// RUN: rocmlir-gen --operation gemm --arch %arch -t f16 -out_datatype f16 -transA=false -transB=false -g 1 -m 384 -n 768 -k 3072 --perf_config="v3:32,64,8,32,16,8,1,1,2,1,1" | rocmlir-tuning-driver --benchmark-config="v3:32,64,8,32,16,8,1,1,2,1,1" | FileCheck %s
2+
// CHECK: {{v3:32,64,8,32,16,8,1,1,2,1,1[\t ]+[0-9].*}}
33
// CHECK-EMPTY:

mlir/utils/performance/perfRunner.py

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,8 +1597,10 @@ def run_config_with_mlir(config: PerfConfiguration,
15971597
if debug:
15981598
print("Running MLIR Benchmark: ", repr(config))
15991599

1600-
# Use HIP timing via tuning-driver if rocprof is disabled
1601-
if not use_rocprof:
1600+
nanoseconds = np.nan
1601+
1602+
# Use HIP timing via tuning-driver if rocprof is disabled and perfconfig is present
1603+
if not use_rocprof and config.perfconfig:
16021604
if debug:
16031605
print("Using HIP timing for benchmarking")
16041606
rocmlir_gen_cmd = paths.mlir_paths.rocmlir_gen_path + ' ' + commandline_options
@@ -1609,36 +1611,31 @@ def run_config_with_mlir(config: PerfConfiguration,
16091611
]
16101612
outs, noerr = run_pipeline([rocmlir_gen_cmd.split(), tuning_driver_command])
16111613
if noerr:
1612-
result = outs.decode().strip()
1613-
if result != "N/A":
1614-
try:
1615-
parts = result.split('\t')
1616-
if len(parts) == 2:
1617-
return float(parts[1])
1618-
else:
1619-
return float(result)
1620-
except ValueError:
1621-
if debug:
1622-
print(f"Failed to parse timing result: {result}")
1623-
return np.nan
1624-
1625-
if debug:
1626-
print("Using rocprof for benchmarking")
1627-
rocmlir_gen_cmd = paths.mlir_paths.rocmlir_gen_path + ' -ph ' + commandline_options
1628-
rocmlir_driver_cmd = [paths.mlir_paths.rocmlir_driver_path, '-c']
1629-
mlir_cpu_runner_args = [
1630-
f'--shared-libs={paths.mlir_paths.libmlir_rocm_runtime_path},{paths.mlir_paths.libconv_validation_wrappers_path},{paths.mlir_paths.libmlir_runtime_utils_path},{paths.mlir_paths.libmlir_c_runner_utils_path}',
1631-
'--entry-point-result=void'
1632-
]
1633-
profiler_cmd = [ROCPROF] + get_metric_args_for_rocprof(arch) + [
1634-
'--kernel-trace', '--stats', '-f', 'csv', '-o', BENCHMARKING_RESULT_FILE_NAME, '--',
1635-
paths.mlir_paths.cpu_runner_path
1636-
] + mlir_cpu_runner_args
1614+
try:
1615+
_, time = outs.split()
1616+
if time != "N/A":
1617+
nanoseconds = float(time)
1618+
except ValueError:
1619+
if debug:
1620+
print(f"Failed to parse timing result: {outs}")
1621+
else:
1622+
if debug:
1623+
print("Using rocprof for benchmarking")
1624+
rocmlir_gen_cmd = paths.mlir_paths.rocmlir_gen_path + ' -ph ' + commandline_options
1625+
rocmlir_driver_cmd = [paths.mlir_paths.rocmlir_driver_path, '-c']
1626+
mlir_cpu_runner_args = [
1627+
f'--shared-libs={paths.mlir_paths.libmlir_rocm_runtime_path},{paths.mlir_paths.libconv_validation_wrappers_path},{paths.mlir_paths.libmlir_runtime_utils_path},{paths.mlir_paths.libmlir_c_runner_utils_path}',
1628+
'--entry-point-result=void'
1629+
]
1630+
profiler_cmd = [ROCPROF] + get_metric_args_for_rocprof(arch) + [
1631+
'--kernel-trace', '--stats', '-f', 'csv', '-o', BENCHMARKING_RESULT_FILE_NAME, '--',
1632+
paths.mlir_paths.cpu_runner_path
1633+
] + mlir_cpu_runner_args
16371634

1638-
outs, noerr = run_pipeline([rocmlir_gen_cmd.split(), rocmlir_driver_cmd, profiler_cmd])
1639-
nanoseconds = np.nan
1640-
if noerr:
1641-
nanoseconds = get_nanoseconds(get_profiler_output_path(arch, BENCHMARKING_STATS_FILE_NAME))
1635+
outs, noerr = run_pipeline([rocmlir_gen_cmd.split(), rocmlir_driver_cmd, profiler_cmd])
1636+
if noerr:
1637+
nanoseconds = get_nanoseconds(
1638+
get_profiler_output_path(arch, BENCHMARKING_STATS_FILE_NAME))
16421639

16431640
return nanoseconds
16441641

@@ -1805,8 +1802,8 @@ def get_fusion_test_info(filename, paths: Paths):
18051802
if "-migraphx-to-tosa" in rocmlir_cmd:
18061803
rocmliropt_cmd = [paths.mlir_paths.rocmlir_opt_path, '-migraphx-to-tosa']
18071804
rocmlir_driver_cmd = [
1808-
paths.mlir_paths.rocmlir_driver_path, '-host-pipeline', 'highlevel',
1809-
'-kernel-pipeline', 'highlevel', '-targets', chip
1805+
paths.mlir_paths.rocmlir_driver_path, '-host-pipeline', 'highlevel', '-kernel-pipeline',
1806+
'highlevel', '-targets', chip
18101807
]
18111808
# rocmlir-opt -migraphx-to-tosa ../mlir/test/fusion/resnet50-e2e/mixr-resnet-fusion-case-1.mlir
18121809
p1 = subprocess.Popen(rocmliropt_cmd,
@@ -1840,8 +1837,8 @@ def get_fusion_test_info(filename, paths: Paths):
18401837
p1.stdout.close()
18411838
else:
18421839
rocmlir_driver_cmd = [
1843-
paths.mlir_paths.rocmlir_driver_path, '-host-pipeline', 'highlevel',
1844-
'-kernel-pipeline', 'highlevel', '-targets', chip
1840+
paths.mlir_paths.rocmlir_driver_path, '-host-pipeline', 'highlevel', '-kernel-pipeline',
1841+
'highlevel', '-targets', chip
18451842
]
18461843
# rocmlir-driver -host-pipeline highlevel -targets gfx90a
18471844
p2 = subprocess.Popen(rocmlir_driver_cmd,
@@ -1879,8 +1876,8 @@ def run_fusion_kernel(filename, rocmlir_gen_args, paths: Paths):
18791876
rocmliropt_cmd = [paths.mlir_paths.rocmlir_opt_path, '-migraphx-to-tosa', filename]
18801877
commands.append(rocmliropt_cmd)
18811878
rocmlir_driver_cmd = [
1882-
paths.mlir_paths.rocmlir_driver_path, '-host-pipeline', 'highlevel',
1883-
'-kernel-pipeline', 'highlevel' '-targets', chip
1879+
paths.mlir_paths.rocmlir_driver_path, '-host-pipeline', 'highlevel', '-kernel-pipeline',
1880+
'highlevel', '-targets', chip
18841881
]
18851882
commands.append(rocmlir_driver_cmd)
18861883
elif "migraphx" in rocmlir_cmd:
@@ -1895,8 +1892,8 @@ def run_fusion_kernel(filename, rocmlir_gen_args, paths: Paths):
18951892
commands.append(rocmlir_driver_cmd)
18961893
else:
18971894
rocmlir_driver_cmd = [
1898-
paths.mlir_paths.rocmlir_driver_path, '-host-pipeline', 'highlevel',
1899-
'-kernel-pipeline', 'highlevel', '-targets', chip
1895+
paths.mlir_paths.rocmlir_driver_path, '-host-pipeline', 'highlevel', '-kernel-pipeline',
1896+
'highlevel', '-targets', chip
19001897
]
19011898
commands.append(rocmlir_driver_cmd)
19021899

0 commit comments

Comments
 (0)