Make NNAPI countNumberOfConsumers return GeneralResult -- hal am: 68b6926e3c

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I5a6a168af09a2ef5861693dc71e7da3bb7d5a365
This commit is contained in:
Michael Butler 2021-02-24 01:11:25 +00:00 committed by Automerger Merge Worker
commit 0194425127
7 changed files with 17 additions and 15 deletions

View file

@ -162,7 +162,7 @@ GeneralResult<Model> unvalidatedConvert(const hal::V1_0::Model& model) {
// Verify number of consumers.
const auto numberOfConsumers =
hal::utils::countNumberOfConsumers(model.operands.size(), operations);
NN_TRY(hal::utils::countNumberOfConsumers(model.operands.size(), operations));
CHECK(model.operands.size() == numberOfConsumers.size());
for (size_t i = 0; i < model.operands.size(); ++i) {
if (model.operands[i].numberOfConsumers != numberOfConsumers[i]) {
@ -360,7 +360,7 @@ nn::GeneralResult<Model> unvalidatedConvert(const nn::Model& model) {
// Update number of consumers.
const auto numberOfConsumers =
hal::utils::countNumberOfConsumers(operands.size(), model.main.operations);
NN_TRY(hal::utils::countNumberOfConsumers(operands.size(), model.main.operations));
CHECK(operands.size() == numberOfConsumers.size());
for (size_t i = 0; i < operands.size(); ++i) {
operands[i].numberOfConsumers = numberOfConsumers[i];

View file

@ -111,7 +111,7 @@ GeneralResult<Model> unvalidatedConvert(const hal::V1_1::Model& model) {
// Verify number of consumers.
const auto numberOfConsumers =
hal::utils::countNumberOfConsumers(model.operands.size(), operations);
NN_TRY(hal::utils::countNumberOfConsumers(model.operands.size(), operations));
CHECK(model.operands.size() == numberOfConsumers.size());
for (size_t i = 0; i < model.operands.size(); ++i) {
if (model.operands[i].numberOfConsumers != numberOfConsumers[i]) {
@ -241,7 +241,7 @@ nn::GeneralResult<Model> unvalidatedConvert(const nn::Model& model) {
// Update number of consumers.
const auto numberOfConsumers =
hal::utils::countNumberOfConsumers(operands.size(), model.main.operations);
NN_TRY(hal::utils::countNumberOfConsumers(operands.size(), model.main.operations));
CHECK(operands.size() == numberOfConsumers.size());
for (size_t i = 0; i < operands.size(); ++i) {
operands[i].numberOfConsumers = numberOfConsumers[i];

View file

@ -227,7 +227,7 @@ GeneralResult<Model> unvalidatedConvert(const hal::V1_2::Model& model) {
// Verify number of consumers.
const auto numberOfConsumers =
hal::utils::countNumberOfConsumers(model.operands.size(), operations);
NN_TRY(hal::utils::countNumberOfConsumers(model.operands.size(), operations));
CHECK(model.operands.size() == numberOfConsumers.size());
for (size_t i = 0; i < model.operands.size(); ++i) {
if (model.operands[i].numberOfConsumers != numberOfConsumers[i]) {
@ -529,7 +529,7 @@ nn::GeneralResult<Model> unvalidatedConvert(const nn::Model& model) {
// Update number of consumers.
const auto numberOfConsumers =
hal::utils::countNumberOfConsumers(operands.size(), model.main.operations);
NN_TRY(hal::utils::countNumberOfConsumers(operands.size(), model.main.operations));
CHECK(operands.size() == numberOfConsumers.size());
for (size_t i = 0; i < operands.size(); ++i) {
operands[i].numberOfConsumers = numberOfConsumers[i];

View file

@ -217,7 +217,7 @@ GeneralResult<Model::Subgraph> unvalidatedConvert(const hal::V1_3::Subgraph& sub
// Verify number of consumers.
const auto numberOfConsumers =
hal::utils::countNumberOfConsumers(subgraph.operands.size(), operations);
NN_TRY(hal::utils::countNumberOfConsumers(subgraph.operands.size(), operations));
CHECK(subgraph.operands.size() == numberOfConsumers.size());
for (size_t i = 0; i < subgraph.operands.size(); ++i) {
if (subgraph.operands[i].numberOfConsumers != numberOfConsumers[i]) {
@ -559,7 +559,7 @@ nn::GeneralResult<Subgraph> unvalidatedConvert(const nn::Model::Subgraph& subgra
// Update number of consumers.
const auto numberOfConsumers =
hal::utils::countNumberOfConsumers(operands.size(), subgraph.operations);
NN_TRY(hal::utils::countNumberOfConsumers(operands.size(), subgraph.operations));
CHECK(operands.size() == numberOfConsumers.size());
for (size_t i = 0; i < operands.size(); ++i) {
operands[i].numberOfConsumers = numberOfConsumers[i];

View file

@ -1310,8 +1310,10 @@ static void mutateExecutionPriorityTest(const std::shared_ptr<IDevice>& device,
////////////////////////// ENTRY POINT //////////////////////////////
void validateModel(const std::shared_ptr<IDevice>& device, const Model& model) {
const auto numberOfConsumers = nn::countNumberOfConsumers(
model.main.operands.size(), nn::convert(model.main.operations).value());
const auto numberOfConsumers =
nn::countNumberOfConsumers(model.main.operands.size(),
nn::convert(model.main.operations).value())
.value();
mutateExecutionOrderTest(device, model, numberOfConsumers);
mutateOperandTypeTest(device, model);
mutateOperandRankTest(device, model);

View file

@ -71,8 +71,8 @@ nn::GeneralResult<std::reference_wrapper<const nn::Request>> flushDataFromPointe
nn::GeneralResult<void> unflushDataFromSharedToPointer(
const nn::Request& request, const std::optional<nn::Request>& maybeRequestInShared);
std::vector<uint32_t> countNumberOfConsumers(size_t numberOfOperands,
const std::vector<nn::Operation>& operations);
nn::GeneralResult<std::vector<uint32_t>> countNumberOfConsumers(
size_t numberOfOperands, const std::vector<nn::Operation>& operations);
nn::GeneralResult<hidl_memory> createHidlMemoryFromSharedMemory(const nn::SharedMemory& memory);
nn::GeneralResult<nn::SharedMemory> createSharedMemoryFromHidlMemory(const hidl_memory& memory);

View file

@ -246,9 +246,9 @@ nn::GeneralResult<void> unflushDataFromSharedToPointer(
return {};
}
std::vector<uint32_t> countNumberOfConsumers(size_t numberOfOperands,
const std::vector<nn::Operation>& operations) {
return nn::countNumberOfConsumers(numberOfOperands, operations);
nn::GeneralResult<std::vector<uint32_t>> countNumberOfConsumers(
size_t numberOfOperands, const std::vector<nn::Operation>& operations) {
return makeGeneralFailure(nn::countNumberOfConsumers(numberOfOperands, operations));
}
nn::GeneralResult<hidl_memory> createHidlMemoryFromSharedMemory(const nn::SharedMemory& memory) {