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
630d874e
Commit
630d874e
authored
Feb 16, 2012
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated the GPU performance sample
parent
c908c501
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
37 deletions
+47
-37
performance.cpp
samples/gpu/performance/performance.cpp
+11
-6
performance.h
samples/gpu/performance/performance.h
+36
-29
tests.cpp
samples/gpu/performance/tests.cpp
+0
-2
No files found.
samples/gpu/performance/performance.cpp
View file @
630d874e
...
...
@@ -60,14 +60,10 @@ void TestSystem::finishCurrentSubtest()
// There is no need to print subtest statistics
return
;
//int cpu_time = static_cast<int>(cpu_elapsed_ / getTickFrequency() * 1000.0);
//int gpu_time = static_cast<int>(gpu_elapsed_ / getTickFrequency() * 1000.0);
double
cpu_time
=
cpu_elapsed_
/
getTickFrequency
()
*
1000.0
;
double
gpu_time
=
gpu_elapsed_
/
getTickFrequency
()
*
1000.0
;
double
speedup
=
static_cast
<
double
>
(
cpu_elapsed_
)
/
std
::
max
((
int64
)
1
,
gpu_elapsed_
);
double
speedup
=
static_cast
<
double
>
(
cpu_elapsed_
)
/
std
::
max
((
int64
)
1
,
gpu_elapsed_
);
speedup_total_
+=
speedup
;
printMetrics
(
cpu_time
,
gpu_time
,
speedup
);
...
...
@@ -77,6 +73,15 @@ void TestSystem::finishCurrentSubtest()
}
double
TestSystem
::
meanTime
(
const
vector
<
int64
>
&
samples
)
{
double
sum
=
accumulate
(
samples
.
begin
(),
samples
.
end
(),
0.
);
if
(
samples
.
size
()
>
1
)
return
(
sum
-
samples
[
0
])
/
(
samples
.
size
()
-
1
);
return
sum
;
}
void
TestSystem
::
printHeading
()
{
cout
<<
endl
;
...
...
@@ -210,7 +215,7 @@ int main(int argc, const char* argv[])
if
(
list
)
TestSystem
::
instance
().
setListMode
(
true
);
TestSystem
::
instance
().
setIters
(
iters
);
TestSystem
::
instance
().
set
Num
Iters
(
iters
);
TestSystem
::
instance
().
run
();
...
...
samples/gpu/performance/performance.h
View file @
630d874e
...
...
@@ -41,7 +41,7 @@ public:
void
setTestFilter
(
const
std
::
string
&
val
)
{
test_filter_
=
val
;
}
const
std
::
string
&
testFilter
()
const
{
return
test_filter_
;
}
void
set
Iters
(
int
iters
)
{
iters_
=
iters
;
}
void
set
NumIters
(
int
num_iters
)
{
num_iters_
=
num_
iters
;
}
void
addInit
(
Runnable
*
init
)
{
inits_
.
push_back
(
init
);
}
void
addTest
(
Runnable
*
test
)
{
tests_
.
push_back
(
test
);
}
...
...
@@ -56,21 +56,20 @@ public:
return
cur_subtest_description_
;
}
bool
stop
()
const
{
return
it_
>=
iters_
;
}
bool
stop
()
const
{
return
cur_iter_idx_
>=
num_
iters_
;
}
void
cpuOn
()
{
cpu_started_
=
cv
::
getTickCount
();
}
void
cpuOff
()
{
int64
delta
=
cv
::
getTickCount
()
-
cpu_started_
;
cpu_times_
.
push_back
(
delta
);
++
it
_
;
++
cur_iter_idx
_
;
}
void
cpuComplete
()
{
double
delta_mean
=
std
::
accumulate
(
cpu_times_
.
begin
(),
cpu_times_
.
end
(),
0
.
0
)
/
iters_
;
cpu_elapsed_
+=
delta_mean
;
cpu_elapsed_
+=
meanTime
(
cpu_times_
);
cur_subtest_is_empty_
=
false
;
it
_
=
0
;
cur_iter_idx
_
=
0
;
}
void
gpuOn
()
{
gpu_started_
=
cv
::
getTickCount
();
}
...
...
@@ -78,30 +77,28 @@ public:
{
int64
delta
=
cv
::
getTickCount
()
-
gpu_started_
;
gpu_times_
.
push_back
(
delta
);
++
it
_
;
++
cur_iter_idx
_
;
}
void
gpuComplete
()
{
double
delta_mean
=
std
::
accumulate
(
gpu_times_
.
begin
(),
gpu_times_
.
end
(),
0
.
0
)
/
iters_
;
gpu_elapsed_
+=
delta_mean
;
gpu_elapsed_
+=
meanTime
(
gpu_times_
);
cur_subtest_is_empty_
=
false
;
it
_
=
0
;
cur_iter_idx
_
=
0
;
}
bool
isListMode
()
const
{
return
is_list_mode_
;
}
void
setListMode
(
bool
value
)
{
is_list_mode_
=
value
;
}
private
:
TestSystem
()
:
cur_subtest_is_empty_
(
true
),
cpu_elapsed_
(
0
),
gpu_elapsed_
(
0
),
speedup_total_
(
0
.
0
),
num_subtests_called_
(
0
),
is_list_mode_
(
false
)
TestSystem
()
:
cur_subtest_is_empty_
(
true
),
cpu_elapsed_
(
0
),
gpu_elapsed_
(
0
),
speedup_total_
(
0
.
0
),
num_subtests_called_
(
0
),
is_list_mode_
(
false
),
num_iters_
(
10
),
cur_iter_idx_
(
0
)
{
iters_
=
10
;
it_
=
0
;
cpu_times_
.
reserve
(
iters_
);
gpu_times_
.
reserve
(
iters_
);
}
cpu_times_
.
reserve
(
num_iters_
);
gpu_times_
.
reserve
(
num_iters_
);
}
void
finishCurrentSubtest
();
void
resetCurrentSubtest
()
...
...
@@ -110,11 +107,13 @@ private:
gpu_elapsed_
=
0
;
cur_subtest_description_
.
str
(
""
);
cur_subtest_is_empty_
=
true
;
it
_
=
0
;
cur_iter_idx
_
=
0
;
cpu_times_
.
clear
();
gpu_times_
.
clear
();
}
double
meanTime
(
const
std
::
vector
<
int64
>
&
samples
);
void
printHeading
();
void
printSummary
();
void
printMetrics
(
double
cpu_time
,
double
gpu_time
,
double
speedup
);
...
...
@@ -136,8 +135,8 @@ private:
bool
is_list_mode_
;
int
iters_
;
int
it
_
;
int
num_
iters_
;
int
cur_iter_idx
_
;
std
::
vector
<
int64
>
cpu_times_
;
std
::
vector
<
int64
>
gpu_times_
;
};
...
...
@@ -164,13 +163,21 @@ private:
#define SUBTEST TestSystem::instance().startNewSubtest()
#define CPU_ON while (!TestSystem::instance().stop()) { TestSystem::instance().cpuOn()
#define CPU_OFF TestSystem::instance().cpuOff(); } TestSystem::instance().cpuComplete()
#define GPU_ON while (!TestSystem::instance().stop()) { TestSystem::instance().gpuOn()
#define GPU_OFF TestSystem::instance().gpuOff(); } TestSystem::instance().gpuComplete()
// Generates matrix
#define CPU_ON \
while
(
!
TestSystem
::
instance
().
stop
())
{
\
TestSystem
::
instance
().
cpuOn
()
#define CPU_OFF \
TestSystem
::
instance
().
cpuOff
();
\
}
TestSystem
::
instance
().
cpuComplete
()
#define GPU_ON \
while
(
!
TestSystem
::
instance
().
stop
())
{
\
TestSystem
::
instance
().
gpuOn
()
#define GPU_OFF \
TestSystem
::
instance
().
gpuOff
();
\
}
TestSystem
::
instance
().
gpuComplete
()
// Generates a matrix
void
gen
(
cv
::
Mat
&
mat
,
int
rows
,
int
cols
,
int
type
,
cv
::
Scalar
low
,
cv
::
Scalar
high
);
...
...
samples/gpu/performance/tests.cpp
View file @
630d874e
...
...
@@ -1203,13 +1203,11 @@ TEST(FarnebackOpticalFlow)
calc
.
flags
|=
useGaussianBlur
?
OPTFLOW_FARNEBACK_GAUSSIAN
:
0
;
gpu
::
GpuMat
d_frame0
(
frame0
),
d_frame1
(
frame1
),
d_flowx
,
d_flowy
;
calc
(
d_frame0
,
d_frame1
,
d_flowx
,
d_flowy
);
GPU_ON
;
calc
(
d_frame0
,
d_frame1
,
d_flowx
,
d_flowy
);
GPU_OFF
;
Mat
flow
;
calcOpticalFlowFarneback
(
frame0
,
frame1
,
flow
,
calc
.
pyrScale
,
calc
.
numLevels
,
calc
.
winSize
,
calc
.
numIters
,
calc
.
polyN
,
calc
.
polySigma
,
calc
.
flags
);
CPU_ON
;
calcOpticalFlowFarneback
(
frame0
,
frame1
,
flow
,
calc
.
pyrScale
,
calc
.
numLevels
,
calc
.
winSize
,
calc
.
numIters
,
calc
.
polyN
,
calc
.
polySigma
,
calc
.
flags
);
CPU_OFF
;
...
...
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