Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冰之2023
Mace
提交
4b9893ca
Mace
项目概览
冰之2023
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
4b9893ca
编写于
1月 09, 2018
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Obfuscate tuning parameters
上级
6e946c75
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
21 addition
and
19 deletion
+21
-19
mace/core/BUILD
mace/core/BUILD
+1
-0
mace/core/runtime/opencl/opencl_development.cc
mace/core/runtime/opencl/opencl_development.cc
+4
-17
mace/python/tools/binary_codegen.py
mace/python/tools/binary_codegen.py
+1
-0
mace/utils/tuner.h
mace/utils/tuner.h
+5
-2
mace/utils/utils.h
mace/utils/utils.h
+10
-0
未找到文件。
mace/core/BUILD
浏览文件 @
4b9893ca
...
...
@@ -96,6 +96,7 @@ cc_library(
deps
=
[
":opencl_headers"
,
"//mace/codegen:generated_opencl_dev"
,
"//mace/utils:utils_hdrs"
,
],
)
...
...
mace/core/runtime/opencl/opencl_development.cc
浏览文件 @
4b9893ca
...
...
@@ -5,24 +5,11 @@
#include <vector>
#include "mace/core/runtime/opencl/cl2_header.h"
#include "mace/utils/utils.h"
namespace
mace
{
namespace
{
inline
void
DecryptOpenCLSource
(
const
std
::
vector
<
unsigned
char
>
&
src
,
std
::
vector
<
unsigned
char
>
*
dst
)
{
dst
->
reserve
(
src
.
size
());
// Keep consistent with encrypt in python tool
const
std
::
string
decrypt_lookup_table
=
"Xiaomi-AI-Platform-Mace"
;
size_t
lookup_table_size
=
decrypt_lookup_table
.
size
();
for
(
int
i
=
0
;
i
<
src
.
size
();
i
++
)
{
dst
->
push_back
(
src
[
i
]
^
decrypt_lookup_table
[
i
%
lookup_table_size
]);
}
}
}
// namespace
bool
GetSourceOrBinaryProgram
(
const
std
::
string
&
program_name
,
const
std
::
string
&
binary_file_name_prefix
,
cl
::
Context
&
context
,
...
...
@@ -36,9 +23,9 @@ bool GetSourceOrBinaryProgram(const std::string &program_name,
return
false
;
}
cl
::
Program
::
Sources
sources
;
std
::
vector
<
unsigned
char
>
decrypt_source
;
DecryptOpenCLSource
(
it_source
->
second
,
&
decrypt
_source
);
sources
.
push_back
(
std
::
string
(
decrypt_source
.
begin
(),
decrypt_source
.
end
())
);
std
::
string
kernel_source
(
it_source
->
second
.
begin
(),
it_source
->
second
.
end
())
;
ObfuscateString
(
&
kernel
_source
);
sources
.
push_back
(
kernel_source
);
*
program
=
cl
::
Program
(
context
,
sources
);
return
true
;
...
...
mace/python/tools/binary_codegen.py
浏览文件 @
4b9893ca
...
...
@@ -27,6 +27,7 @@ def generate_cpp_source():
key_size
,
=
struct
.
unpack
(
"i"
,
binary_array
[
idx
:
idx
+
4
])
idx
+=
4
key
,
=
struct
.
unpack
(
str
(
key_size
)
+
"s"
,
binary_array
[
idx
:
idx
+
key_size
])
key
=
''
.
join
([
'
\\
x{:02x}'
.
format
(
ord
(
c
))
for
c
in
key
])
idx
+=
key_size
params_size
,
=
struct
.
unpack
(
"i"
,
binary_array
[
idx
:
idx
+
4
])
idx
+=
4
...
...
mace/utils/tuner.h
浏览文件 @
4b9893ca
...
...
@@ -15,6 +15,7 @@
#include "mace/utils/logging.h"
#include "mace/utils/timer.h"
#include "mace/utils/utils.h"
namespace
mace
{
...
...
@@ -42,17 +43,19 @@ class Tuner {
&
param_generator
,
const
std
::
function
<
RetType
(
const
std
::
vector
<
param_type
>
&
)
>
&
func
,
Timer
*
timer
)
{
std
::
string
obfucated_param_key
=
param_key
;
ObfuscateString
(
&
obfucated_param_key
);
if
(
IsTuning
()
&&
param_generator
!=
nullptr
)
{
// tune
std
::
vector
<
param_type
>
opt_param
=
default_param
;
RetType
res
=
Tune
<
RetType
>
(
param_generator
,
func
,
timer
,
&
opt_param
);
VLOG
(
1
)
<<
"Tuning result. "
<<
param_key
<<
": "
<<
internal
::
MakeString
(
opt_param
);
param_table_
[
param_key
]
=
opt_param
;
param_table_
[
obfucated_
param_key
]
=
opt_param
;
return
res
;
}
else
{
// run
if
(
param_table_
.
find
(
param_key
)
!=
param_table_
.
end
())
{
if
(
param_table_
.
find
(
obfucated_
param_key
)
!=
param_table_
.
end
())
{
VLOG
(
1
)
<<
param_key
<<
": "
<<
internal
::
MakeString
(
param_table_
[
param_key
]);
return
func
(
param_table_
[
param_key
]);
...
...
mace/utils/utils.h
浏览文件 @
4b9893ca
...
...
@@ -48,5 +48,15 @@ inline std::string ToString(T v) {
return
ss
.
str
();
}
// ObfuscateString(ObfuscateString(str)) ==> str
inline
void
ObfuscateString
(
std
::
string
*
str
)
{
// Keep consistent with obfuscation in python tools
const
std
::
string
kLookupTable
=
"Xiaomi-AI-Platform-Mace"
;
size_t
lookup_table_size
=
kLookupTable
.
size
();
for
(
int
i
=
0
;
i
<
str
->
size
();
i
++
)
{
(
*
str
)[
i
]
=
(
*
str
)[
i
]
^
kLookupTable
[
i
%
lookup_table_size
];
}
}
}
// namespace mace
#endif // MACE_UTILS_UTILS_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录