Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
opencv
Commits
e15928b4
Commit
e15928b4
authored
Jan 23, 2018
by
Li Peng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convolution and tanh layer fusion
Signed-off-by:
Li Peng
<
peng.li@intel.com
>
parent
b97b650a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
5 deletions
+35
-5
dnn.cpp
modules/dnn/src/dnn.cpp
+5
-4
convolution_layer.cpp
modules/dnn/src/layers/convolution_layer.cpp
+10
-0
ocl4dnn.hpp
modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp
+3
-1
ocl4dnn_conv_spatial.cpp
modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp
+14
-0
conv_layer_spatial.cl
modules/dnn/src/opencl/conv_layer_spatial.cl
+3
-0
No files found.
modules/dnn/src/dnn.cpp
View file @
e15928b4
...
...
@@ -1239,13 +1239,14 @@ struct Net::Impl
}
}
// For now,
OpenCL target only support fusion with activation of ReLU/ChannelsPReLU/Power
// For now,
OpenCL target support fusion with activation of ReLU/ChannelsPReLU/Power/Tanh
if
(
preferableTarget
!=
DNN_TARGET_OPENCL
||
(
preferableTarget
==
DNN_TARGET_OPENCL
&&
nextData
&&
(
!
nextData
->
type
.
compare
(
"ReLU"
)
||
!
nextData
->
type
.
compare
(
"ChannelsPReLU"
)
||
!
nextData
->
type
.
compare
(
"Power"
)))
)
((
nextData
->
type
==
"ReLU"
)
||
(
nextData
->
type
==
"ChannelsPReLU"
)
||
(
nextData
->
type
==
"TanH"
)
||
(
nextData
->
type
==
"Power"
)))
)
{
Ptr
<
ActivationLayer
>
nextActivLayer
;
...
...
modules/dnn/src/layers/convolution_layer.cpp
View file @
e15928b4
...
...
@@ -246,6 +246,11 @@ public:
power
=
activ_power
->
power
;
activType
=
OCL4DNN_CONV_FUSED_ACTIV_POWER
;
}
Ptr
<
TanHLayer
>
activ_tanh
=
activ
.
dynamicCast
<
TanHLayer
>
();
if
(
!
activ_tanh
.
empty
())
{
activType
=
OCL4DNN_CONV_FUSED_ACTIV_TANH
;
}
}
#endif
return
!
activ
.
empty
();
...
...
@@ -877,11 +882,16 @@ public:
{
convolutionOp
->
setActivPower
(
true
,
power
);
}
else
if
(
activType
==
OCL4DNN_CONV_FUSED_ACTIV_TANH
)
{
convolutionOp
->
setActivTanh
(
true
);
}
else
{
convolutionOp
->
setActivReLU
(
false
,
0
);
convolutionOp
->
setActivPReLU
(
false
,
reluslope
);
convolutionOp
->
setActivPower
(
false
,
1.
f
);
convolutionOp
->
setActivTanh
(
false
);
}
newActiv
=
false
;
}
...
...
modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp
View file @
e15928b4
...
...
@@ -77,7 +77,8 @@ typedef enum {
OCL4DNN_CONV_FUSED_ACTIV_NONE
=
0
,
OCL4DNN_CONV_FUSED_ACTIV_RELU
=
1
,
OCL4DNN_CONV_FUSED_ACTIV_PRELU
=
2
,
OCL4DNN_CONV_FUSED_ACTIV_POWER
=
3
OCL4DNN_CONV_FUSED_ACTIV_POWER
=
3
,
OCL4DNN_CONV_FUSED_ACTIV_TANH
=
4
}
ocl4dnnFusedActiv_t
;
template
<
typename
Dtype
>
...
...
@@ -94,6 +95,7 @@ class OCL4DNNConvSpatial
void
setActivReLU
(
bool
fuse_activ
,
float
slope
);
void
setActivPReLU
(
bool
fuse_activ
,
std
::
vector
<
float
>
&
slope
);
void
setActivPower
(
bool
fuse_activ
,
float
power
);
void
setActivTanh
(
bool
fuse_activ
);
void
setBias
(
bool
bias_term
);
private
:
...
...
modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp
View file @
e15928b4
...
...
@@ -159,6 +159,9 @@ void OCL4DNNConvSpatial<Dtype>::setFusionDefine(ocl4dnnFusedActiv_t fused_activ,
case
OCL4DNN_CONV_FUSED_ACTIV_POWER
:
addDef
(
"FUSED_CONV_POWER"
,
1
);
break
;
case
OCL4DNN_CONV_FUSED_ACTIV_TANH
:
addDef
(
"FUSED_CONV_TANH"
,
1
);
break
;
default
:
;
}
...
...
@@ -415,6 +418,17 @@ void OCL4DNNConvSpatial<Dtype>::setActivPower(bool fuse_activ, float power)
fused_activ_
=
OCL4DNN_CONV_FUSED_ACTIV_NONE
;
}
template
<
typename
Dtype
>
void
OCL4DNNConvSpatial
<
Dtype
>::
setActivTanh
(
bool
fuse_activ
)
{
if
(
fuse_activ
)
{
fused_activ_
=
OCL4DNN_CONV_FUSED_ACTIV_TANH
;
}
else
fused_activ_
=
OCL4DNN_CONV_FUSED_ACTIV_NONE
;
}
template
<
typename
Dtype
>
bool
OCL4DNNConvSpatial
<
Dtype
>::
Forward
(
const
UMat
&
bottom
,
const
UMat
&
bottom2
,
...
...
modules/dnn/src/opencl/conv_layer_spatial.cl
View file @
e15928b4
...
...
@@ -55,6 +55,9 @@
#
elif
defined
(
FUSED_CONV_POWER
)
#
define
ACTIVATION_RELU_FUNCTION
(
x,
c
)
pow
(
x,
power
)
#
define
NEGATIVE_SLOPE_ARG
Dtype
power,
#
elif
defined
(
FUSED_CONV_TANH
)
#
define
ACTIVATION_RELU_FUNCTION
(
x,
c
)
tanh
(
x
)
#
define
NEGATIVE_SLOPE_ARG
#
else
#
define
ACTIVATION_RELU_FUNCTION
(
x,
c
)
(
x
)
#
define
NEGATIVE_SLOPE_ARG
...
...
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