Make NNAPI Version more structured -- hal
Prior to this topic, NNAPI Versions were linear and represented by an
enumeration. However, this did not properly account for the
non-linearity of runtime-specific features such as a control flow
operations with operands of dynamic sizes. This topic alters Version to
be a struct containing a feature level enumeration as well as a boolean
which indicates whether there are runtime-specific features.
Bug: 206975939
Test: mma
Test: NeuralNetworksTests_static
Change-Id: I78c54ef597bf269b137f2835332bdedac49883d4
diff --git a/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h b/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h
index 1fb694b..4262ef8 100644
--- a/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h
+++ b/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h
@@ -30,7 +30,7 @@
constexpr auto kDefaultPriority = Priority::MEDIUM;
-constexpr std::optional<nn::Version> aidlVersionToCanonicalVersion(int aidlVersion) {
+inline std::optional<nn::Version> aidlVersionToCanonicalVersion(int aidlVersion) {
switch (aidlVersion) {
case 1:
return nn::Version::ANDROID_S;
@@ -41,7 +41,7 @@
}
}
-constexpr auto kVersion = aidlVersionToCanonicalVersion(IDevice::version).value();
+const auto kVersion = aidlVersionToCanonicalVersion(IDevice::version).value();
template <typename Type>
nn::Result<void> validate(const Type& halObject) {
@@ -64,7 +64,7 @@
template <typename Type>
nn::Result<void> compliantVersion(const Type& canonical) {
const auto version = NN_TRY(nn::validate(canonical));
- if (version > kVersion) {
+ if (!nn::isCompliantVersion(version, kVersion)) {
return NN_ERROR() << "Insufficient version: " << version << " vs required " << kVersion;
}
return {};
diff --git a/neuralnetworks/aidl/utils/test/DeviceTest.cpp b/neuralnetworks/aidl/utils/test/DeviceTest.cpp
index 79abe1b..19d2314 100644
--- a/neuralnetworks/aidl/utils/test/DeviceTest.cpp
+++ b/neuralnetworks/aidl/utils/test/DeviceTest.cpp
@@ -152,13 +152,15 @@
};
std::string printDeviceTest(const testing::TestParamInfo<nn::Version>& info) {
- switch (info.param) {
- case nn::Version::ANDROID_S:
+ const nn::Version version = info.param;
+ CHECK(!version.runtimeOnlyFeatures);
+ switch (version.level) {
+ case nn::Version::Level::ANDROID_S:
return "v1";
- case nn::Version::FEATURE_LEVEL_6:
+ case nn::Version::Level::FEATURE_LEVEL_6:
return "v2";
default:
- LOG(FATAL) << "Invalid AIDL version: " << info.param;
+ LOG(FATAL) << "Invalid AIDL version: " << version;
return "invalid";
}
}