Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
e6550fca
Commit
e6550fca
authored
Feb 14, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dnn: fix OpenCL code in pooling_ocl
parent
3cdc0e48
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
11 deletions
+43
-11
pooling_layer.cpp
modules/dnn/src/layers/pooling_layer.cpp
+19
-5
pooling.cl
modules/dnn/src/opencl/pooling.cl
+24
-6
No files found.
modules/dnn/src/layers/pooling_layer.cpp
View file @
e6550fca
...
...
@@ -132,7 +132,7 @@ void PoolingLayerImpl::maxPooling(Blob &src, Blob &dst, Blob &mask)
bool
PoolingLayerImpl
::
maxPooling_ocl
(
Blob
&
src
,
Blob
&
dst
,
Blob
&
mask
)
{
return
pooling_ocl
(
"MaxPoolForward"
,
src
,
dst
);
return
pooling_ocl
(
"MaxPoolForward"
,
src
,
dst
,
&
mask
);
}
void
PoolingLayerImpl
::
avePooling
(
Blob
&
src
,
Blob
&
dst
)
...
...
@@ -201,22 +201,36 @@ bool PoolingLayerImpl::pooling_ocl(const char *kname, const Blob &src, Blob &dst
{
const
UMat
&
srcMat
=
src
.
umatRefConst
();
UMat
&
dstMat
=
dst
.
umatRef
();
UMat
*
indexesMat
=
mask
==
NULL
?
NULL
:
&
dst
.
umatRef
();
UMat
*
maskUMat
=
mask
==
NULL
?
NULL
:
&
mask
->
umatRef
();
CV_Assert
(
maskUMat
==
NULL
||
maskUMat
->
type
()
==
CV_32FC1
);
// FIXIT CV_32SC1
CV_Assert
(
maskUMat
==
NULL
||
maskUMat
->
offset
==
0
);
CV_Assert
(
srcMat
.
offset
==
0
&&
dstMat
.
offset
==
0
);
ocl
::
Kernel
ker
(
kname
,
ocl
::
dnn
::
pooling_oclsrc
,
String
(
"-DT="
)
+
ocl
::
typeToStr
(
src
.
type
()));
ocl
::
Kernel
ker
(
kname
,
ocl
::
dnn
::
pooling_oclsrc
,
cv
::
format
(
"-DT=%s%s"
,
ocl
::
typeToStr
(
src
.
type
()),
maskUMat
?
" -DMASK=1"
:
""
));
if
(
ker
.
empty
())
return
false
;
BlobShape
s
=
src
.
shape
();
size_t
nthreads
=
dst
.
total
();
ker
.
args
((
int
)
nthreads
,
if
(
maskUMat
)
{
ker
.
args
((
int
)
nthreads
,
ocl
::
KernelArg
::
PtrReadOnly
(
srcMat
),
s
[
0
],
s
[
1
],
s
[
2
],
s
[
3
],
out
.
height
,
out
.
width
,
kernel
.
height
,
kernel
.
width
,
stride
.
height
,
stride
.
width
,
pad
.
height
,
pad
.
width
,
ocl
::
KernelArg
::
PtrWriteOnly
(
dstMat
),
ocl
::
KernelArg
(
ocl
::
KernelArg
::
PTR_ONLY
+
ocl
::
KernelArg
::
WRITE_ONLY
,
indexesMat
));
ocl
::
KernelArg
::
PtrWriteOnly
(
*
maskUMat
));
}
else
{
ker
.
args
((
int
)
nthreads
,
ocl
::
KernelArg
::
PtrReadOnly
(
srcMat
),
s
[
0
],
s
[
1
],
s
[
2
],
s
[
3
],
out
.
height
,
out
.
width
,
kernel
.
height
,
kernel
.
width
,
stride
.
height
,
stride
.
width
,
pad
.
height
,
pad
.
width
,
ocl
::
KernelArg
::
PtrWriteOnly
(
dstMat
));
}
size_t
wgSize
=
ocl
::
Device
::
getDefault
().
maxWorkGroupSize
();
if
(
!
ker
.
run
(
1
,
&
nthreads
,
&
wgSize
,
true
))
...
...
modules/dnn/src/opencl/pooling.cl
View file @
e6550fca
...
...
@@ -24,8 +24,16 @@
*
POSSIBILITY
OF
SUCH
DAMAGE.
**************************************************************************************
/
__kernel
void
MaxPoolForward
(
const
int
nthreads,
__global
T*
bottom_data,
const
int
num,
const
int
channels,
const
int
height,
const
int
width,
const
int
pooled_height,
const
int
pooled_width,
const
int
kernel_h,
const
int
kernel_w,
const
int
stride_h,
const
int
stride_w,
const
int
pad_h,
const
int
pad_w,
__global
T*
top_data,
__global
int*
mask
)
{
__kernel
void
MaxPoolForward
(
const
int
nthreads,
__global
T*
bottom_data,
const
int
num,
const
int
channels,
const
int
height,
const
int
width,
const
int
pooled_height,
const
int
pooled_width,
const
int
kernel_h,
const
int
kernel_w,
const
int
stride_h,
const
int
stride_w,
const
int
pad_h,
const
int
pad_w,
__global
T*
top_data
#
ifdef
MASK
,
__global
float*
mask
#
endif
)
{
int
index
=
get_global_id
(
0
)
;
int
tmp
=
get_global_size
(
0
)
;
for
(
index
; index < nthreads; index += tmp) {
...
...
@@ -51,15 +59,25 @@ __kernel void MaxPoolForward(const int nthreads, __global T* bottom_data, const
}
}
}
top_data[index]
=
maxval
;
if
(
mask
)
{
mask[index]
=
maxidx
;
}
#
ifdef
MASK
mask[index]
=
maxidx
;
#
endif
}
}
__kernel
void
AvePoolForward
(
const
int
nthreads,
__global
T*
bottom_data,
const
int
num,
const
int
channels,
const
int
height,
const
int
width,
const
int
pooled_height,
const
int
pooled_width,
const
int
kernel_h,
const
int
kernel_w,
const
int
stride_h,
const
int
stride_w,
const
int
pad_h,
const
int
pad_w,__global
T*
top_data
)
{
__kernel
void
AvePoolForward
(
const
int
nthreads,
__global
T*
bottom_data,
const
int
num,
const
int
channels,
const
int
height,
const
int
width,
const
int
pooled_height,
const
int
pooled_width,
const
int
kernel_h,
const
int
kernel_w,
const
int
stride_h,
const
int
stride_w,
const
int
pad_h,
const
int
pad_w,
__global
T*
top_data
#
ifdef
MASK
,
__global
float*
mask
//
NOT
USED
#
endif
)
{
int
index
=
get_global_id
(
0
)
;
int
tmp
=
get_global_size
(
0
)
;
for
(
index
; index < nthreads; index+=tmp) {
...
...
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