Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
853d8a3e
Mace
项目概览
慢慢CG
/
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看板
提交
853d8a3e
编写于
4月 08, 2018
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace KVStorageStatus with int.
上级
91f2b780
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
27 addition
and
27 deletion
+27
-27
mace/core/file_storage.cc
mace/core/file_storage.cc
+19
-15
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
+2
-2
mace/public/mace_runtime.h
mace/public/mace_runtime.h
+4
-8
未找到文件。
mace/core/file_storage.cc
浏览文件 @
853d8a3e
...
@@ -49,25 +49,29 @@ std::unique_ptr<KVStorage> FileStorageFactory::CreateStorage(
...
@@ -49,25 +49,29 @@ 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
)
{}
KVStorageStatus
FileStorage
::
Load
()
{
int
FileStorage
::
Load
()
{
struct
stat
st
;
struct
stat
st
;
if
(
stat
(
file_path_
.
c_str
(),
&
st
)
==
-
1
)
{
if
(
stat
(
file_path_
.
c_str
(),
&
st
)
==
-
1
)
{
if
(
errno
==
ENOENT
)
{
if
(
errno
==
ENOENT
)
{
return
KVStorageStatus
::
STORAGE_FILE_NOT_EXIST
;
LOG
(
INFO
)
<<
"File "
<<
file_path_
<<
" does not exist"
;
return
0
;
}
else
{
}
else
{
LOG
(
WARNING
)
<<
"
s
tat file "
<<
file_path_
LOG
(
WARNING
)
<<
"
S
tat file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
<<
" failed, error code: "
<<
errno
;
return
KVStorageStatus
::
STORAGE_ERROR
;
return
-
1
;
}
}
}
}
int
fd
=
open
(
file_path_
.
c_str
(),
O_RDONLY
);
int
fd
=
open
(
file_path_
.
c_str
(),
O_RDONLY
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
if
(
errno
==
ENOENT
)
{
if
(
errno
==
ENOENT
)
{
return
KVStorageStatus
::
STORAGE_FILE_NOT_EXIST
;
LOG
(
INFO
)
<<
"File "
<<
file_path_
<<
" does not exist"
;
return
0
;
}
else
{
}
else
{
LOG
(
WARNING
)
<<
"open file "
<<
file_path_
LOG
(
WARNING
)
<<
"open file "
<<
file_path_
<<
" failed, error code: "
<<
errno
;
<<
" failed, error code: "
<<
errno
;
return
KVStorageStatus
::
STORAGE_ERROR
;
return
-
1
;
}
}
}
}
size_t
file_size
=
st
.
st_size
;
size_t
file_size
=
st
.
st_size
;
...
@@ -84,7 +88,7 @@ KVStorageStatus FileStorage::Load() {
...
@@ -84,7 +88,7 @@ KVStorageStatus FileStorage::Load() {
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
-
1
;
}
}
unsigned
char
*
file_data_ptr
=
file_data
;
unsigned
char
*
file_data_ptr
=
file_data
;
...
@@ -121,15 +125,15 @@ KVStorageStatus FileStorage::Load() {
...
@@ -121,15 +125,15 @@ KVStorageStatus FileStorage::Load() {
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
-
1
;
}
}
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
-
1
;
}
}
return
KVStorageStatus
::
STORAGE_SUCCESS
;
return
0
;
}
}
bool
FileStorage
::
Insert
(
const
std
::
string
&
key
,
bool
FileStorage
::
Insert
(
const
std
::
string
&
key
,
...
@@ -145,12 +149,12 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) {
...
@@ -145,12 +149,12 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) {
return
&
(
iter
->
second
);
return
&
(
iter
->
second
);
}
}
KVStorageStatus
FileStorage
::
Flush
()
{
int
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
KVStorageStatus
::
STORAGE_ERROR
;
return
-
1
;
}
}
const
size_t
int_size
=
sizeof
(
int32_t
);
const
size_t
int_size
=
sizeof
(
int32_t
);
...
@@ -194,7 +198,7 @@ KVStorageStatus FileStorage::Flush() {
...
@@ -194,7 +198,7 @@ KVStorageStatus FileStorage::Flush() {
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
-
1
;
}
}
remain_size
-=
buffer_size
;
remain_size
-=
buffer_size
;
buffer_ptr
+=
buffer_size
;
buffer_ptr
+=
buffer_size
;
...
@@ -204,9 +208,9 @@ KVStorageStatus FileStorage::Flush() {
...
@@ -204,9 +208,9 @@ KVStorageStatus 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
-
1
;
}
}
return
KVStorageStatus
::
STORAGE_SUCCESS
;
return
0
;
}
}
};
// namespace mace
};
// namespace mace
mace/core/file_storage.h
浏览文件 @
853d8a3e
...
@@ -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:
KVStorageStatus
Load
()
override
;
int
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
;
KVStorageStatus
Flush
()
override
;
int
Flush
()
override
;
private:
private:
std
::
string
file_path_
;
std
::
string
file_path_
;
...
...
mace/core/runtime/opencl/opencl_runtime.cc
浏览文件 @
853d8a3e
...
@@ -317,7 +317,7 @@ OpenCLRuntime::OpenCLRuntime(GPUPerfHint gpu_perf_hint,
...
@@ -317,7 +317,7 @@ 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
)
{
if
(
storage_
->
Load
()
==
KVStorageStatus
::
STORAGE_ERROR
)
{
if
(
storage_
->
Load
()
!=
0
)
{
LOG
(
FATAL
)
<<
"Load opencl compiled kernel file failed"
;
LOG
(
FATAL
)
<<
"Load opencl compiled kernel file failed"
;
}
}
}
}
...
@@ -506,7 +506,7 @@ cl::Kernel OpenCLRuntime::BuildKernel(
...
@@ -506,7 +506,7 @@ cl::Kernel OpenCLRuntime::BuildKernel(
void
OpenCLRuntime
::
SaveBuiltCLProgram
()
{
void
OpenCLRuntime
::
SaveBuiltCLProgram
()
{
if
(
program_map_changed_
&&
storage_
!=
nullptr
)
{
if
(
program_map_changed_
&&
storage_
!=
nullptr
)
{
if
(
storage_
->
Flush
()
!=
KVStorageStatus
::
STORAGE_SUCCESS
)
{
if
(
storage_
->
Flush
()
!=
0
)
{
LOG
(
FATAL
)
<<
"Store opencl compiled kernel to file failed"
;
LOG
(
FATAL
)
<<
"Store opencl compiled kernel to file failed"
;
}
}
program_map_changed_
=
false
;
program_map_changed_
=
false
;
...
...
mace/public/mace_runtime.h
浏览文件 @
853d8a3e
...
@@ -31,19 +31,15 @@ enum GPUPriorityHint {
...
@@ -31,19 +31,15 @@ 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
KVStorageStatus
Load
()
=
0
;
// return: 0 for success, -1 for error
virtual
int
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
KVStorageStatus
Flush
()
=
0
;
// return: 0 for success, -1 for error
virtual
int
Flush
()
=
0
;
};
};
class
KVStorageFactory
{
class
KVStorageFactory
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录