Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Add 1d_conv flag in convolution primitive (#32864)

Wilson Seokbee83079fc84
diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/convolution.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/convolution.hpp
index 880b4e79de1..d5d909e7087 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/primitives/convolution.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/convolution.hpp
@@ -35,6 +35,7 @@ struct convolution : public primitive_base<convolution> {
/// @param padding_end Defines a padding added to input image on right (x axis) and bottom (y axis).
/// @param grouped_weights_shape True if weights shape is [G, O, I, ...], and false if it's [O, I, ...] or [G*O, I, ...]
/// @param audo_pad The pad type for automatically computing padding sizes
+ /// @param filter_rank Filter rank from op
convolution(const primitive_id& id,
const input_info& input,
const primitive_id& weights,
@@ -49,7 +50,8 @@ struct convolution : public primitive_base<convolution> {
ov::CoordinateDiff padding_end,
bool grouped_weights_shape,
data_types output_data_type,
- const ov::op::PadType& auto_pad = ov::op::PadType::EXPLICIT)
+ const ov::op::PadType& auto_pad = ov::op::PadType::EXPLICIT,
+ size_t filter_rank = 4)
: primitive_base(id, {input}, 1, {optional_data_type{output_data_type}}),
groups(groups),
stride(stride),
@@ -58,6 +60,7 @@ struct convolution : public primitive_base<convolution> {
padding_end(padding_end),
auto_pad(auto_pad),
grouped_weights_shape(grouped_weights_shape),
+ filter_rank(filter_rank),
weights(weights),
bias(bias),
weights_zero_points(w_zero_point),
@@ -81,6 +84,7 @@ struct convolution : public primitive_base<convolution> {
/// @param padding_end Defines a padding added to input image on right (x axis) and bottom (y axis).
/// @param grouped_weights_shape True if weights shape is [G, O, I, ...], and false if it's [O, I, ...] or [G*O, I, ...]
/// @param audo_pad The pad type for automatically computing padding sizes
+ /// @param filter_rank Filter rank from op
convolution(const primitive_id& id,
const input_info& input,
const primitive_id& weights,
@@ -91,7 +95,8 @@ struct convolution : public primitive_base<convolution> {
ov::CoordinateDiff padding_begin,
ov::CoordinateDiff padding_end,
bool grouped_weights_shape,
- const ov::op::PadType& auto_pad = ov::op::PadType::EXPLICIT)
+ const ov::op::PadType& auto_pad = ov::op::PadType::EXPLICIT,
+ size_t filter_rank = 4)
: primitive_base(id, {input}),
groups(groups),
stride(stride),
@@ -100,6 +105,7 @@ struct convolution : public primitive_base<convolution> {
padding_end(padding_end),
auto_pad(auto_pad),
grouped_weights_shape(grouped_weights_shape),
+ filter_rank(filter_rank),
weights(weights),
bias(bias),
weights_zero_points(""),
@@ -126,6 +132,7 @@ struct convolution : public primitive_base<convolution> {
/// @param padding_end Defines a padding added to input image on right (x axis) and bottom (y axis).
/// @param bilinear_interpolation_pad If bilinear_interpolation_pad is true and the sampling location is within
/// one pixel outside of the feature map boundary, then bilinear interpolation is performed on the zero padded feature map.
+ /// @param filter_rank Filter rank from op
convolution(const primitive_id& id,
const std::vector<input_info>& inputs,
const primitive_id& weights,
@@ -137,7 +144,8 @@ struct convolution : public primitive_base<convolution> {
ov::Strides dilation,
ov::CoordinateDiff padding_begin,
ov::CoordinateDiff padding_end,
- bool bilinear_interpolation_pad = false)
+ bool bilinear_interpolation_pad = false,
+ size_t filter_rank = 4)
: primitive_base(id, inputs),
groups(groups),
stride(stride),
@@ -149,6 +157,7 @@ struct convolution : public primitive_base<convolution> {
deformable_groups(deformable_groups),
bilinear_interpolation_pad(bilinear_interpolation_pad),
grouped_weights_shape(false),
+ filter_rank(filter_rank),
weights(weights),
bias(bias),
weights_zero_points(""),
@@ -186,6 +195,8 @@ struct convolution : public primitive_base<convolution> {
/// @param grouped_weights_shape Defines if weights tensor has explicit group dimension.
bool grouped_weights_shape {false};
+ /// @param filter_rank Filter rank from op
+ size_t filter_rank = 4;
/// @brief Primitive id containing weights data.
input_info weights;
/// @brief Primitive id containing bias data.
@@ -210,6 +221,7 @@ struct convolution : public primitive_base<convolution> {
seed = hash_combine(seed, bilinear_interpolation_pad);
seed = hash_combine(seed, transposed);
seed = hash_combine(seed, grouped_weights_shape);
+ seed = hash_combine(seed, filter_rank);
seed = hash_combine(seed, !weights.is_valid());
seed = hash_combine(seed, !bias.is_valid());
seed = hash_combine(seed, !weights_zero_points.is_valid());
@@ -236,6 +248,7 @@ struct convolution : public primitive_base<convolution> {
cmp_fields(bilinear_interpolation_pad) &&
cmp_fields(transposed) &&
cmp_fields(grouped_weights_shape) &&
+ cmp_fields(filter_rank) &&
cmp_fields(weights.is_valid()) &&
cmp_fields(bias.is_valid()) &&
cmp_fields(weights_zero_points.is_valid()) &&
@@ -257,6 +270,7 @@ struct convolution : public primitive_base<convolution> {
ob << bilinear_interpolation_pad;
ob << transposed;
ob << grouped_weights_shape;
+ ob << filter_rank;
ob << weights;
ob << bias;
ob << weights_zero_points;
@@ -277,6 +291,7 @@ struct convolution : public primitive_base<convolution> {
ib >> bilinear_interpolation_pad;
ib >> transposed;
ib >> grouped_weights_shape;
+ ib >> filter_rank;
ib >> weights;
ib >> bias;
ib >> weights_zero_points;
diff --git a/src/plugins/intel_gpu/src/graph/convolution.cpp b/src/plugins/intel_gpu/src/graph/convolution.cpp
index 0baa8674a27..d5eef30b6d2 100644
--- a/src/plugins/intel_gpu/src/graph/convolution.cpp
+++ b/src/plugins/intel_gpu/src/graph/convolution.cpp
@@ -127,7 +127,8 @@ std::vector<layout> calc_output_layout_impl(convolution_node const& node, kernel
// WA for legacy flow, mostly for unit tests as sometimes grouped conv has non-grouped weights
if (legacy_flow && input_shapes[1].size() == 4 && input_shapes[0].size() == 4) {
// Extend grouped 1d conv weights shape from 4d to 5d when conv input shape is canonicalized to 4d by allow_new_shape_infer=false
- if (desc->grouped_weights_shape && desc->groups > 1 && (static_cast<int64_t>(desc->groups) == input_shapes[1][0].get_length())) {
+ const bool is_1d_group_conv = (desc->filter_rank == 4) && desc->grouped_weights_shape && desc->groups > 1;
+ if (is_1d_group_conv && (static_cast<int64_t>(desc->groups) == input_shapes[1][0].get_length())) {
// 1d convolution with groups, e.g. shape [g,oc,ic,x] -> [g,oc,ic,x,1]
weights_shape.insert(weights_shape.end(), 1);
} else {
@@ -214,9 +215,9 @@ convolution_inst::typed_primitive_inst(network& network, convolution_node const&
auto filter_inst = node.weights().get_output_layout().convert_to_weights_layout(argument->grouped_weights_shape);
// Extend grouped 1d conv weights shape from 4d to 5d when conv input shape is canonicalized to 4d by allow_new_shape_infer=false
+ const bool is_1d_group_conv = (argument->filter_rank == 4) && argument->grouped_weights_shape && argument->groups > 1;
const bool needs_filter_extension = !network.get_program()->is_new_shape_infer() &&
- argument->grouped_weights_shape &&
- argument->groups > 1 &&
+ is_1d_group_conv &&
filter_inst.get_rank() == 4 &&
!format::is_grouped(filter_inst.format);
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/convolution.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/convolution.cpp
index 4b203b04c71..2570166276a 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl/convolution.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/convolution.cpp
@@ -92,10 +92,8 @@ public:
.convert_to_weights_layout(primitive->grouped_weights_shape);
// Extend grouped 1d conv weights shape from 4d to 5d when conv input shape is canonicalized to 4d by allow_new_shape_infer=false
- const bool needs_weights_extension = !impl_param.get_program().is_new_shape_infer() &&
- groups > 1 &&
- weights_layout.get_rank() == 4 &&
- conv_params.grouped_weights_shape;
+ const bool is_1d_group_conv = (primitive->filter_rank == 4) && conv_params.grouped_weights_shape && groups > 1;
+ const bool needs_weights_extension = is_1d_group_conv && weights_layout.get_rank() == 4;
if (needs_weights_extension) {
weights_layout = extend_weights_layout_to_5d(weights_layout);
diff --git a/src/plugins/intel_gpu/src/plugin/ops/convolution.cpp b/src/plugins/intel_gpu/src/plugin/ops/convolution.cpp
index 0907a97414f..e46e76d80ab 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/convolution.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/convolution.cpp
@@ -42,6 +42,7 @@ static void CreateConvolutionOp(ProgramBuilder& p, const std::shared_ptr<ov::int
auto pads_begin = op->get_pads_begin();
auto pads_end = op->get_pads_end();
auto auto_pad = op->get_auto_pad();
+ size_t filter_rank = op->get_input_partial_shape(1).rank().get_length();
if (!op->is_dynamic() && !p.use_new_shape_infer()) {
// Extend 1d vectors to 2d as 1d can't be handled properly by the graph optimizer for now
@@ -71,7 +72,8 @@ static void CreateConvolutionOp(ProgramBuilder& p, const std::shared_ptr<ov::int
pads_end,
weights_have_group_dim,
op->get_output_element_type(0),
- auto_pad);
+ auto_pad,
+ filter_rank);
} else {
prim = std::make_shared<cldnn::convolution>(layerName,
inputs[op::Convolution::Args::INPUT],
@@ -83,7 +85,8 @@ static void CreateConvolutionOp(ProgramBuilder& p, const std::shared_ptr<ov::int
pads_begin,
pads_end,
weights_have_group_dim,
- auto_pad);
+ auto_pad,
+ filter_rank);
}
p.add_primitive(*op, prim);
diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/group_convolution.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/group_convolution.cpp
index d97bf9ef4be..97bc46feccf 100644
--- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/group_convolution.cpp
+++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/group_convolution.cpp
@@ -11,6 +11,7 @@
#include "openvino/op/multiply.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/convert.hpp"
+#include "openvino/op/reshape.hpp"
namespace {
using ov::test::InputShape;
@@ -24,6 +25,7 @@ typedef std::tuple<
ov::element::Type, // Weights precision
InputShape, // Input shape
bool, // Weights scaling
+ bool, // Weights reshape
std::string // Device name
> groupConvLayerTestParamsSet;
@@ -31,7 +33,7 @@ class GroupConvolutionLayerGPUTest : public testing::WithParamInterface<groupCon
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<groupConvLayerTestParamsSet>& obj) {
- const auto& [convParams, netType, inType, outType, weightsType, inputShape, weightsScaling, targetDevice] = obj.param;
+ const auto& [convParams, netType, inType, outType, weightsType, inputShape, weightsScaling, weightsReshape, targetDevice] = obj.param;
const auto& [kernel, stride, padBegin, padEnd, dilation, convOutChannels, group, padType] = convParams;
@@ -56,6 +58,7 @@ public:
result << "outPRC=" << outType << "_";
result << "weightsPRC=" << weightsType << "_";
result << "weightsScaling=" << weightsScaling << "_";
+ result << "weightsReshape=" << weightsReshape << "_";
result << "trgDev=" << targetDevice;
return result.str();
@@ -63,7 +66,7 @@ public:
protected:
void SetUp() override {
- const auto& [groupConvParams, netType, _inType, _outType, weightsType, inputShape, weightsScaling, _targetDevice] = this->GetParam();
+ const auto& [groupConvParams, netType, _inType, _outType, weightsType, inputShape, weightsScaling, weightsReshape, _targetDevice] = this->GetParam();
inType = _inType;
outType = _outType;
targetDevice = _targetDevice;
@@ -80,9 +83,18 @@ protected:
std::shared_ptr<ov::Node> groupConvolutionNode;
if (weightsScaling) {
size_t convInChannels = static_cast<size_t>(targetStaticShapes.front()[0][1] / group);
- ov::Shape filter_weights_shape = {group, convOutChannels, convInChannels};
+ ov::Shape filter_weights_shape;
+ if (weightsReshape)
+ filter_weights_shape = {group * convOutChannels, convInChannels};
+ else
+ filter_weights_shape = {group, convOutChannels, convInChannels};
filter_weights_shape.insert(filter_weights_shape.end(), kernel.begin(), kernel.end());
- ov::Shape scaling_shape = {group, convOutChannels, 1, 1};
+ ov::Shape scaling_shape;
+ if (weightsReshape)
+ scaling_shape = {group * convOutChannels};
+ else
+ scaling_shape = {group, convOutChannels};
+ scaling_shape.resize(filter_weights_shape.size(), 1);
auto weights_tensor = ov::test::utils::create_and_fill_tensor(weightsType,
filter_weights_shape, ov::test::utils::InputGenerateData(-127, 256, 256, 1));
auto scaling_tensor = ov::test::utils::create_and_fill_tensor(netType, scaling_shape, ov::test::utils::InputGenerateData(0, 1, 8092, 1));
@@ -90,11 +102,23 @@ protected:
auto convert_node = std::make_shared<ov::op::v0::Convert>(filter_weights_node, netType);
auto scaling_node = std::make_shared<ov::op::v0::Constant>(scaling_tensor);
auto multiply_node = std::make_shared<ov::op::v1::Multiply>(convert_node, scaling_node);
- groupConvolutionNode = ov::test::utils::make_group_convolution(inputParams.front(), multiply_node, netType, stride, padBegin,
+ ov::Output<ov::Node> filter_node;
+ if (weightsReshape) {
+ ov::Shape reshaped_weights_shape = {group, convOutChannels, convInChannels};
+ reshaped_weights_shape.insert(reshaped_weights_shape.end(), kernel.begin(), kernel.end());
+ filter_node = std::make_shared<ov::op::v1::Reshape>(multiply_node,
+ ov::op::v0::Constant::create(ov::element::i64,
+ {reshaped_weights_shape.size()},
+ reshaped_weights_shape),
+ false);
+ } else {
+ filter_node = multiply_node;
+ }
+ groupConvolutionNode = ov::test::utils::make_group_convolution(inputParams.front(), filter_node, netType, stride, padBegin,
padEnd, dilation, padType);
} else {
groupConvolutionNode = ov::test::utils::make_group_convolution(inputParams.front(), netType, kernel, stride, padBegin,
- padEnd, dilation, padType, convOutChannels, group);
+ padEnd, dilation, padType, convOutChannels * group, group);
}
@@ -105,8 +129,8 @@ protected:
function = std::make_shared<ov::Model>(results, inputParams, "GroupConvolution");
if (netType == ov::element::f16) {
- abs_threshold = 0.1;
- rel_threshold = 0.1;
+ abs_threshold = 0.2;
+ rel_threshold = 0.2;
} else {
abs_threshold = 0.005;
rel_threshold = 0.005;
@@ -138,6 +162,10 @@ const InputShape input_shapes_depthwise = {
{10, 64, 3}, {{10, 64, 3}}
};
+const InputShape input_shapes_2d = {
+ {1, 32, 112, 112}, {{1, 32, 112, 112}}
+ };
+
TEST_P(GroupConvolutionLayerGPUTest, Inference) {
run();
}
@@ -159,6 +187,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_GroupConvolutionLayerGPUTest_1D_basic,
::testing::Values(ov::element::i8),
::testing::Values(input_shapes_1d),
::testing::Values(true),
+ ::testing::Values(false),
::testing::Values<std::string>(ov::test::utils::DEVICE_GPU)),
GroupConvolutionLayerGPUTest::getTestCaseName);
@@ -178,6 +207,27 @@ INSTANTIATE_TEST_SUITE_P(smoke_GroupConvolutionLayerGPUTest_1D_depthwise,
::testing::Values(ov::element::i8),
::testing::Values(input_shapes_depthwise),
::testing::Values(true),
+ ::testing::Values(false),
+ ::testing::Values<std::string>(ov::test::utils::DEVICE_GPU)),
+ GroupConvolutionLayerGPUTest::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(smoke_GroupConvolutionLayerGPUTest_2D_basic,
+ GroupConvolutionLayerGPUTest,
+ ::testing::Combine(::testing::Combine(::testing::Values(std::vector<size_t>{3, 3}),
+ ::testing::Values(std::vector<size_t>{1, 1}),
+ ::testing::Values(std::vector<ptrdiff_t>{1, 1}),
+ ::testing::Values(std::vector<ptrdiff_t>{1, 1}),
+ ::testing::Values(std::vector<size_t>{1, 1}),
+ ::testing::Values(1),
+ ::testing::Values(32),
+ ::testing::Values(ov::op::PadType::EXPLICIT)),
+ ::testing::Values(ov::element::f32),
+ ::testing::Values(ov::element::f32),
+ ::testing::Values(ov::element::dynamic),
+ ::testing::Values(ov::element::i8),
+ ::testing::Values(input_shapes_2d),
+ ::testing::Values(true),
+ ::testing::Values(true),
::testing::Values<std::string>(ov::test::utils::DEVICE_GPU)),
GroupConvolutionLayerGPUTest::getTestCaseName);
} // namespace
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp
index eb7109cb6e2..bbf09de92a7 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp
@@ -226,8 +226,8 @@ public:
const auto primitive_hash = primitve->hash();
const auto params_hash = prim_inst->get_impl_params()->hash();
- ASSERT_EQ(primitive_hash, 13549661971645339528UL);
- ASSERT_EQ(params_hash, 2317969473793675238UL);
+ ASSERT_EQ(primitive_hash, 10199782087454290518UL);
+ ASSERT_EQ(params_hash, 655948409235783525UL);
}
void test_quantize_basic(bool is_caching_test) {