From 02222458b5594348317f89735a200aba3bcb53e7 Mon Sep 17 00:00:00 2001 From: sjsujinkim Date: Fri, 23 Mar 2018 17:34:47 +0900 Subject: [PATCH] Implement Model_addOperand This commit implements Model_addOperand. It has dependency on #195. If #195 is landed, it would work well. Signed-off-by: sjsujinkim --- src/runtime/ref/nn/common/Utils.cpp | 4 ++-- src/runtime/ref/nn/common/include/Utils.h | 9 ++++----- src/runtime/ref/nn/runtime/CMakeLists.txt | 2 +- src/runtime/ref/nn/runtime/ModelBuilder.cpp | 9 --------- src/runtime/ref/nn/runtime/NeuralNetworks.cpp | 6 ------ 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/runtime/ref/nn/common/Utils.cpp b/src/runtime/ref/nn/common/Utils.cpp index 6a30a85..44893da 100644 --- a/src/runtime/ref/nn/common/Utils.cpp +++ b/src/runtime/ref/nn/common/Utils.cpp @@ -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++) { diff --git a/src/runtime/ref/nn/common/include/Utils.h b/src/runtime/ref/nn/common/include/Utils.h index 71fcde1..63b047b 100644 --- a/src/runtime/ref/nn/common/include/Utils.h +++ b/src/runtime/ref/nn/common/include/Utils.h @@ -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* 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* 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& 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); diff --git a/src/runtime/ref/nn/runtime/CMakeLists.txt b/src/runtime/ref/nn/runtime/CMakeLists.txt index c558dce..038a160 100644 --- a/src/runtime/ref/nn/runtime/CMakeLists.txt +++ b/src/runtime/ref/nn/runtime/CMakeLists.txt @@ -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) diff --git a/src/runtime/ref/nn/runtime/ModelBuilder.cpp b/src/runtime/ref/nn/runtime/ModelBuilder.cpp index d435a83..1fa59d8 100644 --- a/src/runtime/ref/nn/runtime/ModelBuilder.cpp +++ b/src/runtime/ref/nn/runtime/ModelBuilder.cpp @@ -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) { diff --git a/src/runtime/ref/nn/runtime/NeuralNetworks.cpp b/src/runtime/ref/nn/runtime/NeuralNetworks.cpp index d720018..f0532f1 100644 --- a/src/runtime/ref/nn/runtime/NeuralNetworks.cpp +++ b/src/runtime/ref/nn/runtime/NeuralNetworks.cpp @@ -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(model); return m->addOperand(*type); -#endif } int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel* model, int32_t index, -- 2.7.4