Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
fd61adfd
Mace
项目概览
Xiaomi
/
Mace
通知
106
Star
40
Fork
27
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fd61adfd
编写于
10月 29, 2017
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish tuner util.
上级
2fef9af5
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
152 addition
and
9 deletion
+152
-9
mace/kernels/opencl/batch_norm_opencl.cc
mace/kernels/opencl/batch_norm_opencl.cc
+2
-1
mace/ops/ops_test_util.h
mace/ops/ops_test_util.h
+4
-8
mace/utils/BUILD
mace/utils/BUILD
+11
-0
mace/utils/tuner.h
mace/utils/tuner.h
+135
-0
未找到文件。
mace/kernels/opencl/batch_norm_opencl.cc
浏览文件 @
fd61adfd
...
...
@@ -29,7 +29,7 @@ void BatchNormFunctor<DeviceType::OPENCL, float>::operator()(
auto
bm_kernel
=
cl
::
Kernel
(
program
,
"batch_norm"
);
const
uint32_t
kwg_size
=
runtime
->
GetKernelMaxWorkGroupSize
(
bm_kernel
);
const
uint32_t
lws
[
3
]
=
{
1
,
kwg_size
/
128
,
128
};
const
uint32_t
lws
[
3
]
=
{
1
,
1
,
kwg_size
};
uint32_t
idx
=
0
;
bm_kernel
.
setArg
(
idx
++
,
*
(
static_cast
<
const
cl
::
Buffer
*>
(
input
->
buffer
())));
...
...
@@ -43,6 +43,7 @@ void BatchNormFunctor<DeviceType::OPENCL, float>::operator()(
bm_kernel
.
setArg
(
idx
++
,
lws
[
1
]
*
sizeof
(
float
),
nullptr
);
bm_kernel
.
setArg
(
idx
++
,
lws
[
1
]
*
sizeof
(
float
),
nullptr
);
//TODO need to design the new way to tune.
cl_int
error
=
runtime
->
command_queue
().
enqueueNDRangeKernel
(
bm_kernel
,
cl
::
NullRange
,
cl
::
NDRange
(
gws
[
0
],
gws
[
1
],
gws
[
2
]),
...
...
mace/ops/ops_test_util.h
浏览文件 @
fd61adfd
...
...
@@ -137,13 +137,10 @@ class OpsTestNet {
Workspace
*
ws
()
{
return
&
ws_
;
}
bool
RunOp
(
DeviceType
device
)
{
if
(
!
net_
||
device_
!=
device
)
{
NetDef
net_def
;
net_def
.
add_op
()
->
CopyFrom
(
op_def_
);
VLOG
(
3
)
<<
net_def
.
DebugString
();
net_
=
CreateNet
(
net_def
,
&
ws_
,
device
);
device_
=
device
;
}
return
net_
->
Run
();
}
...
...
@@ -163,7 +160,6 @@ class OpsTestNet {
Workspace
ws_
;
OperatorDef
op_def_
;
std
::
unique_ptr
<
NetBase
>
net_
;
DeviceType
device_
;
};
class
OpsTestBase
:
public
::
testing
::
Test
{
...
...
mace/utils/BUILD
浏览文件 @
fd61adfd
...
...
@@ -28,3 +28,14 @@ cc_library(
],
copts
=
[
"-std=c++11"
],
)
cc_library
(
name
=
"tuner"
,
hdrs
=
[
"tuner.h"
,
],
copts
=
[
"-std=c++11"
],
deps
=
[
"//mace/core"
,
],
)
mace/utils/tuner.h
0 → 100644
浏览文件 @
fd61adfd
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_UTILS_TUNER_H_
#define MACE_UTILS_TUNER_H_
#include <stdlib.h>
#include <vector>
#include <functional>
#include <string>
#include <unordered_map>
#include <fstream>
#include <chrono>
#include <limits>
#include "mace/core/logging.h"
namespace
mace
{
template
<
typename
param_type
>
class
Tuner
{
public:
static
Tuner
*
Get
()
{
static
Tuner
tuner
;
return
&
tuner
;
}
void
TuneOrRun
(
const
std
::
string
&
param_key
,
const
std
::
vector
<
param_type
>
&
default_param
,
std
::
function
<
std
::
vector
<
std
::
vector
<
param_type
>>
()
>
param_generator
,
const
std
::
function
<
void
(
const
std
::
vector
<
param_type
>
&
)
>
&
func
)
{
if
(
param_generator
==
nullptr
)
{
// run
if
(
param_table_
.
find
(
param_key
)
!=
param_table_
.
end
())
{
func
(
param_table_
[
param_key
]);
}
else
{
func
(
default_param
);
}
}
else
{
// tune
std
::
vector
<
param_type
>
opt_param
=
default_param
;
Tune
(
param_generator
,
func
,
opt_param
);
param_table_
[
param_key
]
=
opt_param
;
}
}
private:
Tuner
()
{
path_
=
getenv
(
"MACE_RUN_PARAMTER_PATH"
);
ReadRunParamters
();
}
~
Tuner
()
{
WriteRunParameters
();
}
Tuner
(
const
Tuner
&
)
=
delete
;
Tuner
&
operator
=
(
const
Tuner
&
)
=
delete
;
inline
void
WriteRunParameters
()
{
if
(
path_
!=
nullptr
)
{
std
::
ofstream
ofs
(
path_
,
std
::
ios
::
binary
|
std
::
ios
::
out
);
if
(
ofs
.
is_open
())
{
for
(
auto
&
kp
:
param_table_
)
{
int32_t
key_size
=
kp
.
first
.
size
()
+
1
;
ofs
.
write
(
static_cast
<
char
*>
(
&
key_size
),
sizeof
(
key_size
));
ofs
.
write
(
&
kp
.
first
.
c_str
(),
key_size
);
auto
&
params
=
kp
.
second
;
int32_t
params_size
=
params
.
size
()
*
sizeof
(
param_type
);
ofs
.
write
(
static_cast
<
char
*>
(
&
params_size
),
sizeof
(
params_size
));
for
(
auto
&
param
:
params
)
{
ofs
.
write
(
&
param
,
sizeof
(
params_size
));
}
}
ofs
.
close
();
}
else
{
LOG
(
WARNING
)
<<
"Write run parameter file failed."
;
}
}
}
inline
void
ReadRunParamters
()
{
if
(
path_
!=
nullptr
)
{
std
::
ifstream
ifs
(
path_
,
std
::
ios
::
binary
|
std
::
ios
::
in
);
if
(
ifs
.
is_open
())
{
int32_t
key_size
=
0
;
int32_t
params_size
=
0
;
int32_t
params_count
=
0
;
while
(
!
ifs
.
eof
())
{
ifs
.
read
(
static_cast
<
char
*>
(
&
key_size
),
sizeof
(
key_size
));
std
::
string
key
(
key_size
,
''
);
ifs
.
read
(
&
key
[
0
],
key_size
);
ifs
.
read
(
static_cast
<
char
*>
(
&
params_size
),
sizeof
(
params_size
));
params_count
=
params_size
/
sizeof
(
param_type
);
std
::
vector
<
param_type
>
params
(
params_count
);
for
(
int
i
=
0
;
i
<
params_count
;
++
i
)
{
ifs
.
read
(
&
params
[
i
],
sizeof
(
param_type
));
}
param_table_
.
emplace
(
key
,
params
);
}
ifs
.
close
();
}
else
{
LOG
(
WARNING
)
<<
"Write run parameter file failed."
;
}
}
}
inline
void
Tune
(
std
::
function
<
std
::
vector
<
std
::
vector
<
param_type
>>
()
>
param_generator
,
const
std
::
function
<
void
(
const
std
::
vector
<
param_type
>
&
)
>
&
func
,
std
::
vector
<
param_type
>
&
opt_params
)
{
double
opt_time
=
std
::
numeric_limits
<
double
>::
max
();
auto
params
=
param_generator
();
for
(
const
auto
&
param
:
params
)
{
auto
start
=
std
::
chrono
::
high_resolution_clock
::
now
();
func
(
param
);
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
duration_time
=
end
-
start
;
// Check the execution time
if
(
duration_time
.
count
()
<
opt_time
)
{
opt_time
=
duration_time
.
count
();
opt_params
=
param
;
}
}
}
private:
const
char
*
path_
;
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
param_type
>>
param_table_
;
};
}
// namespace mace
#endif // MACE_UTILS_TUNER_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录