Skip to content

Commit cd92efa

Browse files
committed
[mlir][tosa] Add specification versioning to target environment
This commit adds a new "specification_version" field to the TOSA target environment attribute. This allows a user to specify which version of the TOSA specification they would like to target during lowering. A leading example in the validation pass has also been added. This addition adds a version to each profile compliance entry to track which version of the specification the entry was added. This allows a backwards compatibility check to be implemented between the target version and the profile compliance entry version. For now a default version of "1.0" is assumed. "1.1.draft" is added to denote an in-development version of the specification targeting the next release. Change-Id: I6549e05bd4fe975d12ea31e8acc783233db66171
1 parent 9d0903b commit cd92efa

File tree

11 files changed

+835
-487
lines changed

11 files changed

+835
-487
lines changed

mlir/include/mlir/Dialect/Tosa/IR/TargetEnv.h

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,63 @@ TargetEnvAttr getDefaultTargetEnv(MLIRContext *context);
5050
/// returned by getDefaultTargetEnv() if not provided.
5151
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op);
5252

53+
/// A thin wrapper around the SpecificationVersion enum to represent
54+
/// and provide utilities around the TOSA specification version.
55+
class TosaSpecificationVersion {
56+
public:
57+
TosaSpecificationVersion(uint32_t major, uint32_t minor)
58+
: majorVersion(major), minorVersion(minor) {}
59+
TosaSpecificationVersion(SpecificationVersion version)
60+
: TosaSpecificationVersion(fromVersionEnum(version)) {}
61+
62+
bool isBackwardsCompatibleWith(TosaSpecificationVersion baseVersion) const {
63+
return this->majorVersion == baseVersion.majorVersion &&
64+
this->minorVersion >= baseVersion.minorVersion;
65+
}
66+
67+
uint32_t getMajor() const { return majorVersion; }
68+
uint32_t getMinor() const { return minorVersion; }
69+
70+
private:
71+
uint32_t majorVersion = 0;
72+
uint32_t minorVersion = 0;
73+
74+
static TosaSpecificationVersion
75+
fromVersionEnum(SpecificationVersion version) {
76+
switch (version) {
77+
case SpecificationVersion::V_1_0:
78+
return TosaSpecificationVersion(1, 0);
79+
case SpecificationVersion::V_1_1_DRAFT:
80+
return TosaSpecificationVersion(1, 1);
81+
}
82+
llvm_unreachable("Unknown TOSA version");
83+
}
84+
};
85+
86+
llvm::SmallString<4> stringifyVersion(TosaSpecificationVersion version);
87+
5388
/// This class represents the capability enabled in the target implementation
5489
/// such as profile, extension, and level. It's a wrapper class around
5590
/// tosa::TargetEnvAttr.
5691
class TargetEnv {
5792
public:
5893
TargetEnv() {}
59-
explicit TargetEnv(Level level, const ArrayRef<Profile> &profiles,
94+
explicit TargetEnv(SpecificationVersion specificationVersion, Level level,
95+
const ArrayRef<Profile> &profiles,
6096
const ArrayRef<Extension> &extensions)
61-
: level(level) {
97+
: specificationVersion(specificationVersion), level(level) {
6298
enabledProfiles.insert_range(profiles);
6399
enabledExtensions.insert_range(extensions);
64100
}
65101

66102
explicit TargetEnv(TargetEnvAttr targetAttr)
67-
: TargetEnv(targetAttr.getLevel(), targetAttr.getProfiles(),
68-
targetAttr.getExtensions()) {}
103+
: TargetEnv(targetAttr.getSpecificationVersion(), targetAttr.getLevel(),
104+
targetAttr.getProfiles(), targetAttr.getExtensions()) {}
69105

70106
void addProfile(Profile p) { enabledProfiles.insert(p); }
71107
void addExtension(Extension e) { enabledExtensions.insert(e); }
72108

73-
// TODO implement the following utilities.
74-
// Version getSpecVersion() const;
109+
SpecificationVersion getSpecVersion() const { return specificationVersion; }
75110

76111
TosaLevel getLevel() const {
77112
if (level == Level::eightK)
@@ -105,6 +140,7 @@ class TargetEnv {
105140
}
106141

107142
private:
143+
SpecificationVersion specificationVersion;
108144
Level level;
109145
llvm::SmallSet<Profile, 3> enabledProfiles;
110146
llvm::SmallSet<Extension, 13> enabledExtensions;

0 commit comments

Comments
 (0)