From 3c536f2e65c65cc986e8aaff86214426498d1f7a Mon Sep 17 00:00:00 2001 From: WJJ1995 Date: Tue, 8 Mar 2022 13:11:12 +0800 Subject: [PATCH] =?UTF-8?q?[phi]=20move=20isnan=5Fv2=E3=80=81isfinite=5Fv2?= =?UTF-8?q?=E3=80=81isinf=5Fv2=20to=20phi=20(#40076)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * support isfinite for phi * mark v2 * fixed bugs * fixed include bugs * deal with comments * decoupling selected_rows * rm bfloat16 * fixed infermeta * fixed code style * rm useless code * replace pt by pd --- paddle/fluid/operators/isfinite_v2_op.cc | 64 ++++--------- paddle/fluid/operators/isfinite_v2_op.cu | 55 ----------- paddle/phi/core/compat/op_utils.h | 3 + paddle/phi/infermeta/unary.cc | 5 + paddle/phi/infermeta/unary.h | 2 + paddle/phi/kernels/cpu/isfinite_kernel.cc | 62 ++++++++++++ .../kernels/funcs/isfinite_functor.h} | 33 +++---- paddle/phi/kernels/gpu/isfinite_kernel.cu | 61 ++++++++++++ .../phi/kernels/impl/isfinite_kernel_impl.h | 39 ++++++++ paddle/phi/kernels/isfinite_kernel.h | 31 ++++++ .../kernels/selected_rows/isfinite_kernel.cc | 96 +++++++++++++++++++ .../kernels/selected_rows/isfinite_kernel.h | 31 ++++++ .../selected_rows/isfinite_kernel_impl.h | 39 ++++++++ paddle/phi/ops/compat/isfinite_sig.cc | 19 ++++ 14 files changed, 419 insertions(+), 121 deletions(-) delete mode 100644 paddle/fluid/operators/isfinite_v2_op.cu create mode 100644 paddle/phi/kernels/cpu/isfinite_kernel.cc rename paddle/{fluid/operators/isfinite_v2_op.h => phi/kernels/funcs/isfinite_functor.h} (52%) create mode 100644 paddle/phi/kernels/gpu/isfinite_kernel.cu create mode 100644 paddle/phi/kernels/impl/isfinite_kernel_impl.h create mode 100644 paddle/phi/kernels/isfinite_kernel.h create mode 100644 paddle/phi/kernels/selected_rows/isfinite_kernel.cc create mode 100644 paddle/phi/kernels/selected_rows/isfinite_kernel.h create mode 100644 paddle/phi/kernels/selected_rows/isfinite_kernel_impl.h create mode 100644 paddle/phi/ops/compat/isfinite_sig.cc diff --git a/paddle/fluid/operators/isfinite_v2_op.cc b/paddle/fluid/operators/isfinite_v2_op.cc index 735fffa7203..cfa370ff9cb 100644 --- a/paddle/fluid/operators/isfinite_v2_op.cc +++ b/paddle/fluid/operators/isfinite_v2_op.cc @@ -12,11 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/fluid/operators/isfinite_v2_op.h" - #include +#include "paddle/fluid/framework/infershape_utils.h" +#include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/operators/common_infer_shape_functions.h" +#include "paddle/phi/core/infermeta_utils.h" +#include "paddle/phi/infermeta/unary.h" namespace paddle { namespace framework { @@ -49,11 +51,6 @@ class OverflowV2Op : public framework::OperatorWithKernel { const framework::VariableNameMap &outputs, const framework::AttributeMap &attrs) : OperatorWithKernel(type, inputs, outputs, attrs) {} - void InferShape(framework::InferShapeContext *ctx) const override { - OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "isfinitev2"); - OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "isfinitev2"); - UnaryOpUnchangedInferShape(ctx); - } protected: framework::OpKernelType GetExpectedKernelType( @@ -104,6 +101,14 @@ element of X as a tensor. } // namespace paddle namespace ops = paddle::operators; +DECLARE_INFER_SHAPE_FUNCTOR(isinf_v2, IsinfInferShapeFunctor, + PD_INFER_META(phi::IsfiniteInferMeta)); + +DECLARE_INFER_SHAPE_FUNCTOR(isnan_v2, IsnanInferShapeFunctor, + PD_INFER_META(phi::IsfiniteInferMeta)); + +DECLARE_INFER_SHAPE_FUNCTOR(isfinite_v2, IsfiniteInferShapeFunctor, + PD_INFER_META(phi::IsfiniteInferMeta)); #define REGISTER_V2OP_MAKER(op_type, comment) \ namespace paddle { \ @@ -124,50 +129,17 @@ REGISTER_V2OP_MAKER(isfinite_v2, "isfinitev2(X)"); REGISTER_OPERATOR( isinf_v2, ops::OverflowV2Op, ops::_isinf_v2OverflowV2OpMaker, paddle::framework::EmptyGradOpMaker, - paddle::framework::EmptyGradOpMaker); + paddle::framework::EmptyGradOpMaker, + IsinfInferShapeFunctor); REGISTER_OPERATOR( isnan_v2, ops::OverflowV2Op, ops::_isnan_v2OverflowV2OpMaker, paddle::framework::EmptyGradOpMaker, - paddle::framework::EmptyGradOpMaker); + paddle::framework::EmptyGradOpMaker, + IsnanInferShapeFunctor); REGISTER_OPERATOR( isfinite_v2, ops::OverflowV2Op, ops::_isfinite_v2OverflowV2OpMaker, paddle::framework::EmptyGradOpMaker, - paddle::framework::EmptyGradOpMaker); - -REGISTER_OP_CPU_KERNEL(isnan_v2, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel); - -REGISTER_OP_CPU_KERNEL( - isinf_v2, ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel); - -REGISTER_OP_CPU_KERNEL( - isfinite_v2, ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel); + paddle::framework::EmptyGradOpMaker, + IsfiniteInferShapeFunctor); diff --git a/paddle/fluid/operators/isfinite_v2_op.cu b/paddle/fluid/operators/isfinite_v2_op.cu deleted file mode 100644 index 1b9f19d36df..00000000000 --- a/paddle/fluid/operators/isfinite_v2_op.cu +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2020 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/fluid/operators/isfinite_v2_op.h" -#include "paddle/fluid/platform/float16.h" - -namespace ops = paddle::operators; -namespace plat = paddle::platform; - -REGISTER_OP_CUDA_KERNEL(isnan_v2, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel); - -REGISTER_OP_CUDA_KERNEL( - isinf_v2, ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel); - -REGISTER_OP_CUDA_KERNEL( - isfinite_v2, ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel); diff --git a/paddle/phi/core/compat/op_utils.h b/paddle/phi/core/compat/op_utils.h index 8f64a7145ed..9947e00ecb5 100644 --- a/paddle/phi/core/compat/op_utils.h +++ b/paddle/phi/core/compat/op_utils.h @@ -40,6 +40,9 @@ const std::unordered_set standard_kernel_suffixs({ const std::unordered_set deprecated_op_names({"diag", "flatten", "flatten_grad", + "isinf", + "isnan", + "isfinite", "matmul", "matmul_grad", "matmul_grad_grad", diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index 4053cfbc362..17edc846187 100644 --- a/paddle/phi/infermeta/unary.cc +++ b/paddle/phi/infermeta/unary.cc @@ -1007,6 +1007,11 @@ void SizeInferMeta(const MetaTensor& input, MetaTensor* out) { out->set_dims({1}); } +void IsfiniteInferMeta(const MetaTensor& x, MetaTensor* out) { + out->set_dims(x.dims()); + out->set_dtype(DataType::BOOL); +} + void PixelShuffleInferMeta(const MetaTensor& x, int upscale_factor, const std::string& data_format, diff --git a/paddle/phi/infermeta/unary.h b/paddle/phi/infermeta/unary.h index a679ef8c11a..dac7c19cf9b 100644 --- a/paddle/phi/infermeta/unary.h +++ b/paddle/phi/infermeta/unary.h @@ -157,6 +157,8 @@ void PixelShuffleInferMeta(const MetaTensor& x, const std::string& data_format, MetaTensor* out); +void IsfiniteInferMeta(const MetaTensor& input, MetaTensor* out); + void TransposeInferMeta(const MetaTensor& x, const std::vector& axis, MetaTensor* out); diff --git a/paddle/phi/kernels/cpu/isfinite_kernel.cc b/paddle/phi/kernels/cpu/isfinite_kernel.cc new file mode 100644 index 00000000000..33a7429a22a --- /dev/null +++ b/paddle/phi/kernels/cpu/isfinite_kernel.cc @@ -0,0 +1,62 @@ +// 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/isfinite_kernel.h" + +#include "paddle/phi/backends/cpu/cpu_context.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/impl/isfinite_kernel_impl.h" + +namespace phi { + +template +inline void IsfiniteKernelImpl(const Context& dev_ctx, + const DenseTensor& x, + DenseTensor* out) { + dev_ctx.template Alloc(out); + Functor functor; + functor(x, out); +} + +} // namespace phi + +PD_REGISTER_KERNEL(isinf, + CPU, + ALL_LAYOUT, + phi::IsinfKernel, + float, + double, + phi::dtype::float16, + int, + int64_t) {} + +PD_REGISTER_KERNEL(isnan, + CPU, + ALL_LAYOUT, + phi::IsnanKernel, + float, + double, + phi::dtype::float16, + int, + int64_t) {} + +PD_REGISTER_KERNEL(isfinite, + CPU, + ALL_LAYOUT, + phi::IsfiniteKernel, + float, + double, + phi::dtype::float16, + int, + int64_t) {} diff --git a/paddle/fluid/operators/isfinite_v2_op.h b/paddle/phi/kernels/funcs/isfinite_functor.h similarity index 52% rename from paddle/fluid/operators/isfinite_v2_op.h rename to paddle/phi/kernels/funcs/isfinite_functor.h index b646e460ec7..c804bee8d4c 100644 --- a/paddle/fluid/operators/isfinite_v2_op.h +++ b/paddle/phi/kernels/funcs/isfinite_functor.h @@ -1,4 +1,4 @@ -// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. +// 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. @@ -14,39 +14,32 @@ #pragma once -#include - -#include "paddle/fluid/framework/eigen.h" #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/framework/tensor_util.h" -#include "paddle/fluid/operators/isfinite_op.h" -#include "paddle/fluid/platform/float16.h" -#include "paddle/fluid/platform/transform.h" +#include "paddle/phi/common/scalar.h" +#include "paddle/phi/core/dense_tensor.h" +#include "paddle/phi/infermeta/unary.h" namespace phi { -class DenseTensor; -} // namespace phi - -namespace paddle { -namespace operators { +namespace funcs { struct InfinityV2Functor { - void operator()(const framework::Tensor& tensor, framework::Tensor* out) { - framework::TensorContainsInfV2(tensor, out); + void operator()(const DenseTensor& tensor, DenseTensor* out) { + paddle::framework::TensorContainsInfV2(tensor, out); } }; struct NANV2Functor { - void operator()(const framework::Tensor& tensor, framework::Tensor* out) { - framework::TensorContainsNANV2(tensor, out); + void operator()(const DenseTensor& tensor, DenseTensor* out) { + paddle::framework::TensorContainsNANV2(tensor, out); } }; struct IsfiniteV2Functor { - void operator()(const framework::Tensor& tensor, framework::Tensor* out) { - framework::TensorIsfiniteV2(tensor, out); + void operator()(const DenseTensor& tensor, DenseTensor* out) { + paddle::framework::TensorIsfiniteV2(tensor, out); } }; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace phi diff --git a/paddle/phi/kernels/gpu/isfinite_kernel.cu b/paddle/phi/kernels/gpu/isfinite_kernel.cu new file mode 100644 index 00000000000..4b41ed1e55d --- /dev/null +++ b/paddle/phi/kernels/gpu/isfinite_kernel.cu @@ -0,0 +1,61 @@ +// 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/backends/gpu/gpu_context.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/impl/isfinite_kernel_impl.h" +#include "paddle/phi/kernels/isfinite_kernel.h" + +namespace phi { + +template +inline void IsfiniteKernelImpl(const Context& dev_ctx, + const DenseTensor& x, + DenseTensor* out) { + dev_ctx.template Alloc(out); + Functor functor; + functor(x, out); +} + +} // namespace phi + +PD_REGISTER_KERNEL(isinf, + GPU, + ALL_LAYOUT, + phi::IsinfKernel, + float, + double, + phi::dtype::float16, + int, + int64_t) {} + +PD_REGISTER_KERNEL(isnan, + GPU, + ALL_LAYOUT, + phi::IsnanKernel, + float, + double, + phi::dtype::float16, + int, + int64_t) {} + +PD_REGISTER_KERNEL(isfinite, + GPU, + ALL_LAYOUT, + phi::IsfiniteKernel, + float, + double, + phi::dtype::float16, + int, + int64_t) {} diff --git a/paddle/phi/kernels/impl/isfinite_kernel_impl.h b/paddle/phi/kernels/impl/isfinite_kernel_impl.h new file mode 100644 index 00000000000..affa85f8a2d --- /dev/null +++ b/paddle/phi/kernels/impl/isfinite_kernel_impl.h @@ -0,0 +1,39 @@ +// 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/funcs/isfinite_functor.h" +#include "paddle/phi/kernels/isfinite_kernel.h" + +namespace phi { + +template +inline void IsfiniteKernelImpl(const Context& ctx, + const DenseTensor& x, + DenseTensor* out); + +#define DEFINE_ISFINITE_KERNEL(isfinite_kernel, functor) \ + template \ + void isfinite_kernel( \ + const Context& ctx, const DenseTensor& x, DenseTensor* out) { \ + IsfiniteKernelImpl(ctx, x, out); \ + } + +DEFINE_ISFINITE_KERNEL(IsinfKernel, funcs::InfinityV2Functor) +DEFINE_ISFINITE_KERNEL(IsnanKernel, funcs::NANV2Functor) +DEFINE_ISFINITE_KERNEL(IsfiniteKernel, funcs::IsfiniteV2Functor) +#undef DEFINE_ISFINITE_KERNEL + +} // namespace phi diff --git a/paddle/phi/kernels/isfinite_kernel.h b/paddle/phi/kernels/isfinite_kernel.h new file mode 100644 index 00000000000..e695a8e0742 --- /dev/null +++ b/paddle/phi/kernels/isfinite_kernel.h @@ -0,0 +1,31 @@ +/* Copyright (c) 2021 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 { + +#define DEFINE_ISFINITE_KERNEL(isfinite_kernel) \ + template \ + void isfinite_kernel( \ + const Context& ctx, const DenseTensor& x, DenseTensor* out); + +DEFINE_ISFINITE_KERNEL(IsinfKernel) +DEFINE_ISFINITE_KERNEL(IsnanKernel) +DEFINE_ISFINITE_KERNEL(IsfiniteKernel) +#undef DEFINE_ISFINITE_KERNEL + +} // namespace phi diff --git a/paddle/phi/kernels/selected_rows/isfinite_kernel.cc b/paddle/phi/kernels/selected_rows/isfinite_kernel.cc new file mode 100644 index 00000000000..a507cdd0d86 --- /dev/null +++ b/paddle/phi/kernels/selected_rows/isfinite_kernel.cc @@ -0,0 +1,96 @@ +// 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/selected_rows/isfinite_kernel.h" + +#include "paddle/phi/backends/cpu/cpu_context.h" +#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) +#include "paddle/phi/backends/gpu/gpu_context.h" +#endif +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/selected_rows/isfinite_kernel_impl.h" + +namespace phi { + +template +inline void IsfiniteSRImpl(const Context& dev_ctx, + const SelectedRows& x, + SelectedRows* out) { + dev_ctx.template Alloc(out); + Functor functor; + functor(x.value(), out->mutable_value()); +} +} // namespace phi + +PD_REGISTER_KERNEL(isinf_sr, + CPU, + ALL_LAYOUT, + phi::IsinfSR, + float, + double, + phi::dtype::float16, + int, + int64_t) {} + +PD_REGISTER_KERNEL(isnan_sr, + CPU, + ALL_LAYOUT, + phi::IsnanSR, + float, + double, + phi::dtype::float16, + int, + int64_t) {} + +PD_REGISTER_KERNEL(isfinite_sr, + CPU, + ALL_LAYOUT, + phi::IsfiniteSR, + float, + double, + phi::dtype::float16, + int, + int64_t) {} + +#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) +PD_REGISTER_KERNEL(isinf_sr, + GPU, + ALL_LAYOUT, + phi::IsinfSR, + float, + double, + phi::dtype::float16, + int, + int64_t) {} + +PD_REGISTER_KERNEL(isnan_sr, + GPU, + ALL_LAYOUT, + phi::IsnanSR, + float, + double, + phi::dtype::float16, + int, + int64_t) {} + +PD_REGISTER_KERNEL(isfinite_sr, + GPU, + ALL_LAYOUT, + phi::IsfiniteSR, + float, + double, + phi::dtype::float16, + int, + int64_t) {} +#endif diff --git a/paddle/phi/kernels/selected_rows/isfinite_kernel.h b/paddle/phi/kernels/selected_rows/isfinite_kernel.h new file mode 100644 index 00000000000..948d8c89477 --- /dev/null +++ b/paddle/phi/kernels/selected_rows/isfinite_kernel.h @@ -0,0 +1,31 @@ +/* Copyright (c) 2021 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/selected_rows.h" + +namespace phi { + +#define DEFINE_ISFINITE_SR(isfinite_sr) \ + template \ + void isfinite_sr( \ + const Context& ctx, const SelectedRows& x, SelectedRows* out); + +DEFINE_ISFINITE_SR(IsinfSR) +DEFINE_ISFINITE_SR(IsnanSR) +DEFINE_ISFINITE_SR(IsfiniteSR) +#undef DEFINE_ISFINITE_SR + +} // namespace phi diff --git a/paddle/phi/kernels/selected_rows/isfinite_kernel_impl.h b/paddle/phi/kernels/selected_rows/isfinite_kernel_impl.h new file mode 100644 index 00000000000..c53abdf996c --- /dev/null +++ b/paddle/phi/kernels/selected_rows/isfinite_kernel_impl.h @@ -0,0 +1,39 @@ +// 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/funcs/isfinite_functor.h" +#include "paddle/phi/kernels/selected_rows/isfinite_kernel.h" + +namespace phi { + +template +inline void IsfiniteSRImpl(const Context& ctx, + const SelectedRows& x, + SelectedRows* out); + +#define DEFINE_ISFINITE_SR(isfinite_sr, functor) \ + template \ + void isfinite_sr( \ + const Context& ctx, const SelectedRows& x, SelectedRows* out) { \ + IsfiniteSRImpl(ctx, x, out); \ + } + +DEFINE_ISFINITE_SR(IsinfSR, funcs::InfinityV2Functor) +DEFINE_ISFINITE_SR(IsnanSR, funcs::NANV2Functor) +DEFINE_ISFINITE_SR(IsfiniteSR, funcs::IsfiniteV2Functor) +#undef DEFINE_ISFINITE_SR + +} // namespace phi diff --git a/paddle/phi/ops/compat/isfinite_sig.cc b/paddle/phi/ops/compat/isfinite_sig.cc new file mode 100644 index 00000000000..218b4c2f962 --- /dev/null +++ b/paddle/phi/ops/compat/isfinite_sig.cc @@ -0,0 +1,19 @@ +// 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/core/compat/op_utils.h" + +PD_REGISTER_BASE_KERNEL_NAME(isinf_v2, isinf); +PD_REGISTER_BASE_KERNEL_NAME(isnan_v2, isnan); +PD_REGISTER_BASE_KERNEL_NAME(isfinite_v2, isfinite); -- GitLab