Merge "Make NNAPI Version more structured -- hal" am: 71b595549c

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1890277

Change-Id: Idc83d3c0b5e2cfb1d6da853b0754cbc108f57681
This commit is contained in:
Michael Butler
2021-11-19 00:17:10 +00:00
committed by Automerger Merge Worker
8 changed files with 21 additions and 20 deletions

View File

@@ -28,7 +28,7 @@
namespace android::hardware::neuralnetworks::V1_0::utils {
constexpr auto kVersion = nn::Version::ANDROID_OC_MR1;
const auto kVersion = nn::Version::ANDROID_OC_MR1;
template <typename Type>
nn::Result<void> validate(const Type& halObject) {
@@ -51,7 +51,7 @@ bool valid(const Type& halObject) {
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 {};

View File

@@ -30,7 +30,7 @@
namespace android::hardware::neuralnetworks::V1_1::utils {
constexpr auto kDefaultExecutionPreference = ExecutionPreference::FAST_SINGLE_ANSWER;
constexpr auto kVersion = nn::Version::ANDROID_P;
const auto kVersion = nn::Version::ANDROID_P;
template <typename Type>
nn::Result<void> validate(const Type& halObject) {
@@ -53,7 +53,7 @@ bool valid(const Type& halObject) {
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 {};

View File

@@ -39,7 +39,7 @@ using V1_1::utils::kDefaultExecutionPreference;
constexpr auto kDefaultMesaureTiming = MeasureTiming::NO;
constexpr auto kNoTiming = Timing{.timeOnDevice = std::numeric_limits<uint64_t>::max(),
.timeInDriver = std::numeric_limits<uint64_t>::max()};
constexpr auto kVersion = nn::Version::ANDROID_Q;
const auto kVersion = nn::Version::ANDROID_Q;
template <typename Type>
nn::Result<void> validate(const Type& halObject) {
@@ -62,7 +62,7 @@ bool valid(const Type& halObject) {
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 {};

View File

@@ -315,7 +315,7 @@ nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> Burst::
// if the request is valid but of a higher version than what's supported in burst execution,
// fall back to another execution path
if (const auto version = NN_TRY(nn::validate(request)); version > nn::Version::ANDROID_Q) {
if (!compliantVersion(request).ok()) {
// fallback to another execution path if the packet could not be sent
return kPreparedModel->execute(request, measure, deadline, loopTimeoutDuration);
}
@@ -359,7 +359,7 @@ nn::GeneralResult<nn::SharedExecution> Burst::createReusableExecution(
// if the request is valid but of a higher version than what's supported in burst execution,
// fall back to another execution path
if (const auto version = NN_TRY(nn::validate(request)); version > nn::Version::ANDROID_Q) {
if (!compliantVersion(request).ok()) {
// fallback to another execution path if the packet could not be sent
return kPreparedModel->createReusableExecution(request, measure, loopTimeoutDuration);
}

View File

@@ -39,7 +39,7 @@ using V1_2::utils::kDefaultMesaureTiming;
using V1_2::utils::kNoTiming;
constexpr auto kDefaultPriority = Priority::MEDIUM;
constexpr auto kVersion = nn::Version::ANDROID_R;
const auto kVersion = nn::Version::ANDROID_R;
template <typename Type>
nn::Result<void> validate(const Type& halObject) {
@@ -62,7 +62,7 @@ bool valid(const Type& halObject) {
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 {};

View File

@@ -30,7 +30,7 @@ namespace aidl::android::hardware::neuralnetworks::utils {
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 std::optional<nn::Version> aidlVersionToCanonicalVersion(int aidlVersi
}
}
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 @@ bool valid(const Type& halObject) {
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 {};

View File

@@ -152,13 +152,15 @@ class DeviceTest : public ::testing::TestWithParam<nn::Version> {
};
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";
}
}

View File

@@ -28,7 +28,6 @@ namespace android::hardware::neuralnetworks::utils {
namespace {
using ::testing::_;
using ::testing::InvokeWithoutArgs;
using ::testing::Return;
using SharedMockDevice = std::shared_ptr<const nn::MockDevice>;
@@ -54,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; };
constexpr auto kFeatureLevel = nn::Version::ANDROID_OC_MR1;
const auto kFeatureLevel = nn::Version::ANDROID_OC_MR1;
constexpr auto kDeviceType = nn::DeviceType::ACCELERATOR;
constexpr auto getSupportedExtensions_ret = []() -> const std::vector<nn::Extension>& {
return kExtensions;
@@ -142,7 +141,7 @@ TEST(ResilientDeviceTest, cachedData) {
TEST(ResilientDeviceTest, getFeatureLevel) {
// setup call
const auto [mockDevice, mockDeviceFactory, device] = setup();
constexpr auto kFeatureLevel = nn::Version::ANDROID_OC_MR1;
const auto kFeatureLevel = nn::Version::ANDROID_OC_MR1;
EXPECT_CALL(*mockDevice, getFeatureLevel()).Times(1).WillOnce(Return(kFeatureLevel));
// run test