Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e83e44c7
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
e83e44c7
编写于
4月 15, 2022
作者:
C
Chen Weihang
提交者:
GitHub
4月 15, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polish tensor depreacted method warning (#41807)
上级
1665594d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
43 deletion
+49
-43
paddle/phi/api/lib/tensor.cc
paddle/phi/api/lib/tensor.cc
+49
-43
未找到文件。
paddle/phi/api/lib/tensor.cc
浏览文件 @
e83e44c7
...
@@ -67,13 +67,14 @@ Tensor::Tensor(std::shared_ptr<phi::TensorBase> tensor_impl)
...
@@ -67,13 +67,14 @@ Tensor::Tensor(std::shared_ptr<phi::TensorBase> tensor_impl)
}
}
Tensor
::
Tensor
(
const
Place
&
place
)
{
Tensor
::
Tensor
(
const
Place
&
place
)
{
LOG
(
WARNING
)
<<
"The Tensor(place) constructor is deprecated since version "
LOG_FIRST_N
(
WARNING
,
1
)
"2.3, and will be removed in version 2.4! Please use "
<<
"The Tensor(place) constructor is deprecated since version "
"`paddle::empty/full` method to create a new "
"2.3, and will be removed in version 2.4! Please use "
"Tensor instead. "
"`paddle::empty/full` method to create a new "
"Reason: A legal tensor cannot be constructed only based on "
"Tensor instead. "
"the `place`, and datatype, shape, layout, etc. is also "
"Reason: A legal tensor cannot be constructed only based on "
"required."
;
"the `place`, and datatype, shape, layout, etc. is also "
"required."
;
DefaultAllocator
alloc
(
detail
::
GetCorrectPlaceByPlaceType
(
place
));
DefaultAllocator
alloc
(
detail
::
GetCorrectPlaceByPlaceType
(
place
));
impl_
=
std
::
move
(
std
::
make_shared
<
phi
::
DenseTensor
>
(
impl_
=
std
::
move
(
std
::
make_shared
<
phi
::
DenseTensor
>
(
&
alloc
,
&
alloc
,
...
@@ -82,13 +83,14 @@ Tensor::Tensor(const Place &place) {
...
@@ -82,13 +83,14 @@ Tensor::Tensor(const Place &place) {
}
}
Tensor
::
Tensor
(
const
Place
&
place
,
const
std
::
vector
<
int64_t
>
&
shape
)
{
Tensor
::
Tensor
(
const
Place
&
place
,
const
std
::
vector
<
int64_t
>
&
shape
)
{
LOG
(
WARNING
)
<<
"The Tensor(place, shape) constructor is deprecated since "
LOG_FIRST_N
(
WARNING
,
1
)
"version 2.3, and will be removed in version 2.4! Please use "
<<
"The Tensor(place, shape) constructor is deprecated since "
"`paddle::empty/full` method to create a new "
"version 2.3, and will be removed in version 2.4! Please use "
"Tensor instead. "
"`paddle::empty/full` method to create a new "
"Reason: A legal tensor cannot be constructed only based on "
"Tensor instead. "
"the `place` and `shape`, and datatype, layout, etc. is also "
"Reason: A legal tensor cannot be constructed only based on "
"required."
;
"the `place` and `shape`, and datatype, layout, etc. is also "
"required."
;
DefaultAllocator
alloc
(
detail
::
GetCorrectPlaceByPlaceType
(
place
));
DefaultAllocator
alloc
(
detail
::
GetCorrectPlaceByPlaceType
(
place
));
impl_
=
std
::
move
(
std
::
make_shared
<
phi
::
DenseTensor
>
(
impl_
=
std
::
move
(
std
::
make_shared
<
phi
::
DenseTensor
>
(
&
alloc
,
&
alloc
,
...
@@ -118,14 +120,15 @@ std::vector<int64_t> Tensor::shape() const {
...
@@ -118,14 +120,15 @@ std::vector<int64_t> Tensor::shape() const {
}
}
void
Tensor
::
reshape
(
const
std
::
vector
<
int64_t
>
&
shape
)
{
void
Tensor
::
reshape
(
const
std
::
vector
<
int64_t
>
&
shape
)
{
LOG
(
WARNING
)
<<
"The function of resetting the shape of the uninitialized "
LOG_FIRST_N
(
WARNING
,
1
)
"Tensor of the `reshape` method is deprecated since version "
<<
"The function of resetting the shape of the uninitialized "
"2.3, and will be removed in version 2.4, please use "
"Tensor of the `reshape` method is deprecated since version "
"`paddle::empty/full` method to create a new Tensor "
"2.3, and will be removed in version 2.4, please use "
"instead. "
"`paddle::empty/full` method to create a new Tensor "
"reason: `reshape` means changing the tensor shape without "
"instead. "
"touching underlying data, this requires the total size of "
"reason: `reshape` means changing the tensor shape without "
"the tensor to remain constant."
;
"touching underlying data, this requires the total size of "
"the tensor to remain constant."
;
if
(
is_dense_tensor
())
{
if
(
is_dense_tensor
())
{
static_cast
<
phi
::
DenseTensor
*>
(
impl_
.
get
())
->
Resize
(
phi
::
make_ddim
(
shape
));
static_cast
<
phi
::
DenseTensor
*>
(
impl_
.
get
())
->
Resize
(
phi
::
make_ddim
(
shape
));
}
else
{
}
else
{
...
@@ -175,15 +178,16 @@ bool Tensor::is_gpu_pinned() const {
...
@@ -175,15 +178,16 @@ bool Tensor::is_gpu_pinned() const {
template
<
typename
T
>
template
<
typename
T
>
T
*
Tensor
::
mutable_data
()
{
T
*
Tensor
::
mutable_data
()
{
LOG
(
WARNING
)
<<
"Allocating memory through `mutable_data` method is "
LOG_FIRST_N
(
WARNING
,
1
)
"deprecated since version 2.3, and `mutable_data` method "
<<
"Allocating memory through `mutable_data` method is "
"will be removed in version 2.4! Please use "
"deprecated since version 2.3, and `mutable_data` method "
"`paddle::empty/full` method to create a new "
"will be removed in version 2.4! Please use "
"Tensor with allocated memory, and use data<T>() method "
"`paddle::empty/full` method to create a new "
"to get the memory pointer of tensor instead. "
"Tensor with allocated memory, and use data<T>() method "
"Reason: When calling `mutable_data` to allocate memory, "
"to get the memory pointer of tensor instead. "
"the place, datatype, and data layout of tensor may be in "
"Reason: When calling `mutable_data` to allocate memory, "
"an illegal state."
;
"the place, datatype, and data layout of tensor may be in "
"an illegal state."
;
if
(
is_dense_tensor
())
{
if
(
is_dense_tensor
())
{
return
static_cast
<
phi
::
DenseTensor
*>
(
impl_
.
get
())
return
static_cast
<
phi
::
DenseTensor
*>
(
impl_
.
get
())
->
mutable_data
<
T
>
(
place
());
->
mutable_data
<
T
>
(
place
());
...
@@ -208,15 +212,16 @@ Tensor::mutable_data<phi::dtype::float16>();
...
@@ -208,15 +212,16 @@ Tensor::mutable_data<phi::dtype::float16>();
template
<
typename
T
>
template
<
typename
T
>
T
*
Tensor
::
mutable_data
(
const
Place
&
place
)
{
T
*
Tensor
::
mutable_data
(
const
Place
&
place
)
{
LOG
(
WARNING
)
<<
"Allocating memory through `mutable_data` method is "
LOG_FIRST_N
(
WARNING
,
1
)
"deprecated since version 2.3, and `mutable_data` method "
<<
"Allocating memory through `mutable_data` method is "
"will be removed in version 2.4! Please use "
"deprecated since version 2.3, and `mutable_data` method "
"`paddle::empty/full` method to create a new "
"will be removed in version 2.4! Please use "
"Tensor with allocated memory, and use data<T>() method "
"`paddle::empty/full` method to create a new "
"to get the memory pointer of tensor instead. "
"Tensor with allocated memory, and use data<T>() method "
"Reason: When calling `mutable_data` to allocate memory, "
"to get the memory pointer of tensor instead. "
"the datatype, and data layout of tensor may be in "
"Reason: When calling `mutable_data` to allocate memory, "
"an illegal state."
;
"the datatype, and data layout of tensor may be in "
"an illegal state."
;
if
(
is_dense_tensor
())
{
if
(
is_dense_tensor
())
{
return
static_cast
<
phi
::
DenseTensor
*>
(
impl_
.
get
())
->
mutable_data
<
T
>
(
place
);
return
static_cast
<
phi
::
DenseTensor
*>
(
impl_
.
get
())
->
mutable_data
<
T
>
(
place
);
}
}
...
@@ -328,9 +333,10 @@ bool Tensor::defined() const { return impl_ != nullptr; }
...
@@ -328,9 +333,10 @@ bool Tensor::defined() const { return impl_ != nullptr; }
bool
Tensor
::
initialized
()
const
{
return
defined
()
&&
impl_
->
initialized
();
}
bool
Tensor
::
initialized
()
const
{
return
defined
()
&&
impl_
->
initialized
();
}
bool
Tensor
::
is_initialized
()
const
{
bool
Tensor
::
is_initialized
()
const
{
LOG
(
WARNING
)
<<
"The `is_initialized` method is deprecated since version "
LOG_FIRST_N
(
WARNING
,
1
)
"2.3, and will be removed in version 2.4! "
<<
"The `is_initialized` method is deprecated since version "
"Please use `initialized` method instead."
;
"2.3, and will be removed in version 2.4! "
"Please use `initialized` method instead."
;
return
defined
()
&&
impl_
->
initialized
();
return
defined
()
&&
impl_
->
initialized
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录