Skip to content

Commit

Permalink
Refactor gpu subgraph tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olpipi committed Dec 4, 2023
1 parent 87a96a4 commit 513ebb4
Show file tree
Hide file tree
Showing 11 changed files with 670 additions and 837 deletions.
550 changes: 263 additions & 287 deletions src/plugins/intel_gpu/tests/functional/subgraph_tests/condition.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@
// SPDX-License-Identifier: Apache-2.0
//

#include <openvino/opsets/opset1.hpp>
#include <common_test_utils/ov_tensor_utils.hpp>

#include "ov_models/builders.hpp"
#include "ov_models/utils/ov_helpers.hpp"
#include "shared_test_classes/base/layer_test_utils.hpp"
#include "common_test_utils/ov_tensor_utils.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "openvino/pass/serialize.hpp"

using namespace ngraph;
using namespace ov::test;
using namespace InferenceEngine;
#include "openvino/op/parameter.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/result.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/broadcast.hpp"

namespace {
using ov::test::InputShape;

namespace GPULayerTestsDefinitions {
using BroadcastEltwiseParams = std::tuple<
ElementType, // input precision
InputShape, // input shape
ov::Shape // target broadcast shape
ov::element::Type, // input type
InputShape, // input shape
ov::Shape // target broadcast shape
>;

class BroadcastEltwise : virtual public SubgraphBaseTest, public testing::WithParamInterface<BroadcastEltwiseParams> {
class BroadcastEltwise : virtual public ov::test::SubgraphBaseTest,
public testing::WithParamInterface<BroadcastEltwiseParams> {
public:
static std::string getTestCaseName(const testing::TestParamInfo<BroadcastEltwiseParams>& obj) {
ElementType input_precision;
ov::element::Type model_type;
InputShape input_shape;
ov::Shape target_shape;
std::tie(input_precision, input_shape, target_shape) = obj.param;
std::tie(model_type, input_shape, target_shape) = obj.param;

std::ostringstream result;
result << "precision=" << input_precision << "IS=(" << ov::test::utils::partialShape2str({input_shape.first}) << ")_TS=(";
result << "precision=" << model_type << "IS=(" << ov::test::utils::partialShape2str({input_shape.first}) << ")_TS=(";
for (const auto& item : input_shape.second) {
result << ov::test::utils::vec2str(item) << "_";
}
Expand All @@ -41,23 +40,23 @@ class BroadcastEltwise : virtual public SubgraphBaseTest, public testing::WithPa

protected:
void SetUp() override {
ElementType input_precision;
ov::element::Type model_type;
InputShape input_shape;
std::tie(input_precision, input_shape, target_shape) = GetParam();
std::tie(model_type, input_shape, target_shape) = GetParam();
targetDevice = ov::test::utils::DEVICE_GPU;

std::vector<InputShape> input_shapes{input_shape, {{}, {{target_shape.size()}}}};
init_input_shapes(input_shapes);

ov::element::TypeVector input_precisions{input_precision, ov::element::i64};
ov::element::TypeVector model_types{model_type, ov::element::i64};
ov::ParameterVector params;
for (size_t i = 0; i < input_precisions.size(); i++) {
auto param_node = std::make_shared<ov::op::v0::Parameter>(input_precisions[i], inputDynamicShapes[i]);
for (size_t i = 0; i < model_types.size(); i++) {
auto param_node = std::make_shared<ov::op::v0::Parameter>(model_types[i], inputDynamicShapes[i]);
params.push_back(param_node);
}
const auto bcast_data = ov::opset10::Constant::create(input_precision, {}, {1.f});
const auto bcast = std::make_shared<ov::opset10::Broadcast>(bcast_data, params[1]);
const auto add = std::make_shared<ov::opset10::Add>(params[0], bcast);
const auto bcast_data = ov::op::v0::Constant::create(model_type, {}, {1.f});
const auto bcast = std::make_shared<ov::op::v3::Broadcast>(bcast_data, params[1]);
const auto add = std::make_shared<ov::op::v1::Add>(params[0], bcast);
function = std::make_shared<ov::Model>(add, params);
}

Expand Down Expand Up @@ -95,7 +94,6 @@ TEST_P(BroadcastEltwise, smoke_CompareWithRefs) {
EXPECT_EQ(last_input_layer_type, "broadcast");
}

namespace {
const std::vector<InputShape> input_shapes = {
{{-1, -1, -1, -1}, {{1, 3, 16, 16}}},
{{-1, -1}, {{16, 16}}},
Expand All @@ -113,4 +111,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_BroadcastEltwise,
::testing::ValuesIn(target_shapes)),
BroadcastEltwise::getTestCaseName);
} // namespace
} // namespace GPULayerTestsDefinitions

Original file line number Diff line number Diff line change
@@ -1,59 +1,53 @@
// Copyright (C) 2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <tuple>
#include <string>
#include <vector>
#include <memory>
#include "ov_models/utils/ov_helpers.hpp"
#include "ov_models/builders.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "shared_test_classes/single_layer/split.hpp"
#include <common_test_utils/ov_tensor_utils.hpp>
#include "common_test_utils/ov_tensor_utils.hpp"
#include "common_test_utils/node_builders/eltwise.hpp"

using namespace ngraph;
using namespace InferenceEngine;
using namespace ov::test;
#include "openvino/op/parameter.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/result.hpp"
#include "openvino/op/variadic_split.hpp"

namespace GPULayerTestsDefinitions {
namespace {
using ov::test::InputShape;

typedef std::tuple<
std::vector<InputShape>, // input shapes
ElementType, // Network precision
TargetDevice, // Device name
std::map<std::string, std::string> // Additional network configuration
std::vector<InputShape>, // input shapes
ov::element::Type, // Model type
std::string // Device name
> DynamicModelStaticSplitLayerGPUTestParamsSet;

const std::vector<ElementType> netPrecisions = {
ElementType::f16
const std::vector<ov::element::Type> model_types = {
ov::element::f16
};

class DynamicModelStaticSplitLayerGPUTest : public testing::WithParamInterface<DynamicModelStaticSplitLayerGPUTestParamsSet>,
virtual public SubgraphBaseTest {
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<DynamicModelStaticSplitLayerGPUTestParamsSet>& obj) {
DynamicModelStaticSplitLayerGPUTestParamsSet basicParamsSet = obj.param;
std::ostringstream result;
std::vector<InputShape> inputShapes;
ElementType netType;
TargetDevice targetDevice;
std::map<std::string, std::string> additionalConfig;
ov::element::Type model_type;
std::string targetDevice;

std::tie(inputShapes, netType, targetDevice, additionalConfig) = basicParamsSet;
std::tie(inputShapes, model_type, targetDevice) = basicParamsSet;
result << "IS=";
for (const auto& shape : inputShapes) {
result << ov::test::utils::partialShape2str({shape.first}) << "_";
for (const auto& actual_shape : shape.second) {
result << ov::test::utils::partialShape2str({actual_shape}) << "_";
}
}
result << "NetType=" << netType << "_";
result << "NetType=" << model_type << "_";
result << "targetDevice=" << targetDevice;
return result.str();
}

protected:
void generate_inputs(const std::vector<ngraph::Shape>& targetInputStaticShapes) override {
void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {
inputs.clear();
const auto& funcInputs = function->inputs();
for (size_t i = 0; i < funcInputs.size(); ++i) {
Expand All @@ -71,42 +65,37 @@ class DynamicModelStaticSplitLayerGPUTest : public testing::WithParamInterface<D
void SetUp() override {
DynamicModelStaticSplitLayerGPUTestParamsSet basicParamsSet = this->GetParam();
std::vector<InputShape> inputShapes;
ElementType netType;
std::map<std::string, std::string> additionalConfig;
std::tie(inputShapes, netType, targetDevice, additionalConfig) = basicParamsSet;
ov::element::Type model_type;
std::tie(inputShapes, model_type, targetDevice) = basicParamsSet;

init_input_shapes(inputShapes);
const auto inShapSplit = inputDynamicShapes[0];
const auto inShapeElt = inputDynamicShapes[1];
ov::ParameterVector params;
for (auto&& shape : {inShapSplit, inShapeElt})
params.push_back(std::make_shared<ov::op::v0::Parameter>(netType, shape));
params.push_back(std::make_shared<ov::op::v0::Parameter>(model_type, shape));

auto axis = ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0});
auto axis = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0});
axis->set_friendly_name("axis");

auto split_sizes = ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1});
auto split_sizes = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {1, 1});
split_sizes->set_friendly_name("split_sizes");

auto variadicSplitOp = std::make_shared<ngraph::opset1::VariadicSplit>(params[0], axis, split_sizes);
auto variadicSplitOp = std::make_shared<ov::op::v1::VariadicSplit>(params[0], axis, split_sizes);
variadicSplitOp->set_friendly_name("variadicSplit");

auto addOp = ngraph::builder::makeEltwise(params[1], variadicSplitOp->output(1), ngraph::helpers::EltwiseTypes::ADD);
auto addOp = ov::test::utils::makeEltwise(params[1], variadicSplitOp->output(1), ov::test::utils::EltwiseTypes::ADD);
addOp->set_friendly_name("add");

ngraph::ResultVector results = {std::make_shared<ngraph::opset1::Result>(addOp)};
function = std::make_shared<ngraph::Function>(results, params, "eltwise_add_out");
ov::ResultVector results = {std::make_shared<ov::op::v0::Result>(addOp)};
function = std::make_shared<ov::Model>(results, params, "eltwise_add_out");
}
};


TEST_P(DynamicModelStaticSplitLayerGPUTest, CompareWithRefs) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
TEST_P(DynamicModelStaticSplitLayerGPUTest, Inference) {
run();
}

namespace {
std::map<std::string, std::string> emptyAdditionalConfig;
const std::vector<std::vector<ov::test::InputShape>> dynInputShapes = {
{
// Input for static VariadicSplit
Expand All @@ -124,11 +113,9 @@ const std::vector<std::vector<ov::test::InputShape>> dynInputShapes = {


const auto testParams_smoke = ::testing::Combine(::testing::ValuesIn(dynInputShapes),
::testing::ValuesIn(netPrecisions), // netprec
::testing::Values(ov::test::utils::DEVICE_GPU),
::testing::Values(emptyAdditionalConfig));
::testing::ValuesIn(model_types), // netprec
::testing::Values(ov::test::utils::DEVICE_GPU));

INSTANTIATE_TEST_SUITE_P(smoke_dynamic_model_static_split, DynamicModelStaticSplitLayerGPUTest,
testParams_smoke, DynamicModelStaticSplitLayerGPUTest::getTestCaseName);
} // namespace
} // namespace GPULayerTestsDefinitions
Loading

0 comments on commit 513ebb4

Please sign in to comment.