Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d13c7799
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看板
未验证
提交
d13c7799
编写于
1月 15, 2022
作者:
石
石晓伟
提交者:
GitHub
1月 15, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
isolates friends of storage, test=develop (#38977)
上级
35d2b71a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
44 deletion
+10
-44
paddle/pten/api/lib/utils/tensor_utils.cc
paddle/pten/api/lib/utils/tensor_utils.cc
+9
-36
paddle/pten/core/compat_utils.h
paddle/pten/core/compat_utils.h
+1
-8
未找到文件。
paddle/pten/api/lib/utils/tensor_utils.cc
浏览文件 @
d13c7799
...
...
@@ -325,9 +325,7 @@ void SharesStorageBase(pten::DenseTensor* src, paddle::framework::Tensor* dst) {
platform
::
errors
::
InvalidArgument
(
"The destination Tensor is nullptr when move allocation."
));
dst
->
Resize
(
src
->
dims
());
auto
*
storage
=
static_cast
<
SharedStorage
*>
(
pten
::
CompatibleDenseTensorUtils
::
UnsafeGetMutableStorage
(
src
));
dst
->
ResetHolderWithType
(
storage
->
GetAllocation
(),
dst
->
ResetHolderWithType
(
src
->
Holder
(),
pten
::
TransToProtoVarType
(
src
->
dtype
()));
dst
->
set_offset
(
src
->
meta
().
offset
);
}
...
...
@@ -345,19 +343,7 @@ void ReMakePtenDenseTensorBase(const paddle::framework::Tensor& src,
meta
->
dtype
=
pten
::
TransToPtenDataType
(
src
.
type
());
meta
->
layout
=
src
.
layout
();
meta
->
offset
=
src
.
offset
();
auto
*
shared_storage
=
static_cast
<
SharedStorage
*>
(
pten
::
CompatibleDenseTensorUtils
::
UnsafeGetMutableStorage
(
dst
));
PADDLE_ENFORCE_NOT_NULL
(
shared_storage
,
platform
::
errors
::
NotFound
(
"Target DenseTensor's shared storage is nullptr."
));
PADDLE_ENFORCE_EQ
(
src
.
IsInitialized
(),
true
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"Source Tensor is not initialized."
));
shared_storage
->
ResetAllocation
(
src
.
Holder
());
dst
->
ResetHolder
(
src
.
Holder
());
}
void
ReMakePtenDenseTensor
(
const
paddle
::
framework
::
Tensor
&
src
,
...
...
@@ -378,19 +364,12 @@ void ReMakePtenDenseTensorByArgDefBase(const paddle::framework::Tensor& src,
meta
->
layout
=
src
.
layout
();
meta
->
offset
=
src
.
offset
();
auto
*
shared_storage
=
static_cast
<
SharedStorage
*>
(
pten
::
CompatibleDenseTensorUtils
::
UnsafeGetMutableStorage
(
dst
));
PADDLE_ENFORCE_NOT_NULL
(
shared_storage
,
platform
::
errors
::
NotFound
(
"Target DenseTensor's shared storage is nullptr."
));
if
(
src
.
IsInitialized
()
&&
src
.
place
()
==
pten
::
TransToFluidPlace
(
arg_def
.
backend
))
{
shared_storage
->
ResetAllocation
(
src
.
Holder
());
dst
->
ResetHolder
(
src
.
Holder
());
}
else
{
shared_storage
->
ResetAllocationPlace
(
pten
::
TransToFluidPlace
(
arg_def
.
backend
));
// This does not affect the correctness, and will be modified immediately.
// dst->mutable_data(
pten::TransToFluidPlace(arg_def.backend));
}
}
...
...
@@ -481,14 +460,10 @@ void MakeVariableFromPtenTensor(pten::DenseTensor* src,
tensor
->
Resize
(
src
->
dims
());
SetLoD
(
tensor
->
mutable_lod
(),
src
->
lod
());
// here dynamic_cast is slow
auto
*
storage
=
static_cast
<
SharedStorage
*>
(
pten
::
CompatibleDenseTensorUtils
::
UnsafeGetMutableStorage
(
src
));
if
(
!
tensor
->
IsInitialized
()
||
(
tensor
->
IsInitialized
()
&&
!
IsSameAllocation
(
tensor
->
Holder
(),
s
torage
->
GetAllocation
())))
{
tensor
->
ResetHolderWithType
(
std
::
move
(
s
torage
->
GetAllocation
()),
dtype
);
!
IsSameAllocation
(
tensor
->
Holder
(),
s
rc
->
Holder
())))
{
tensor
->
ResetHolderWithType
(
std
::
move
(
s
rc
->
Holder
()),
dtype
);
}
else
{
// Even the pten tensor and Variable have the same Alloctation (both have
// the same pointer address, same size and same place)
...
...
@@ -502,10 +477,8 @@ void MakeVariableFromPtenTensor(pten::DenseTensor* src,
auto
dtype
=
pten
::
TransToProtoVarType
(
src
->
dtype
());
if
(
!
tensor
->
value
().
IsInitialized
())
{
auto
storage
=
dynamic_cast
<
SharedStorage
*>
(
pten
::
CompatibleDenseTensorUtils
::
UnsafeGetMutableStorage
(
src
));
tensor
->
mutable_value
()
->
ResetHolderWithType
(
std
::
move
(
storage
->
GetAllocation
()),
dtype
);
tensor
->
mutable_value
()
->
ResetHolderWithType
(
std
::
move
(
src
->
Holder
()),
dtype
);
}
}
else
{
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
...
...
paddle/pten/core/compat_utils.h
浏览文件 @
d13c7799
...
...
@@ -31,10 +31,6 @@ namespace pten {
class
CompatibleDenseTensorUtils
{
public:
static
Storage
*
UnsafeGetMutableStorage
(
DenseTensor
*
tensor
)
{
return
tensor
->
storage_
.
get
();
}
static
DenseTensorMeta
*
GetMutableMeta
(
DenseTensor
*
tensor
)
{
return
&
(
tensor
->
meta_
);
}
...
...
@@ -42,10 +38,7 @@ class CompatibleDenseTensorUtils {
// only can deal with SharedStorage now
static
void
ClearStorage
(
DenseTensor
*
tensor
)
{
// use static_cast to improve performance, replace by dynamic_cast later
if
(
tensor
->
storage_
!=
nullptr
)
{
static_cast
<
paddle
::
experimental
::
SharedStorage
*>
(
tensor
->
storage_
.
get
())
->
Reset
();
}
tensor
->
MoveMemoryHolder
();
}
static
DenseTensor
Slice
(
const
DenseTensor
&
tensor
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录