From 60a7b86cf070a9f582ef36900e463f877fa784fe Mon Sep 17 00:00:00 2001 From: Michael Butler Date: Wed, 17 Nov 2021 16:33:35 -0800 Subject: [PATCH] Rename Version::ANDROID_* to kVersionFeatureLevel* -- hal Prior to this change, version constants (e.g., Version::ANDROID_S) were public static constants to make the version constants look as if they were enum values. However, this method prevented versions from being constexpr, because the Version type was incomplete by that point in time. This change moves these version constants outside of the Version struct, and makes them constexpr. They have the new names: * Version::ANDROID_OC_MR1 -> kVersionFeatureLevel1 * Version::ANDROID_P -> kVersionFeatureLevel2 * Version::ANDROID_Q -> kVersionFeatureLevel3 * Version::ANDROID_R -> kVersionFeatureLevel4 * Version::ANDROID_S -> kVersionFeatureLevel5 * Version::FEATURE_LEVEL_6 -> kVersionFeatureLevel6 * Version::EXPERIMENTAL -> kVersionFeatureLevelExperimental Bug: 206975939 Test: mma Change-Id: Ibf5f2fdb1459a69c51865aa5fdcd0cb0c3a88ade --- .../1.0/utils/include/nnapi/hal/1.0/Callbacks.h | 2 +- neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Utils.h | 2 +- neuralnetworks/1.0/utils/src/Device.cpp | 2 +- neuralnetworks/1.0/utils/test/DeviceTest.cpp | 2 +- neuralnetworks/1.1/utils/include/nnapi/hal/1.1/Utils.h | 2 +- neuralnetworks/1.1/utils/src/Device.cpp | 2 +- neuralnetworks/1.1/utils/test/DeviceTest.cpp | 2 +- .../1.2/utils/include/nnapi/hal/1.2/Callbacks.h | 3 ++- neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Utils.h | 2 +- neuralnetworks/1.2/utils/src/Device.cpp | 2 +- neuralnetworks/1.2/utils/test/DeviceTest.cpp | 2 +- .../1.3/utils/include/nnapi/hal/1.3/Callbacks.h | 3 ++- neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Utils.h | 2 +- neuralnetworks/1.3/utils/src/Device.cpp | 2 +- neuralnetworks/1.3/utils/test/DeviceTest.cpp | 2 +- neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h | 8 ++++---- neuralnetworks/aidl/utils/src/Callbacks.cpp | 3 ++- neuralnetworks/aidl/utils/test/DeviceTest.cpp | 4 ++-- neuralnetworks/utils/common/test/ResilientDeviceTest.cpp | 6 +++--- 19 files changed, 28 insertions(+), 25 deletions(-) diff --git a/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Callbacks.h b/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Callbacks.h index 1ab9dcb90a..244001f45b 100644 --- a/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Callbacks.h +++ b/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Callbacks.h @@ -41,7 +41,7 @@ nn::GeneralResult> supportedOperationsCallback( // Converts the results of IDevice::prepareModel* to the NN canonical format. On success, this // function returns with a non-null nn::SharedPreparedModel with a feature level of -// nn::Version::ANDROID_OC_MR1. On failure, this function returns with the appropriate +// nn::kVersionFeatureLevel1. On failure, this function returns with the appropriate // nn::GeneralError. nn::GeneralResult prepareModelCallback( ErrorStatus status, const sp& preparedModel); diff --git a/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Utils.h b/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Utils.h index ed7c3e7c29..7710a7eaa2 100644 --- a/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Utils.h +++ b/neuralnetworks/1.0/utils/include/nnapi/hal/1.0/Utils.h @@ -28,7 +28,7 @@ namespace android::hardware::neuralnetworks::V1_0::utils { -const auto kVersion = nn::Version::ANDROID_OC_MR1; +constexpr auto kVersion = nn::kVersionFeatureLevel1; template nn::Result validate(const Type& halObject) { diff --git a/neuralnetworks/1.0/utils/src/Device.cpp b/neuralnetworks/1.0/utils/src/Device.cpp index 49913a2584..b0c236efe8 100644 --- a/neuralnetworks/1.0/utils/src/Device.cpp +++ b/neuralnetworks/1.0/utils/src/Device.cpp @@ -99,7 +99,7 @@ const std::string& Device::getVersionString() const { } nn::Version Device::getFeatureLevel() const { - return nn::Version::ANDROID_OC_MR1; + return kVersion; } nn::DeviceType Device::getType() const { diff --git a/neuralnetworks/1.0/utils/test/DeviceTest.cpp b/neuralnetworks/1.0/utils/test/DeviceTest.cpp index e881da2c85..83e555fad5 100644 --- a/neuralnetworks/1.0/utils/test/DeviceTest.cpp +++ b/neuralnetworks/1.0/utils/test/DeviceTest.cpp @@ -233,7 +233,7 @@ TEST(DeviceTest, getFeatureLevel) { const auto featureLevel = device->getFeatureLevel(); // verify result - EXPECT_EQ(featureLevel, nn::Version::ANDROID_OC_MR1); + EXPECT_EQ(featureLevel, nn::kVersionFeatureLevel1); } TEST(DeviceTest, getCachedData) { diff --git a/neuralnetworks/1.1/utils/include/nnapi/hal/1.1/Utils.h b/neuralnetworks/1.1/utils/include/nnapi/hal/1.1/Utils.h index 3aebb9367d..ff06739f32 100644 --- a/neuralnetworks/1.1/utils/include/nnapi/hal/1.1/Utils.h +++ b/neuralnetworks/1.1/utils/include/nnapi/hal/1.1/Utils.h @@ -30,7 +30,7 @@ namespace android::hardware::neuralnetworks::V1_1::utils { constexpr auto kDefaultExecutionPreference = ExecutionPreference::FAST_SINGLE_ANSWER; -const auto kVersion = nn::Version::ANDROID_P; +constexpr auto kVersion = nn::kVersionFeatureLevel2; template nn::Result validate(const Type& halObject) { diff --git a/neuralnetworks/1.1/utils/src/Device.cpp b/neuralnetworks/1.1/utils/src/Device.cpp index 7d54cabeb9..3effa8428d 100644 --- a/neuralnetworks/1.1/utils/src/Device.cpp +++ b/neuralnetworks/1.1/utils/src/Device.cpp @@ -99,7 +99,7 @@ const std::string& Device::getVersionString() const { } nn::Version Device::getFeatureLevel() const { - return nn::Version::ANDROID_P; + return kVersion; } nn::DeviceType Device::getType() const { diff --git a/neuralnetworks/1.1/utils/test/DeviceTest.cpp b/neuralnetworks/1.1/utils/test/DeviceTest.cpp index 41e0e3050d..2248da6ffe 100644 --- a/neuralnetworks/1.1/utils/test/DeviceTest.cpp +++ b/neuralnetworks/1.1/utils/test/DeviceTest.cpp @@ -243,7 +243,7 @@ TEST(DeviceTest, getFeatureLevel) { const auto featureLevel = device->getFeatureLevel(); // verify result - EXPECT_EQ(featureLevel, nn::Version::ANDROID_P); + EXPECT_EQ(featureLevel, nn::kVersionFeatureLevel2); } TEST(DeviceTest, getCachedData) { diff --git a/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Callbacks.h b/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Callbacks.h index 6dd8138f64..fc04303726 100644 --- a/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Callbacks.h +++ b/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Callbacks.h @@ -38,7 +38,8 @@ namespace android::hardware::neuralnetworks::V1_2::utils { // Converts the results of IDevice::prepareModel* to the NN canonical format. On success, this // function returns with a non-null nn::SharedPreparedModel with a feature level of -// nn::Version::ANDROID_Q. On failure, this function returns with the appropriate nn::GeneralError. +// nn::kVersionFeatureLevel3. On failure, this function returns with the appropriate +// nn::GeneralError. nn::GeneralResult prepareModelCallback( V1_0::ErrorStatus status, const sp& preparedModel); diff --git a/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Utils.h b/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Utils.h index 7ec32e85c3..a06f2ac241 100644 --- a/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Utils.h +++ b/neuralnetworks/1.2/utils/include/nnapi/hal/1.2/Utils.h @@ -39,7 +39,7 @@ using V1_1::utils::kDefaultExecutionPreference; constexpr auto kDefaultMesaureTiming = MeasureTiming::NO; constexpr auto kNoTiming = Timing{.timeOnDevice = std::numeric_limits::max(), .timeInDriver = std::numeric_limits::max()}; -const auto kVersion = nn::Version::ANDROID_Q; +constexpr auto kVersion = nn::kVersionFeatureLevel3; template nn::Result validate(const Type& halObject) { diff --git a/neuralnetworks/1.2/utils/src/Device.cpp b/neuralnetworks/1.2/utils/src/Device.cpp index f12669a6dc..e7acecdf7a 100644 --- a/neuralnetworks/1.2/utils/src/Device.cpp +++ b/neuralnetworks/1.2/utils/src/Device.cpp @@ -192,7 +192,7 @@ const std::string& Device::getVersionString() const { } nn::Version Device::getFeatureLevel() const { - return nn::Version::ANDROID_Q; + return kVersion; } nn::DeviceType Device::getType() const { diff --git a/neuralnetworks/1.2/utils/test/DeviceTest.cpp b/neuralnetworks/1.2/utils/test/DeviceTest.cpp index 215d44c83f..1dc6285be5 100644 --- a/neuralnetworks/1.2/utils/test/DeviceTest.cpp +++ b/neuralnetworks/1.2/utils/test/DeviceTest.cpp @@ -483,7 +483,7 @@ TEST(DeviceTest, getFeatureLevel) { const auto featureLevel = device->getFeatureLevel(); // verify result - EXPECT_EQ(featureLevel, nn::Version::ANDROID_Q); + EXPECT_EQ(featureLevel, nn::kVersionFeatureLevel3); } TEST(DeviceTest, getCachedData) { diff --git a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Callbacks.h b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Callbacks.h index 4b8ddc1885..10892bc403 100644 --- a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Callbacks.h +++ b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Callbacks.h @@ -47,7 +47,8 @@ nn::GeneralResult> supportedOperationsCallback( // Converts the results of IDevice::prepareModel* to the NN canonical format. On success, this // function returns with a non-null nn::SharedPreparedModel with a feature level of -// nn::Version::ANDROID_R. On failure, this function returns with the appropriate nn::GeneralError. +// nn::kVersionFeatureLevel4. On failure, this function returns with the appropriate +// nn::GeneralError. nn::GeneralResult prepareModelCallback( ErrorStatus status, const sp& preparedModel); diff --git a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Utils.h b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Utils.h index 0ea3f29694..594d727d5d 100644 --- a/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Utils.h +++ b/neuralnetworks/1.3/utils/include/nnapi/hal/1.3/Utils.h @@ -39,7 +39,7 @@ using V1_2::utils::kDefaultMesaureTiming; using V1_2::utils::kNoTiming; constexpr auto kDefaultPriority = Priority::MEDIUM; -const auto kVersion = nn::Version::ANDROID_R; +constexpr auto kVersion = nn::kVersionFeatureLevel4; template nn::Result validate(const Type& halObject) { diff --git a/neuralnetworks/1.3/utils/src/Device.cpp b/neuralnetworks/1.3/utils/src/Device.cpp index a73ce82ed2..9517fda877 100644 --- a/neuralnetworks/1.3/utils/src/Device.cpp +++ b/neuralnetworks/1.3/utils/src/Device.cpp @@ -143,7 +143,7 @@ const std::string& Device::getVersionString() const { } nn::Version Device::getFeatureLevel() const { - return nn::Version::ANDROID_R; + return kVersion; } nn::DeviceType Device::getType() const { diff --git a/neuralnetworks/1.3/utils/test/DeviceTest.cpp b/neuralnetworks/1.3/utils/test/DeviceTest.cpp index 2d1b2f295a..7eba4bc935 100644 --- a/neuralnetworks/1.3/utils/test/DeviceTest.cpp +++ b/neuralnetworks/1.3/utils/test/DeviceTest.cpp @@ -505,7 +505,7 @@ TEST(DeviceTest, getFeatureLevel) { const auto featureLevel = device->getFeatureLevel(); // verify result - EXPECT_EQ(featureLevel, nn::Version::ANDROID_R); + EXPECT_EQ(featureLevel, nn::kVersionFeatureLevel4); } TEST(DeviceTest, getCachedData) { diff --git a/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h b/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h index 4262ef885f..b4e747e808 100644 --- a/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h +++ b/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h @@ -30,18 +30,18 @@ namespace aidl::android::hardware::neuralnetworks::utils { constexpr auto kDefaultPriority = Priority::MEDIUM; -inline std::optional aidlVersionToCanonicalVersion(int aidlVersion) { +constexpr std::optional aidlVersionToCanonicalVersion(int aidlVersion) { switch (aidlVersion) { case 1: - return nn::Version::ANDROID_S; + return nn::kVersionFeatureLevel5; case 2: - return nn::Version::FEATURE_LEVEL_6; + return nn::kVersionFeatureLevel6; default: return std::nullopt; } } -const auto kVersion = aidlVersionToCanonicalVersion(IDevice::version).value(); +constexpr auto kVersion = aidlVersionToCanonicalVersion(IDevice::version).value(); template nn::Result validate(const Type& halObject) { diff --git a/neuralnetworks/aidl/utils/src/Callbacks.cpp b/neuralnetworks/aidl/utils/src/Callbacks.cpp index a32147734c..8084970690 100644 --- a/neuralnetworks/aidl/utils/src/Callbacks.cpp +++ b/neuralnetworks/aidl/utils/src/Callbacks.cpp @@ -35,7 +35,8 @@ namespace { // Converts the results of IDevice::prepareModel* to the NN canonical format. On success, this // function returns with a non-null nn::SharedPreparedModel with a feature level of -// nn::Version::ANDROID_S. On failure, this function returns with the appropriate nn::GeneralError. +// nn::kVersionFeatureLevel5. On failure, this function returns with the appropriate +// nn::GeneralError. nn::GeneralResult prepareModelCallback( ErrorStatus status, const std::shared_ptr& preparedModel) { HANDLE_STATUS_AIDL(status) << "model preparation failed with " << toString(status); diff --git a/neuralnetworks/aidl/utils/test/DeviceTest.cpp b/neuralnetworks/aidl/utils/test/DeviceTest.cpp index 19d2314994..4e9fc469b4 100644 --- a/neuralnetworks/aidl/utils/test/DeviceTest.cpp +++ b/neuralnetworks/aidl/utils/test/DeviceTest.cpp @@ -155,7 +155,7 @@ std::string printDeviceTest(const testing::TestParamInfo& info) { const nn::Version version = info.param; CHECK(!version.runtimeOnlyFeatures); switch (version.level) { - case nn::Version::Level::ANDROID_S: + case nn::Version::Level::FEATURE_LEVEL_5: return "v1"; case nn::Version::Level::FEATURE_LEVEL_6: return "v2"; @@ -893,7 +893,7 @@ TEST_P(DeviceTest, allocateDeadObject) { } INSTANTIATE_TEST_SUITE_P(TestDevice, DeviceTest, - ::testing::Values(nn::Version::ANDROID_S, nn::Version::FEATURE_LEVEL_6), + ::testing::Values(nn::kVersionFeatureLevel5, nn::kVersionFeatureLevel6), printDeviceTest); } // namespace aidl::android::hardware::neuralnetworks::utils diff --git a/neuralnetworks/utils/common/test/ResilientDeviceTest.cpp b/neuralnetworks/utils/common/test/ResilientDeviceTest.cpp index 2e93a1155c..0488b6359b 100644 --- a/neuralnetworks/utils/common/test/ResilientDeviceTest.cpp +++ b/neuralnetworks/utils/common/test/ResilientDeviceTest.cpp @@ -53,7 +53,7 @@ SharedMockDevice createConfiguredMockDevice() { // Setup default actions for each relevant call. constexpr auto getName_ret = []() -> const std::string& { return kName; }; constexpr auto getVersionString_ret = []() -> const std::string& { return kVersionString; }; - const auto kFeatureLevel = nn::Version::ANDROID_OC_MR1; + constexpr auto kFeatureLevel = nn::kVersionFeatureLevel1; constexpr auto kDeviceType = nn::DeviceType::ACCELERATOR; constexpr auto getSupportedExtensions_ret = []() -> const std::vector& { return kExtensions; @@ -141,7 +141,7 @@ TEST(ResilientDeviceTest, cachedData) { TEST(ResilientDeviceTest, getFeatureLevel) { // setup call const auto [mockDevice, mockDeviceFactory, device] = setup(); - const auto kFeatureLevel = nn::Version::ANDROID_OC_MR1; + constexpr auto kFeatureLevel = nn::kVersionFeatureLevel1; EXPECT_CALL(*mockDevice, getFeatureLevel()).Times(1).WillOnce(Return(kFeatureLevel)); // run test @@ -591,7 +591,7 @@ TEST(ResilientDeviceTest, recoverCacheMismatchGetFeatureLevel) { const auto recoveredMockDevice = createConfiguredMockDevice(); EXPECT_CALL(*recoveredMockDevice, getFeatureLevel()) .Times(1) - .WillOnce(Return(nn::Version::ANDROID_P)); + .WillOnce(Return(nn::kVersionFeatureLevel2)); EXPECT_CALL(*mockDeviceFactory, Call(false)).Times(1).WillOnce(Return(recoveredMockDevice)); // run test