Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit eec1922

Browse files
jmenondiyessi
authored andcommitted
CPU: Eliminate slices (#849)
1 parent 6e1b605 commit eec1922

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/ngraph/runtime/cpu/pass/cpu_nop_elimination.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "cpu_nop_elimination.hpp"
2424
#include "ngraph/op/convert.hpp"
2525
#include "ngraph/op/pad.hpp"
26+
#include "ngraph/op/slice.hpp"
2627
#include "ngraph/op/sum.hpp"
2728

2829
#define TI(x) std::type_index(typeid(x))
@@ -64,12 +65,24 @@ HANDLER_DECL(eliminate_convert)
6465
return false;
6566
}
6667

68+
HANDLER_DECL(eliminate_slice)
69+
{
70+
auto slice = std::dynamic_pointer_cast<ngraph::op::Slice>(node);
71+
if (slice->get_input_shape(0) == slice->get_output_shape(0))
72+
{
73+
function->replace_node(node, node->get_input_op(0));
74+
return true;
75+
}
76+
return false;
77+
}
78+
6779
static const std::unordered_map<std::type_index,
6880
std::function<bool(const std::shared_ptr<ngraph::Function>&,
6981
const std::shared_ptr<ngraph::Node>&)>>
7082
dispatcher{{TI(ngraph::op::Pad), &eliminate_pad},
7183
{TI(ngraph::op::Sum), &eliminate_sum},
72-
{TI(ngraph::op::Convert), &eliminate_convert}};
84+
{TI(ngraph::op::Convert), &eliminate_convert},
85+
{TI(ngraph::op::Slice), &eliminate_slice}};
7386

7487
bool ngraph::runtime::cpu::pass::CPUNopElimination::run_on_function(
7588
std::shared_ptr<ngraph::Function> function)

0 commit comments

Comments
 (0)