From b60526c67e65be74902b8a6a51a3d252b7d9ec2f Mon Sep 17 00:00:00 2001 From: Vitaliy Urusovskij Date: Sat, 3 Feb 2024 10:00:55 -0800 Subject: [PATCH] Aggressive clean of `LayerTestsUtils::LayerTestsCommon` (#22311) --- .../classes/convolution.hpp | 2 +- .../embedding_bag_offsets_sum.cpp | 2 +- .../embedding_bag_packed_sum.cpp | 2 +- .../embedding_segments_sum.cpp | 2 +- .../custom/single_layer_tests/range.cpp | 2 +- .../custom/single_layer_tests/roi_pooling.cpp | 2 +- .../custom/single_layer_tests/roialign.cpp | 2 +- .../src/concat_const_inplace.cpp | 4 +- .../base_reference_cnn_test.cpp | 117 ----- .../base_reference_cnn_test.hpp | 53 --- .../shared_test_classes/base/benchmark.hpp | 133 ------ .../base/layer_test_utils.hpp | 125 +---- .../subgraph/scaleshift.hpp | 20 - .../subgraph/split_conv_concat.hpp | 13 - .../src/base/layer_test_utils.cpp | 446 ------------------ .../src/base/utils/generate_inputs.cpp | 1 - .../src/subgraph/scale_shift.cpp | 36 -- .../src/subgraph/split_conv_concat.cpp | 29 -- .../functional_test_utils/precision_utils.hpp | 2 +- 19 files changed, 14 insertions(+), 979 deletions(-) delete mode 100644 src/plugins/template/tests/functional/subgraph_reference/base_reference_cnn_test.cpp delete mode 100644 src/plugins/template/tests/functional/subgraph_reference/base_reference_cnn_test.hpp delete mode 100644 src/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/convolution.hpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/convolution.hpp index 263d3b4914d0b5..7b8e4ba3385233 100644 --- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/convolution.hpp +++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/convolution.hpp @@ -25,7 +25,7 @@ typedef std::tuple< ElementType, // Input precision ElementType, // Output precision InputShape, // Input shape - LayerTestsUtils::TargetDevice // Device name + ov::test::TargetDevice // Device name > convLayerTestParamsSet; typedef std::tuple< diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_bag_offsets_sum.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_bag_offsets_sum.cpp index 7248e95d5a8225..2b3dc2dd3398b3 100644 --- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_bag_offsets_sum.cpp +++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_bag_offsets_sum.cpp @@ -23,7 +23,7 @@ typedef std::tuple + ov::test::TargetDevice> embeddingBagOffsetsSumLayerTestParamsSet; class EmbeddingBagOffsetsSumLayerCPUTest : public testing::WithParamInterface, diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_bag_packed_sum.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_bag_packed_sum.cpp index d93dcf877054b8..f976441d6351b3 100644 --- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_bag_packed_sum.cpp +++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_bag_packed_sum.cpp @@ -20,7 +20,7 @@ typedef std::tuple + ov::test::TargetDevice> embeddingBagPackedSumLayerTestParamsSet; class EmbeddingBagPackedSumLayerCPUTest : public testing::WithParamInterface, diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_segments_sum.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_segments_sum.cpp index ada1ffe8a9ca95..50b57b7a6dd822 100644 --- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_segments_sum.cpp +++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/embedding_segments_sum.cpp @@ -24,7 +24,7 @@ typedef std::tuple + ov::test::TargetDevice> embeddingSegmentsSumLayerTestParamsSet; class EmbeddingSegmentsSumLayerCPUTest : public testing::WithParamInterface, diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/range.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/range.cpp index 4bcd8f55c35b5b..985456e52fdaeb 100644 --- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/range.cpp +++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/range.cpp @@ -19,7 +19,7 @@ // typedef std::tuple< // RangeSpecificParams, // InferenceEngine::Precision, // Net precision -// LayerTestsUtils::TargetDevice // Device name +// ov::test::TargetDevice // Device name //> RangeLayerTestParams; // // typedef std::tuple< diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/roi_pooling.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/roi_pooling.cpp index 8f2bcb583782e7..8d67ee0724ceb2 100644 --- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/roi_pooling.cpp +++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/roi_pooling.cpp @@ -23,7 +23,7 @@ using roiPoolingParams = std::tuple; // Device name + ov::test::TargetDevice>; // Device name using ROIPoolingCPUTestParamsSet = std::tuple; using ROIAlignLayerCPUTestParamsSet = std::tuple< diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/concat_const_inplace.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/concat_const_inplace.cpp index f070cbca71604d..bb12b5de29b23d 100644 --- a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/concat_const_inplace.cpp +++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/concat_const_inplace.cpp @@ -52,7 +52,9 @@ class ConcatConstantInPlaceTest : public testing::WithParamInterface weightValuesFP32(12); ov::Shape convFilterShape = {1, 12, 1, 1}; - FuncTestUtils::fillInputsBySinValues(weightValuesFP32.data(), weightValuesFP32.size()); + for (size_t i = 0; i < weightValuesFP32.size(); i++) { + weightValuesFP32.data()[i] = sin(static_cast(i)); + } auto weightsNode = std::make_shared(ov::element::f32, convFilterShape, weightValuesFP32); std::shared_ptr conv = std::make_shared(concat, weightsNode, diff --git a/src/plugins/template/tests/functional/subgraph_reference/base_reference_cnn_test.cpp b/src/plugins/template/tests/functional/subgraph_reference/base_reference_cnn_test.cpp deleted file mode 100644 index abdf47a4b8c3b0..00000000000000 --- a/src/plugins/template/tests/functional/subgraph_reference/base_reference_cnn_test.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "base_reference_cnn_test.hpp" - -#include - -#include "functional_test_utils/ov_plugin_cache.hpp" -#include "openvino/core/type/element_type.hpp" -#include "openvino/runtime/allocator.hpp" -#include "openvino/runtime/tensor.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "transformations/utils/utils.hpp" - -using namespace ov; - -namespace reference_tests { - -ReferenceCNNTest::ReferenceCNNTest() : targetDevice("TEMPLATE") { - core = test::utils::PluginCache::get().core(targetDevice); - legacy_core = PluginCache::get().ie(targetDevice); -} - -void ReferenceCNNTest::Exec() { - LoadNetwork(); - LoadNetworkLegacy(); - - if (legacy_input_blobs.empty() && inputData.empty()) { - FillInputs(); - } - Infer(); - InferLegacy(); - - Validate(); -} - -void ReferenceCNNTest::LoadNetwork() { - executableNetwork = core->compile_model(function, targetDevice); -} - -void ReferenceCNNTest::LoadNetworkLegacy() { - auto inputInfo = legacy_network.getInputsInfo(); - auto outputInfo = legacy_network.getOutputsInfo(); - for (const auto& param : function->get_parameters()) { - inputInfo[param->get_friendly_name()]->setPrecision( - InferenceEngine::details::convertPrecision(param->get_element_type())); - } - for (const auto& result : function->get_results()) { - outputInfo[ov::op::util::create_ie_output_name(result->input_value(0))]->setPrecision( - InferenceEngine::details::convertPrecision(result->get_element_type())); - } - legacy_exec_network = legacy_core->LoadNetwork(legacy_network, targetDevice); -} - -void ReferenceCNNTest::FillInputs() { - const auto& params = function->get_parameters(); - std::default_random_engine random(0); // hard-coded seed to make test results predictable - std::uniform_int_distribution distrib(0, 255); - for (const auto& param : params) { - auto elem_count = shape_size(param->get_output_tensor(0).get_shape()); - InferenceEngine::TensorDesc d(InferenceEngine::Precision::FP32, - param->get_output_tensor(0).get_shape(), - InferenceEngine::Layout::NCHW); - auto blob = make_blob_with_precision(d); - blob->allocate(); - - auto mBlob = InferenceEngine::as(blob); - auto mBlobHolder = mBlob->wmap(); - auto buf = mBlobHolder.as(); - ASSERT_EQ(mBlob->size(), elem_count); - - ov::Tensor ov_blob; - ov_blob = ov::Tensor(param->get_element_type(), param->get_shape()); - auto ov_buf = static_cast(ov_blob.data()); - - for (size_t j = 0; j < elem_count; j++) { - auto v = distrib(random); - buf[j] = static_cast(v); - ov_buf[j] = static_cast(v); - } - legacy_input_blobs[param->get_friendly_name()] = blob; - inputData.push_back(ov_blob); - } -} - -void ReferenceCNNTest::Infer() { - inferRequest = executableNetwork.create_infer_request(); - const auto& functionParams = function->get_parameters(); - - for (size_t i = 0; i < functionParams.size(); ++i) { - const auto& param = functionParams[i]; - inferRequest.set_tensor(param->get_friendly_name(), inputData[i]); - } - inferRequest.infer(); -} - -void ReferenceCNNTest::InferLegacy() { - legacy_infer_request = legacy_exec_network.CreateInferRequest(); - legacy_infer_request.SetInput(legacy_input_blobs); - legacy_infer_request.Infer(); -} - -void ReferenceCNNTest::Validate() { - for (const auto& result : function->get_results()) { - auto name = ov::op::util::create_ie_output_name(result->input_value(0)); - outputs_ov20.emplace_back(inferRequest.get_tensor(name)); - auto outBlob = legacy_infer_request.GetBlob(name); - auto outMem = outBlob->buffer(); - void* outData = outMem.as(); - outputs_legacy.emplace_back(element::f32, result->get_shape(), outData); - } - for (size_t i = 0; i < outputs_legacy.size(); i++) { - CommonReferenceTest::ValidateBlobs(outputs_legacy[i], outputs_ov20[i], i, threshold, abs_threshold); - } -} - -} // namespace reference_tests diff --git a/src/plugins/template/tests/functional/subgraph_reference/base_reference_cnn_test.hpp b/src/plugins/template/tests/functional/subgraph_reference/base_reference_cnn_test.hpp deleted file mode 100644 index 4dcb27ee2c2dc4..00000000000000 --- a/src/plugins/template/tests/functional/subgraph_reference/base_reference_cnn_test.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "base_reference_test.hpp" -#include "inference_engine.hpp" - -namespace reference_tests { - -class ReferenceCNNTest { -public: - ReferenceCNNTest(); - - void Exec(); - - void LoadNetwork(); - void FillInputs(); // Both for legacy and for OV2.0 API - void Infer(); - - void LoadNetworkLegacy(); - void InferLegacy(); - - virtual void Validate(); - -protected: - const std::string targetDevice; - std::shared_ptr function; - InferenceEngine::CNNNetwork legacy_network; - - float threshold = 1e-5f; // Relative diff - float abs_threshold = -1.f; // Absolute diff (not used when negative) - - std::vector outputs_ov20; - std::vector outputs_legacy; - -protected: - // These will be generated by default, if user has not specified inputs manually - std::vector inputData; - InferenceEngine::BlobMap legacy_input_blobs; - -private: - std::shared_ptr core; - ov::CompiledModel executableNetwork; - ov::InferRequest inferRequest; - - std::shared_ptr legacy_core; - InferenceEngine::ExecutableNetwork legacy_exec_network; - InferenceEngine::InferRequest legacy_infer_request; -}; - -} // namespace reference_tests diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/benchmark.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/benchmark.hpp index cd0e1375eda074..15d89175ea5382 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/benchmark.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/benchmark.hpp @@ -63,139 +63,6 @@ class BenchmarkLayerTestReporter { pugi::xml_document report_xml_{}; }; -} // namespace test -} // namespace ov - -namespace LayerTestsDefinitions { - -template -class BenchmarkLayerTest : public BaseLayerTest { - static_assert(std::is_base_of::value, - "BaseLayerTest should inherit from LayerTestsUtils::LayerTestsCommon"); - -public: - static constexpr int kDefaultNumberOfAttempts = 100; - static constexpr double kMaxAllowedBenchmarkDifference = 0.05; - - void RunBenchmark(const std::initializer_list& nodeTypeNames, - const std::chrono::milliseconds warmupTime = std::chrono::milliseconds(2000), - const int numAttempts = kDefaultNumberOfAttempts) { - bench_node_type_names_ = nodeTypeNames; - warmup_time_ = warmupTime; - num_attempts_ = numAttempts; - this->configuration.insert({"PERF_COUNT", "YES"}); - this->Run(); - } - - void RunBenchmark(const std::string& nodeTypeName, - const std::chrono::milliseconds warmupTime = std::chrono::milliseconds(2000), - const int numAttempts = kDefaultNumberOfAttempts) { - if (!nodeTypeName.empty()) { - RunBenchmark({nodeTypeName}, warmupTime, numAttempts); - } else { - RunBenchmark({}, warmupTime, numAttempts); - } - } - - void Validate() override { - for (const auto& res : curr_bench_results_) { - const auto& node_type_name = res.first; - const auto curr_time = static_cast(res.second); - if (prev_bench_results_.count(node_type_name) > 0) { - const auto prev_time = static_cast(prev_bench_results_[node_type_name]); - const auto delta_time = static_cast(curr_time - prev_time); - if (delta_time/prev_time > kMaxAllowedBenchmarkDifference) { - std::cerr << "node_type_name: " << node_type_name << - ", for test case: " << BaseLayerTest::GetTestName() << - ", has exceeded the benchmark threshold: " << kMaxAllowedBenchmarkDifference << - ". Current: " << curr_time << " us, previous: " << prev_time << " us" << std::endl; - } - } - } - } - -protected: - void Infer() override { - this->inferRequest = this->executableNetwork.CreateInferRequest(); - this->ConfigureInferRequest(); - -#ifdef ENABLE_BENCHMARK_FILE_REPORT - reporter_ = std::unique_ptr( - new ::ov::test::BenchmarkLayerTestReporter{false}); -#else - reporter_ = std::unique_ptr( - new ::ov::test::BenchmarkLayerTestReporter{true}); -#endif - for (const auto& node_type_name : bench_node_type_names_) { - try { - const auto time = reporter_->get_time(node_type_name, BaseLayerTest::GetTestName()); - prev_bench_results_[node_type_name] = time; - } catch (...) { - } - } - - std::map results_us{}; - for (const auto& node_type_name : bench_node_type_names_) { - results_us[node_type_name] = {}; - } - - // Warmup - auto warm_current = std::chrono::steady_clock::now(); - const auto warm_end = warm_current + warmup_time_; - while (warm_current < warm_end) { - this->inferRequest.Infer(); - warm_current = std::chrono::steady_clock::now(); - } - - // Benchmark - for (size_t i = 0; i < num_attempts_; ++i) { - this->inferRequest.Infer(); - const auto& perf_results = this->inferRequest.GetPerformanceCounts(); - for (auto& res : results_us) { - const std::string node_type_name = res.first; - uint64_t& time = res.second; - auto found_profile = std::find_if(perf_results.begin(), perf_results.end(), - [&node_type_name](const InferenceEngine::InferenceEngineProfileInfo& profile) { - return profile.layer_type == node_type_name; - }); - if (found_profile == perf_results.end()) { - IE_THROW() << "Cannot find operator by node type: " << node_type_name; - } - time += found_profile->second.realTime_uSec; - } - } - - std::stringstream report{}; - uint64_t total_us = 0; - for (const auto& res : results_us) { - const std::string node_type_name = res.first; - uint64_t time = res.second; - time /= num_attempts_; - total_us += time; - report << std::fixed << std::setfill('0') << node_type_name << ": " << time << " us\n"; -#ifdef ENABLE_BENCHMARK_FILE_REPORT - curr_bench_results_[node_type_name] = time; - reporter_->report(node_type_name, BaseLayerTest::GetTestName(), time); -#endif - } - report << std::fixed << std::setfill('0') << "Total time: " << total_us << " us\n"; - std::cout << report.str(); - } - -private: - std::unique_ptr reporter_; - std::unordered_map prev_bench_results_; - std::unordered_map curr_bench_results_; - std::vector bench_node_type_names_; - std::chrono::milliseconds warmup_time_; - int num_attempts_; -}; - -} // namespace LayerTestsDefinitions - -namespace ov { -namespace test { - template class BenchmarkLayerTest : public BaseLayerTest { static_assert(std::is_base_of::value, diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/layer_test_utils.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/layer_test_utils.hpp index b2a605d89716e8..cb14a2f97467ab 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/layer_test_utils.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/layer_test_utils.hpp @@ -5,15 +5,13 @@ #pragma once #include -#include #include "common_test_utils/common_utils.hpp" #include "common_test_utils/ov_test_utils.hpp" #include "common_test_utils/test_common.hpp" -#include "functional_test_utils/blob_utils.hpp" +#include "common_test_utils/data_utils.hpp" #include "functional_test_utils/crash_handler.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "functional_test_utils/precision_utils.hpp" +// #include "functional_test_utils/plugin_cache.hpp" #include "functional_test_utils/skip_tests_config.hpp" #include "functional_test_utils/summary/environment.hpp" #include "functional_test_utils/summary/op_summary.hpp" @@ -25,126 +23,9 @@ namespace LayerTestsUtils { using TargetDevice = std::string; -typedef std::tuple< - InferenceEngine::Precision, // Network Precision - InferenceEngine::SizeVector, // Input Shape - TargetDevice // Target Device -> basicParams; - -enum RefMode { - INTERPRETER, - CONSTANT_FOLDING, - IE -}; - -class LayerTestsCommon : public ov::test::TestsCommon { -public: - virtual InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &inputInfo) const; - - virtual void Run(); - - static void Compare(const std::vector>> &expected, - const std::vector &actual, - float threshold, - float abs_threshold = -1.f); - - static void Compare(const std::pair> &expected, - const InferenceEngine::Blob::Ptr &actual, - float threshold, - float abs_threshold = -1.f); - - virtual void Compare(const std::vector>> &expectedOutputs, - const std::vector &actualOutputs); - - virtual void Compare(const std::pair> &expected, const InferenceEngine::Blob::Ptr &actual); - - virtual void Compare(const InferenceEngine::Blob::Ptr &expected, const InferenceEngine::Blob::Ptr &actual); - - virtual void Compare(const InferenceEngine::TensorDesc &actualDesc, const InferenceEngine::TensorDesc &expectedDesc); - - std::shared_ptr GetFunction(); - - std::map& GetConfiguration(); - - template - static void Compare(const T_NGRAPH *expected, const T_IE *actual, std::size_t size, float threshold, float abs_threshold = -1.f) { - for (std::size_t i = 0; i < size; ++i) { - const T_NGRAPH &ref = expected[i]; - const auto &res = actual[i]; - const auto absoluteDifference = ov::test::utils::ie_abs(res - ref); - if (abs_threshold > 0.f && absoluteDifference > abs_threshold) { - IE_THROW() << "Absolute comparison of values expected: " << std::to_string(ref) << " and actual: " << std::to_string(res) - << " at index " << i << " with absolute threshold " << abs_threshold - << " failed"; - } - if (absoluteDifference <= threshold) { - continue; - } - double max; - if (sizeof(T_IE) < sizeof(T_NGRAPH)) { - max = static_cast(std::max(ov::test::utils::ie_abs(T_NGRAPH(res)), ov::test::utils::ie_abs(ref))); - } else { - max = static_cast(std::max(ov::test::utils::ie_abs(res), ov::test::utils::ie_abs(T_IE(ref)))); - } - double diff = static_cast(absoluteDifference) / max; - if (max == 0 || (diff > static_cast(threshold)) || - (std::isnan(static_cast(res)) ^ std::isnan(static_cast(ref)))) { - IE_THROW() << "Relative comparison of values expected: " << std::to_string(ref) << " and actual: " << std::to_string(res) - << " at index " << i << " with threshold " << threshold - << " failed"; - } - } - } - +class LayerTestsCommon { protected: LayerTestsCommon(); - - RefMode GetRefMode() { - return refMode; - } - - std::shared_ptr getCore() { - return core; - } - - virtual void ConfigureNetwork(); - - virtual void LoadNetwork(); - - virtual void ExpectLoadNetworkToThrow(const std::string& msg); - - virtual void GenerateInputs(); - - virtual void ConfigureInferRequest(); - - virtual void Infer(); - - TargetDevice targetDevice; - std::shared_ptr function; - std::shared_ptr functionRefs; - std::map configuration; - // Non default values of layouts/precisions will be set to CNNNetwork - InferenceEngine::Layout inLayout = InferenceEngine::Layout::ANY; - InferenceEngine::Layout outLayout = InferenceEngine::Layout::ANY; - InferenceEngine::Precision inPrc = InferenceEngine::Precision::UNSPECIFIED; - InferenceEngine::Precision outPrc = InferenceEngine::Precision::UNSPECIFIED; - InferenceEngine::ExecutableNetwork executableNetwork; - std::vector inputs; - float threshold; - float abs_threshold; - InferenceEngine::CNNNetwork cnnNetwork; - std::shared_ptr core; - - virtual void Validate(); - - virtual std::vector>> CalculateRefs(); - - virtual std::vector GetOutputs(); - - InferenceEngine::InferRequest inferRequest; - -private: - RefMode refMode = RefMode::INTERPRETER; }; } // namespace LayerTestsUtils diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/scaleshift.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/scaleshift.hpp index ac72c943319c2a..3c0a23c74d2bde 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/scaleshift.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/scaleshift.hpp @@ -32,23 +32,3 @@ class ScaleShiftLayerTest: }; } // namespace test } // namespace ov - -// legacy impl for npu repo -namespace SubgraphTestsDefinitions { - -using ScaleShiftParamsTuple = typename std::tuple< - std::vector>, //input shapes - InferenceEngine::Precision, //Network precision - std::string, //Device name - std::vector, //scale - std::vector>; //shift - -class ScaleShiftLayerTest: - public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon{ -public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); -protected: - void SetUp() override; -}; -} // namespace SubgraphTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/split_conv_concat.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/split_conv_concat.hpp index d74865a6bb0c6b..a08870dfb68006 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/split_conv_concat.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/split_conv_concat.hpp @@ -30,16 +30,3 @@ class SplitConvConcat : public testing::WithParamInterface, - virtual public ov::test::SplitConvConcatBase { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj); - -protected: - void SetUp() override; -}; - -} // namespace SubgraphTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp b/src/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp deleted file mode 100644 index b5e9395d1c5619..00000000000000 --- a/src/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp +++ /dev/null @@ -1,446 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#ifdef _WIN32 -#include -#endif - -#include - -#include "common_test_utils/file_utils.hpp" -#include "ie_icore.hpp" -#include "openvino/opsets/opset.hpp" -#include "openvino/pass/serialize.hpp" -#include "openvino/runtime/device_id_parser.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -namespace LayerTestsUtils { - -LayerTestsCommon::LayerTestsCommon() : threshold(1e-2f), abs_threshold(-1.f) { - core = PluginCache::get().ie(targetDevice); -} - -void LayerTestsCommon::Run() { - bool isCurrentTestDisabled = ov::test::utils::current_test_is_disabled(); - - ov::test::utils::PassRate::Statuses status = isCurrentTestDisabled ? - ov::test::utils::PassRate::Statuses::SKIPPED : - ov::test::utils::PassRate::Statuses::CRASHED; - - auto &s = ov::test::utils::OpSummary::getInstance(); - s.setDeviceName(targetDevice); - s.updateOPsStats(function, status); - - if (isCurrentTestDisabled) - GTEST_SKIP() << "Disabled test due to configuration" << std::endl; - - if (functionRefs == nullptr) { - functionRefs = function->clone(); - functionRefs->set_friendly_name("refFunction"); - } - - // in case of crash jump will be made and work will be continued - auto crashHandler = std::unique_ptr(new ov::test::utils::CrashHandler()); - - // place to jump in case of a crash - int jmpRes = 0; -#ifdef _WIN32 - jmpRes = setjmp(ov::test::utils::env); -#else - jmpRes = sigsetjmp(ov::test::utils::env, 1); -#endif - if (jmpRes == ov::test::utils::JMP_STATUS::ok) { - crashHandler->StartTimer(); - try { - LoadNetwork(); - GenerateInputs(); - Infer(); - Validate(); - s.updateOPsStats(functionRefs, ov::test::utils::PassRate::Statuses::PASSED); - } - catch (const std::runtime_error &re) { - s.updateOPsStats(functionRefs, ov::test::utils::PassRate::Statuses::FAILED); - GTEST_FATAL_FAILURE_(re.what()); - } catch (const std::exception &ex) { - s.updateOPsStats(functionRefs, ov::test::utils::PassRate::Statuses::FAILED); - GTEST_FATAL_FAILURE_(ex.what()); - } catch (...) { - s.updateOPsStats(functionRefs, ov::test::utils::PassRate::Statuses::FAILED); - GTEST_FATAL_FAILURE_("Unknown failure occurred."); - } - } else if (jmpRes == ov::test::utils::JMP_STATUS::anyError) { - IE_THROW() << "Crash happens"; - } else if (jmpRes == ov::test::utils::JMP_STATUS::alarmErr) { - s.updateOPsStats(functionRefs, ov::test::utils::PassRate::Statuses::HANGED); - IE_THROW() << "Crash happens"; - } -} - -InferenceEngine::Blob::Ptr LayerTestsCommon::GenerateInput(const InferenceEngine::InputInfo& info) const { - return FuncTestUtils::createAndFillBlob(info.getTensorDesc()); -} - -void LayerTestsCommon::Compare( - const std::vector>>& expectedOutputs, - const std::vector& actualOutputs, - float threshold, - float abs_threshold) { - for (std::size_t outputIndex = 0; outputIndex < expectedOutputs.size(); ++outputIndex) { - const auto &expected = expectedOutputs[outputIndex]; - const auto &actual = actualOutputs[outputIndex]; - Compare(expected, actual, threshold, abs_threshold); - } -} - -template -inline void callCompare(const std::pair>& expected, - const T_IE* actualBuffer, - size_t size, - float threshold, - float abs_threshold) { - auto expectedBuffer = expected.second.data(); - switch (expected.first) { - case ov::element::Type_t::boolean: - case ov::element::Type_t::u8: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::i8: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::u16: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::i16: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::u32: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::i32: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::u64: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::i64: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::bf16: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::f16: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::f32: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::f64: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - case ov::element::Type_t::i4: { - auto expectedOut = - ngraph::helpers::convertOutputPrecision(expected.second, expected.first, ov::element::Type_t::i8, size); - LayerTestsCommon::Compare(reinterpret_cast(expectedOut.data()), - actualBuffer, - size, - threshold, - abs_threshold); - break; - } - case ov::element::Type_t::u4: { - auto expectedOut = - ngraph::helpers::convertOutputPrecision(expected.second, expected.first, ov::element::Type_t::u8, size); - LayerTestsCommon::Compare(reinterpret_cast(expectedOut.data()), - actualBuffer, - size, - threshold, - abs_threshold); - break; - } - case ov::element::Type_t::dynamic: - case ov::element::Type_t::undefined: - LayerTestsCommon::Compare(reinterpret_cast(expectedBuffer), - actualBuffer, - size, - threshold, - abs_threshold); - break; - default: - FAIL() << "Comparator for " << expected.first << " precision isn't supported"; - } - return; -} - -void LayerTestsCommon::Compare(const std::pair>& expected, - const InferenceEngine::Blob::Ptr& actual, - float threshold, - float abs_threshold) { - const auto &precision = actual->getTensorDesc().getPrecision(); - auto k = static_cast(expected.first.size()) / precision.size(); - // W/A for int4, uint4 - if (expected.first == ov::element::Type_t::u4 || expected.first == ov::element::Type_t::i4) { - k /= 2; - } else if (expected.first == ov::element::Type_t::undefined || expected.first == ov::element::Type_t::dynamic) { - k = 1; - } - ASSERT_EQ(expected.second.size(), actual->byteSize() * k); - - auto memory = InferenceEngine::as(actual); - IE_ASSERT(memory); - const auto lockedMemory = memory->wmap(); - const auto actualBuffer = lockedMemory.as(); - - const auto &size = actual->size(); - switch (precision) { - case InferenceEngine::Precision::BOOL: - case InferenceEngine::Precision::U8: - callCompare(expected, reinterpret_cast(actualBuffer), size, threshold, abs_threshold); - break; - case InferenceEngine::Precision::I8: - callCompare(expected, reinterpret_cast(actualBuffer), size, threshold, abs_threshold); - break; - case InferenceEngine::Precision::U16: - callCompare(expected, reinterpret_cast(actualBuffer), size, threshold, abs_threshold); - break; - case InferenceEngine::Precision::I16: - callCompare(expected, reinterpret_cast(actualBuffer), size, threshold, abs_threshold); - break; - case InferenceEngine::Precision::U32: - callCompare(expected, reinterpret_cast(actualBuffer), size, threshold, abs_threshold); - break; - case InferenceEngine::Precision::I32: - callCompare(expected, reinterpret_cast(actualBuffer), size, threshold, abs_threshold); - break; - case InferenceEngine::Precision::U64: - callCompare(expected, reinterpret_cast(actualBuffer), size, threshold, abs_threshold); - break; - case InferenceEngine::Precision::I64: - callCompare(expected, reinterpret_cast(actualBuffer), size, threshold, abs_threshold); - break; - case InferenceEngine::Precision::BF16: - callCompare(expected, - reinterpret_cast(actualBuffer), - size, - threshold, - abs_threshold); - break; - case InferenceEngine::Precision::FP16: - callCompare(expected, - reinterpret_cast(actualBuffer), - size, - threshold, - abs_threshold); - break; - case InferenceEngine::Precision::FP32: - callCompare(expected, reinterpret_cast(actualBuffer), size, threshold, abs_threshold); - break; - case InferenceEngine::Precision::FP64: - callCompare(expected, reinterpret_cast(actualBuffer), size, threshold, abs_threshold); - break; - default: - FAIL() << "Comparator for " << precision << " precision isn't supported"; - } -} - -void LayerTestsCommon::Compare(const std::pair>& expected, - const InferenceEngine::Blob::Ptr& actual) { - Compare(expected, actual, threshold); -} - -void LayerTestsCommon::Compare(const InferenceEngine::Blob::Ptr &expected, const InferenceEngine::Blob::Ptr &actual) { - auto get_raw_buffer = [](const InferenceEngine::Blob::Ptr &blob) { - auto memory = InferenceEngine::as(blob); - IE_ASSERT(memory); - const auto lockedMemory = memory->wmap(); - return lockedMemory.as(); - }; - const auto expectedBuffer = get_raw_buffer(expected); - const auto actualBuffer = get_raw_buffer(actual); - - const auto &precision = actual->getTensorDesc().getPrecision(); - const auto &size = actual->size(); - switch (precision) { - case InferenceEngine::Precision::FP32: - Compare(reinterpret_cast(expectedBuffer), reinterpret_cast(actualBuffer), - size, threshold); - break; - case InferenceEngine::Precision::I32: - Compare(reinterpret_cast(expectedBuffer), - reinterpret_cast(actualBuffer), size, 0); - break; - case InferenceEngine::Precision::I16: - Compare(reinterpret_cast(expectedBuffer), - reinterpret_cast(actualBuffer), size, 0); - break; - case InferenceEngine::Precision::U8: - Compare(reinterpret_cast(expectedBuffer), - reinterpret_cast(actualBuffer), size, 0); - break; - default: - FAIL() << "Comparator for " << precision << " precision isn't supported"; - } -} - -void LayerTestsCommon::Compare(const InferenceEngine::TensorDesc &actualDesc, const InferenceEngine::TensorDesc &expectedDesc) { - auto expectedDims = actualDesc.getDims(); - auto actualDims = expectedDesc.getDims(); - ASSERT_EQ(actualDims.size(), expectedDims.size()); - for (size_t j = 0; j < actualDims.size(); ++j) { - ASSERT_EQ(actualDims.at(j), expectedDims.at(j)); - } - ASSERT_EQ(actualDesc.getLayout(), expectedDesc.getLayout()); - ASSERT_EQ(actualDesc.getPrecision(), expectedDesc.getPrecision()); -} - -void LayerTestsCommon::ConfigureNetwork() { - for (const auto &in : cnnNetwork.getInputsInfo()) { - if (inLayout != InferenceEngine::Layout::ANY) { - in.second->setLayout(inLayout); - } - if (inPrc != InferenceEngine::Precision::UNSPECIFIED) { - in.second->setPrecision(inPrc); - } - } - - for (const auto &out : cnnNetwork.getOutputsInfo()) { - if (outLayout != InferenceEngine::Layout::ANY) { - out.second->setLayout(outLayout); - } - if (outPrc != InferenceEngine::Precision::UNSPECIFIED) { - out.second->setPrecision(outPrc); - } - } -} - -void LayerTestsCommon::LoadNetwork() { - cnnNetwork = InferenceEngine::CNNNetwork{function}; - ConfigureNetwork(); - executableNetwork = core->LoadNetwork(cnnNetwork, targetDevice, configuration); -} - -void LayerTestsCommon::ExpectLoadNetworkToThrow(const std::string& msg) { - std::string what; - try { - LoadNetwork(); - } catch (const std::exception& e) { - what.assign(e.what()); - } - EXPECT_STR_CONTAINS(what.c_str(), msg.c_str()); -} - -void LayerTestsCommon::GenerateInputs() { - inputs.clear(); - const auto& inputsInfo = executableNetwork.GetInputsInfo(); - const auto& functionParams = function->get_parameters(); - for (int i = 0; i < functionParams.size(); ++i) { - const auto& param = functionParams[i]; - const auto infoIt = inputsInfo.find(param->get_friendly_name()); - GTEST_ASSERT_NE(infoIt, inputsInfo.cend()); - InferenceEngine::InputInfo::CPtr info = infoIt->second; - InferenceEngine::Blob::Ptr blob = GenerateInput(*info); - inputs.push_back(blob); - } -} - -void LayerTestsCommon::ConfigureInferRequest() { - const auto& inputsInfo = executableNetwork.GetInputsInfo(); - const auto& functionParams = function->get_parameters(); - for (int i = 0; i < functionParams.size(); ++i) { - const auto& param = functionParams[i]; - const auto infoIt = inputsInfo.find(param->get_friendly_name()); - GTEST_ASSERT_NE(infoIt, inputsInfo.cend()); - - const auto& info = infoIt->second; - auto blob = inputs[i]; - inferRequest.SetBlob(info->name(), blob); - } -} - -void LayerTestsCommon::Infer() { - inferRequest = executableNetwork.CreateInferRequest(); - - ConfigureInferRequest(); - - inferRequest.Infer(); -} - -std::vector>> LayerTestsCommon::CalculateRefs() { - return {}; -} - -std::vector LayerTestsCommon::GetOutputs() { - auto outputs = std::vector{}; - for (const auto &output : executableNetwork.GetOutputsInfo()) { - const auto &name = output.first; - outputs.push_back(inferRequest.GetBlob(name)); - } - return outputs; -} - -void LayerTestsCommon::Compare( - const std::vector>>& expectedOutputs, - const std::vector& actualOutputs) { - Compare(expectedOutputs, actualOutputs, threshold); -} - -void LayerTestsCommon::Validate() {} - -std::shared_ptr LayerTestsCommon::GetFunction() { - return function; -} - -std::map &LayerTestsCommon::GetConfiguration() { - return configuration; -} - -} // namespace LayerTestsUtils diff --git a/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp b/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp index 6a982171cc6bcd..7514ab753ab100 100644 --- a/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp +++ b/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp @@ -491,7 +491,6 @@ ov::Tensor generate(const std::shared_ptr& node, size_t port, const ov::element::Type& elemType, const ov::Shape& targetShape) { - InferenceEngine::Blob::Ptr blobPtr; switch (port) { case 0: { auto data_size = shape_size(targetShape); diff --git a/src/tests/functional/shared_test_classes/src/subgraph/scale_shift.cpp b/src/tests/functional/shared_test_classes/src/subgraph/scale_shift.cpp index 37482b17c5aaea..f90231a4c0bfb7 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/scale_shift.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/scale_shift.cpp @@ -46,39 +46,3 @@ void ScaleShiftLayerTest::SetUp() { } } // namespace test } // namespace ov - -// legacy impl for npu repo -namespace SubgraphTestsDefinitions { - std::string ScaleShiftLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { - std::vector> inputShapes; - InferenceEngine::Precision netPrecision; - std::string targetName; - std::vector scale, shift; - std::tie(inputShapes, netPrecision, targetName, scale, shift) = obj.param; - std::ostringstream results; - - results << "IS=" << ov::test::utils::vec2str(inputShapes) << "_"; - results << "Scale=" << ov::test::utils::vec2str(scale) << "_"; - results << "Shift=" << ov::test::utils::vec2str(shift) << "_"; - results << "netPRC=" << netPrecision.name() << "_"; - results << "targetDevice=" << targetName << "_"; - return results.str(); - } - - void ScaleShiftLayerTest::SetUp() { - std::vector> inputShapes; - InferenceEngine::Precision netPrecision; - std::vector scale, shift; - std::tie(inputShapes, netPrecision, targetDevice, scale, shift) = this->GetParam(); - auto paramsShape = ov::Shape{1}; - if (inputShapes.size() > 1) - paramsShape = ov::Shape(inputShapes[1]); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector paramsIn{std::make_shared(ngPrc, ov::Shape(inputShapes[0]))}; - auto mul_const = std::make_shared(ngPrc, paramsShape, scale); - auto mul = std::make_shared(paramsIn[0], mul_const); - auto add_const = std::make_shared(ngPrc, paramsShape, shift); - auto add = std::make_shared(mul, add_const); - function = std::make_shared(add, paramsIn, "scale_shift"); - } -} // namespace SubgraphTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/src/subgraph/split_conv_concat.cpp b/src/tests/functional/shared_test_classes/src/subgraph/split_conv_concat.cpp index 43c939dbc0e3f0..35c59647712f5e 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/split_conv_concat.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/split_conv_concat.cpp @@ -75,32 +75,3 @@ void SplitConvConcatBase::configure_test(const ov::test::BasicParams& param) { } // namespace test } // namespace ov - -namespace SubgraphTestsDefinitions { - -std::string SplitConvConcat::getTestCaseName(const testing::TestParamInfo& obj) { - InferenceEngine::Precision precision; - InferenceEngine::SizeVector inputShapes; - std::string targetDevice; - std::tie(precision, inputShapes, targetDevice) = obj.param; - auto element_type = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(precision); - - std::ostringstream result; - result << "IS=" << ov::test::utils::vec2str(inputShapes) << "_"; - result << "ET=" << element_type << "_"; - result << "targetDevice=" << targetDevice; - return result.str(); -} - -void SplitConvConcat::SetUp() { - InferenceEngine::Precision precision; - InferenceEngine::SizeVector inputShapes; - std::tie(precision, inputShapes, targetDevice) = this->GetParam(); - auto element_type = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(precision); - ov::Shape shape = inputShapes; - - ov::test::BasicParams param(element_type, shape, targetDevice); - configure_test(param); -} - -} // namespace SubgraphTestsDefinitions diff --git a/src/tests/test_utils/functional_test_utils/include/functional_test_utils/precision_utils.hpp b/src/tests/test_utils/functional_test_utils/include/functional_test_utils/precision_utils.hpp index 1585517b3a7fd4..38ba8b8ea515f3 100644 --- a/src/tests/test_utils/functional_test_utils/include/functional_test_utils/precision_utils.hpp +++ b/src/tests/test_utils/functional_test_utils/include/functional_test_utils/precision_utils.hpp @@ -59,4 +59,4 @@ inline ::ov::element::Type convertIE2nGraphPrc(const InferenceEngine::Precision& } } // namespace PrecisionUtils -} // namespace FuncTestUtils +} // namespace FuncTestUtils \ No newline at end of file