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
e5b563b3
Commit
e5b563b3
authored
Feb 17, 2011
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored GPU performance sample, added filter suport
parent
12c2ead8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
58 deletions
+69
-58
performance.cpp
samples/gpu/performance/performance.cpp
+41
-27
performance.h
samples/gpu/performance/performance.h
+28
-31
No files found.
samples/gpu/performance/performance.cpp
View file @
e5b563b3
...
...
@@ -5,13 +5,27 @@
using
namespace
std
;
using
namespace
cv
;
void
TestSystem
::
setWorkingDir
(
const
string
&
val
)
{
working_dir_
=
val
;
}
void
TestSystem
::
setTestFilter
(
const
string
&
val
)
{
test_filter_
=
val
;
}
void
TestSystem
::
run
()
{
// Run initializers
// Run
test
initializers
vector
<
Runnable
*>::
iterator
it
=
inits_
.
begin
();
for
(;
it
!=
inits_
.
end
();
++
it
)
{
(
*
it
)
->
run
();
if
((
*
it
)
->
name
().
find
(
test_filter_
,
0
)
!=
string
::
npos
)
(
*
it
)
->
run
();
}
printHeading
();
...
...
@@ -20,21 +34,24 @@ void TestSystem::run()
it
=
tests_
.
begin
();
for
(;
it
!=
tests_
.
end
();
++
it
)
{
cout
<<
endl
<<
(
*
it
)
->
name
()
<<
":
\n
"
;
try
{
(
*
it
)
->
run
();
flushSubtestData
();
if
((
*
it
)
->
name
().
find
(
test_filter_
,
0
)
!=
string
::
npos
)
{
cout
<<
endl
<<
(
*
it
)
->
name
()
<<
":
\n
"
;
(
*
it
)
->
run
();
finishCurrentSubtest
();
}
}
catch
(
const
Exception
&
)
{
// Message is printed via callback
reset
SubtestData
();
reset
CurrentSubtest
();
}
catch
(
const
runtime_error
&
e
)
{
printError
(
e
.
what
());
reset
SubtestData
();
reset
CurrentSubtest
();
}
}
...
...
@@ -42,27 +59,23 @@ void TestSystem::run()
}
void
TestSystem
::
setWorkingDir
(
const
string
&
val
)
{
working_dir_
=
val
;
}
void
TestSystem
::
flushSubtestData
()
void
TestSystem
::
finishCurrentSubtest
()
{
if
(
!
can_flush_
)
if
(
cur_subtest_is_empty_
)
// 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
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
;
print
Item
(
cpu_time
,
gpu_time
,
speedup
);
print
Metrics
(
cpu_time
,
gpu_time
,
speedup
);
num_subtests_called_
++
;
reset
SubtestData
();
reset
CurrentSubtest
();
}
...
...
@@ -86,7 +99,7 @@ void TestSystem::printSummary()
}
void
TestSystem
::
print
Item
(
double
cpu_time
,
double
gpu_time
,
double
speedup
)
void
TestSystem
::
print
Metrics
(
double
cpu_time
,
double
gpu_time
,
double
speedup
)
{
cout
<<
TAB
<<
setiosflags
(
ios_base
::
left
);
stringstream
stream
;
...
...
@@ -102,14 +115,14 @@ void TestSystem::printItem(double cpu_time, double gpu_time, double speedup)
stream
<<
"x"
<<
setprecision
(
3
)
<<
speedup
;
cout
<<
setw
(
14
)
<<
stream
.
str
();
cout
<<
description_
.
str
();
cout
<<
cur_subtest_
description_
.
str
();
cout
<<
resetiosflags
(
ios_base
::
left
)
<<
endl
;
}
void
TestSystem
::
printError
(
const
std
::
string
&
msg
)
{
cout
<<
TAB
<<
"[error: "
<<
msg
<<
"] "
<<
description_
.
str
()
<<
endl
;
cout
<<
TAB
<<
"[error: "
<<
msg
<<
"] "
<<
cur_subtest_
description_
.
str
()
<<
endl
;
}
...
...
@@ -138,13 +151,15 @@ int CV_CDECL cvErrorCallback(int /*status*/, const char* /*func_name*/,
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
2
)
cout
<<
"Usage: performance_gpu <working_dir_with_slash>
\n\n
"
;
else
TestSystem
::
instance
().
setWorkingDir
(
argv
[
1
]);
if
(
argc
<
3
)
cout
<<
"Usage: performance_gpu <test_filter> <working_dir_with_slash>
\n\n
"
;
if
(
argc
>=
2
)
TestSystem
::
instance
().
setTestFilter
(
argv
[
1
]);
if
(
argc
>=
3
)
TestSystem
::
instance
().
setWorkingDir
(
argv
[
2
]);
redirectError
(
cvErrorCallback
);
TestSystem
::
instance
().
run
();
return
0
;
}
\ No newline at end of file
}
samples/gpu/performance/performance.h
View file @
e5b563b3
...
...
@@ -13,9 +13,7 @@ class Runnable
{
public
:
explicit
Runnable
(
const
std
::
string
&
name
)
:
name_
(
name
)
{}
const
std
::
string
&
name
()
const
{
return
name_
;
}
virtual
void
run
()
=
0
;
private
:
...
...
@@ -32,70 +30,67 @@ public:
return
me
;
}
void
addInit
(
Runnable
*
init
)
{
inits_
.
push_back
(
init
);
}
void
setWorkingDir
(
const
std
::
string
&
val
);
const
std
::
string
&
workingDir
()
const
{
return
working_dir_
;
}
void
addTest
(
Runnable
*
test
)
{
tests_
.
push_back
(
test
);
}
void
setTestFilter
(
const
std
::
string
&
val
);
const
std
::
string
&
testFilter
()
const
{
return
test_filter_
;
}
void
addInit
(
Runnable
*
init
)
{
inits_
.
push_back
(
init
);
}
void
addTest
(
Runnable
*
test
)
{
tests_
.
push_back
(
test
);
}
void
run
();
// Ends current subtest and starts new one
std
::
stringstream
&
subtest
()
// It's public because OpenCV callback uses it
void
printError
(
const
std
::
string
&
msg
);
std
::
stringstream
&
startNewSubtest
()
{
f
lushSubtestData
();
return
description_
;
f
inishCurrentSubtest
();
return
cur_subtest_
description_
;
}
void
cpuOn
()
{
cpu_started_
=
cv
::
getTickCount
();
}
void
cpuOff
()
{
int64
delta
=
cv
::
getTickCount
()
-
cpu_started_
;
cpu_elapsed_
+=
delta
;
c
an_flush_
=
tru
e
;
c
ur_subtest_is_empty_
=
fals
e
;
}
void
gpuOn
()
{
gpu_started_
=
cv
::
getTickCount
();
}
void
gpuOff
()
{
int64
delta
=
cv
::
getTickCount
()
-
gpu_started_
;
gpu_elapsed_
+=
delta
;
c
an_flush_
=
tru
e
;
c
ur_subtest_is_empty_
=
fals
e
;
}
void
setWorkingDir
(
const
std
::
string
&
val
);
const
std
::
string
&
workingDir
()
const
{
return
working_dir_
;
}
void
printError
(
const
std
::
string
&
msg
);
private
:
TestSystem
()
:
can_flush_
(
false
),
cpu_elapsed_
(
0
),
gpu_elapsed_
(
0
),
speedup_total_
(
0
.
0
),
num_subtests_called_
(
0
)
{}
TestSystem
()
:
cur_subtest_is_empty_
(
true
),
cpu_elapsed_
(
0
),
gpu_elapsed_
(
0
),
speedup_total_
(
0
.
0
),
num_subtests_called_
(
0
)
{}
void
flushSubtestData
();
void
resetSubtestData
()
void
finishCurrentSubtest
();
void
resetCurrentSubtest
()
{
cpu_elapsed_
=
0
;
gpu_elapsed_
=
0
;
description_
.
str
(
""
);
c
an_flush_
=
fals
e
;
cur_subtest_
description_
.
str
(
""
);
c
ur_subtest_is_empty_
=
tru
e
;
}
void
printHeading
();
void
printSummary
();
void
print
Item
(
double
cpu_time
,
double
gpu_time
,
double
speedup
);
void
print
Metrics
(
double
cpu_time
,
double
gpu_time
,
double
speedup
);
std
::
string
working_dir_
;
std
::
string
test_filter_
;
std
::
vector
<
Runnable
*>
inits_
;
std
::
vector
<
Runnable
*>
tests_
;
// Current test (subtest) description
std
::
stringstream
description_
;
bool
can_flush_
;
std
::
stringstream
cur_subtest_description_
;
bool
cur_subtest_is_empty_
;
int64
cpu_started_
,
cpu_elapsed_
;
int64
gpu_started_
,
gpu_elapsed_
;
...
...
@@ -124,15 +119,17 @@ private:
}
name
##
_test_instance
;
\
void
name
##
_test
::
run
()
#define SUBTEST TestSystem::instance().subtest()
#define SUBTEST TestSystem::instance().s
tartNewS
ubtest()
#define CPU_ON TestSystem::instance().cpuOn()
#define GPU_ON TestSystem::instance().gpuOn()
#define CPU_OFF TestSystem::instance().cpuOff()
#define GPU_OFF TestSystem::instance().gpuOff()
// Generates matrix
void
gen
(
cv
::
Mat
&
mat
,
int
rows
,
int
cols
,
int
type
,
cv
::
Scalar
low
,
cv
::
Scalar
high
);
// Returns abs path taking into account test system working dir
std
::
string
abspath
(
const
std
::
string
&
relpath
);
#endif // OPENCV_GPU_SAMPLE_PERFORMANCE_H_
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