Save pointer to buffer for operand value setting (#3736)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 28 Nov 2018 04:54:13 +0000 (13:54 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 28 Nov 2018 04:54:12 +0000 (13:54 +0900)
For operand value setting, save pointer to buffer instead of copy when size is greater than
ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES defined in NeuralNetworks.h

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

index 26f53a5..b2a1dac 100644 (file)
@@ -148,9 +148,22 @@ int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel *model, int32_t in
   }
 
   using ::neurun::graph::operand::CachedData;
+  using ::neurun::graph::operand::ExternalData;
 
-  model->deref().setOperandValue(
-      ind, nnfw::make_unique<CachedData>(reinterpret_cast<const uint8_t *>(buffer), length));
+  // 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
+  // until all executions using this model have completed
+  if (length <= ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES)
+  {
+    model->deref().setOperandValue(
+        ind, nnfw::make_unique<CachedData>(reinterpret_cast<const uint8_t *>(buffer), length));
+  }
+  else
+  {
+    model->deref().setOperandValue(
+        ind, nnfw::make_unique<ExternalData>(reinterpret_cast<const uint8_t *>(buffer), length));
+  }
 
   return ANEURALNETWORKS_NO_ERROR;
 }