Implement Model_setOperandValue
authorsjsujinkim <sjsujin.kim@samsung.com>
Mon, 26 Mar 2018 02:31:25 +0000 (11:31 +0900)
committer최형규/동작제어Lab(SR)/Senior Engineer/삼성전자 <hk0110.choi@samsung.com>
Mon, 26 Mar 2018 06:14:54 +0000 (15:14 +0900)
This commit implements Model_setOperandValue and enalbes below helpers.

- sizeOfData
- alignBytesNeeded

Signed-off-by: sjsujinkim <sjsujin.kim@samsung.com>
src/runtime/ref/nn/common/Utils.cpp
src/runtime/ref/nn/common/include/Utils.h
src/runtime/ref/nn/runtime/ModelBuilder.cpp
src/runtime/ref/nn/runtime/ModelBuilder.h
src/runtime/ref/nn/runtime/NeuralNetworks.cpp

index 44893da..5b4679a 100644 (file)
@@ -77,6 +77,7 @@ void initVLogMask() {
         }
     }
 }
+#endif // REF-ANN
 #define COUNT(X) (sizeof(X) / sizeof(X[0]))
 
 const char* kTypeNames[kNumberOfDataTypes] = {
@@ -213,6 +214,7 @@ uint32_t sizeOfData(OperandType type, const std::vector<uint32_t>& dimensions) {
     }
     return size;
 }
+#if 0 // REF-ANN
 hidl_memory allocateSharedMemory(int64_t size) {
     hidl_memory memory;
 
@@ -229,6 +231,7 @@ hidl_memory allocateSharedMemory(int64_t size) {
 
     return memory;
 }
+#endif // REF-ANN
 uint32_t alignBytesNeeded(uint32_t index, size_t length) {
     uint32_t pattern;
     if (length < 2) {
@@ -241,7 +244,7 @@ uint32_t alignBytesNeeded(uint32_t index, size_t length) {
     uint32_t extra = (~(index - 1)) & pattern;
     return extra;
 }
-
+#if 0 // REF-ANN
 void logModelToInfo(const Model& model) {
     LOG(INFO) << "Model start";
     LOG(INFO) << "operands" << toString(model.operands);
index 63b047b..a673b72 100644 (file)
@@ -82,7 +82,6 @@ void initVLogMask();
             abort();                                                                           \
         }                                                                                      \
     } while (0)
-#if 0 // REF-ANN
 // Returns the amount of space needed to store a value of the specified
 // dimensions and type.
 uint32_t sizeOfData(OperandType type, const std::vector<uint32_t>& dimensions);
@@ -92,6 +91,7 @@ uint32_t sizeOfData(OperandType type, const std::vector<uint32_t>& dimensions);
 inline uint32_t sizeOfData(const Operand& operand) {
     return sizeOfData(operand.type, operand.dimensions);
 }
+#if 0 // REF-ANN
 
 // Returns the name of the operation in ASCII.
 const char* getOperationName(OperationType opCode);
@@ -100,7 +100,7 @@ const char* getOperationName(OperationType opCode);
 // Memory is reference counted by hidl_memory instances, and is deallocated
 // once there are no more references.
 hidl_memory allocateSharedMemory(int64_t size);
-
+#endif // REF-ANN
 // Returns the number of padding bytes needed to align data of the
 // specified length.  It aligns object of length:
 // 2, 3 on a 2 byte boundary,
@@ -109,7 +109,7 @@ hidl_memory allocateSharedMemory(int64_t size);
 // TODO: This is arbitrary, more a proof of concept.  We need
 // to determine what this should be.
 uint32_t alignBytesNeeded(uint32_t index, size_t length);
-
+#if 0 // REF-ANN
 // Does a detailed LOG(INFO) of the model
 void logModelToInfo(const Model& model);
 #endif // REF-ANN
index 1fa59d8..f8383b5 100644 (file)
@@ -59,9 +59,6 @@ int ModelBuilder::addOperand(const ANeuralNetworksOperandType& type) {
 }
 
 int ModelBuilder::setOperandValue(uint32_t index, const void* buffer, size_t length) {
-    // Dummy Implementation
-    return 0;
-#if 0
     VLOG(MODEL) << __func__ << " for operand " << index << " size " << length;
     if (index >= operandCount()) {
         LOG(ERROR) << "ANeuralNetworksModel_setOperandValue setting operand " << index << " of "
@@ -113,7 +110,6 @@ int ModelBuilder::setOperandValue(uint32_t index, const void* buffer, size_t len
         }
     }
     return ANEURALNETWORKS_NO_ERROR;
-#endif
 }
 
 int ModelBuilder::copyLargeValuesToSharedMemory() {
index 847b8d4..37d463c 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <vector>
 #include <memory>
+#include <string.h> // For memcpy
+                    // TODO-NNRT : Remove if the header containing this header is included
 
 #include "HalInterfaces.h"
 #include "Utils.h"
index f0532f1..6c6490d 100644 (file)
@@ -297,18 +297,12 @@ int ANeuralNetworksModel_addOperand(ANeuralNetworksModel* model,
 
 int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel* model, int32_t index,
                                          const void* buffer, size_t length) {
-    // Dummy Implementation
-    return ANEURALNETWORKS_NO_ERROR;
-
-    // Original code for reference
-#if 0
     if (!model || !buffer) {
         LOG(ERROR) << "ANeuralNetworksModel_setOperandValue passed a nullptr";
         return ANEURALNETWORKS_UNEXPECTED_NULL;
     }
     ModelBuilder* m = reinterpret_cast<ModelBuilder*>(model);
     return m->setOperandValue(index, buffer, length);
-#endif
 }
 
 int ANeuralNetworksModel_setOperandValueFromMemory(ANeuralNetworksModel* model, int32_t index,