From ecce5ccdd5725bd0669c24742bfd46dbf043fec2 Mon Sep 17 00:00:00 2001 From: Matthias Gehre Date: Tue, 14 May 2024 08:28:41 +0200 Subject: [PATCH] TosaToLinalg: Allow to skip the TOSA validation pass (#91742) Allow to skip running the TOSA validation pass when spec conformance is not required. --- .../mlir/Conversion/TosaToLinalg/TosaToLinalg.h | 5 +++-- .../Conversion/TosaToLinalg/TosaToLinalgPass.cpp | 14 ++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/mlir/include/mlir/Conversion/TosaToLinalg/TosaToLinalg.h b/mlir/include/mlir/Conversion/TosaToLinalg/TosaToLinalg.h index 5fd77c8a0211a6..67965e34d8a3d7 100644 --- a/mlir/include/mlir/Conversion/TosaToLinalg/TosaToLinalg.h +++ b/mlir/include/mlir/Conversion/TosaToLinalg/TosaToLinalg.h @@ -38,8 +38,9 @@ void addTosaToLinalgPasses( const TosaToLinalgNamedOptions &tosaToLinalgNamedOptions = TosaToLinalgNamedOptions(), // Note: Default to 'none' level unless otherwise specified. - tosa::TosaValidationOptions const &validationOptions = { - tosa::TosaProfileEnum::Undefined, false, tosa::TosaLevelEnum::None}); + std::optional validationOptions = + tosa::TosaValidationOptions{tosa::TosaProfileEnum::Undefined, false, + tosa::TosaLevelEnum::None}); /// Populates TOSA to linalg pipelines /// Currently, this includes only the "tosa-to-linalg-pipeline". diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp index ad7f6cf84e5edc..8904e3253922c0 100644 --- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp +++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp @@ -78,7 +78,7 @@ std::unique_ptr mlir::tosa::createTosaToLinalg() { void mlir::tosa::addTosaToLinalgPasses( OpPassManager &pm, const TosaToLinalgOptions &options, const TosaToLinalgNamedOptions &tosaToLinalgNamedOptions, - tosa::TosaValidationOptions const &validationOptions) { + std::optional validationOptions) { // Optional decompositions are designed to benefit linalg. if (!options.disableTosaDecompositions) pm.addNestedPass(tosa::createTosaOptionalDecompositions()); @@ -93,7 +93,8 @@ void mlir::tosa::addTosaToLinalgPasses( pm.addNestedPass(tosa::createTosaLayerwiseConstantFoldPass( {options.aggressiveReduceConstant})); pm.addNestedPass(tosa::createTosaMakeBroadcastablePass()); - pm.addPass(tosa::createTosaValidation(validationOptions)); + if (validationOptions) + pm.addPass(tosa::createTosaValidation(*validationOptions)); pm.addNestedPass(tosa::createTosaToLinalg()); } @@ -110,11 +111,12 @@ void mlir::tosa::registerTosaToLinalgPipelines() { [](OpPassManager &pm) { TosaToLinalgOptions tosaToLinalgOptions; TosaToLinalgNamedOptions tosaToLinalgNamedOptions; + TosaValidationOptions validationOptions; + validationOptions.profile = tosa::TosaProfileEnum::BaseInference; + validationOptions.StrictOperationSpecAlignment = true; + validationOptions.level = tosa::TosaLevelEnum::EightK; tosa::addTosaToLinalgPasses(pm, tosaToLinalgOptions, tosaToLinalgNamedOptions, - /* validationOptions = */ - {tosa::TosaProfileEnum::BaseInference, - /* StrictOperationSpecAlignment = */ true, - tosa::TosaLevelEnum::EightK}); + validationOptions); }); }