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
07309635
Commit
07309635
authored
Sep 24, 2013
by
Ilya Lavrenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored and extended ocl::compare
parent
8e0e352d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
54 deletions
+106
-54
arithm.cpp
modules/ocl/src/arithm.cpp
+32
-54
arithm_compare.cl
modules/ocl/src/opencl/arithm_compare.cl
+74
-0
arithm_compare_eq.cl
modules/ocl/src/opencl/arithm_compare_eq.cl
+0
-0
arithm_compare_ne.cl
modules/ocl/src/opencl/arithm_compare_ne.cl
+0
-0
No files found.
modules/ocl/src/arithm.cpp
View file @
07309635
...
...
@@ -82,8 +82,7 @@ namespace cv
extern
const
char
*
arithm_bitwise_binary_scalar
;
extern
const
char
*
arithm_bitwise_binary_scalar_mask
;
extern
const
char
*
arithm_bitwise_not
;
extern
const
char
*
arithm_compare_eq
;
extern
const
char
*
arithm_compare_ne
;
extern
const
char
*
arithm_compare
;
extern
const
char
*
arithm_transpose
;
extern
const
char
*
arithm_flip
;
extern
const
char
*
arithm_flip_rc
;
...
...
@@ -268,76 +267,55 @@ void cv::ocl::absdiff(const oclMat &src1, const Scalar &src2, oclMat &dst)
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////// compare ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
static
void
compare_run
(
const
oclMat
&
src1
,
const
oclMat
&
src2
,
oclMat
&
dst
,
string
kernelName
,
const
char
**
kernelString
)
static
void
compare_run
(
const
oclMat
&
src1
,
const
oclMat
&
src2
,
oclMat
&
dst
,
int
cmpOp
,
string
kernelName
,
const
char
**
kernelString
)
{
dst
.
create
(
src1
.
size
(),
CV_8UC1
);
CV_Assert
(
src1
.
oclchannels
()
==
1
);
CV_Assert
(
src1
.
type
()
==
src2
.
type
());
Context
*
clCxt
=
src1
.
clCxt
;
dst
.
create
(
src1
.
size
(),
CV_8UC1
);
Context
*
clCxt
=
src1
.
clCxt
;
int
depth
=
src1
.
depth
();
int
vector_lengths
[
7
]
=
{
4
,
0
,
4
,
4
,
4
,
4
,
4
};
size_t
vector_length
=
vector_lengths
[
depth
];
int
offset_cols
=
(
dst
.
offset
/
dst
.
elemSize1
())
&
(
vector_length
-
1
);
int
cols
=
divUp
(
dst
.
cols
+
offset_cols
,
vector_length
);
size_t
localThreads
[
3
]
=
{
64
,
4
,
1
};
size_t
globalThreads
[
3
]
=
{
cols
,
dst
.
rows
,
1
};
size_t
globalThreads
[
3
]
=
{
dst
.
cols
,
dst
.
rows
,
1
};
int
src1step1
=
src1
.
step1
(),
src1offset1
=
src1
.
offset
/
src1
.
elemSize1
();
int
src2step1
=
src2
.
step1
(),
src2offset1
=
src2
.
offset
/
src2
.
elemSize1
();
int
dststep1
=
dst
.
step1
(),
dstoffset1
=
dst
.
offset
/
dst
.
elemSize1
();
const
char
*
const
typeMap
[]
=
{
"uchar"
,
"char"
,
"ushort"
,
"short"
,
"int"
,
"float"
,
"double"
};
const
char
*
operationMap
[]
=
{
"=="
,
">"
,
">="
,
"<"
,
"<="
,
"!="
};
std
::
string
buildOptions
=
format
(
"-D T=%s -D Operation=%s"
,
typeMap
[
depth
],
operationMap
[
cmpOp
]);
int
dst_step1
=
dst
.
cols
*
dst
.
elemSize
();
vector
<
pair
<
size_t
,
const
void
*>
>
args
;
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
src1
.
data
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
src1
.
step
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
src1
.
offset
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
src1
step1
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
src1
offset1
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
src2
.
data
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
src2
.
step
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
src2
.
offset
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
src2
step1
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
src2
offset1
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
dst
.
data
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
dst
.
step
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
dst
.
offset
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
dststep1
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
dstoffset1
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
src1
.
cols
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
src1
.
rows
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
cols
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
dst_step1
));
openCLExecuteKernel
(
clCxt
,
kernelString
,
kernelName
,
globalThreads
,
localThreads
,
args
,
-
1
,
depth
);
openCLExecuteKernel
(
clCxt
,
kernelString
,
kernelName
,
globalThreads
,
localThreads
,
args
,
-
1
,
-
1
,
buildOptions
.
c_str
()
);
}
void
cv
::
ocl
::
compare
(
const
oclMat
&
src1
,
const
oclMat
&
src2
,
oclMat
&
dst
,
int
cmpOp
)
{
if
(
!
src1
.
clCxt
->
supportsFeature
(
Context
::
CL_DOUBLE
)
&&
src1
.
type
()
==
CV_64F
)
if
(
!
src1
.
clCxt
->
supportsFeature
(
Context
::
CL_DOUBLE
)
&&
src1
.
depth
()
==
CV_64F
)
{
cout
<<
"Selected device do not support double"
<<
endl
;
return
;
}
string
kernelName
;
const
char
**
kernelString
=
NULL
;
switch
(
cmpOp
)
{
case
CMP_EQ
:
kernelName
=
"arithm_compare_eq"
;
kernelString
=
&
arithm_compare_eq
;
break
;
case
CMP_GT
:
kernelName
=
"arithm_compare_gt"
;
kernelString
=
&
arithm_compare_eq
;
break
;
case
CMP_GE
:
kernelName
=
"arithm_compare_ge"
;
kernelString
=
&
arithm_compare_eq
;
break
;
case
CMP_NE
:
kernelName
=
"arithm_compare_ne"
;
kernelString
=
&
arithm_compare_ne
;
break
;
case
CMP_LT
:
kernelName
=
"arithm_compare_lt"
;
kernelString
=
&
arithm_compare_ne
;
break
;
case
CMP_LE
:
kernelName
=
"arithm_compare_le"
;
kernelString
=
&
arithm_compare_ne
;
break
;
default
:
CV_Error
(
CV_StsBadArg
,
"Unknown comparison method"
);
}
compare_run
(
src1
,
src2
,
dst
,
kernelName
,
kernelString
);
CV_Assert
(
src1
.
channels
()
==
1
&&
src2
.
channels
()
==
1
);
CV_Assert
(
cmpOp
>=
CMP_EQ
&&
cmpOp
<=
CMP_NE
);
compare_run
(
src1
,
src2
,
dst
,
cmpOp
,
"arithm_compare"
,
&
arithm_compare
);
}
//////////////////////////////////////////////////////////////////////////////
...
...
modules/ocl/src/opencl/arithm_compare.cl
0 → 100644
View file @
07309635
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//
IMPORTANT:
READ
BEFORE
DOWNLOADING,
COPYING,
INSTALLING
OR
USING.
//
//
By
downloading,
copying,
installing
or
using
the
software
you
agree
to
this
license.
//
If
you
do
not
agree
to
this
license,
do
not
download,
install,
//
copy
or
use
the
software.
//
//
//
License
Agreement
//
For
Open
Source
Computer
Vision
Library
//
//
Copyright
(
C
)
2010-2012,
Institute
Of
Software
Chinese
Academy
Of
Science,
all
rights
reserved.
//
Copyright
(
C
)
2010-2012,
Advanced
Micro
Devices,
Inc.,
all
rights
reserved.
//
Third
party
copyrights
are
property
of
their
respective
owners.
//
//
@Authors
//
Jia
Haipeng,
jiahaipeng95@gmail.com
//
//
Redistribution
and
use
in
source
and
binary
forms,
with
or
without
modification,
//
are
permitted
provided
that
the
following
conditions
are
met:
//
//
*
Redistribution
's
of
source
code
must
retain
the
above
copyright
notice,
//
this
list
of
conditions
and
the
following
disclaimer.
//
//
*
Redistribution
's
in
binary
form
must
reproduce
the
above
copyright
notice,
//
this
list
of
conditions
and
the
following
disclaimer
in
the
documentation
//
and/or
other
oclMaterials
provided
with
the
distribution.
//
//
*
The
name
of
the
copyright
holders
may
not
be
used
to
endorse
or
promote
products
//
derived
from
this
software
without
specific
prior
written
permission.
//
//
This
software
is
provided
by
the
copyright
holders
and
contributors
as
is
and
//
any
express
or
implied
warranties,
including,
but
not
limited
to,
the
implied
//
warranties
of
merchantability
and
fitness
for
a
particular
purpose
are
disclaimed.
//
In
no
event
shall
the
Intel
Corporation
or
contributors
be
liable
for
any
direct,
//
indirect,
incidental,
special,
exemplary,
or
consequential
damages
//
(
including,
but
not
limited
to,
procurement
of
substitute
goods
or
services
;
//
loss
of
use,
data,
or
profits
; or business interruption) however caused
//
and
on
any
theory
of
liability,
whether
in
contract,
strict
liability,
//
or
tort
(
including
negligence
or
otherwise
)
arising
in
any
way
out
of
//
the
use
of
this
software,
even
if
advised
of
the
possibility
of
such
damage.
//
//M*/
#
if
defined
(
DOUBLE_SUPPORT
)
#
ifdef
cl_khr_fp64
#
pragma
OPENCL
EXTENSION
cl_khr_fp64:enable
#
elif
defined
(
cl_amd_fp64
)
#
pragma
OPENCL
EXTENSION
cl_amd_fp64:enable
#
endif
#
endif
//////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////addWeighted//////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
__kernel
void
arithm_compare
(
__global
T
*
src1,
int
src1_step1,
int
src1_offset1,
__global
T
*
src2,
int
src2_step1,
int
src2_offset1,
__global
uchar
*
dst,
int
dst_step1,
int
dst_offset1,
int
cols1,
int
rows
)
{
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
if
(
x
<
cols1
&&
y
<
rows
)
{
int
src1_index
=
mad24
(
y,
src1_step1,
x
+
src1_offset1
)
;
int
src2_index
=
mad24
(
y,
src2_step1,
x
+
src2_offset1
)
;
int
dst_index
=
mad24
(
y,
dst_step1,
x
+
dst_offset1
)
;
dst[dst_index]
=
convert_uchar
(
src1[src1_index]
Operation
src2[src2_index]
?
255
:
0
)
;
}
}
modules/ocl/src/opencl/arithm_compare_eq.cl
deleted
100644 → 0
View file @
8e0e352d
This diff is collapsed.
Click to expand it.
modules/ocl/src/opencl/arithm_compare_ne.cl
deleted
100644 → 0
View file @
8e0e352d
This diff is collapsed.
Click to expand it.
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