Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
71d375bb
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
71d375bb
编写于
11月 02, 2021
作者:
C
Chen Weihang
提交者:
GitHub
11月 02, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[PTen] Add lock to kernel signature map init (#36923)
* add lock to kernel sig map * add lock for map emplace
上级
e512aa9a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
25 deletion
+51
-25
paddle/fluid/framework/pten_utils.cc
paddle/fluid/framework/pten_utils.cc
+37
-0
paddle/fluid/framework/pten_utils.h
paddle/fluid/framework/pten_utils.h
+14
-25
未找到文件。
paddle/fluid/framework/pten_utils.cc
浏览文件 @
71d375bb
...
...
@@ -59,6 +59,43 @@ pten::KernelKey TransOpKernelTypeToPtenKernelKey(
return
pten
::
KernelKey
(
backend
,
layout
,
dtype
);
}
KernelSignatureMap
*
KernelSignatureMap
::
kernel_signature_map_
=
nullptr
;
std
::
mutex
KernelSignatureMap
::
mutex_
;
KernelSignatureMap
&
KernelSignatureMap
::
Instance
()
{
if
(
kernel_signature_map_
==
nullptr
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex_
);
if
(
kernel_signature_map_
==
nullptr
)
{
kernel_signature_map_
=
new
KernelSignatureMap
;
}
}
return
*
kernel_signature_map_
;
}
bool
KernelSignatureMap
::
Has
(
const
std
::
string
&
op_type
)
const
{
return
map_
.
find
(
op_type
)
!=
map_
.
end
();
}
void
KernelSignatureMap
::
Emplace
(
const
std
::
string
&
op_type
,
KernelSignature
&&
signature
)
{
if
(
!
Has
(
op_type
))
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex_
);
if
(
!
Has
(
op_type
))
{
map_
.
emplace
(
op_type
,
signature
);
}
}
}
const
KernelSignature
&
KernelSignatureMap
::
Get
(
const
std
::
string
&
op_type
)
const
{
auto
it
=
map_
.
find
(
op_type
);
PADDLE_ENFORCE_NE
(
it
,
map_
.
end
(),
platform
::
errors
::
NotFound
(
"Operator `%s`'s kernel signature is not registered."
,
op_type
));
return
it
->
second
;
}
const
paddle
::
SmallVector
<
std
::
string
>&
KernelArgsNameMakerByOpProto
::
GetInputArgsNames
()
{
for
(
int
i
=
0
;
i
<
op_proto_
->
inputs_size
();
++
i
)
{
...
...
paddle/fluid/framework/pten_utils.h
浏览文件 @
71d375bb
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
...
...
@@ -62,35 +63,23 @@ struct KernelSignature {
// TODO(chenweihang): we can generate this map by proto info in compile time
class
KernelSignatureMap
{
public:
static
KernelSignatureMap
&
Instance
()
{
static
KernelSignatureMap
g_kernel_signature_map
;
return
g_kernel_signature_map
;
}
bool
Has
(
const
std
::
string
&
op_type
)
const
{
return
map_
.
find
(
op_type
)
!=
map_
.
end
();
}
void
Emplace
(
const
std
::
string
&
op_type
,
KernelSignature
&&
signature
)
{
if
(
!
Has
(
op_type
))
{
map_
.
emplace
(
op_type
,
signature
);
}
}
const
KernelSignature
&
Get
(
const
std
::
string
&
op_type
)
const
{
auto
it
=
map_
.
find
(
op_type
);
PADDLE_ENFORCE_NE
(
it
,
map_
.
end
(),
platform
::
errors
::
NotFound
(
"Operator `%s`'s kernel signature is not registered."
,
op_type
));
return
it
->
second
;
}
static
KernelSignatureMap
&
Instance
();
bool
Has
(
const
std
::
string
&
op_type
)
const
;
void
Emplace
(
const
std
::
string
&
op_type
,
KernelSignature
&&
signature
);
const
KernelSignature
&
Get
(
const
std
::
string
&
op_type
)
const
;
private:
KernelSignatureMap
()
=
default
;
paddle
::
flat_hash_map
<
std
::
string
,
KernelSignature
>
map_
;
DISABLE_COPY_AND_ASSIGN
(
KernelSignatureMap
);
private:
static
KernelSignatureMap
*
kernel_signature_map_
;
static
std
::
mutex
mutex_
;
paddle
::
flat_hash_map
<
std
::
string
,
KernelSignature
>
map_
;
};
class
KernelArgsNameMaker
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录