Collect optional operand index (#3768)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Tue, 4 Dec 2018 01:16:30 +0000 (10:16 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 4 Dec 2018 01:16:30 +0000 (10:16 +0900)
Collect optional operand index using defined API in frontend

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
runtimes/neurun/src/frontend/model.cc

index aa99ca4..5baf86f 100644 (file)
@@ -109,6 +109,8 @@ int ANeuralNetworksModel_addOperand(ANeuralNetworksModel *model,
 int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel *model, int32_t index,
                                          const void *buffer, size_t length)
 {
+  const bool isOptional = ((buffer == nullptr) && (length == 0));
+
   if ((model == nullptr) || ((buffer == nullptr) && (length != 0)))
   {
     return ANEURALNETWORKS_UNEXPECTED_NULL;
@@ -132,7 +134,7 @@ int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel *model, int32_t in
   }
 
   auto &obj = model->deref().operands().at(ind);
-  if (obj.operandSize() != length)
+  if ((obj.operandSize() != length) && !isOptional)
   {
     return ANEURALNETWORKS_BAD_DATA;
   }
@@ -144,6 +146,13 @@ int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel *model, int32_t in
   using ::neurun::graph::operand::CachedData;
   using ::neurun::graph::operand::ExternalData;
 
+  // Remain operands.at(ind).data()->base() as nullptr for optional operand
+  // This will be filled when model finished
+  if (isOptional)
+  {
+    model->setOptionalOperand(ind);
+  }
+
   // NNAPI spec in NeuralNetworks.h
   // For values of length greater than ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES,
   // the application is responsible for not changing the content of this region