Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2a905f6b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
2a905f6b
编写于
11月 24, 2021
作者:
C
Chen Weihang
提交者:
GitHub
11月 25, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
infershape func to infermeta (#37524)
上级
171da2ce
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
102 addition
and
102 deletion
+102
-102
paddle/pten/api/lib/creation.cc
paddle/pten/api/lib/creation.cc
+4
-4
paddle/pten/api/lib/linalg.cc
paddle/pten/api/lib/linalg.cc
+4
-4
paddle/pten/api/lib/manipulation.cc
paddle/pten/api/lib/manipulation.cc
+5
-5
paddle/pten/api/lib/math.cc
paddle/pten/api/lib/math.cc
+10
-10
paddle/pten/api/lib/utils.cc
paddle/pten/api/lib/utils.cc
+1
-1
paddle/pten/include/creation.h
paddle/pten/include/creation.h
+1
-1
paddle/pten/include/linalg.h
paddle/pten/include/linalg.h
+1
-1
paddle/pten/include/manipulation.h
paddle/pten/include/manipulation.h
+2
-2
paddle/pten/include/math.h
paddle/pten/include/math.h
+8
-8
paddle/pten/infermeta/binary.cc
paddle/pten/infermeta/binary.cc
+9
-9
paddle/pten/infermeta/binary.h
paddle/pten/infermeta/binary.h
+14
-14
paddle/pten/infermeta/nary.cc
paddle/pten/infermeta/nary.cc
+6
-6
paddle/pten/infermeta/nary.h
paddle/pten/infermeta/nary.h
+9
-9
paddle/pten/infermeta/unary.cc
paddle/pten/infermeta/unary.cc
+10
-10
paddle/pten/infermeta/unary.h
paddle/pten/infermeta/unary.h
+15
-15
paddle/pten/kernels/cpu/manipulation.cc
paddle/pten/kernels/cpu/manipulation.cc
+1
-1
paddle/pten/kernels/cuda/manipulation.cu
paddle/pten/kernels/cuda/manipulation.cu
+1
-1
paddle/pten/kernels/xpu/manipulation.cc
paddle/pten/kernels/xpu/manipulation.cc
+1
-1
未找到文件。
paddle/pten/api/lib/creation.cc
浏览文件 @
2a905f6b
...
...
@@ -52,8 +52,8 @@ PD_DLL_DECL Tensor full(const ScalarArray& shape,
kernel_context
.
EmplaceBackAttr
(
pten
::
ScalarArray
(
shape
));
kernel_context
.
EmplaceBackAttr
(
pten
::
Scalar
(
value
));
// 4. Infer
Shape
auto
out_meta
=
pten
::
FullInfer
Shape
(
shape
,
dtype
,
layout
);
// 4. Infer
Meta
auto
out_meta
=
pten
::
FullInfer
Meta
(
shape
,
dtype
,
layout
);
// 5. Prepare outputs
const
auto
allocator
=
...
...
@@ -97,8 +97,8 @@ PD_DLL_DECL Tensor full_like(const Tensor& x,
auto
dense_x
=
std
::
dynamic_pointer_cast
<
pten
::
DenseTensor
>
(
x
.
impl
());
kernel_context
.
EmplaceBackAttr
(
pten
::
Scalar
(
value
));
// 4. Infer
Shape
auto
out_meta
=
FullLikeInfer
Shape
(
dense_x
->
meta
(),
dtype
,
layout
);
// 4. Infer
Meta
auto
out_meta
=
FullLikeInfer
Meta
(
dense_x
->
meta
(),
dtype
,
layout
);
// 5. Prepare outputs
Tensor
out
;
...
...
paddle/pten/api/lib/linalg.cc
浏览文件 @
2a905f6b
...
...
@@ -55,8 +55,8 @@ PD_DLL_DECL Tensor dot(const Tensor& x, const Tensor& y) {
kernel_context
.
EmplaceBackInput
(
dense_y
);
// TODO(chenweihang): add transform impl
// 4. Infer
Shape
auto
out_meta
=
DotInfer
Shape
(
dense_x
->
meta
(),
dense_y
->
meta
());
// 4. Infer
Meta
auto
out_meta
=
DotInfer
Meta
(
dense_x
->
meta
(),
dense_y
->
meta
());
// 5. Prepare outputs
Tensor
out
;
...
...
@@ -95,8 +95,8 @@ PD_DLL_DECL Tensor matmul(const Tensor& x,
kernel_context
.
EmplaceBackAttr
(
transpose_y
);
// TODO(chenweihang): add transform impl
// 4. Infer
Shape
auto
out_meta
=
MatmulInfer
Shape
(
// 4. Infer
Meta
auto
out_meta
=
MatmulInfer
Meta
(
dense_x
->
meta
(),
dense_y
->
meta
(),
transpose_x
,
transpose_y
);
// 5. Prepare outputs
...
...
paddle/pten/api/lib/manipulation.cc
浏览文件 @
2a905f6b
...
...
@@ -50,8 +50,8 @@ PD_DLL_DECL Tensor flatten(const Tensor& x, int start_axis, int stop_axis) {
kernel_context
.
EmplaceBackAttr
(
start_axis
);
kernel_context
.
EmplaceBackAttr
(
stop_axis
);
// 4. Infer
Shape
auto
out_meta
=
FlattenInfer
Shape
(
dense_x
->
meta
(),
start_axis
,
stop_axis
);
// 4. Infer
Meta
auto
out_meta
=
FlattenInfer
Meta
(
dense_x
->
meta
(),
start_axis
,
stop_axis
);
// 5. Prepare outputs
Tensor
out
;
...
...
@@ -84,7 +84,7 @@ PD_DLL_DECL Tensor cast(const Tensor& x, DataType out_dtype) {
kernel_context
.
EmplaceBackAttr
(
out_dtype
);
kernel_context
.
EmplaceBackAttr
(
dense_x
->
meta
().
dtype
);
// 4. Infer
Shape
// 4. Infer
Meta
auto
out_meta
=
CastInferMeta
(
dense_x
->
meta
(),
out_dtype
);
// 5. Prepare outputs
...
...
@@ -117,8 +117,8 @@ PD_DLL_DECL Tensor reshape(const Tensor& x, const std::vector<int64_t>& shape) {
kernel_context
.
EmplaceBackInput
(
dense_x
);
kernel_context
.
EmplaceBackAttr
(
shape
);
// 4. Infer
Shape
auto
out_meta
=
Infer
Shape
FromVecValue
(
dense_x
->
meta
(),
shape
);
// 4. Infer
Meta
auto
out_meta
=
Infer
Meta
FromVecValue
(
dense_x
->
meta
(),
shape
);
// 5. Prepare outputs
Tensor
out
;
...
...
paddle/pten/api/lib/math.cc
浏览文件 @
2a905f6b
...
...
@@ -50,8 +50,8 @@ PD_DLL_DECL Tensor mean(const Tensor& x) {
auto
dense_x
=
std
::
dynamic_pointer_cast
<
pten
::
DenseTensor
>
(
x
.
impl
());
kernel_context
.
EmplaceBackInput
(
dense_x
);
// 4. Infer
Shape
auto
out_meta
=
ReductionInfer
Shape
(
dense_x
->
meta
());
// 4. Infer
Meta
auto
out_meta
=
ReductionInfer
Meta
(
dense_x
->
meta
());
// 5. Prepare outputs
Tensor
out
;
...
...
@@ -86,8 +86,8 @@ PD_DLL_DECL Tensor add(const Tensor& x, const Tensor& y) {
kernel_context
.
EmplaceBackInput
(
dense_y
);
kernel_context
.
EmplaceBackAttr
(
-
1
);
// 4. Infer
Shape
auto
out_meta
=
ElementwiseInfer
Shape
(
dense_x
->
meta
(),
dense_y
->
meta
(),
-
1
);
// 4. Infer
Meta
auto
out_meta
=
ElementwiseInfer
Meta
(
dense_x
->
meta
(),
dense_y
->
meta
(),
-
1
);
// 5. Prepare outputs
Tensor
out
;
...
...
@@ -121,8 +121,8 @@ PD_DLL_DECL Tensor subtract(const Tensor& x, const Tensor& y) {
kernel_context
.
EmplaceBackInput
(
dense_y
);
kernel_context
.
EmplaceBackAttr
(
-
1
);
// 4. Infer
Shape
auto
out_meta
=
ElementwiseInfer
Shape
(
dense_x
->
meta
(),
dense_y
->
meta
(),
-
1
);
// 4. Infer
Meta
auto
out_meta
=
ElementwiseInfer
Meta
(
dense_x
->
meta
(),
dense_y
->
meta
(),
-
1
);
// 5. Prepare outputs
Tensor
out
;
...
...
@@ -156,8 +156,8 @@ PD_DLL_DECL Tensor divide(const Tensor& x, const Tensor& y) {
kernel_context
.
EmplaceBackInput
(
dense_y
);
kernel_context
.
EmplaceBackAttr
(
-
1
);
// 4. Infer
Shape
auto
out_meta
=
ElementwiseInfer
Shape
(
dense_x
->
meta
(),
dense_y
->
meta
(),
-
1
);
// 4. Infer
Meta
auto
out_meta
=
ElementwiseInfer
Meta
(
dense_x
->
meta
(),
dense_y
->
meta
(),
-
1
);
// 5. Prepare outputs
Tensor
out
;
...
...
@@ -191,8 +191,8 @@ PD_DLL_DECL Tensor multiply(const Tensor& x, const Tensor& y) {
kernel_context
.
EmplaceBackInput
(
dense_y
);
kernel_context
.
EmplaceBackAttr
(
-
1
);
// 4. Infer
Shape
auto
out_meta
=
ElementwiseInfer
Shape
(
dense_x
->
meta
(),
dense_y
->
meta
(),
-
1
);
// 4. Infer
Meta
auto
out_meta
=
ElementwiseInfer
Meta
(
dense_x
->
meta
(),
dense_y
->
meta
(),
-
1
);
// 5. Prepare outputs
Tensor
out
;
...
...
paddle/pten/api/lib/utils.cc
浏览文件 @
2a905f6b
...
...
@@ -55,7 +55,7 @@ PD_DLL_DECL Tensor copy_to(const Tensor& x, Backend backend, bool blocking) {
kernel_context
.
EmplaceBackAttr
(
blocking
);
// 4. InferMeta
auto
out_meta
=
UnchangedInfer
Shape
(
dense_x
->
meta
());
auto
out_meta
=
UnchangedInfer
Meta
(
dense_x
->
meta
());
// 5. Prepare outputs
const
auto
allocator
=
...
...
paddle/pten/include/creation.h
浏览文件 @
2a905f6b
...
...
@@ -31,7 +31,7 @@ DenseTensor FillAnyLike(
DataType
dtype
=
DataType
::
UNDEFINED
,
Backend
backend
=
Backend
::
UNDEFINED
,
// Is backend needed here?
DataLayout
layout
=
DataLayout
::
UNDEFINED
)
{
auto
out_meta
=
FullLikeInfer
Shape
(
x
.
meta
(),
dtype
,
layout
);
auto
out_meta
=
FullLikeInfer
Meta
(
x
.
meta
(),
dtype
,
layout
);
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
paddle/pten/include/linalg.h
浏览文件 @
2a905f6b
...
...
@@ -26,7 +26,7 @@ template <typename T, typename ContextT>
DenseTensor
Dot
(
const
ContextT
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
)
{
auto
out_meta
=
DotInfer
Shape
(
x
.
meta
(),
y
.
meta
());
auto
out_meta
=
DotInfer
Meta
(
x
.
meta
(),
y
.
meta
());
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
paddle/pten/include/manipulation.h
浏览文件 @
2a905f6b
...
...
@@ -28,7 +28,7 @@ DenseTensor Flatten(const ContextT& dev_ctx,
const
DenseTensor
&
x
,
int
start_axis
,
int
stop_axis
)
{
auto
out_meta
=
FlattenInfer
Shape
(
x
.
meta
(),
start_axis
,
stop_axis
);
auto
out_meta
=
FlattenInfer
Meta
(
x
.
meta
(),
start_axis
,
stop_axis
);
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
@@ -55,7 +55,7 @@ template <typename T, typename ContextT>
DenseTensor
Reshape
(
const
ContextT
&
dev_ctx
,
const
DenseTensor
&
x
,
const
std
::
vector
<
int64_t
>&
shape
)
{
auto
out_meta
=
Infer
Shape
FromVecValue
(
x
.
meta
(),
shape
);
auto
out_meta
=
Infer
Meta
FromVecValue
(
x
.
meta
(),
shape
);
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
paddle/pten/include/math.h
浏览文件 @
2a905f6b
...
...
@@ -24,7 +24,7 @@ namespace pten {
template
<
typename
T
,
typename
ContextT
>
DenseTensor
Sign
(
const
ContextT
&
dev_ctx
,
const
DenseTensor
&
x
)
{
auto
out_meta
=
UnchangedInfer
Shape
(
x
.
meta
());
auto
out_meta
=
UnchangedInfer
Meta
(
x
.
meta
());
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
@@ -35,7 +35,7 @@ DenseTensor Sign(const ContextT& dev_ctx, const DenseTensor& x) {
template
<
typename
T
,
typename
ContextT
>
DenseTensor
Mean
(
const
ContextT
&
dev_ctx
,
const
DenseTensor
&
x
)
{
auto
out_meta
=
ReductionInfer
Shape
(
x
.
meta
());
auto
out_meta
=
ReductionInfer
Meta
(
x
.
meta
());
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
@@ -50,7 +50,7 @@ DenseTensor Scale(const ContextT& dev_ctx,
float
scale
,
float
bias
,
bool
bias_after_scale
)
{
auto
out_meta
=
UnchangedInfer
Shape
(
x
.
meta
());
auto
out_meta
=
UnchangedInfer
Meta
(
x
.
meta
());
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
@@ -65,7 +65,7 @@ DenseTensor Scale(const ContextT& dev_ctx,
const
DenseTensor
&
scale
,
float
bias
,
bool
bias_after_scale
)
{
auto
out_meta
=
UnchangedInfer
Shape
(
x
.
meta
());
auto
out_meta
=
UnchangedInfer
Meta
(
x
.
meta
());
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
@@ -79,7 +79,7 @@ DenseTensor Add(const ContextT& dev_ctx,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
)
{
auto
out_meta
=
ElementwiseInfer
Shape
(
x
.
meta
(),
y
.
meta
(),
axis
);
auto
out_meta
=
ElementwiseInfer
Meta
(
x
.
meta
(),
y
.
meta
(),
axis
);
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
@@ -93,7 +93,7 @@ DenseTensor Subtract(const ContextT& dev_ctx,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
)
{
auto
out_meta
=
ElementwiseInfer
Shape
(
x
.
meta
(),
y
.
meta
(),
axis
);
auto
out_meta
=
ElementwiseInfer
Meta
(
x
.
meta
(),
y
.
meta
(),
axis
);
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
@@ -107,7 +107,7 @@ DenseTensor Divide(const ContextT& dev_ctx,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
)
{
auto
out_meta
=
ElementwiseInfer
Shape
(
x
.
meta
(),
y
.
meta
(),
axis
);
auto
out_meta
=
ElementwiseInfer
Meta
(
x
.
meta
(),
y
.
meta
(),
axis
);
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
@@ -121,7 +121,7 @@ DenseTensor Multiply(const ContextT& dev_ctx,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
)
{
auto
out_meta
=
ElementwiseInfer
Shape
(
x
.
meta
(),
y
.
meta
(),
axis
);
auto
out_meta
=
ElementwiseInfer
Meta
(
x
.
meta
(),
y
.
meta
(),
axis
);
const
auto
allocator
=
std
::
make_shared
<
paddle
::
experimental
::
DefaultAllocator
>
(
dev_ctx
.
GetPlace
());
...
...
paddle/pten/infermeta/binary.cc
浏览文件 @
2a905f6b
...
...
@@ -18,8 +18,8 @@ limitations under the License. */
namespace
pten
{
DenseTensorMeta
DotInfer
Shape
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
)
{
DenseTensorMeta
DotInfer
Meta
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
)
{
auto
x_dims
=
x_meta
.
dims
;
auto
x_rank
=
static_cast
<
size_t
>
(
x_dims
.
size
());
PADDLE_ENFORCE_EQ
(
true
,
...
...
@@ -60,10 +60,10 @@ DenseTensorMeta DotInferShape(const DenseTensorMeta& x_meta,
return
return_meta
;
}
DenseTensorMeta
MatmulInfer
Shape
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
,
bool
trans_x
,
bool
trans_y
)
{
DenseTensorMeta
MatmulInfer
Meta
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
,
bool
trans_x
,
bool
trans_y
)
{
std
::
vector
<
int64_t
>
dims_x
=
paddle
::
framework
::
vectorize
(
x_meta
.
dims
);
std
::
vector
<
int64_t
>
dims_y
=
paddle
::
framework
::
vectorize
(
y_meta
.
dims
);
auto
ndims_x
=
dims_x
.
size
();
...
...
@@ -130,9 +130,9 @@ DenseTensorMeta MatmulInferShape(const DenseTensorMeta& x_meta,
return
{
x_meta
.
dtype
,
ddim_out
,
x_meta
.
layout
};
}
DenseTensorMeta
ElementwiseInfer
Shape
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
,
int
axis
)
{
DenseTensorMeta
ElementwiseInfer
Meta
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
,
int
axis
)
{
DenseTensorMeta
return_meta
(
x_meta
.
dtype
,
x_meta
.
dims
,
x_meta
.
layout
);
if
(
x_meta
.
dims
!=
y_meta
.
dims
)
{
auto
x_dims
=
x_meta
.
dims
;
...
...
paddle/pten/infermeta/binary.h
浏览文件 @
2a905f6b
...
...
@@ -19,29 +19,29 @@ limitations under the License. */
namespace
pten
{
// Common Infer
Shape
Functions for binary operators, The format like:
// Common Infer
Meta
Functions for binary operators, The format like:
//
// 1. DenseTensorMeta [OpName]Infer
Shape
(const DenseTensorMeta& x_meta, ...)
// 1. DenseTensorMeta [OpName]Infer
Meta
(const DenseTensorMeta& x_meta, ...)
// {}
// 2. std::pair<DenseTensorMeta, DenseTensorMeta> [OpName]Infer
Shape
(const
// 2. std::pair<DenseTensorMeta, DenseTensorMeta> [OpName]Infer
Meta
(const
// DenseTensorMeta&
// x_meta, ...) {}
// 3. std::tuple<DenseTensorMeta, DenseTensorMeta, DenseTensorMeta>
// [OpName]Infer
Shape
(const
// [OpName]Infer
Meta
(const
// DenseTensorMeta& x_meta, ...)
// NOTE: The name "Infer
Shape
" may be not appropriate. "InferMeta" may be good.
// NOTE: The name "Infer
Meta
" may be not appropriate. "InferMeta" may be good.
// Because functions in this file
// not only can infer shape, but alse need infer lod or other useful data.
DenseTensorMeta
DotInfer
Shape
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
);
DenseTensorMeta
DotInfer
Meta
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
);
DenseTensorMeta
MatmulInfer
Shape
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
,
bool
trans_x
,
bool
trans_y
);
DenseTensorMeta
MatmulInfer
Meta
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
,
bool
trans_x
,
bool
trans_y
);
DenseTensorMeta
ElementwiseInfer
Shape
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
,
int
axis
);
DenseTensorMeta
ElementwiseInfer
Meta
(
const
DenseTensorMeta
&
x_meta
,
const
DenseTensorMeta
&
y_meta
,
int
axis
);
}
// namespace pten
paddle/pten/infermeta/nary.cc
浏览文件 @
2a905f6b
...
...
@@ -17,16 +17,16 @@ limitations under the License. */
namespace
pten
{
DenseTensorMeta
FullInfer
Shape
(
const
std
::
vector
<
int64_t
>&
shape
,
DataType
dtype
,
DataLayout
layout
)
{
DenseTensorMeta
FullInfer
Meta
(
const
std
::
vector
<
int64_t
>&
shape
,
DataType
dtype
,
DataLayout
layout
)
{
const
auto
&
out_dims
=
paddle
::
framework
::
make_ddim
(
shape
);
return
{
dtype
,
out_dims
,
layout
};
}
DenseTensorMeta
FullInfer
Shape
(
const
ScalarArray
&
shape
,
DataType
dtype
,
DataLayout
layout
)
{
DenseTensorMeta
FullInfer
Meta
(
const
ScalarArray
&
shape
,
DataType
dtype
,
DataLayout
layout
)
{
const
auto
&
out_dims
=
paddle
::
framework
::
make_ddim
(
shape
.
GetData
());
return
{
dtype
,
out_dims
,
layout
};
}
...
...
paddle/pten/infermeta/nary.h
浏览文件 @
2a905f6b
...
...
@@ -19,20 +19,20 @@ limitations under the License. */
namespace
pten
{
// Common Infer
Shape
Functions for 0-nary operators(no input tensor), The format
// Common Infer
Meta
Functions for 0-nary operators(no input tensor), The format
// like:
//
// 1. DenseTensorMeta [OpName]Infer
Shape
( ...)
// NOTE: The name "Infer
Shape
" may be not appropriate. "InferMeta" may be good.
// 1. DenseTensorMeta [OpName]Infer
Meta
( ...)
// NOTE: The name "Infer
Meta
" may be not appropriate. "InferMeta" may be good.
// Because functions in this file
// not only can infer shape, but alse need infer lod or other useful data.
DenseTensorMeta
FullInfer
Shape
(
const
std
::
vector
<
int64_t
>&
shape
,
DataType
dtype
,
DataLayout
layout
);
DenseTensorMeta
FullInfer
Meta
(
const
std
::
vector
<
int64_t
>&
shape
,
DataType
dtype
,
DataLayout
layout
);
DenseTensorMeta
FullInfer
Shape
(
const
ScalarArray
&
shape
,
DataType
dtype
,
DataLayout
layout
);
DenseTensorMeta
FullInfer
Meta
(
const
ScalarArray
&
shape
,
DataType
dtype
,
DataLayout
layout
);
}
// namespace pten
paddle/pten/infermeta/unary.cc
浏览文件 @
2a905f6b
...
...
@@ -17,19 +17,19 @@ limitations under the License. */
namespace
pten
{
DenseTensorMeta
UnchangedInfer
Shape
(
const
DenseTensorMeta
&
x_meta
)
{
DenseTensorMeta
UnchangedInfer
Meta
(
const
DenseTensorMeta
&
x_meta
)
{
return
x_meta
;
}
DenseTensorMeta
ReductionInfer
Shape
(
const
DenseTensorMeta
&
x_meta
)
{
DenseTensorMeta
ReductionInfer
Meta
(
const
DenseTensorMeta
&
x_meta
)
{
const
auto
&
out_dims
=
paddle
::
framework
::
make_ddim
({
1
});
DenseTensorMeta
return_meta
(
x_meta
.
dtype
,
out_dims
,
x_meta
.
layout
);
return
return_meta
;
}
DenseTensorMeta
FlattenInfer
Shape
(
const
DenseTensorMeta
&
x_meta
,
int
start_axis
,
int
stop_axis
)
{
DenseTensorMeta
FlattenInfer
Meta
(
const
DenseTensorMeta
&
x_meta
,
int
start_axis
,
int
stop_axis
)
{
auto
&
x_dims
=
x_meta
.
dims
;
int
in_dims_size
=
x_dims
.
size
();
if
(
start_axis
<
0
)
{
...
...
@@ -80,9 +80,9 @@ DenseTensorMeta CastInferMeta(const DenseTensorMeta& x_meta,
return
out_meta
;
}
DenseTensorMeta
FullLikeInfer
Shape
(
const
DenseTensorMeta
&
x_meta
,
DataType
dtype
,
DataLayout
layout
)
{
DenseTensorMeta
FullLikeInfer
Meta
(
const
DenseTensorMeta
&
x_meta
,
DataType
dtype
,
DataLayout
layout
)
{
return
{
dtype
==
DataType
::
UNDEFINED
?
x_meta
.
dtype
:
dtype
,
x_meta
.
dims
,
layout
==
DataLayout
::
UNDEFINED
?
x_meta
.
layout
:
layout
};
...
...
@@ -208,8 +208,8 @@ static paddle::framework::DDim ValidateShape(
return
paddle
::
framework
::
make_ddim
(
output_shape
);
}
DenseTensorMeta
Infer
Shape
FromVecValue
(
const
DenseTensorMeta
&
x_meta
,
const
std
::
vector
<
int64_t
>&
shape
)
{
DenseTensorMeta
Infer
Meta
FromVecValue
(
const
DenseTensorMeta
&
x_meta
,
const
std
::
vector
<
int64_t
>&
shape
)
{
PADDLE_ENFORCE_EQ
(
!
shape
.
empty
(),
true
,
paddle
::
platform
::
errors
::
InvalidArgument
(
...
...
paddle/pten/infermeta/unary.h
浏览文件 @
2a905f6b
...
...
@@ -19,34 +19,34 @@ limitations under the License. */
namespace
pten
{
// Common Infer
Shape
Functions for unary operators, The format like:
// Common Infer
Meta
Functions for unary operators, The format like:
//
// 1. DenseTensorMeta [OpName]Infer
Shape
(const DenseTensorMeta& x_meta, ...)
// 1. DenseTensorMeta [OpName]Infer
Meta
(const DenseTensorMeta& x_meta, ...)
// {}
// 2. std::pair<DenseTensorMeta, DenseTensorMeta> [OpName]Infer
Shape
(const
// 2. std::pair<DenseTensorMeta, DenseTensorMeta> [OpName]Infer
Meta
(const
// DenseTensorMeta&
// x_meta, ...) {}
// 3. std::tuple<DenseTensorMeta, DenseTensorMeta, DenseTensorMeta>
// [OpName]Infer
Shape
(const
// [OpName]Infer
Meta
(const
// DenseTensorMeta& x_meta, ...)
// NOTE: The name "Infer
Shape
" may be not appropriate. "InferMeta" may be good.
// NOTE: The name "Infer
Meta
" may be not appropriate. "InferMeta" may be good.
// Because functions in this file
// not only can infer shape, but alse need infer lod or other useful data.
DenseTensorMeta
UnchangedInfer
Shape
(
const
DenseTensorMeta
&
x_meta
);
DenseTensorMeta
UnchangedInfer
Meta
(
const
DenseTensorMeta
&
x_meta
);
DenseTensorMeta
ReductionInfer
Shape
(
const
DenseTensorMeta
&
x_meta
);
DenseTensorMeta
ReductionInfer
Meta
(
const
DenseTensorMeta
&
x_meta
);
DenseTensorMeta
FlattenInfer
Shape
(
const
DenseTensorMeta
&
x_meta
,
int
start_axis
,
int
stop_axis
);
DenseTensorMeta
FlattenInfer
Meta
(
const
DenseTensorMeta
&
x_meta
,
int
start_axis
,
int
stop_axis
);
DenseTensorMeta
CastInferMeta
(
const
DenseTensorMeta
&
x_meta
,
const
DataType
out_dtype
);
DenseTensorMeta
FullLikeInfer
Shape
(
const
DenseTensorMeta
&
x_meta
,
DataType
dtype
,
DataLayout
layout
);
DenseTensorMeta
FullLikeInfer
Meta
(
const
DenseTensorMeta
&
x_meta
,
DataType
dtype
,
DataLayout
layout
);
DenseTensorMeta
Infer
Shape
FromVecValue
(
const
DenseTensorMeta
&
x_meta
,
const
std
::
vector
<
int64_t
>&
shape
);
DenseTensorMeta
Infer
Meta
FromVecValue
(
const
DenseTensorMeta
&
x_meta
,
const
std
::
vector
<
int64_t
>&
shape
);
}
// namespace pten
paddle/pten/kernels/cpu/manipulation.cc
浏览文件 @
2a905f6b
...
...
@@ -50,7 +50,7 @@ void ReshapeFromVectorVal(const CPUContext& dev_ctx,
const
DenseTensor
&
x
,
const
std
::
vector
<
int64_t
>&
shape
,
DenseTensor
*
out
)
{
auto
out_meta
=
Infer
Shape
FromVecValue
(
x
.
meta
(),
shape
);
auto
out_meta
=
Infer
Meta
FromVecValue
(
x
.
meta
(),
shape
);
if
(
&
x
==
out
)
{
out
->
Resize
(
out_meta
.
dims
);
return
;
...
...
paddle/pten/kernels/cuda/manipulation.cu
浏览文件 @
2a905f6b
...
...
@@ -50,7 +50,7 @@ void ReshapeFromVectorVal(const CUDAContext& dev_ctx,
const
DenseTensor
&
x
,
const
std
::
vector
<
int64_t
>&
shape
,
DenseTensor
*
out
)
{
auto
out_meta
=
Infer
Shape
FromVecValue
(
x
.
meta
(),
shape
);
auto
out_meta
=
Infer
Meta
FromVecValue
(
x
.
meta
(),
shape
);
if
(
&
x
==
out
)
{
out
->
Resize
(
out_meta
.
dims
);
return
;
...
...
paddle/pten/kernels/xpu/manipulation.cc
浏览文件 @
2a905f6b
...
...
@@ -55,7 +55,7 @@ void ReshapeFromVectorVal(const XPUContext& dev_ctx,
const
DenseTensor
&
x
,
const
std
::
vector
<
int64_t
>&
shape
,
DenseTensor
*
out
)
{
auto
out_meta
=
Infer
Shape
FromVecValue
(
x
.
meta
(),
shape
);
auto
out_meta
=
Infer
Meta
FromVecValue
(
x
.
meta
(),
shape
);
if
(
&
x
==
out
)
{
out
->
Resize
(
out_meta
.
dims
);
return
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录