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
f883b31c
Commit
f883b31c
authored
Feb 08, 2012
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated performance sample
parent
a618b774
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
11 deletions
+74
-11
performance.cpp
samples/gpu/performance/performance.cpp
+10
-3
performance.h
samples/gpu/performance/performance.h
+43
-8
tests.cpp
samples/gpu/performance/tests.cpp
+21
-0
No files found.
samples/gpu/performance/performance.cpp
View file @
f883b31c
...
...
@@ -60,8 +60,11 @@ 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
);
//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_
);
...
...
@@ -161,7 +164,8 @@ int main(int argc, const char* argv[])
"{ f | filter | | filter for test }"
"{ w | workdir | | set working directory }"
"{ l | list | false | show all tests }"
"{ d | device | 0 | device id }"
;
"{ d | device | 0 | device id }"
"{ i | iters | 10 | iteration count }"
;
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
...
...
@@ -190,6 +194,7 @@ int main(int argc, const char* argv[])
string
filter
=
cmd
.
get
<
string
>
(
"filter"
);
string
workdir
=
cmd
.
get
<
string
>
(
"workdir"
);
bool
list
=
cmd
.
get
<
bool
>
(
"list"
);
int
iters
=
cmd
.
get
<
int
>
(
"iters"
);
if
(
!
filter
.
empty
())
TestSystem
::
instance
().
setTestFilter
(
filter
);
...
...
@@ -205,6 +210,8 @@ int main(int argc, const char* argv[])
if
(
list
)
TestSystem
::
instance
().
setListMode
(
true
);
TestSystem
::
instance
().
setIters
(
iters
);
TestSystem
::
instance
().
run
();
return
0
;
...
...
samples/gpu/performance/performance.h
View file @
f883b31c
...
...
@@ -4,6 +4,7 @@
#include <iostream>
#include <cstdio>
#include <vector>
#include <numeric>
#include <string>
#include "opencv2/core/core.hpp"
#include "opencv2/gpu/gpu.hpp"
...
...
@@ -40,6 +41,8 @@ public:
void
setTestFilter
(
const
std
::
string
&
val
)
{
test_filter_
=
val
;
}
const
std
::
string
&
testFilter
()
const
{
return
test_filter_
;
}
void
setIters
(
int
iters
)
{
iters_
=
iters
;
}
void
addInit
(
Runnable
*
init
)
{
inits_
.
push_back
(
init
);
}
void
addTest
(
Runnable
*
test
)
{
tests_
.
push_back
(
test
);
}
void
run
();
...
...
@@ -53,20 +56,36 @@ public:
return
cur_subtest_description_
;
}
bool
stop
()
const
{
return
it_
>=
iters_
;
}
void
cpuOn
()
{
cpu_started_
=
cv
::
getTickCount
();
}
void
cpuOff
()
{
int64
delta
=
cv
::
getTickCount
()
-
cpu_started_
;
cpu_elapsed_
+=
delta
;
cpu_times_
.
push_back
(
delta
);
++
it_
;
}
void
cpuComplete
()
{
double
delta_mean
=
std
::
accumulate
(
cpu_times_
.
begin
(),
cpu_times_
.
end
(),
0
.
0
)
/
iters_
;
cpu_elapsed_
+=
delta_mean
;
cur_subtest_is_empty_
=
false
;
}
it_
=
0
;
}
void
gpuOn
()
{
gpu_started_
=
cv
::
getTickCount
();
}
void
gpuOff
()
{
int64
delta
=
cv
::
getTickCount
()
-
gpu_started_
;
gpu_elapsed_
+=
delta
;
gpu_times_
.
push_back
(
delta
);
++
it_
;
}
void
gpuComplete
()
{
double
delta_mean
=
std
::
accumulate
(
gpu_times_
.
begin
(),
gpu_times_
.
end
(),
0
.
0
)
/
iters_
;
gpu_elapsed_
+=
delta_mean
;
cur_subtest_is_empty_
=
false
;
it_
=
0
;
}
bool
isListMode
()
const
{
return
is_list_mode_
;
}
...
...
@@ -76,7 +95,13 @@ 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
)
{}
is_list_mode_
(
false
)
{
iters_
=
10
;
it_
=
0
;
cpu_times_
.
reserve
(
iters_
);
gpu_times_
.
reserve
(
iters_
);
}
void
finishCurrentSubtest
();
void
resetCurrentSubtest
()
...
...
@@ -85,6 +110,9 @@ private:
gpu_elapsed_
=
0
;
cur_subtest_description_
.
str
(
""
);
cur_subtest_is_empty_
=
true
;
it_
=
0
;
cpu_times_
.
clear
();
gpu_times_
.
clear
();
}
void
printHeading
();
...
...
@@ -107,6 +135,11 @@ private:
int
num_subtests_called_
;
bool
is_list_mode_
;
int
iters_
;
int
it_
;
std
::
vector
<
int64
>
cpu_times_
;
std
::
vector
<
int64
>
gpu_times_
;
};
...
...
@@ -130,10 +163,12 @@ private:
void
name
##
_test
::
run
()
#define SUBTEST TestSystem::instance().startNewSubtest()
#define CPU_ON TestSystem::instance().cpuOn()
#define GPU_ON TestSystem::instance().gpuOn()
#define CPU_OFF TestSystem::instance().cpuOff()
#define GPU_OFF TestSystem::instance().gpuOff()
#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
void
gen
(
cv
::
Mat
&
mat
,
int
rows
,
int
cols
,
int
type
,
cv
::
Scalar
low
,
...
...
samples/gpu/performance/tests.cpp
View file @
f883b31c
...
...
@@ -767,6 +767,27 @@ TEST(threshold)
gpu
::
threshold
(
d_src
,
d_dst
,
50.0
,
0.0
,
THRESH_BINARY
);
GPU_OFF
;
}
for
(
int
size
=
2000
;
size
<=
4000
;
size
+=
1000
)
{
SUBTEST
<<
size
<<
'x'
<<
size
<<
", 32FC1, THRESH_TRUNC [NPP]"
;
gen
(
src
,
size
,
size
,
CV_32FC1
,
0
,
100
);
threshold
(
src
,
dst
,
50.0
,
0.0
,
THRESH_TRUNC
);
CPU_ON
;
threshold
(
src
,
dst
,
50.0
,
0.0
,
THRESH_TRUNC
);
CPU_OFF
;
d_src
.
upload
(
src
);
gpu
::
threshold
(
d_src
,
d_dst
,
50.0
,
0.0
,
THRESH_TRUNC
);
GPU_ON
;
gpu
::
threshold
(
d_src
,
d_dst
,
50.0
,
0.0
,
THRESH_TRUNC
);
GPU_OFF
;
}
}
TEST
(
pow
)
...
...
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