diff --git a/paddle/phi/kernels/CMakeLists.txt b/paddle/phi/kernels/CMakeLists.txt index 8589785a97e853f38044bceb076f6d3ffda4a0c7..d7f9849ad94e9e092657d12283152fafe35b7900 100644 --- a/paddle/phi/kernels/CMakeLists.txt +++ b/paddle/phi/kernels/CMakeLists.txt @@ -166,6 +166,7 @@ if(WITH_MKLDNN) "cpu/*.cc" "legacy/*.cc" "legacy/cpu/*.cc" + "legacy/onednn/*.cc" "selected_rows/*.cc" "selected_rows/cpu/*.cc" "sparse/*.cc" diff --git a/paddle/phi/kernels/cpu/reduce_max_kernel.cc b/paddle/phi/kernels/cpu/reduce_max_kernel.cc index d71476a0f920d2424f06d024c085db1e08d333ae..080db4814a1ff72a4826e48d43c913c1173686fe 100644 --- a/paddle/phi/kernels/cpu/reduce_max_kernel.cc +++ b/paddle/phi/kernels/cpu/reduce_max_kernel.cc @@ -22,13 +22,12 @@ namespace phi { template -void MaxRawKernel(const Context& dev_ctx, - const DenseTensor& x, - const IntArray& dims, - bool keep_dim, - bool reduce_all, - DenseTensor* out) { - reduce_all = recompute_reduce_all(x, dims, reduce_all); +void MaxKernel(const Context& dev_ctx, + const DenseTensor& x, + const IntArray& dims, + bool keep_dim, + DenseTensor* out) { + bool reduce_all = recompute_reduce_all(x, dims); auto out_dtype = x.dtype(); phi::Reduce( dev_ctx, x, reduce_all, dims.GetData(), keep_dim, out_dtype, out); @@ -37,4 +36,4 @@ void MaxRawKernel(const Context& dev_ctx, } // namespace phi PD_REGISTER_KERNEL( - max_raw, CPU, ALL_LAYOUT, phi::MaxRawKernel, float, double, int, int64_t) {} + max, CPU, ALL_LAYOUT, phi::MaxKernel, float, double, int, int64_t) {} diff --git a/paddle/phi/kernels/kps/reduce_max_kernel.cu b/paddle/phi/kernels/kps/reduce_max_kernel.cu index a03035dcf1932d0d516bf435d5ee49a79a5cb7fd..bfb9fe50daad66b6e82a7dd8541d2d6447f6ec06 100644 --- a/paddle/phi/kernels/kps/reduce_max_kernel.cu +++ b/paddle/phi/kernels/kps/reduce_max_kernel.cu @@ -19,13 +19,12 @@ namespace phi { template -void MaxRawKernel(const Context& dev_ctx, - const DenseTensor& x, - const IntArray& dims, - bool keep_dim, - bool reduce_all, - DenseTensor* out) { - reduce_all = recompute_reduce_all(x, dims, reduce_all); +void MaxKernel(const Context& dev_ctx, + const DenseTensor& x, + const IntArray& dims, + bool keep_dim, + DenseTensor* out) { + bool reduce_all = recompute_reduce_all(x, dims); auto out_dtype = x.dtype(); phi::Reduce( dev_ctx, x, reduce_all, dims.GetData(), keep_dim, out_dtype, out); @@ -34,12 +33,12 @@ void MaxRawKernel(const Context& dev_ctx, } // namespace phi #ifdef PADDLE_WITH_XPU_KP -PD_REGISTER_KERNEL(max_raw, KPS, ALL_LAYOUT, phi::MaxRawKernel, float) {} +PD_REGISTER_KERNEL(max, KPS, ALL_LAYOUT, phi::MaxKernel, float) {} #else -PD_REGISTER_KERNEL(max_raw, +PD_REGISTER_KERNEL(max, KPS, ALL_LAYOUT, - phi::MaxRawKernel, + phi::MaxKernel, float, double, int, diff --git a/paddle/phi/kernels/legacy/cpu/reduce_max_kernel.cc b/paddle/phi/kernels/legacy/cpu/reduce_max_kernel.cc new file mode 100644 index 0000000000000000000000000000000000000000..12b5fbe7a97fd18125d4119ba36de08a6a216d9a --- /dev/null +++ b/paddle/phi/kernels/legacy/cpu/reduce_max_kernel.cc @@ -0,0 +1,40 @@ +// Copyright (c) 2023 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/reduce_max_kernel.h" + +#include "paddle/phi/backends/cpu/cpu_context.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/cpu/reduce.h" +#include "paddle/phi/kernels/funcs/reduce_functor.h" + +namespace phi { + +template +void MaxRawKernel(const Context& dev_ctx, + const DenseTensor& x, + const IntArray& dims, + bool keep_dim, + bool reduce_all, + DenseTensor* out) { + reduce_all = recompute_reduce_all(x, dims, reduce_all); + auto out_dtype = x.dtype(); + phi::Reduce( + dev_ctx, x, reduce_all, dims.GetData(), keep_dim, out_dtype, out); +} + +} // namespace phi + +PD_REGISTER_KERNEL( + max_raw, CPU, ALL_LAYOUT, phi::MaxRawKernel, float, double, int, int64_t) {} diff --git a/paddle/phi/kernels/legacy/kps/reduce_max_kernel.cu b/paddle/phi/kernels/legacy/kps/reduce_max_kernel.cu new file mode 100644 index 0000000000000000000000000000000000000000..8d069a5f5911c0464dab9da17ced3cb1022ecce3 --- /dev/null +++ b/paddle/phi/kernels/legacy/kps/reduce_max_kernel.cu @@ -0,0 +1,49 @@ +// Copyright (c) 2023 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/reduce_max_kernel.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/gpu/reduce.h" + +namespace phi { + +template +void MaxRawKernel(const Context& dev_ctx, + const DenseTensor& x, + const IntArray& dims, + bool keep_dim, + bool reduce_all, + DenseTensor* out) { + reduce_all = recompute_reduce_all(x, dims, reduce_all); + auto out_dtype = x.dtype(); + phi::Reduce( + dev_ctx, x, reduce_all, dims.GetData(), keep_dim, out_dtype, out); +} + +} // namespace phi + +#ifdef PADDLE_WITH_XPU_KP +PD_REGISTER_KERNEL(max_raw, KPS, ALL_LAYOUT, phi::MaxRawKernel, float) {} +#else +PD_REGISTER_KERNEL(max_raw, + KPS, + ALL_LAYOUT, + phi::MaxRawKernel, + float, + double, + int, + int64_t, + phi::dtype::float16, + phi::dtype::bfloat16) {} +#endif diff --git a/paddle/phi/kernels/legacy/onednn/reduce_max_kernel.cc b/paddle/phi/kernels/legacy/onednn/reduce_max_kernel.cc new file mode 100644 index 0000000000000000000000000000000000000000..ff9e04e9e970573105f5987657c2643eb5b8f8e9 --- /dev/null +++ b/paddle/phi/kernels/legacy/onednn/reduce_max_kernel.cc @@ -0,0 +1,39 @@ +/* Copyright (c) 2023 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/reduce_max_kernel.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/onednn/reduce_kernel_impl.h" + +namespace phi { +template +void MaxRawKernel(const Context& dev_ctx, + const DenseTensor& x, + const IntArray& dims, + bool keep_dim, + bool reduce_all, + DenseTensor* out) { + reduce_all = recompute_reduce_all(x, dims, reduce_all); + ReduceKernel(dev_ctx, + x, + dims, + keep_dim, + reduce_all, + out, + dnnl::algorithm::reduction_max); +} +} // namespace phi + +PD_REGISTER_KERNEL( + max_raw, OneDNN, ONEDNN, phi::MaxRawKernel, float, phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/legacy/reduce_max_kernel.h b/paddle/phi/kernels/legacy/reduce_max_kernel.h new file mode 100644 index 0000000000000000000000000000000000000000..ce1333d7fbd18badcd454c4b636450c6036ad514 --- /dev/null +++ b/paddle/phi/kernels/legacy/reduce_max_kernel.h @@ -0,0 +1,29 @@ +// Copyright (c) 2023 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/common/int_array.h" +#include "paddle/phi/core/dense_tensor.h" + +namespace phi { +template +void MaxRawKernel(const Context& dev_ctx, + const DenseTensor& x, + const IntArray& dims, + bool keep_dim, + bool reduce_all, + DenseTensor* out); + +} // namespace phi diff --git a/paddle/phi/kernels/legacy/xpu/reduce_max_kernel.cc b/paddle/phi/kernels/legacy/xpu/reduce_max_kernel.cc new file mode 100644 index 0000000000000000000000000000000000000000..cb9ff8f6bdb8028c989fec7a04f63176a6ba2bbc --- /dev/null +++ b/paddle/phi/kernels/legacy/xpu/reduce_max_kernel.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2023 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/reduce_max_kernel.h" + +#include "paddle/phi/backends/xpu/enforce_xpu.h" +#include "paddle/phi/backends/xpu/xpu_context.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/xpu/reduce.h" + +namespace phi { + +template +void MaxRawKernel(const Context& dev_ctx, + const DenseTensor& x, + const IntArray& dims, + bool keep_dim, + bool reduce_all, + DenseTensor* out) { + reduce_all = recompute_reduce_all(x, dims, reduce_all); + using XPUType = typename XPUTypeTrait::Type; + auto f = [](xpu::Context* ctx, + const T* x, + T* y, + const std::vector& xdims, + const std::vector& reduce_dims) { + return xpu::reduce_max(ctx, + reinterpret_cast(x), + reinterpret_cast(y), + xdims, + reduce_dims); + }; + + int r = XPUReduce( + dev_ctx, x, dims.GetData(), keep_dim, reduce_all, out, f); + PADDLE_ENFORCE_XDNN_SUCCESS(r, "reduce_max"); +} + +} // namespace phi + +PD_REGISTER_KERNEL(max_raw, XPU, ALL_LAYOUT, phi::MaxRawKernel, float, int) {} diff --git a/paddle/phi/kernels/onednn/reduce_max_kernel.cc b/paddle/phi/kernels/onednn/reduce_max_kernel.cc index 3ece76367598a68a01e47fad0a0df725972c9b31..b5c8499a55daa9524bbee4400becf757f2c65447 100644 --- a/paddle/phi/kernels/onednn/reduce_max_kernel.cc +++ b/paddle/phi/kernels/onednn/reduce_max_kernel.cc @@ -18,13 +18,12 @@ limitations under the License. */ namespace phi { template -void MaxRawKernel(const Context& dev_ctx, - const DenseTensor& x, - const IntArray& dims, - bool keep_dim, - bool reduce_all, - DenseTensor* out) { - reduce_all = recompute_reduce_all(x, dims, reduce_all); +void MaxKernel(const Context& dev_ctx, + const DenseTensor& x, + const IntArray& dims, + bool keep_dim, + DenseTensor* out) { + bool reduce_all = recompute_reduce_all(x, dims); ReduceKernel(dev_ctx, x, dims, @@ -36,4 +35,4 @@ void MaxRawKernel(const Context& dev_ctx, } // namespace phi PD_REGISTER_KERNEL( - max_raw, OneDNN, ONEDNN, phi::MaxRawKernel, float, phi::dtype::bfloat16) {} + max, OneDNN, ONEDNN, phi::MaxKernel, float, phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/reduce_max_kernel.cc b/paddle/phi/kernels/reduce_max_kernel.cc deleted file mode 100644 index 8f61ec6623b1ca6620ebf7a2536aeb55424a5c05..0000000000000000000000000000000000000000 --- a/paddle/phi/kernels/reduce_max_kernel.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2023 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/reduce_max_kernel.h" - -#include "paddle/phi/backends/all_context.h" -#include "paddle/phi/core/kernel_registry.h" - -namespace phi { - -template -void MaxKernel(const Context& dev_ctx, - const DenseTensor& x, - const IntArray& dims, - bool keep_dim, - DenseTensor* out) { - bool reduce_all = recompute_reduce_all(x, dims); - MaxRawKernel(dev_ctx, x, dims, keep_dim, reduce_all, out); -} - -} // namespace phi - -PD_REGISTER_KERNEL( - max, CPU, ALL_LAYOUT, phi::MaxKernel, float, double, int, int64_t) {} - -#if defined(PADDLE_WITH_CUDA) -PD_REGISTER_KERNEL(max, - GPU, - ALL_LAYOUT, - phi::MaxKernel, - float, - double, - int, - int64_t, - phi::dtype::float16, - phi::dtype::bfloat16) {} -#endif - -#if defined(PADDLE_WITH_HIP) -PD_REGISTER_KERNEL( - max, GPU, ALL_LAYOUT, phi::MaxKernel, float, double, int, int64_t) {} -#endif - -#if defined(PADDLE_WITH_XPU_KP) && !defined(PADDLE_WITH_XPU) -PD_REGISTER_KERNEL(max, KPS, ALL_LAYOUT, phi::MaxKernel, float) {} -#endif - -#if defined(PADDLE_WITH_MKLDNN) -PD_REGISTER_KERNEL( - max, OneDNN, ONEDNN, phi::MaxKernel, float, phi::dtype::bfloat16) {} -#endif - -#if defined(PADDLE_WITH_XPU) -PD_REGISTER_KERNEL(max, XPU, ALL_LAYOUT, phi::MaxKernel, float, int) {} -#endif diff --git a/paddle/phi/kernels/reduce_max_kernel.h b/paddle/phi/kernels/reduce_max_kernel.h index 2af22a2ddde3d00c2bc4c67f34b008b2259ee167..3709600c1cb8ac8c696840541b8ebb5e78fa6b25 100644 --- a/paddle/phi/kernels/reduce_max_kernel.h +++ b/paddle/phi/kernels/reduce_max_kernel.h @@ -18,14 +18,6 @@ #include "paddle/phi/core/dense_tensor.h" namespace phi { -template -void MaxRawKernel(const Context& dev_ctx, - const DenseTensor& x, - const IntArray& dims, - bool keep_dim, - bool reduce_all, - DenseTensor* out); - template void MaxKernel(const Context& dev_ctx, const DenseTensor& x, diff --git a/paddle/phi/kernels/xpu/reduce_max_kernel.cc b/paddle/phi/kernels/xpu/reduce_max_kernel.cc index cb9ff8f6bdb8028c989fec7a04f63176a6ba2bbc..afe7f4a731469b4783145d2edd6e9bdbc979c241 100644 --- a/paddle/phi/kernels/xpu/reduce_max_kernel.cc +++ b/paddle/phi/kernels/xpu/reduce_max_kernel.cc @@ -22,13 +22,12 @@ namespace phi { template -void MaxRawKernel(const Context& dev_ctx, - const DenseTensor& x, - const IntArray& dims, - bool keep_dim, - bool reduce_all, - DenseTensor* out) { - reduce_all = recompute_reduce_all(x, dims, reduce_all); +void MaxKernel(const Context& dev_ctx, + const DenseTensor& x, + const IntArray& dims, + bool keep_dim, + DenseTensor* out) { + bool reduce_all = recompute_reduce_all(x, dims); using XPUType = typename XPUTypeTrait::Type; auto f = [](xpu::Context* ctx, const T* x, @@ -49,4 +48,4 @@ void MaxRawKernel(const Context& dev_ctx, } // namespace phi -PD_REGISTER_KERNEL(max_raw, XPU, ALL_LAYOUT, phi::MaxRawKernel, float, int) {} +PD_REGISTER_KERNEL(max, XPU, ALL_LAYOUT, phi::MaxKernel, float, int) {} diff --git a/test/cpp/phi/kernels/test_fused_adam_kernel.cc b/test/cpp/phi/kernels/test_fused_adam_kernel.cc index 1a8432e45318be3987648c8dc6c86c920e13d222..5202dc3a9468b81775706639ac118b2d9bb8f339 100644 --- a/test/cpp/phi/kernels/test_fused_adam_kernel.cc +++ b/test/cpp/phi/kernels/test_fused_adam_kernel.cc @@ -34,7 +34,7 @@ #include "paddle/phi/kernels/full_kernel.h" #include "paddle/phi/kernels/fused_adam_kernel.h" #include "paddle/phi/kernels/gaussian_kernel.h" -#include "paddle/phi/kernels/reduce_max_kernel.h" +#include "paddle/phi/kernels/legacy/reduce_max_kernel.h" namespace phi {