From 5170c42ee0bd67c74b48644847ad71d377134b4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 4 Dec 2018 10:16:30 +0900 Subject: [PATCH] Collect optional operand index (#3768) Collect optional operand index using defined API in frontend Signed-off-by: Hyeongseok Oh --- runtimes/neurun/src/frontend/model.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/runtimes/neurun/src/frontend/model.cc b/runtimes/neurun/src/frontend/model.cc index aa99ca4..5baf86f 100644 --- a/runtimes/neurun/src/frontend/model.cc +++ b/runtimes/neurun/src/frontend/model.cc @@ -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 -- 2.7.4