Extended test infrastructure to call per plugin configure function before running a test. The function allows to pass plugin specific configuration (#2731)
This commit is contained in:
parent
50645befb7
commit
9b4f499930
8
docs/template_plugin/tests/functional/plugin_config.cpp
Normal file
8
docs/template_plugin/tests/functional/plugin_config.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// Copyright (C) 2020 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "functional_test_utils/plugin_config.hpp"
|
||||||
|
|
||||||
|
void PreparePluginConfiguration(LayerTestsUtils::LayerTestsCommon* test) {
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
// Copyright (C) 2020 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "functional_test_utils/plugin_config.hpp"
|
||||||
|
|
||||||
|
void PreparePluginConfiguration(LayerTestsUtils::LayerTestsCommon* test) {
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
// Copyright (C) 2020 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "functional_test_utils/plugin_config.hpp"
|
||||||
|
#include "functional_test_utils/blob_utils.hpp"
|
||||||
|
#include "legacy/ie_ngraph_utils.hpp"
|
||||||
|
|
||||||
|
void PreparePluginConfiguration(LayerTestsUtils::LayerTestsCommon* test) {
|
||||||
|
const float MAX_VAL_2B_FEAT = 16384.0f;
|
||||||
|
auto inputParameters = test->GetFunction()->get_parameters();
|
||||||
|
auto& configuration = test->GetConfiguration();
|
||||||
|
for (size_t i = 0; i < inputParameters.size(); ++i) {
|
||||||
|
std::string scaleFactorConfigKey = "GNA_SCALE_FACTOR" + std::string("_") + std::to_string(i);
|
||||||
|
if (configuration.find(scaleFactorConfigKey) != configuration.end()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto elementType = inputParameters[i]->get_element_type();
|
||||||
|
auto shape = inputParameters[i]->get_shape();
|
||||||
|
auto precision = InferenceEngine::details::convertPrecision(elementType);
|
||||||
|
precision = (precision.getPrecVal() == InferenceEngine::Precision::FP16) ?
|
||||||
|
InferenceEngine::Precision(InferenceEngine::Precision::FP32) : precision;
|
||||||
|
|
||||||
|
InferenceEngine::SizeVector size(shape);
|
||||||
|
InferenceEngine::TensorDesc tensor(precision, size, InferenceEngine::Layout::ANY);
|
||||||
|
InferenceEngine::DataPtr dataPtr = std::make_shared<InferenceEngine::Data>("tmp", tensor);
|
||||||
|
|
||||||
|
InferenceEngine::InputInfo info;
|
||||||
|
info.setInputData(dataPtr);
|
||||||
|
info.setPrecision(precision);
|
||||||
|
|
||||||
|
auto blob = test->GenerateInput(info);
|
||||||
|
float floatScaleFactor = 1.0f;
|
||||||
|
|
||||||
|
auto memory = InferenceEngine::as<InferenceEngine::MemoryBlob>(blob);
|
||||||
|
IE_ASSERT(memory);
|
||||||
|
|
||||||
|
const auto lockedMemory = memory->wmap();
|
||||||
|
if (precision == InferenceEngine::Precision::FP32) {
|
||||||
|
float* ptrFloatFeat = lockedMemory.as<float*>();
|
||||||
|
float max = 0.0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < blob->size(); i++) {
|
||||||
|
if (fabs(ptrFloatFeat[i]) > max) {
|
||||||
|
max = fabs(ptrFloatFeat[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
floatScaleFactor = (max == 0) ? 1.0f : MAX_VAL_2B_FEAT / max;
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration[scaleFactorConfigKey] = std::to_string(floatScaleFactor);
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,6 @@ std::vector<InferenceEngine::Precision> netPrecisions = {
|
|||||||
|
|
||||||
std::map<std::string, std::string> additional_config = {
|
std::map<std::string, std::string> additional_config = {
|
||||||
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"},
|
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"},
|
||||||
{"GNA_SCALE_FACTOR_0", "1234"}
|
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
// Copyright (C) 2020 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "functional_test_utils/plugin_config.hpp"
|
||||||
|
|
||||||
|
void PreparePluginConfiguration(LayerTestsUtils::LayerTestsCommon* test) {
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
// Copyright (C) 2020 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "functional_test_utils/plugin_config.hpp"
|
||||||
|
|
||||||
|
void PreparePluginConfiguration(LayerTestsUtils::LayerTestsCommon* test) {
|
||||||
|
}
|
@ -6,6 +6,7 @@
|
|||||||
#include <transformations/op_conversions/convert_space_to_batch.hpp>
|
#include <transformations/op_conversions/convert_space_to_batch.hpp>
|
||||||
|
|
||||||
#include "layer_test_utils.hpp"
|
#include "layer_test_utils.hpp"
|
||||||
|
#include "plugin_config.hpp"
|
||||||
|
|
||||||
namespace LayerTestsUtils {
|
namespace LayerTestsUtils {
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ void LayerTestsCommon::ConfigureNetwork() const {
|
|||||||
|
|
||||||
void LayerTestsCommon::LoadNetwork() {
|
void LayerTestsCommon::LoadNetwork() {
|
||||||
cnnNetwork = InferenceEngine::CNNNetwork{function};
|
cnnNetwork = InferenceEngine::CNNNetwork{function};
|
||||||
|
PreparePluginConfiguration(this);
|
||||||
ConfigureNetwork();
|
ConfigureNetwork();
|
||||||
executableNetwork = core->LoadNetwork(cnnNetwork, targetDevice, configuration);
|
executableNetwork = core->LoadNetwork(cnnNetwork, targetDevice, configuration);
|
||||||
}
|
}
|
||||||
@ -212,4 +214,12 @@ void LayerTestsCommon::Validate() {
|
|||||||
void LayerTestsCommon::SetRefMode(RefMode mode) {
|
void LayerTestsCommon::SetRefMode(RefMode mode) {
|
||||||
refMode = mode;
|
refMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<ngraph::Function> LayerTestsCommon::GetFunction() {
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::string>& LayerTestsCommon::GetConfiguration() {
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
} // namespace LayerTestsUtils
|
} // namespace LayerTestsUtils
|
||||||
|
@ -60,6 +60,10 @@ public:
|
|||||||
|
|
||||||
virtual void SetRefMode(RefMode mode);
|
virtual void SetRefMode(RefMode mode);
|
||||||
|
|
||||||
|
std::shared_ptr<ngraph::Function> GetFunction();
|
||||||
|
|
||||||
|
std::map<std::string, std::string>& GetConfiguration();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LayerTestsCommon();
|
LayerTestsCommon();
|
||||||
|
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
// Copyright (C) 2020 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "functional_test_utils/layer_test_utils.hpp"
|
||||||
|
|
||||||
|
void PreparePluginConfiguration(LayerTestsUtils::LayerTestsCommon* test);
|
Loading…
Reference in New Issue
Block a user