Skip to content

[mlir][tosa] Change the type of profile option to ListOption #111214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mlir/include/mlir/Conversion/TosaToLinalg/TosaToLinalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void addTosaToLinalgPasses(
TosaToLinalgNamedOptions(),
// Note: Default to 'none' level unless otherwise specified.
std::optional<tosa::TosaValidationOptions> validationOptions =
tosa::TosaValidationOptions{tosa::TosaProfileEnum::Undefined, false,
tosa::TosaLevelEnum::None});
tosa::TosaValidationOptions{
{"none"}, false, tosa::TosaLevelEnum::None});

/// Populates TOSA to linalg pipelines
/// Currently, this includes only the "tosa-to-linalg-pipeline".
Expand Down
17 changes: 3 additions & 14 deletions mlir/include/mlir/Dialect/Tosa/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def TosaProfileType : I32EnumAttr<"TosaProfileEnum", "Tosa profile",
I32EnumAttrCase<"BaseInference", 0, "bi">,
I32EnumAttrCase<"MainInference", 1, "mi">,
I32EnumAttrCase<"MainTraining", 2, "mt">,
I32EnumAttrCase<"Undefined", 3>
I32EnumAttrCase<"Undefined", 3, "none">
]>{
let cppNamespace = "mlir::tosa";
}
Expand All @@ -97,19 +97,8 @@ def TosaValidation : Pass<"tosa-validate", "mlir::ModuleOp"> {
}];

let options = [
Option<"profile", "profile", "mlir::tosa::TosaProfileEnum",
/*default=*/"mlir::tosa::TosaProfileEnum::Undefined",
"Validate if operations match for the given profile",
[{::llvm::cl::values(
clEnumValN(mlir::tosa::TosaProfileEnum::BaseInference, "bi",
"Use Base Inference profile."),
clEnumValN(mlir::tosa::TosaProfileEnum::MainInference, "mi",
"Use Main Inference profile."),
clEnumValN(mlir::tosa::TosaProfileEnum::MainTraining, "mt",
"Use Main Training profile."),
clEnumValN(mlir::tosa::TosaProfileEnum::Undefined, "undefined",
"Do not define a profile.")
)}]>,
ListOption<"profile", "profile", "std::string",
"Validate if operations match for the given profile set">,
Option<"StrictOperationSpecAlignment", "strict-op-spec-alignment", "bool",
/*default=*/"false",
"Verify if the properties of certain operations align the spec requirement">,
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void mlir::tosa::registerTosaToLinalgPipelines() {
TosaToLinalgOptions tosaToLinalgOptions;
TosaToLinalgNamedOptions tosaToLinalgNamedOptions;
TosaValidationOptions validationOptions;
validationOptions.profile = tosa::TosaProfileEnum::BaseInference;
validationOptions.profile = {"none"};
validationOptions.StrictOperationSpecAlignment = true;
validationOptions.level = tosa::TosaLevelEnum::EightK;
tosa::addTosaToLinalgPasses(pm, tosaToLinalgOptions,
Expand Down
16 changes: 15 additions & 1 deletion mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,28 @@ struct TosaValidation : public tosa::impl::TosaValidationBase<TosaValidation> {
if (level == TosaLevelEnum::EightK) {
tosaLevel = TOSA_LEVEL_EIGHTK;
}

if (!profile.empty()) {
for (std::string &prof : profile) {
auto profSymbol = symbolizeTosaProfileEnum(prof);
if (profSymbol) {
enabled_profiles.push_back(profSymbol.value());
}
}
}
}

bool CheckVariable(Operation *op);
bool CheckVariableReadOrWrite(Operation *op);

bool isValidElementType(Type type);
bool isEnabledProfile(TosaProfileEnum prof) {
return std::find(enabled_profiles.begin(), enabled_profiles.end(), prof) !=
std::end(enabled_profiles);
}

SmallVector<std::function<LogicalResult(Operation *)>> constCheckers;
SmallVector<TosaProfileEnum, 3> enabled_profiles;
TosaLevel tosaLevel;
DenseMap<StringAttr, mlir::Type> variablesMap;
};
Expand Down Expand Up @@ -507,7 +521,7 @@ LogicalResult TosaValidation::applyVariableCheck(Operation *op) {

bool TosaValidation::isValidElementType(Type type) {
if (isa<FloatType>(type)) {
if (profile == TosaProfileEnum::BaseInference)
if (!isEnabledProfile(TosaProfileEnum::MainInference))
return false;
return type.isF32() || type.isF16() || type.isBF16();
}
Expand Down
8 changes: 7 additions & 1 deletion mlir/test/Dialect/Tosa/invalid.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate=strict-op-spec-alignment
//--------------------------------------------------------------------------------------------------
// Test expected errors in terms of the shape and type of tensor, and the argument type of
// operation. Excludes the profile compilance checking since it is performed earlier in the
// validation flow.
//--------------------------------------------------------------------------------------------------

// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate="profile=bi,mi,mt strict-op-spec-alignment"


func.func @test_const() -> tensor<1xf32> {
Expand Down
6 changes: 5 additions & 1 deletion mlir/test/Dialect/Tosa/level_check.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate
//--------------------------------------------------------------------------------------------------
// Enable all supported profiles to focus the verification of expected level errors.
//--------------------------------------------------------------------------------------------------

// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate="profile=bi,mi,mt"


func.func @test_argmax(%arg0: tensor<1x1x1x1x29x29x4xf32>) -> tensor<1x1x1x1x29x4xi32> {
Expand Down
Loading