Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
668bfb35
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
668bfb35
编写于
9月 03, 2021
作者:
L
Leo Chen
提交者:
GitHub
9月 03, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] add 32 extra bytes for npu memory slot (#35347)
上级
e913796c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
23 addition
and
9 deletion
+23
-9
paddle/fluid/memory/allocation/naive_best_fit_allocator.cc
paddle/fluid/memory/allocation/naive_best_fit_allocator.cc
+6
-4
paddle/fluid/memory/detail/buddy_allocator.cc
paddle/fluid/memory/detail/buddy_allocator.cc
+9
-3
paddle/fluid/memory/detail/buddy_allocator.h
paddle/fluid/memory/detail/buddy_allocator.h
+5
-2
paddle/fluid/platform/device_memory_aligment.cc
paddle/fluid/platform/device_memory_aligment.cc
+3
-0
未找到文件。
paddle/fluid/memory/allocation/naive_best_fit_allocator.cc
浏览文件 @
668bfb35
...
...
@@ -225,6 +225,7 @@ size_t Used<platform::XPUPlace>(const platform::XPUPlace &place) {
// For Ascend NPU
#ifdef PADDLE_WITH_ASCEND_CL
constexpr
int
EXTRA_PADDING_SIZE
=
32
;
class
NPUBuddyAllocatorList
{
private:
NPUBuddyAllocatorList
()
:
devices_
(
platform
::
GetSelectedNPUDevices
())
{
...
...
@@ -257,10 +258,11 @@ class NPUBuddyAllocatorList {
std
::
call_once
(
*
init_flags_
[
pos
],
[
this
,
pos
]
{
platform
::
SetNPUDeviceId
(
devices_
[
pos
]);
allocators_
[
pos
].
reset
(
new
BuddyAllocator
(
std
::
unique_ptr
<
detail
::
SystemAllocator
>
(
new
detail
::
NPUAllocator
(
devices_
[
pos
])),
platform
::
NPUMinChunkSize
(),
platform
::
NPUMaxChunkSize
()));
allocators_
[
pos
].
reset
(
new
BuddyAllocator
(
std
::
unique_ptr
<
detail
::
SystemAllocator
>
(
new
detail
::
NPUAllocator
(
devices_
[
pos
])),
platform
::
NPUMinChunkSize
(),
platform
::
NPUMaxChunkSize
(),
EXTRA_PADDING_SIZE
));
VLOG
(
10
)
<<
"
\n\n
NOTE:
\n
"
<<
"You can set GFlags environment variable "
<<
"'FLAGS_fraction_of_gpu_memory_to_use' "
...
...
paddle/fluid/memory/detail/buddy_allocator.cc
浏览文件 @
668bfb35
...
...
@@ -31,9 +31,10 @@ namespace detail {
BuddyAllocator
::
BuddyAllocator
(
std
::
unique_ptr
<
SystemAllocator
>
system_allocator
,
size_t
min_chunk_size
,
size_t
max_chunk_size
)
size_t
max_chunk_size
,
size_t
extra_padding_size
)
:
min_chunk_size_
(
min_chunk_size
),
max_chunk_size_
(
max_chunk_size
),
extra_padding_size_
(
extra_padding_size
),
cache_
(
system_allocator
->
UseGpu
()),
system_allocator_
(
std
::
move
(
system_allocator
))
{}
...
...
@@ -59,9 +60,14 @@ inline size_t align(size_t size, size_t alignment) {
void
*
BuddyAllocator
::
Alloc
(
size_t
unaligned_size
)
{
// adjust allocation alignment
size_t
size
=
align
(
unaligned_size
+
sizeof
(
MemoryBlock
::
Desc
),
min_chunk_size_
);
size_t
size
=
align
(
unaligned_size
+
sizeof
(
MemoryBlock
::
Desc
)
+
extra_padding_size_
,
min_chunk_size_
);
VLOG
(
10
)
<<
"alloc: "
<<
unaligned_size
<<
", padding for desc: "
<<
sizeof
(
MemoryBlock
::
Desc
)
<<
", extra padding: "
<<
extra_padding_size_
<<
", alignment: "
<<
min_chunk_size_
;
// acquire the allocator lock
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
...
...
paddle/fluid/memory/detail/buddy_allocator.h
浏览文件 @
668bfb35
...
...
@@ -35,7 +35,8 @@ namespace detail {
class
BuddyAllocator
{
public:
BuddyAllocator
(
std
::
unique_ptr
<
SystemAllocator
>
system_allocator
,
size_t
min_chunk_size
,
size_t
max_chunk_size
);
size_t
min_chunk_size
,
size_t
max_chunk_size
,
size_t
extra_padding_size
=
0
);
~
BuddyAllocator
();
...
...
@@ -86,7 +87,9 @@ class BuddyAllocator {
size_t
min_chunk_size_
;
// the minimum size of each chunk
size_t
max_chunk_size_
;
// the maximum size of each chunk
size_t
realloc_size_
=
0
;
// the size of re-allocated chunk
size_t
realloc_size_
=
0
;
// the size of re-allocated chunk
size_t
extra_padding_size_
=
0
;
// the size of padding to the size of memory
// to alloc, especially used in NPU
private:
/**
...
...
paddle/fluid/platform/device_memory_aligment.cc
浏览文件 @
668bfb35
...
...
@@ -37,6 +37,9 @@ size_t Alignment(size_t size, const platform::Place &place, int align_size) {
#endif
}
}
if
(
is_npu_place
(
place
))
{
size
+=
32
;
// required by ascendcl
}
size_t
remaining
=
size
%
alignment
;
return
remaining
==
0
?
size
:
size
+
(
alignment
-
remaining
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录