Implement Model_addOperand
authorsjsujinkim <sjsujin.kim@samsung.com>
Fri, 23 Mar 2018 08:34:47 +0000 (17:34 +0900)
committer최형규/동작제어Lab(SR)/Senior Engineer/삼성전자 <hk0110.choi@samsung.com>
Mon, 26 Mar 2018 06:14:37 +0000 (15:14 +0900)
This commit implements Model_addOperand.
It has dependency on #195.
If #195 is landed, it would work well.

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/CMakeLists.txt
src/runtime/ref/nn/runtime/ModelBuilder.cpp
src/runtime/ref/nn/runtime/NeuralNetworks.cpp

index 6a30a85..44893da 100644 (file)
@@ -251,7 +251,7 @@ void logModelToInfo(const Model& model) {
     LOG(INFO) << "operandValues size" << model.operandValues.size();
     LOG(INFO) << "pools" << toString(model.pools);
 }
-
+#endif // REF-ANN
 // Validates the type. The used dimensions can be underspecified.
 int validateOperandType(const ANeuralNetworksOperandType& type, const char* tag,
                         bool allowPartial) {
@@ -280,7 +280,7 @@ int validateOperandType(const ANeuralNetworksOperandType& type, const char* tag,
     }
     return ANEURALNETWORKS_NO_ERROR;
 }
-
+#if 0 // REF-ANN
 int validateOperandList(uint32_t count, const uint32_t* list, uint32_t operandCount,
                         const char* tag) {
     for (uint32_t i = 0; i < count; i++) {
index 71fcde1..63b047b 100644 (file)
@@ -17,9 +17,7 @@
 #ifndef ANDROID_ML_NN_COMMON_UTILS_H
 #define ANDROID_ML_NN_COMMON_UTILS_H
 
-#if 0 // REF-ANN
 #include "HalInterfaces.h"
-#endif
 #include "NeuralNetworks.h"
 #include "Log.h"
 
@@ -114,7 +112,7 @@ uint32_t alignBytesNeeded(uint32_t index, size_t length);
 
 // Does a detailed LOG(INFO) of the model
 void logModelToInfo(const Model& model);
-
+#endif // REF-ANN
 inline void setFromIntList(hidl_vec<uint32_t>* vec, uint32_t count, const uint32_t* data) {
     vec->resize(count);
     for (uint32_t i = 0; i < count; i++) {
@@ -128,7 +126,7 @@ inline void setFromIntList(std::vector<uint32_t>* vec, uint32_t count, const uin
         (*vec)[i] = data[i];
     }
 }
-
+#if 0 // REF-ANN
 inline std::string toString(uint32_t obj) {
     return std::to_string(obj);
 }
@@ -141,12 +139,13 @@ std::string toString(const std::vector<Type>& range) {
     }
     return os += "]";
 }
-
+#endif // REF-ANN
 inline bool validCode(uint32_t codeCount, uint32_t codeCountOEM, uint32_t code) {
     return (code < codeCount) || (code >= kOEMCodeBase && (code - kOEMCodeBase) < codeCountOEM);
 }
 
 int validateOperandType(const ANeuralNetworksOperandType& type, const char* tag, bool allowPartial);
+#if 0 // REF-ANN
 int validateOperandList(uint32_t count, const uint32_t* list, uint32_t operandCount,
                         const char* tag);
 bool validateModel(const Model& model);
index c558dce..038a160 100644 (file)
@@ -13,4 +13,4 @@ include_directories(runtime PRIVATE . include ../include ../common/include ${DEP
 file(GLOB SRCS *.cc)
 
 add_executable(runtime_run ${SRCS})
-target_link_libraries(runtime_run runtime)
+target_link_libraries(runtime_run runtime runtime_ref_common)
index d435a83..1fa59d8 100644 (file)
@@ -19,8 +19,6 @@
 
 #include "CompilationBuilder.h"
 
-#include "Log.h"
-
 #if 0
 #define LOG_TAG "ModelBuilder"
 
@@ -31,16 +29,10 @@ namespace android {
 namespace nn {
 
 // The maximum number of operands and operations that a model may have.
-#if 0
 const uint32_t MAX_NUMBER_OF_OPERANDS = 0xFFFFFFFE;
 const uint32_t MAX_NUMBER_OF_OPERATIONS = 0xFFFFFFFE;
-#endif
 
 int ModelBuilder::addOperand(const ANeuralNetworksOperandType& type) {
-    // Dummy Implementation
-    return 0;
-
-#if 0
     if (mCompletedModel) {
         LOG(ERROR) << "ANeuralNetworksModel_addOperand can't modify after model finished";
         return ANEURALNETWORKS_BAD_DATA;
@@ -64,7 +56,6 @@ int ModelBuilder::addOperand(const ANeuralNetworksOperandType& type) {
     operand.lifetime = OperandLifeTime::TEMPORARY_VARIABLE;
     operand.location = {.poolIndex = 0, .offset = 0, .length = 0};
     return ANEURALNETWORKS_NO_ERROR;
-#endif
 }
 
 int ModelBuilder::setOperandValue(uint32_t index, const void* buffer, size_t length) {
index d720018..f0532f1 100644 (file)
@@ -287,18 +287,12 @@ int ANeuralNetworksModel_finish(ANeuralNetworksModel* model) {
 
 int ANeuralNetworksModel_addOperand(ANeuralNetworksModel* model,
                                     const ANeuralNetworksOperandType* type) {
-    // Dummy Implementation
-    return ANEURALNETWORKS_NO_ERROR;
-
-    // Original code for reference
-#if 0
     if (!model || !type) {
         LOG(ERROR) << "ANeuralNetworksModel_addOperand passed a nullptr";
         return ANEURALNETWORKS_UNEXPECTED_NULL;
     }
     ModelBuilder* m = reinterpret_cast<ModelBuilder*>(model);
     return m->addOperand(*type);
-#endif
 }
 
 int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel* model, int32_t index,