Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
068f48d8
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
068f48d8
编写于
7月 15, 2022
作者:
X
xiongkun
提交者:
GitHub
7月 15, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ Phi Kernel ] Transfer as_real to phi. (#44263)
* transfer as_real to phi * fix erros * blocking: True -> False
上级
13d01e6e
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
131 addition
and
35 deletion
+131
-35
paddle/fluid/operators/complex_view_op.cc
paddle/fluid/operators/complex_view_op.cc
+6
-15
paddle/fluid/operators/complex_view_op.cu
paddle/fluid/operators/complex_view_op.cu
+0
-5
paddle/fluid/operators/complex_view_op.h
paddle/fluid/operators/complex_view_op.h
+0
-15
paddle/phi/api/yaml/legacy_api.yaml
paddle/phi/api/yaml/legacy_api.yaml
+9
-0
paddle/phi/infermeta/unary.cc
paddle/phi/infermeta/unary.cc
+8
-0
paddle/phi/infermeta/unary.h
paddle/phi/infermeta/unary.h
+2
-0
paddle/phi/kernels/as_real_kernel.h
paddle/phi/kernels/as_real_kernel.h
+26
-0
paddle/phi/kernels/cpu/as_real_kernel.cc
paddle/phi/kernels/cpu/as_real_kernel.cc
+22
-0
paddle/phi/kernels/gpu/as_real_kernel.cu
paddle/phi/kernels/gpu/as_real_kernel.cu
+22
-0
paddle/phi/kernels/impl/as_real_impl.h
paddle/phi/kernels/impl/as_real_impl.h
+35
-0
python/paddle/fluid/tests/unittests/test_complex_view_op.py
python/paddle/fluid/tests/unittests/test_complex_view_op.py
+1
-0
未找到文件。
paddle/fluid/operators/complex_view_op.cc
浏览文件 @
068f48d8
...
...
@@ -20,7 +20,9 @@
#include <vector>
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/phi/infermeta/unary.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -94,17 +96,6 @@ class AsRealOp : public framework::OperatorWithKernel {
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"as_real"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"Out"
),
"Output"
,
"Out"
,
"as_real"
);
auto
out_dims_v
=
phi
::
vectorize
(
ctx
->
GetInputDim
(
"X"
));
out_dims_v
.
push_back
(
2
);
const
framework
::
DDim
out_dims
=
phi
::
make_ddim
(
out_dims_v
);
ctx
->
SetOutputDim
(
"Out"
,
out_dims
);
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
protected:
framework
::
OpKernelType
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
...
...
@@ -148,6 +139,9 @@ class AsRealGradMaker : public framework::SingleGradOpMaker<T> {
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
as_real
,
AsRealInferShapeFunctor
,
PD_INFER_META
(
phi
::
AsRealInferMeta
));
REGISTER_OPERATOR
(
as_complex
,
ops
::
AsComplexOp
,
...
...
@@ -158,13 +152,10 @@ REGISTER_OPERATOR(as_complex,
REGISTER_OPERATOR
(
as_real
,
ops
::
AsRealOp
,
ops
::
AsRealOpMaker
,
AsRealInferShapeFunctor
,
ops
::
AsRealGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
AsRealGradMaker
<
paddle
::
imperative
::
OpBase
>
);
REGISTER_OP_CPU_KERNEL
(
as_complex
,
ops
::
AsComplexKernel
<
phi
::
CPUContext
,
float
>
,
ops
::
AsComplexKernel
<
phi
::
CPUContext
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
as_real
,
ops
::
AsRealKernel
<
phi
::
CPUContext
,
float
>
,
ops
::
AsRealKernel
<
phi
::
CPUContext
,
double
>
);
paddle/fluid/operators/complex_view_op.cu
浏览文件 @
068f48d8
...
...
@@ -22,8 +22,3 @@ REGISTER_OP_CUDA_KERNEL(
as_complex
,
ops
::
AsComplexKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
AsComplexKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
);
REGISTER_OP_CUDA_KERNEL
(
as_real
,
ops
::
AsRealKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
AsRealKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
);
paddle/fluid/operators/complex_view_op.h
浏览文件 @
068f48d8
...
...
@@ -41,20 +41,5 @@ class AsComplexKernel : public framework::OpKernel<T> {
}
};
template
<
typename
DeviceContext
,
typename
T
>
class
AsRealKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
const
auto
*
x
=
context
.
Input
<
framework
::
LoDTensor
>
(
"X"
);
auto
*
out
=
context
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
const
framework
::
DDim
out_dims_original
=
out
->
dims
();
framework
::
TensorCopy
(
*
x
,
context
.
GetPlace
(),
out
);
out
->
Resize
(
out_dims_original
);
// restored the shape
out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
// restore the dtype
}
};
}
// namespace operators
}
// namespace paddle
paddle/phi/api/yaml/legacy_api.yaml
浏览文件 @
068f48d8
...
...
@@ -167,6 +167,15 @@
func
:
argsort
backward
:
argsort_grad
-
api
:
as_real
args
:
(Tensor x)
output
:
Tensor
infer_meta
:
func
:
AsRealInferMeta
kernel
:
func
:
as_real
# backward : as_complex
# asin
-
api
:
asin
args
:
(Tensor x)
...
...
paddle/phi/infermeta/unary.cc
浏览文件 @
068f48d8
...
...
@@ -148,6 +148,14 @@ void ArgsortInferMeta(const MetaTensor& input,
indices
->
share_lod
(
input
);
}
void
AsRealInferMeta
(
const
MetaTensor
&
input
,
MetaTensor
*
output
)
{
auto
out_dims_v
=
phi
::
vectorize
(
input
.
dims
());
out_dims_v
.
push_back
(
2
);
auto
out_dims
=
phi
::
make_ddim
(
out_dims_v
);
output
->
set_dims
(
out_dims
);
output
->
share_lod
(
input
);
}
void
BatchSizeLikeInferMeta
(
const
MetaTensor
&
x
,
const
std
::
vector
<
int
>&
shape
,
int
x_batch_size_dim
,
...
...
paddle/phi/infermeta/unary.h
浏览文件 @
068f48d8
...
...
@@ -48,6 +48,8 @@ void ArgsortInferMeta(const MetaTensor& input,
MetaTensor
*
output
,
MetaTensor
*
indices
);
void
AsRealInferMeta
(
const
MetaTensor
&
input
,
MetaTensor
*
output
);
void
BatchSizeLikeInferMeta
(
const
MetaTensor
&
x
,
const
std
::
vector
<
int
>&
shape
,
int
x_batch_size_dim
,
...
...
paddle/phi/kernels/as_real_kernel.h
0 → 100644
浏览文件 @
068f48d8
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "paddle/phi/core/dense_tensor.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
AsRealKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
DenseTensor
*
out
);
}
// namespace phi
paddle/phi/kernels/cpu/as_real_kernel.cc
0 → 100644
浏览文件 @
068f48d8
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/as_real_kernel.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/as_real_impl.h"
PD_REGISTER_KERNEL
(
as_real
,
CPU
,
ALL_LAYOUT
,
phi
::
AsRealKernel
,
float
,
double
)
{
}
paddle/phi/kernels/gpu/as_real_kernel.cu
0 → 100644
浏览文件 @
068f48d8
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/as_real_kernel.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/as_real_impl.h"
PD_REGISTER_KERNEL
(
as_real
,
GPU
,
ALL_LAYOUT
,
phi
::
AsRealKernel
,
float
,
double
)
{
}
paddle/phi/kernels/impl/as_real_impl.h
0 → 100644
浏览文件 @
068f48d8
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "paddle/phi/kernels/as_real_kernel.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/funcs/for_range.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
AsRealKernel
(
const
Context
&
ctx
,
const
DenseTensor
&
x
,
DenseTensor
*
out
)
{
ctx
.
template
Alloc
<
T
>(
out
);
auto
out_dims_original
=
out
->
dims
();
Copy
(
ctx
,
x
,
ctx
.
GetPlace
(),
false
,
out
);
out
->
Resize
(
out_dims_original
);
// restored the shape.
out
->
set_type
(
paddle
::
experimental
::
CppTypeToDataType
<
T
>::
Type
());
// restored the
// dtype.
}
}
// namespace phi
python/paddle/fluid/tests/unittests/test_complex_view_op.py
浏览文件 @
068f48d8
...
...
@@ -67,6 +67,7 @@ class TestViewAsRealOp(OpTest):
out_ref
=
ref_view_as_real
(
x
)
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Out'
:
out_ref
}
self
.
python_api
=
paddle
.
as_real
self
.
out_grad
=
np
.
ones
([
10
,
10
,
2
],
dtype
=
"float64"
)
def
test_check_output
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录