Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Phi]Move angle op to phi #44393

Merged
merged 7 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions paddle/fluid/operators/angle_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/fluid/operators/angle_op.h"

#include <memory>
#include <string>
#include <unordered_map>
Expand All @@ -22,22 +20,17 @@
#include "paddle/fluid/platform/mkldnn_helper.h"
#endif

#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/unary.h"

namespace paddle {
namespace operators {

class AngleOp : public framework::OperatorWithKernel {
public:
using framework::OperatorWithKernel::OperatorWithKernel;

void InferShape(framework::InferShapeContext* ctx) const override {
OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "angle");
OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "angle");

auto in_dims = ctx->GetInputDim("X");

ctx->SetOutputDim("Out", in_dims);
ctx->ShareLoD("X", /*->*/ "Out");
}
};

class AngleOpMaker : public framework::OpProtoAndCheckerMaker {
Expand Down Expand Up @@ -108,24 +101,15 @@ class AngleGradMaker : public framework::SingleGradOpMaker<T> {

namespace ops = paddle::operators;

DECLARE_INFER_SHAPE_FUNCTOR(angle,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

反向的Infermeta也需要删掉

Copy link
Contributor Author

@0x45f 0x45f Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已迁移反向infeshape,感谢

AngleInferShapeFunctor,
PD_INFER_META(phi::RealAndImagInferMeta));

REGISTER_OPERATOR(angle,
ops::AngleOp,
ops::AngleOpMaker,
ops::AngleGradMaker<paddle::framework::OpDesc>,
ops::AngleGradMaker<paddle::imperative::OpBase>);

REGISTER_OP_CPU_KERNEL(
angle,
ops::AngleKernel<phi::CPUContext, float>,
ops::AngleKernel<phi::CPUContext, double>,
ops::AngleKernel<phi::CPUContext, paddle::platform::complex<float>>,
ops::AngleKernel<phi::CPUContext, paddle::platform::complex<double>>);
ops::AngleGradMaker<paddle::imperative::OpBase>,
AngleInferShapeFunctor);

REGISTER_OPERATOR(angle_grad, ops::AngleGradOp);

REGISTER_OP_CPU_KERNEL(
angle_grad,
ops::AngleGradKernel<phi::CPUContext, float>,
ops::AngleGradKernel<phi::CPUContext, double>,
ops::AngleGradKernel<phi::CPUContext, paddle::platform::complex<float>>,
ops::AngleGradKernel<phi::CPUContext, paddle::platform::complex<double>>);
33 changes: 0 additions & 33 deletions paddle/fluid/operators/angle_op.cu

This file was deleted.

72 changes: 0 additions & 72 deletions paddle/fluid/operators/angle_op.h

This file was deleted.

9 changes: 9 additions & 0 deletions paddle/phi/api/yaml/legacy_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@
kernel :
func : allclose

- api : angle
args : (Tensor x)
output : Tensor
infer_meta :
func : RealAndImagInferMeta
kernel :
func : angle
backward : angle_grad

- api : any
args : (Tensor x, int64_t[] dims={}, bool keep_dim=false)
output : Tensor(out)
Expand Down
12 changes: 12 additions & 0 deletions paddle/phi/api/yaml/legacy_backward.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@
kernel :
func : addmm_grad

- backward_api : angle_grad
forward : angle (Tensor x) -> Tensor(out)
args : (Tensor x, Tensor out_grad)
output : Tensor(x_grad)
infer_meta :
func : UnchangedInferMeta
param : [x]
kernel :
func : angle_grad
data_transform:
skip_transform : out_grad

- backward_api : argsort_grad
forward : argsort (Tensor x, int axis, bool descending) -> Tensor(out), Tensor(indices)
args : (Tensor indices, Tensor x, Tensor out_grad, int axis, bool descending)
Expand Down
27 changes: 27 additions & 0 deletions paddle/phi/kernels/angle_grad_kernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 AnagleGradKernel(const Context& dev_ctx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有拼写错误

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

拼写错误已改正,感谢

const DenseTensor& x,
const DenseTensor& out_grad,
DenseTensor* x_grad);

} // namespace phi
30 changes: 30 additions & 0 deletions paddle/phi/kernels/angle_kernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <math.h>

#include "paddle/phi/core/dense_tensor.h"

namespace phi {

template <typename T, typename Context>
void AnagleKernel(const Context& dev_ctx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

const DenseTensor& x,
DenseTensor* out);

} // namespace phi
28 changes: 28 additions & 0 deletions paddle/phi/kernels/cpu/angle_grad_kernel.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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/angle_grad_kernel.h"
#include "paddle/phi/kernels/impl/angle_grad_kernel_impl.h"

#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"

PD_REGISTER_KERNEL(angle_grad,
CPU,
ALL_LAYOUT,
phi::AnagleGradKernel,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}
29 changes: 29 additions & 0 deletions paddle/phi/kernels/cpu/angle_kernel.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// 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/angle_kernel.h"
#include "paddle/phi/kernels/impl/angle_kernel_impl.h"

#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"

PD_REGISTER_KERNEL(angle,
CPU,
ALL_LAYOUT,
phi::AnagleKernel,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}
28 changes: 28 additions & 0 deletions paddle/phi/kernels/gpu/angle_grad_kernel.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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/angle_grad_kernel.h"
#include "paddle/phi/kernels/impl/angle_grad_kernel_impl.h"

#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"

PD_REGISTER_KERNEL(angle_grad,
GPU,
ALL_LAYOUT,
phi::AnagleGradKernel,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}
29 changes: 29 additions & 0 deletions paddle/phi/kernels/gpu/angle_kernel.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// 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/angle_kernel.h"
#include "paddle/phi/kernels/impl/angle_kernel_impl.h"

#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"

PD_REGISTER_KERNEL(angle,
GPU,
ALL_LAYOUT,
phi::AnagleKernel,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}
Loading