Add isUpdatable to NNAPI canonical IDevice -- hal

Bug: 177284207
Test: mma
Change-Id: I580d5325be91f566ee1c591736a87a94d0a74315
This commit is contained in:
Michael Butler
2021-01-11 19:35:53 -08:00
parent 9c1b7cacfb
commit 080fbf755c
13 changed files with 41 additions and 6 deletions

View File

@@ -52,6 +52,7 @@ class Device final : public nn::IDevice {
const std::string& getVersionString() const override;
nn::Version getFeatureLevel() const override;
nn::DeviceType getType() const override;
bool isUpdatable() const override;
const std::vector<nn::Extension>& getSupportedExtensions() const override;
const nn::Capabilities& getCapabilities() const override;
std::pair<uint32_t, uint32_t> getNumberOfCacheFilesNeeded() const override;

View File

@@ -106,6 +106,10 @@ nn::DeviceType Device::getType() const {
return nn::DeviceType::OTHER;
}
bool Device::isUpdatable() const {
return false;
}
const std::vector<nn::Extension>& Device::getSupportedExtensions() const {
return kExtensions;
}

View File

@@ -52,6 +52,7 @@ class Device final : public nn::IDevice {
const std::string& getVersionString() const override;
nn::Version getFeatureLevel() const override;
nn::DeviceType getType() const override;
bool isUpdatable() const override;
const std::vector<nn::Extension>& getSupportedExtensions() const override;
const nn::Capabilities& getCapabilities() const override;
std::pair<uint32_t, uint32_t> getNumberOfCacheFilesNeeded() const override;

View File

@@ -106,6 +106,10 @@ nn::DeviceType Device::getType() const {
return nn::DeviceType::UNKNOWN;
}
bool Device::isUpdatable() const {
return false;
}
const std::vector<nn::Extension>& Device::getSupportedExtensions() const {
return kExtensions;
}

View File

@@ -71,6 +71,7 @@ class Device final : public nn::IDevice {
const std::string& getVersionString() const override;
nn::Version getFeatureLevel() const override;
nn::DeviceType getType() const override;
bool isUpdatable() const override;
const std::vector<nn::Extension>& getSupportedExtensions() const override;
const nn::Capabilities& getCapabilities() const override;
std::pair<uint32_t, uint32_t> getNumberOfCacheFilesNeeded() const override;

View File

@@ -199,6 +199,10 @@ nn::DeviceType Device::getType() const {
return kDeviceType;
}
bool Device::isUpdatable() const {
return false;
}
const std::vector<nn::Extension>& Device::getSupportedExtensions() const {
return kExtensions;
}

View File

@@ -54,6 +54,7 @@ class Device final : public nn::IDevice {
const std::string& getVersionString() const override;
nn::Version getFeatureLevel() const override;
nn::DeviceType getType() const override;
bool isUpdatable() const override;
const std::vector<nn::Extension>& getSupportedExtensions() const override;
const nn::Capabilities& getCapabilities() const override;
std::pair<uint32_t, uint32_t> getNumberOfCacheFilesNeeded() const override;

View File

@@ -150,6 +150,10 @@ nn::DeviceType Device::getType() const {
return kDeviceType;
}
bool Device::isUpdatable() const {
return false;
}
const std::vector<nn::Extension>& Device::getSupportedExtensions() const {
return kExtensions;
}

View File

@@ -32,7 +32,7 @@ namespace android::hardware::neuralnetworks::utils {
class InvalidDevice final : public nn::IDevice {
public:
InvalidDevice(std::string name, std::string versionString, nn::Version featureLevel,
nn::DeviceType type, std::vector<nn::Extension> extensions,
nn::DeviceType type, bool isUpdatable, std::vector<nn::Extension> extensions,
nn::Capabilities capabilities,
std::pair<uint32_t, uint32_t> numberOfCacheFilesNeeded);
@@ -40,6 +40,7 @@ class InvalidDevice final : public nn::IDevice {
const std::string& getVersionString() const override;
nn::Version getFeatureLevel() const override;
nn::DeviceType getType() const override;
bool isUpdatable() const override;
const std::vector<nn::Extension>& getSupportedExtensions() const override;
const nn::Capabilities& getCapabilities() const override;
std::pair<uint32_t, uint32_t> getNumberOfCacheFilesNeeded() const override;
@@ -70,6 +71,7 @@ class InvalidDevice final : public nn::IDevice {
const std::string kVersionString;
const nn::Version kFeatureLevel;
const nn::DeviceType kType;
const bool kIsUpdatable;
const std::vector<nn::Extension> kExtensions;
const nn::Capabilities kCapabilities;
const std::pair<uint32_t, uint32_t> kNumberOfCacheFilesNeeded;

View File

@@ -53,6 +53,7 @@ class ResilientDevice final : public nn::IDevice,
const std::string& getVersionString() const override;
nn::Version getFeatureLevel() const override;
nn::DeviceType getType() const override;
bool isUpdatable() const override;
const std::vector<nn::Extension>& getSupportedExtensions() const override;
const nn::Capabilities& getCapabilities() const override;
std::pair<uint32_t, uint32_t> getNumberOfCacheFilesNeeded() const override;

View File

@@ -32,13 +32,14 @@
namespace android::hardware::neuralnetworks::utils {
InvalidDevice::InvalidDevice(std::string name, std::string versionString, nn::Version featureLevel,
nn::DeviceType type, std::vector<nn::Extension> extensions,
nn::Capabilities capabilities,
nn::DeviceType type, bool isUpdatable,
std::vector<nn::Extension> extensions, nn::Capabilities capabilities,
std::pair<uint32_t, uint32_t> numberOfCacheFilesNeeded)
: kName(std::move(name)),
kVersionString(std::move(versionString)),
kFeatureLevel(featureLevel),
kType(type),
kIsUpdatable(isUpdatable),
kExtensions(std::move(extensions)),
kCapabilities(std::move(capabilities)),
kNumberOfCacheFilesNeeded(numberOfCacheFilesNeeded) {}
@@ -59,6 +60,10 @@ nn::DeviceType InvalidDevice::getType() const {
return kType;
}
bool InvalidDevice::isUpdatable() const {
return kIsUpdatable;
}
const std::vector<nn::Extension>& InvalidDevice::getSupportedExtensions() const {
return kExtensions;
}

View File

@@ -122,12 +122,14 @@ nn::GeneralResult<nn::SharedDevice> ResilientDevice::recover(const nn::IDevice*
};
if (compare(&IDevice::getName) || compare(&IDevice::getVersionString) ||
compare(&IDevice::getFeatureLevel) || compare(&IDevice::getType) ||
compare(&IDevice::getSupportedExtensions) || compare(&IDevice::getCapabilities)) {
compare(&IDevice::isUpdatable) || compare(&IDevice::getSupportedExtensions) ||
compare(&IDevice::getCapabilities)) {
LOG(ERROR) << "Recovered device has different metadata than what is cached. Marking "
"IDevice object as invalid.";
device = std::make_shared<const InvalidDevice>(
kName, kVersionString, mDevice->getFeatureLevel(), mDevice->getType(), kExtensions,
kCapabilities, mDevice->getNumberOfCacheFilesNeeded());
kName, kVersionString, mDevice->getFeatureLevel(), mDevice->getType(),
mDevice->isUpdatable(), kExtensions, kCapabilities,
mDevice->getNumberOfCacheFilesNeeded());
mIsValid = false;
}
@@ -151,6 +153,10 @@ nn::DeviceType ResilientDevice::getType() const {
return getDevice()->getType();
}
bool ResilientDevice::isUpdatable() const {
return getDevice()->isUpdatable();
}
const std::vector<nn::Extension>& ResilientDevice::getSupportedExtensions() const {
return kExtensions;
}

View File

@@ -29,6 +29,7 @@ class MockDevice final : public IDevice {
MOCK_METHOD(const std::string&, getVersionString, (), (const, override));
MOCK_METHOD(Version, getFeatureLevel, (), (const, override));
MOCK_METHOD(DeviceType, getType, (), (const, override));
MOCK_METHOD(bool, isUpdatable, (), (const, override));
MOCK_METHOD(const std::vector<Extension>&, getSupportedExtensions, (), (const, override));
MOCK_METHOD(const Capabilities&, getCapabilities, (), (const, override));
MOCK_METHOD((std::pair<uint32_t, uint32_t>), getNumberOfCacheFilesNeeded, (),