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

[CPU][ARM] Dynamic shapes support in ARM transformations #17548

Merged
merged 14 commits into from
Jun 12, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ ov::intel_cpu::ConvertGroupConvolution::ConvertGroupConvolution() {
if (!gconv) {
return false;
}

auto data_shape = gconv->get_input_shape(Inputs::Data);
const unsigned int channel_axis = 1;
const auto& input0 = gconv->input_value(0);
const auto& output_shape = gconv->get_output_partial_shape(0);
const auto& data_shape = input0.get_partial_shape();
// Weights layout GOIYX
size_t groups = gconv->get_input_shape(Inputs::Weights)[0];
if (groups == data_shape.at(1) && groups == gconv->get_output_shape(0)[1]) { // depthwise case

if (data_shape[channel_axis].is_dynamic() ||
output_shape[channel_axis].is_dynamic()) {
return false;
}

if (groups == data_shape[channel_axis].get_length() &&
groups == output_shape[channel_axis].get_length()) { // depthwise case
return false;
}

Expand All @@ -33,7 +42,7 @@ ov::intel_cpu::ConvertGroupConvolution::ConvertGroupConvolution() {
groups);
replace_nodes.push_back(split_weights);

auto axis = ov::opset8::Constant::create<int64_t>(ngraph::element::i64, ngraph::Shape{}, {1});
auto axis = ov::opset8::Constant::create<int64_t>(ngraph::element::i64, ngraph::Shape{}, {channel_axis});
auto split = std::make_shared<ov::opset1::Split>(gconv->input_value(Inputs::Data), axis, groups);
replace_nodes.push_back(split);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@ ngraph::matcher_pass_callback ov::intel_cpu::ConvertConv1DBase::convert_conv1d_t
return false;
}

auto input_shape = conv->get_input_shape(0);
const auto& input0 = conv->input_value(0);
const auto& input_shape = input0.get_partial_shape();
// is Conv1D
if (input_shape.size() != 3) {
return false;
}

auto input = conv->input_value(0);
auto weights = conv->input_value(1);
auto input2d_shape = input_shape;
input2d_shape.push_back(1);
auto in2d_shape = std::make_shared<ov::opset8::Constant>(ngraph::element::i64, ngraph::Shape{4}, input2d_shape);

auto weights2d_shape = weights.get_shape();
weights2d_shape.push_back(1);
auto w_shape = std::make_shared<ov::opset8::Constant>(ngraph::element::i64, ngraph::Shape{weights2d_shape.size()}, weights2d_shape);

auto input2d = std::make_shared<ov::opset8::Reshape>(input, in2d_shape, true);
auto weights2d = std::make_shared<ov::opset8::Reshape>(weights, w_shape, true);
auto getUnsqueeze = [&](const ngraph::Output<ngraph::Node>& node) {
auto rank = node.get_partial_shape().rank().get_length();
return std::make_shared<ov::opset8::Unsqueeze>(node,
ov::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {rank}));
};

auto input2d = getUnsqueeze(input);
auto weights2d = getUnsqueeze(weights);

auto conv2d = std::make_shared<Conv>(input2d,
weights2d,
Expand All @@ -46,8 +50,9 @@ ngraph::matcher_pass_callback ov::intel_cpu::ConvertConv1DBase::convert_conv1d_t
ngraph::Strides{conv->get_dilations()[0], 1},
conv->get_auto_pad());

auto in_shape = std::make_shared<ov::opset8::Constant>(ngraph::element::i64, ngraph::Shape{3}, conv->get_output_shape(0));
auto reshape = std::make_shared<ov::opset8::Reshape>(conv2d, in_shape, true);
auto reshape = std::make_shared<ov::opset8::Squeeze>(
conv2d,
ov::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {input_shape.rank().get_length()}));

reshape->set_friendly_name(conv->get_friendly_name());
ngraph::copy_runtime_info(conv, {input2d, weights2d, conv2d, reshape});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@ ngraph::matcher_pass_callback ov::intel_cpu::ConvertReduceMultiAxisBase::convert
if (!std::dynamic_pointer_cast<T>(reduce)) {
return false;
}
if (ngraph::shape_size(reduce->input_value(1).get_shape()) <= 1) {

const auto& input0 = reduce->input_value(0);
const auto& input1 = reduce->input_value(1);
const auto& data_shape0 = input0.get_partial_shape();
const auto& data_shape1 = input1.get_partial_shape();
if (data_shape0.is_dynamic() ||
data_shape1.is_dynamic()) {
return false;
}

if (ngraph::shape_size(input1.get_shape()) <= 1) {
return false;
}
auto reduction_axes = std::dynamic_pointer_cast<ov::opset8::Constant>(reduce->input_value(1).get_node_shared_ptr());
auto reduction_axes = std::dynamic_pointer_cast<ov::opset8::Constant>(input1.get_node_shared_ptr());
if (!reduction_axes) {
return false;
}
auto axes = reduction_axes->cast_vector<int64_t>();
ngraph::NodeVector new_ops;
std::shared_ptr<ngraph::Node> node = reduce->input_value(0).get_node_shared_ptr();
std::shared_ptr<ngraph::Node> node = input0.get_node_shared_ptr();
for (auto axis : axes) {
auto reduction_axis = ov::opset8::Constant::create<int64_t>(ngraph::element::i64, ngraph::Shape{}, {axis});
node = std::make_shared<T>(node, reduction_axis, true);
Expand Down