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
efe0b774
Commit
efe0b774
authored
Jun 09, 2011
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reverted wrong commit for one of gpu samples
parent
ace94d2e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
38 deletions
+19
-38
driver_api_stereo_multi.cpp
samples/gpu/driver_api_stereo_multi.cpp
+19
-38
No files found.
samples/gpu/driver_api_stereo_multi.cpp
View file @
efe0b774
...
...
@@ -32,11 +32,7 @@ int main()
#include <cuda.h>
#include <cuda_runtime.h>
#include <GL/gl.h>
#include <cudaGL.h>
#include "opencv2/core/internal.hpp" // For TBB wrappers
#include "tbb/tbb.h"
#include "tbb/mutex.h"
using
namespace
std
;
using
namespace
cv
;
...
...
@@ -58,14 +54,14 @@ inline void safeCall_(int code, const char* expr, const char* file, int line)
}
// Each GPU is associated with its own context
CUcontext
contexts
[
/*2*/
1
];
CUcontext
contexts
[
2
];
void
inline
contextOn
(
int
id
)
void
inline
contextOn
(
int
id
)
{
safeCall
(
cuCtxPushCurrent
(
contexts
[
id
]));
}
void
inline
contextOff
()
void
inline
contextOff
()
{
CUcontext
prev_context
;
safeCall
(
cuCtxPopCurrent
(
&
prev_context
));
...
...
@@ -80,10 +76,6 @@ GpuMat d_result[2];
// CPU result
Mat
result
;
int
some
[
2
];
tbb
::
mutex
mutex
;
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
3
)
...
...
@@ -93,11 +85,11 @@ int main(int argc, char** argv)
}
int
num_devices
=
getCudaEnabledDeviceCount
();
//
if (num_devices < 2)
//
{
//
std::cout << "Two or more GPUs are required\n";
//
return -1;
//
}
if
(
num_devices
<
2
)
{
std
::
cout
<<
"Two or more GPUs are required
\n
"
;
return
-
1
;
}
for
(
int
i
=
0
;
i
<
num_devices
;
++
i
)
{
...
...
@@ -131,14 +123,13 @@ int main(int argc, char** argv)
// Create context for GPU #0
CUdevice
device
;
safeCall
(
cuDeviceGet
(
&
device
,
0
));
safeCall
(
cuGLCtxCreate
(
&
contexts
[
0
],
0
,
device
));
//safeCall(cuCtxCreate(&contexts[0], 0, device));
safeCall
(
cuCtxCreate
(
&
contexts
[
0
],
0
,
device
));
contextOff
();
//
// Create context for GPU #1
// safeCall(cuDeviceGet(&device, 0
));
//
safeCall(cuCtxCreate(&contexts[1], 0, device));
//
contextOff();
// Create context for GPU #1
safeCall
(
cuDeviceGet
(
&
device
,
1
));
safeCall
(
cuCtxCreate
(
&
contexts
[
1
],
0
,
device
));
contextOff
();
// Split source images for processing on GPU #0
contextOn
(
0
);
...
...
@@ -148,20 +139,15 @@ int main(int argc, char** argv)
contextOff
();
// Split source images for processing on the GPU #1
contextOn
(
0
);
contextOn
(
1
);
d_left
[
1
].
upload
(
left
.
rowRange
(
left
.
rows
/
2
,
left
.
rows
));
d_right
[
1
].
upload
(
right
.
rowRange
(
right
.
rows
/
2
,
right
.
rows
));
bm
[
1
]
=
new
StereoBM_GPU
();
contextOff
();
some
[
0
]
=
some
[
1
]
=
0
;
// Execute calculation in two threads using two GPUs
vector
<
int
>
devices
;
for
(
int
i
=
0
;
i
<
4
;
++
i
)
devices
.
push_back
(
rand
()
%
2
);
tbb
::
parallel_do
(
&
devices
[
0
],
&
devices
[
devices
.
size
()
-
1
],
Worker
());
cout
<<
some
[
0
]
<<
" "
<<
some
[
1
]
<<
endl
;
int
devices
[]
=
{
0
,
1
};
parallel_do
(
devices
,
devices
+
2
,
Worker
());
// Release the first GPU resources
contextOn
(
0
);
...
...
@@ -173,7 +159,7 @@ int main(int argc, char** argv)
contextOff
();
// Release the second GPU resources
contextOn
(
0
);
contextOn
(
1
);
imshow
(
"GPU #1 result"
,
Mat
(
d_result
[
1
]));
d_left
[
1
].
release
();
d_right
[
1
].
release
();
...
...
@@ -189,9 +175,7 @@ int main(int argc, char** argv)
void
Worker
::
operator
()(
int
device_id
)
const
{
mutex
.
lock
();
contextOn
(
0
);
contextOn
(
device_id
);
bm
[
device_id
]
->
operator
()(
d_left
[
device_id
],
d_right
[
device_id
],
d_result
[
device_id
]);
...
...
@@ -200,16 +184,13 @@ void Worker::operator()(int device_id) const
<<
"): finished
\n
"
;
contextOff
();
mutex
.
unlock
();
}
void
destroyContexts
()
{
safeCall
(
cuCtxDestroy
(
contexts
[
0
]));
//
safeCall(cuCtxDestroy(contexts[1]));
safeCall
(
cuCtxDestroy
(
contexts
[
1
]));
}
#endif
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