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
f277e1c2
Commit
f277e1c2
authored
Aug 07, 2018
by
Jaikrishnan Menon
Committed by
Scott Cyphers
Aug 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DEX Micro-optimizations: Use the mapped-value reference capture idiom everywhere (#1352)
parent
4efcb76e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
24 deletions
+56
-24
cpu_external_function.cpp
src/ngraph/runtime/cpu/cpu_external_function.cpp
+50
-22
cpu_external_function.hpp
src/ngraph/runtime/cpu/cpu_external_function.hpp
+6
-2
No files found.
src/ngraph/runtime/cpu/cpu_external_function.cpp
View file @
f277e1c2
...
...
@@ -1129,7 +1129,9 @@ void runtime::cpu::CPU_ExternalFunction::build()
for
(
size_t
i
=
0
;
i
<
param
->
get_output_size
();
++
i
)
{
shared_ptr
<
descriptor
::
TensorView
>
tv
=
param
->
get_output_tensor_view
(
i
);
function_input_index
[
tv
->
get_tensor
().
get_name
()]
=
arg_index
;
function_input_index
.
emplace_back
(
tensor_data
[
tv
->
get_tensor
().
get_name
()],
arg_index
,
tensor_stale
[
tv
->
get_tensor
().
get_name
()]);
arg_index
++
;
}
}
...
...
@@ -1139,14 +1141,14 @@ void runtime::cpu::CPU_ExternalFunction::build()
{
shared_ptr
<
Node
>
op
=
m_function
->
get_output_op
(
i
);
shared_ptr
<
descriptor
::
TensorView
>
tv
=
op
->
get_output_tensor_view
();
function_output_index
[
tv
->
get_tensor
().
get_name
()]
=
i
;
function_output_index
.
emplace_back
(
tensor_data
[
tv
->
get_tensor
().
get_name
()],
i
)
;
auto
res
=
std
::
dynamic_pointer_cast
<
ngraph
::
op
::
Result
>
(
op
);
if
(
!
res
->
needs_copy
())
{
shared_ptr
<
descriptor
::
TensorView
>
itv
=
res
->
get_inputs
().
at
(
0
).
get_output
().
get_tensor_view
();
function_output_index
[
itv
->
get_tensor
().
get_name
()]
=
i
;
function_output_index
.
emplace_back
(
tensor_data
[
itv
->
get_tensor
().
get_name
()],
i
)
;
}
}
...
...
@@ -1159,7 +1161,8 @@ void runtime::cpu::CPU_ExternalFunction::build()
{
for
(
auto
tensor
:
node
->
liveness_new_list
)
{
intermediates_offsets
[
tensor
->
get_name
()]
=
tensor
->
get_pool_offset
();
intermediates_offsets
.
emplace_back
(
tensor_data
[
tensor
->
get_name
()],
tensor
->
get_pool_offset
());
}
}
}
...
...
@@ -1212,21 +1215,47 @@ void runtime::cpu::CPU_ExternalFunction::build()
handler
->
second
(
this
,
node
.
get
(),
in
,
out
);
bool
disable_caching
=
computes_result
(
node
.
get
())
||
possibly_overwritten
(
node
.
get
());
auto
enable
=
[
&
,
in_names
,
out_names
,
disable_caching
](
CPURuntimeContext
*
ctx
)
->
bool
{
bool
en
=
false
;
for
(
const
auto
&
name
:
in_names
)
{
if
(
tensor_stale
[
name
]
||
disable_caching
)
vector
<
reference_wrapper
<
bool
>>
in_stale
,
out_stale
;
for
(
const
auto
&
name
:
in_names
)
{
in_stale
.
emplace_back
(
tensor_stale
[
name
]);
}
for
(
const
auto
&
name
:
out_names
)
{
out_stale
.
emplace_back
(
tensor_stale
[
name
]);
}
function
<
bool
(
CPURuntimeContext
*
)
>
enable
;
if
(
disable_caching
)
{
enable
=
[
in_stale
,
out_stale
](
CPURuntimeContext
*
ctx
)
->
bool
{
for
(
auto
&
stale
:
out_stale
)
{
en
=
true
;
stale
.
get
()
=
true
;
}
}
for
(
const
auto
&
name
:
out_names
)
{
tensor_stale
[
name
]
=
en
;
}
return
en
;
};
return
true
;
};
}
else
{
enable
=
[
in_stale
,
out_stale
](
CPURuntimeContext
*
ctx
)
->
bool
{
bool
en
=
false
;
for
(
const
auto
&
stale
:
in_stale
)
{
if
(
stale
)
{
en
=
true
;
break
;
}
}
for
(
auto
&
stale
:
out_stale
)
{
stale
.
get
()
=
en
;
}
return
en
;
};
}
enables
.
emplace_back
(
make_pair
(
enable
,
functors
.
size
()
-
functor_count
));
enable_nodename_list
.
emplace_back
(
make_pair
(
enable
,
node
->
get_name
()));
...
...
@@ -1240,20 +1269,19 @@ void runtime::cpu::CPU_ExternalFunction::build()
{
for
(
auto
&
p
:
intermediates_offsets
)
{
tensor_data
[
p
.
first
]
=
static_cast
<
uint8_t
*>
(
ctx
->
memory_buffers
[
0
]
->
get_ptr
())
+
p
.
second
;
p
.
first
.
get
()
=
static_cast
<
uint8_t
*>
(
ctx
->
memory_buffers
[
0
]
->
get_ptr
())
+
p
.
second
;
}
}
for
(
const
auto
&
p
:
function_input_index
)
{
tensor_data
[
p
.
first
]
=
inputs
[
p
.
second
];
tensor_stale
[
p
.
first
]
=
ctx
->
p_en
[
p
.
second
];
get
<
0
>
(
p
).
get
()
=
inputs
[
get
<
1
>
(
p
)
];
get
<
2
>
(
p
).
get
()
=
ctx
->
p_en
[
get
<
1
>
(
p
)
];
}
for
(
const
auto
&
p
:
function_output_index
)
{
tensor_data
[
p
.
first
]
=
outputs
[
p
.
second
];
p
.
first
.
get
()
=
outputs
[
p
.
second
];
}
auto
functor
=
functors
.
begin
();
...
...
src/ngraph/runtime/cpu/cpu_external_function.hpp
View file @
f277e1c2
...
...
@@ -24,6 +24,7 @@
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
#include "ngraph/codegen/code_writer.hpp"
...
...
@@ -178,8 +179,11 @@ namespace ngraph
executor
;
std
::
unordered_map
<
std
::
string
,
void
*>
tensor_data
;
std
::
unordered_map
<
std
::
string
,
bool
>
tensor_stale
;
std
::
unordered_map
<
std
::
string
,
size_t
>
intermediates_offsets
;
std
::
unordered_map
<
std
::
string
,
size_t
>
function_input_index
,
function_output_index
;
std
::
list
<
std
::
pair
<
std
::
reference_wrapper
<
void
*>
,
size_t
>>
intermediates_offsets
;
std
::
list
<
std
::
tuple
<
std
::
reference_wrapper
<
void
*>
,
size_t
,
std
::
reference_wrapper
<
bool
>>>
function_input_index
;
std
::
list
<
std
::
pair
<
std
::
reference_wrapper
<
void
*>
,
size_t
>>
function_output_index
;
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
CPU_ExternalFunction
>>
callees
;
bool
m_is_built
;
bool
m_direct_execution
;
...
...
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