Skip to content

Commit

Permalink
Merge branch 'master' into feature/add-u2-u3-u6-to-convert
Browse files Browse the repository at this point in the history
  • Loading branch information
mlukasze authored Mar 29, 2024
2 parents e9d789e + 5f20525 commit b601124
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 72 deletions.
4 changes: 0 additions & 4 deletions .github/components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ CPU:
revalidate:
- C_API
- Python_API
- JS_API
- samples
- ONNX_RT
- PyTorch_FE
Expand Down Expand Up @@ -106,7 +105,6 @@ IR_FE:
revalidate:
- C_API
- Python_API
- JS_API
- samples
build:
- CPU
Expand Down Expand Up @@ -176,8 +174,6 @@ Python_API:
- PyTorch_FE

JS_API:
revalidate:
- samples
build:
- CPU
- IR_FE
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/op/divide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ bool Divide::evaluate(TensorVector& outputs, const TensorVector& inputs) const {
this,
outputs,
inputs,
OV_PP_ET_LIST(f32, i8, i32, i64, u8, u32, u64),
OV_PP_ET_LIST(f32, i32, i64, u32, u64),
divide::Evaluate,
inputs[0].get_element_type(),
inputs[0],
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/op/multiply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool Multiply::evaluate(TensorVector& outputs, const TensorVector& inputs) const
this,
outputs,
inputs,
OV_PP_ET_LIST(f32, f64, i8, i32, i64, u8, u32, u64),
OV_PP_ET_LIST(f32, f64, i32, i64, u32, u64),
multiply::Evaluate,
inputs[0].get_element_type(),
inputs[0],
Expand Down
30 changes: 0 additions & 30 deletions src/plugins/intel_cpu/src/infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,36 +558,6 @@ void SyncInferRequest::init_tensor(const std::size_t& port_index, const ov::ISyn
tensor = ov::make_tensor(model_prec, tensor_shape);
}
ov::ISyncInferRequest::set_tensor(port, tensor);
} else {
const auto& tensor_shape = tensor->get_shape();
const bool isDynamic = port_shape.is_dynamic();
// Static shape case is enough information that shapes are incompatible to throw exception
// but in dynamic shape case we also need to handle following corner case:
// on tensor initialization stage we create empty tensor with dimensions equal 0
// so if we have tensor with all zero dimension we mustn't throw exception
if (!port_shape.compatible(ov::PartialShape(tensor_shape)) &&
(!isDynamic || static_cast<int64_t>(tensor_shape.size()) != port_shape.rank().get_length() ||
std::any_of(tensor_shape.begin(), tensor_shape.end(), [](const size_t& dims) {
return dims != 0;
}))) {
OPENVINO_THROW("ParameterMismatch: model input and output use the same index: ",
port_index,
", but expect tensors with different shapes. Input shape: ",
ov::PartialShape(tensor_shape),
", output shape: ",
port_shape);
}

const auto netOutPrc = port.get_element_type();
if (netOutPrc != tensor->get_element_type()) {
OPENVINO_THROW("ParameterMismatch: model input and output use the same index: ",
port_index,
" but expect tensor with different precision: ",
tensor->get_element_type(),
" for input and ",
netOutPrc,
" for output.");
}
}
m_outputs[port_index] = tensor;
if (!port_shape.is_dynamic() && !m_output_external_ptr.count(port_index)) {
Expand Down
27 changes: 25 additions & 2 deletions src/plugins/intel_gpu/src/graph/layout_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,32 @@ bool layout_optimizer::should_select_b_fs_yx_fsv16_layout(convolution_node const
auto current_conv_partially_supports_layout = convolution_b_fs_yx_fsv16_opt(input_layout, output_layout, weights_layout, prim, true);
auto may_use_weak_restrictions = is_prev_conv_node_supports_layout || weak_restriction_cond;

return ((_optimization_attributes.b_fs_yx_fsv16_network) &&
std::function<bool(const program_node&, size_t, size_t)> need_heavy_reorder = [&](const program_node& node, size_t cur_depth, size_t max_depth) {
if (cur_depth > max_depth) return false;
if (node.is_type<reorder>()) {
for (auto& reorder_user : node.get_users()) {
if (reorder_user->is_type<reshape>()) {
for (auto& reshape_user : reorder_user->get_users()) {
// Meteor Lake showed planar format Convolution without Reorder is better than
// blocked format Convolution in case Reorder is larger than [1, 512, 128, 128].
if (reshape_user->is_type<mvn>() && node.get_output_layout().get_linear_size() > 8300000) {
GPU_DEBUG_LOG << node.id() << ": " << node.get_output_layout().to_short_string() << " -> heavy reorder" << std::endl;
return true;
}
}
}
}
}
bool res = false;
for (const auto& usr : node.get_users()) {
res |= need_heavy_reorder(*usr, cur_depth + 1, max_depth);
}
return res;
};

return (((_optimization_attributes.b_fs_yx_fsv16_network) &&
(current_conv_supports_layout || (may_use_weak_restrictions && current_conv_partially_supports_layout))) ||
input_layout.format == format::b_fs_yx_fsv16;
input_layout.format == format::b_fs_yx_fsv16) && !need_heavy_reorder(reinterpret_cast<program_node const&>(node), 0, 3);
}

bool layout_optimizer::convolution_b_fs_zyx_fsv16_opt(const layout& input_layout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
if (!device_info.supports_immad)
manager.register_pass<ov::intel_gpu::BroadcastReshapeMatmulFusion>();

const size_t zp_pad_size = 32;
const size_t zp_pad_size = device_info.supports_immad ? 16 : 32;
manager.register_pass<ov::intel_gpu::BroadcastAndPadZeroPointBuffers>(zp_pad_size);

// This is supposed to be the last pass to ensure that we don't have name collisions until
Expand Down
42 changes: 42 additions & 0 deletions src/plugins/template/backend/ops/divide.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/reference/divide.hpp"

#include "evaluate_node.hpp"

template <ov::element::Type_t ET>
bool evaluate(const std::shared_ptr<ov::op::v1::Divide>& op,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
using T = ov::fundamental_type_for<ET>;
ov::reference::divide(inputs[0].data<const T>(),
inputs[1].data<const T>(),
outputs[0].data<T>(),
inputs[0].get_shape(),
inputs[1].get_shape(),
op->get_autob(),
op->is_pythondiv());
return true;
}

template <>
bool evaluate_node<ov::op::v1::Divide>(std::shared_ptr<ov::Node> node,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
const auto& element_type = node->get_output_element_type(0);

switch (element_type) {
case ov::element::i8:
return evaluate<ov::element::i8>(ov::as_type_ptr<ov::op::v1::Divide>(node), outputs, inputs);
case ov::element::i16:
return evaluate<ov::element::i16>(ov::as_type_ptr<ov::op::v1::Divide>(node), outputs, inputs);
case ov::element::u8:
return evaluate<ov::element::u8>(ov::as_type_ptr<ov::op::v1::Divide>(node), outputs, inputs);
case ov::element::u16:
return evaluate<ov::element::u16>(ov::as_type_ptr<ov::op::v1::Divide>(node), outputs, inputs);
default:
OPENVINO_THROW("Unhandled data type ", element_type, " in evaluate_node()");
}
}
9 changes: 6 additions & 3 deletions src/plugins/template/backend/ops/multiply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ template <ov::element::Type_t ET>
bool evaluate(const std::shared_ptr<ov::op::v1::Multiply>& op,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
using T = typename ov::element_type_traits<ET>::value_type;
using T = ov::fundamental_type_for<ET>;
ov::reference::multiply(inputs[0].data<const T>(),
inputs[1].data<const T>(),
outputs[0].data<T>(),
ov::shape_size(inputs[0].get_shape()));
inputs[0].get_shape(),
inputs[1].get_shape(),
op->get_autob());

return true;
}

Expand All @@ -34,6 +37,6 @@ bool evaluate_node<ov::op::v1::Multiply>(std::shared_ptr<ov::Node> node,
case ov::element::u16:
return evaluate<ov::element::u16>(ov::as_type_ptr<ov::op::v1::Multiply>(node), outputs, inputs);
default:
OPENVINO_THROW("Unhandled data type ", node->get_element_type().get_type_name(), " in evaluate_node()");
OPENVINO_THROW("Unhandled data type ", element_type, " in evaluate_node()");
}
}
4 changes: 4 additions & 0 deletions src/plugins/template/backend/ops/ops_evaluates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ extern template bool evaluate_node<ov::op::v1::DeformablePSROIPooling>(std::shar
ov::TensorVector& outputs,
const ov::TensorVector& inputs);

extern template bool evaluate_node<ov::op::v1::Divide>(std::shared_ptr<ov::Node> node,
ov::TensorVector& outputs,
const ov::TensorVector& inputs);

extern template bool evaluate_node<ov::op::v1::Equal>(std::shared_ptr<ov::Node> node,
ov::TensorVector& outputs,
const ov::TensorVector& inputs);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/template/backend/opset_int_tbl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ _OPENVINO_OP_REG(ConvertLike, op::v1)
_OPENVINO_OP_REG(Convolution, op::v1)
_OPENVINO_OP_REG(ConvolutionBackpropData, op::v1)
_OPENVINO_OP_REG(DeformablePSROIPooling, op::v1)
_OPENVINO_OP_REG(Divide, op::v1)
_OPENVINO_OP_REG(Equal, op::v1)
_OPENVINO_OP_REG(Greater, op::v1)
_OPENVINO_OP_REG(GroupConvolution, op::v1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ std::vector<DivideRoundingParams> generateParamsForDivideCppRoundingInt32() {
}

std::vector<DivideParams> generateCombinedParamsForDivide() {
const std::vector<std::vector<DivideParams>> allTypeParams{generateParamsForDivide<element::Type_t::f32>(),
const std::vector<std::vector<DivideParams>> allTypeParams{generateParamsForDivide<element::Type_t::i8>(),
generateParamsForDivide<element::Type_t::u8>(),
generateParamsForDivide<element::Type_t::f32>(),
generateParamsForDivide<element::Type_t::f16>(),
generateParamsForDivide<element::Type_t::bf16>(),
generateParamsForDivide<element::Type_t::i64>(),
Expand Down
113 changes: 84 additions & 29 deletions src/plugins/template/tests/functional/op_reference/multiply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,18 @@ template <element::Type_t IN_ET>
std::vector<MultiplyParams> generateParamsForMultiply() {
using T = typename element_type_traits<IN_ET>::value_type;

std::vector<MultiplyParams> params{
MultiplyParams(ov::PartialShape{2, 2},
ov::PartialShape{2, 2},
IN_ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{5, 6, 7, 8},
std::vector<T>{5, 12, 21, 32}),
MultiplyParams(
ov::PartialShape{3, 2, 1},
ov::PartialShape{1, 6},
IN_ET,
std::vector<T>{12, 24, 36, 48, 60, 72},
std::vector<T>{1, 2, 3, 4, 6, 1},
std::vector<T>{12, 24, 36, 48, 72, 12, 24, 48, 72, 96, 144, 24, 36, 72, 108, 144, 216, 36,
48, 96, 144, 192, 288, 48, 60, 120, 180, 240, 360, 60, 72, 144, 216, 288, 432, 72}),
MultiplyParams(ov::PartialShape{1},
ov::PartialShape{1},
IN_ET,
std::vector<T>{2},
std::vector<T>{8},
std::vector<T>{16})};
std::vector<MultiplyParams> params{MultiplyParams(ov::PartialShape{2, 2},
ov::PartialShape{2, 2},
IN_ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{5, 6, 7, 8},
std::vector<T>{5, 12, 21, 32}),
MultiplyParams(ov::PartialShape{1},
ov::PartialShape{1},
IN_ET,
std::vector<T>{2},
std::vector<T>{8},
std::vector<T>{16})};
return params;
}

Expand All @@ -115,15 +106,79 @@ std::vector<MultiplyParams> generateParamsForMultiplyFloat() {
return params;
}

template <element::Type_t IN_ET>
std::vector<MultiplyParams> generateParamsForMultiplyWithBroadcast() {
using T = typename element_type_traits<IN_ET>::value_type;

std::vector<MultiplyParams> params{MultiplyParams(
ov::PartialShape{3, 2, 1},
ov::PartialShape{1, 6},
IN_ET,
std::vector<T>{12, 24, 36, 48, 60, 72},
std::vector<T>{1, 2, 3, 4, 6, 1},
std::vector<T>{12, 24, 36, 48, 72, 12, 24, 48, 72, 96, 144, 24, 36, 72, 108, 144, 216, 36,
48, 96, 144, 192, 288, 48, 60, 120, 180, 240, 360, 60, 72, 144, 216, 288, 432, 72})};

return params;
}

template <>
std::vector<MultiplyParams> generateParamsForMultiplyWithBroadcast<element::Type_t::i8>() {
constexpr auto IN_ET = element::Type_t::i8;
using T = typename element_type_traits<IN_ET>::value_type;

std::vector<MultiplyParams> params{MultiplyParams(
ov::PartialShape{3, 2, 1},
ov::PartialShape{1, 6},
IN_ET,
std::vector<T>{-12, -6, 4, 14, 18, 20},
std::vector<T>{1, 2, 3, 4, 6, 1},
std::vector<T>{-12, -24, -36, -48, -72, -12, -6, -12, -18, -24, -36, -6, 4, 8, 12, 16, 24, 4,
14, 28, 42, 56, 84, 14, 18, 36, 54, 72, 108, 18, 20, 40, 60, 80, 120, 20})};

return params;
}

template <>
std::vector<MultiplyParams> generateParamsForMultiplyWithBroadcast<element::Type_t::u8>() {
constexpr auto IN_ET = element::Type_t::u8;
using T = typename element_type_traits<IN_ET>::value_type;

std::vector<MultiplyParams> params{MultiplyParams(
ov::PartialShape{3, 2, 1},
ov::PartialShape{1, 6},
IN_ET,
std::vector<T>{12, 24, 36, 38, 40, 42},
std::vector<T>{1, 2, 3, 4, 6, 1},
std::vector<T>{12, 24, 36, 48, 72, 12, 24, 48, 72, 96, 144, 24, 36, 72, 108, 144, 216, 36,
38, 76, 114, 152, 228, 38, 40, 80, 120, 160, 240, 40, 42, 84, 126, 168, 252, 42})};

return params;
}

std::vector<MultiplyParams> generateCombinedParamsForMultiply() {
const std::vector<std::vector<MultiplyParams>> allTypeParams{generateParamsForMultiply<element::Type_t::f32>(),
generateParamsForMultiply<element::Type_t::f64>(),
generateParamsForMultiply<element::Type_t::f16>(),
generateParamsForMultiply<element::Type_t::bf16>(),
generateParamsForMultiply<element::Type_t::i64>(),
generateParamsForMultiply<element::Type_t::i32>(),
generateParamsForMultiply<element::Type_t::u64>(),
generateParamsForMultiply<element::Type_t::u32>()};
const std::vector<std::vector<MultiplyParams>> allTypeParams{
generateParamsForMultiplyWithBroadcast<element::Type_t::i8>(),
generateParamsForMultiplyWithBroadcast<element::Type_t::u8>(),
generateParamsForMultiplyWithBroadcast<element::Type_t::f32>(),
generateParamsForMultiplyWithBroadcast<element::Type_t::f64>(),
generateParamsForMultiplyWithBroadcast<element::Type_t::f16>(),
generateParamsForMultiplyWithBroadcast<element::Type_t::bf16>(),
generateParamsForMultiplyWithBroadcast<element::Type_t::i64>(),
generateParamsForMultiplyWithBroadcast<element::Type_t::i32>(),
generateParamsForMultiplyWithBroadcast<element::Type_t::u64>(),
generateParamsForMultiplyWithBroadcast<element::Type_t::u32>(),
generateParamsForMultiply<element::Type_t::i8>(),
generateParamsForMultiply<element::Type_t::u8>(),
generateParamsForMultiply<element::Type_t::f32>(),
generateParamsForMultiply<element::Type_t::f64>(),
generateParamsForMultiply<element::Type_t::f16>(),
generateParamsForMultiply<element::Type_t::bf16>(),
generateParamsForMultiply<element::Type_t::i64>(),
generateParamsForMultiply<element::Type_t::i32>(),
generateParamsForMultiply<element::Type_t::u64>(),
generateParamsForMultiply<element::Type_t::u32>(),
};

std::vector<MultiplyParams> combinedParams;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include "shared_test_classes/subgraph/parameter_result.hpp"
#include "openvino/runtime/tensor.hpp"

namespace ov {
namespace test {
Expand All @@ -13,5 +14,24 @@ TEST_P(ParameterResultSubgraphTest, Inference) {
run();
}

TEST_P(ParameterResultSubgraphTest, CheckSharedTensor) {
ov::test::InputShape input_shape;
std::tie(input_shape, targetDevice) = this->GetParam();

ov::Shape shape = input_shape.second[0];
auto input = ov::Tensor(ov::element::f32, shape);

// Load model
ov::Core core;
auto compiled_model = core.compile_model(function, targetDevice);

// Infer
auto infer_req = compiled_model.create_infer_request();
infer_req.set_input_tensor(input);
infer_req.infer();

ASSERT_EQ(infer_req.get_input_tensor().data(), infer_req.get_output_tensor().data());
}

} // namespace test
} // namespace ov

0 comments on commit b601124

Please sign in to comment.