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
b025ac0e
Commit
b025ac0e
authored
Nov 20, 2018
by
Amy Zhuang
Committed by
Michał Karzyński
Nov 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not change the offset of the slice when processing in place (#2063)
parent
599fb3e7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
45 deletions
+58
-45
cpu_emitter.cpp
src/ngraph/runtime/cpu/cpu_emitter.cpp
+4
-6
cpu_external_function.cpp
src/ngraph/runtime/cpu/cpu_external_function.cpp
+54
-39
No files found.
src/ngraph/runtime/cpu/cpu_emitter.cpp
View file @
b025ac0e
...
...
@@ -1048,15 +1048,14 @@ namespace ngraph
{
writer
<<
"if ("
<<
args
[
i
].
get_name
()
<<
" < "
<<
out
[
0
].
get_name
()
<<
" || "
<<
args
[
i
].
get_name
()
<<
" >= "
<<
out
[
0
].
get_name
()
<<
" + "
<<
out
[
0
].
get_size
()
*
out
[
0
].
get_element_type
().
size
()
<<
")
\n
"
;
<<
" + "
<<
out
[
0
].
get_size
()
<<
")
\n
"
;
writer
.
block_begin
();
writer
<<
"memcpy("
<<
out
[
0
].
get_name
()
<<
" + "
<<
offset
<<
", "
<<
args
[
i
].
get_name
()
<<
", "
<<
args
[
i
].
get_size
()
*
out
[
0
].
get_element_type
().
size
()
<<
");
\n
"
;
writer
.
block_end
();
offset
+=
args
[
i
].
get_size
()
*
out
[
0
].
get_element_type
().
size
()
;
offset
+=
args
[
i
].
get_size
();
}
return
;
}
...
...
@@ -2025,11 +2024,10 @@ namespace ngraph
}
writer
<<
"if ("
<<
out
[
0
].
get_name
()
<<
" < "
<<
args
[
0
].
get_name
()
<<
" || "
<<
out
[
0
].
get_name
()
<<
" >= "
<<
args
[
0
].
get_name
()
<<
" + "
<<
args
[
0
].
get_size
()
*
out
[
0
].
get_element_type
().
size
()
<<
")
\n
"
;
<<
" + "
<<
args
[
0
].
get_size
()
<<
")
\n
"
;
writer
.
block_begin
();
writer
<<
"memcpy("
<<
out
[
0
].
get_name
()
<<
", "
<<
args
[
0
].
get_name
()
<<
" + "
<<
start
*
out
[
0
].
get_element_type
().
size
()
<<
", "
<<
" + "
<<
start
<<
", "
<<
out
[
0
].
get_size
()
*
out
[
0
].
get_element_type
().
size
()
<<
");
\n
"
;
writer
.
block_end
();
return
;
...
...
src/ngraph/runtime/cpu/cpu_external_function.cpp
View file @
b025ac0e
...
...
@@ -668,9 +668,6 @@ using namespace ngraph::runtime;
}
}
// In place slice optimization
process_in_place_slice
(
ordered_ops
);
// In place concatenation optimization
process_in_place_concat
(
ordered_ops
);
...
...
@@ -693,19 +690,6 @@ using namespace ngraph::runtime;
writer
<<
"size_t pool_base_ptr = (size_t) ctx->memory_buffers["
<<
m_memory_buffer_sizes
.
size
()
-
1
<<
"]->get_ptr();
\n
"
;
writer
<<
"
\n
"
;
// Add temporaries to the variable name map
for
(
shared_ptr
<
Node
>
node
:
ordered_ops
)
{
for
(
descriptor
::
Tensor
*
tensor
:
node
->
liveness_new_list
)
{
stringstream
ss
;
ss
<<
"(("
<<
tensor
->
get_element_type
().
c_type_string
()
<<
"*)(pool_base_ptr + "
<<
tensor
->
get_pool_offset
()
<<
"))"
;
m_variable_name_map
[
tensor
->
get_name
()]
=
ss
.
str
();
m_tensor_roles
[
tensor
->
get_name
()]
=
CPUTensorRole
::
INTERMEDIATE
;
}
}
}
writer
<<
"bool* t_en = (bool*)"
<<
current_function
->
get_name
()
<<
"_t_en;
\n
"
;
...
...
@@ -749,6 +733,28 @@ using namespace ngraph::runtime;
}
}
// In place slice optimization
process_in_place_slice
(
ordered_ops
);
if
(
temporaries_used
)
{
// Add temporaries to the variable name map
for
(
shared_ptr
<
Node
>
node
:
ordered_ops
)
{
for
(
descriptor
::
Tensor
*
tensor
:
node
->
liveness_new_list
)
{
stringstream
ss
;
ss
<<
"(("
<<
tensor
->
get_element_type
().
c_type_string
()
<<
"*)(pool_base_ptr + "
<<
tensor
->
get_pool_offset
()
<<
"))"
;
m_variable_name_map
[
tensor
->
get_name
()]
=
ss
.
str
();
if
(
m_tensor_roles
.
find
(
tensor
->
get_name
())
==
m_tensor_roles
.
end
())
{
m_tensor_roles
[
tensor
->
get_name
()]
=
CPUTensorRole
::
INTERMEDIATE
;
}
}
}
}
// Add outputs to the variable name map
for
(
size_t
i
=
0
;
i
<
current_function
->
get_output_size
();
++
i
)
{
...
...
@@ -1342,7 +1348,7 @@ void runtime::cpu::CPU_ExternalFunction::propagate_in_place_concat(
auto
old_offset
=
input_tensor
->
get_pool_offset
();
input_tensor
->
set_pool_offset
(
offset
);
NGRAPH_DEBUG
<<
"cpu_external_function, propagate: change offset, old offset is "
<<
"cpu_external_function, propagate: c
oncat, c
hange offset, old offset is "
<<
old_offset
<<
", new offset is "
<<
offset
<<
std
::
endl
;
offset
+=
input_tensor
->
size
();
if
(
auto
arg_concat
=
std
::
dynamic_pointer_cast
<
ngraph
::
op
::
Concat
>
(
arg
))
...
...
@@ -1368,11 +1374,17 @@ void runtime::cpu::CPU_ExternalFunction::process_in_place_slice(
auto
in_place_oi_pairs
=
op_annotations
->
get_in_place_oi_pairs
();
if
(
in_place_oi_pairs
.
size
()
>
0
)
{
auto
arg
=
slice
->
get_argumen
t
(
0
);
auto
input
=
slice
->
get_input_from
(
arg
);
auto
input
=
&
slice
->
get_inputs
().
a
t
(
0
);
auto
arg
=
input
->
get_output
().
get_node
(
);
auto
index
=
input
->
get_output
().
get_index
();
auto
input_node
=
std
::
dynamic_pointer_cast
<
ngraph
::
op
::
Op
>
(
arg
);
auto
input_tensor
=
&
input_node
->
get_output_tensor
(
index
);
if
(
m_tensor_roles
[
input_tensor
->
get_name
()]
==
CPUTensorRole
::
INPUT
)
{
NGRAPH_DEBUG
<<
"cpu_external_function: function input pointer passed to "
"slice, do not change offset."
;
continue
;
}
auto
offset
=
input_tensor
->
get_pool_offset
();
auto
lower_bounds
=
slice
->
get_lower_bounds
();
auto
start
=
0
,
accumulated
=
1
;
...
...
@@ -1387,7 +1399,7 @@ void runtime::cpu::CPU_ExternalFunction::process_in_place_slice(
auto
old_offset
=
output_tensor
->
get_pool_offset
();
output_tensor
->
set_pool_offset
(
offset
);
NGRAPH_DEBUG
<<
"cpu_external_function: change offset, old offset is "
NGRAPH_DEBUG
<<
"cpu_external_function:
slice,
change offset, old offset is "
<<
old_offset
<<
", new offset is "
<<
offset
<<
std
::
endl
;
}
}
...
...
@@ -1459,28 +1471,9 @@ void runtime::cpu::CPU_ExternalFunction::build()
// Build executor
// In place slice optimization
process_in_place_slice
(
m_function
->
get_ordered_ops
());
// In place concatenation optimization
process_in_place_concat
(
m_function
->
get_ordered_ops
());
// Intermediates
if
(
m_function
->
get_temporary_pool_size
())
{
m_memory_buffer_sizes
.
push_back
(
m_function
->
get_temporary_pool_size
());
for
(
auto
&
node
:
m_function
->
get_ordered_ops
())
{
for
(
auto
tensor
:
node
->
liveness_new_list
)
{
intermediates_offsets
.
emplace_back
(
tensor_data
[
tensor
->
get_name
()],
tensor
->
get_pool_offset
());
m_tensor_roles
[
tensor
->
get_name
()]
=
CPUTensorRole
::
INTERMEDIATE
;
}
}
}
// Constants
for
(
auto
&
node
:
m_function
->
get_ordered_ops
())
{
...
...
@@ -1509,6 +1502,28 @@ void runtime::cpu::CPU_ExternalFunction::build()
}
}
// In place slice optimization
process_in_place_slice
(
m_function
->
get_ordered_ops
());
// Intermediates
if
(
m_function
->
get_temporary_pool_size
())
{
m_memory_buffer_sizes
.
push_back
(
m_function
->
get_temporary_pool_size
());
for
(
auto
&
node
:
m_function
->
get_ordered_ops
())
{
for
(
auto
tensor
:
node
->
liveness_new_list
)
{
intermediates_offsets
.
emplace_back
(
tensor_data
[
tensor
->
get_name
()],
tensor
->
get_pool_offset
());
if
(
m_tensor_roles
.
find
(
tensor
->
get_name
())
==
m_tensor_roles
.
end
())
{
m_tensor_roles
[
tensor
->
get_name
()]
=
CPUTensorRole
::
INTERMEDIATE
;
}
}
}
}
// Outputs
for
(
size_t
i
=
0
;
i
<
m_function
->
get_output_size
();
++
i
)
{
...
...
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