Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e8b9ae20
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e8b9ae20
编写于
9月 25, 2022
作者:
S
sneaxiy
提交者:
GitHub
9月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move some singleton to cc file (#46470)
上级
991ec7d3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
24 deletion
+42
-24
paddle/fluid/framework/op_version_registry.cc
paddle/fluid/framework/op_version_registry.cc
+10
-0
paddle/fluid/framework/op_version_registry.h
paddle/fluid/framework/op_version_registry.h
+4
-8
paddle/fluid/platform/device_context.cc
paddle/fluid/platform/device_context.cc
+24
-1
paddle/fluid/platform/device_context.h
paddle/fluid/platform/device_context.h
+4
-15
未找到文件。
paddle/fluid/framework/op_version_registry.cc
浏览文件 @
e8b9ae20
...
@@ -70,6 +70,11 @@ OpVersionDesc&& OpVersionDesc::DeleteOutput(const std::string& name,
...
@@ -70,6 +70,11 @@ OpVersionDesc&& OpVersionDesc::DeleteOutput(const std::string& name,
return
std
::
move
(
*
this
);
return
std
::
move
(
*
this
);
}
}
OpVersionRegistrar
&
OpVersionRegistrar
::
GetInstance
()
{
static
OpVersionRegistrar
instance
;
return
instance
;
}
OpVersion
&
OpVersionRegistrar
::
Register
(
const
std
::
string
&
op_type
)
{
OpVersion
&
OpVersionRegistrar
::
Register
(
const
std
::
string
&
op_type
)
{
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
op_version_map_
.
find
(
op_type
),
op_version_map_
.
find
(
op_type
),
...
@@ -89,6 +94,11 @@ uint32_t OpVersionRegistrar::version_id(const std::string& op_type) const {
...
@@ -89,6 +94,11 @@ uint32_t OpVersionRegistrar::version_id(const std::string& op_type) const {
return
op_version_map_
.
find
(
op_type
)
->
second
.
version_id
();
return
op_version_map_
.
find
(
op_type
)
->
second
.
version_id
();
}
}
PassVersionCheckerRegistrar
&
PassVersionCheckerRegistrar
::
GetInstance
()
{
static
PassVersionCheckerRegistrar
instance
;
return
instance
;
}
// Provide a fake registration item for pybind testing.
// Provide a fake registration item for pybind testing.
#include "paddle/fluid/framework/op_version_registry.inl"
#include "paddle/fluid/framework/op_version_registry.inl"
...
...
paddle/fluid/framework/op_version_registry.h
浏览文件 @
e8b9ae20
...
@@ -230,10 +230,8 @@ class OpVersion {
...
@@ -230,10 +230,8 @@ class OpVersion {
class
OpVersionRegistrar
{
class
OpVersionRegistrar
{
public:
public:
static
OpVersionRegistrar
&
GetInstance
()
{
static
OpVersionRegistrar
&
GetInstance
();
static
OpVersionRegistrar
instance
;
return
instance
;
}
OpVersion
&
Register
(
const
std
::
string
&
op_type
);
OpVersion
&
Register
(
const
std
::
string
&
op_type
);
const
std
::
unordered_map
<
std
::
string
,
OpVersion
>&
GetVersionMap
()
{
const
std
::
unordered_map
<
std
::
string
,
OpVersion
>&
GetVersionMap
()
{
return
op_version_map_
;
return
op_version_map_
;
...
@@ -365,10 +363,8 @@ class PassVersionCheckers {
...
@@ -365,10 +363,8 @@ class PassVersionCheckers {
class
PassVersionCheckerRegistrar
{
class
PassVersionCheckerRegistrar
{
public:
public:
static
PassVersionCheckerRegistrar
&
GetInstance
()
{
static
PassVersionCheckerRegistrar
&
GetInstance
();
static
PassVersionCheckerRegistrar
instance
;
return
instance
;
}
PassVersionCheckers
&
Register
(
const
std
::
string
&
pass_name
)
{
PassVersionCheckers
&
Register
(
const
std
::
string
&
pass_name
)
{
PADDLE_ENFORCE_EQ
(
pass_version_checkers_map_
.
find
(
pass_name
),
PADDLE_ENFORCE_EQ
(
pass_version_checkers_map_
.
find
(
pass_name
),
pass_version_checkers_map_
.
end
(),
pass_version_checkers_map_
.
end
(),
...
...
paddle/fluid/platform/device_context.cc
浏览文件 @
e8b9ae20
...
@@ -73,7 +73,30 @@ DeviceType Place2DeviceType(const platform::Place& place) {
...
@@ -73,7 +73,30 @@ DeviceType Place2DeviceType(const platform::Place& place) {
}
}
}
}
DeviceContextPool
*
DeviceContextPool
::
pool
=
nullptr
;
static
DeviceContextPool
*
pool
=
nullptr
;
DeviceContextPool
&
DeviceContextPool
::
Instance
()
{
PADDLE_ENFORCE_NOT_NULL
(
pool
,
phi
::
errors
::
PreconditionNotMet
(
"Need to Create DeviceContextPool firstly!"
));
return
*
pool
;
}
/*! \brief Create should only called by Init function */
DeviceContextPool
&
DeviceContextPool
::
Init
(
const
std
::
vector
<
platform
::
Place
>&
places
)
{
if
(
pool
==
nullptr
)
{
pool
=
new
DeviceContextPool
(
places
);
}
return
*
pool
;
}
bool
DeviceContextPool
::
IsInitialized
()
{
return
pool
!=
nullptr
;
}
void
DeviceContextPool
::
SetPool
(
DeviceContextPool
*
dev_pool
)
{
pool
=
dev_pool
;
}
thread_local
const
std
::
map
<
Place
,
thread_local
const
std
::
map
<
Place
,
std
::
shared_future
<
std
::
unique_ptr
<
DeviceContext
>>>*
std
::
shared_future
<
std
::
unique_ptr
<
DeviceContext
>>>*
DeviceContextPool
::
external_device_contexts_
=
nullptr
;
DeviceContextPool
::
external_device_contexts_
=
nullptr
;
...
...
paddle/fluid/platform/device_context.h
浏览文件 @
e8b9ae20
...
@@ -339,24 +339,14 @@ void EmplaceDeviceContexts(
...
@@ -339,24 +339,14 @@ void EmplaceDeviceContexts(
/*! \brief device context pool singleton */
/*! \brief device context pool singleton */
class
DeviceContextPool
{
class
DeviceContextPool
{
public:
public:
static
DeviceContextPool
&
Instance
()
{
static
DeviceContextPool
&
Instance
();
PADDLE_ENFORCE_NOT_NULL
(
pool
,
platform
::
errors
::
PreconditionNotMet
(
"Need to Create DeviceContextPool firstly!"
));
return
*
pool
;
}
/*! \brief Create should only called by Init function */
/*! \brief Create should only called by Init function */
static
DeviceContextPool
&
Init
(
const
std
::
vector
<
platform
::
Place
>&
places
)
{
static
DeviceContextPool
&
Init
(
const
std
::
vector
<
platform
::
Place
>&
places
);
if
(
pool
==
nullptr
)
{
pool
=
new
DeviceContextPool
(
places
);
}
return
*
pool
;
}
static
bool
IsInitialized
()
{
return
pool
!=
nullptr
;
}
static
bool
IsInitialized
()
;
static
void
SetPool
(
DeviceContextPool
*
dev_pool
)
{
pool
=
dev_pool
;
}
static
void
SetPool
(
DeviceContextPool
*
dev_pool
)
;
/*! \brief Return handle of single device context. */
/*! \brief Return handle of single device context. */
platform
::
DeviceContext
*
Get
(
const
platform
::
Place
&
place
);
platform
::
DeviceContext
*
Get
(
const
platform
::
Place
&
place
);
...
@@ -380,7 +370,6 @@ class DeviceContextPool {
...
@@ -380,7 +370,6 @@ class DeviceContextPool {
private:
private:
explicit
DeviceContextPool
(
const
std
::
vector
<
platform
::
Place
>&
places
);
explicit
DeviceContextPool
(
const
std
::
vector
<
platform
::
Place
>&
places
);
static
DeviceContextPool
*
pool
;
std
::
map
<
Place
,
std
::
shared_future
<
std
::
unique_ptr
<
DeviceContext
>>>
std
::
map
<
Place
,
std
::
shared_future
<
std
::
unique_ptr
<
DeviceContext
>>>
device_contexts_
;
device_contexts_
;
static
thread_local
const
std
::
static
thread_local
const
std
::
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录