Removed public headers / dependencies for readers plugins (#1534)
authorIlya Lavrenov <ilya.lavrenov@intel.com>
Thu, 30 Jul 2020 04:00:44 +0000 (07:00 +0300)
committerGitHub <noreply@github.com>
Thu, 30 Jul 2020 04:00:44 +0000 (07:00 +0300)
* Removed public headers / depedencies for readers plugins

* Refactored cmake for onnx reader plugin as well

inference-engine/samples/hello_reshape_ssd/CMakeLists.txt
inference-engine/src/readers/ir_reader/CMakeLists.txt
inference-engine/src/readers/ir_reader/ie_ir_parser.hpp
inference-engine/src/readers/ir_reader/ie_ir_reader.cpp
inference-engine/src/readers/ir_reader_v7/CMakeLists.txt
inference-engine/src/readers/onnx_reader/CMakeLists.txt
inference-engine/tests/unit/inference_engine/CMakeLists.txt
inference-engine/tests/unit/inference_engine/ie_blob_proxy_test.cpp [deleted file]

index 808de45..f87718c 100644 (file)
@@ -17,5 +17,5 @@ ie_add_sample(NAME hello_reshape_ssd
               HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/reshape_ssd_extension.hpp"
               OPENCV_DEPENDENCIES imgcodecs)
 
-find_package(ngraph)
+find_package(ngraph REQUIRED)
 target_link_libraries(hello_reshape_ssd PRIVATE ${NGRAPH_LIBRARIES})
index 1396d98..6f1e475 100644 (file)
@@ -8,30 +8,29 @@ if(ENABLE_LTO)
     ie_enable_lto()
 endif()
 
-set(PUBLIC_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/")
-
-file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
-file(GLOB_RECURSE PUBLIC_HEADERS ${PUBLIC_HEADERS_DIR}/*.h ${PUBLIC_HEADERS_DIR}/*.hpp)
+file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
+                              ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
 
 # Create named folders for the sources within the .vcproj
 # Empty name lists them directly under the .vcproj
 
 source_group("src" FILES ${LIBRARY_SRC})
-source_group("include" FILES ${PUBLIC_HEADERS})
 
 # Create shared library
 
-add_library(${TARGET_NAME} SHARED ${LIBRARY_SRC} ${PUBLIC_HEADERS})
+add_library(${TARGET_NAME} SHARED ${LIBRARY_SRC})
 
 target_compile_definitions(${TARGET_NAME} PRIVATE IMPLEMENT_INFERENCE_ENGINE_API
                                                   IMPLEMENT_INFERENCE_ENGINE_PLUGIN
                                                   IR_READER_V10)
 
-target_include_directories(${TARGET_NAME} PUBLIC ${PUBLIC_HEADERS_DIR})
-target_include_directories(${TARGET_NAME} PRIVATE "${IE_MAIN_SOURCE_DIR}/src/inference_engine")
+target_include_directories(${TARGET_NAME} PRIVATE "${IE_MAIN_SOURCE_DIR}/src/inference_engine" # for CNNNetworkNgraphImpl
+                                                  "${CMAKE_CURRENT_SOURCE_DIR}")
 
-target_link_libraries(${TARGET_NAME} PUBLIC inference_engine_reader_api inference_engine_plugin_api ${NGRAPH_LIBRARIES} inference_engine)
-target_link_libraries(${TARGET_NAME} PRIVATE pugixml)
+target_link_libraries(${TARGET_NAME} PRIVATE ${NGRAPH_LIBRARIES}
+                                             inference_engine_reader_api
+                                             inference_engine_plugin_api
+                                             inference_engine pugixml)
 
 # code style
 
index 862622d..ebbfefe 100644 (file)
@@ -4,24 +4,25 @@
 
 #pragma once
 
-#include <ngraph/opsets/opset.hpp>
+#ifdef IR_READER_V10
+# include <ngraph/node.hpp>
+# include <ie_ngraph_utils.hpp>
+#endif  // IR_READER_V10
+
 #include <ie_blob.h>
 #include <ie_icnn_network.hpp>
 #include <ie_iextension.h>
 #include <xml_parse_utils.h>
 
+#include <cctype>
 #include <algorithm>
-#include <details/caseless.hpp>
 #include <map>
 #include <memory>
-#include <ngraph/ngraph.hpp>
 #include <set>
 #include <sstream>
 #include <string>
 #include <vector>
 
-#include "ie_ngraph_utils.hpp"
-
 namespace InferenceEngine {
 
 class IParser {
@@ -48,6 +49,8 @@ public:
     std::shared_ptr<ICNNNetwork> parse(const pugi::xml_node& root, std::istream& binStream) override;
 };
 
+#ifdef IR_READER_V10
+
 class V10Parser : public IParser {
 public:
     explicit V10Parser(const std::vector<IExtensionPtr>& exts);
@@ -291,4 +294,6 @@ private:
     };
 };
 
+#endif  // IR_READER_V10
+
 }  // namespace InferenceEngine
index 61cfb5a..76dd895 100644 (file)
@@ -2,22 +2,17 @@
 // SPDX-License-Identifier: Apache-2.0
 //
 
-#include <file_utils.h>
 #include <xml_parse_utils.h>
 
 #include <ie_ir_version.hpp>
 #include <ie_ir_reader.hpp>
 #include <memory>
-#include <ngraph/ngraph.hpp>
 #include <string>
 #include <vector>
 #include <sstream>
 #include <algorithm>
-#include <cctype>
 
-#include "description_buffer.hpp"
 #include "ie_ir_parser.hpp"
-#include "ie_ngraph_utils.hpp"
 
 using namespace InferenceEngine;
 
index 1200a41..ed76d1d 100644 (file)
@@ -8,31 +8,29 @@ if(ENABLE_LTO)
     ie_enable_lto()
 endif()
 
-set(PUBLIC_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/")
-
-file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
+file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
+                              ${CMAKE_CURRENT_SOURCE_DIR}/*.h
+                              ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
 list(APPEND LIBRARY_SRC ${IE_MAIN_SOURCE_DIR}/src/readers/ir_reader/ie_ir_reader.cpp)
-file(GLOB_RECURSE PUBLIC_HEADERS ${PUBLIC_HEADERS_DIR}/*.h ${PUBLIC_HEADERS_DIR}/*.hpp)
 
 # Create named folders for the sources within the .vcproj
 # Empty name lists them directly under the .vcproj
 
 source_group("src" FILES ${LIBRARY_SRC})
-source_group("include" FILES ${PUBLIC_HEADERS})
 
 # Create shared library
 
-add_library(${TARGET_NAME} SHARED ${LIBRARY_SRC} ${PUBLIC_HEADERS})
+add_library(${TARGET_NAME} SHARED ${LIBRARY_SRC})
 
 target_compile_definitions(${TARGET_NAME} PRIVATE IMPLEMENT_INFERENCE_ENGINE_API
                                                   IMPLEMENT_INFERENCE_ENGINE_PLUGIN)
 
-target_include_directories(${TARGET_NAME} PUBLIC ${PUBLIC_HEADERS_DIR})
-target_include_directories(${TARGET_NAME} PRIVATE "${IE_MAIN_SOURCE_DIR}/src/inference_engine"
+target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/"
+                                                  "${IE_MAIN_SOURCE_DIR}/src/inference_engine"
                                                   "${IE_MAIN_SOURCE_DIR}/src/readers/ir_reader")
 
-target_link_libraries(${TARGET_NAME} PUBLIC inference_engine_reader_api inference_engine_plugin_api ${NGRAPH_LIBRARIES} inference_engine)
-target_link_libraries(${TARGET_NAME} PRIVATE pugixml)
+target_link_libraries(${TARGET_NAME} PRIVATE inference_engine_reader_api inference_engine_plugin_api
+                                             inference_engine pugixml)
 
 # code style
 
index 1708581..084ae3b 100644 (file)
@@ -8,24 +8,22 @@ if(ENABLE_LTO)
     ie_enable_lto()
 endif()
 
-set(PUBLIC_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/")
-
-file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
-file(GLOB_RECURSE PUBLIC_HEADERS ${PUBLIC_HEADERS_DIR}/*.h ${PUBLIC_HEADERS_DIR}/*.hpp)
+file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
+                              ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
 
 # Create named folders for the sources within the .vcproj
 # Empty name lists them directly under the .vcproj
 
 source_group("src" FILES ${LIBRARY_SRC})
-source_group("include" FILES ${PUBLIC_HEADERS})
 
 # Create shared library
 
-add_library(${TARGET_NAME} SHARED ${LIBRARY_SRC} ${PUBLIC_HEADERS})
+add_library(${TARGET_NAME} SHARED ${LIBRARY_SRC})
 
-target_include_directories(${TARGET_NAME} PUBLIC ${PUBLIC_HEADERS_DIR})
+target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
 
 target_compile_definitions(${TARGET_NAME} PRIVATE IMPLEMENT_INFERENCE_ENGINE_PLUGIN)
+
 target_link_libraries(${TARGET_NAME} PRIVATE inference_engine_reader_api onnx_importer inference_engine)
 
 # code style
index 9bf8990..90be3c7 100644 (file)
@@ -25,6 +25,3 @@ addIeTargetTest(
         LABELS
             IE
 )
-
-target_include_directories(${TARGET_NAME} PRIVATE
-    $<TARGET_PROPERTY:inference_engine_ir_v7_reader,INTERFACE_INCLUDE_DIRECTORIES>)
diff --git a/inference-engine/tests/unit/inference_engine/ie_blob_proxy_test.cpp b/inference-engine/tests/unit/inference_engine/ie_blob_proxy_test.cpp
deleted file mode 100644 (file)
index 47070db..0000000
+++ /dev/null
@@ -1,267 +0,0 @@
-// Copyright (C) 2018-2020 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include <ie_blob_proxy.hpp>
-
-#include <gtest/gtest.h>
-#include <gmock/gmock-spec-builders.h>
-
-#include "unit_test_utils/mocks/mock_allocator.hpp"
-
-using namespace ::testing;
-using namespace std;
-using namespace InferenceEngine;
-using namespace InferenceEngine::details;
-
-#define MAKE_SHORT(l, h) h * 0x100 + l
-
-using BlobProxyTests = ::testing::Test;
-
-TEST(BlobProxyTests, convertByteBlobToFloat) {
-    const int size = 4;
-    float test_array[size] = {2.2f, 3.5f, 1.1f, 0.0f};
-    TBlob<uint8_t>::Ptr b(new TBlob<uint8_t>({ Precision::U8, {size * sizeof(float)}, C }));
-    b->allocate();
-    uint8_t *sPtr = reinterpret_cast<uint8_t *>(test_array);
-    uint8_t *dPtr = b->data();
-    ASSERT_EQ(b->size(), size * sizeof(float));
-    for (size_t i = 0; i < b->size(); i++) {
-        dPtr[i] = sPtr[i];
-    }
-}
-
-TEST(BlobProxyTests, shouldNotDeAllocate) {
-    SizeVector v = {1, 2, 3};
-    std::shared_ptr<MockAllocator> allocator(new MockAllocator());
-
-    TBlob<float> blob({ Precision::FP32, v, CHW }, dynamic_pointer_cast<IAllocator>(allocator));
-
-    Blob::Ptr spBlob(&blob, [](Blob*) {
-        //don't delete
-    });
-
-    TBlobProxy<float> proxy(Precision::FP32, C, spBlob, 2, {2});
-
-    EXPECT_EQ(((Blob&)proxy).deallocate(), false);
-}
-
-
-TEST(BlobProxyTests, canAccessProxyBlobUsingBaseMethod) {
-    SizeVector v = {1, 2, 3};
-    std::shared_ptr<MockAllocator> allocator(new MockAllocator());
-
-    float data[] = {5, 6, 7, 8, 9, 10};
-
-    EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))).WillRepeatedly(Return(reinterpret_cast<void*>(1) ));
-    EXPECT_CALL(*allocator.get(), lock(_, LOCK_FOR_WRITE)).WillRepeatedly(Return(data));
-    EXPECT_CALL(*allocator.get(), unlock(_)).Times(1);
-    EXPECT_CALL(*allocator.get(), free(_)).Times(1);
-
-    TBlob<float> blob({ Precision::FP32, v, CHW }, dynamic_pointer_cast<IAllocator>(allocator));
-    blob.allocate();
-
-    Blob::Ptr spBlob(&blob, [](Blob*) {
-        //don't delete
-    });
-
-    TBlobProxy<float> proxy(Precision::FP32, C, spBlob, 2, {2});
-
-    auto proxyBuffer = proxy.buffer();
-    float *ptr = proxyBuffer.as<float*>();
-    ASSERT_EQ(ptr[2] , 9);
-}
-
-TEST(BlobProxyTests, canAccessProxyBlobUsingHelpers) {
-    SizeVector v = {1, 2, 3};
-    std::shared_ptr<MockAllocator> allocator(new MockAllocator());
-
-    float data[] = {5, 6, 7, 8, 9, 10};
-
-    EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))).WillRepeatedly(Return(reinterpret_cast<void*>(1)));
-    EXPECT_CALL(*allocator.get(), lock(_, LOCK_FOR_WRITE)).WillOnce(Return(data));
-    EXPECT_CALL(*allocator.get(), lock(_, LOCK_FOR_READ)).WillOnce(Return(data));
-    EXPECT_CALL(*allocator.get(), unlock(_)).Times(2);
-    EXPECT_CALL(*allocator.get(), free(_)).Times(1);
-
-    TBlob<float> blob({Precision::FP32, v, CHW }, dynamic_pointer_cast<IAllocator>(allocator));
-    blob.allocate();
-
-    Blob::Ptr spBlob(&blob, [](Blob*) {
-        //don't delete
-    });
-
-    TBlobProxy<float> proxy(Precision::FP32, C, spBlob, 2, {2});
-
-    auto proxyData = proxy.data();
-    float *ptr = reinterpret_cast<float*>(&proxyData[0]);
-    ASSERT_EQ(ptr[2] , 9);
-
-    auto readOnly = proxy.readOnly();
-    ptr = readOnly.as<float*>();
-    ASSERT_EQ(ptr[2] , 9);
-}
-
-TEST(BlobProxyTests, canCreateProxyBlobFromDifferentBaseBlobType) {
-    SizeVector v = {1, 2, 3};
-    std::shared_ptr<MockAllocator> allocator(new MockAllocator());
-
-    uint8_t data[] = {5, 6, 7, 8, 9, 10};
-
-    EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(uint8_t))).WillRepeatedly(Return(reinterpret_cast<void*>(1)));
-    EXPECT_CALL(*allocator.get(), lock(_, LOCK_FOR_READ)).WillOnce(Return(data));
-    EXPECT_CALL(*allocator.get(), unlock(_)).Times(1);
-    EXPECT_CALL(*allocator.get(), free(_)).Times(1);
-
-    TBlob<uint8_t > blob({ Precision::U8, v, CHW }, dynamic_pointer_cast<IAllocator>(allocator));
-    blob.allocate();
-
-    Blob::Ptr spBlob(&blob, [](Blob*){
-        //don't delete
-    });
-
-    TBlobProxy<short> proxy(Precision::I16, C, spBlob, 0, {3});
-
-    auto readOnly = proxy.readOnly();
-    const short * ptr = readOnly;
-    ASSERT_EQ(ptr[0] , MAKE_SHORT(data[0], data[1]));
-    ASSERT_EQ(ptr[1] , MAKE_SHORT(data[2], data[3]));
-    ASSERT_EQ(ptr[2] , MAKE_SHORT(data[4], data[5]));
-}
-
-TEST(BlobProxyTests, canNotCreateBlobWithOffsetOfSizeOutOfOriginal) {
-    SizeVector v = {1, 1, 3};
-    std::shared_ptr<MockAllocator> allocator(new MockAllocator());
-
-    EXPECT_CALL(*allocator.get(), alloc(1 * 1 * 3 * sizeof(float))).WillRepeatedly(Return(reinterpret_cast<void*>(1)));
-    EXPECT_CALL(*allocator.get(), free(_)).Times(1);
-
-    TBlob<float> blob({ Precision::FP32, v, CHW }, dynamic_pointer_cast<IAllocator>(allocator));
-    blob.allocate();
-
-    Blob::Ptr spBlob(&blob, [](Blob*){
-        //don't delete
-    });
-
-    EXPECT_THROW(TBlobProxy<float>(Precision::FP32, C, spBlob, 0, {4}), InferenceEngineException);
-    EXPECT_THROW(TBlobProxy<float>(Precision::FP32, C, spBlob, 3, {1}), InferenceEngineException);
-    EXPECT_THROW(TBlobProxy<float>(Precision::FP32, C, spBlob, 2, {2}), InferenceEngineException);
-}
-
-
-TEST(BlobProxyTests, canAccessBothArraysAfterProxying) {
-    SizeVector v = {1, 2, 4};
-    std::shared_ptr<MockAllocator> allocator(new MockAllocator());
-
-    uint8_t data[] = {5, 6, 7, 8, 9, 10, 11, 12};
-
-    EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 4 * sizeof(uint8_t))).WillRepeatedly(Return(reinterpret_cast<void*>(1)));
-    EXPECT_CALL(*allocator.get(), lock(_, LOCK_FOR_READ)).Times(2).WillRepeatedly(Return(data));
-    EXPECT_CALL(*allocator.get(), unlock(_)).Times(2);
-    EXPECT_CALL(*allocator.get(), free(_)).Times(1);
-
-    TBlob<uint8_t> blob({ Precision::U8, v, CHW }, dynamic_pointer_cast<IAllocator>(allocator));
-    blob.allocate();
-
-    Blob::Ptr spBlob(&blob, [](Blob*){
-        //don't delete
-    });
-
-    TBlobProxy<short> proxy(Precision::I16, C, spBlob, 2, {3});
-
-    auto readOnly = proxy.readOnly();
-    short* ptr = readOnly.as<short*>();
-    ASSERT_EQ(ptr[0] , MAKE_SHORT(data[2], data[3]));
-    ASSERT_EQ(ptr[1] , MAKE_SHORT(data[4], data[5]));
-
-    auto origBuffer = blob.readOnly();
-    const uint8_t* origPtr = origBuffer;
-
-    ASSERT_EQ(origPtr[0] , 5);
-    ASSERT_EQ(origPtr[1] , 6);
-}
-
-TEST(BlobProxyTests, convertTwoByteBlobToFloat) {
-    const int size = 4;
-    float test_array[size] = {2.2f, 3.5f, 1.1f, 0.0f};
-    TBlob<uint16_t>::Ptr b(new TBlob<uint16_t>(TensorDesc(Precision::U16, {size*sizeof(float) / sizeof(uint16_t)}, C)));
-    b->allocate();
-    uint16_t *sPtr = reinterpret_cast<uint16_t *>(test_array);
-    uint16_t *dPtr = b->data();
-    ASSERT_EQ(b->byteSize(), size*sizeof(float));
-    ASSERT_EQ(b->size(), size*sizeof(float)/sizeof(uint16_t));
-    for (size_t i = 0; i < b->size(); i++) {
-        dPtr[i] = sPtr[i];
-    }
-
-    TBlobProxy<float>::Ptr proxy(new TBlobProxy<float>(Precision::FP32, C, b, sizeof(float) / sizeof(uint16_t), {size - 1}));
-    ASSERT_NEAR(3.5f, proxy->data()[0], 0.0001f);
-    ASSERT_NEAR(1.1f, proxy->data()[1], 0.0001f);
-    ASSERT_NEAR(0.0f, proxy->data()[2], 0.0001f);
-    ASSERT_EQ(size - 1, proxy->size());
-    ASSERT_EQ(size*sizeof(float) - sizeof(float), proxy->byteSize());
-}
-
-TEST(BlobProxyTests, throwsIfSmallProxyObjectSize) {
-    TBlob<float>::Ptr b(new TBlob<float>(TensorDesc(Precision::FP32, C)));
-
-    b->getTensorDesc().setDims({3});
-    b->allocate();
-    b->data()[0] = 1.0f;
-    b->data()[1] = 2.0f;
-    b->data()[2] = 3.0f;
-
-    ASSERT_ANY_THROW(
-            TBlobProxy<uint8_t> proxy(Precision::U8, C, b, 0, { b->byteSize() + 1 })) << "Should have failed by now: proxy size is larger than blob size";
-}
-
-TEST(BlobProxyTests, canReturnConstantData) {
-    TBlob<float>::Ptr b(new TBlob<float>(TensorDesc(Precision::FP32, C)));
-
-    b->getTensorDesc().setDims({3});
-    b->allocate();
-    b->data()[0] = 1.0f;
-    b->data()[1] = 2.0f;
-    b->data()[2] = 3.0f;
-
-    TBlobProxy<uint8_t> const proxy(Precision::U8, C, b, 0, { b->byteSize() });
-    ASSERT_NE(proxy.cbuffer().as<const void*>(), nullptr);
-}
-
-TEST(BlobProxyTests, canIterateOverData) {
-    TBlob<uint8_t>::Ptr b(new TBlob<uint8_t >(TensorDesc(Precision::FP32, C)));
-
-    b->getTensorDesc().setDims({3});
-    b->allocate();
-    b->data()[0] = 1.0f;
-    b->data()[1] = 2.0f;
-    b->data()[2] = 3.0f;
-
-    TBlobProxy<uint8_t> proxy(Precision::U8, C, b, 1, { 2 });
-    vector<uint8_t > u8buffer;
-    for (auto & element : proxy) {
-        u8buffer.push_back(element);
-    }
-    ASSERT_EQ(2, u8buffer.size());
-    ASSERT_EQ(2, u8buffer[0]);
-    ASSERT_EQ(3, u8buffer[1]);
-}
-
-TEST(BlobProxyTests, canIterateOverReadOnly) {
-    TBlob<uint8_t>::Ptr b(new TBlob<uint8_t >(TensorDesc(Precision::FP32, C)));
-
-    b->getTensorDesc().setDims({3});
-    b->allocate();
-    b->data()[0] = 1.0f;
-    b->data()[1] = 2.0f;
-    b->data()[2] = 3.0f;
-
-    TBlobProxy<uint8_t> const proxy(Precision::U8, C, b, 1, { 2 });
-    vector<uint8_t > u8buffer;
-    for (auto  element : proxy) {
-        u8buffer.push_back(element);
-    }
-    ASSERT_EQ(2, u8buffer.size());
-    ASSERT_EQ(2, u8buffer[0]);
-    ASSERT_EQ(3, u8buffer[1]);
-}