Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
d13c7799
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看板
未验证
提交
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) {
...
@@ -325,9 +325,7 @@ void SharesStorageBase(pten::DenseTensor* src, paddle::framework::Tensor* dst) {
platform
::
errors
::
InvalidArgument
(
platform
::
errors
::
InvalidArgument
(
"The destination Tensor is nullptr when move allocation."
));
"The destination Tensor is nullptr when move allocation."
));
dst
->
Resize
(
src
->
dims
());
dst
->
Resize
(
src
->
dims
());
auto
*
storage
=
static_cast
<
SharedStorage
*>
(
dst
->
ResetHolderWithType
(
src
->
Holder
(),
pten
::
CompatibleDenseTensorUtils
::
UnsafeGetMutableStorage
(
src
));
dst
->
ResetHolderWithType
(
storage
->
GetAllocation
(),
pten
::
TransToProtoVarType
(
src
->
dtype
()));
pten
::
TransToProtoVarType
(
src
->
dtype
()));
dst
->
set_offset
(
src
->
meta
().
offset
);
dst
->
set_offset
(
src
->
meta
().
offset
);
}
}
...
@@ -345,19 +343,7 @@ void ReMakePtenDenseTensorBase(const paddle::framework::Tensor& src,
...
@@ -345,19 +343,7 @@ void ReMakePtenDenseTensorBase(const paddle::framework::Tensor& src,
meta
->
dtype
=
pten
::
TransToPtenDataType
(
src
.
type
());
meta
->
dtype
=
pten
::
TransToPtenDataType
(
src
.
type
());
meta
->
layout
=
src
.
layout
();
meta
->
layout
=
src
.
layout
();
meta
->
offset
=
src
.
offset
();
meta
->
offset
=
src
.
offset
();
dst
->
ResetHolder
(
src
.
Holder
());
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
());
}
}
void
ReMakePtenDenseTensor
(
const
paddle
::
framework
::
Tensor
&
src
,
void
ReMakePtenDenseTensor
(
const
paddle
::
framework
::
Tensor
&
src
,
...
@@ -378,19 +364,12 @@ void ReMakePtenDenseTensorByArgDefBase(const paddle::framework::Tensor& src,
...
@@ -378,19 +364,12 @@ void ReMakePtenDenseTensorByArgDefBase(const paddle::framework::Tensor& src,
meta
->
layout
=
src
.
layout
();
meta
->
layout
=
src
.
layout
();
meta
->
offset
=
src
.
offset
();
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
()
&&
if
(
src
.
IsInitialized
()
&&
src
.
place
()
==
pten
::
TransToFluidPlace
(
arg_def
.
backend
))
{
src
.
place
()
==
pten
::
TransToFluidPlace
(
arg_def
.
backend
))
{
shared_storage
->
ResetAllocation
(
src
.
Holder
());
dst
->
ResetHolder
(
src
.
Holder
());
}
else
{
}
else
{
shared_storage
->
ResetAllocationPlace
(
// This does not affect the correctness, and will be modified immediately.
pten
::
TransToFluidPlace
(
arg_def
.
backend
));
// dst->mutable_data(
pten::TransToFluidPlace(arg_def.backend));
}
}
}
}
...
@@ -481,14 +460,10 @@ void MakeVariableFromPtenTensor(pten::DenseTensor* src,
...
@@ -481,14 +460,10 @@ void MakeVariableFromPtenTensor(pten::DenseTensor* src,
tensor
->
Resize
(
src
->
dims
());
tensor
->
Resize
(
src
->
dims
());
SetLoD
(
tensor
->
mutable_lod
(),
src
->
lod
());
SetLoD
(
tensor
->
mutable_lod
(),
src
->
lod
());
// here dynamic_cast is slow
auto
*
storage
=
static_cast
<
SharedStorage
*>
(
pten
::
CompatibleDenseTensorUtils
::
UnsafeGetMutableStorage
(
src
));
if
(
!
tensor
->
IsInitialized
()
||
if
(
!
tensor
->
IsInitialized
()
||
(
tensor
->
IsInitialized
()
&&
(
tensor
->
IsInitialized
()
&&
!
IsSameAllocation
(
tensor
->
Holder
(),
s
torage
->
GetAllocation
())))
{
!
IsSameAllocation
(
tensor
->
Holder
(),
s
rc
->
Holder
())))
{
tensor
->
ResetHolderWithType
(
std
::
move
(
s
torage
->
GetAllocation
()),
dtype
);
tensor
->
ResetHolderWithType
(
std
::
move
(
s
rc
->
Holder
()),
dtype
);
}
else
{
}
else
{
// Even the pten tensor and Variable have the same Alloctation (both have
// Even the pten tensor and Variable have the same Alloctation (both have
// the same pointer address, same size and same place)
// the same pointer address, same size and same place)
...
@@ -502,10 +477,8 @@ void MakeVariableFromPtenTensor(pten::DenseTensor* src,
...
@@ -502,10 +477,8 @@ void MakeVariableFromPtenTensor(pten::DenseTensor* src,
auto
dtype
=
pten
::
TransToProtoVarType
(
src
->
dtype
());
auto
dtype
=
pten
::
TransToProtoVarType
(
src
->
dtype
());
if
(
!
tensor
->
value
().
IsInitialized
())
{
if
(
!
tensor
->
value
().
IsInitialized
())
{
auto
storage
=
dynamic_cast
<
SharedStorage
*>
(
tensor
->
mutable_value
()
->
ResetHolderWithType
(
std
::
move
(
src
->
Holder
()),
pten
::
CompatibleDenseTensorUtils
::
UnsafeGetMutableStorage
(
src
));
dtype
);
tensor
->
mutable_value
()
->
ResetHolderWithType
(
std
::
move
(
storage
->
GetAllocation
()),
dtype
);
}
}
}
else
{
}
else
{
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
...
...
paddle/pten/core/compat_utils.h
浏览文件 @
d13c7799
...
@@ -31,10 +31,6 @@ namespace pten {
...
@@ -31,10 +31,6 @@ namespace pten {
class
CompatibleDenseTensorUtils
{
class
CompatibleDenseTensorUtils
{
public:
public:
static
Storage
*
UnsafeGetMutableStorage
(
DenseTensor
*
tensor
)
{
return
tensor
->
storage_
.
get
();
}
static
DenseTensorMeta
*
GetMutableMeta
(
DenseTensor
*
tensor
)
{
static
DenseTensorMeta
*
GetMutableMeta
(
DenseTensor
*
tensor
)
{
return
&
(
tensor
->
meta_
);
return
&
(
tensor
->
meta_
);
}
}
...
@@ -42,10 +38,7 @@ class CompatibleDenseTensorUtils {
...
@@ -42,10 +38,7 @@ class CompatibleDenseTensorUtils {
// only can deal with SharedStorage now
// only can deal with SharedStorage now
static
void
ClearStorage
(
DenseTensor
*
tensor
)
{
static
void
ClearStorage
(
DenseTensor
*
tensor
)
{
// use static_cast to improve performance, replace by dynamic_cast later
// use static_cast to improve performance, replace by dynamic_cast later
if
(
tensor
->
storage_
!=
nullptr
)
{
tensor
->
MoveMemoryHolder
();
static_cast
<
paddle
::
experimental
::
SharedStorage
*>
(
tensor
->
storage_
.
get
())
->
Reset
();
}
}
}
static
DenseTensor
Slice
(
const
DenseTensor
&
tensor
,
static
DenseTensor
Slice
(
const
DenseTensor
&
tensor
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录