From 2bb5aae8fd6a521183565ade69dfc72ec8a83ce0 Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Mon, 21 Feb 2022 14:29:35 +0800 Subject: [PATCH] [pten]rm reduce_sum and reduce_mean raw kernel (#39484) * rm reduce_sum raw kernel * remove reduce_mean kernel * remove reduce_mean kernel * reduce support int and int64_t * mean support int and int64_t type --- .../performance_tests/benchmark_eager_cpu.cc | 2 +- .../performance_tests/benchmark_eager_cuda.cc | 2 +- .../performance_tests/benchmark_fluid_cpu.cc | 2 +- .../performance_tests/benchmark_fluid_cuda.cc | 2 +- .../new_executor/standalone_executor_test.cc | 4 +-- paddle/fluid/imperative/tests/test_tracer.cc | 2 +- .../operators/reduce_ops/reduce_mean_op.cc | 7 ----- .../operators/reduce_ops/reduce_mean_op.cu | 27 ----------------- .../operators/reduce_ops/reduce_sum_op.cc | 21 -------------- .../operators/reduce_ops/reduce_sum_op.cu | 29 ------------------- .../reduce_ops/unity_build_rule.cmake | 1 - paddle/phi/kernels/gpu/math_kernel.cu | 4 ++- paddle/phi/kernels/math_kernel.cc | 2 ++ 13 files changed, 12 insertions(+), 93 deletions(-) delete mode 100644 paddle/fluid/operators/reduce_ops/reduce_mean_op.cu delete mode 100644 paddle/fluid/operators/reduce_ops/reduce_sum_op.cu diff --git a/paddle/fluid/eager/tests/performance_tests/benchmark_eager_cpu.cc b/paddle/fluid/eager/tests/performance_tests/benchmark_eager_cpu.cc index b72b7cb8753..6c4bf9a4f17 100644 --- a/paddle/fluid/eager/tests/performance_tests/benchmark_eager_cpu.cc +++ b/paddle/fluid/eager/tests/performance_tests/benchmark_eager_cpu.cc @@ -176,4 +176,4 @@ TEST(Benchmark, EagerIntermediateMLPCPU) { USE_OP_ITSELF(scale); USE_OP_ITSELF(elementwise_add); USE_OP_ITSELF(matmul_v2); -USE_OP(reduce_sum); +USE_OP_ITSELF(reduce_sum); diff --git a/paddle/fluid/eager/tests/performance_tests/benchmark_eager_cuda.cc b/paddle/fluid/eager/tests/performance_tests/benchmark_eager_cuda.cc index 701a9b2cba1..14e7ce8cfcf 100644 --- a/paddle/fluid/eager/tests/performance_tests/benchmark_eager_cuda.cc +++ b/paddle/fluid/eager/tests/performance_tests/benchmark_eager_cuda.cc @@ -185,7 +185,7 @@ TEST(Benchmark, EagerIntermediateMLPCUDA) { USE_OP_ITSELF(scale); USE_OP_ITSELF(matmul_v2); -USE_OP(reduce_sum); +USE_OP_ITSELF(reduce_sum); USE_OP(reduce_sum_grad); USE_OP_ITSELF(elementwise_add); diff --git a/paddle/fluid/eager/tests/performance_tests/benchmark_fluid_cpu.cc b/paddle/fluid/eager/tests/performance_tests/benchmark_fluid_cpu.cc index bea80809a3b..3292de93636 100644 --- a/paddle/fluid/eager/tests/performance_tests/benchmark_fluid_cpu.cc +++ b/paddle/fluid/eager/tests/performance_tests/benchmark_fluid_cpu.cc @@ -214,4 +214,4 @@ TEST(Benchmark, FluidMLPCPU) { USE_OP_ITSELF(scale); USE_OP_ITSELF(elementwise_add); USE_OP_ITSELF(matmul_v2); -USE_OP(reduce_sum); +USE_OP_ITSELF(reduce_sum); diff --git a/paddle/fluid/eager/tests/performance_tests/benchmark_fluid_cuda.cc b/paddle/fluid/eager/tests/performance_tests/benchmark_fluid_cuda.cc index 86c1ad7e23a..e9b7d10070d 100644 --- a/paddle/fluid/eager/tests/performance_tests/benchmark_fluid_cuda.cc +++ b/paddle/fluid/eager/tests/performance_tests/benchmark_fluid_cuda.cc @@ -247,7 +247,7 @@ TEST(Benchmark, FluidMLPCUDA) { USE_OP_ITSELF(scale); USE_OP_ITSELF(matmul_v2); -USE_OP(reduce_sum); +USE_OP_ITSELF(reduce_sum); USE_OP(reduce_sum_grad); USE_OP_ITSELF(elementwise_add); diff --git a/paddle/fluid/framework/new_executor/standalone_executor_test.cc b/paddle/fluid/framework/new_executor/standalone_executor_test.cc index c1d449d3020..2c3359ffa8e 100644 --- a/paddle/fluid/framework/new_executor/standalone_executor_test.cc +++ b/paddle/fluid/framework/new_executor/standalone_executor_test.cc @@ -35,8 +35,8 @@ USE_OP(sigmoid); USE_OP(tanh); USE_OP(elementwise_mul); USE_OP(softmax_with_cross_entropy); -USE_OP(reduce_mean); -USE_OP(reduce_sum); +USE_OP_ITSELF(reduce_mean); +USE_OP_ITSELF(reduce_sum); USE_OP(reduce_sum_grad); USE_OP(reduce_mean_grad); USE_OP_ITSELF(reshape2_grad); diff --git a/paddle/fluid/imperative/tests/test_tracer.cc b/paddle/fluid/imperative/tests/test_tracer.cc index afe1f92ca03..d05036f7a12 100644 --- a/paddle/fluid/imperative/tests/test_tracer.cc +++ b/paddle/fluid/imperative/tests/test_tracer.cc @@ -590,6 +590,6 @@ TEST(test_tracer, eager_tracer) { USE_OP(mul); USE_OP(mul_grad); -USE_OP(reduce_sum); +USE_OP_ITSELF(reduce_sum); USE_OP(reduce_sum_grad); USE_OP_ITSELF(elementwise_add); diff --git a/paddle/fluid/operators/reduce_ops/reduce_mean_op.cc b/paddle/fluid/operators/reduce_ops/reduce_mean_op.cc index c8d568c8c2c..e80df5f95bb 100644 --- a/paddle/fluid/operators/reduce_ops/reduce_mean_op.cc +++ b/paddle/fluid/operators/reduce_ops/reduce_mean_op.cc @@ -99,13 +99,6 @@ REGISTER_OPERATOR(reduce_mean_grad, ops::ReduceGradOp, ops::ReduceMeanDoubleGradDescMaker, ops::ReduceMeanDoubleGradOpBaseMaker, ops::ReduceMeanGradNoNeedBufferVarInferer); -REGISTER_OP_CPU_KERNEL(reduce_mean, - ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel); template using CPUReduceMeanGradKernel = diff --git a/paddle/fluid/operators/reduce_ops/reduce_mean_op.cu b/paddle/fluid/operators/reduce_ops/reduce_mean_op.cu deleted file mode 100644 index 30a699e979e..00000000000 --- a/paddle/fluid/operators/reduce_ops/reduce_mean_op.cu +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2018 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 -#include "paddle/fluid/operators/reduce_ops/reduce_mean_op.h" -#include "paddle/fluid/operators/reduce_ops/reduce_op.h" - -REGISTER_OP_CUDA_KERNEL( - reduce_mean, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel); diff --git a/paddle/fluid/operators/reduce_ops/reduce_sum_op.cc b/paddle/fluid/operators/reduce_ops/reduce_sum_op.cc index cfafc117399..bdab14a18a0 100644 --- a/paddle/fluid/operators/reduce_ops/reduce_sum_op.cc +++ b/paddle/fluid/operators/reduce_ops/reduce_sum_op.cc @@ -107,27 +107,6 @@ REGISTER_OPERATOR(reduce_sum_grad, ops::ReduceGradOp, ops::ReduceSumDoubleOpGradMaker, ops::ReduceSumGradNoNeedBufferVarInferer); -REGISTER_OP_CPU_KERNEL( - reduce_sum, ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel, ops::SumFunctor>, - ops::ReduceKernel, - - ops::SumFunctor>); - template using CPUReduceSumGradKernel = ops::ReduceSumGradKernel, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel, - ops::ReduceCudaKernel, kps::AddFunctor, - kps::IdentityFunctor>, - ops::ReduceCudaKernel, kps::AddFunctor, - kps::IdentityFunctor>); diff --git a/paddle/fluid/operators/reduce_ops/unity_build_rule.cmake b/paddle/fluid/operators/reduce_ops/unity_build_rule.cmake index 74781ef6f02..c4f32a8d257 100644 --- a/paddle/fluid/operators/reduce_ops/unity_build_rule.cmake +++ b/paddle/fluid/operators/reduce_ops/unity_build_rule.cmake @@ -21,5 +21,4 @@ register_unity_group(cu register_unity_group(cu frobenius_norm_op.cu) register_unity_group(cu logsumexp_op.cu) register_unity_group(cu reduce_max_op.cu) -register_unity_group(cu reduce_mean_op.cu) register_unity_group(cu reduce_min_op.cu) diff --git a/paddle/phi/kernels/gpu/math_kernel.cu b/paddle/phi/kernels/gpu/math_kernel.cu index 2ae40bd4b19..c3605ce655f 100644 --- a/paddle/phi/kernels/gpu/math_kernel.cu +++ b/paddle/phi/kernels/gpu/math_kernel.cu @@ -165,4 +165,6 @@ PT_REGISTER_KERNEL(mean_raw, float, double, bool, - float16) {} + float16, + int, + int64_t) {} diff --git a/paddle/phi/kernels/math_kernel.cc b/paddle/phi/kernels/math_kernel.cc index 7fb6cc0ba9c..e1e3679ea8b 100644 --- a/paddle/phi/kernels/math_kernel.cc +++ b/paddle/phi/kernels/math_kernel.cc @@ -152,6 +152,8 @@ PT_REGISTER_KERNEL(mean, float, double, bool, + int, + int64_t, phi::dtype::float16) {} PT_REGISTER_KERNEL(sum, GPU, -- GitLab