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
310c483d
Commit
310c483d
authored
Jan 24, 2011
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added first version of gpu performance tests
parent
811ba318
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
258 additions
and
2 deletions
+258
-2
match_template.cpp
modules/gpu/src/match_template.cpp
+1
-1
CMakeLists.txt
samples/gpu/CMakeLists.txt
+3
-1
CMakeLists.txt
samples/gpu/performance/CMakeLists.txt
+30
-0
performance.cpp
samples/gpu/performance/performance.cpp
+94
-0
performance.h
samples/gpu/performance/performance.h
+100
-0
tests.cpp
samples/gpu/performance/tests.cpp
+30
-0
No files found.
modules/gpu/src/match_template.cpp
View file @
310c483d
...
...
@@ -178,7 +178,7 @@ namespace
if
(
depth
==
CV_8U
)
return
300
;
break
;
case
CV_TM_SQDIFF
:
if
(
depth
==
CV_8U
)
return
5
00
;
if
(
depth
==
CV_8U
)
return
3
00
;
break
;
}
CV_Error
(
CV_StsBadArg
,
"getTemplateThreshold: unsupported match template mode"
);
...
...
samples/gpu/CMakeLists.txt
View file @
310c483d
...
...
@@ -47,7 +47,9 @@ if (BUILD_EXAMPLES)
foreach
(
sample_filename
${
gpu_samples
}
)
get_filename_component
(
sample
${
sample_filename
}
NAME_WE
)
MY_DEFINE_EXAMPLE
(
${
sample
}
${
sample_filename
}
)
endforeach
()
endforeach
()
include
(
"performance/CMakeLists.txt"
)
endif
(
BUILD_EXAMPLES
)
if
(
NOT WIN32
)
...
...
samples/gpu/performance/CMakeLists.txt
0 → 100644
View file @
310c483d
set
(
the_target
"example_gpu_performance"
)
file
(
GLOB sources
"performance/*.cpp"
)
file
(
GLOB headers
"performance/*.h"
)
add_executable
(
${
the_target
}
${
sources
}
${
headers
}
)
set_target_properties
(
${
the_target
}
PROPERTIES
OUTPUT_NAME
"performance_gpu"
PROJECT_LABEL
"(EXAMPLE_GPU) performance"
)
add_dependencies
(
${
the_target
}
opencv_core opencv_flann opencv_imgproc opencv_highgui
opencv_ml opencv_video opencv_objdetect opencv_features2d
opencv_calib3d opencv_legacy opencv_contrib opencv_gpu
)
target_link_libraries
(
${
the_target
}
${
OPENCV_LINKER_LIBS
}
opencv_core
opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_gpu
)
if
(
WIN32
)
install
(
TARGETS
${
the_target
}
RUNTIME DESTINATION
"samples/gpu"
COMPONENT main
)
endif
()
if
(
NOT WIN32
)
file
(
GLOB GPU_FILES performance/*.cpp performance/*.h
)
install
(
FILES
${
GPU_FILES
}
DESTINATION share/opencv/samples/gpu/performance
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
)
endif
()
\ No newline at end of file
samples/gpu/performance/performance.cpp
0 → 100644
View file @
310c483d
#include <iomanip>
#include "performance.h"
using
namespace
std
;
using
namespace
cv
;
void
Test
::
gen
(
Mat
&
mat
,
int
rows
,
int
cols
,
int
type
,
Scalar
low
,
Scalar
high
)
{
mat
.
create
(
rows
,
cols
,
type
);
RNG
rng
(
0
);
rng
.
fill
(
mat
,
RNG
::
UNIFORM
,
low
,
high
);
}
void
Test
::
gen
(
Mat
&
mat
,
int
rows
,
int
cols
,
int
type
)
{
mat
.
create
(
rows
,
cols
,
type
);
Mat
mat8u
(
rows
,
cols
*
mat
.
elemSize
(),
CV_8U
,
mat
.
data
,
mat
.
step
);
RNG
rng
(
0
);
rng
.
fill
(
mat
,
RNG
::
UNIFORM
,
Scalar
(
0
),
Scalar
(
256
));
}
void
TestSystem
::
run
()
{
cout
<<
setiosflags
(
ios_base
::
left
);
cout
<<
" "
<<
setw
(
10
)
<<
"CPU, ms"
<<
setw
(
10
)
<<
"GPU, ms"
<<
setw
(
10
)
<<
"SPEEDUP"
<<
"DESCRIPTION
\n
"
;
cout
<<
resetiosflags
(
ios_base
::
left
);
vector
<
Test
*>::
iterator
it
=
tests_
.
begin
();
for
(;
it
!=
tests_
.
end
();
++
it
)
{
can_flush_
=
false
;
Test
*
test
=
*
it
;
cout
<<
endl
<<
test
->
name
()
<<
":
\n
"
;
test
->
run
();
flush
();
}
cout
<<
setiosflags
(
ios_base
::
fixed
|
ios_base
::
left
);
cout
<<
"
\n
CPU Total: "
<<
setprecision
(
3
)
<<
cpu_total_
/
getTickFrequency
()
<<
" sec
\n
"
;
cout
<<
"GPU Total: "
<<
setprecision
(
3
)
<<
gpu_total_
/
getTickFrequency
()
<<
" sec (x"
<<
setprecision
(
3
)
<<
(
double
)
cpu_total_
/
gpu_total_
<<
")
\n
"
;
cout
<<
resetiosflags
(
ios_base
::
fixed
|
ios_base
::
left
);
}
void
TestSystem
::
flush
()
{
if
(
!
can_flush_
)
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
=
(
double
)
cpu_time
/
gpu_time
;
cpu_elapsed_
=
0
;
gpu_elapsed_
=
0
;
cout
<<
" "
<<
setiosflags
(
ios_base
::
fixed
|
ios_base
::
left
);
stringstream
stream
;
stream
<<
cpu_time
;
cout
<<
setw
(
10
)
<<
stream
.
str
();
stream
.
str
(
""
);
stream
<<
gpu_time
;
cout
<<
setw
(
10
)
<<
stream
.
str
();
stream
.
str
(
""
);
stream
<<
"x"
<<
setprecision
(
3
)
<<
speedup
;
cout
<<
setw
(
10
)
<<
stream
.
str
();
cout
<<
description_
.
str
();
description_
.
str
(
""
);
cout
<<
resetiosflags
(
ios_base
::
fixed
|
ios_base
::
left
)
<<
endl
;
can_flush_
=
false
;
}
int
main
()
{
TestSystem
::
instance
()
->
run
();
return
0
;
}
\ No newline at end of file
samples/gpu/performance/performance.h
0 → 100644
View file @
310c483d
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <opencv2/core/core.hpp>
class
Test
{
public
:
Test
(
const
std
::
string
&
name
)
:
name_
(
name
)
{}
const
std
::
string
&
name
()
const
{
return
name_
;
}
void
gen
(
cv
::
Mat
&
mat
,
int
rows
,
int
cols
,
int
type
,
cv
::
Scalar
low
,
cv
::
Scalar
high
);
void
gen
(
cv
::
Mat
&
mat
,
int
rows
,
int
cols
,
int
type
);
virtual
void
run
()
=
0
;
private
:
std
::
string
name_
;
};
class
TestSystem
{
public
:
static
TestSystem
*
instance
()
{
static
TestSystem
me
;
return
&
me
;
}
void
add
(
Test
*
test
)
{
tests_
.
push_back
(
test
);
}
void
run
();
void
cpuOn
()
{
cpu_started_
=
cv
::
getTickCount
();
}
void
cpuOff
()
{
int64
delta
=
cv
::
getTickCount
()
-
cpu_started_
;
cpu_elapsed_
+=
delta
;
cpu_total_
+=
delta
;
can_flush_
=
true
;
}
void
gpuOn
()
{
gpu_started_
=
cv
::
getTickCount
();
}
void
gpuOff
()
{
int64
delta
=
cv
::
getTickCount
()
-
gpu_started_
;
gpu_elapsed_
+=
delta
;
gpu_total_
+=
delta
;
can_flush_
=
true
;
}
// Ends current subtest and starts new one
std
::
stringstream
&
subtest
()
{
flush
();
return
description_
;
}
private
:
TestSystem
()
:
can_flush_
(
false
),
cpu_elapsed_
(
0
),
cpu_total_
(
0
),
gpu_elapsed_
(
0
),
gpu_total_
(
0
)
{};
void
flush
();
std
::
vector
<
Test
*>
tests_
;
// Current test (subtest) description
std
::
stringstream
description_
;
bool
can_flush_
;
int64
cpu_started_
,
cpu_elapsed_
,
cpu_total_
;
int64
gpu_started_
,
gpu_elapsed_
,
gpu_total_
;
};
#define TEST(name) \
struct
name
##
_test
:
public
Test
\
{
\
name
##
_test
()
:
Test
(
#
name
)
{
TestSystem
::
instance
()
->
add
(
this
);
}
\
void
run
();
\
}
name
##
_test_instance
;
\
void
name
##
_test
::
run
()
#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 SUBTEST TestSystem::instance()->subtest()
#define DESCRIPTION TestSystem::instance()->subtest()
\ No newline at end of file
samples/gpu/performance/tests.cpp
0 → 100644
View file @
310c483d
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/gpu/gpu.hpp>
#include "performance.h"
using
namespace
std
;
using
namespace
cv
;
TEST
(
matchTemplate
)
{
for
(
int
templ_size
=
5
;
templ_size
<=
1000
;
templ_size
*=
2
)
{
SUBTEST
<<
"img 3000, templ "
<<
templ_size
<<
", 8U, SQDIFF"
;
Mat
image
;
gen
(
image
,
3000
,
3000
,
CV_8U
);
Mat
templ
;
gen
(
templ
,
templ_size
,
templ_size
,
CV_8U
);
Mat
result
;
CPU_ON
;
matchTemplate
(
image
,
templ
,
result
,
CV_TM_SQDIFF
);
CPU_OFF
;
gpu
::
GpuMat
d_image
(
image
);
gpu
::
GpuMat
d_templ
(
templ
);
gpu
::
GpuMat
d_result
;
GPU_ON
;
gpu
::
matchTemplate
(
d_image
,
d_templ
,
d_result
,
CV_TM_SQDIFF
);
GPU_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