Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
1e9b3a3d
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1e9b3a3d
编写于
11月 17, 2021
作者:
Z
zyfncg
提交者:
GitHub
11月 17, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename TensorBase interface data_type() to dtype() (#37257)
上级
0daa69d4
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
26 addition
and
29 deletion
+26
-29
paddle/pten/api/lib/tensor.cc
paddle/pten/api/lib/tensor.cc
+2
-2
paddle/pten/api/lib/utils/tensor_utils.cc
paddle/pten/api/lib/utils/tensor_utils.cc
+1
-1
paddle/pten/core/compat_utils.h
paddle/pten/core/compat_utils.h
+1
-1
paddle/pten/core/dense_tensor.cc
paddle/pten/core/dense_tensor.cc
+7
-9
paddle/pten/core/dense_tensor.h
paddle/pten/core/dense_tensor.h
+1
-1
paddle/pten/core/tensor_base.h
paddle/pten/core/tensor_base.h
+1
-1
paddle/pten/kernels/cpu/utils.cc
paddle/pten/kernels/cpu/utils.cc
+2
-2
paddle/pten/kernels/cuda/math.cu
paddle/pten/kernels/cuda/math.cu
+1
-1
paddle/pten/kernels/cuda/utils.cu
paddle/pten/kernels/cuda/utils.cu
+2
-2
paddle/pten/kernels/xpu/utils.cc
paddle/pten/kernels/xpu/utils.cc
+2
-2
paddle/pten/tests/api/test_tensor_utils.cc
paddle/pten/tests/api/test_tensor_utils.cc
+5
-6
paddle/pten/tests/core/test_dense_tensor.cc
paddle/pten/tests/core/test_dense_tensor.cc
+1
-1
未找到文件。
paddle/pten/api/lib/tensor.cc
浏览文件 @
1e9b3a3d
...
...
@@ -109,9 +109,9 @@ void Tensor::reshape(const std::vector<int64_t> &shape) {
"and it will be implemented by calling the reshape kernel later."
));
}
DataType
Tensor
::
dtype
()
const
{
return
impl_
->
d
ata_
type
();
}
DataType
Tensor
::
dtype
()
const
{
return
impl_
->
dtype
();
}
DataType
Tensor
::
type
()
const
{
return
impl_
->
d
ata_
type
();
}
DataType
Tensor
::
type
()
const
{
return
impl_
->
dtype
();
}
DataLayout
Tensor
::
layout
()
const
{
return
impl_
->
layout
();
}
...
...
paddle/pten/api/lib/utils/tensor_utils.cc
浏览文件 @
1e9b3a3d
...
...
@@ -125,7 +125,7 @@ void MovesStorage(pten::DenseTensor* src, paddle::framework::Tensor* dst) {
auto
storage
=
src
->
release
();
std
::
shared_ptr
<
paddle
::
memory
::
allocation
::
Allocation
>
holder
(
new
TensorStorage
(
std
::
move
(
storage
)));
dst
->
ResetHolderWithType
(
holder
,
pten
::
TransToProtoVarType
(
src
->
d
ata_
type
()));
dst
->
ResetHolderWithType
(
holder
,
pten
::
TransToProtoVarType
(
src
->
dtype
()));
}
void
MovesStorage
(
pten
::
DenseTensor
*
src
,
paddle
::
framework
::
LoDTensor
*
dst
)
{
...
...
paddle/pten/core/compat_utils.h
浏览文件 @
1e9b3a3d
...
...
@@ -74,7 +74,7 @@ class CompatibleDenseTensorUtils {
ret
.
meta_
.
dims
[
0
]
=
end_idx
-
begin_idx
;
ret
.
meta_
.
offset
=
tensor
->
meta_
.
offset
+
begin_idx
*
(
tensor
->
numel
()
/
tensor
->
dims
()[
0
])
*
paddle
::
experimental
::
SizeOf
(
tensor
->
d
ata_
type
());
paddle
::
experimental
::
SizeOf
(
tensor
->
dtype
());
}
return
ret
;
}
...
...
paddle/pten/core/dense_tensor.cc
浏览文件 @
1e9b3a3d
...
...
@@ -24,14 +24,12 @@ namespace pten {
DenseTensor
::
DenseTensor
(
const
std
::
shared_ptr
<
Allocator
>&
a
,
const
DenseTensorMeta
&
meta
)
:
meta_
(
meta
),
storage_
(
make_intrusive
<
TensorStorage
>
(
a
,
SizeOf
(
data_type
())
*
numel
()))
{}
storage_
(
make_intrusive
<
TensorStorage
>
(
a
,
SizeOf
(
dtype
())
*
numel
()))
{}
DenseTensor
::
DenseTensor
(
const
std
::
shared_ptr
<
Allocator
>&
a
,
DenseTensorMeta
&&
meta
)
:
meta_
(
std
::
move
(
meta
)),
storage_
(
make_intrusive
<
TensorStorage
>
(
a
,
SizeOf
(
data_type
())
*
numel
()))
{}
storage_
(
make_intrusive
<
TensorStorage
>
(
a
,
SizeOf
(
dtype
())
*
numel
()))
{}
DenseTensor
::
DenseTensor
(
intrusive_ptr
<
Storage
>
storage
,
const
DenseTensorMeta
&
meta
)
...
...
@@ -60,7 +58,7 @@ void* DenseTensor::mutable_data(size_t request_bytes) {
storage_
,
paddle
::
platform
::
errors
::
PreconditionNotMet
(
"The storage must be valid when call the mutable data function."
));
size_t
bytes
=
numel
()
*
SizeOf
(
d
ata_
type
());
size_t
bytes
=
numel
()
*
SizeOf
(
dtype
());
if
(
request_bytes
)
{
PADDLE_ENFORCE_GE
(
request_bytes
,
bytes
,
...
...
@@ -87,19 +85,19 @@ T* DenseTensor::mutable_data() {
paddle
::
experimental
::
CppTypeToDataType
<
T
>::
Type
();
}
PADDLE_ENFORCE
(
(
d
ata_
type
()
==
paddle
::
experimental
::
CppTypeToDataType
<
T
>::
Type
()),
(
dtype
()
==
paddle
::
experimental
::
CppTypeToDataType
<
T
>::
Type
()),
paddle
::
platform
::
errors
::
InvalidArgument
(
"The type of data (%d) we are trying to retrieve does not match the "
"type of data currently contained in the container (%d)."
,
static_cast
<
int
>
(
paddle
::
experimental
::
CppTypeToDataType
<
T
>::
Type
()),
static_cast
<
int
>
(
d
ata_
type
())));
static_cast
<
int
>
(
dtype
())));
return
static_cast
<
T
*>
(
mutable_data
());
}
template
<
typename
T
>
const
T
*
DenseTensor
::
data
()
const
{
PADDLE_ENFORCE
(
(
d
ata_
type
()
==
paddle
::
experimental
::
CppTypeToDataType
<
T
>::
Type
()),
(
dtype
()
==
paddle
::
experimental
::
CppTypeToDataType
<
T
>::
Type
()),
paddle
::
platform
::
errors
::
InvalidArgument
(
"The type of data we are trying to retrieve does not match the "
"type of data currently contained in the container."
));
...
...
@@ -115,7 +113,7 @@ const void* DenseTensor::data() const {
}
void
DenseTensor
::
check_memory_size
()
const
{
size_t
bytes
=
numel
()
*
SizeOf
(
d
ata_
type
());
size_t
bytes
=
numel
()
*
SizeOf
(
dtype
());
PADDLE_ENFORCE_GE
(
memory_size
(),
bytes
,
paddle
::
platform
::
errors
::
InvalidArgument
(
...
...
paddle/pten/core/dense_tensor.h
浏览文件 @
1e9b3a3d
...
...
@@ -93,7 +93,7 @@ class DenseTensor : public TensorBase,
/// \brief Returns the data type of the tensor.
/// \return The data type of the tensor.
DataType
d
ata_
type
()
const
noexcept
override
{
return
meta_
.
type
;
}
DataType
dtype
()
const
noexcept
override
{
return
meta_
.
type
;
}
/// \brief Returns the data layout of the tensor.
/// \return The data layout of the tensor.
...
...
paddle/pten/core/tensor_base.h
浏览文件 @
1e9b3a3d
...
...
@@ -43,7 +43,7 @@ class TensorBase {
/// \brief Returns the data type of the tensor.
/// \return The data type of the tensor.
virtual
DataType
d
ata_
type
()
const
=
0
;
virtual
DataType
dtype
()
const
=
0
;
/// \brief Returns the data layout of the tensor.
/// \return The data layout of the tensor.
...
...
paddle/pten/kernels/cpu/utils.cc
浏览文件 @
1e9b3a3d
...
...
@@ -38,8 +38,8 @@ void Copy(const CPUContext& dev_ctx, const DenseTensor& src, DenseTensor* dst) {
VLOG
(
4
)
<<
"src:"
<<
src_ptr
<<
", dst:"
<<
dst_ptr
;
CHECK
(
dst
->
layout
()
==
src
.
layout
());
auto
size
=
src
.
numel
()
*
paddle
::
framework
::
SizeOfType
(
TransToProtoVarType
(
src
.
data_
type
()));
auto
size
=
src
.
numel
()
*
paddle
::
framework
::
SizeOfType
(
TransToProtoVarType
(
src
.
d
type
()));
if
(
paddle
::
platform
::
is_cpu_place
(
src_place
)
&&
paddle
::
platform
::
is_cpu_place
(
dst_place
))
{
...
...
paddle/pten/kernels/cuda/math.cu
浏览文件 @
1e9b3a3d
...
...
@@ -81,7 +81,7 @@ void Mean(const CUDAContext& dev_ctx, const DenseTensor& x, DenseTensor* out) {
dev_ctx
.
GetPlace
());
pten
::
DenseTensor
tmp
(
alloc
,
DenseTensorMeta
(
x
.
d
ata_
type
(),
DenseTensorMeta
(
x
.
dtype
(),
paddle
::
framework
::
make_ddim
(
{
static_cast
<
int64_t
>
(
temp_storage_bytes
)}),
x
.
layout
()));
...
...
paddle/pten/kernels/cuda/utils.cu
浏览文件 @
1e9b3a3d
...
...
@@ -48,8 +48,8 @@ void Copy(const CUDAContext& dev_ctx,
VLOG
(
4
)
<<
"src:"
<<
src_ptr
<<
", dst:"
<<
dst_ptr
;
CHECK
(
dst
->
layout
()
==
src
.
layout
());
auto
size
=
src
.
numel
()
*
paddle
::
framework
::
SizeOfType
(
TransToProtoVarType
(
src
.
data_
type
()));
auto
size
=
src
.
numel
()
*
paddle
::
framework
::
SizeOfType
(
TransToProtoVarType
(
src
.
d
type
()));
if
(
paddle
::
platform
::
is_cuda_pinned_place
(
src_place
)
&&
// NOLINT
paddle
::
platform
::
is_cuda_pinned_place
(
dst_place
))
{
...
...
paddle/pten/kernels/xpu/utils.cc
浏览文件 @
1e9b3a3d
...
...
@@ -38,8 +38,8 @@ void Copy(const XPUDeviceContext& dev_ctx,
<<
dst_place
;
dst
->
Resize
(
src
.
dims
());
CHECK
(
dst
->
layout
()
==
src
.
layout
());
auto
size
=
src
.
numel
()
*
paddle
::
framework
::
SizeOfType
(
TransToProtoVarType
(
src
.
data_
type
()));
auto
size
=
src
.
numel
()
*
paddle
::
framework
::
SizeOfType
(
TransToProtoVarType
(
src
.
d
type
()));
if
(
paddle
::
platform
::
is_xpu_place
(
src_place
)
&&
// NOLINT
paddle
::
platform
::
is_cpu_place
(
dst_place
))
{
...
...
paddle/pten/tests/api/test_tensor_utils.cc
浏览文件 @
1e9b3a3d
...
...
@@ -47,8 +47,7 @@ TEST(tensor_utils, dense_tensor_to_lod_tensor) {
CHECK
(
dense_tensor
.
lod
().
size
()
==
lod_tensor
.
lod
().
size
());
CHECK
(
dense_tensor
.
lod
()[
0
]
==
static_cast
<
std
::
vector
<
size_t
>>
((
lod_tensor
.
lod
()[
0
])));
CHECK
(
dense_tensor
.
data_type
()
==
pten
::
TransToPtenDataType
(
lod_tensor
.
type
()));
CHECK
(
dense_tensor
.
dtype
()
==
pten
::
TransToPtenDataType
(
lod_tensor
.
type
()));
CHECK
(
dense_tensor
.
layout
()
==
pten
::
TransToPtenDataLayout
(
lod_tensor
.
layout
()));
CHECK
(
platform
::
is_cpu_place
(
lod_tensor
.
place
()));
...
...
@@ -58,7 +57,7 @@ TEST(tensor_utils, dense_tensor_to_lod_tensor) {
auto
dense_tensor_1
=
MakePtenDenseTensor
(
lod_tensor
);
CHECK
(
dense_tensor_1
->
dims
()
==
dims
);
CHECK
(
dense_tensor_1
->
d
ata_
type
()
==
dtype
);
CHECK
(
dense_tensor_1
->
dtype
()
==
dtype
);
CHECK
(
dense_tensor_1
->
layout
()
==
layout
);
CHECK
(
dense_tensor_1
->
lod
().
size
()
==
lod
.
size
());
CHECK
(
dense_tensor_1
->
lod
()[
0
]
==
lod
[
0
]);
...
...
@@ -83,7 +82,7 @@ TEST(tensor_utils, dense_tensor_to_tensor) {
framework
::
Tensor
tensor
;
MovesStorage
(
&
dense_tensor
,
&
tensor
);
CHECK
(
dense_tensor
.
d
ata_
type
()
==
pten
::
TransToPtenDataType
(
tensor
.
type
()));
CHECK
(
dense_tensor
.
dtype
()
==
pten
::
TransToPtenDataType
(
tensor
.
type
()));
CHECK
(
dense_tensor
.
layout
()
==
pten
::
TransToPtenDataLayout
(
tensor
.
layout
()));
CHECK
(
platform
::
is_cpu_place
(
tensor
.
place
()));
...
...
@@ -92,7 +91,7 @@ TEST(tensor_utils, dense_tensor_to_tensor) {
auto
dense_tensor_1
=
MakePtenDenseTensor
(
tensor
);
CHECK
(
dense_tensor_1
->
dims
()
==
dims
);
CHECK
(
dense_tensor_1
->
d
ata_
type
()
==
dtype
);
CHECK
(
dense_tensor_1
->
dtype
()
==
dtype
);
CHECK
(
dense_tensor_1
->
layout
()
==
layout
);
const
float
*
data_1
=
dense_tensor_1
->
data
<
float
>
();
CHECK
(
data_1
[
0
]
==
1.0
f
);
...
...
@@ -117,7 +116,7 @@ TEST(PtenUtils, VarToPtTensor) {
// 2. test API
auto
tensor_x
=
MakePtenTensorBaseFromVar
(
v
,
tensor_def
);
// 3. check result
ASSERT_EQ
(
tensor_x
->
d
ata_
type
(),
pten
::
DataType
::
INT32
);
ASSERT_EQ
(
tensor_x
->
dtype
(),
pten
::
DataType
::
INT32
);
}
}
// namespace tests
...
...
paddle/pten/tests/core/test_dense_tensor.cc
浏览文件 @
1e9b3a3d
...
...
@@ -82,7 +82,7 @@ TEST(dense_tensor, ctor) {
bool
r
{
true
};
r
=
r
&&
(
t
.
numel
()
==
product
(
m
.
dims
));
r
=
r
&&
(
t
.
dims
()
==
m
.
dims
);
r
=
r
&&
(
t
.
d
ata_
type
()
==
m
.
type
);
r
=
r
&&
(
t
.
dtype
()
==
m
.
type
);
r
=
r
&&
(
t
.
layout
()
==
m
.
layout
);
r
=
r
&&
(
t
.
place
()
==
paddle
::
platform
::
CPUPlace
());
r
=
r
&&
t
.
initialized
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录