From: 오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Wed, 28 Nov 2018 04:54:13 +0000 (+0900) Subject: Save pointer to buffer for operand value setting (#3736) X-Git-Tag: 0.3~297 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6fd804f470421dde9166c81224e1454a8234ea61;p=platform%2Fcore%2Fml%2Fnnfw.git Save pointer to buffer for operand value setting (#3736) 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 --- diff --git a/runtimes/neurun/src/frontend/model.cc b/runtimes/neurun/src/frontend/model.cc index 26f53a5..b2a1dac 100644 --- a/runtimes/neurun/src/frontend/model.cc +++ b/runtimes/neurun/src/frontend/model.cc @@ -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(reinterpret_cast(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(reinterpret_cast(buffer), length)); + } + else + { + model->deref().setOperandValue( + ind, nnfw::make_unique(reinterpret_cast(buffer), length)); + } return ANEURALNETWORKS_NO_ERROR; }