Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
91f2b780
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,发现更多精彩内容 >>
提交
91f2b780
编写于
4月 08, 2018
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refacotr KVStorage apis with return status.
上级
36458f35
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
55 addition
and
18 deletion
+55
-18
mace/core/file_storage.cc
mace/core/file_storage.cc
+38
-11
mace/core/file_storage.h
mace/core/file_storage.h
+2
-2
mace/core/runtime/opencl/opencl_runtime.cc
mace/core/runtime/opencl/opencl_runtime.cc
+6
-2
mace/public/mace_runtime.h
mace/public/mace_runtime.h
+8
-2
tools/mace_tools.py
tools/mace_tools.py
+1
-1
未找到文件。
mace/core/file_storage.cc
浏览文件 @
91f2b780
...
@@ -49,16 +49,28 @@ std::unique_ptr<KVStorage> FileStorageFactory::CreateStorage(
...
@@ -49,16 +49,28 @@ std::unique_ptr<KVStorage> FileStorageFactory::CreateStorage(
FileStorage
::
FileStorage
(
const
std
::
string
&
file_path
)
:
FileStorage
::
FileStorage
(
const
std
::
string
&
file_path
)
:
file_path_
(
file_path
)
{}
file_path_
(
file_path
)
{}
void
FileStorage
::
Load
()
{
KVStorageStatus
FileStorage
::
Load
()
{
struct
stat
st
;
struct
stat
st
;
stat
(
file_path_
.
c_str
(),
&
st
);
if
(
stat
(
file_path_
.
c_str
(),
&
st
)
==
-
1
)
{
size_t
file_size
=
st
.
st_size
;
if
(
errno
==
ENOENT
)
{
return
KVStorageStatus
::
STORAGE_FILE_NOT_EXIST
;
}
else
{
LOG
(
WARNING
)
<<
"stat file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
return
KVStorageStatus
::
STORAGE_ERROR
;
}
}
int
fd
=
open
(
file_path_
.
c_str
(),
O_RDONLY
);
int
fd
=
open
(
file_path_
.
c_str
(),
O_RDONLY
);
if
(
fd
==
-
1
)
{
if
(
fd
<
0
)
{
LOG
(
WARNING
)
<<
"open file "
<<
file_path_
if
(
errno
==
ENOENT
)
{
<<
" failed, error code: "
<<
errno
;
return
KVStorageStatus
::
STORAGE_FILE_NOT_EXIST
;
return
;
}
else
{
LOG
(
WARNING
)
<<
"open file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
return
KVStorageStatus
::
STORAGE_ERROR
;
}
}
}
size_t
file_size
=
st
.
st_size
;
unsigned
char
*
file_data
=
unsigned
char
*
file_data
=
static_cast
<
unsigned
char
*>
(
mmap
(
nullptr
,
file_size
,
PROT_READ
,
static_cast
<
unsigned
char
*>
(
mmap
(
nullptr
,
file_size
,
PROT_READ
,
MAP_PRIVATE
,
fd
,
0
));
MAP_PRIVATE
,
fd
,
0
));
...
@@ -72,7 +84,7 @@ void FileStorage::Load() {
...
@@ -72,7 +84,7 @@ void FileStorage::Load() {
LOG
(
WARNING
)
<<
"close file "
<<
file_path_
LOG
(
WARNING
)
<<
"close file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
<<
" failed, error code: "
<<
errno
;
}
}
return
;
return
KVStorageStatus
::
STORAGE_ERROR
;
}
}
unsigned
char
*
file_data_ptr
=
file_data
;
unsigned
char
*
file_data_ptr
=
file_data
;
...
@@ -104,12 +116,20 @@ void FileStorage::Load() {
...
@@ -104,12 +116,20 @@ void FileStorage::Load() {
if
(
res
!=
0
)
{
if
(
res
!=
0
)
{
LOG
(
WARNING
)
<<
"munmap file "
<<
file_path_
LOG
(
WARNING
)
<<
"munmap file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
<<
" failed, error code: "
<<
errno
;
res
=
close
(
fd
);
if
(
res
!=
0
)
{
LOG
(
WARNING
)
<<
"close file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
}
return
KVStorageStatus
::
STORAGE_ERROR
;
}
}
res
=
close
(
fd
);
res
=
close
(
fd
);
if
(
res
!=
0
)
{
if
(
res
!=
0
)
{
LOG
(
WARNING
)
<<
"close file "
<<
file_path_
LOG
(
WARNING
)
<<
"close file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
<<
" failed, error code: "
<<
errno
;
return
KVStorageStatus
::
STORAGE_ERROR
;
}
}
return
KVStorageStatus
::
STORAGE_SUCCESS
;
}
}
bool
FileStorage
::
Insert
(
const
std
::
string
&
key
,
bool
FileStorage
::
Insert
(
const
std
::
string
&
key
,
...
@@ -125,12 +145,12 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) {
...
@@ -125,12 +145,12 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) {
return
&
(
iter
->
second
);
return
&
(
iter
->
second
);
}
}
void
FileStorage
::
Flush
()
{
KVStorageStatus
FileStorage
::
Flush
()
{
int
fd
=
open
(
file_path_
.
c_str
(),
O_WRONLY
|
O_CREAT
,
0600
);
int
fd
=
open
(
file_path_
.
c_str
(),
O_WRONLY
|
O_CREAT
,
0600
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
LOG
(
WARNING
)
<<
"open file "
<<
file_path_
LOG
(
WARNING
)
<<
"open file "
<<
file_path_
<<
" failed, error code:"
<<
errno
;
<<
" failed, error code:"
<<
errno
;
return
;
return
KVStorageStatus
::
STORAGE_ERROR
;
}
}
const
size_t
int_size
=
sizeof
(
int32_t
);
const
size_t
int_size
=
sizeof
(
int32_t
);
...
@@ -169,7 +189,12 @@ void FileStorage::Flush() {
...
@@ -169,7 +189,12 @@ void FileStorage::Flush() {
if
(
res
==
-
1
)
{
if
(
res
==
-
1
)
{
LOG
(
WARNING
)
<<
"write file "
<<
file_path_
LOG
(
WARNING
)
<<
"write file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
<<
" failed, error code: "
<<
errno
;
return
;
res
=
close
(
fd
);
if
(
res
!=
0
)
{
LOG
(
WARNING
)
<<
"close file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
}
return
KVStorageStatus
::
STORAGE_ERROR
;
}
}
remain_size
-=
buffer_size
;
remain_size
-=
buffer_size
;
buffer_ptr
+=
buffer_size
;
buffer_ptr
+=
buffer_size
;
...
@@ -179,7 +204,9 @@ void FileStorage::Flush() {
...
@@ -179,7 +204,9 @@ void FileStorage::Flush() {
if
(
res
!=
0
)
{
if
(
res
!=
0
)
{
LOG
(
WARNING
)
<<
"close file "
<<
file_path_
LOG
(
WARNING
)
<<
"close file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
<<
" failed, error code: "
<<
errno
;
return
KVStorageStatus
::
STORAGE_ERROR
;
}
}
return
KVStorageStatus
::
STORAGE_SUCCESS
;
}
}
};
// namespace mace
};
// namespace mace
mace/core/file_storage.h
浏览文件 @
91f2b780
...
@@ -18,11 +18,11 @@ class FileStorage : public KVStorage {
...
@@ -18,11 +18,11 @@ class FileStorage : public KVStorage {
explicit
FileStorage
(
const
std
::
string
&
file_path
);
explicit
FileStorage
(
const
std
::
string
&
file_path
);
public:
public:
void
Load
()
override
;
KVStorageStatus
Load
()
override
;
bool
Insert
(
const
std
::
string
&
key
,
bool
Insert
(
const
std
::
string
&
key
,
const
std
::
vector
<
unsigned
char
>
&
value
)
override
;
const
std
::
vector
<
unsigned
char
>
&
value
)
override
;
const
std
::
vector
<
unsigned
char
>
*
Find
(
const
std
::
string
&
key
)
override
;
const
std
::
vector
<
unsigned
char
>
*
Find
(
const
std
::
string
&
key
)
override
;
void
Flush
()
override
;
KVStorageStatus
Flush
()
override
;
private:
private:
std
::
string
file_path_
;
std
::
string
file_path_
;
...
...
mace/core/runtime/opencl/opencl_runtime.cc
浏览文件 @
91f2b780
...
@@ -317,7 +317,9 @@ OpenCLRuntime::OpenCLRuntime(GPUPerfHint gpu_perf_hint,
...
@@ -317,7 +317,9 @@ OpenCLRuntime::OpenCLRuntime(GPUPerfHint gpu_perf_hint,
storage_
=
kStorageFactory
->
CreateStorage
(
cl_compiled_file_name
);
storage_
=
kStorageFactory
->
CreateStorage
(
cl_compiled_file_name
);
if
(
platform_info_
!=
kCompiledProgramPlatform
)
{
if
(
platform_info_
!=
kCompiledProgramPlatform
)
{
storage_
->
Load
();
if
(
storage_
->
Load
()
==
KVStorageStatus
::
STORAGE_ERROR
)
{
LOG
(
FATAL
)
<<
"Load opencl compiled kernel file failed"
;
}
}
}
}
}
}
}
...
@@ -504,7 +506,9 @@ cl::Kernel OpenCLRuntime::BuildKernel(
...
@@ -504,7 +506,9 @@ cl::Kernel OpenCLRuntime::BuildKernel(
void
OpenCLRuntime
::
SaveBuiltCLProgram
()
{
void
OpenCLRuntime
::
SaveBuiltCLProgram
()
{
if
(
program_map_changed_
&&
storage_
!=
nullptr
)
{
if
(
program_map_changed_
&&
storage_
!=
nullptr
)
{
storage_
->
Flush
();
if
(
storage_
->
Flush
()
!=
KVStorageStatus
::
STORAGE_SUCCESS
)
{
LOG
(
FATAL
)
<<
"Store opencl compiled kernel to file failed"
;
}
program_map_changed_
=
false
;
program_map_changed_
=
false
;
}
}
}
}
...
...
mace/public/mace_runtime.h
浏览文件 @
91f2b780
...
@@ -31,13 +31,19 @@ enum GPUPriorityHint {
...
@@ -31,13 +31,19 @@ enum GPUPriorityHint {
enum
CPUPowerOption
{
DEFAULT
=
0
,
HIGH_PERFORMANCE
=
1
,
BATTERY_SAVE
=
2
};
enum
CPUPowerOption
{
DEFAULT
=
0
,
HIGH_PERFORMANCE
=
1
,
BATTERY_SAVE
=
2
};
enum
KVStorageStatus
{
STORAGE_SUCCESS
=
0
,
STORAGE_FILE_NOT_EXIST
=
1
,
STORAGE_ERROR
=
2
};
class
KVStorage
{
class
KVStorage
{
public:
public:
virtual
void
Load
()
=
0
;
virtual
KVStorageStatus
Load
()
=
0
;
virtual
bool
Insert
(
const
std
::
string
&
key
,
virtual
bool
Insert
(
const
std
::
string
&
key
,
const
std
::
vector
<
unsigned
char
>
&
value
)
=
0
;
const
std
::
vector
<
unsigned
char
>
&
value
)
=
0
;
virtual
const
std
::
vector
<
unsigned
char
>
*
Find
(
const
std
::
string
&
key
)
=
0
;
virtual
const
std
::
vector
<
unsigned
char
>
*
Find
(
const
std
::
string
&
key
)
=
0
;
virtual
void
Flush
()
=
0
;
virtual
KVStorageStatus
Flush
()
=
0
;
};
};
class
KVStorageFactory
{
class
KVStorageFactory
{
...
...
tools/mace_tools.py
浏览文件 @
91f2b780
...
@@ -215,7 +215,7 @@ def build_mace_run_prod(model_name, target_runtime, target_abi, target_soc,
...
@@ -215,7 +215,7 @@ def build_mace_run_prod(model_name, target_runtime, target_abi, target_soc,
tuning_run
(
tuning_run
(
model_name
,
model_name
,
target_runtime
,
target_runtime
,
target_abi
,
target_abi
,
target_soc
,
target_soc
,
model_output_dir
,
model_output_dir
,
running_round
=
0
,
running_round
=
0
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录