Skip to content

Commit b82a207

Browse files
tatwaichongDanielCChen
authored andcommitted
[mlir][tosa] Change the type of profile option to ListOption (llvm#111214)
In tosa valiation pass, change the type of profile option to ListOption. Now TOSA profiles is turned from hierarchical to composable. Each profile is an independent set, i.e. an target can implement multiple profiles. Set the profile option to none by default, and limit to profiles if requested. The profiles can be specified via command line, e.g. $ mlir-opt ... --tosa-validate="profile=bi,mi" which tells the valiation pass that BI and MI are enabled. Change-Id: I1fb8d0c1b27eccd768349b6eb4234093313efb57
1 parent befc3ba commit b82a207

File tree

6 files changed

+33
-20
lines changed

6 files changed

+33
-20
lines changed

mlir/include/mlir/Conversion/TosaToLinalg/TosaToLinalg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ void addTosaToLinalgPasses(
3939
TosaToLinalgNamedOptions(),
4040
// Note: Default to 'none' level unless otherwise specified.
4141
std::optional<tosa::TosaValidationOptions> validationOptions =
42-
tosa::TosaValidationOptions{tosa::TosaProfileEnum::Undefined, false,
43-
tosa::TosaLevelEnum::None});
42+
tosa::TosaValidationOptions{
43+
{"none"}, false, tosa::TosaLevelEnum::None});
4444

4545
/// Populates TOSA to linalg pipelines
4646
/// Currently, this includes only the "tosa-to-linalg-pipeline".

mlir/include/mlir/Dialect/Tosa/Transforms/Passes.td

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def TosaProfileType : I32EnumAttr<"TosaProfileEnum", "Tosa profile",
7676
I32EnumAttrCase<"BaseInference", 0, "bi">,
7777
I32EnumAttrCase<"MainInference", 1, "mi">,
7878
I32EnumAttrCase<"MainTraining", 2, "mt">,
79-
I32EnumAttrCase<"Undefined", 3>
79+
I32EnumAttrCase<"Undefined", 3, "none">
8080
]>{
8181
let cppNamespace = "mlir::tosa";
8282
}
@@ -97,19 +97,8 @@ def TosaValidation : Pass<"tosa-validate", "mlir::ModuleOp"> {
9797
}];
9898

9999
let options = [
100-
Option<"profile", "profile", "mlir::tosa::TosaProfileEnum",
101-
/*default=*/"mlir::tosa::TosaProfileEnum::Undefined",
102-
"Validate if operations match for the given profile",
103-
[{::llvm::cl::values(
104-
clEnumValN(mlir::tosa::TosaProfileEnum::BaseInference, "bi",
105-
"Use Base Inference profile."),
106-
clEnumValN(mlir::tosa::TosaProfileEnum::MainInference, "mi",
107-
"Use Main Inference profile."),
108-
clEnumValN(mlir::tosa::TosaProfileEnum::MainTraining, "mt",
109-
"Use Main Training profile."),
110-
clEnumValN(mlir::tosa::TosaProfileEnum::Undefined, "undefined",
111-
"Do not define a profile.")
112-
)}]>,
100+
ListOption<"profile", "profile", "std::string",
101+
"Validate if operations match for the given profile set">,
113102
Option<"StrictOperationSpecAlignment", "strict-op-spec-alignment", "bool",
114103
/*default=*/"false",
115104
"Verify if the properties of certain operations align the spec requirement">,

mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void mlir::tosa::registerTosaToLinalgPipelines() {
115115
TosaToLinalgOptions tosaToLinalgOptions;
116116
TosaToLinalgNamedOptions tosaToLinalgNamedOptions;
117117
TosaValidationOptions validationOptions;
118-
validationOptions.profile = tosa::TosaProfileEnum::BaseInference;
118+
validationOptions.profile = {"none"};
119119
validationOptions.StrictOperationSpecAlignment = true;
120120
validationOptions.level = tosa::TosaLevelEnum::EightK;
121121
tosa::addTosaToLinalgPasses(pm, tosaToLinalgOptions,

mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,28 @@ struct TosaValidation : public tosa::impl::TosaValidationBase<TosaValidation> {
405405
if (level == TosaLevelEnum::EightK) {
406406
tosaLevel = TOSA_LEVEL_EIGHTK;
407407
}
408+
409+
if (!profile.empty()) {
410+
for (std::string &prof : profile) {
411+
auto profSymbol = symbolizeTosaProfileEnum(prof);
412+
if (profSymbol) {
413+
enabled_profiles.push_back(profSymbol.value());
414+
}
415+
}
416+
}
408417
}
409418

410419
bool CheckVariable(Operation *op);
411420
bool CheckVariableReadOrWrite(Operation *op);
412421

413422
bool isValidElementType(Type type);
423+
bool isEnabledProfile(TosaProfileEnum prof) {
424+
return std::find(enabled_profiles.begin(), enabled_profiles.end(), prof) !=
425+
std::end(enabled_profiles);
426+
}
414427

415428
SmallVector<std::function<LogicalResult(Operation *)>> constCheckers;
429+
SmallVector<TosaProfileEnum, 3> enabled_profiles;
416430
TosaLevel tosaLevel;
417431
DenseMap<StringAttr, mlir::Type> variablesMap;
418432
};
@@ -507,7 +521,7 @@ LogicalResult TosaValidation::applyVariableCheck(Operation *op) {
507521

508522
bool TosaValidation::isValidElementType(Type type) {
509523
if (isa<FloatType>(type)) {
510-
if (profile == TosaProfileEnum::BaseInference)
524+
if (!isEnabledProfile(TosaProfileEnum::MainInference))
511525
return false;
512526
return type.isF32() || type.isF16() || type.isBF16();
513527
}

mlir/test/Dialect/Tosa/invalid.mlir

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate=strict-op-spec-alignment
1+
//--------------------------------------------------------------------------------------------------
2+
// Test expected errors in terms of the shape and type of tensor, and the argument type of
3+
// operation. Excludes the profile compilance checking since it is performed earlier in the
4+
// validation flow.
5+
//--------------------------------------------------------------------------------------------------
6+
7+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate="profile=bi,mi,mt strict-op-spec-alignment"
28

39

410
func.func @test_const() -> tensor<1xf32> {

mlir/test/Dialect/Tosa/level_check.mlir

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate
1+
//--------------------------------------------------------------------------------------------------
2+
// Enable all supported profiles to focus the verification of expected level errors.
3+
//--------------------------------------------------------------------------------------------------
4+
5+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate="profile=bi,mi,mt"
26

37

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

0 commit comments

Comments
 (0)