Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e16ab42b
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看板
未验证
提交
e16ab42b
编写于
2月 21, 2022
作者:
Z
zyfncg
提交者:
GitHub
2月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Pten] Add copy_to wrapped infermeta (#39703)
* add copy_to wrapped infermeta * test=allcases * test=allcases * test=allcases
上级
dcfe1986
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
97 addition
and
1 deletion
+97
-1
paddle/phi/core/infermeta_utils.cc
paddle/phi/core/infermeta_utils.cc
+10
-0
paddle/phi/core/infermeta_utils.h
paddle/phi/core/infermeta_utils.h
+15
-1
paddle/phi/infermeta/unary.cc
paddle/phi/infermeta/unary.cc
+10
-0
paddle/phi/infermeta/unary.h
paddle/phi/infermeta/unary.h
+5
-0
paddle/phi/tests/core/test_meta_fn_utils.cc
paddle/phi/tests/core/test_meta_fn_utils.cc
+57
-0
未找到文件。
paddle/phi/core/infermeta_utils.cc
浏览文件 @
e16ab42b
...
...
@@ -83,6 +83,16 @@ MetaTensor* InferMetaContext::MutableOutputAt(size_t idx) {
return
outputs_
.
at
(
idx
).
get
();
}
std
::
vector
<
MetaTensor
>
InferMetaContext
::
MutableOutputBetween
(
size_t
start
,
size_t
end
)
{
std
::
vector
<
MetaTensor
>
result
;
result
.
reserve
(
end
-
start
);
for
(
size_t
i
=
start
;
i
<
end
;
++
i
)
{
result
.
emplace_back
(
*
outputs_
.
at
(
i
));
}
return
result
;
}
MetaFnFactory
&
MetaFnFactory
::
Instance
()
{
static
MetaFnFactory
g_meta_fn_map
;
return
g_meta_fn_map
;
...
...
paddle/phi/core/infermeta_utils.h
浏览文件 @
e16ab42b
...
...
@@ -52,6 +52,7 @@ class InferMetaContext {
const
MetaTensor
&
InputAt
(
size_t
idx
)
const
;
std
::
vector
<
MetaTensor
>
InputsBetween
(
size_t
start
,
size_t
end
)
const
;
MetaTensor
*
MutableOutputAt
(
size_t
idx
);
std
::
vector
<
MetaTensor
>
MutableOutputBetween
(
size_t
start
,
size_t
end
);
template
<
typename
AttrType
>
AttrType
AttrAt
(
size_t
idx
)
{
...
...
@@ -186,7 +187,20 @@ struct InferMetaFnImpl<Return (*)(Args...), infer_meta_fn> {
}
};
// TODO(chenweihang): support vector<MetaTensor> output later
template
<
typename
...
Tail
>
struct
InferMetaFnCallHelper
<
std
::
vector
<
MetaTensor
>*
,
Tail
...
>
{
template
<
int
in_idx
,
int
attr_idx
,
int
out_idx
,
typename
...
PreviousArgs
>
static
void
Call
(
InferMetaContext
*
ctx
,
PreviousArgs
&
...
pargs
)
{
const
std
::
pair
<
int
,
int
>
range
=
ctx
->
OutputRangeAt
(
out_idx
);
std
::
vector
<
MetaTensor
>
tmp
=
ctx
->
MutableOutputBetween
(
range
.
first
,
range
.
second
);
std
::
vector
<
MetaTensor
>*
arg
=
&
tmp
;
InferMetaFnCallHelper
<
Tail
...
>::
template
Call
<
in_idx
,
attr_idx
,
out_idx
+
1
>(
ctx
,
pargs
...,
arg
);
}
};
template
<
typename
...
Tail
>
struct
InferMetaFnCallHelper
<
MetaConfig
,
Tail
...
>
{
...
...
paddle/phi/infermeta/unary.cc
浏览文件 @
e16ab42b
...
...
@@ -79,6 +79,13 @@ void CastInferMeta(const MetaTensor& x, DataType out_dtype, MetaTensor* out) {
out
->
set_layout
(
x
.
layout
());
}
void
CopyToInferMeta
(
const
MetaTensor
&
x
,
Backend
backend
,
bool
blocking
,
MetaTensor
*
out
)
{
UnchangedInferMeta
(
x
,
out
);
}
void
CreateLikeInferMeta
(
const
MetaTensor
&
x
,
DataType
dtype
,
MetaTensor
*
out
)
{
out
->
set_dims
(
x
.
dims
());
out
->
set_dtype
(
dtype
==
DataType
::
UNDEFINED
?
x
.
dtype
()
:
dtype
);
...
...
@@ -497,3 +504,6 @@ void TraceInferMeta(
}
}
// namespace phi
PT_REGISTER_INFER_META_FN
(
copy_to
,
phi
::
CopyToInferMeta
);
PT_REGISTER_INFER_META_FN
(
split
,
phi
::
SplitInferMeta
);
paddle/phi/infermeta/unary.h
浏览文件 @
e16ab42b
...
...
@@ -41,6 +41,11 @@ void FlattenInferMeta(const MetaTensor& x,
void
CastInferMeta
(
const
MetaTensor
&
x
,
DataType
out_dtype
,
MetaTensor
*
out
);
void
CopyToInferMeta
(
const
MetaTensor
&
x
,
Backend
backend
,
bool
blocking
,
MetaTensor
*
out
);
void
CreateLikeInferMeta
(
const
MetaTensor
&
x
,
DataType
dtype
,
MetaTensor
*
out
);
void
InferMetaFromVecValue
(
const
MetaTensor
&
x
,
...
...
paddle/phi/tests/core/test_meta_fn_utils.cc
浏览文件 @
e16ab42b
...
...
@@ -60,5 +60,62 @@ TEST(MetaFnFactory, InferMetaFnExists) {
EXPECT_EQ
(
dense_out1
.
dims
()[
1
],
dense_out2
.
dims
()[
1
]);
}
TEST
(
MetaFnFactory
,
CopyInferMetaFn
)
{
phi
::
DenseTensor
dense_x
;
dense_x
.
Resize
({
3
,
4
});
phi
::
MetaTensor
meta_x
(
&
dense_x
);
phi
::
DenseTensor
dense_out1
;
phi
::
MetaTensor
meta_out
(
&
dense_out1
);
phi
::
UnchangedInferMeta
(
meta_x
,
&
meta_out
);
auto
shared_meat_x
=
std
::
make_shared
<
phi
::
MetaTensor
>
(
&
dense_x
);
phi
::
DenseTensor
dense_out2
;
auto
shared_meta_out
=
std
::
make_shared
<
phi
::
MetaTensor
>
(
&
dense_out2
);
phi
::
InferMetaContext
ctx
;
ctx
.
EmplaceBackInput
(
shared_meat_x
);
ctx
.
EmplaceBackAttr
(
Backend
::
CPU
);
ctx
.
EmplaceBackAttr
(
false
);
ctx
.
EmplaceBackOutput
(
shared_meta_out
);
ctx
.
SetMetaConfig
(
/*is_runtime=*/
true
);
phi
::
MetaFnFactory
::
Instance
().
Get
(
"copy_to"
)(
&
ctx
);
EXPECT_EQ
(
dense_out1
.
dims
().
size
(),
dense_out2
.
dims
().
size
());
EXPECT_EQ
(
dense_out1
.
dims
()[
0
],
dense_out2
.
dims
()[
0
]);
EXPECT_EQ
(
dense_out1
.
dims
()[
1
],
dense_out2
.
dims
()[
1
]);
}
TEST
(
MetaFnFactory
,
SplitInferMetaFn
)
{
phi
::
DenseTensor
dense_x
;
dense_x
.
Resize
({
4
,
10
});
phi
::
MetaTensor
meta_x
(
&
dense_x
);
auto
shared_meat_x
=
std
::
make_shared
<
phi
::
MetaTensor
>
(
&
dense_x
);
phi
::
DenseTensor
dense_out1
;
phi
::
DenseTensor
dense_out2
;
paddle
::
SmallVector
<
std
::
shared_ptr
<
phi
::
MetaTensor
>>
out
;
out
.
push_back
(
std
::
make_shared
<
phi
::
MetaTensor
>
(
&
dense_out1
));
out
.
push_back
(
std
::
make_shared
<
phi
::
MetaTensor
>
(
&
dense_out2
));
phi
::
InferMetaContext
ctx
;
ctx
.
EmplaceBackInput
(
shared_meat_x
);
ScalarArray
num_or_sections
{
2
,
2
};
Scalar
axis
{
0
};
ctx
.
EmplaceBackAttr
(
num_or_sections
);
ctx
.
EmplaceBackAttr
(
axis
);
ctx
.
EmplaceBackOutputs
(
out
);
ctx
.
SetMetaConfig
(
/*is_runtime=*/
true
);
phi
::
MetaFnFactory
::
Instance
().
Get
(
"split"
)(
&
ctx
);
ASSERT_EQ
(
dense_out1
.
dims
().
size
(),
2
);
ASSERT_EQ
(
dense_out1
.
dims
()[
0
],
2
);
ASSERT_EQ
(
dense_out1
.
dims
()[
1
],
10
);
ASSERT_EQ
(
dense_out2
.
dims
().
size
(),
2
);
ASSERT_EQ
(
dense_out2
.
dims
()[
0
],
2
);
ASSERT_EQ
(
dense_out2
.
dims
()[
1
],
10
);
}
}
// namespace tests
}
// namespace phi
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录