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
f40231af
Commit
f40231af
authored
Jun 29, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11851 from pengli:3.4
parents
6c196d30
145eae32
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
37 deletions
+44
-37
dnn.cpp
modules/dnn/src/dnn.cpp
+1
-1
pooling_layer.cpp
modules/dnn/src/layers/pooling_layer.cpp
+1
-0
ocl4dnn.hpp
modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp
+3
-0
ocl4dnn_pool.cpp
modules/dnn/src/ocl4dnn/src/ocl4dnn_pool.cpp
+4
-4
ocl4dnn_pooling.cl
modules/dnn/src/opencl/ocl4dnn_pooling.cl
+35
-32
No files found.
modules/dnn/src/dnn.cpp
View file @
f40231af
...
@@ -1446,7 +1446,7 @@ struct Net::Impl
...
@@ -1446,7 +1446,7 @@ struct Net::Impl
// TODO: OpenCL target support more fusion styles.
// TODO: OpenCL target support more fusion styles.
if
(
preferableBackend
==
DNN_BACKEND_OPENCV
&&
IS_DNN_OPENCL_TARGET
(
preferableTarget
)
&&
if
(
preferableBackend
==
DNN_BACKEND_OPENCV
&&
IS_DNN_OPENCL_TARGET
(
preferableTarget
)
&&
(
!
cv
::
ocl
::
useOpenCL
()
||
(
ld
.
layerInstance
->
type
!=
"Convolution"
&&
(
!
cv
::
ocl
::
useOpenCL
()
||
(
ld
.
layerInstance
->
type
!=
"Convolution"
&&
ld
.
layerInstance
->
type
!=
"MVN"
))
)
ld
.
layerInstance
->
type
!=
"MVN"
&&
ld
.
layerInstance
->
type
!=
"Pooling"
))
)
continue
;
continue
;
Ptr
<
Layer
>&
currLayer
=
ld
.
layerInstance
;
Ptr
<
Layer
>&
currLayer
=
ld
.
layerInstance
;
...
...
modules/dnn/src/layers/pooling_layer.cpp
View file @
f40231af
...
@@ -165,6 +165,7 @@ public:
...
@@ -165,6 +165,7 @@ public:
(
type
==
AVE
?
LIBDNN_POOLING_METHOD_AVE
:
(
type
==
AVE
?
LIBDNN_POOLING_METHOD_AVE
:
LIBDNN_POOLING_METHOD_STO
);
LIBDNN_POOLING_METHOD_STO
);
config
.
avePoolPaddedArea
=
avePoolPaddedArea
;
config
.
avePoolPaddedArea
=
avePoolPaddedArea
;
config
.
computeMaxIdx
=
computeMaxIdx
;
config
.
use_half
=
use_half
;
config
.
use_half
=
use_half
;
poolOp
=
Ptr
<
OCL4DNNPool
<
float
>
>
(
new
OCL4DNNPool
<
float
>
(
config
));
poolOp
=
Ptr
<
OCL4DNNPool
<
float
>
>
(
new
OCL4DNNPool
<
float
>
(
config
));
}
}
...
...
modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp
View file @
f40231af
...
@@ -352,6 +352,7 @@ struct OCL4DNNPoolConfig
...
@@ -352,6 +352,7 @@ struct OCL4DNNPoolConfig
pool_method
(
LIBDNN_POOLING_METHOD_MAX
),
pool_method
(
LIBDNN_POOLING_METHOD_MAX
),
global_pooling
(
false
),
global_pooling
(
false
),
avePoolPaddedArea
(
true
),
avePoolPaddedArea
(
true
),
computeMaxIdx
(
true
),
use_half
(
false
)
use_half
(
false
)
{}
{}
MatShape
in_shape
;
MatShape
in_shape
;
...
@@ -365,6 +366,7 @@ struct OCL4DNNPoolConfig
...
@@ -365,6 +366,7 @@ struct OCL4DNNPoolConfig
ocl4dnnPoolingMethod_t
pool_method
;
// = LIBDNN_POOLING_METHOD_MAX;
ocl4dnnPoolingMethod_t
pool_method
;
// = LIBDNN_POOLING_METHOD_MAX;
bool
global_pooling
;
// = false;
bool
global_pooling
;
// = false;
bool
avePoolPaddedArea
;
bool
avePoolPaddedArea
;
bool
computeMaxIdx
;
bool
use_half
;
bool
use_half
;
};
};
...
@@ -399,6 +401,7 @@ class OCL4DNNPool
...
@@ -399,6 +401,7 @@ class OCL4DNNPool
int32_t
pooled_height_
;
int32_t
pooled_height_
;
int32_t
pooled_width_
;
int32_t
pooled_width_
;
bool
avePoolPaddedArea
;
bool
avePoolPaddedArea
;
bool
computeMaxIdx
;
bool
use_half
;
bool
use_half
;
};
};
...
...
modules/dnn/src/ocl4dnn/src/ocl4dnn_pool.cpp
View file @
f40231af
...
@@ -56,6 +56,7 @@ OCL4DNNPool<Dtype>::OCL4DNNPool(OCL4DNNPoolConfig config)
...
@@ -56,6 +56,7 @@ OCL4DNNPool<Dtype>::OCL4DNNPool(OCL4DNNPoolConfig config)
channels_
=
config
.
channels
;
channels_
=
config
.
channels
;
pool_method_
=
config
.
pool_method
;
pool_method_
=
config
.
pool_method
;
avePoolPaddedArea
=
config
.
avePoolPaddedArea
;
avePoolPaddedArea
=
config
.
avePoolPaddedArea
;
computeMaxIdx
=
config
.
computeMaxIdx
;
use_half
=
config
.
use_half
;
use_half
=
config
.
use_half
;
for
(
int
i
=
0
;
i
<
spatial_dims
;
++
i
)
for
(
int
i
=
0
;
i
<
spatial_dims
;
++
i
)
...
@@ -97,7 +98,7 @@ bool OCL4DNNPool<Dtype>::Forward(const UMat& bottom,
...
@@ -97,7 +98,7 @@ bool OCL4DNNPool<Dtype>::Forward(const UMat& bottom,
UMat
&
top_mask
)
UMat
&
top_mask
)
{
{
bool
ret
=
true
;
bool
ret
=
true
;
size_t
global
[]
=
{
128
*
128
};
size_t
global
[]
=
{
(
size_t
)
count_
};
size_t
local
[]
=
{
128
};
size_t
local
[]
=
{
128
};
// support 2D case
// support 2D case
...
@@ -105,8 +106,7 @@ bool OCL4DNNPool<Dtype>::Forward(const UMat& bottom,
...
@@ -105,8 +106,7 @@ bool OCL4DNNPool<Dtype>::Forward(const UMat& bottom,
{
{
case
LIBDNN_POOLING_METHOD_MAX
:
case
LIBDNN_POOLING_METHOD_MAX
:
{
{
bool
haveMask
=
!
top_mask
.
empty
();
String
kname
=
computeMaxIdx
?
"max_pool_forward_mask"
:
"max_pool_forward"
;
String
kname
=
haveMask
?
"max_pool_forward_mask"
:
"max_pool_forward"
;
kname
+=
(
use_half
)
?
"_half"
:
"_float"
;
kname
+=
(
use_half
)
?
"_half"
:
"_float"
;
ocl
::
Kernel
oclk_max_pool_forward
(
ocl
::
Kernel
oclk_max_pool_forward
(
kname
.
c_str
(),
kname
.
c_str
(),
...
@@ -118,7 +118,7 @@ bool OCL4DNNPool<Dtype>::Forward(const UMat& bottom,
...
@@ -118,7 +118,7 @@ bool OCL4DNNPool<Dtype>::Forward(const UMat& bottom,
kernel_w_
,
kernel_h_
,
kernel_w_
,
kernel_h_
,
stride_w_
,
stride_h_
,
stride_w_
,
stride_h_
,
pad_w_
,
pad_h_
,
pad_w_
,
pad_h_
,
haveMask
?
" -D HAVE_MASK=1"
:
""
computeMaxIdx
?
" -D HAVE_MASK=1"
:
""
));
));
if
(
oclk_max_pool_forward
.
empty
())
if
(
oclk_max_pool_forward
.
empty
())
...
...
modules/dnn/src/opencl/ocl4dnn_pooling.cl
View file @
f40231af
...
@@ -65,28 +65,33 @@ __kernel void
...
@@ -65,28 +65,33 @@ __kernel void
#
endif
#
endif
)
)
{
{
for
(
int
index
=
get_global_id
(
0
)
; index < nthreads;
int
index
=
get_global_id
(
0
)
;
index
+=
get_global_size
(
0
))
if
(
index
>=
nthreads
)
{
return
;
const
int
pw
=
index
%
pooled_width
;
const
int
pw
=
index
%
pooled_width
;
const
int
ph
=
(
index
/
pooled_width
)
%
pooled_height
;
const
int
xx
=
index
/
pooled_width
;
const
int
c
=
(
index
/
pooled_width
/
pooled_height
)
%
channels
;
const
int
ph
=
xx
%
pooled_height
;
const
int
n
=
index
/
pooled_width
/
pooled_height
/
channels
;
const
int
ch
=
xx
/
pooled_height
;
int
hstart
=
ph
*
STRIDE_H
-
PAD_H
;
int
hstart
=
ph
*
STRIDE_H
-
PAD_H
;
int
wstart
=
pw
*
STRIDE_W
-
PAD_W
;
int
wstart
=
pw
*
STRIDE_W
-
PAD_W
;
const
int
hend
=
min
(
hstart
+
KERNEL_H,
height
)
;
const
int
wend
=
min
(
wstart
+
KERNEL_W,
width
)
;
hstart
=
max
(
hstart,
(
int
)
0
)
;
wstart
=
max
(
wstart,
(
int
)
0
)
;
Dtype
maxval
=
-FLT_MAX
;
Dtype
maxval
=
-FLT_MAX
;
int
maxidx
=
-1
;
int
maxidx
=
-1
;
__global
const
Dtype*
bottom_slice
=
bottom_data
int
in_offset
=
ch
*
height
*
width
;
+
(
n
*
channels
+
c
)
*
height
*
width
;
for
(
int
h
=
0
; h < KERNEL_H; ++h)
for
(
int
h
=
hstart
; h < hend; ++h) {
{
for
(
int
w
=
wstart
; w < wend; ++w) {
int
off_y
=
hstart
+
h
;
if
(
bottom_slice[h
*
width
+
w]
>
maxval
)
{
if
(
off_y
>=
0
&&
off_y
<
height
)
maxidx
=
h
*
width
+
w
;
{
maxval
=
bottom_slice[maxidx]
;
for
(
int
w
=
0
; w < KERNEL_W; ++w)
{
int
off_x
=
wstart
+
w
;
if
(
off_x
>=
0
&&
off_x
<
width
)
{
Dtype
val
=
bottom_data[in_offset
+
off_y
*
width
+
off_x]
;
maxidx
=
(
val
>
maxval
)
?
(
off_y
*
width
+
off_x
)
:
maxidx
;
maxval
=
fmax
(
val,
maxval
)
;
}
}
}
}
}
}
}
...
@@ -94,7 +99,6 @@ __kernel void
...
@@ -94,7 +99,6 @@ __kernel void
#
ifdef
HAVE_MASK
#
ifdef
HAVE_MASK
mask[index]
=
maxidx
;
mask[index]
=
maxidx
;
#
endif
#
endif
}
}
}
#
elif
defined
KERNEL_AVE_POOL
#
elif
defined
KERNEL_AVE_POOL
...
@@ -105,14 +109,14 @@ __kernel void TEMPLATE(ave_pool_forward, Dtype)(
...
@@ -105,14 +109,14 @@ __kernel void TEMPLATE(ave_pool_forward, Dtype)(
const
int
pooled_height,
const
int
pooled_width,
const
int
pooled_height,
const
int
pooled_width,
__global
Dtype*
top_data
)
__global
Dtype*
top_data
)
{
{
for
(
int
index
=
get_global_id
(
0
)
; index < nthreads
;
int
index
=
get_global_id
(
0
)
;
index
+=
get_global_size
(
0
)
)
if
(
index
>=
nthreads
)
{
return
;
{
const
int
pw
=
index
%
pooled_width
;
const
int
pw
=
index
%
pooled_width
;
const
int
ph
=
(
index
/
pooled_width
)
%
pooled_height
;
const
int
xx
=
index
/
pooled_width
;
const
int
c
=
(
index
/
pooled_width
/
pooled_height
)
%
channels
;
const
int
ph
=
xx
%
pooled_height
;
const
int
n
=
index
/
pooled_width
/
pooled_height
/
channels
;
const
int
ch
=
xx
/
pooled_height
;
int
hstart
=
ph
*
STRIDE_H
-
PAD_H
;
int
hstart
=
ph
*
STRIDE_H
-
PAD_H
;
int
wstart
=
pw
*
STRIDE_W
-
PAD_W
;
int
wstart
=
pw
*
STRIDE_W
-
PAD_W
;
int
hend
=
min
(
hstart
+
KERNEL_H,
height
+
PAD_H
)
;
int
hend
=
min
(
hstart
+
KERNEL_H,
height
+
PAD_H
)
;
...
@@ -132,16 +136,15 @@ __kernel void TEMPLATE(ave_pool_forward, Dtype)(
...
@@ -132,16 +136,15 @@ __kernel void TEMPLATE(ave_pool_forward, Dtype)(
pool_size
=
(
hend
-
hstart
)
*
(
wend
-
wstart
)
;
pool_size
=
(
hend
-
hstart
)
*
(
wend
-
wstart
)
;
#
endif
#
endif
Dtype
aveval
=
0
;
Dtype
aveval
=
0
;
__global
const
Dtype*
bottom_slice
=
bottom_data
int
in_offset
=
ch
*
height
*
width
;
+
(
n
*
channels
+
c
)
*
height
*
width
;
for
(
int
h
=
hstart
; h < hend; ++h)
for
(
int
h
=
hstart
; h < hend; ++h) {
{
for
(
int
w
=
wstart
; w < wend; ++w) {
for
(
int
w
=
wstart
; w < wend; ++w)
aveval
+=
bottom_slice[h
*
width
+
w]
;
{
aveval
+=
bottom_data[in_offset
+
h
*
width
+
w]
;
}
}
}
}
top_data[index]
=
aveval
/
pool_size
;
top_data[index]
=
aveval
/
pool_size
;
}
}
}
}
#
elif
defined
KERNEL_STO_POOL
#
elif
defined
KERNEL_STO_POOL
...
...
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