Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
08d9caa0
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,发现更多精彩内容 >>
提交
08d9caa0
编写于
5月 03, 2018
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unuseful code for mt opencl runtime.
上级
67f9c391
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
16 addition
and
34 deletion
+16
-34
mace/core/file_storage.cc
mace/core/file_storage.cc
+4
-1
mace/core/file_storage.h
mace/core/file_storage.h
+1
-0
mace/core/runtime/opencl/opencl_runtime.cc
mace/core/runtime/opencl/opencl_runtime.cc
+3
-11
mace/core/runtime/opencl/opencl_runtime.h
mace/core/runtime/opencl/opencl_runtime.h
+0
-2
mace/utils/rwlock.h
mace/utils/rwlock.h
+8
-20
未找到文件。
mace/core/file_storage.cc
浏览文件 @
08d9caa0
...
@@ -57,7 +57,7 @@ std::unique_ptr<KVStorage> FileStorageFactory::CreateStorage(
...
@@ -57,7 +57,7 @@ std::unique_ptr<KVStorage> FileStorageFactory::CreateStorage(
}
}
FileStorage
::
FileStorage
(
const
std
::
string
&
file_path
)
:
FileStorage
::
FileStorage
(
const
std
::
string
&
file_path
)
:
file_path_
(
file_path
)
{}
data_changed_
(
false
),
file_path_
(
file_path
)
{}
int
FileStorage
::
Load
()
{
int
FileStorage
::
Load
()
{
struct
stat
st
;
struct
stat
st
;
...
@@ -151,6 +151,7 @@ bool FileStorage::Insert(const std::string &key,
...
@@ -151,6 +151,7 @@ bool FileStorage::Insert(const std::string &key,
const
std
::
vector
<
unsigned
char
>
&
value
)
{
const
std
::
vector
<
unsigned
char
>
&
value
)
{
utils
::
WriteLock
lock
(
&
data_mutex_
);
utils
::
WriteLock
lock
(
&
data_mutex_
);
data_
.
emplace
(
key
,
value
);
data_
.
emplace
(
key
,
value
);
data_changed_
=
true
;
return
true
;
return
true
;
}
}
...
@@ -164,6 +165,7 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) {
...
@@ -164,6 +165,7 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) {
int
FileStorage
::
Flush
()
{
int
FileStorage
::
Flush
()
{
utils
::
WriteLock
lock
(
&
data_mutex_
);
utils
::
WriteLock
lock
(
&
data_mutex_
);
if
(
!
data_changed_
)
return
0
;
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_
...
@@ -224,6 +226,7 @@ int FileStorage::Flush() {
...
@@ -224,6 +226,7 @@ int FileStorage::Flush() {
<<
" failed, error code: "
<<
errno
;
<<
" failed, error code: "
<<
errno
;
return
-
1
;
return
-
1
;
}
}
data_changed_
=
false
;
return
0
;
return
0
;
}
}
...
...
mace/core/file_storage.h
浏览文件 @
08d9caa0
...
@@ -36,6 +36,7 @@ class FileStorage : public KVStorage {
...
@@ -36,6 +36,7 @@ class FileStorage : public KVStorage {
int
Flush
()
override
;
int
Flush
()
override
;
private:
private:
bool
data_changed_
;
std
::
string
file_path_
;
std
::
string
file_path_
;
std
::
map
<
std
::
string
,
std
::
vector
<
unsigned
char
>>
data_
;
std
::
map
<
std
::
string
,
std
::
vector
<
unsigned
char
>>
data_
;
utils
::
RWMutex
data_mutex_
;
utils
::
RWMutex
data_mutex_
;
...
...
mace/core/runtime/opencl/opencl_runtime.cc
浏览文件 @
08d9caa0
...
@@ -348,8 +348,6 @@ OpenCLRuntime::OpenCLRuntime():
...
@@ -348,8 +348,6 @@ OpenCLRuntime::OpenCLRuntime():
&
err
);
&
err
);
MACE_CHECK_CL_SUCCESS
(
err
);
MACE_CHECK_CL_SUCCESS
(
err
);
this
->
program_map_changed_
=
false
;
extern
std
::
shared_ptr
<
KVStorageFactory
>
kStorageFactory
;
extern
std
::
shared_ptr
<
KVStorageFactory
>
kStorageFactory
;
if
(
kStorageFactory
!=
nullptr
)
{
if
(
kStorageFactory
!=
nullptr
)
{
const
std
::
string
cl_compiled_file_name
=
"mace_cl_compiled_program.bin"
;
const
std
::
string
cl_compiled_file_name
=
"mace_cl_compiled_program.bin"
;
...
@@ -512,8 +510,6 @@ void OpenCLRuntime::BuildProgramFromSource(
...
@@ -512,8 +510,6 @@ void OpenCLRuntime::BuildProgramFromSource(
if
(
this
->
storage_
!=
nullptr
)
{
if
(
this
->
storage_
!=
nullptr
)
{
this
->
storage_
->
Insert
(
built_program_key
,
content
);
this
->
storage_
->
Insert
(
built_program_key
,
content
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
program_map_changed_mutex_
);
this
->
program_map_changed_
=
true
;
}
}
VLOG
(
3
)
<<
"Program from source: "
<<
built_program_key
;
VLOG
(
3
)
<<
"Program from source: "
<<
built_program_key
;
...
@@ -567,13 +563,9 @@ cl::Kernel OpenCLRuntime::BuildKernel(
...
@@ -567,13 +563,9 @@ cl::Kernel OpenCLRuntime::BuildKernel(
void
OpenCLRuntime
::
SaveBuiltCLProgram
()
{
void
OpenCLRuntime
::
SaveBuiltCLProgram
()
{
if
(
storage_
!=
nullptr
)
{
if
(
storage_
!=
nullptr
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
program_map_changed_mutex_
);
if
(
storage_
->
Flush
()
!=
0
)
{
if
(
program_map_changed_
)
{
LOG
(
FATAL
)
<<
"Store OPENCL compiled kernel to file failed."
if
(
storage_
->
Flush
()
!=
0
)
{
" Please Make sure the storage directory exist."
;
LOG
(
FATAL
)
<<
"Store OPENCL compiled kernel to file failed."
" Please Make sure the storage directory exist."
;
}
program_map_changed_
=
false
;
}
}
}
}
}
}
...
...
mace/core/runtime/opencl/opencl_runtime.h
浏览文件 @
08d9caa0
...
@@ -125,11 +125,9 @@ class OpenCLRuntime {
...
@@ -125,11 +125,9 @@ class OpenCLRuntime {
std
::
shared_ptr
<
cl
::
CommandQueue
>
command_queue_
;
std
::
shared_ptr
<
cl
::
CommandQueue
>
command_queue_
;
std
::
map
<
std
::
string
,
cl
::
Program
>
built_program_map_
;
std
::
map
<
std
::
string
,
cl
::
Program
>
built_program_map_
;
std
::
mutex
program_build_mutex_
;
std
::
mutex
program_build_mutex_
;
std
::
mutex
program_map_changed_mutex_
;
std
::
string
platform_info_
;
std
::
string
platform_info_
;
std
::
string
opencl_version_
;
std
::
string
opencl_version_
;
bool
out_of_range_check_
;
bool
out_of_range_check_
;
bool
program_map_changed_
;
uint64_t
device_gloabl_mem_cache_size_
;
uint64_t
device_gloabl_mem_cache_size_
;
uint32_t
device_compute_units_
;
uint32_t
device_compute_units_
;
GPUType
gpu_type_
;
GPUType
gpu_type_
;
...
...
mace/utils/rwlock.h
浏览文件 @
08d9caa0
...
@@ -43,29 +43,22 @@ class RWMutex {
...
@@ -43,29 +43,22 @@ class RWMutex {
class
ReadLock
{
class
ReadLock
{
public:
public:
explicit
ReadLock
(
RWMutex
*
rw_mutex
)
:
rw_mutex_
(
rw_mutex
)
{
explicit
ReadLock
(
RWMutex
*
rw_mutex
)
:
rw_mutex_
(
rw_mutex
)
{
if
(
rw_mutex_
==
nullptr
)
{
MACE_CHECK_NOTNULL
(
rw_mutex
);
return
;
}
std
::
unique_lock
<
std
::
mutex
>
lock
(
rw_mutex
->
mutex_
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
rw_mutex
->
mutex_
);
rw_mutex
->
waiting_readers_
++
;
rw_mutex
->
waiting_readers_
+=
1
;
rw_mutex
->
reader_cv_
.
wait
(
lock
,
[
&
]()
->
bool
{
rw_mutex
->
reader_cv_
.
wait
(
lock
,
[
&
]()
->
bool
{
return
rw_mutex
->
waiting_writers_
==
0
&&
rw_mutex
->
counter_
>=
0
;
return
rw_mutex
->
waiting_writers_
==
0
&&
rw_mutex
->
counter_
>=
0
;
});
});
rw_mutex
->
waiting_readers_
--
;
rw_mutex
->
waiting_readers_
-=
1
;
rw_mutex
->
counter_
++
;
rw_mutex
->
counter_
+=
1
;
}
}
~
ReadLock
()
{
~
ReadLock
()
{
if
(
rw_mutex_
==
nullptr
)
{
return
;
}
std
::
unique_lock
<
std
::
mutex
>
lock
(
rw_mutex_
->
mutex_
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
rw_mutex_
->
mutex_
);
rw_mutex_
->
counter_
-=
1
;
rw_mutex_
->
counter_
-=
1
;
if
(
rw_mutex_
->
waiting_writers_
>
0
)
{
if
(
rw_mutex_
->
waiting_writers_
>
0
)
{
if
(
rw_mutex_
->
counter_
==
0
)
{
if
(
rw_mutex_
->
counter_
==
0
)
{
rw_mutex_
->
writer_cv_
.
notify_one
();
rw_mutex_
->
writer_cv_
.
notify_one
();
}
}
}
else
{
rw_mutex_
->
reader_cv_
.
notify_all
();
}
}
}
}
ReadLock
(
const
ReadLock
&
)
=
delete
;
ReadLock
(
const
ReadLock
&
)
=
delete
;
...
@@ -80,21 +73,16 @@ class ReadLock {
...
@@ -80,21 +73,16 @@ class ReadLock {
class
WriteLock
{
class
WriteLock
{
public:
public:
explicit
WriteLock
(
RWMutex
*
rw_mutex
)
:
rw_mutex_
(
rw_mutex
)
{
explicit
WriteLock
(
RWMutex
*
rw_mutex
)
:
rw_mutex_
(
rw_mutex
)
{
if
(
rw_mutex_
==
nullptr
)
{
MACE_CHECK_NOTNULL
(
rw_mutex
);
return
;
}
std
::
unique_lock
<
std
::
mutex
>
lock
(
rw_mutex
->
mutex_
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
rw_mutex
->
mutex_
);
rw_mutex
->
waiting_writers_
++
;
rw_mutex
->
waiting_writers_
+=
1
;
rw_mutex
->
writer_cv_
.
wait
(
lock
,
[
&
]()
->
bool
{
rw_mutex
->
writer_cv_
.
wait
(
lock
,
[
&
]()
->
bool
{
return
rw_mutex
->
counter_
==
0
;
return
rw_mutex
->
counter_
==
0
;
});
});
rw_mutex
->
waiting_writers_
--
;
rw_mutex
->
waiting_writers_
-=
1
;
rw_mutex
->
counter_
--
;
rw_mutex
->
counter_
-=
1
;
}
}
~
WriteLock
()
{
~
WriteLock
()
{
if
(
rw_mutex_
==
nullptr
)
{
return
;
}
std
::
unique_lock
<
std
::
mutex
>
lock
(
rw_mutex_
->
mutex_
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
rw_mutex_
->
mutex_
);
rw_mutex_
->
counter_
=
0
;
rw_mutex_
->
counter_
=
0
;
if
(
rw_mutex_
->
waiting_writers_
>
0
)
{
if
(
rw_mutex_
->
waiting_writers_
>
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录