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
268853d0
Commit
268853d0
authored
Jul 13, 2018
by
Louis Feng
Committed by
Jayaram Bobba
Jul 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reshape inplace without copy data if possible. (#1206)
parent
4659d60d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
2 deletions
+40
-2
reshape.cpp
src/ngraph/op/reshape.cpp
+5
-0
reshape.hpp
src/ngraph/op/reshape.hpp
+2
-0
cpu_emitter.cpp
src/ngraph/runtime/cpu/cpu_emitter.cpp
+9
-0
cpu_assignment.cpp
src/ngraph/runtime/cpu/pass/cpu_assignment.cpp
+24
-2
No files found.
src/ngraph/op/reshape.cpp
View file @
268853d0
...
...
@@ -67,6 +67,11 @@ op::Reshape::Reshape(const shared_ptr<Node>& arg,
"dimensions for reshape"
);
}
if
(
!
std
::
is_sorted
(
m_input_order
.
begin
(),
m_input_order
.
end
()))
{
m_is_transpose
=
true
;
}
set_value_type_checked
(
input
.
get_element_type
(),
m_output_shape
);
}
...
...
src/ngraph/op/reshape.hpp
View file @
268853d0
...
...
@@ -78,12 +78,14 @@ namespace ngraph
const
AxisVector
&
get_input_order
()
const
{
return
m_input_order
;
}
/// \return The shape of the output tensor.
const
Shape
&
get_output_shape
()
const
{
return
m_output_shape
;
}
bool
get_is_transpose
()
const
{
return
m_is_transpose
;
}
protected
:
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
const
NodeVector
&
deltas
)
override
;
const
AxisVector
m_input_order
;
const
Shape
m_output_shape
;
bool
m_is_transpose
{
false
};
};
}
}
src/ngraph/runtime/cpu/cpu_emitter.cpp
View file @
268853d0
...
...
@@ -1652,6 +1652,15 @@ namespace ngraph
void
CPU_Emitter
::
EMITTER_DECL
(
ngraph
::
op
::
Reshape
)
{
auto
reshape
=
static_cast
<
const
ngraph
::
op
::
Reshape
*>
(
node
);
auto
annotation
=
reshape
->
get_op_annotations
();
if
(
annotation
&&
annotation
->
get_in_place_oi_pairs
().
size
()
>
0
&&
out
[
0
].
get_name
()
==
args
[
0
].
get_name
())
{
writer
.
block_begin
();
writer
<<
"// Stride change only, skipping.
\n
"
;
writer
.
block_end
();
return
;
}
writer
.
block_begin
();
#if USE_EIGEN_CORE_INLINE == 1
auto
arg_shape
=
args
[
0
].
get_shape
();
...
...
src/ngraph/runtime/cpu/pass/cpu_assignment.cpp
View file @
268853d0
...
...
@@ -563,6 +563,30 @@ namespace ngraph
auto
axis_order
=
reshape
->
get_input_order
();
bool
flag
=
true
;
auto
op_annotations
=
std
::
make_shared
<
ngraph
::
runtime
::
cpu
::
CPUOpAnnotations
>
();
auto
users
=
reshape
->
get_users
();
auto
arg
=
reshape
->
get_argument
(
0
);
// we need to copy input data if reshape modifies the data or inputs are
// not in the memory pool, or has output users.
bool
need_copy
=
reshape
->
get_is_transpose
()
||
arg
->
is_parameter
()
||
arg
->
is_constant
();
for
(
auto
n
=
users
.
begin
();
!
need_copy
&&
n
!=
users
.
end
();
++
n
)
{
if
((
*
n
)
->
is_output
())
{
need_copy
=
true
;
}
}
if
(
!
need_copy
)
{
// map output to the input memory
std
::
map
<
size_t
,
size_t
>
oi_pairs
=
{{
0
,
0
}};
op_annotations
->
set_in_place_oi_pairs
(
oi_pairs
);
reshape
->
set_op_annotations
(
op_annotations
);
}
// Use Eigen for 3D
if
(
node
->
get_input_element_type
(
0
)
==
element
::
f32
&&
arg0_shape
.
size
()
<
TENSOR_MAX_DIMS
&&
arg0_shape
.
size
()
>
3
&&
...
...
@@ -579,8 +603,6 @@ namespace ngraph
if
(
flag
)
{
auto
op_annotations
=
std
::
make_shared
<
ngraph
::
runtime
::
cpu
::
CPUOpAnnotations
>
();
op_annotations
->
set_mkldnn_op
(
true
);
reshape
->
set_op_annotations
(
op_annotations
);
}
...
...
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