Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
01345a51
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
01345a51
编写于
5月 23, 2023
作者:
L
Leo Chen
提交者:
GitHub
5月 23, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add host memory stats (#54036)
* add host memory stats * add ut
上级
3dc99088
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
74 addition
and
3 deletion
+74
-3
paddle/fluid/memory/allocation/buddy_allocator.cc
paddle/fluid/memory/allocation/buddy_allocator.cc
+5
-3
paddle/fluid/memory/allocation/cpu_allocator.cc
paddle/fluid/memory/allocation/cpu_allocator.cc
+4
-0
paddle/fluid/memory/allocation/naive_best_fit_allocator.cc
paddle/fluid/memory/allocation/naive_best_fit_allocator.cc
+3
-0
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+2
-0
python/paddle/fluid/tests/unittests/test_host_memory_stats.py
...on/paddle/fluid/tests/unittests/test_host_memory_stats.py
+60
-0
未找到文件。
paddle/fluid/memory/allocation/buddy_allocator.cc
浏览文件 @
01345a51
...
...
@@ -59,6 +59,8 @@ BuddyAllocator::BuddyAllocator(
#endif
}
#endif
VLOG
(
1
)
<<
"min_chunk_size_: "
<<
min_chunk_size_
<<
", max_chunk_size_:"
<<
max_chunk_size_
;
}
BuddyAllocator
::~
BuddyAllocator
()
{
...
...
@@ -228,7 +230,7 @@ void* BuddyAllocator::SystemAlloc(size_t size) {
size_t
index
=
0
;
void
*
p
=
system_allocator_
->
Alloc
(
&
index
,
size
);
VLOG
(
10
)
<<
"Allocated "
<<
p
<<
" from system allocator."
;
VLOG
(
8
)
<<
"Allocated "
<<
p
<<
" size "
<<
size
<<
" from system allocator."
;
if
(
p
==
nullptr
)
return
nullptr
;
...
...
@@ -258,8 +260,8 @@ BuddyAllocator::PoolSet::iterator BuddyAllocator::RefillPool(
if
(
p
==
nullptr
)
return
pool_
.
end
();
VLOG
(
10
)
<<
"Creating and inserting new block "
<<
p
<<
" from system allocator"
;
VLOG
(
8
)
<<
"Creating and inserting new block "
<<
p
<<
" size "
<<
allocate_bytes
<<
" from system allocator"
;
static_cast
<
MemoryBlock
*>
(
p
)
->
Init
(
&
cache_
,
MemoryBlock
::
FREE_CHUNK
,
...
...
paddle/fluid/memory/allocation/cpu_allocator.cc
浏览文件 @
01345a51
...
...
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include "paddle/fluid/memory/stats.h"
#include "paddle/fluid/platform/enforce.h"
namespace
paddle
{
...
...
@@ -25,12 +26,14 @@ namespace allocation {
bool
CPUAllocator
::
IsAllocThreadSafe
()
const
{
return
true
;
}
void
CPUAllocator
::
FreeImpl
(
phi
::
Allocation
*
allocation
)
{
auto
size
=
allocation
->
size
();
void
*
p
=
allocation
->
ptr
();
#ifdef _WIN32
_aligned_free
(
p
);
#else
free
(
p
);
#endif
HOST_MEMORY_STAT_UPDATE
(
Reserved
,
0
,
-
size
);
delete
allocation
;
}
...
...
@@ -46,6 +49,7 @@ phi::Allocation *CPUAllocator::AllocateImpl(size_t size) {
platform
::
errors
::
ResourceExhausted
(
"Fail to alloc memory of %ld size, error code is %d."
,
size
,
error
));
#endif
HOST_MEMORY_STAT_UPDATE
(
Reserved
,
0
,
size
);
return
new
Allocation
(
p
,
size
,
platform
::
CPUPlace
());
}
}
// namespace allocation
...
...
paddle/fluid/memory/allocation/naive_best_fit_allocator.cc
浏览文件 @
01345a51
...
...
@@ -379,6 +379,7 @@ template <>
void
*
Alloc
<
platform
::
CUDAPinnedPlace
>
(
const
platform
::
CUDAPinnedPlace
&
place
,
size_t
size
)
{
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
VLOG
(
10
)
<<
"Allocate "
<<
size
<<
" bytes on "
<<
platform
::
Place
(
place
);
auto
*
buddy_allocator
=
GetCUDAPinnedBuddyAllocator
();
void
*
ptr
=
buddy_allocator
->
Alloc
(
size
);
...
...
@@ -401,6 +402,7 @@ void Free<platform::CUDAPinnedPlace>(const platform::CUDAPinnedPlace &place,
void
*
p
,
size_t
size
)
{
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
VLOG
(
10
)
<<
"Free "
<<
size
<<
" bytes on "
<<
platform
::
Place
(
place
);
GetCUDAPinnedBuddyAllocator
()
->
Free
(
p
);
#else
PADDLE_THROW
(
platform
::
errors
::
PermissionDenied
(
...
...
@@ -412,6 +414,7 @@ template <>
uint64_t
Release
<
platform
::
CUDAPinnedPlace
>
(
const
platform
::
CUDAPinnedPlace
&
place
)
{
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
VLOG
(
10
)
<<
"Release on "
<<
platform
::
Place
(
place
);
return
GetCUDAPinnedBuddyAllocator
()
->
Release
();
#else
PADDLE_THROW
(
platform
::
errors
::
PermissionDenied
(
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
01345a51
...
...
@@ -1946,6 +1946,8 @@ All parameter, weight, gradient are variables in Paddle.
m
.
def
(
"device_memory_stat_current_value"
,
memory
::
DeviceMemoryStatCurrentValue
);
m
.
def
(
"device_memory_stat_peak_value"
,
memory
::
DeviceMemoryStatPeakValue
);
m
.
def
(
"host_memory_stat_current_value"
,
memory
::
HostMemoryStatCurrentValue
);
m
.
def
(
"host_memory_stat_peak_value"
,
memory
::
HostMemoryStatPeakValue
);
m
.
def
(
"run_cmd"
,
[](
const
std
::
string
&
cmd
,
...
...
python/paddle/fluid/tests/unittests/test_host_memory_stats.py
0 → 100644
浏览文件 @
01345a51
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
unittest
import
paddle
from
paddle.fluid
import
core
paddle
.
set_device
(
'cpu'
)
class
TestHostMemoryStats
(
unittest
.
TestCase
):
def
test_memory_allocated_with_pinned
(
self
,
device
=
None
):
if
core
.
is_compiled_with_cuda
():
tensor
=
paddle
.
zeros
(
shape
=
[
256
])
tensor_pinned
=
tensor
.
pin_memory
()
alloc_size
=
4
*
256
# 256 float32 data, with 4 bytes for each one
memory_allocated_size
=
core
.
host_memory_stat_current_value
(
"Allocated"
,
0
)
self
.
assertEqual
(
memory_allocated_size
,
alloc_size
*
2
)
def
foo
():
tensor
=
paddle
.
zeros
(
shape
=
[
256
])
tensor_pinned
=
tensor
.
pin_memory
()
memory_allocated_size
=
core
.
host_memory_stat_current_value
(
"Allocated"
,
0
)
self
.
assertEqual
(
memory_allocated_size
,
alloc_size
*
4
)
max_allocated_size
=
core
.
host_memory_stat_peak_value
(
"Allocated"
,
0
)
self
.
assertEqual
(
memory_allocated_size
,
alloc_size
*
4
)
foo
()
memory_allocated_size
=
core
.
host_memory_stat_current_value
(
"Allocated"
,
0
)
self
.
assertEqual
(
memory_allocated_size
,
alloc_size
*
2
)
max_allocated_size
=
core
.
host_memory_stat_peak_value
(
"Allocated"
,
0
)
self
.
assertEqual
(
max_allocated_size
,
alloc_size
*
4
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录