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
4e57f92e
Commit
4e57f92e
authored
Oct 25, 2013
by
Andrey Pavlenko
Committed by
OpenCV Buildbot
Oct 25, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1692 from ilya-lavrenov:ocl_separableFilter
parents
d60924f4
b33a62be
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
88 deletions
+25
-88
filtering.cpp
modules/ocl/src/filtering.cpp
+17
-51
filter_sep_col.cl
modules/ocl/src/opencl/filter_sep_col.cl
+7
-36
filter_sep_row.cl
modules/ocl/src/opencl/filter_sep_row.cl
+0
-0
test_filters.cpp
modules/ocl/test/test_filters.cpp
+1
-1
No files found.
modules/ocl/src/filtering.cpp
View file @
4e57f92e
...
...
@@ -1058,74 +1058,39 @@ template <> struct index_and_sizeof<float>
template
<
typename
T
>
void
linearRowFilter_gpu
(
const
oclMat
&
src
,
const
oclMat
&
dst
,
oclMat
mat_kernel
,
int
ksize
,
int
anchor
,
int
bordertype
)
{
Context
*
clCxt
=
src
.
clCxt
;
CV_Assert
(
bordertype
<=
BORDER_REFLECT_101
);
CV_Assert
(
ksize
==
(
anchor
<<
1
)
+
1
);
int
channels
=
src
.
oclchannels
();
size_t
localThreads
[
3
]
=
{
16
,
16
,
1
};
string
kernelName
=
"row_filter"
;
char
btype
[
30
];
size_t
localThreads
[
3
]
=
{
16
,
16
,
1
};
size_t
globalThreads
[
3
]
=
{
dst
.
cols
,
dst
.
rows
,
1
};
switch
(
bordertype
)
{
case
0
:
sprintf
(
btype
,
"BORDER_CONSTANT"
);
break
;
case
1
:
sprintf
(
btype
,
"BORDER_REPLICATE"
);
break
;
case
2
:
sprintf
(
btype
,
"BORDER_REFLECT"
);
break
;
case
3
:
sprintf
(
btype
,
"BORDER_WRAP"
);
break
;
case
4
:
sprintf
(
btype
,
"BORDER_REFLECT_101"
);
break
;
}
char
compile_option
[
128
];
sprintf
(
compile_option
,
"-D RADIUSX=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D %s"
,
anchor
,
(
int
)
localThreads
[
0
],
(
int
)
localThreads
[
1
],
channels
,
btype
);
size_t
globalThreads
[
3
];
globalThreads
[
1
]
=
(
dst
.
rows
+
localThreads
[
1
]
-
1
)
/
localThreads
[
1
]
*
localThreads
[
1
];
globalThreads
[
2
]
=
(
1
+
localThreads
[
2
]
-
1
)
/
localThreads
[
2
]
*
localThreads
[
2
];
const
char
*
const
borderMap
[]
=
{
"BORDER_CONSTANT"
,
"BORDER_REPLICATE"
,
"BORDER_REFLECT"
,
"BORDER_WRAP"
,
"BORDER_REFLECT_101"
};
std
::
string
buildOptions
=
format
(
"-D RADIUSX=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D %s"
,
anchor
,
(
int
)
localThreads
[
0
],
(
int
)
localThreads
[
1
],
channels
,
borderMap
[
bordertype
]);
if
(
src
.
depth
()
==
CV_8U
)
{
switch
(
channels
)
{
case
1
:
case
3
:
globalThreads
[
0
]
=
((
dst
.
cols
+
4
)
/
4
+
localThreads
[
0
]
-
1
)
/
localThreads
[
0
]
*
localThreads
[
0
];
globalThreads
[
0
]
=
(
dst
.
cols
+
3
)
>>
2
;
break
;
case
2
:
globalThreads
[
0
]
=
(
(
dst
.
cols
+
1
)
/
2
+
localThreads
[
0
]
-
1
)
/
localThreads
[
0
]
*
localThreads
[
0
]
;
globalThreads
[
0
]
=
(
dst
.
cols
+
1
)
>>
1
;
break
;
case
4
:
globalThreads
[
0
]
=
(
dst
.
cols
+
localThreads
[
0
]
-
1
)
/
localThreads
[
0
]
*
localThreads
[
0
]
;
globalThreads
[
0
]
=
dst
.
cols
;
break
;
}
}
else
{
globalThreads
[
0
]
=
(
dst
.
cols
+
localThreads
[
0
]
-
1
)
/
localThreads
[
0
]
*
localThreads
[
0
];
}
//sanity checks
CV_Assert
(
clCxt
==
dst
.
clCxt
);
CV_Assert
(
src
.
cols
==
dst
.
cols
);
CV_Assert
(
src
.
oclchannels
()
==
dst
.
oclchannels
());
CV_Assert
(
ksize
==
(
anchor
<<
1
)
+
1
);
int
src_pix_per_row
,
dst_pix_per_row
;
int
src_offset_x
,
src_offset_y
;
//, dst_offset_in_pixel;
src_pix_per_row
=
src
.
step
/
src
.
elemSize
();
src_offset_x
=
(
src
.
offset
%
src
.
step
)
/
src
.
elemSize
();
src_offset_y
=
src
.
offset
/
src
.
step
;
dst_pix_per_row
=
dst
.
step
/
dst
.
elemSize
();
//dst_offset_in_pixel = dst.offset / dst.elemSize();
int
src_pix_per_row
=
src
.
step
/
src
.
elemSize
();
int
src_offset_x
=
(
src
.
offset
%
src
.
step
)
/
src
.
elemSize
();
int
src_offset_y
=
src
.
offset
/
src
.
step
;
int
dst_pix_per_row
=
dst
.
step
/
dst
.
elemSize
();
int
ridusy
=
(
dst
.
rows
-
src
.
rows
)
>>
1
;
vector
<
pair
<
size_t
,
const
void
*>
>
args
;
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
&
src
.
data
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
&
dst
.
data
));
...
...
@@ -1140,7 +1105,8 @@ void linearRowFilter_gpu(const oclMat &src, const oclMat &dst, oclMat mat_kernel
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
ridusy
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
mat_kernel
.
data
));
openCLExecuteKernel
(
clCxt
,
&
filter_sep_row
,
kernelName
,
globalThreads
,
localThreads
,
args
,
channels
,
src
.
depth
(),
compile_option
);
openCLExecuteKernel
(
src
.
clCxt
,
&
filter_sep_row
,
"row_filter"
,
globalThreads
,
localThreads
,
args
,
channels
,
src
.
depth
(),
buildOptions
.
c_str
());
}
Ptr
<
BaseRowFilter_GPU
>
cv
::
ocl
::
getLinearRowFilter_GPU
(
int
srcType
,
int
/*bufType*/
,
const
Mat
&
rowKernel
,
int
anchor
,
int
bordertype
)
...
...
modules/ocl/src/opencl/filter_sep_col.cl
View file @
4e57f92e
...
...
@@ -47,36 +47,6 @@
#
define
READ_TIMES_ROW
((
2*
(
RADIUS+LSIZE0
)
-1
)
/LSIZE0
)
#
endif
#
ifdef
BORDER_CONSTANT
//BORDER_CONSTANT:
iiiiii|abcdefgh|iiiiiii
#
define
ELEM
(
i,l_edge,r_edge,elem1,elem2
)
(
i
)
<
(
l_edge
)
| (i) >= (r_edge) ? (elem1) : (elem2)
#endif
#ifdef BORDER_REPLICATE
//BORDER_REPLICATE: aaaaaa|abcdefgh|hhhhhhh
#define ADDR_L(i,l_edge,r_edge) (i) < (l_edge) ? (l_edge) : (i)
#define ADDR_R(i,r_edge,addr) (i) >= (r_edge) ? (r_edge)-1 : (addr)
#endif
#ifdef BORDER_REFLECT
//BORDER_REFLECT: fedcba|abcdefgh|hgfedcb
#define ADDR_L(i,l_edge,r_edge) (i) < (l_edge) ? -(i)-1 : (i)
#define ADDR_R(i,r_edge,addr) (i) >= (r_edge) ? -(i)-1+((r_edge)<<1) : (addr)
#endif
#ifdef BORDER_REFLECT_101
//BORDER_REFLECT_101: gfedcb|abcdefgh|gfedcba
#define ADDR_L(i,l_edge,r_edge) (i) < (l_edge) ? -(i) : (i)
#define ADDR_R(i,r_edge,addr) (i) >= (r_edge) ? -(i)-2+((r_edge)<<1) : (addr)
#endif
#ifdef BORDER_WRAP
//BORDER_WRAP: cdefgh|abcdefgh
|
abcdefg
#
define
ADDR_L
(
i,l_edge,r_edge
)
(
i
)
<
(
l_edge
)
?
(
i
)
+
(
r_edge
)
:
(
i
)
#
define
ADDR_R
(
i,r_edge,addr
)
(
i
)
>=
(
r_edge
)
?
(
i
)
-
(
r_edge
)
:
(
addr
)
#
endif
/**********************************************************************************
These
kernels
are
written
for
separable
filters
such
as
Sobel,
Scharr,
GaussianBlur.
Now
(
6/29/2011
)
the
kernels
only
support
8U
data
type
and
the
anchor
of
the
convovle
...
...
@@ -107,15 +77,16 @@ __kernel __attribute__((reqd_work_group_size(LSIZE0,LSIZE1,1))) void col_filter
{
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
l_x
=
get_local_id
(
0
)
;
int
l_y
=
get_local_id
(
1
)
;
int
start_addr
=
mad24
(
y,src_step_in_pixel,x
)
;
int
end_addr
=
mad24
(
src_whole_rows
-
1
,
src_step_in_pixel,src_whole_cols
)
;
int
i
;
GENTYPE_SRC
sum
;
GENTYPE_SRC
temp[READ_TIMES_COL]
;
__local
GENTYPE_SRC
LDS_DAT[LSIZE1*READ_TIMES_COL][LSIZE0+1]
;
int
start_addr
=
mad24
(
y,
src_step_in_pixel,
x
)
;
int
end_addr
=
mad24
(
src_whole_rows
-
1
,
src_step_in_pixel,
src_whole_cols
)
;
int
i
;
GENTYPE_SRC
sum,
temp[READ_TIMES_COL]
;
__local
GENTYPE_SRC
LDS_DAT[LSIZE1
*
READ_TIMES_COL][LSIZE0
+
1]
;
//read
pixels
from
src
for
(
i
=
0
;i<READ_TIMES_COL;i++)
...
...
modules/ocl/src/opencl/filter_sep_row.cl
View file @
4e57f92e
This diff is collapsed.
Click to expand it.
modules/ocl/test/test_filters.cpp
View file @
4e57f92e
...
...
@@ -403,7 +403,7 @@ INSTANTIATE_TEST_CASE_P(Filter, SobelTest, Combine(
Bool
()));
INSTANTIATE_TEST_CASE_P
(
Filter
,
ScharrTest
,
Combine
(
Values
(
CV_8UC1
,
CV_8UC3
,
CV_8UC4
,
CV_32FC1
,
CV_32FC4
),
Values
(
CV_8UC1
,
CV_8UC3
,
CV_8UC4
,
CV_32FC1
,
CV_32FC
3
,
CV_32FC
4
),
Values
(
0
),
// not used
Values
(
Size
(
0
,
1
),
Size
(
1
,
0
)),
Values
((
int
)
BORDER_CONSTANT
,
(
int
)
BORDER_REFLECT101
,
...
...
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