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
1f1ab184
Commit
1f1ab184
authored
Aug 10, 2018
by
Jayaram Bobba
Committed by
Scott Cyphers
Aug 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dex non-mkldnn version of clipped relu (#1376)
* Dex non-mkldnn version of clipped relu * Change to static_cast
parent
a8fb4fe0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
7 deletions
+31
-7
bounded_relu.cpp
src/ngraph/runtime/cpu/builder/bounded_relu.cpp
+14
-6
relu.hpp
src/ngraph/runtime/cpu/kernel/relu.hpp
+16
-0
cpu_fusion.cpp
test/cpu_fusion.cpp
+1
-1
No files found.
src/ngraph/runtime/cpu/builder/bounded_relu.cpp
View file @
1f1ab184
...
...
@@ -32,17 +32,12 @@ namespace ngraph
template
<>
void
Builder
::
BUILDER_DECL
(
ngraph
::
op
::
BoundedRelu
)
{
if
(
!
runtime
::
cpu
::
mkldnn_utils
::
use_mkldnn_kernel
(
node
))
{
throw
ngraph_error
(
"BoundedRelu is supported only through MKLDNN and doesnt have reference "
"INTERPRETER implementation"
);
}
auto
&
functors
=
external_function
->
get_functors
();
auto
&
tensor_data
=
external_function
->
get_tensor_data
();
auto
&
input_tensor
=
tensor_data
[
args
[
0
].
get_name
()];
auto
&
out_tensor
=
tensor_data
[
out
[
0
].
get_name
()];
size_t
count
=
out
[
0
].
get_size
();
if
(
runtime
::
cpu
::
mkldnn_utils
::
use_mkldnn_kernel
(
node
))
{
...
...
@@ -56,6 +51,19 @@ namespace ngraph
};
functors
.
emplace_back
(
functor
);
}
else
{
std
::
function
<
decltype
(
runtime
::
cpu
::
kernel
::
bounded_relu
<
float
>
)
>
kernel
;
SELECT_KERNEL
(
kernel
,
out
[
0
].
get_element_type
(),
runtime
::
cpu
::
kernel
::
bounded_relu
);
auto
alpha
=
static_cast
<
const
op
::
BoundedRelu
*>
(
node
)
->
get_alpha
();
auto
functor
=
[
&
,
kernel
,
alpha
,
count
](
CPURuntimeContext
*
ctx
)
{
kernel
(
input_tensor
,
out_tensor
,
alpha
,
count
);
};
functors
.
emplace_back
(
functor
);
}
}
REGISTER_OP_BUILDER
(
BoundedRelu
);
}
...
...
src/ngraph/runtime/cpu/kernel/relu.hpp
View file @
1f1ab184
...
...
@@ -45,6 +45,22 @@ namespace ngraph
out
.
device
(
eigen
::
global_thread_pool_device
)
=
in0
.
cwiseMax
(
ElementType
(
0
));
}
template
<
typename
ElementType
>
void
bounded_relu
(
void
*
input0
,
void
*
output
,
ElementType
alpha
,
size_t
count
)
{
Eigen
::
array
<
Eigen
::
Index
,
1
>
out_dims
,
in_dims
;
out_dims
[
0
]
=
in_dims
[
0
]
=
count
;
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
ElementType
,
1
,
Eigen
::
RowMajor
>>
out
(
static_cast
<
ElementType
*>
(
output
),
out_dims
);
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
ElementType
,
1
,
Eigen
::
RowMajor
>>
in0
(
static_cast
<
ElementType
*>
(
input0
),
in_dims
);
out
.
device
(
eigen
::
global_thread_pool_device
)
=
in0
.
cwiseMax
(
ElementType
(
0
)).
cwiseMin
(
alpha
);
}
template
<
typename
ElementType
>
void
relu_backprop
(
void
*
arg
,
void
*
delta_arg
,
void
*
out
,
size_t
count
)
{
...
...
test/cpu_fusion.cpp
View file @
1f1ab184
...
...
@@ -2603,7 +2603,7 @@ static void check_bounded_relu(Shape param_shape, float constant_val)
auto
cpu_f
=
make_function
(
param_shape
,
constant_val
);
auto
int_f
=
make_function
(
param_shape
,
constant_val
);
test
::
Uniform
<
float
>
rng
(
0.0
f
,
1
.0
f
);
test
::
Uniform
<
float
>
rng
(
-
10.0
f
,
10
.0
f
);
vector
<
vector
<
float
>>
args
;
for
(
shared_ptr
<
op
::
Parameter
>
param
:
int_f
->
get_parameters
())
...
...
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