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
1894f1a3
Commit
1894f1a3
authored
Jun 22, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11773 from alalek:dnn_ocl_update_force_tuning_flag
parents
44367026
50c607d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
28 deletions
+51
-28
ocl4dnn.hpp
modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp
+1
-0
ocl4dnn_conv_spatial.cpp
modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp
+50
-28
No files found.
modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp
View file @
1894f1a3
...
@@ -306,6 +306,7 @@ class OCL4DNNConvSpatial
...
@@ -306,6 +306,7 @@ class OCL4DNNConvSpatial
std
::
string
kernel_name_
;
std
::
string
kernel_name_
;
std
::
string
cache_path_
;
std
::
string
cache_path_
;
bool
use_cache_path_
;
// true if cache_path_ directory exists
bool
use_cache_path_
;
// true if cache_path_ directory exists
bool
run_auto_tuning_
;
bool
force_auto_tuning_
;
bool
force_auto_tuning_
;
int32_t
kernel_index_
;
int32_t
kernel_index_
;
std
::
vector
<
cv
::
Ptr
<
kernelConfig
>
>
kernelQueue
;
std
::
vector
<
cv
::
Ptr
<
kernelConfig
>
>
kernelQueue
;
...
...
modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp
View file @
1894f1a3
...
@@ -67,6 +67,46 @@ typedef std::map<std::string, std::string> kernel_hash_t;
...
@@ -67,6 +67,46 @@ typedef std::map<std::string, std::string> kernel_hash_t;
static
kernel_hash_t
kernelConfigMap
;
static
kernel_hash_t
kernelConfigMap
;
static
bool
defaultConfigLoaded
=
false
;
static
bool
defaultConfigLoaded
=
false
;
static
std
::
string
sanitize
(
const
std
::
string
&
s
)
{
std
::
string
s_
=
s
;
for
(
size_t
i
=
0
;
i
<
s_
.
size
();
i
++
)
{
char
c
=
s_
[
i
];
if
(
!
((
c
>=
'0'
&&
c
<=
'9'
)
||
(
c
>=
'a'
&&
c
<=
'z'
)
||
(
c
>=
'A'
&&
c
<=
'Z'
)
||
c
==
'_'
))
{
s_
[
i
]
=
'_'
;
}
}
// TODO add hash?
// s_ = s_ + cv::format("_%08llx", crc64((uchar*)s.c_str(), s.size()));
return
s_
;
}
static
void
initializeGlobalBuiltinConfigurations
(
const
std
::
string
&
cache_path
)
{
CV_Assert
(
defaultConfigLoaded
==
false
);
CV_Assert
(
kernelConfigMap
.
empty
());
const
size_t
numConfigs
=
sizeof
(
default_kernel_config_intel
)
/
sizeof
(
default_kernel_config_intel
[
0
])
/
2
;
for
(
size_t
i
=
0
;
i
<
numConfigs
;
i
++
)
{
std
::
string
key
=
std
::
string
(
"Intel(R) Corporation_"
)
+
default_kernel_config_intel
[
2
*
i
];
if
(
!
cache_path
.
empty
())
{
std
::
string
cacheFile
=
cache_path
+
sanitize
(
key
);
std
::
ifstream
cachedKernel
(
cacheFile
.
c_str
());
if
(
cachedKernel
)
continue
;
// external configuration found, skip builtin
}
std
::
pair
<
std
::
string
,
std
::
string
>
entry
(
key
,
default_kernel_config_intel
[
2
*
i
+
1
]);
kernelConfigMap
.
insert
(
entry
);
}
defaultConfigLoaded
=
true
;
}
template
<
typename
Dtype
>
template
<
typename
Dtype
>
OCL4DNNConvSpatial
<
Dtype
>::
OCL4DNNConvSpatial
(
OCL4DNNConvConfig
config
)
OCL4DNNConvSpatial
<
Dtype
>::
OCL4DNNConvSpatial
(
OCL4DNNConvConfig
config
)
{
{
...
@@ -139,9 +179,8 @@ OCL4DNNConvSpatial<Dtype>::OCL4DNNConvSpatial(OCL4DNNConvConfig config)
...
@@ -139,9 +179,8 @@ OCL4DNNConvSpatial<Dtype>::OCL4DNNConvSpatial(OCL4DNNConvConfig config)
}
}
}
}
force_auto_tuning_
=
run_auto_tuning_
=
use_cache_path_
&&
!
utils
::
getConfigurationParameterBool
(
"OPENCV_OCL4DNN_DISABLE_AUTO_TUNING"
,
false
);
(
use_cache_path_
&&
!
utils
::
getConfigurationParameterBool
(
"OPENCV_OCL4DNN_DISABLE_AUTO_TUNING"
,
false
))
force_auto_tuning_
=
utils
::
getConfigurationParameterBool
(
"OPENCV_OCL4DNN_FORCE_AUTO_TUNING"
,
false
);
||
utils
::
getConfigurationParameterBool
(
"OPENCV_OCL4DNN_FORCE_AUTO_TUNING"
,
false
);
}
}
template
<
typename
Dtype
>
template
<
typename
Dtype
>
...
@@ -562,17 +601,7 @@ void OCL4DNNConvSpatial<Dtype>::generateKey()
...
@@ -562,17 +601,7 @@ void OCL4DNNConvSpatial<Dtype>::generateKey()
key_
=
ocl
::
Device
::
getDefault
().
vendorName
()
+
"_EU"
+
cv
::
format
(
"%d"
,
ocl
::
Device
::
getDefault
().
maxComputeUnits
())
+
"_"
+
keyBuilder
.
str
();
key_
=
ocl
::
Device
::
getDefault
().
vendorName
()
+
"_EU"
+
cv
::
format
(
"%d"
,
ocl
::
Device
::
getDefault
().
maxComputeUnits
())
+
"_"
+
keyBuilder
.
str
();
key_sanitized_
=
key_
;
key_sanitized_
=
sanitize
(
key_
);
for
(
size_t
i
=
0
;
i
<
key_sanitized_
.
size
();
i
++
)
{
char
c
=
key_sanitized_
[
i
];
if
(
!
((
c
>=
'0'
&&
c
<=
'9'
)
||
(
c
>=
'a'
&&
c
<=
'z'
)
||
(
c
>=
'A'
&&
c
<=
'Z'
)
||
c
==
'_'
))
{
key_sanitized_
[
i
]
=
'_'
;
}
}
// TODO add hash?
// key_sanitized_ = key_sanitized_ + cv::format("_%08llx", crc64((uchar*)key_.c_str(), key_.size()));
short_key_
=
keyBuilder
.
str
();
short_key_
=
keyBuilder
.
str
();
}
}
...
@@ -1805,7 +1834,7 @@ void OCL4DNNConvSpatial<Dtype>::prepareKernel(const UMat &bottom, UMat &top,
...
@@ -1805,7 +1834,7 @@ void OCL4DNNConvSpatial<Dtype>::prepareKernel(const UMat &bottom, UMat &top,
calculateBenchmark
(
bottom
,
benchData
,
(
use_half_
)
?
weights_half
:
weight
,
bias
,
numImages
);
calculateBenchmark
(
bottom
,
benchData
,
(
use_half_
)
?
weights_half
:
weight
,
bias
,
numImages
);
if
(
force_auto_tuning_
)
if
(
run_auto_tuning_
||
force_auto_tuning_
)
{
{
setupConvolution
(
bottom
,
top
,
weight
,
bias
,
numImages
,
benchData
);
setupConvolution
(
bottom
,
top
,
weight
,
bias
,
numImages
,
benchData
);
}
}
...
@@ -1820,18 +1849,8 @@ template<typename Dtype>
...
@@ -1820,18 +1849,8 @@ template<typename Dtype>
bool
OCL4DNNConvSpatial
<
Dtype
>::
loadCachedConfig
()
bool
OCL4DNNConvSpatial
<
Dtype
>::
loadCachedConfig
()
{
{
cv
::
AutoLock
lock
(
kernelConfigMutex
);
cv
::
AutoLock
lock
(
kernelConfigMutex
);
if
(
!
defaultConfigLoaded
)
if
(
!
defaultConfigLoaded
&&
!
force_auto_tuning_
)
{
initializeGlobalBuiltinConfigurations
((
use_cache_path_
&&
!
cache_path_
.
empty
())
?
(
cache_path_
+
'/'
)
:
std
::
string
());
const
size_t
numConfigs
=
sizeof
(
default_kernel_config_intel
)
/
sizeof
(
default_kernel_config_intel
[
0
])
/
2
;
for
(
size_t
i
=
0
;
i
<
numConfigs
;
i
++
)
{
std
::
pair
<
std
::
string
,
std
::
string
>
entry
(
std
::
string
(
"Intel(R) Corporation_"
)
+
default_kernel_config_intel
[
2
*
i
],
default_kernel_config_intel
[
2
*
i
+
1
]);
kernelConfigMap
.
insert
(
entry
);
}
defaultConfigLoaded
=
true
;
}
kernel_hash_t
::
iterator
it
=
kernelConfigMap
.
find
(
key_
);
kernel_hash_t
::
iterator
it
=
kernelConfigMap
.
find
(
key_
);
if
(
it
!=
kernelConfigMap
.
end
())
if
(
it
!=
kernelConfigMap
.
end
())
...
@@ -1904,9 +1923,12 @@ bool OCL4DNNConvSpatial<Dtype>::setupKernelByConfig(int x, int y, int z, int typ
...
@@ -1904,9 +1923,12 @@ bool OCL4DNNConvSpatial<Dtype>::setupKernelByConfig(int x, int y, int z, int typ
template
<
typename
Dtype
>
template
<
typename
Dtype
>
bool
OCL4DNNConvSpatial
<
Dtype
>::
loadTunedConfig
()
bool
OCL4DNNConvSpatial
<
Dtype
>::
loadTunedConfig
()
{
{
if
(
force_auto_tuning_
)
return
false
;
// don't load results from external storage
if
(
!
use_cache_path_
)
if
(
!
use_cache_path_
)
{
{
if
(
cache_path_
.
empty
()
&&
!
force_auto_tuning_
)
if
(
cache_path_
.
empty
())
{
{
static
int
warn_
=
0
;
static
int
warn_
=
0
;
if
(
!
warn_
)
if
(
!
warn_
)
...
...
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