Fixed precisions conversion in new API with compile_model(filename) (#7711)

* Fixed precisions conversion in new API

* Added tests

* Fixed old IR cases

* Disable FP16
This commit is contained in:
Ilya Lavrenov 2021-09-29 07:00:13 +03:00 committed by GitHub
parent d2878e4012
commit bd09f70876
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 447 additions and 17 deletions

View File

@ -0,0 +1,50 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "behavior/ov_exec_network.hpp"
#include "ie_plugin_config.hpp"
using namespace ov::test;
namespace {
const std::vector<ov::element::Type> netPrecisions = {
ov::element::i8,
ov::element::i16,
ov::element::i32,
ov::element::i64,
ov::element::u8,
ov::element::u16,
ov::element::u32,
ov::element::u64,
ov::element::f16,
ov::element::f32,
};
const std::vector<std::map<std::string, std::string>> configs = {
{},
};
const std::vector<std::map<std::string, std::string>> multiConfigs = {
{{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_TEMPLATE}}};
INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests,
OVExecNetwork,
::testing::Combine(::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_TEMPLATE),
::testing::ValuesIn(configs)),
OVExecNetwork::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Multi_BehaviorTests,
OVExecNetwork,
::testing::Combine(::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_MULTI),
::testing::ValuesIn(multiConfigs)),
OVExecNetwork::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests,
OVExecNetwork,
::testing::Combine(::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_AUTO),
::testing::ValuesIn(multiConfigs)),
OVExecNetwork::getTestCaseName);
} // namespace

View File

@ -42,6 +42,8 @@ using namespace std::placeholders;
namespace ov {
namespace runtime {
namespace {
template <typename T>
struct Parsed {
std::string _deviceName;
@ -118,6 +120,13 @@ ie::Parameter copyParameterValue(const ie::Parameter& value) {
return std::move(value);
}
ie::CNNNetwork toCNN(const std::shared_ptr<const ngraph::Function>& model) {
return ie::CNNNetwork(
std::make_shared<ie::details::CNNNetworkNGraphImpl>(std::const_pointer_cast<ngraph::Function>(model),
std::vector<ie::IExtensionPtr>{},
true));
}
template <typename F>
void allowNotImplemented(F&& f) {
try {
@ -126,6 +135,8 @@ void allowNotImplemented(F&& f) {
}
}
} // namespace
class CoreImpl : public ie::ICore, public std::enable_shared_from_this<ie::ICore> {
mutable std::map<std::string, ov::runtime::InferencePlugin> plugins;
@ -180,6 +191,8 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this<ie::ICore
std::map<std::string, PluginDescriptor> pluginRegistry;
mutable std::mutex pluginsMutex; // to lock parallel access to pluginRegistry and plugins
const bool newAPI;
bool DeviceSupportsImportExport(const std::string& deviceName) const override {
auto parsed = parseDeviceNameIntoConfig(deviceName);
auto plugin = GetCPPPluginByName(parsed._deviceName);
@ -345,7 +358,7 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this<ie::ICore
}
public:
CoreImpl() {
CoreImpl(bool _newAPI) : newAPI(_newAPI) {
opsetNames.insert("opset1");
opsetNames.insert("opset2");
opsetNames.insert("opset3");
@ -437,12 +450,28 @@ public:
ie::CNNNetwork ReadNetwork(const std::string& modelPath, const std::string& binPath) const override {
OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::IE_RT, "CoreImpl::ReadNetwork from file");
return ie::details::ReadNetwork(modelPath, binPath, extensions);
auto cnnNet = InferenceEngine::details::ReadNetwork(modelPath, binPath, extensions);
OPENVINO_ASSERT(cnnNet.getFunction() || !newAPI, "Cannot read IR v7 from OpenVINO 2.0 API");
if (!newAPI)
return cnnNet;
return InferenceEngine::CNNNetwork(std::make_shared<InferenceEngine::details::CNNNetworkNGraphImpl>(
cnnNet.getFunction(),
std::vector<InferenceEngine::IExtensionPtr>{},
newAPI));
}
ie::CNNNetwork ReadNetwork(const std::string& model, const ie::Blob::CPtr& weights) const override {
OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::IE_RT, "CoreImpl::ReadNetwork from memory");
return ie::details::ReadNetwork(model, weights, extensions);
auto cnnNet = InferenceEngine::details::ReadNetwork(model, weights, extensions);
OPENVINO_ASSERT(cnnNet.getFunction() || !newAPI, "Cannot read IR v7 from OpenVINO 2.0 API");
if (!newAPI)
return cnnNet;
return InferenceEngine::CNNNetwork(std::make_shared<InferenceEngine::details::CNNNetworkNGraphImpl>(
cnnNet.getFunction(),
std::vector<InferenceEngine::IExtensionPtr>{},
newAPI));
}
// TODO: In future this method can be added to ICore interface
@ -980,7 +1009,10 @@ std::vector<std::string> DeviceIDParser::getMultiDevices(std::string devicesList
return deviceNames;
}
class Core::Impl : public ov::runtime::CoreImpl {};
class Core::Impl : public ov::runtime::CoreImpl {
public:
Impl() : ov::runtime::CoreImpl(false) {}
};
Core::Core(const std::string& xmlConfigFile) {
_impl = std::make_shared<Impl>();
@ -1244,7 +1276,10 @@ namespace runtime {
OPENVINO_ASSERT(false, "Unexpected exception"); \
}
class Core::Impl : public CoreImpl {};
class Core::Impl : public CoreImpl {
public:
Impl() : ov::runtime::CoreImpl(true) {}
};
Core::Core(const std::string& xmlConfigFile) {
_impl = std::make_shared<Impl>();
@ -1278,17 +1313,6 @@ std::shared_ptr<ngraph::Function> Core::read_model(const std::string& model, con
OV_CORE_CALL_STATEMENT(return _impl->ReadNetwork(model, weights).getFunction(););
}
namespace {
ie::CNNNetwork toCNN(const std::shared_ptr<const ngraph::Function>& model) {
return ie::CNNNetwork(
std::make_shared<ie::details::CNNNetworkNGraphImpl>(std::const_pointer_cast<ngraph::Function>(model),
std::vector<ie::IExtensionPtr>{},
true));
}
} // namespace
ExecutableNetwork Core::compile_model(const std::shared_ptr<const ngraph::Function>& model,
const std::string& deviceName,
const ConfigMap& config) {
@ -1303,7 +1327,6 @@ ExecutableNetwork Core::compile_model(const std::string& modelPath,
const std::string& deviceName,
const ConfigMap& config) {
OV_CORE_CALL_STATEMENT({
// TODO: need to pass newAPI flag to preserve conversions of precisions
auto exec = _impl->LoadNetwork(modelPath, deviceName, config);
return {exec.operator const InferenceEngine::details::SharedObjectLoader&().get(),
exec.operator std::shared_ptr<InferenceEngine::IExecutableNetworkInternal>&()};

View File

@ -0,0 +1,50 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "behavior/ov_exec_network.hpp"
#include "ie_plugin_config.hpp"
using namespace ov::test;
namespace {
const std::vector<ov::element::Type> netPrecisions = {
ov::element::i8,
ov::element::i16,
ov::element::i32,
ov::element::i64,
ov::element::u8,
ov::element::u16,
ov::element::u32,
ov::element::u64,
ov::element::f16,
ov::element::f32,
};
const std::vector<std::map<std::string, std::string>> configs = {
{},
};
const std::vector<std::map<std::string, std::string>> multiConfigs = {
{{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_CPU}}};
INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests,
OVExecNetwork,
::testing::Combine(::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::ValuesIn(configs)),
OVExecNetwork::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Multi_BehaviorTests,
OVExecNetwork,
::testing::Combine(::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_MULTI),
::testing::ValuesIn(multiConfigs)),
OVExecNetwork::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests,
OVExecNetwork,
::testing::Combine(::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_AUTO),
::testing::ValuesIn(multiConfigs)),
OVExecNetwork::getTestCaseName);
} // namespace

View File

@ -91,6 +91,15 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*ReduceOpsLayerTest.*type=Mean_.*netPRC=(I64|I32).*)",
R"(.*ReduceOpsLayerTest.*type=Mean_.*netPRC=U64.*)",
// TODO: CVS-66526 overrides i/o precisions in execution graph
R"(.*smoke_BehaviorTests.*OVExecNetwork.*type=(i8|i16).*)",
R"(.*smoke_BehaviorTests.*OVExecNetwork.*type=(i64|u16).*)",
R"(.*smoke_BehaviorTests.*OVExecNetwork.*type=(u32|u64).*)",
R"(.*smoke_BehaviorTests.*OVExecNetwork.*type=f16.*)",
R"(.*smoke_(Auto|Multi)_BehaviorTests.*OVExecNetwork.*type=(i8|u32).*)",
R"(.*smoke_(Auto|Multi)_BehaviorTests.*OVExecNetwork.*type=f16.*)",
R"(.*smoke_(Auto|Multi)_BehaviorTests/OVExecNetwork.*type=i8.*)",
// Issue: 62746
R"(smoke_CachingSupportCase_CPU/LoadNetworkCacheTestBase.CompareWithRefImpl/ReadConcatSplitAssign_f32_batch1_CPU)",
};

View File

@ -0,0 +1,227 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <gtest/gtest.h>
#include <memory>
#include <string>
#include <tuple>
#include <typeindex>
#include <vector>
#include "common_test_utils/test_common.hpp"
#include "functional_test_utils/ov_plugin_cache.hpp"
#include "functional_test_utils/skip_tests_config.hpp"
#include "ngraph_functions/subgraph_builders.hpp"
#include "openvino/runtime/runtime.hpp"
namespace ov {
namespace test {
using BehaviorParamsEmptyConfig = std::tuple<ov::element::Type, // element type
std::string>; // device
class BehaviorTestsEmptyConfig : public testing::WithParamInterface<BehaviorParamsEmptyConfig>,
public CommonTestUtils::TestsCommon {
public:
static std::string getTestCaseName(testing::TestParamInfo<BehaviorParamsEmptyConfig> obj) {
std::string targetDevice;
ov::element::Type elementType;
std::tie(elementType, targetDevice) = obj.param;
std::ostringstream result;
result << "element_type=" << elementType;
result << "targetDevice=" << targetDevice;
return result.str();
}
void SetUp() override {
std::tie(elementType, targetDevice) = this->GetParam();
function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType);
}
void TearDown() override {
function.reset();
}
std::shared_ptr<ov::runtime::Core> ie = PluginCache::get().core();
std::shared_ptr<ngraph::Function> function;
std::string targetDevice;
ov::element::Type elementType;
};
using BehaviorBasicParams = std::tuple<ov::element::Type, // element type
std::string, // device
std::map<std::string, std::string>>; // config
class BehaviorTestsBasic : public testing::WithParamInterface<BehaviorBasicParams>,
public CommonTestUtils::TestsCommon {
public:
static std::string getTestCaseName(testing::TestParamInfo<BehaviorBasicParams> obj) {
std::string targetDevice;
ov::element::Type elementType;
std::map<std::string, std::string> configuration;
std::tie(elementType, targetDevice, configuration) = obj.param;
std::ostringstream result;
result << "element_type=" << elementType << "_";
result << "targetDevice=" << targetDevice << "_";
if (!configuration.empty()) {
for (auto& configItem : configuration) {
result << "configItem=" << configItem.first << "_" << configItem.second << "_";
}
}
return result.str();
}
void SetUp() override {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
std::tie(elementType, targetDevice, configuration) = this->GetParam();
function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType);
}
void TearDown() override {
if (!configuration.empty()) {
PluginCache::get().reset();
}
function.reset();
}
std::shared_ptr<ov::runtime::Core> ie = PluginCache::get().core();
std::shared_ptr<ngraph::Function> function;
std::string targetDevice;
std::map<std::string, std::string> configuration;
ov::element::Type elementType;
};
using InferRequestParams = std::tuple<ov::element::Type, // element type
std::string, // device
std::map<std::string, std::string>>; // config
class InferRequestTests : public testing::WithParamInterface<InferRequestParams>, public CommonTestUtils::TestsCommon {
public:
static std::string getTestCaseName(testing::TestParamInfo<InferRequestParams> obj) {
std::string targetDevice;
ov::element::Type elementType;
std::map<std::string, std::string> configuration;
std::tie(elementType, targetDevice, configuration) = obj.param;
std::ostringstream result;
result << "element_type=" << elementType;
result << "targetDevice=" << targetDevice << "_";
if (!configuration.empty()) {
for (auto& configItem : configuration) {
result << "configItem=" << configItem.first << "_" << configItem.second << "_";
}
}
return result.str();
}
void SetUp() override {
// Skip test according to plugin specific disabledTestPatterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED()
std::tie(elementType, targetDevice, configuration) = this->GetParam();
function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType);
// Load CNNNetwork to target plugins
execNet = ie->compile_model(function, targetDevice, configuration);
}
void TearDown() override {
if (!configuration.empty()) {
PluginCache::get().reset();
}
function.reset();
}
protected:
ov::runtime::ExecutableNetwork execNet;
std::shared_ptr<ov::runtime::Core> ie = PluginCache::get().core();
std::shared_ptr<ngraph::Function> function;
std::string targetDevice;
std::map<std::string, std::string> configuration;
ov::element::Type elementType;
};
using BehaviorParamsSingleOption = std::tuple<ov::element::Type, // element type
std::string, // device
std::string>; // key
class BehaviorTestsSingleOption : public testing::WithParamInterface<BehaviorParamsSingleOption>,
public CommonTestUtils::TestsCommon {
public:
void SetUp() override {
std::tie(elementType, targetDevice, key) = this->GetParam();
function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType);
}
void TearDown() override {
function.reset();
}
std::shared_ptr<ov::runtime::Core> ie = PluginCache::get().core();
std::shared_ptr<ngraph::Function> function;
std::string targetDevice;
std::string key;
ov::element::Type elementType;
};
using BehaviorParamsSingleOptionDefault =
std::tuple<ov::element::Type, // element type
std::string, // Device name
std::pair<std::string, InferenceEngine::Parameter> // Configuration key and its default value
>;
class BehaviorTestsSingleOptionDefault : public testing::WithParamInterface<BehaviorParamsSingleOptionDefault>,
public CommonTestUtils::TestsCommon {
public:
void SetUp() override {
std::pair<std::string, InferenceEngine::Parameter> entry;
std::tie(elementType, targetDevice, entry) = this->GetParam();
std::tie(key, value) = entry;
function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType);
}
void TearDown() override {
function.reset();
}
std::shared_ptr<ov::runtime::Core> ie = PluginCache::get().core();
std::shared_ptr<ngraph::Function> function;
std::string targetDevice;
std::string key;
InferenceEngine::Parameter value;
ov::element::Type elementType;
};
using BehaviorParamsSingleOptionCustom =
std::tuple<ov::element::Type, // element type
std::string, // Device name
std::tuple<std::string, std::string, InferenceEngine::Parameter> // Configuration key, value and
// reference
>;
class BehaviorTestsSingleOptionCustom : public testing::WithParamInterface<BehaviorParamsSingleOptionCustom>,
public CommonTestUtils::TestsCommon {
public:
void SetUp() override {
std::tuple<std::string, std::string, InferenceEngine::Parameter> entry;
std::tie(elementType, targetDevice, entry) = this->GetParam();
std::tie(key, value, reference) = entry;
function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType);
}
void TearDown() override {
function.reset();
}
std::shared_ptr<ov::runtime::Core> ie = PluginCache::get().core();
std::shared_ptr<ngraph::Function> function;
std::string targetDevice;
std::string key;
std::string value;
ov::runtime::Parameter reference;
ov::element::Type elementType;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,71 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <chrono>
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include "base/ov_behavior_test_utils.hpp"
#include <transformations/serialize.hpp>
#include "common_test_utils/test_constants.hpp"
#include "openvino/runtime/runtime.hpp"
namespace ov {
namespace test {
using OVExecNetwork = ov::test::BehaviorTestsBasic;
// Load correct network to Plugin to get executable network
TEST_P(OVExecNetwork, precisionsAsInOriginalFunction) {
// Skip test according to plugin specific disabledTestPatterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED()
ov::runtime::ExecutableNetwork execNet;
ASSERT_NO_THROW(execNet = ie->compile_model(function, targetDevice, configuration));
EXPECT_EQ(function->get_parameters().size(), execNet.get_parameters().size());
auto ref_parameter = function->get_parameters().back();
auto actual_parameter = execNet.get_parameters().back();
EXPECT_EQ(ref_parameter->get_element_type(), actual_parameter->get_element_type());
EXPECT_EQ(ref_parameter->get_shape(), actual_parameter->get_shape());
EXPECT_EQ(ref_parameter->get_friendly_name(), actual_parameter->get_friendly_name());
EXPECT_EQ(function->get_results().size(), execNet.get_results().size());
auto ref_result = function->get_results().back();
auto actual_result = execNet.get_results().back();
EXPECT_EQ(ref_result->get_element_type(), actual_result->get_element_type());
EXPECT_EQ(ref_result->get_shape(), actual_result->get_shape());
EXPECT_EQ(ref_result->get_friendly_name(), actual_result->get_friendly_name());
}
// Load correct network to Plugin to get executable network
TEST_P(OVExecNetwork, precisionsAsInOriginalIR) {
// Skip test according to plugin specific disabledTestPatterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED()
const std::string m_out_xml_path_1 = "precisionsAsInOriginalIR.xml";
const std::string m_out_bin_path_1 = "precisionsAsInOriginalIR.bin";
ngraph::pass::Serialize(m_out_xml_path_1, m_out_bin_path_1).run_on_function(function);
ov::runtime::ExecutableNetwork execNet;
ASSERT_NO_THROW(execNet = ie->compile_model(m_out_xml_path_1, targetDevice, configuration));
EXPECT_EQ(function->get_parameters().size(), execNet.get_parameters().size());
auto ref_parameter = function->get_parameters().back();
auto actual_parameter = execNet.get_parameters().back();
EXPECT_EQ(elementType, ref_parameter->get_element_type());
EXPECT_EQ(ref_parameter->get_element_type(), actual_parameter->get_element_type());
EXPECT_EQ(ref_parameter->get_shape(), actual_parameter->get_shape());
EXPECT_EQ(ref_parameter->get_friendly_name(), actual_parameter->get_friendly_name());
EXPECT_EQ(function->get_results().size(), execNet.get_results().size());
auto ref_result = function->get_results().back();
auto actual_result = execNet.get_results().back();
EXPECT_EQ(ref_result->get_element_type(), actual_result->get_element_type());
EXPECT_EQ(ref_result->get_shape(), actual_result->get_shape());
EXPECT_EQ(ref_result->get_friendly_name(), actual_result->get_friendly_name());
}
} // namespace test
} // namespace ov