Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5c6ae96b
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看板
未验证
提交
5c6ae96b
编写于
8月 23, 2023
作者:
R
ronnywang
提交者:
GitHub
8月 23, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CustomDevice] Fix device occupancy (#56556)
上级
8b17207c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
39 addition
and
45 deletion
+39
-45
paddle/fluid/framework/custom_operator.cc
paddle/fluid/framework/custom_operator.cc
+1
-3
paddle/fluid/memory/allocation/allocator_facade.cc
paddle/fluid/memory/allocation/allocator_facade.cc
+6
-12
paddle/fluid/platform/device/custom/custom_device_resource_pool.cc
...uid/platform/device/custom/custom_device_resource_pool.cc
+14
-14
paddle/fluid/platform/profiler_helper.h
paddle/fluid/platform/profiler_helper.h
+2
-3
paddle/phi/backends/device_manager.cc
paddle/phi/backends/device_manager.cc
+16
-13
未找到文件。
paddle/fluid/framework/custom_operator.cc
浏览文件 @
5c6ae96b
...
...
@@ -946,9 +946,7 @@ static void RegisterOperatorKernel(
#ifdef PADDLE_WITH_CUSTOM_DEVICE
auto
device_types
=
phi
::
DeviceManager
::
GetAllCustomDeviceTypes
();
for
(
const
auto
&
dev_type
:
device_types
)
{
for
(
size_t
dev_id
=
0
;
dev_id
<
phi
::
DeviceManager
::
GetDeviceCount
(
dev_type
);
dev_id
++
)
{
for
(
auto
&
dev_id
:
phi
::
DeviceManager
::
GetSelectedDeviceList
(
dev_type
))
{
RegisterOperatorKernelWithPlace
(
name
,
op_kernel_func
,
proto
::
VarType
::
RAW
,
...
...
paddle/fluid/memory/allocation/allocator_facade.cc
浏览文件 @
5c6ae96b
...
...
@@ -206,9 +206,8 @@ class AllocatorFacadePrivate {
#ifdef PADDLE_WITH_CUSTOM_DEVICE
auto
device_types
=
phi
::
DeviceManager
::
GetAllCustomDeviceTypes
();
for
(
const
auto
&
dev_type
:
device_types
)
{
for
(
size_t
dev_id
=
0
;
dev_id
<
phi
::
DeviceManager
::
GetDeviceCount
(
dev_type
);
++
dev_id
)
{
for
(
auto
&
dev_id
:
phi
::
DeviceManager
::
GetSelectedDeviceList
(
dev_type
))
{
InitNaiveBestFitCustomDeviceAllocator
(
platform
::
CustomPlace
(
dev_type
,
dev_id
));
}
...
...
@@ -272,9 +271,8 @@ class AllocatorFacadePrivate {
#ifdef PADDLE_WITH_CUSTOM_DEVICE
auto
device_types
=
phi
::
DeviceManager
::
GetAllCustomDeviceTypes
();
for
(
const
auto
&
dev_type
:
device_types
)
{
for
(
size_t
dev_id
=
0
;
dev_id
<
phi
::
DeviceManager
::
GetDeviceCount
(
dev_type
);
++
dev_id
)
{
for
(
auto
&
dev_id
:
phi
::
DeviceManager
::
GetSelectedDeviceList
(
dev_type
))
{
InitAutoGrowthCustomDeviceAllocator
(
platform
::
CustomPlace
(
dev_type
,
dev_id
),
allow_free_idle_chunk
);
}
...
...
@@ -1212,9 +1210,7 @@ class AllocatorFacadePrivate {
#ifdef PADDLE_WITH_CUSTOM_DEVICE
auto
device_types
=
phi
::
DeviceManager
::
GetAllCustomDeviceTypes
();
for
(
const
auto
&
dev_type
:
device_types
)
{
for
(
size_t
dev_id
=
0
;
dev_id
<
phi
::
DeviceManager
::
GetDeviceCount
(
dev_type
);
dev_id
++
)
{
for
(
auto
&
dev_id
:
phi
::
DeviceManager
::
GetSelectedDeviceList
(
dev_type
))
{
platform
::
CustomPlace
p
(
dev_type
,
dev_id
);
system_allocators_
[
p
]
=
std
::
make_shared
<
NaiveBestFitAllocator
>
(
p
);
}
...
...
@@ -1248,9 +1244,7 @@ class AllocatorFacadePrivate {
#ifdef PADDLE_WITH_CUSTOM_DEVICE
auto
device_types
=
phi
::
DeviceManager
::
GetAllCustomDeviceTypes
();
for
(
const
auto
&
dev_type
:
device_types
)
{
for
(
size_t
dev_id
=
0
;
dev_id
<
phi
::
DeviceManager
::
GetDeviceCount
(
dev_type
);
dev_id
++
)
{
for
(
auto
&
dev_id
:
phi
::
DeviceManager
::
GetSelectedDeviceList
(
dev_type
))
{
places
.
emplace_back
(
platform
::
CustomPlace
(
dev_type
,
dev_id
));
}
}
...
...
paddle/fluid/platform/device/custom/custom_device_resource_pool.cc
浏览文件 @
5c6ae96b
...
...
@@ -27,9 +27,10 @@ CustomDeviceStreamResourcePool::CustomDeviceStreamResourcePool(
platform
::
errors
::
PreconditionNotMet
(
"Required device shall be CustomPlace, but received %d. "
,
place
));
int
dev_cnt
=
phi
::
DeviceManager
::
GetDeviceCount
(
place
.
GetDeviceType
());
pool_
.
reserve
(
dev_cnt
);
for
(
int
dev_idx
=
0
;
dev_idx
<
dev_cnt
;
++
dev_idx
)
{
auto
selected_devices
=
phi
::
DeviceManager
::
GetSelectedDeviceList
(
place
.
GetDeviceType
());
pool_
.
reserve
(
selected_devices
.
size
());
for
(
auto
&
dev_idx
:
selected_devices
)
{
auto
creator
=
[
place
,
dev_idx
,
this
]
{
auto
place_
=
phi
::
CustomPlace
(
place
.
GetDeviceType
(),
dev_idx
);
phi
::
DeviceManager
::
SetDevice
(
place_
);
...
...
@@ -82,12 +83,11 @@ CustomDeviceStreamResourcePool& CustomDeviceStreamResourcePool::Instance(
if
(
pool
.
find
(
place
.
GetDeviceType
())
==
pool
.
end
())
{
pool
.
insert
({
place
.
GetDeviceType
(),
std
::
vector
<
CustomDeviceStreamResourcePool
*>
()});
for
(
size_t
i
=
0
;
i
<
phi
::
DeviceManager
::
GetDeviceCount
(
place
.
GetDeviceType
());
++
i
)
{
for
(
auto
&
dev_id
:
phi
::
DeviceManager
::
GetSelectedDeviceList
(
place
.
GetDeviceType
()))
{
pool
[
place
.
GetDeviceType
()].
emplace_back
(
new
CustomDeviceStreamResourcePool
(
paddle
::
platform
::
CustomPlace
(
place
.
GetDeviceType
(),
i
)));
paddle
::
platform
::
CustomPlace
(
place
.
GetDeviceType
(),
dev_id
)));
}
}
PADDLE_ENFORCE_LT
(
...
...
@@ -125,9 +125,10 @@ CustomDeviceEventResourcePool::CustomDeviceEventResourcePool(
platform
::
errors
::
PreconditionNotMet
(
"Required device shall be CustomPlace, but received %d. "
,
place
));
int
dev_cnt
=
phi
::
DeviceManager
::
GetDeviceCount
(
place
.
GetDeviceType
());
pool_
.
reserve
(
dev_cnt
);
for
(
int
dev_idx
=
0
;
dev_idx
<
dev_cnt
;
++
dev_idx
)
{
auto
selected_devices
=
phi
::
DeviceManager
::
GetSelectedDeviceList
(
place
.
GetDeviceType
());
pool_
.
reserve
(
selected_devices
.
size
());
for
(
auto
&
dev_idx
:
selected_devices
)
{
auto
creator
=
[
place
,
dev_idx
,
this
]
{
auto
place_
=
phi
::
CustomPlace
(
place
.
GetDeviceType
(),
dev_idx
);
phi
::
DeviceManager
::
SetDevice
(
place_
);
...
...
@@ -180,12 +181,11 @@ CustomDeviceEventResourcePool& CustomDeviceEventResourcePool::Instance(
if
(
pool
.
find
(
place
.
GetDeviceType
())
==
pool
.
end
())
{
pool
.
insert
(
{
place
.
GetDeviceType
(),
std
::
vector
<
CustomDeviceEventResourcePool
*>
()});
for
(
size_t
i
=
0
;
i
<
phi
::
DeviceManager
::
GetDeviceCount
(
place
.
GetDeviceType
());
++
i
)
{
for
(
auto
&
dev_id
:
phi
::
DeviceManager
::
GetSelectedDeviceList
(
place
.
GetDeviceType
()))
{
pool
[
place
.
GetDeviceType
()].
emplace_back
(
new
CustomDeviceEventResourcePool
(
paddle
::
platform
::
CustomPlace
(
place
.
GetDeviceType
(),
i
)));
paddle
::
platform
::
CustomPlace
(
place
.
GetDeviceType
(),
dev_id
)));
}
}
PADDLE_ENFORCE_LT
(
...
...
paddle/fluid/platform/profiler_helper.h
浏览文件 @
5c6ae96b
...
...
@@ -116,9 +116,8 @@ void SynchronizeAllDevice() {
auto
dev_types
=
phi
::
DeviceManager
::
GetAllCustomDeviceTypes
();
for
(
const
auto
&
dev_type
:
dev_types
)
{
int
pre_device_id
=
phi
::
DeviceManager
::
GetDevice
(
dev_type
);
auto
dev_cnt
=
phi
::
DeviceManager
::
GetDeviceCount
(
dev_type
);
for
(
size_t
i
=
0
;
i
<
dev_cnt
;
i
++
)
{
auto
place
=
paddle
::
platform
::
CustomPlace
(
dev_type
,
i
);
for
(
auto
&
dev_id
:
phi
::
DeviceManager
::
GetSelectedDeviceList
(
dev_type
))
{
auto
place
=
paddle
::
platform
::
CustomPlace
(
dev_type
,
dev_id
);
phi
::
DeviceManager
::
SetDevice
(
place
);
phi
::
DeviceManager
::
SynchronizeDevice
(
place
);
}
...
...
paddle/phi/backends/device_manager.cc
浏览文件 @
5c6ae96b
...
...
@@ -465,21 +465,24 @@ std::vector<size_t> DeviceManager::GetDeviceList(
std
::
vector
<
size_t
>
DeviceManager
::
GetSelectedDeviceList
(
const
std
::
string
&
device_type
)
{
std
::
vector
<
size_t
>
devices
;
std
::
string
FLAGS
=
"FLAGS_selected_"
+
device_type
+
"s"
;
auto
FLAGS_selected_devices
=
getenv
(
FLAGS
.
c_str
());
if
(
FLAGS_selected_devices
)
{
auto
devices_str
=
paddle
::
string
::
Split
(
FLAGS_selected_devices
,
','
);
for
(
auto
id
:
devices_str
)
{
devices
.
push_back
(
atoi
(
id
.
c_str
()));
}
}
else
{
int
count
=
DeviceManager
::
GetDeviceCount
(
device_type
);
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
devices
.
push_back
(
i
);
static
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
size_t
>>
device_list_map
;
if
(
device_list_map
.
find
(
device_type
)
==
device_list_map
.
end
())
{
std
::
vector
<
size_t
>&
device_list
=
device_list_map
[
device_type
];
std
::
string
FLAGS
=
"FLAGS_selected_"
+
device_type
+
"s"
;
auto
FLAGS_selected_devices
=
getenv
(
FLAGS
.
c_str
());
if
(
FLAGS_selected_devices
)
{
auto
devices_str
=
paddle
::
string
::
Split
(
FLAGS_selected_devices
,
','
);
for
(
auto
id
:
devices_str
)
{
device_list
.
push_back
(
atoi
(
id
.
c_str
()));
}
}
else
{
int
count
=
DeviceManager
::
GetDeviceCount
(
device_type
);
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
device_list
.
push_back
(
i
);
}
}
}
return
device
s
;
return
device
_list_map
[
device_type
]
;
}
void
DeviceManager
::
CCLDestroyComm
(
const
std
::
string
&
device_type
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录