forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,690 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (C) ß2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <ngraph/ngraph.hpp> | ||
#include <ngraph/pass/graph_rewrite.hpp> | ||
#include <ngraph/pattern/matcher.hpp> | ||
|
||
|
||
namespace ngraph { | ||
namespace snippets { | ||
namespace pass { | ||
|
||
class Markup : public ngraph::pass::FunctionPass { | ||
public: | ||
OPENVINO_RTTI("ConvolutionDecomposition", "0"); | ||
bool run_on_model(const std::shared_ptr<ngraph::Function>& m) override; | ||
}; | ||
|
||
} // namespace pass | ||
} // namespace snippets | ||
} // namespace ngraph |
27 changes: 27 additions & 0 deletions
27
src/common/snippets/include/snippets/roi_backprop/convolution.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <openvino/op/gather.hpp> | ||
#include <openvino/core/partial_shape.hpp> | ||
|
||
namespace ov { | ||
namespace op { | ||
namespace v1 { | ||
template <class ShapeType> | ||
void roi_backprop( | ||
const Convolution* op, | ||
const std::vector<ShapeType>& input_shapes, | ||
std::vector<ShapeType>& roi_shapes, | ||
std::vector<ov::Shape>& strides) { | ||
NODE_VALIDATION_CHECK(op, (input_shapes.size() == 2ul) && (roi_shapes.size() == 1)); | ||
|
||
// TODO: just to test | ||
// | ||
} | ||
|
||
} // namespace v1 | ||
} // namespace op | ||
} // namespace ov |
39 changes: 39 additions & 0 deletions
39
src/common/snippets/include/snippets/roi_backprop/gather_roi_backprop.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <openvino/op/gather.hpp> | ||
#include <openvino/core/partial_shape.hpp> | ||
|
||
namespace ov { | ||
namespace op { | ||
namespace v8 { | ||
template <class ShapeType> | ||
void roi_backprop( | ||
const Gather* op, | ||
const std::vector<ShapeType>& input_shapes, | ||
std::vector<ShapeType>& roi_shapes, | ||
std::vector<ov::Shape>& strides) { | ||
NODE_VALIDATION_CHECK(op, input_shapes.size() == 3); | ||
|
||
roi_shapes.resize(3ul); | ||
|
||
auto& roi_data = roi_shapes[0]; | ||
auto& data_shape = input_shapes[0]; | ||
if (auto constant = ov::as_type_ptr<ov::opset1::Constant>(op->get_input_node_shared_ptr(2))) { | ||
const auto axis_value = constant->cast_vector<int64_t>()[0]; | ||
roi_data = ov::Shape(data_shape.size(), 1); | ||
roi_data[axis_value] = data_shape[axis_value]; | ||
} else { | ||
roi_data = data_shape; | ||
} | ||
|
||
roi_shapes[1] = input_shapes[1]; | ||
roi_shapes[2] = input_shapes[2]; | ||
} | ||
|
||
} // namespace v8 | ||
} // namespace op | ||
} // namespace ov |
44 changes: 44 additions & 0 deletions
44
src/common/snippets/include/snippets/roi_backprop/max_pool.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <openvino/op/gather.hpp> | ||
#include <openvino/core/partial_shape.hpp> | ||
|
||
namespace ov { | ||
namespace op { | ||
namespace v1 { | ||
template <class ShapeType> | ||
void roi_backprop( | ||
const MaxPool* op, | ||
const std::vector<ShapeType>& input_shapes, | ||
std::vector<ShapeType>& roi_shapes, | ||
std::vector<ov::Shape>& strides) { | ||
NODE_VALIDATION_CHECK(op, (input_shapes.size() == 1ul) && (roi_shapes.size() == 1)); | ||
NODE_VALIDATION_CHECK(op, input_shapes[0].rank() == roi_shapes[0].rank()); | ||
|
||
// TODO: roi backpropagation: dynamic shape can be used | ||
// TODO: roi backpropagation: params are ignored | ||
|
||
const auto kernel = op->get_kernel(); | ||
auto roi_shape = roi_shapes[0]; | ||
auto shape_offset = input_shapes[0].size() - (kernel.size() + 2ul); | ||
for (auto i = 2ul; i < roi_shape.size() - shape_offset; ++i) { | ||
roi_shape[i] = roi_shape[i] * kernel[i - 2ul]; | ||
} | ||
roi_shapes[0] = roi_shape; | ||
|
||
const auto op_strides = op->get_strides(); | ||
auto strides0 = strides[0]; | ||
auto strides0_offset = input_shapes[0].size() - (op_strides.size() + 2ul); | ||
for (auto i = 2ul; i < strides0.size() - strides0_offset; ++i) { | ||
strides0[i] = strides0[i] * op_strides[i - 2ul]; | ||
} | ||
strides[0] = strides0; | ||
} | ||
|
||
} // namespace v1 | ||
} // namespace op | ||
} // namespace ov |
45 changes: 45 additions & 0 deletions
45
src/common/snippets/include/snippets/roi_backprop/roi_backprop.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <map> | ||
|
||
#include <ngraph/runtime/host_tensor.hpp> | ||
#include <openvino/core/core.hpp> | ||
#include <openvino/core/node.hpp> | ||
|
||
namespace ov { | ||
namespace snippets { | ||
|
||
class ROIBackprop { | ||
public: | ||
std::vector<ov::PartialShape> shapes; | ||
std::vector<ov::Shape> strides; | ||
}; | ||
|
||
void roi_backprop(ov::Node* op, | ||
const std::vector<ov::PartialShape>& input_shapes, | ||
const std::vector<ov::PartialShape>& cur_roi, | ||
const std::vector<ov::Shape>& cur_roi_strides, | ||
std::vector<ov::PartialShape>& new_roi, | ||
std::vector<ov::Shape>& new_roi_strides); | ||
|
||
using roi_map = std::map<ov::Node*, ROIBackprop>; | ||
roi_map get_roi_from_function(const std::shared_ptr<ov::Model>& m, const std::vector<ov::PartialShape>& start_roi); | ||
|
||
class BaseROIBackprop { | ||
public: | ||
BaseROIBackprop(std::shared_ptr<ov::Node> node) : node(node) {} | ||
virtual ROIBackprop infer_roi( | ||
const std::vector<ov::PartialShape>& input_shapes, | ||
const std::vector<ov::PartialShape>& cur_roi, | ||
const std::vector<ov::Shape>& cur_strides) = 0; | ||
|
||
protected: | ||
std::shared_ptr<ov::Node> node; | ||
}; | ||
|
||
std::shared_ptr<BaseROIBackprop> make_roi_backprop(const std::shared_ptr<ngraph::Node>& op); | ||
|
||
} // namespace snippets | ||
} // namespace ov |
21 changes: 21 additions & 0 deletions
21
src/common/snippets/include/snippets/roi_backprop/utils.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
#pragma once | ||
|
||
#include <openvino/core/validation_util.hpp> | ||
#include <openvino/opsets/opset1.hpp> | ||
|
||
template <class OpType, class ShapeType> | ||
void transparent_roi_backprop(const OpType* op, | ||
const std::vector<ShapeType>& input_shapes, | ||
const std::vector<ShapeType>& cur_roi, | ||
const std::vector<ov::Shape>& cur_strides, | ||
std::vector<ShapeType>& new_roi, | ||
std::vector<ov::Shape>& new_strides) { | ||
NODE_VALIDATION_CHECK(op, cur_roi.size() == 1, "Incorrect number of current roi shapes"); | ||
for (auto& roi_shape : new_roi) | ||
roi_shape = cur_roi[0]; | ||
|
||
new_strides = cur_strides; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.