Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
4b41aca2
Commit
4b41aca2
authored
Mar 07, 2018
by
Jai Menon
Committed by
Scott Cyphers
Mar 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CPU: No-op elimination pass (#603)
parent
ad58cb29
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
0 deletions
+104
-0
CMakeLists.txt
src/ngraph/CMakeLists.txt
+1
-0
cpu_external_function.cpp
src/ngraph/runtime/cpu/cpu_external_function.cpp
+2
-0
cpu_nop_elimination.cpp
src/ngraph/runtime/cpu/pass/cpu_nop_elimination.cpp
+64
-0
cpu_nop_elimination.hpp
src/ngraph/runtime/cpu/pass/cpu_nop_elimination.hpp
+37
-0
No files found.
src/ngraph/CMakeLists.txt
View file @
4b41aca2
...
...
@@ -190,6 +190,7 @@ if (NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR AND
runtime/cpu/pass/cpu_assignment.cpp
runtime/cpu/pass/cpu_fusion.cpp
runtime/cpu/pass/cpu_layout.cpp
runtime/cpu/pass/cpu_nop_elimination.cpp
)
# LLVM binary builds are typically built without RTTI
# The built-in headers are in a version-specific directory
...
...
src/ngraph/runtime/cpu/cpu_external_function.cpp
View file @
4b41aca2
...
...
@@ -113,6 +113,7 @@
#include "ngraph/runtime/cpu/pass/cpu_assignment.hpp"
#include "ngraph/runtime/cpu/pass/cpu_fusion.hpp"
#include "ngraph/runtime/cpu/pass/cpu_layout.hpp"
#include "ngraph/runtime/cpu/pass/cpu_nop_elimination.hpp"
#ifdef NGRAPH_DISTRIBUTED
#include "ngraph/ops/allreduce.hpp"
...
...
@@ -270,6 +271,7 @@ void runtime::cpu::CPU_ExternalFunction::compile()
ngraph
::
pass
::
Manager
pass_manager
;
pass_manager
.
register_pass
<
runtime
::
cpu
::
pass
::
CPUNopElimination
>
();
pass_manager
.
register_pass
<
ngraph
::
pass
::
CoreFusion
>
();
pass_manager
.
register_pass
<
runtime
::
cpu
::
pass
::
CPUFusion
>
();
pass_manager
.
register_pass
<
runtime
::
cpu
::
pass
::
CPUAssignment
>
(
this
);
...
...
src/ngraph/runtime/cpu/pass/cpu_nop_elimination.cpp
0 → 100644
View file @
4b41aca2
/*******************************************************************************
* Copyright 2018 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#include <memory>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include "cpu_nop_elimination.hpp"
#include "ngraph/ops/pad.hpp"
#define TI(x) std::type_index(typeid(x))
#define HANDLER_DECL(x) \
static bool x(const std::shared_ptr<ngraph::Function>& function, \
const std::shared_ptr<ngraph::Node>& node)
HANDLER_DECL
(
eliminate_pad
)
{
auto
pad
=
std
::
dynamic_pointer_cast
<
ngraph
::
op
::
Pad
>
(
node
);
if
(
pad
->
get_input_shape
(
0
)
==
pad
->
get_output_shape
(
0
))
{
function
->
replace_node
(
node
,
node
->
get_input_op
(
0
));
return
true
;
}
return
false
;
}
static
const
std
::
unordered_map
<
std
::
type_index
,
std
::
function
<
bool
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
,
const
std
::
shared_ptr
<
ngraph
::
Node
>&
)
>>
dispatcher
{{
TI
(
ngraph
::
op
::
Pad
),
&
eliminate_pad
}};
bool
ngraph
::
runtime
::
cpu
::
pass
::
CPUNopElimination
::
run_on_function
(
std
::
shared_ptr
<
ngraph
::
Function
>
function
)
{
bool
clobbered
=
false
;
for
(
const
auto
&
n
:
function
->
get_ops
())
{
// Work around a warning [-Wpotentially-evaluated-expression]
const
Node
&
node
=
*
n
;
auto
handler
=
dispatcher
.
find
(
TI
(
node
));
if
(
handler
!=
dispatcher
.
end
())
{
clobbered
=
handler
->
second
(
function
,
n
)
||
clobbered
;
}
}
return
clobbered
;
}
src/ngraph/runtime/cpu/pass/cpu_nop_elimination.hpp
0 → 100644
View file @
4b41aca2
/*******************************************************************************
* Copyright 2018 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#pragma once
#include "ngraph/pass/pass.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
cpu
{
namespace
pass
{
class
CPUNopElimination
:
public
ngraph
::
pass
::
FunctionPass
{
public
:
bool
run_on_function
(
std
::
shared_ptr
<
ngraph
::
Function
>
function
)
override
;
};
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment