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
40c76b9d
Commit
40c76b9d
authored
Aug 09, 2012
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.x related fixes
parent
3f68e5bb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
310 additions
and
131 deletions
+310
-131
perf_labeling.cpp
modules/gpu/perf/perf_labeling.cpp
+3
-1
perf_labeling.cpp
modules/gpu/perf_cpu/perf_labeling.cpp
+158
-0
ccomponetns.cu
modules/gpu/src/cuda/ccomponetns.cu
+5
-4
graphcuts.cpp
modules/gpu/src/graphcuts.cpp
+0
-0
emulation.hpp
modules/gpu/src/opencv2/gpu/device/emulation.hpp
+137
-125
test_labeling.cpp
modules/gpu/test/test_labeling.cpp
+7
-1
No files found.
modules/gpu/perf/perf_labeling.cpp
View file @
40c76b9d
...
@@ -48,7 +48,9 @@ GPU_PERF_TEST(ConnectedComponents, cv::gpu::DeviceInfo, cv::Size)
...
@@ -48,7 +48,9 @@ GPU_PERF_TEST(ConnectedComponents, cv::gpu::DeviceInfo, cv::Size)
cv
::
gpu
::
DeviceInfo
devInfo
=
GET_PARAM
(
0
);
cv
::
gpu
::
DeviceInfo
devInfo
=
GET_PARAM
(
0
);
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
cv
::
Mat
image
=
readImage
(
"gpu/labeling/label.png"
,
cv
::
IMREAD_GRAYSCALE
);
cv
::
Mat
image
=
readImage
(
"gpu/labeling/aloe-disp.png"
,
cv
::
IMREAD_GRAYSCALE
);
cv
::
threshold
(
image
,
image
,
150
,
255
,
CV_THRESH_BINARY
);
cv
::
gpu
::
GpuMat
mask
;
cv
::
gpu
::
GpuMat
mask
;
mask
.
create
(
image
.
rows
,
image
.
cols
,
CV_8UC1
);
mask
.
create
(
image
.
rows
,
image
.
cols
,
CV_8UC1
);
...
...
modules/gpu/perf_cpu/perf_labeling.cpp
0 → 100644
View file @
40c76b9d
/*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) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials 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*/
#include "perf_precomp.hpp"
#ifdef HAVE_CUDA
namespace
{
struct
GreedyLabeling
{
struct
dot
{
int
x
;
int
y
;
static
dot
make
(
int
i
,
int
j
)
{
dot
d
;
d
.
x
=
i
;
d
.
y
=
j
;
return
d
;
}
};
struct
InInterval
{
InInterval
(
const
int
&
_lo
,
const
int
&
_hi
)
:
lo
(
-
_lo
),
hi
(
_hi
)
{};
const
int
lo
,
hi
;
bool
operator
()
(
const
unsigned
char
a
,
const
unsigned
char
b
)
const
{
int
d
=
a
-
b
;
return
lo
<=
d
&&
d
<=
hi
;
}
};
GreedyLabeling
(
cv
::
Mat
img
)
:
image
(
img
),
_labels
(
image
.
size
(),
CV_32SC1
,
cv
::
Scalar
::
all
(
-
1
))
{
stack
=
new
dot
[
image
.
cols
*
image
.
rows
];}
~
GreedyLabeling
(){
delete
[]
stack
;}
void
operator
()
(
cv
::
Mat
labels
)
const
{
InInterval
inInt
(
0
,
2
);
int
cc
=
-
1
;
int
*
dist_labels
=
(
int
*
)
labels
.
data
;
int
pitch
=
labels
.
step1
();
unsigned
char
*
source
=
(
unsigned
char
*
)
image
.
data
;
int
width
=
image
.
cols
;
int
height
=
image
.
rows
;
for
(
int
j
=
0
;
j
<
image
.
rows
;
++
j
)
for
(
int
i
=
0
;
i
<
image
.
cols
;
++
i
)
{
if
(
dist_labels
[
j
*
pitch
+
i
]
!=
-
1
)
continue
;
dot
*
top
=
stack
;
dot
p
=
dot
::
make
(
i
,
j
);
cc
++
;
dist_labels
[
j
*
pitch
+
i
]
=
cc
;
while
(
top
>=
stack
)
{
int
*
dl
=
&
dist_labels
[
p
.
y
*
pitch
+
p
.
x
];
unsigned
char
*
sp
=
&
source
[
p
.
y
*
image
.
step1
()
+
p
.
x
];
dl
[
0
]
=
cc
;
//right
if
(
p
.
x
<
(
width
-
1
)
&&
dl
[
+
1
]
==
-
1
&&
inInt
(
sp
[
0
],
sp
[
+
1
]))
*
top
++
=
dot
::
make
(
p
.
x
+
1
,
p
.
y
);
//left
if
(
p
.
x
>
0
&&
dl
[
-
1
]
==
-
1
&&
inInt
(
sp
[
0
],
sp
[
-
1
]))
*
top
++
=
dot
::
make
(
p
.
x
-
1
,
p
.
y
);
//bottom
if
(
p
.
y
<
(
height
-
1
)
&&
dl
[
+
pitch
]
==
-
1
&&
inInt
(
sp
[
0
],
sp
[
+
image
.
step1
()]))
*
top
++
=
dot
::
make
(
p
.
x
,
p
.
y
+
1
);
//top
if
(
p
.
y
>
0
&&
dl
[
-
pitch
]
==
-
1
&&
inInt
(
sp
[
0
],
sp
[
-
image
.
step1
()]))
*
top
++
=
dot
::
make
(
p
.
x
,
p
.
y
-
1
);
p
=
*--
top
;
}
}
}
cv
::
Mat
image
;
cv
::
Mat
_labels
;
dot
*
stack
;
};
}
GPU_PERF_TEST
(
ConnectedComponents
,
cv
::
gpu
::
DeviceInfo
,
cv
::
Size
)
{
cv
::
gpu
::
DeviceInfo
devInfo
=
GET_PARAM
(
0
);
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
cv
::
Mat
image
=
readImage
(
"gpu/labeling/aloe-disp.png"
,
cv
::
IMREAD_GRAYSCALE
);
GreedyLabeling
host
(
image
);
host
(
host
.
_labels
);
declare
.
time
(
1.0
);
TEST_CYCLE
()
{
host
(
host
.
_labels
);
}
}
INSTANTIATE_TEST_CASE_P
(
Labeling
,
ConnectedComponents
,
testing
::
Combine
(
ALL_DEVICES
,
testing
::
Values
(
cv
::
Size
(
261
,
262
))));
#endif
\ No newline at end of file
modules/gpu/src/cuda/ccomponetns.cu
View file @
40c76b9d
...
@@ -42,6 +42,7 @@
...
@@ -42,6 +42,7 @@
#include <opencv2/gpu/device/common.hpp>
#include <opencv2/gpu/device/common.hpp>
#include <opencv2/gpu/device/vec_traits.hpp>
#include <opencv2/gpu/device/vec_traits.hpp>
#include <opencv2/gpu/device/vec_math.hpp>
#include <opencv2/gpu/device/vec_math.hpp>
#include <opencv2/gpu/device/emulation.hpp>
#include <iostream>
#include <iostream>
#include <stdio.h>
#include <stdio.h>
...
@@ -255,8 +256,7 @@ namespace cv { namespace gpu { namespace device
...
@@ -255,8 +256,7 @@ namespace cv { namespace gpu { namespace device
edgesTile[yloc][xloc] = c;
edgesTile[yloc][xloc] = c;
}
}
for (int k = 0; ;++k)
for (int i = 0; ; ++i)
{
{
//1. backup
//1. backup
#pragma unroll
#pragma unroll
...
@@ -312,11 +312,12 @@ namespace cv { namespace gpu { namespace device
...
@@ -312,11 +312,12 @@ namespace cv { namespace gpu { namespace device
if (new_labels[i][j] < old_labels[i][j])
if (new_labels[i][j] < old_labels[i][j])
{
{
changed = 1;
changed = 1;
atomicMin(&labelsTile[0][0] + old_labels[i][j], new_labels[i][j]);
Emulation::smem::
atomicMin(&labelsTile[0][0] + old_labels[i][j], new_labels[i][j]);
}
}
}
}
changed = __syncthreads_or(changed);
changed = Emulation::sycthOr(changed);
if (!changed)
if (!changed)
break;
break;
...
...
modules/gpu/src/graphcuts.cpp
View file @
40c76b9d
This diff is collapsed.
Click to expand it.
modules/gpu/src/opencv2/gpu/device/emulation.hpp
View file @
40c76b9d
/*M///////////////////////////////////////////////////////////////////////////////////////
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//
// By downloading, copying, installing or using the software you agree to this license.
// 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,
// If you do not agree to this license, do not download, install,
// copy or use the software.
// copy or use the software.
//
//
//
//
// License Agreement
// License Agreement
// For Open Source Computer Vision Library
// For Open Source Computer Vision Library
//
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
// Third party copyrights are property of their respective owners.
//
//
// Redistribution and use in source and binary forms, with or without modification,
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// are permitted provided that the following conditions are met:
//
//
// * Redistribution's of source code must retain the above copyright notice,
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// this list of conditions and the following disclaimer.
//
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// and/or other materials provided with the distribution.
//
//
// * The name of the copyright holders may not be used to endorse or promote products
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// derived from this software without specific prior written permission.
//
//
// This software is provided by the copyright holders and contributors "as is" and
// This software is provided by the copyright holders and contributors "as is" and
// any express or bpied warranties, including, but not limited to, the bpied
// any express or bpied warranties, including, but not limited to, the bpied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// 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,
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// 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.
// the use of this software, even if advised of the possibility of such damage.
//
//
//M*/
//M*/
#ifndef OPENCV_GPU_EMULATION_HPP_
#ifndef OPENCV_GPU_EMULATION_HPP_
#define OPENCV_GPU_EMULATION_HPP_
#define OPENCV_GPU_EMULATION_HPP_
#include "warp_reduce.hpp"
#include "warp_reduce.hpp"
#include <stdio.h>
#include <stdio.h>
namespace
cv
{
namespace
gpu
{
namespace
device
namespace
cv
{
namespace
gpu
{
namespace
device
{
{
struct
Emulation
struct
Emulation
{
{
template
<
int
CTA_SIZE
>
static
__forceinline__
__device__
int
Ballot
(
int
predicate
)
static
__device__
__forceinline__
int
sycthOr
(
int
pred
)
{
{
#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ >= 200)
#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120)
return
__ballot
(
predicate
);
// just campilation stab
#else
return
false
;
__shared__
volatile
int
cta_buffer
[
CTA_SIZE
];
#else
return
__syncthreads_or
(
pred
);
int
tid
=
threadIdx
.
x
;
#endif
cta_buffer
[
tid
]
=
predicate
?
(
1
<<
(
tid
&
31
))
:
0
;
}
return
warp_reduce
(
cta_buffer
);
#endif
template
<
int
CTA_SIZE
>
}
static
__forceinline__
__device__
int
Ballot
(
int
predicate
)
{
struct
smem
#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ >= 200)
{
return
__ballot
(
predicate
);
enum
{
TAG_MASK
=
(
1U
<<
(
(
sizeof
(
unsigned
int
)
<<
3
)
-
5U
))
-
1U
};
#else
__shared__
volatile
int
cta_buffer
[
CTA_SIZE
];
template
<
typename
T
>
static
__device__
__forceinline__
T
atomicInc
(
T
*
address
,
T
val
)
int
tid
=
threadIdx
.
x
;
{
cta_buffer
[
tid
]
=
predicate
?
(
1
<<
(
tid
&
31
))
:
0
;
#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120)
return
warp_reduce
(
cta_buffer
);
T
count
;
#endif
unsigned
int
tag
=
threadIdx
.
x
<<
(
(
sizeof
(
unsigned
int
)
<<
3
)
-
5U
);
}
do
{
struct
smem
count
=
*
address
&
TAG_MASK
;
{
count
=
tag
|
(
count
+
1
);
enum
{
TAG_MASK
=
(
1U
<<
(
(
sizeof
(
unsigned
int
)
<<
3
)
-
5U
))
-
1U
};
*
address
=
count
;
}
while
(
*
address
!=
count
);
template
<
typename
T
>
static
__device__
__forceinline__
T
atomicInc
(
T
*
address
,
T
val
)
return
(
count
&
TAG_MASK
)
-
1
;
{
#else
#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120)
return
::
atomicInc
(
address
,
val
);
T
count
;
#endif
unsigned
int
tag
=
threadIdx
.
x
<<
(
(
sizeof
(
unsigned
int
)
<<
3
)
-
5U
);
}
do
{
template
<
typename
T
>
count
=
*
address
&
TAG_MASK
;
static
__device__
__forceinline__
void
atomicAdd
(
T
*
address
,
T
val
)
count
=
tag
|
(
count
+
1
);
{
*
address
=
count
;
#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120)
}
while
(
*
address
!=
count
);
T
count
;
unsigned
int
tag
=
threadIdx
.
x
<<
(
(
sizeof
(
unsigned
int
)
<<
3
)
-
5U
);
return
(
count
&
TAG_MASK
)
-
1
;
do
#else
{
return
::
atomicInc
(
address
,
val
);
count
=
*
address
&
TAG_MASK
;
#endif
count
=
tag
|
(
count
+
val
);
}
*
address
=
count
;
}
while
(
*
address
!=
count
);
template
<
typename
T
>
#else
static
__device__
__forceinline__
void
atomicAdd
(
T
*
address
,
T
val
)
::
atomicAdd
(
address
,
val
);
{
#endif
#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120)
}
T
count
;
unsigned
int
tag
=
threadIdx
.
x
<<
(
(
sizeof
(
unsigned
int
)
<<
3
)
-
5U
);
template
<
typename
T
>
do
static
__device__
__forceinline__
T
atomicMin
(
T
*
address
,
T
val
)
{
{
count
=
*
address
&
TAG_MASK
;
#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120)
count
=
tag
|
(
count
+
val
);
T
count
=
min
(
*
address
,
val
);
*
address
=
count
;
do
}
while
(
*
address
!=
count
);
{
#else
*
address
=
count
;
::
atomicAdd
(
address
,
val
);
}
while
(
*
address
>
count
);
#endif
}
return
count
;
#else
template
<
typename
T
>
return
::
atomicMin
(
address
,
val
);
static
__device__
__forceinline__
T
atomicMin
(
T
*
address
,
T
val
)
#endif
{
}
#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120)
};
T
count
=
min
(
*
address
,
val
);
};
do
}}}
// namespace cv { namespace gpu { namespace device
{
*
address
=
count
;
}
while
(
*
address
>
count
);
return
count
;
#else
return
::
atomicMin
(
address
,
val
);
#endif
}
};
};
}}}
// namespace cv { namespace gpu { namespace device
#endif
/* OPENCV_GPU_EMULATION_HPP_ */
#endif
/* OPENCV_GPU_EMULATION_HPP_ */
\ No newline at end of file
modules/gpu/test/test_labeling.cpp
View file @
40c76b9d
...
@@ -164,7 +164,7 @@ struct Labeling : testing::TestWithParam<cv::gpu::DeviceInfo>
...
@@ -164,7 +164,7 @@ struct Labeling : testing::TestWithParam<cv::gpu::DeviceInfo>
cv
::
Mat
loat_image
()
cv
::
Mat
loat_image
()
{
{
return
cv
::
imread
(
std
::
string
(
cvtest
::
TS
::
ptr
()
->
get_data_path
()
)
+
"labeling/
label.png
"
);
return
cv
::
imread
(
std
::
string
(
cvtest
::
TS
::
ptr
()
->
get_data_path
()
)
+
"labeling/
IMG_0727.JPG
"
);
}
}
};
};
...
@@ -173,6 +173,8 @@ TEST_P(Labeling, ConnectedComponents)
...
@@ -173,6 +173,8 @@ TEST_P(Labeling, ConnectedComponents)
cv
::
Mat
image
;
cv
::
Mat
image
;
cvtColor
(
loat_image
(),
image
,
CV_BGR2GRAY
);
cvtColor
(
loat_image
(),
image
,
CV_BGR2GRAY
);
cv
::
threshold
(
image
,
image
,
150
,
255
,
CV_THRESH_BINARY
);
ASSERT_TRUE
(
image
.
type
()
==
CV_8UC1
);
ASSERT_TRUE
(
image
.
type
()
==
CV_8UC1
);
GreedyLabeling
host
(
image
);
GreedyLabeling
host
(
image
);
...
@@ -189,6 +191,10 @@ TEST_P(Labeling, ConnectedComponents)
...
@@ -189,6 +191,10 @@ TEST_P(Labeling, ConnectedComponents)
ASSERT_NO_THROW
(
cv
::
gpu
::
labelComponents
(
mask
,
components
));
ASSERT_NO_THROW
(
cv
::
gpu
::
labelComponents
(
mask
,
components
));
host
.
checkCorrectness
(
cv
::
Mat
(
components
));
host
.
checkCorrectness
(
cv
::
Mat
(
components
));
cv
::
imshow
(
"test"
,
image
);
cv
::
waitKey
(
0
);
cv
::
imshow
(
"test"
,
host
.
_labels
);
cv
::
waitKey
(
0
);
}
}
INSTANTIATE_TEST_CASE_P
(
ConnectedComponents
,
Labeling
,
ALL_DEVICES
);
INSTANTIATE_TEST_CASE_P
(
ConnectedComponents
,
Labeling
,
ALL_DEVICES
);
...
...
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