Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor gpu tests #21448

Merged
merged 7 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@

#include "behavior/plugin/hetero_query_network.hpp"

using namespace HeteroTests;

namespace HeteroTests {

TEST_P(HeteroQueryNetworkTest, HeteroSinglePlugin) {
std::string deviceName = GetParam();
RunTest(deviceName);
}

INSTANTIATE_TEST_CASE_P(
HeteroGpu,
HeteroQueryNetworkTest,
::testing::Values(
std::string("HETERO:GPU")));
HeteroGpu,
HeteroQueryNetworkTest,
::testing::Values(
std::string("HETERO:GPU")));

} // namespace HeteroTests
138 changes: 54 additions & 84 deletions src/plugins/intel_gpu/tests/functional/behavior/infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,129 +2,98 @@
// SPDX-License-Identifier: Apache-2.0
//

#include <string>
#include <utility>
#include <vector>
#include <memory>

#include "common_test_utils/test_common.hpp"
#include "common_test_utils/common_utils.hpp"
#include "common_test_utils/node_builders/activation.hpp"
#include "openvino/core/preprocess/pre_post_process.hpp"
#include "openvino/runtime/core.hpp"

#include <common_test_utils/test_common.hpp>
#include "ov_models/subgraph_builders.hpp"
#include "functional_test_utils/blob_utils.hpp"
#include "openvino/core/preprocess/pre_post_process.hpp"
#include "transformations/utils/utils.hpp"
#include "common_test_utils/common_utils.hpp"
#include "shared_test_classes/base/layer_test_utils.hpp"

using namespace ::testing;

const std::vector<InferenceEngine::Precision> inputPrecisions = {
InferenceEngine::Precision::I16,
InferenceEngine::Precision::U16,
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::U8,
InferenceEngine::Precision::I8,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::U32,
InferenceEngine::Precision::U64,
InferenceEngine::Precision::I64,
// Interpreter backend doesn't implement evaluate method for OP
// InferenceEngine::Precision::FP64,
};
#include "shared_test_classes/base/ov_subgraph.hpp"

namespace {
typedef std::tuple<
InferenceEngine::Precision, // Input/Output Precision
InferenceEngine::Layout, // Input layout
InferenceEngine::Layout, // Output layout
std::vector<size_t>, // Input Shape
ov::element::Type, // Input/Output type
ov::Shape, // Input Shape
std::string> newtworkParams;

class InferRequestIOPrecision : public testing::WithParamInterface<newtworkParams>,
virtual public LayerTestsUtils::LayerTestsCommon {
virtual public ov::test::SubgraphBaseStaticTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<newtworkParams> &obj);
InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override;

protected:
void SetUp() override;
};

std::string InferRequestIOPrecision::getTestCaseName(const testing::TestParamInfo<newtworkParams> &obj) {
InferenceEngine::Precision netPrecision;
InferenceEngine::Layout inLayout, outLayout;
std::vector<size_t> shape;
ov::element::Type model_type;
ov::Shape shape;
std::string targetDevice;
std::tie(netPrecision, inLayout, outLayout, shape, targetDevice) = obj.param;
std::tie(model_type, shape, targetDevice) = obj.param;

std::ostringstream result;
const char separator = '_';
result << "netPRC=" << netPrecision.name() << separator;
result << "inL=" << inLayout << separator;
result << "outL=" << outLayout << separator;
result << "netPRC=" << model_type.get_type_name() << separator;
result << "trgDev=" << targetDevice;
return result.str();
}

void InferRequestIOPrecision::SetUp() {
InferenceEngine::Precision netPrecision;
std::vector<size_t> shape;
std::tie(netPrecision, inLayout, outLayout, shape, targetDevice) = GetParam();
inPrc = netPrecision;
outPrc = netPrecision;
ov::element::Type model_type;
ov::Shape shape;
std::tie(model_type, shape, targetDevice) = GetParam();

float clamp_min = netPrecision.isSigned() ? -5.f : 0.0f;
float clamp_min = model_type.is_signed() ? -5.f : 0.0f;
float clamp_max = 5.0f;

auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
ov::ParameterVector params {std::make_shared<ov::op::v0::Parameter>(ngPrc, ov::Shape(shape))};
ov::ParameterVector params {std::make_shared<ov::op::v0::Parameter>(model_type, ov::Shape(shape))};
params[0]->set_friendly_name("Input");

auto activation = ngraph::builder::makeActivation(params[0],
ngPrc,
ngraph::helpers::ActivationTypes::Clamp,
{},
{clamp_min, clamp_max});
auto activation = ov::test::utils::make_activation(params[0],
model_type,
ov::test::utils::ActivationTypes::Clamp,
{},
{clamp_min, clamp_max});

function = std::make_shared<ngraph::Function>(ngraph::NodeVector{activation}, params);
function = std::make_shared<ov::Model>(ov::NodeVector{activation}, params);
}

InferenceEngine::Blob::Ptr InferRequestIOPrecision::GenerateInput(const InferenceEngine::InputInfo &info) const {
bool inPrcSigned = function->get_parameters()[0]->get_element_type().is_signed();
bool inPrcReal = function->get_parameters()[0]->get_element_type().is_real();

int32_t data_start_from = inPrcSigned ? -10 : 0;
uint32_t data_range = 20;
int32_t resolution = inPrcReal ? 32768 : 1;

return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), data_range,
data_start_from,
resolution);
TEST_P(InferRequestIOPrecision, Inference) {
run();
}

TEST_P(InferRequestIOPrecision, CompareWithRefs) {
Run();
}
const std::vector<ov::element::Type> input_types = {
ov::element::i16,
ov::element::u16,
ov::element::f32,
ov::element::f16,
ov::element::u8,
ov::element::i8,
ov::element::i32,
ov::element::u32,
ov::element::u64,
ov::element::i64,
// Interpreter backend doesn't implement evaluate method for OP
// ov::element::f64,
};

INSTANTIATE_TEST_SUITE_P(smoke_GPU_BehaviorTests, InferRequestIOPrecision,
::testing::Combine(
::testing::ValuesIn(inputPrecisions),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(std::vector<size_t>{1, 50}),
::testing::ValuesIn(input_types),
::testing::Values(ov::Shape{1, 50}),
::testing::Values(ov::test::utils::DEVICE_GPU)),
InferRequestIOPrecision::getTestCaseName);

TEST(TensorTest, smoke_canSetShapeForPreallocatedTensor) {
auto ie = ov::Core();
auto core = ov::Core();
using namespace ov::preprocess;
auto p = PrePostProcessor(ngraph::builder::subgraph::makeSplitMultiConvConcat());
p.input().tensor().set_element_type(ov::element::i8);
p.input().preprocess().convert_element_type(ov::element::f32);

auto function = p.build();
auto exec_net = ie.compile_model(function, ov::test::utils::DEVICE_GPU);
auto exec_net = core.compile_model(function, ov::test::utils::DEVICE_GPU);
auto inf_req = exec_net.create_infer_request();

// Check set_shape call for pre-allocated input/output tensors
Expand All @@ -144,27 +113,27 @@ TEST(TensorTest, smoke_canSetScalarTensor) {
params.front()->output(0).get_tensor().set_names({"scalar1"});

std::vector<size_t> const_shape = {1};
auto const1 = ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{1}, const_shape);
auto const1 = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{1}, const_shape);
const1->set_friendly_name("Const_1");
const1->output(0).get_tensor().set_names({"const1"});
const1->fill_data(ov::element::i64, 0);

auto unsqueeze1 = std::make_shared<ngraph::opset1::Unsqueeze>(params.front(), const1);
auto unsqueeze1 = std::make_shared<ov::op::v0::Unsqueeze>(params.front(), const1);

ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(unsqueeze1)};
std::shared_ptr<ngraph::Function> fnPtr = std::make_shared<ngraph::Function>(results, params);
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(unsqueeze1)};
auto model = std::make_shared<ov::Model>(results, params);

auto ie = ov::Core();
auto compiled_model = ie.compile_model(fnPtr, ov::test::utils::DEVICE_GPU);
auto core = ov::Core();
auto compiled_model = core.compile_model(model, ov::test::utils::DEVICE_GPU);
auto request = compiled_model.create_infer_request();
double real_data = 1.0;
ov::Tensor input_data(ngraph::element::f64, {}, &real_data);
ov::Tensor input_data(ov::element::f64, {}, &real_data);
request.set_tensor("scalar1", input_data);
ASSERT_NO_THROW(request.infer());
}

TEST(TensorTest, smoke_canSetTensorForDynamicInput) {
auto ie = ov::Core();
auto core = ov::Core();
using namespace ov::preprocess;
auto p = PrePostProcessor(ngraph::builder::subgraph::makeSplitMultiConvConcat());
p.input().tensor().set_element_type(ov::element::i8);
Expand All @@ -173,7 +142,7 @@ TEST(TensorTest, smoke_canSetTensorForDynamicInput) {
auto function = p.build();
std::map<size_t, ov::PartialShape> shapes = { {0, ov::PartialShape{-1, -1, -1, -1}} };
function->reshape(shapes);
auto exec_net = ie.compile_model(function, ov::test::utils::DEVICE_GPU);
auto exec_net = core.compile_model(function, ov::test::utils::DEVICE_GPU);
auto inf_req = exec_net.create_infer_request();

ov::Tensor t1(ov::element::i8, {1, 4, 20, 20});
Expand Down Expand Up @@ -243,3 +212,4 @@ TEST(VariablesTest, smoke_canSetStateTensor) {

ASSERT_NO_THROW(request.infer());
}
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
//

#include <string>
#include <utility>
#include <vector>
#include <memory>

#include "openvino/runtime/core.hpp"

#include <common_test_utils/test_common.hpp>
#include "shared_test_classes/base/layer_test_utils.hpp"
#include "base/ov_behavior_test_utils.hpp"
#include "functional_test_utils/ov_plugin_cache.hpp"

using namespace ::testing;
#include "openvino/runtime/core.hpp"

namespace {
using params = std::tuple<ov::element::Type, ov::element::Type>;

class InferencePrecisionTests : public testing::WithParamInterface<params>,
virtual public LayerTestsUtils::LayerTestsCommon {
class InferencePrecisionTests : public ::testing::TestWithParam<params> {
public:
static std::string getTestCaseName(const testing::TestParamInfo<params> &obj) {
ov::element::Type model_precision;
Expand All @@ -33,7 +22,7 @@ class InferencePrecisionTests : public testing::WithParamInterface<params>,

TEST_P(InferencePrecisionTests, smoke_canSetInferencePrecisionAndInfer) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
auto core = ov::test::utils::PluginCache::get().core();
auto core = ov::test::utils::PluginCache::get().core();
ov::element::Type model_precision;
ov::element::Type inference_precision;
std::tie(model_precision, inference_precision) = GetParam();
Expand Down Expand Up @@ -84,3 +73,4 @@ TEST(ExecutionModeTest, SetCompileGetInferPrecisionAndExecMode) {
ASSERT_EQ(ov::element::f16, compiled_model.get_property(ov::hint::inference_precision));
}
}
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "common_test_utils/test_common.hpp"
#include "common_test_utils/common_utils.hpp"
#include "common_test_utils/test_constants.hpp"
#include "functional_test_utils/skip_tests_config.hpp"
#include "functional_test_utils/ov_plugin_cache.hpp"
#include "openvino/core/partial_shape.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/runtime/compiled_model.hpp"
#include "openvino/runtime/infer_request.hpp"
#include "openvino/runtime/core.hpp"
#include "ov_models/subgraph_builders.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "functional_test_utils/skip_tests_config.hpp"
#include "functional_test_utils/ov_plugin_cache.hpp"
#include "common_test_utils/common_utils.hpp"

#include <vector>

#include <gtest/gtest.h>

using namespace ov::test;
#include "openvino/op/add.hpp"

namespace {
using MemoryDynamicBatchParams = std::tuple<
ov::PartialShape, // Partial shape for network initialization
ov::Shape, // Actual shape to be passed to inference request
Expand Down Expand Up @@ -57,9 +52,9 @@ class MemoryDynamicBatch : public ::testing::Test,
infer_request = compiled_model.create_infer_request();
}

static std::shared_ptr<ov::Model> build_model(ElementType precision, const ov::PartialShape& shape) {
auto param = std::make_shared<ov::op::v0::Parameter>(precision, shape);
const ov::op::util::VariableInfo variable_info { shape, precision, "v0" };
static std::shared_ptr<ov::Model> build_model(ov::element::Type type, const ov::PartialShape& shape) {
auto param = std::make_shared<ov::op::v0::Parameter>(type, shape);
const ov::op::util::VariableInfo variable_info { shape, type, "v0" };
auto variable = std::make_shared<ov::op::util::Variable>(variable_info);
auto read_value = std::make_shared<ov::op::v6::ReadValue>(param, variable);
auto add = std::make_shared<ov::op::v1::Add>(read_value, param);
Expand Down Expand Up @@ -169,3 +164,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_MemoryDynamicBatch, MemoryDynamicBatch,
::testing::ValuesIn(iterations_num),
::testing::Values(ov::test::utils::DEVICE_GPU)),
MemoryDynamicBatch::get_test_case_name);
} // namespace
Loading
Loading