Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
e285258e
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看板
未验证
提交
e285258e
编写于
8月 09, 2021
作者:
L
Leo Chen
提交者:
GitHub
8月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] add lock for npu_pinned_allocator (#34700)
* add lock * fix typo
上级
80092576
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
6 addition
and
0 deletion
+6
-0
paddle/fluid/memory/allocation/npu_pinned_allocator.cc
paddle/fluid/memory/allocation/npu_pinned_allocator.cc
+5
-0
paddle/fluid/memory/allocation/npu_pinned_allocator.h
paddle/fluid/memory/allocation/npu_pinned_allocator.h
+1
-0
未找到文件。
paddle/fluid/memory/allocation/npu_pinned_allocator.cc
浏览文件 @
e285258e
...
@@ -39,6 +39,7 @@ void NPUPinnedAllocator::ProcessEventsAndFree() {
...
@@ -39,6 +39,7 @@ void NPUPinnedAllocator::ProcessEventsAndFree() {
}
}
Allocation
*
NPUPinnedAllocator
::
AllocateImpl
(
size_t
size
)
{
Allocation
*
NPUPinnedAllocator
::
AllocateImpl
(
size_t
size
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mtx_
);
ProcessEventsAndFree
();
ProcessEventsAndFree
();
void
*
ptr
;
void
*
ptr
;
int
error
=
posix_memalign
(
&
ptr
,
kAlignment
,
size
);
int
error
=
posix_memalign
(
&
ptr
,
kAlignment
,
size
);
...
@@ -50,6 +51,7 @@ Allocation *NPUPinnedAllocator::AllocateImpl(size_t size) {
...
@@ -50,6 +51,7 @@ Allocation *NPUPinnedAllocator::AllocateImpl(size_t size) {
}
}
void
NPUPinnedAllocator
::
FreeImpl
(
Allocation
*
allocation
)
{
void
NPUPinnedAllocator
::
FreeImpl
(
Allocation
*
allocation
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mtx_
);
void
*
ptr
=
allocation
->
ptr
();
void
*
ptr
=
allocation
->
ptr
();
auto
iter
=
npu_events_
.
find
(
allocation
);
auto
iter
=
npu_events_
.
find
(
allocation
);
aclrtEvent
event
=
iter
->
second
;
aclrtEvent
event
=
iter
->
second
;
...
@@ -65,11 +67,14 @@ void NPUPinnedAllocator::FreeImpl(Allocation *allocation) {
...
@@ -65,11 +67,14 @@ void NPUPinnedAllocator::FreeImpl(Allocation *allocation) {
}
}
uint64_t
NPUPinnedAllocator
::
ReleaseImpl
(
const
platform
::
Place
&
place
)
{
uint64_t
NPUPinnedAllocator
::
ReleaseImpl
(
const
platform
::
Place
&
place
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mtx_
);
// Empty implementation
return
static_cast
<
uint64_t
>
(
0
);
return
static_cast
<
uint64_t
>
(
0
);
}
}
void
NPUPinnedAllocator
::
RecordEvent
(
Allocation
*
allocation
,
void
NPUPinnedAllocator
::
RecordEvent
(
Allocation
*
allocation
,
aclrtStream
stream
)
{
aclrtStream
stream
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mtx_
);
aclrtEvent
event
=
nullptr
;
aclrtEvent
event
=
nullptr
;
PADDLE_ENFORCE_NPU_SUCCESS
(
aclrtCreateEvent
(
&
event
));
PADDLE_ENFORCE_NPU_SUCCESS
(
aclrtCreateEvent
(
&
event
));
PADDLE_ENFORCE_NPU_SUCCESS
(
aclrtRecordEvent
(
event
,
stream
));
PADDLE_ENFORCE_NPU_SUCCESS
(
aclrtRecordEvent
(
event
,
stream
));
...
...
paddle/fluid/memory/allocation/npu_pinned_allocator.h
浏览文件 @
e285258e
...
@@ -42,6 +42,7 @@ class NPUPinnedAllocator : public Allocator {
...
@@ -42,6 +42,7 @@ class NPUPinnedAllocator : public Allocator {
private:
private:
std
::
unordered_map
<
Allocation
*
,
aclrtEvent
>
npu_events_
;
std
::
unordered_map
<
Allocation
*
,
aclrtEvent
>
npu_events_
;
mutable
std
::
mutex
mtx_
;
};
};
}
// namespace allocation
}
// namespace allocation
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录