Skip to content

Commit

Permalink
[LPT] LPT CNNNetwork usage macros: part #2: cmake files update and te…
Browse files Browse the repository at this point in the history
…sts addoption
  • Loading branch information
eshoguli committed Oct 19, 2020
1 parent 4021c8c commit a0e4209
Show file tree
Hide file tree
Showing 70 changed files with 180 additions and 612 deletions.
2 changes: 2 additions & 0 deletions inference-engine/src/cldnn_engine/cldnn_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@
#include <sys/stat.h>
#include <exec_graph_info.hpp>

#ifdef USE_CNNNETWORK_LPT
#include "low_precision_transformations/transformer.hpp"
#include "low_precision_transformations/fully_connected.hpp"
#include "low_precision_transformations/gemm.hpp"
#endif

#include <iostream>
#include <iomanip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# SPDX-License-Identifier: Apache-2.0
#

if (NOT USE_CNNNETWORK_LPT)
add_library("inference_engine_lp_transformations" ALIAS "inference_engine_transformations")
return()
endif()

set (TARGET_NAME "inference_engine_lp_transformations")

set(PUBLIC_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
Expand Down Expand Up @@ -49,3 +54,5 @@ install(TARGETS ${TARGET_NAME}
RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT core
ARCHIVE DESTINATION ${IE_CPACK_ARCHIVE_PATH} COMPONENT core
LIBRARY DESTINATION ${IE_CPACK_LIBRARY_PATH} COMPONENT core)

target_compile_definitions(${TARGET_NAME} PUBLIC USE_CNNNETWORK_LPT)
6 changes: 4 additions & 2 deletions inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
#include <legacy/ie_util_internal.hpp>
#include <legacy/graph_tools.hpp>
#include <threading/ie_executor_manager.hpp>

#ifdef USE_CNNNETWORK_LPT
#include "low_precision_transformations/convolution.hpp"
#include "low_precision_transformations/eltwise.hpp"
#include "low_precision_transformations/fully_connected.hpp"
#include "low_precision_transformations/scaleshift_to_convolution.hpp"
#include "low_precision_transformations/transformer.hpp"
#endif

#include <threading/ie_cpu_streams_executor.hpp>
#include <ie_system_conf.h>
#include <threading/ie_thread_affinity.hpp>
Expand Down
1 change: 0 additions & 1 deletion inference-engine/src/mkldnn_plugin/mkldnn_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

#include "precision_utils.h"
#include <ie_plugin_config.hpp>
#include "low_precision_transformations/transformer.hpp"

#include "utils/blob_dump.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TRANSFORMATIONS_API EltwiseBaseTransformation : public LayerTransformation
bool canBeTransformed(const TransformationContext& context, std::shared_ptr<Node> layer) const override;
bool isPrecisionPreserved(std::shared_ptr<Node> layer) const noexcept override;

static bool isBroadcasted(const Shape& shape) noexcept;
protected:
int getNotEmpty(const std::shared_ptr<Node>& eltwise) const;
std::pair<int, int> getMultiplyConstBranch(const std::shared_ptr<Node>& eltwise) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using namespace ngraph;
using namespace ngraph::pass;
using namespace ngraph::pass::low_precision;

bool isBroadcasted(const Shape& shape) noexcept {
bool EltwiseBaseTransformation::isBroadcasted(const Shape& shape) noexcept {
const size_t spatialIndex = shape.size() == 1 ? 0ul : (shape.size() == 2ul ? 1ul : 2ul);
for (size_t i = spatialIndex; i < shape.size(); ++i) {
if (shape[i] != 1ul) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,47 @@
//

#include <gtest/gtest.h>
#include "low_precision_transformations/eltwise.hpp"
#include "transformations/low_precision/eltwise_base_transformation.hpp"

#include <ie_data.h>

using namespace ::testing;
using namespace std;
using namespace InferenceEngine;
using namespace InferenceEngine::details;

using namespace ngraph;
using namespace ngraph::pass::low_precision;

class EltwiseTransformationIsBroadcastedTests : public ::testing::Test {
protected:
const TensorDesc c1 = TensorDesc(Precision::FP32, { 1ul }, Layout::C);
const TensorDesc c1000 = TensorDesc(Precision::FP32, { 1000ul }, Layout::C);
const TensorDesc n1c1 = TensorDesc(Precision::FP32, { 1ul, 1ul }, Layout::NC);
const TensorDesc n1c256 = TensorDesc(Precision::FP32, { 1ul, 256ul }, Layout::NC);
const TensorDesc n1c1000h1w1 = TensorDesc(Precision::FP32, { 1ul, 1000ul, 1ul, 1ul }, Layout::NCHW);
const TensorDesc n1c32h144w144 = TensorDesc(Precision::FP32, { 1ul, 32ul, 144ul, 144ul }, Layout::NCHW);
const Shape c1 = Shape({ 1ul });
const Shape c1000 = Shape({ 1000ul });
const Shape n1c1 = Shape({ 1ul, 1ul });
const Shape n1c256 = Shape({ 1ul, 256ul });
const Shape n1c1000h1w1 = Shape({ 1ul, 1000ul, 1ul, 1ul });
const Shape n1c32h144w144 = Shape({ 1ul, 32ul, 144ul, 144ul });
};

TEST_F(EltwiseTransformationIsBroadcastedTests, c1) {
ASSERT_TRUE(EltwiseTransformation::isBroadcasted(c1));
ASSERT_TRUE(EltwiseBaseTransformation::isBroadcasted(c1));
}

TEST_F(EltwiseTransformationIsBroadcastedTests, c1000) {
ASSERT_FALSE(EltwiseTransformation::isBroadcasted(c1000));
ASSERT_FALSE(EltwiseBaseTransformation::isBroadcasted(c1000));
}

TEST_F(EltwiseTransformationIsBroadcastedTests, n1c1) {
ASSERT_TRUE(EltwiseTransformation::isBroadcasted(n1c1));
ASSERT_TRUE(EltwiseBaseTransformation::isBroadcasted(n1c1));
}

TEST_F(EltwiseTransformationIsBroadcastedTests, n1c256) {
ASSERT_FALSE(EltwiseTransformation::isBroadcasted(n1c256));
ASSERT_FALSE(EltwiseBaseTransformation::isBroadcasted(n1c256));
}

TEST_F(EltwiseTransformationIsBroadcastedTests, n1c1000h1w1) {
ASSERT_TRUE(EltwiseTransformation::isBroadcasted(n1c1000h1w1));
ASSERT_TRUE(EltwiseBaseTransformation::isBroadcasted(n1c1000h1w1));
}

TEST_F(EltwiseTransformationIsBroadcastedTests, n1c32h144w144) {
ASSERT_FALSE(EltwiseTransformation::isBroadcasted(n1c32h144w144));
ASSERT_FALSE(EltwiseBaseTransformation::isBroadcasted(n1c32h144w144));
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,50 @@
//

#include <gtest/gtest.h>
#include "low_precision_transformations/transformer.hpp"
#include "transformations/low_precision/transformer.hpp"

using namespace ::testing;
using namespace InferenceEngine;
using namespace InferenceEngine::details;
using namespace ngraph::pass::low_precision;

class LowPrecisionTransformationsTests : public Test {};

TEST_F(LowPrecisionTransformationsTests, remove) {
LowPrecisionTransformations transformations = LowPrecisionTransformer::getAllTransformations(LayerTransformation::Params());
LayerTransformationPtr transformation = transformations.find("ScaleShift");
ASSERT_NE(nullptr, transformation);
auto transformation = transformations.find("Convolution");
ASSERT_NE(0, transformation.size());

transformations.remove("ScaleShift");
transformation = transformations.find("ScaleShift");
ASSERT_EQ(nullptr, transformation);
transformations.remove("Convolution");
transformation = transformations.find("Convolution");
ASSERT_EQ(0, transformation.size());
}

TEST_F(LowPrecisionTransformationsTests, removeBranchSpecificTransformations) {
LowPrecisionTransformations transformations = LowPrecisionTransformer::getAllTransformations(LayerTransformation::Params());
LayerTransformationPtr transformation = transformations.find("Concat");
ASSERT_NE(nullptr, transformation);
auto transformation = transformations.find("Concat");
ASSERT_NE(0, transformation.size());

transformations.removeBranchSpecificTransformations("Concat");
transformation = transformations.find("Concat");
ASSERT_EQ(nullptr, transformation);
ASSERT_EQ(0, transformation.size());
}

TEST_F(LowPrecisionTransformationsTests, removeTransformations) {
LowPrecisionTransformations transformations = LowPrecisionTransformer::getAllTransformations(LayerTransformation::Params());
LayerTransformationPtr transformation = transformations.find("FullyConnected");
ASSERT_NE(nullptr, transformation);
auto transformation = transformations.find("MatMul");
ASSERT_NE(0, transformation.size());

transformations.removeTransformations("FullyConnected");
transformation = transformations.find("FullyConnected");
ASSERT_EQ(nullptr, transformation);
transformations.removeTransformations("MatMul");
transformation = transformations.find("MatMul");
ASSERT_EQ(0, transformation.size());
}

TEST_F(LowPrecisionTransformationsTests, removeCleanupTransformations) {
LowPrecisionTransformations transformations = LowPrecisionTransformer::getAllTransformations(LayerTransformation::Params());
LayerTransformationPtr transformation = transformations.find("ScaleShift");
ASSERT_NE(nullptr, transformation);
auto transformation = transformations.find("Multiply");
ASSERT_NE(0, transformation.size());
const size_t originalSize = transformation.size();

transformations.removeCleanupTransformations("ScaleShift");
transformation = transformations.find("ScaleShift");
ASSERT_EQ(nullptr, transformation);
transformations.removeCleanupTransformations("Multiply");
transformation = transformations.find("Multiply");
ASSERT_EQ(originalSize - 1, transformation.size());
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

#include <gtest/gtest.h>
#include <gmock/gmock-spec-builders.h>
#include "low_precision_transformations/layer_transformation.hpp"
#include "low_precision_transformations/fake_quantize.hpp"
#include "transformations/low_precision/layer_transformation.hpp"
#include "transformations/low_precision/fake_quantize.hpp"

#include <ie_data.h>

using namespace ::testing;
using namespace std;
using namespace InferenceEngine;
using namespace InferenceEngine::details;
using namespace ngraph::pass::low_precision;

class PrecisionDetailsTests : public ::testing::Test {
protected:
Expand All @@ -27,7 +26,7 @@ TEST_F(PrecisionDetailsTests, getPrecisionDetailsI8levels255WithoutZeroPoint) {
LayerTransformation::Params params = LayerTransformation::Params();
FakeQuantizeTransformation fakeQuantizeTransformation(params);
const LayerTransformation::PrecisionDetails precisionDetails = fakeQuantizeTransformation.getPrecisionDetails(i8levels255WithoutZeroPoint);
ASSERT_EQ(Precision::I8, precisionDetails.precision);
ASSERT_EQ(ngraph::element::i8, precisionDetails.precision);
ASSERT_TRUE(precisionDetails.hasNegativeOutput);
ASSERT_FALSE(precisionDetails.hasZeroPoint);
}
Expand All @@ -36,7 +35,7 @@ TEST_F(PrecisionDetailsTests, getPrecisionDetailsI8levels255WithZeroPoint) {
LayerTransformation::Params params = LayerTransformation::Params();
FakeQuantizeTransformation fakeQuantizeTransformation(params);
const LayerTransformation::PrecisionDetails precisionDetails = fakeQuantizeTransformation.getPrecisionDetails(i8levels255WithZeroPoint);
ASSERT_EQ(Precision::UNSPECIFIED, precisionDetails.precision);
ASSERT_EQ(ngraph::element::undefined, precisionDetails.precision);
ASSERT_TRUE(precisionDetails.hasNegativeOutput);
ASSERT_TRUE(precisionDetails.hasZeroPoint);
}
Expand All @@ -45,7 +44,7 @@ TEST_F(PrecisionDetailsTests, getPrecisionDetailsI8levels256WithoutZeroPoint) {
LayerTransformation::Params params = LayerTransformation::Params();
FakeQuantizeTransformation fakeQuantizeTransformation(params);
const LayerTransformation::PrecisionDetails precisionDetails = fakeQuantizeTransformation.getPrecisionDetails(i8levels256WithoutZeroPoint);
ASSERT_EQ(Precision::I8, precisionDetails.precision);
ASSERT_EQ(ngraph::element::i8, precisionDetails.precision);
ASSERT_TRUE(precisionDetails.hasNegativeOutput);
ASSERT_FALSE(precisionDetails.hasZeroPoint);
}
Expand All @@ -54,7 +53,7 @@ TEST_F(PrecisionDetailsTests, getPrecisionDetailsU8levels256WithoutZeroPoint) {
LayerTransformation::Params params = LayerTransformation::Params();
FakeQuantizeTransformation fakeQuantizeTransformation(params);
const LayerTransformation::PrecisionDetails precisionDetails = fakeQuantizeTransformation.getPrecisionDetails(u8levels256WithoutZeroPoint);
ASSERT_EQ(Precision::U8, precisionDetails.precision);
ASSERT_EQ(ngraph::element::u8, precisionDetails.precision);
ASSERT_FALSE(precisionDetails.hasNegativeOutput);
ASSERT_FALSE(precisionDetails.hasZeroPoint);
}
Expand All @@ -63,7 +62,7 @@ TEST_F(PrecisionDetailsTests, getPrecisionDetailsU8levels256WithZeroPoint) {
LayerTransformation::Params params = LayerTransformation::Params();
FakeQuantizeTransformation fakeQuantizeTransformation(params);
const LayerTransformation::PrecisionDetails precisionDetails = fakeQuantizeTransformation.getPrecisionDetails(u8levels256WithZeroPoint);
ASSERT_EQ(Precision::UNSPECIFIED, precisionDetails.precision);
ASSERT_EQ(ngraph::element::undefined, precisionDetails.precision);
ASSERT_FALSE(precisionDetails.hasNegativeOutput);
ASSERT_TRUE(precisionDetails.hasZeroPoint);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "common_test_utils/test_constants.hpp"

using namespace LayerTestsDefinitions;
using namespace InferenceEngine::details;
using namespace ngraph::pass::low_precision;

namespace {
const std::vector<InferenceEngine::Precision> netPrecisions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "ngraph_functions/low_precision_transformations/fake_quantize_function.hpp"

using namespace LayerTestsDefinitions;
using namespace InferenceEngine::details;
using namespace ngraph::pass::low_precision;

namespace {
const std::vector<InferenceEngine::Precision> netPrecisions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "ngraph_functions/low_precision_transformations/fake_quantize_function.hpp"

using namespace LayerTestsDefinitions;
using namespace InferenceEngine::details;
using namespace ngraph::pass::low_precision;

namespace {
const std::vector<InferenceEngine::Precision> netPrecisions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "ngraph_functions/low_precision_transformations/fuse_fake_quantize_and_scale_shift_function.hpp"

using namespace LayerTestsDefinitions;
using namespace InferenceEngine::details;
using namespace ngraph::pass::low_precision;

namespace {
const std::vector<InferenceEngine::Precision> netPrecisions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "common_test_utils/test_constants.hpp"

using namespace LayerTestsDefinitions;
using namespace InferenceEngine::details;
using namespace ngraph::pass::low_precision;

namespace {
const std::vector<InferenceEngine::Precision> netPrecisions = {
Expand Down
Loading

0 comments on commit a0e4209

Please sign in to comment.