summaryrefslogtreecommitdiff
path: root/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc')
-rw-r--r--runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc65
1 files changed, 57 insertions, 8 deletions
diff --git a/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc
index eb12d7e76..2265e990f 100644
--- a/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc
+++ b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc
@@ -64,7 +64,7 @@ bool ANeuralNetworksExecution::compareDataType(const ANeuralNetworksOperandType
{
try
{
- const auto operand_type = _execution->primary_subgraph().operands().at(index).typeInfo();
+ const auto &operand_type = _execution->primary_subgraph().operands().at(index).typeInfo();
const auto typeInfo = NNAPIConvert::getTypeInfo(type);
if (operand_type != typeInfo)
@@ -98,9 +98,20 @@ bool ANeuralNetworksExecution::compareShape(const ANeuralNetworksOperandType *ty
return operand_shape == shape_from_type;
}
+bool ANeuralNetworksExecution::IsOptionalInput(const onert::ir::OperandIndex index) noexcept
+{
+ const auto &operand_shape = _execution->primary_subgraph().operands().at(index).shape();
+ for (int32_t i = 0; i < operand_shape.rank(); ++i)
+ {
+ if (operand_shape.dim(i) != 0)
+ return false;
+ }
+ return true;
+}
+
bool ANeuralNetworksExecution::hasUnspecifiedDims(const onert::ir::OperandIndex index) noexcept
{
- const auto operand_shape = _execution->primary_subgraph().operands().at(index).shape();
+ const auto &operand_shape = _execution->primary_subgraph().operands().at(index).shape();
return operand_shape.hasUnspecifiedDims();
}
@@ -127,10 +138,10 @@ bool ANeuralNetworksExecution::setInput(uint32_t index, const ANeuralNetworksOpe
onert::ir::IOIndex input_index{index};
const auto operand_index = getInputOperandIndex(index);
- const auto type_info = _execution->primary_subgraph().operands().at(operand_index).typeInfo();
+ const auto &type_info = _execution->primary_subgraph().operands().at(operand_index).typeInfo();
const auto shape = (type != nullptr)
- ? NNAPIConvert::getShape(type)
- : _execution->primary_subgraph().operands().at(operand_index).shape();
+ ? NNAPIConvert::getShape(type)
+ : _execution->primary_subgraph().operands().at(operand_index).shape();
// NOTE The nnapi does not provide setting io_layout and not support changing layout. In other
// words, we can assume that io_layout from nnapi always is the same as layout of the used
@@ -148,6 +159,44 @@ bool ANeuralNetworksExecution::setInput(uint32_t index, const ANeuralNetworksOpe
return true;
}
+bool ANeuralNetworksExecution::setOptionalInput(uint32_t index,
+ const ANeuralNetworksOperandType *type,
+ const void *buffer, size_t length) noexcept
+{
+ assert(type == nullptr);
+ assert(buffer == nullptr);
+ assert(length == 0);
+ try
+ {
+ onert::ir::IOIndex input_index{index};
+ const auto operand_index = getInputOperandIndex(index);
+
+ const auto shape = (type != nullptr)
+ ? NNAPIConvert::getShape(type)
+ : _execution->primary_subgraph().operands().at(operand_index).shape();
+
+ // ANeuralNetworksExecution::setInput() uses only shape information
+ ANeuralNetworksOperandType optional_input_type;
+ optional_input_type.dimensionCount = shape.rank();
+ std::vector<uint32_t> dims(optional_input_type.dimensionCount);
+ for (uint32_t i = 0; i < optional_input_type.dimensionCount; ++i)
+ {
+ dims.at(i) = shape.dim(i);
+ }
+ optional_input_type.dimensions = dims.data();
+
+ return setInput(index, &optional_input_type, buffer, length);
+ }
+ catch (const std::exception &e)
+ {
+ VERBOSE(EXCEPTION) << e.what() << std::endl;
+
+ return false;
+ }
+
+ return true;
+}
+
bool ANeuralNetworksExecution::setOutput(uint32_t index, const ANeuralNetworksOperandType *type,
void *buffer, size_t length) noexcept
{
@@ -156,10 +205,10 @@ bool ANeuralNetworksExecution::setOutput(uint32_t index, const ANeuralNetworksOp
onert::ir::IOIndex output_index{index};
const auto operand_index = getOutputOperandIndex(index);
- const auto type_info = _execution->primary_subgraph().operands().at(operand_index).typeInfo();
+ const auto &type_info = _execution->primary_subgraph().operands().at(operand_index).typeInfo();
const auto shape = (type != nullptr)
- ? NNAPIConvert::getShape(type)
- : _execution->primary_subgraph().operands().at(operand_index).shape();
+ ? NNAPIConvert::getShape(type)
+ : _execution->primary_subgraph().operands().at(operand_index).shape();
// NOTE The nnapi does not provide setting io_layout and not support changing layout. In other
// words, we can assume that io_layout from nnapi always is the same as layout of the used