Add a centralized runtime extension information store
Fix: 124107169
Fix: 123523457
Fix: 124285861
Fix: 124104123
Fix: 123178734
Test: NeuralNetworksTest_static
Test: NeuralNetworksTest_utils
Test: NeuralNetworksTest_FibonacciExtension (from change Ibe0fc5356baa909bce8424138bd5cfac9f74648f)
Change-Id: Id3f105476f42bd747a098f081a07b161036e4922
Merged-In: Id3f105476f42bd747a098f081a07b161036e4922
(cherry picked from commit 93c679813ab8f19a2d696a22f5fce229a1e62a73)
diff --git a/runtime/ExecutionBuilder.cpp b/runtime/ExecutionBuilder.cpp
index 7825eb7..870a8b2 100644
--- a/runtime/ExecutionBuilder.cpp
+++ b/runtime/ExecutionBuilder.cpp
@@ -25,6 +25,7 @@
#include "Manager.h"
#include "ModelBuilder.h"
#include "Tracing.h"
+#include "TypeManager.h"
#include "Utils.h"
#include <mutex>
@@ -43,7 +44,12 @@
static bool checkDimensionInfo(const Operand& operand, const ANeuralNetworksOperandType* newType,
const char* tag, bool allowUnspecified) {
if (newType != nullptr) {
- if (validateOperandType(*newType, tag, allowUnspecified) != ANEURALNETWORKS_NO_ERROR) {
+ const Extension::OperandTypeInformation* info = nullptr;
+ if (isExtensionOperandType(operand.type)) {
+ NN_RET_CHECK(TypeManager::get()->getExtensionOperandTypeInfo(operand.type, &info));
+ }
+ if (validateOperandType(*newType, info, tag, allowUnspecified) !=
+ ANEURALNETWORKS_NO_ERROR) {
LOG(ERROR) << tag << ": Invalid newType";
return false;
}
@@ -61,7 +67,8 @@
}
}
} else {
- if (!allowUnspecified && hasUnspecifiedDimensions(operand)) {
+ if (!allowUnspecified && TypeManager::get()->isTensorType(operand.type) &&
+ tensorHasUnspecifiedDimensions(operand)) {
LOG(ERROR) << tag << ": Setting with operand type that is not fully specified";
return false;
}
@@ -82,8 +89,8 @@
state = ModelArgumentInfo::HAS_NO_VALUE;
} else {
NN_RETURN_IF_ERROR(updateDimensionInfo(operand, type));
- if (!isExtensionOperandType(operand.type) && operand.type != OperandType::OEM) {
- uint32_t neededLength = sizeOfData(operand.type, dimensions);
+ if (operand.type != OperandType::OEM) {
+ uint32_t neededLength = TypeManager::get()->getSizeOfData(operand.type, dimensions);
if (neededLength != length && neededLength != 0) {
LOG(ERROR) << "Setting argument with invalid length: " << length
<< ", expected length: " << neededLength;
@@ -100,8 +107,8 @@
int ModelArgumentInfo::setFromMemory(const Operand& operand, const ANeuralNetworksOperandType* type,
uint32_t poolIndex, uint32_t offset, uint32_t length) {
NN_RETURN_IF_ERROR(updateDimensionInfo(operand, type));
- if (!isExtensionOperandType(operand.type) && operand.type != OperandType::OEM) {
- uint32_t neededLength = sizeOfData(operand.type, dimensions);
+ if (operand.type != OperandType::OEM) {
+ uint32_t neededLength = TypeManager::get()->getSizeOfData(operand.type, dimensions);
if (neededLength != length && neededLength != 0) {
LOG(ERROR) << "Setting argument with invalid length: " << length
<< ", expected length: " << neededLength;
@@ -118,8 +125,8 @@
int ModelArgumentInfo::setFromTemporaryMemory(const Operand& operand, uint32_t poolIndex,
uint32_t offset, uint32_t length) {
NN_RETURN_IF_ERROR(updateDimensionInfo(operand, nullptr));
- if (!isExtensionOperandType(operand.type) && operand.type != OperandType::OEM) {
- uint32_t neededLength = sizeOfData(operand.type, dimensions);
+ if (operand.type != OperandType::OEM) {
+ uint32_t neededLength = TypeManager::get()->getSizeOfData(operand.type, dimensions);
if (neededLength != length) {
LOG(ERROR) << "Setting argument with invalid length: " << length
<< ", expected length: " << neededLength;
@@ -687,8 +694,7 @@
// ExecutionBuilder::setOutputFromMemory()
uint32_t poolIndex = mMemories.add(memory);
- uint32_t length =
- mDevice->getSizeOfData(inputOrOutputOperand, mModel->getExtensionNameToPrefixMap());
+ uint32_t length = TypeManager::get()->getSizeOfData(inputOrOutputOperand);
return inputOrOutputInfo->setFromTemporaryMemory(inputOrOutputOperand, poolIndex, offset,
length);
}