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
c8d9c405
Commit
c8d9c405
authored
Nov 02, 2017
by
Jaikrishnan Menon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CPU: Start op::Reduce implementation and implement no-axes case
parent
3871a4f0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
0 deletions
+60
-0
emitter.cpp
src/ngraph/runtime/cpu/emitter.cpp
+58
-0
emitter.hpp
src/ngraph/runtime/cpu/emitter.hpp
+1
-0
external_function.cpp
src/ngraph/runtime/cpu/external_function.cpp
+1
-0
No files found.
src/ngraph/runtime/cpu/emitter.cpp
View file @
c8d9c405
...
...
@@ -26,6 +26,7 @@
#include "ngraph/ops/constant.hpp"
#include "ngraph/ops/function_call.hpp"
#include "ngraph/ops/get_tuple_element.hpp"
#include "ngraph/ops/reduce.hpp"
#include "ngraph/ops/reshape.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
#include "ngraph/runtime/cpu/call_frame.hpp"
...
...
@@ -1081,3 +1082,60 @@ void Emitter::EMITTER_DECL(EmitFunctionCall)
" (*cf)(inputs, outputs);
\n
"
" }
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitReduce
)
{
auto
reduce
=
static_cast
<
const
op
::
Reduce
*>
(
n
);
auto
reduction_function
=
reduce
->
get_reduction_function
();
std
::
shared_ptr
<
ExternalFunction
>
external
;
try
{
external
=
function_map
.
at
(
reduction_function
);
}
catch
(
const
std
::
out_of_range
)
{
external
=
make_shared
<
ExternalFunction
>
(
reduction_function
);
function_map
.
insert
({
reduction_function
,
external
});
}
auto
reductee_type
=
reduce
->
get_arguments
().
at
(
0
)
->
get_value_type
();
auto
reductee_tensor_view_type
=
dynamic_pointer_cast
<
const
TensorViewType
>
(
reductee_type
);
assert
(
reductee_tensor_view_type
);
auto
reductee_shape
=
reductee_tensor_view_type
->
get_shape
();
auto
f_result_type
=
reduction_function
->
get_result_type
();
auto
f_result_tensor_view_type
=
dynamic_pointer_cast
<
const
TensorViewType
>
(
f_result_type
);
assert
(
f_result_tensor_view_type
);
auto
&
f_result_element_type
=
f_result_tensor_view_type
->
get_element_type
();
auto
result_type
=
reduce
->
get_value_type
();
auto
result_tensor_view_type
=
dynamic_pointer_cast
<
const
TensorViewType
>
(
result_type
);
assert
(
result_tensor_view_type
);
auto
result_shape
=
result_tensor_view_type
->
get_shape
();
auto
&
reduction_axes
=
reduce
->
get_reduction_axes
();
// Trivial case: no reduction axes (this includes the scalar-reductee case).
if
(
reduction_axes
.
empty
())
{
TU
+=
" {
\n
"
" call_frame->get_parameterized_tensor_view<"
+
element_type_names
[
TI
(
f_result_element_type
)]
+
">("
+
to_string
(
outputs
.
at
(
0
).
get_index
())
+
")->get_vector() =
\n
"
" call_frame->get_parameterized_tensor_view<"
+
element_type_names
[
TI
(
f_result_element_type
)]
+
">("
+
to_string
(
inputs
.
at
(
0
).
get_index
())
+
")->get_vector();
\n
"
" }
\n
"
;
}
else
{
throw
ngraph_error
(
"Reduce: only vectors and matrices are currently supported"
);
}
}
src/ngraph/runtime/cpu/emitter.hpp
View file @
c8d9c405
...
...
@@ -79,6 +79,7 @@ namespace ngraph
void
EMITTER_DECL
(
EmitConstant
);
void
EMITTER_DECL
(
EmitReshape
);
void
EMITTER_DECL
(
EmitFunctionCall
);
void
EMITTER_DECL
(
EmitReduce
);
};
}
}
...
...
src/ngraph/runtime/cpu/external_function.cpp
View file @
c8d9c405
...
...
@@ -111,6 +111,7 @@ static const OpMap dispatcher{
{
TI
(
ngraph
::
op
::
Constant
),
&
Emitter
::
EmitConstant
},
{
TI
(
ngraph
::
op
::
Reshape
),
&
Emitter
::
EmitReshape
},
{
TI
(
ngraph
::
op
::
FunctionCall
),
&
Emitter
::
EmitFunctionCall
},
{
TI
(
ngraph
::
op
::
Reduce
),
&
Emitter
::
EmitReduce
},
};
#undef TI
...
...
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