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
c0d76ef9
Commit
c0d76ef9
authored
Jan 13, 2015
by
Alexander Smorkalov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
driver_api_stereo_multi sample reworked to use parallel_for_ instead of parallel_do
parent
72063bf1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
32 deletions
+23
-32
driver_api_stereo_multi.cpp
samples/gpu/driver_api_stereo_multi.cpp
+23
-32
No files found.
samples/gpu/driver_api_stereo_multi.cpp
View file @
c0d76ef9
...
...
@@ -13,25 +13,12 @@
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
#if !defined(HAVE_CUDA) || !defined(HAVE_TBB) || defined(__arm__)
#if defined(__arm__)
int
main
()
{
#if !defined(HAVE_CUDA)
std
::
cout
<<
"CUDA support is required (CMake key 'WITH_CUDA' must be true).
\n
"
;
#endif
#if !defined(HAVE_TBB)
std
::
cout
<<
"TBB support is required (CMake key 'WITH_TBB' must be true).
\n
"
;
#endif
#if defined(__arm__)
std
::
cout
<<
"Unsupported for ARM CUDA library."
<<
std
::
endl
;
#endif
return
0
;
}
#else
#include <cuda.h>
...
...
@@ -42,7 +29,6 @@ using namespace std;
using
namespace
cv
;
using
namespace
cv
::
gpu
;
struct
Worker
{
void
operator
()(
int
device_id
)
const
;
};
void
destroyContexts
();
#define safeCall(expr) safeCall_(expr, #expr, __FILE__, __LINE__)
...
...
@@ -77,6 +63,27 @@ GpuMat d_right[2];
StereoBM_GPU
*
bm
[
2
];
GpuMat
d_result
[
2
];
struct
Worker
:
public
ParallelLoopBody
{
virtual
void
operator
()
(
const
Range
&
range
)
const
{
for
(
int
device_id
=
range
.
start
;
device_id
!=
range
.
end
;
++
device_id
)
{
contextOn
(
device_id
);
bm
[
device_id
]
->
operator
()(
d_left
[
device_id
],
d_right
[
device_id
],
d_result
[
device_id
]);
std
::
cout
<<
"GPU #"
<<
device_id
<<
" ("
<<
DeviceInfo
().
name
()
<<
"): finished
\n
"
;
contextOff
();
}
}
};
static
void
printHelp
()
{
std
::
cout
<<
"Usage: driver_api_stereo_multi_gpu --left <left_image> --right <right_image>
\n
"
;
...
...
@@ -162,8 +169,7 @@ int main(int argc, char** argv)
contextOff
();
// Execute calculation in two threads using two GPUs
int
devices
[]
=
{
0
,
1
};
parallel_do
(
devices
,
devices
+
2
,
Worker
());
parallel_for_
(
cv
::
Range
(
0
,
2
,
Worker
());
// Release the first GPU resources
contextOn
(
0
);
...
...
@@ -188,21 +194,6 @@ int main(int argc, char** argv)
return
0
;
}
void
Worker
::
operator
()(
int
device_id
)
const
{
contextOn
(
device_id
);
bm
[
device_id
]
->
operator
()(
d_left
[
device_id
],
d_right
[
device_id
],
d_result
[
device_id
]);
std
::
cout
<<
"GPU #"
<<
device_id
<<
" ("
<<
DeviceInfo
().
name
()
<<
"): finished
\n
"
;
contextOff
();
}
void
destroyContexts
()
{
safeCall
(
cuCtxDestroy
(
contexts
[
0
]));
...
...
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