Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
0ac642b5
MegEngine
项目概览
MegEngine 天元
/
MegEngine
接近 2 年 前同步成功
通知
414
Star
4708
Fork
583
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
0ac642b5
编写于
6月 04, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(imperative): persistent cache write through on put
GitOrigin-RevId: f9408ae5046a28b06b6de914f430a15c78ab82d9
上级
47dcdf3e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
9 addition
and
1 deletion
+9
-1
imperative/python/src/utils.cpp
imperative/python/src/utils.cpp
+9
-1
未找到文件。
imperative/python/src/utils.cpp
浏览文件 @
0ac642b5
...
...
@@ -18,6 +18,7 @@
#include <pybind11/operators.h>
#include <atomic>
#include <cstdint>
#include <shared_mutex>
#include "./imperative_rt.h"
#include "megbrain/common.h"
#include "megbrain/comp_node.h"
...
...
@@ -236,12 +237,16 @@ void init_utils(py::module m) {
m
.
def
(
"_timed_func_exec_cb"
,
[](
const
std
::
string
&
user_data
){
mgb
::
sys
::
TimedFuncInvoker
::
ins
().
fork_exec_impl_mainloop
(
user_data
.
c_str
());
});
using
mgb
::
PersistentCache
;
class
PyPersistentCache
:
public
mgb
::
PersistentCache
{
private:
using
KeyPair
=
std
::
pair
<
std
::
string
,
std
::
string
>
;
using
BlobPtr
=
std
::
unique_ptr
<
Blob
,
void
(
*
)(
Blob
*
)
>
;
std
::
shared_mutex
m_mutex
;
std
::
unordered_map
<
KeyPair
,
BlobPtr
,
mgb
::
pairhash
>
m_local_cache
;
static
size_t
hash_key_pair
(
const
KeyPair
&
kp
)
{
std
::
hash
<
std
::
string
>
hasher
;
return
hasher
(
kp
.
first
)
^
hasher
(
kp
.
second
);
...
...
@@ -275,11 +280,11 @@ void init_utils(py::module m) {
}
public:
mgb
::
Maybe
<
Blob
>
get
(
const
std
::
string
&
category
,
const
Blob
&
key
)
override
{
thread_local
std
::
unordered_map
<
KeyPair
,
BlobPtr
,
mgb
::
pairhash
>
m_local_cache
;
auto
py_get
=
[
this
](
const
std
::
string
&
category
,
const
Blob
&
key
)
->
mgb
::
Maybe
<
Blob
>
{
PYBIND11_OVERLOAD_PURE
(
mgb
::
Maybe
<
Blob
>
,
PersistentCache
,
get
,
category
,
key
);
};
KeyPair
kp
=
{
category
,
blob_to_str
(
key
)
};
std
::
shared_lock
<
decltype
(
m_mutex
)
>
rlock
;
auto
iter
=
m_local_cache
.
find
(
kp
);
if
(
iter
==
m_local_cache
.
end
())
{
auto
py_ret
=
py_get
(
category
,
key
);
...
...
@@ -296,6 +301,9 @@ void init_utils(py::module m) {
}
}
void
put
(
const
std
::
string
&
category
,
const
Blob
&
key
,
const
Blob
&
value
)
override
{
KeyPair
kp
=
{
category
,
blob_to_str
(
key
)
};
std
::
unique_lock
<
decltype
(
m_mutex
)
>
wlock
;
m_local_cache
.
insert_or_assign
(
kp
,
copy_blob
(
value
));
PYBIND11_OVERLOAD_PURE
(
void
,
PersistentCache
,
put
,
category
,
key
,
value
);
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录