From 6fc796e36e55925a5f17a3e4c29fe29d7d0b55e3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9C=A4=ED=98=84=EC=8B=9D/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 25 Apr 2019 14:00:14 +0900 Subject: [PATCH] [nnkit] Moving TensorInfoParser & ParsedTensor into util dir (#3356) * [nnkit] Moving TensorInfoParser & ParsedTensor into util dir This commit moves TensorInfoParser & ParsedTensor into util dir. These two files are used by `nnkit tf` and also `nnkit moco tf`. So it would be better to move these into common directory for better reuse. Signed-off-by: Hyun Sik Yoon * modify dir name from `util` to `tftestinfo` * util -> tftestinfo --- contrib/nnkit/libs/support/tf/CMakeLists.txt | 13 +----------- .../support/tf/include/nnkit/support/tf/Backend.h | 4 +++- .../support/tf/include/nnkit/support/tf/Runner.h | 4 +++- .../tf/include/nnkit/support/tf/TensorContext.h | 4 +++- .../tf/include/nnkit/support/tf/TensorDataMap.h | 4 +++- contrib/nnkit/libs/support/tf/src/Backend.cpp | 8 +++++--- contrib/nnkit/libs/support/tf/src/Runner.cpp | 2 ++ .../nnkit/libs/support/tf/src/TensorContext.cpp | 3 +++ .../nnkit/libs/support/tftestinfo/CMakeLists.txt | 24 ++++++++++++++++++++++ contrib/nnkit/libs/support/tftestinfo/README.md | 2 ++ .../nnkit/support/tftestinfo}/ParsedTensor.h | 10 ++++----- .../nnkit/support/tftestinfo}/TensorInfoParser.h | 14 ++++++------- .../{tf => tftestinfo}/src/TensorInfoParser.cpp | 18 ++++++++-------- .../src/TensorInfoParser.test.cpp | 4 ++-- 14 files changed, 73 insertions(+), 41 deletions(-) create mode 100644 contrib/nnkit/libs/support/tftestinfo/CMakeLists.txt create mode 100644 contrib/nnkit/libs/support/tftestinfo/README.md rename contrib/nnkit/libs/support/{tf/include/nnkit/support/tf => tftestinfo/include/nnkit/support/tftestinfo}/ParsedTensor.h (92%) rename contrib/nnkit/libs/support/{tf/include/nnkit/support/tf => tftestinfo/include/nnkit/support/tftestinfo}/TensorInfoParser.h (73%) rename contrib/nnkit/libs/support/{tf => tftestinfo}/src/TensorInfoParser.cpp (92%) rename contrib/nnkit/libs/support/{tf => tftestinfo}/src/TensorInfoParser.test.cpp (96%) diff --git a/contrib/nnkit/libs/support/tf/CMakeLists.txt b/contrib/nnkit/libs/support/tf/CMakeLists.txt index c7a7f86..bffa22d 100644 --- a/contrib/nnkit/libs/support/tf/CMakeLists.txt +++ b/contrib/nnkit/libs/support/tf/CMakeLists.txt @@ -5,22 +5,11 @@ if(NOT TensorFlow_FOUND) endif(NOT TensorFlow_FOUND) file(GLOB_RECURSE SOURCES "src/*.cpp") -file(GLOB_RECURSE TESTS "src/*.test.cpp") -list(REMOVE_ITEM SOURCES ${TESTS}) add_library(nnkit_support_tf-1.12 STATIC ${SOURCES}) set_target_properties(nnkit_support_tf-1.12 PROPERTIES POSITION_INDEPENDENT_CODE ON) target_include_directories(nnkit_support_tf-1.12 PUBLIC include) -target_link_libraries(nnkit_support_tf-1.12 nnkit_intf_backend stdex) +target_link_libraries(nnkit_support_tf-1.12 nnkit_intf_backend stdex nnkit_support_tftestinfo) target_link_libraries(nnkit_support_tf-1.12 tensorflow) add_library(nnkit_support_tf ALIAS nnkit_support_tf-1.12) - -if(NOT ENABLE_TEST) - return() -endif(NOT ENABLE_TEST) - -nncc_find_package(GTest REQUIRED) - -GTest_AddTest(nnkit_tf_test ${TESTS}) -target_link_libraries(nnkit_tf_test nnkit_support_tf) diff --git a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/Backend.h b/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/Backend.h index 906379f..c1022c1 100644 --- a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/Backend.h +++ b/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/Backend.h @@ -19,8 +19,8 @@ #include "nnkit/support/tf/TensorDataMap.h" #include "nnkit/support/tf/TensorContext.h" -#include "nnkit/support/tf/ParsedTensor.h" #include "nnkit/support/tf/Runner.h" +#include "nnkit/support/tftestinfo/ParsedTensor.h" #include @@ -34,6 +34,8 @@ namespace support namespace tf { +using nnkit::support::tftestinfo::ParsedTensor; + class Backend final : public nnkit::Backend { public: diff --git a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/Runner.h b/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/Runner.h index 3079950..b115ed1 100644 --- a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/Runner.h +++ b/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/Runner.h @@ -17,7 +17,7 @@ #ifndef __NNKIT_SUPPORT_TF_RUNNER_H__ #define __NNKIT_SUPPORT_TF_RUNNER_H__ -#include "nnkit/support/tf/ParsedTensor.h" +#include "nnkit/support/tftestinfo/ParsedTensor.h" #include "nnkit/support/tf/TensorDataMap.h" #include @@ -31,6 +31,8 @@ namespace support namespace tf { +using nnkit::support::tftestinfo::ParsedTensor; + class Runner final { public: diff --git a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorContext.h b/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorContext.h index d7011b4..f1ecd6c 100644 --- a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorContext.h +++ b/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorContext.h @@ -18,7 +18,7 @@ #define __NNKIT_SUPPORT_TF_TENSOR_CONTEXT_H__ #include "nnkit/TensorContext.h" -#include "nnkit/support/tf/ParsedTensor.h" +#include "nnkit/support/tftestinfo/ParsedTensor.h" #include "nnkit/support/tf/TensorDataMap.h" #include @@ -30,6 +30,8 @@ namespace support namespace tf { +using nnkit::support::tftestinfo::ParsedTensor; + class TensorContext final : public nnkit::TensorContext { public: diff --git a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorDataMap.h b/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorDataMap.h index d0d72c9..3c214aa 100644 --- a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorDataMap.h +++ b/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorDataMap.h @@ -17,7 +17,7 @@ #ifndef __NNKIT_SUPPORT_TF_TENSOR_DATA_MAP_H__ #define __NNKIT_SUPPORT_TF_TENSOR_DATA_MAP_H__ -#include "nnkit/support/tf/ParsedTensor.h" +#include "nnkit/support/tftestinfo/ParsedTensor.h" #include @@ -32,6 +32,8 @@ namespace support namespace tf { +using nnkit::support::tftestinfo::ParsedTensor; + /** * @brief Class to map parsed tensor and memory for tensor values. * For parsed tensor, this memory is used to fill input or output values of graph. diff --git a/contrib/nnkit/libs/support/tf/src/Backend.cpp b/contrib/nnkit/libs/support/tf/src/Backend.cpp index 09a866e..3774215 100644 --- a/contrib/nnkit/libs/support/tf/src/Backend.cpp +++ b/contrib/nnkit/libs/support/tf/src/Backend.cpp @@ -16,8 +16,8 @@ #include "nnkit/support/tf/Backend.h" -#include "nnkit/support/tf/ParsedTensor.h" -#include "nnkit/support/tf/TensorInfoParser.h" +#include "nnkit/support/tftestinfo/ParsedTensor.h" +#include "nnkit/support/tftestinfo/TensorInfoParser.h" #include "nnkit/support/tf/TensorDataMap.h" #include "nnkit/support/tf/TensorContext.h" #include "nnkit/support/tf/Runner.h" @@ -33,9 +33,11 @@ namespace support namespace tf { +using nnkit::support::tftestinfo::ParsedTensor; + Backend::Backend(const char *pb_path, const char *info_path) : _tf_runner(pb_path) { - auto parsed_tensors = parse(info_path); + auto parsed_tensors = nnkit::support::tftestinfo::parse(info_path); for (auto &parsed_tensor : parsed_tensors) { diff --git a/contrib/nnkit/libs/support/tf/src/Runner.cpp b/contrib/nnkit/libs/support/tf/src/Runner.cpp index 416397d..5088d11 100644 --- a/contrib/nnkit/libs/support/tf/src/Runner.cpp +++ b/contrib/nnkit/libs/support/tf/src/Runner.cpp @@ -40,6 +40,7 @@ #include "nnkit/support/tf/Runner.h" +#include "nnkit/support/tftestinfo/ParsedTensor.h" #include "nncc/core/ADT/tensor/Shape.h" #include @@ -57,6 +58,7 @@ namespace tf { using nncc::core::ADT::tensor::num_elements; +using nnkit::support::tftestinfo::ParsedTensor; namespace { diff --git a/contrib/nnkit/libs/support/tf/src/TensorContext.cpp b/contrib/nnkit/libs/support/tf/src/TensorContext.cpp index e5098fe..528ccba 100644 --- a/contrib/nnkit/libs/support/tf/src/TensorContext.cpp +++ b/contrib/nnkit/libs/support/tf/src/TensorContext.cpp @@ -15,6 +15,7 @@ */ #include "nnkit/support/tf/TensorContext.h" +#include "nnkit/support/tftestinfo/ParsedTensor.h" #include #include @@ -26,6 +27,8 @@ namespace support namespace tf { +using nnkit::support::tftestinfo::ParsedTensor; + void TensorContext::getMutableFloatTensor(uint32_t n, const nnkit::TensorContext::TypedAccessor &f) { // for input diff --git a/contrib/nnkit/libs/support/tftestinfo/CMakeLists.txt b/contrib/nnkit/libs/support/tftestinfo/CMakeLists.txt new file mode 100644 index 0000000..c021128 --- /dev/null +++ b/contrib/nnkit/libs/support/tftestinfo/CMakeLists.txt @@ -0,0 +1,24 @@ +nncc_find_package(TensorFlow QUIET) + +if(NOT TensorFlow_FOUND) + return() +endif(NOT TensorFlow_FOUND) + +file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE TESTS "src/*.test.cpp") +list(REMOVE_ITEM SOURCES ${TESTS}) + +add_library(nnkit_support_tftestinfo STATIC ${SOURCES}) +set_target_properties(nnkit_support_tftestinfo PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(nnkit_support_tftestinfo PUBLIC include) +target_link_libraries(nnkit_support_tftestinfo stdex angkor) +target_link_libraries(nnkit_support_tftestinfo tensorflow) + +if(NOT ENABLE_TEST) + return() +endif(NOT ENABLE_TEST) + +nncc_find_package(GTest REQUIRED) + +GTest_AddTest(nnkit_support_tftestinfo_test ${TESTS}) +target_link_libraries(nnkit_support_tftestinfo_test nnkit_support_tftestinfo) diff --git a/contrib/nnkit/libs/support/tftestinfo/README.md b/contrib/nnkit/libs/support/tftestinfo/README.md new file mode 100644 index 0000000..6bb674a --- /dev/null +++ b/contrib/nnkit/libs/support/tftestinfo/README.md @@ -0,0 +1,2 @@ +# Purpose +This dir contains a helper classes to handle `test.info` files under `moco/test`. diff --git a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/ParsedTensor.h b/contrib/nnkit/libs/support/tftestinfo/include/nnkit/support/tftestinfo/ParsedTensor.h similarity index 92% rename from contrib/nnkit/libs/support/tf/include/nnkit/support/tf/ParsedTensor.h rename to contrib/nnkit/libs/support/tftestinfo/include/nnkit/support/tftestinfo/ParsedTensor.h index 442ce46..b0770f8 100644 --- a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/ParsedTensor.h +++ b/contrib/nnkit/libs/support/tftestinfo/include/nnkit/support/tftestinfo/ParsedTensor.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NNKIT_SUPPORT_TF_PARSED_TENSOR_H__ -#define __NNKIT_SUPPORT_TF_PARSED_TENSOR_H__ +#ifndef __NNKIT_SUPPORT_TFTESTINFO_PARSED_TENSOR_H__ +#define __NNKIT_SUPPORT_TFTESTINFO_PARSED_TENSOR_H__ #include "nncc/core/ADT/tensor/Shape.h" @@ -29,7 +29,7 @@ namespace nnkit { namespace support { -namespace tf +namespace tftestinfo { /** @@ -99,8 +99,8 @@ private: TF_DataType _dtype; }; -} // namespace tf +} // namespace tftestinfo } // namespace support } // namespace nnkit -#endif // __NNKIT_SUPPORT_TF_PARSED_TENSOR_H__ +#endif // __NNKIT_SUPPORT_TFTESTINFO_PARSED_TENSOR_H__ diff --git a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorInfoParser.h b/contrib/nnkit/libs/support/tftestinfo/include/nnkit/support/tftestinfo/TensorInfoParser.h similarity index 73% rename from contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorInfoParser.h rename to contrib/nnkit/libs/support/tftestinfo/include/nnkit/support/tftestinfo/TensorInfoParser.h index 13097f2..9421b5e 100644 --- a/contrib/nnkit/libs/support/tf/include/nnkit/support/tf/TensorInfoParser.h +++ b/contrib/nnkit/libs/support/tftestinfo/include/nnkit/support/tftestinfo/TensorInfoParser.h @@ -16,13 +16,13 @@ /** * @file TensorInfoParser.h - * @brief This file contains functions to parse tensor.info files in moco/test/tf + * @brief This file contains functions to parse test.info files in moco/test/tf */ -#ifndef __NNKIT_SUPPORT_TF_TENSOR_INFO_PARSER_H__ -#define __NNKIT_SUPPORT_TF_TENSOR_INFO_PARSER_H__ +#ifndef __NNKIT_SUPPORT_TFTESTINFO_TENSOR_INFO_PARSER_H__ +#define __NNKIT_SUPPORT_TFTESTINFO_TENSOR_INFO_PARSER_H__ -#include "nnkit/support/tf/ParsedTensor.h" +#include "ParsedTensor.h" #include #include @@ -31,7 +31,7 @@ namespace nnkit { namespace support { -namespace tf +namespace tftestinfo { /** @@ -39,8 +39,8 @@ namespace tf */ std::vector> parse(const char *info_path); -} // namespace tf +} // namespace tftestinfo } // namespace support } // namespace nnkit -#endif // __NNKIT_SUPPORT_TF_TENSOR_INFO_PARSER_H__ +#endif // __NNKIT_SUPPORT_TFTESTINFO_TENSOR_INFO_PARSER_H__ diff --git a/contrib/nnkit/libs/support/tf/src/TensorInfoParser.cpp b/contrib/nnkit/libs/support/tftestinfo/src/TensorInfoParser.cpp similarity index 92% rename from contrib/nnkit/libs/support/tf/src/TensorInfoParser.cpp rename to contrib/nnkit/libs/support/tftestinfo/src/TensorInfoParser.cpp index 327d9d9..99f2d25 100644 --- a/contrib/nnkit/libs/support/tf/src/TensorInfoParser.cpp +++ b/contrib/nnkit/libs/support/tftestinfo/src/TensorInfoParser.cpp @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "nnkit/support/tf/TensorInfoParser.h" -#include "nnkit/support/tf/ParsedTensor.h" +#include "nnkit/support/tftestinfo/TensorInfoParser.h" +#include "nnkit/support/tftestinfo/ParsedTensor.h" #include #include @@ -31,12 +31,14 @@ /** * @file TensorInfoParser.cpp - * @brief This file contains functions to parse tensor.info files in moco/test/tf + * @brief This file contains functions to parse test.info files in moco/test/tf */ namespace { +using nnkit::support::tftestinfo::ParsedTensor; + // remove comment and whitespaces void compact(std::string &line) { @@ -48,12 +50,12 @@ void compact(std::string &line) line.erase(pos, 1); } -nnkit::support::tf::ParsedTensor::Kind get_kind(const std::string &tok) +ParsedTensor::Kind get_kind(const std::string &tok) { if (tok == "input") - return nnkit::support::tf::ParsedTensor::Kind::Input; + return ParsedTensor::Kind::Input; else if (tok == "output") - return nnkit::support::tf::ParsedTensor::Kind::Output; + return ParsedTensor::Kind::Output; else throw std::runtime_error("A line must be either 'input' or 'output' but : " + tok); } @@ -113,7 +115,7 @@ namespace nnkit { namespace support { -namespace tf +namespace tftestinfo { #define CHECK_NOT_NULL(x) \ @@ -206,6 +208,6 @@ std::vector> parse(const char *info_path) return tensors; } -} // namespace tf +} // namespace tftestinfo } // namespace support } // namespace nnkit diff --git a/contrib/nnkit/libs/support/tf/src/TensorInfoParser.test.cpp b/contrib/nnkit/libs/support/tftestinfo/src/TensorInfoParser.test.cpp similarity index 96% rename from contrib/nnkit/libs/support/tf/src/TensorInfoParser.test.cpp rename to contrib/nnkit/libs/support/tftestinfo/src/TensorInfoParser.test.cpp index 4802801..0cd6039 100644 --- a/contrib/nnkit/libs/support/tf/src/TensorInfoParser.test.cpp +++ b/contrib/nnkit/libs/support/tftestinfo/src/TensorInfoParser.test.cpp @@ -15,13 +15,13 @@ */ #include "TensorInfoParser.cpp" -#include "nnkit/support/tf/ParsedTensor.h" +#include "nnkit/support/tftestinfo/ParsedTensor.h" #include #include -using namespace nnkit::support::tf; +using namespace nnkit::support::tftestinfo; namespace { -- 2.7.4