diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt index a8e493e2397e..13bcf0c05310 100644 --- a/mlir/CMakeLists.txt +++ b/mlir/CMakeLists.txt @@ -53,6 +53,11 @@ add_subdirectory(lib) # C API needs all dialects for registration, but should be built before tests. add_subdirectory(lib/CAPI) +# Process utils before test so that targets defined there (e.g. +# ci-performance-scripts, which copies performance scripts onto the lit PATH) +# exist when the test suite registers its build dependencies. +add_subdirectory(utils) + if (MLIR_INCLUDE_TESTS) add_definitions(-DMLIR_INCLUDE_TESTS) add_custom_target(RocMLIRUnitTests) @@ -64,4 +69,3 @@ if (MLIR_INCLUDE_TESTS) add_subdirectory(test) endif() add_subdirectory(tools) -add_subdirectory(utils) diff --git a/mlir/test/CMakeLists.txt b/mlir/test/CMakeLists.txt index a11fbf077298..7a47173f84d6 100644 --- a/mlir/test/CMakeLists.txt +++ b/mlir/test/CMakeLists.txt @@ -114,6 +114,13 @@ if (TARGET amd_arch_db) list(APPEND ROCMLIR_TEST_DEPENDS amd_arch_db) endif() +# Performance scripts (e.g. tuningRunner.py) are copied into ROCMLIR_BIN_DIR, +# which is on the lit PATH, by the ci-performance-scripts target. Tests that +# invoke these scripts directly need them copied before the test suite runs. +if (TARGET ci-performance-scripts) + list(APPEND ROCMLIR_TEST_DEPENDS ci-performance-scripts) +endif() + if(MLIR_ENABLE_ROCM_RUNNER) list(APPEND ROCMLIR_TEST_DEPENDS mlir_runner_utils diff --git a/mlir/test/perf-scripts/runtime/tuningRunner-gemm.py b/mlir/test/perf-scripts/runtime/tuningRunner-gemm.py new file mode 100644 index 000000000000..f92f25a96a44 --- /dev/null +++ b/mlir/test/perf-scripts/runtime/tuningRunner-gemm.py @@ -0,0 +1,17 @@ +# Using a tiny GEMM with --debug-quick-tune-data. This emits a `.debug` +# TSV of the per-config table entries (PerfConfig + TFlops) but, unlike the +# full ``--debug`` flag, omits the heavy per-iteration ``MeasurementsMs`` +# arrays. Verify the debug file is produced, has the expected header and +# per-config rows, and that the measurements column is absent. +# +# tuningRunner.py drives real GPU tuning, so it needs the ROCm runner / GPU +# runtime. +# REQUIRES: rocm-runner +# RUN: rm -f %t2.tsv %t2.tsv.state %t2.tsv.debug +# RUN: tuningRunner.py --op gemm --tuning-space=quick --debug-quick-tune-data \ +# RUN: --config='-g 1 -m 64 -n 64 -k 64 -t f32 -out_datatype f32 -transA 0 -transB 0' \ +# RUN: -q -o %t2.tsv +# RUN: FileCheck %s --check-prefix=DEBUG --implicit-check-not=MeasurementsMs < %t2.tsv.debug +# +# DEBUG: PerfConfig{{.*}}TFlops +# DEBUG: {{v[0-9]+:}} diff --git a/mlir/utils/performance/tests/test_tuningRunner.py b/mlir/utils/performance/tests/test_tuningRunner.py index f74284f8d52c..de94136554a2 100644 --- a/mlir/utils/performance/tests/test_tuningRunner.py +++ b/mlir/utils/performance/tests/test_tuningRunner.py @@ -241,6 +241,7 @@ def _options(self, output_path, arch="gfx900", num_cu=64, num_chiplets=1, tuning num_cu=num_cu, num_chiplets=num_chiplets, debug=False, + debug_quick_tune_data=False, quiet=False, verbose=False, tuning_space_kind=tuning_space, @@ -452,6 +453,7 @@ def test_cache_loaded_with_canonical_key(self): num_cu=64, num_chiplets=1, debug=False, + debug_quick_tune_data=False, quiet=False, verbose=False, tuning_space_kind="full", diff --git a/mlir/utils/performance/tuningRunner.py b/mlir/utils/performance/tuningRunner.py index dc8c11e547a5..e792aa7fda45 100755 --- a/mlir/utils/performance/tuningRunner.py +++ b/mlir/utils/performance/tuningRunner.py @@ -169,6 +169,7 @@ def get_gpu_logger(gpu_id: int) -> logging.LoggerAdapter: class Options: """Configuration options for the tuning process.""" debug: bool + debug_quick_tune_data: bool tuning_space_kind: str quiet: bool verbose: bool @@ -1640,8 +1641,9 @@ def tune_configs(ctx: TuningContext, status_only: bool) -> bool: has_errors = False - debug_enabled = ctx.options.debug and ctx.options.output != '-' - if ctx.options.debug and not debug_enabled: + debug_requested = ctx.options.debug or ctx.options.debug_quick_tune_data + debug_enabled = debug_requested and ctx.options.output != '-' + if debug_requested and not debug_enabled: logger.warning("Debug output disabled when writing to stdout") with (OutputFileWriter(ctx.options.output, ctx.options) as results_writer, @@ -1939,7 +1941,13 @@ def parse_arguments(gpu_topology: GpuTopology, "--debug", action='store_true', default=False, - help="Enable debug output including detailed measurements") + help="Enable debug output including detailed per-iteration measurements") + + parser.add_argument("--debug-quick-tune-data", + action='store_true', + default=False, + help="Enable debug output for quick tuning data generation without the " + "detailed per-iteration measurement arrays") parser.add_argument("--tuning-space", default="full", @@ -2125,6 +2133,7 @@ def main(args=None): num_cu=num_cu, num_chiplets=num_chiplets, debug=parsed_args.debug, + debug_quick_tune_data=parsed_args.debug_quick_tune_data, quiet=parsed_args.quiet, verbose=parsed_args.verbose, tuning_space_kind=parsed_args.tuning_space,