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
eca45d1c
Commit
eca45d1c
authored
May 22, 2019
by
Adam Rogowiec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move common RNN utility functions to RNNCellBase.
parent
8ad92a06
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
45 deletions
+85
-45
lstm_cell.cpp
src/ngraph/op/fused/lstm_cell.cpp
+0
-45
rnn_cell_base.cpp
src/ngraph/op/fused/rnn_cell_base.cpp
+43
-0
rnn_cell_base.hpp
src/ngraph/op/fused/rnn_cell_base.hpp
+42
-0
No files found.
src/ngraph/op/fused/lstm_cell.cpp
View file @
eca45d1c
...
...
@@ -23,11 +23,6 @@
#include "ngraph/op/constant.hpp"
#include "ngraph/op/dot.hpp"
#include "ngraph/op/fused/lstm_cell.hpp"
#include "ngraph/op/maximum.hpp"
#include "ngraph/op/minimum.hpp"
#include "ngraph/op/multiply.hpp"
#include "ngraph/op/subtract.hpp"
#include "ngraph/op/util/broadcasting.hpp"
#include "ngraph/op/util/reshape.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/type/element_type.hpp"
...
...
@@ -36,46 +31,6 @@
using
namespace
std
;
using
namespace
ngraph
;
// ------------- HELPER FUNCTIONS ---------------------------------------------
static
shared_ptr
<
Node
>
add
(
const
shared_ptr
<
Node
>&
lhs
,
const
shared_ptr
<
Node
>&
rhs
)
{
auto
args
=
op
::
numpy_style_broadcast
({
lhs
,
rhs
});
return
{
make_shared
<
op
::
Add
>
(
args
.
at
(
0
),
args
.
at
(
1
))};
}
static
shared_ptr
<
Node
>
sub
(
const
shared_ptr
<
Node
>&
lhs
,
const
shared_ptr
<
Node
>&
rhs
)
{
auto
args
=
op
::
numpy_style_broadcast
({
lhs
,
rhs
});
return
{
make_shared
<
op
::
Subtract
>
(
args
.
at
(
0
),
args
.
at
(
1
))};
}
static
shared_ptr
<
Node
>
mul
(
const
shared_ptr
<
Node
>&
lhs
,
const
shared_ptr
<
Node
>&
rhs
)
{
auto
args
=
op
::
numpy_style_broadcast
({
lhs
,
rhs
});
return
{
make_shared
<
op
::
Multiply
>
(
args
.
at
(
0
),
args
.
at
(
1
))};
}
static
shared_ptr
<
Node
>
clip
(
const
shared_ptr
<
Node
>&
data
,
float
threshold
)
{
if
(
threshold
==
0.
f
)
{
return
data
;
}
float
min_val
=
-
threshold
;
float
max_val
=
threshold
;
size_t
size
=
shape_size
(
data
->
get_shape
());
const
shared_ptr
<
Node
>
min_val_node
=
op
::
Constant
::
create
(
data
->
get_element_type
(),
data
->
get_shape
(),
vector
<
float
>
(
size
,
min_val
));
const
shared_ptr
<
Node
>
max_val_node
=
op
::
Constant
::
create
(
data
->
get_element_type
(),
data
->
get_shape
(),
vector
<
float
>
(
size
,
max_val
));
return
make_shared
<
op
::
Minimum
>
(
max_val_node
,
make_shared
<
op
::
Maximum
>
(
data
,
min_val_node
));
}
// ------------- LSTM_CELL ----------------------------------------------------
op
::
LSTMCell
::
LSTMCell
(
const
shared_ptr
<
Node
>&
X
,
const
shared_ptr
<
Node
>&
W
,
const
shared_ptr
<
Node
>&
R
,
...
...
src/ngraph/op/fused/rnn_cell_base.cpp
View file @
eca45d1c
...
...
@@ -17,7 +17,14 @@
#include <algorithm>
#include <iterator>
#include "ngraph/op/add.hpp"
#include "ngraph/op/constant.hpp"
#include "ngraph/op/fused/rnn_cell_base.hpp"
#include "ngraph/op/maximum.hpp"
#include "ngraph/op/minimum.hpp"
#include "ngraph/op/multiply.hpp"
#include "ngraph/op/subtract.hpp"
#include "ngraph/op/util/broadcasting.hpp"
#include "ngraph/util.hpp"
using
namespace
std
;
...
...
@@ -60,3 +67,39 @@ op::ActivationFunction op::RNNCellBase::get_activation_function(size_t idx) cons
return
afunc
;
}
shared_ptr
<
Node
>
op
::
RNNCellBase
::
add
(
const
shared_ptr
<
Node
>&
lhs
,
const
shared_ptr
<
Node
>&
rhs
)
{
auto
args
=
op
::
numpy_style_broadcast
({
lhs
,
rhs
});
return
{
make_shared
<
op
::
Add
>
(
args
.
at
(
0
),
args
.
at
(
1
))};
}
shared_ptr
<
Node
>
op
::
RNNCellBase
::
sub
(
const
shared_ptr
<
Node
>&
lhs
,
const
shared_ptr
<
Node
>&
rhs
)
{
auto
args
=
op
::
numpy_style_broadcast
({
lhs
,
rhs
});
return
{
make_shared
<
op
::
Subtract
>
(
args
.
at
(
0
),
args
.
at
(
1
))};
}
shared_ptr
<
Node
>
op
::
RNNCellBase
::
mul
(
const
shared_ptr
<
Node
>&
lhs
,
const
shared_ptr
<
Node
>&
rhs
)
{
auto
args
=
op
::
numpy_style_broadcast
({
lhs
,
rhs
});
return
{
make_shared
<
op
::
Multiply
>
(
args
.
at
(
0
),
args
.
at
(
1
))};
}
shared_ptr
<
Node
>
op
::
RNNCellBase
::
clip
(
const
shared_ptr
<
Node
>&
data
,
const
float
threshold
)
{
if
(
threshold
==
0.
f
)
{
return
data
;
}
float
min_val
=
-
threshold
;
float
max_val
=
threshold
;
size_t
size
=
shape_size
(
data
->
get_shape
());
const
shared_ptr
<
Node
>
min_val_node
=
op
::
Constant
::
create
(
data
->
get_element_type
(),
data
->
get_shape
(),
vector
<
float
>
(
size
,
min_val
));
const
shared_ptr
<
Node
>
max_val_node
=
op
::
Constant
::
create
(
data
->
get_element_type
(),
data
->
get_shape
(),
vector
<
float
>
(
size
,
max_val
));
return
make_shared
<
op
::
Minimum
>
(
max_val_node
,
make_shared
<
op
::
Maximum
>
(
data
,
min_val_node
));
}
src/ngraph/op/fused/rnn_cell_base.hpp
View file @
eca45d1c
...
...
@@ -17,9 +17,11 @@
#pragma once
#include <cstddef>
#include <memory>
#include <string>
#include <vector>
#include "ngraph/node.hpp"
#include "ngraph/op/util/activation_functions.hpp"
namespace
ngraph
...
...
@@ -66,6 +68,46 @@ namespace ngraph
/// \return The object representing activation function.
///
ActivationFunction
get_activation_function
(
std
::
size_t
idx
)
const
;
///
/// \brief Creates node with element-wise add operation with numpy broadcasting.
///
/// \param[in] lhs The left hand side argument node.
/// \param[in] rhs The right hand side argument node.
///
/// \return Node with element-wise add operation.
///
static
std
::
shared_ptr
<
Node
>
add
(
const
std
::
shared_ptr
<
Node
>&
lhs
,
const
std
::
shared_ptr
<
Node
>&
rhs
);
///
/// \brief Creates node with element-wise subtract operation with numpy broadcasting.
///
/// \param[in] lhs The left hand side argument node.
/// \param[in] rhs The right hand side argument node.
///
/// \return Node with element-wise subtract operation.
///
static
std
::
shared_ptr
<
Node
>
sub
(
const
std
::
shared_ptr
<
Node
>&
lhs
,
const
std
::
shared_ptr
<
Node
>&
rhs
);
///
/// \brief Creates node with element-wise multiply operation with numpy broadcasting.
///
/// \param[in] lhs The left hand side argument node.
/// \param[in] rhs The right hand side argument node.
///
/// \return Node with element-wise multiply operation.
///
static
std
::
shared_ptr
<
Node
>
mul
(
const
std
::
shared_ptr
<
Node
>&
lhs
,
const
std
::
shared_ptr
<
Node
>&
rhs
);
///
/// \brief Creates node with element-wise clip operation with numpy broadcasting.
///
/// \param[in] lhs The left hand side argument node.
/// \param[in] rhs The right hand side argument node.
///
/// \return Node with element-wise clip operation.
///
static
std
::
shared_ptr
<
Node
>
clip
(
const
std
::
shared_ptr
<
Node
>&
data
,
const
float
threshold
);
private
:
std
::
size_t
m_hidden_size
=
0.
f
;
...
...
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