From 839d8bb3244053eec87aebb33b786f33278179cf Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Sun, 7 Aug 2022 10:48:33 -0500 Subject: [PATCH] Fix kernels header pos error (#44902) * fix header pos error * fix namespace error --- paddle/phi/kernels/affine_grid_grad_kernel.h | 1 - paddle/phi/kernels/affine_grid_kernel.h | 1 - .../kernels/cpu/affine_grid_grad_kernel.cc | 2 ++ paddle/phi/kernels/cpu/affine_grid_kernel.cc | 2 ++ .../kernels/cpu/fill_diagonal_grad_kernel.cc | 3 +- .../phi/kernels/cpu/fill_diagonal_kernel.cc | 3 +- .../phi/kernels/fill_diagonal_grad_kernel.h | 2 -- paddle/phi/kernels/fill_diagonal_kernel.h | 3 -- .../affine_grid_utils.h} | 0 paddle/phi/kernels/funcs/common_shape.h | 11 +++++++ .../kernels/gpu/affine_grid_grad_kernel.cu | 2 ++ paddle/phi/kernels/gpu/affine_grid_kernel.cu | 2 ++ .../kernels/gpu/fill_diagonal_grad_kernel.cu | 3 +- .../phi/kernels/gpu/fill_diagonal_kernel.cu | 3 +- .../kernels/impl/fill_diagonal_kernel_impl.h | 32 ------------------- 15 files changed, 27 insertions(+), 43 deletions(-) rename paddle/phi/kernels/{affine_grid_impl.h => funcs/affine_grid_utils.h} (100%) delete mode 100644 paddle/phi/kernels/impl/fill_diagonal_kernel_impl.h diff --git a/paddle/phi/kernels/affine_grid_grad_kernel.h b/paddle/phi/kernels/affine_grid_grad_kernel.h index 061b763ed33..df2dfca10b0 100644 --- a/paddle/phi/kernels/affine_grid_grad_kernel.h +++ b/paddle/phi/kernels/affine_grid_grad_kernel.h @@ -15,7 +15,6 @@ #pragma once #include "paddle/phi/common/int_array.h" -#include "paddle/phi/kernels/affine_grid_impl.h" namespace phi { diff --git a/paddle/phi/kernels/affine_grid_kernel.h b/paddle/phi/kernels/affine_grid_kernel.h index febd5be0a36..57ac0007b1c 100644 --- a/paddle/phi/kernels/affine_grid_kernel.h +++ b/paddle/phi/kernels/affine_grid_kernel.h @@ -15,7 +15,6 @@ #pragma once #include "paddle/phi/common/int_array.h" -#include "paddle/phi/kernels/affine_grid_impl.h" namespace phi { diff --git a/paddle/phi/kernels/cpu/affine_grid_grad_kernel.cc b/paddle/phi/kernels/cpu/affine_grid_grad_kernel.cc index 778a0adc9ca..7bea3ff476b 100644 --- a/paddle/phi/kernels/cpu/affine_grid_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/affine_grid_grad_kernel.cc @@ -13,9 +13,11 @@ // limitations under the License. #include "paddle/phi/kernels/affine_grid_grad_kernel.h" + #include "paddle/phi/backends/cpu/cpu_context.h" #include "paddle/phi/common/int_array.h" #include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/affine_grid_utils.h" namespace phi { diff --git a/paddle/phi/kernels/cpu/affine_grid_kernel.cc b/paddle/phi/kernels/cpu/affine_grid_kernel.cc index 6584a8eb263..712c2a19277 100644 --- a/paddle/phi/kernels/cpu/affine_grid_kernel.cc +++ b/paddle/phi/kernels/cpu/affine_grid_kernel.cc @@ -13,9 +13,11 @@ // limitations under the License. #include "paddle/phi/kernels/affine_grid_kernel.h" + #include "paddle/phi/backends/cpu/cpu_context.h" #include "paddle/phi/common/int_array.h" #include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/affine_grid_utils.h" namespace phi { diff --git a/paddle/phi/kernels/cpu/fill_diagonal_grad_kernel.cc b/paddle/phi/kernels/cpu/fill_diagonal_grad_kernel.cc index 1291a677bf9..0fe9c50dc15 100644 --- a/paddle/phi/kernels/cpu/fill_diagonal_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/fill_diagonal_grad_kernel.cc @@ -15,6 +15,7 @@ #include "paddle/phi/kernels/fill_diagonal_grad_kernel.h" #include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/common_shape.h" namespace phi { @@ -30,7 +31,7 @@ void FillDiagonalGradKernel(const Context& ctx, phi::Copy(ctx, out_grad, ctx.GetPlace(), false, x_grad); auto dx_dims = x_grad->dims(); - auto strides = CalStride(dx_dims); + auto strides = funcs::CalStride(dx_dims); auto size = x_grad->numel(); auto wrapsize = std::min(size, dx_dims[1] * dx_dims[1]); diff --git a/paddle/phi/kernels/cpu/fill_diagonal_kernel.cc b/paddle/phi/kernels/cpu/fill_diagonal_kernel.cc index 232f2444cf4..c5888f5d30e 100644 --- a/paddle/phi/kernels/cpu/fill_diagonal_kernel.cc +++ b/paddle/phi/kernels/cpu/fill_diagonal_kernel.cc @@ -16,6 +16,7 @@ #include "paddle/phi/core/kernel_registry.h" #include "paddle/phi/core/tensor_utils.h" +#include "paddle/phi/kernels/funcs/common_shape.h" namespace phi { @@ -32,7 +33,7 @@ void FillDiagonalKernel(const Context& ctx, phi::Copy(ctx, x, ctx.GetPlace(), false, out); auto out_dims = out->dims(); - auto strides = CalStride(out_dims); + auto strides = funcs::CalStride(out_dims); auto size = out->numel(); // The wrap mode supported only the dims equels to 2; In wrap mode, the diff --git a/paddle/phi/kernels/fill_diagonal_grad_kernel.h b/paddle/phi/kernels/fill_diagonal_grad_kernel.h index 23f2ae577c2..e1d55364945 100644 --- a/paddle/phi/kernels/fill_diagonal_grad_kernel.h +++ b/paddle/phi/kernels/fill_diagonal_grad_kernel.h @@ -16,8 +16,6 @@ #include "paddle/phi/core/dense_tensor.h" -#include "paddle/phi/kernels/impl/fill_diagonal_kernel_impl.h" - namespace phi { template diff --git a/paddle/phi/kernels/fill_diagonal_kernel.h b/paddle/phi/kernels/fill_diagonal_kernel.h index ecd3ffbe5cc..6d4dc78e824 100644 --- a/paddle/phi/kernels/fill_diagonal_kernel.h +++ b/paddle/phi/kernels/fill_diagonal_kernel.h @@ -15,9 +15,6 @@ #pragma once #include "paddle/phi/core/dense_tensor.h" - -#include "paddle/phi/kernels/impl/fill_diagonal_kernel_impl.h" - namespace phi { template diff --git a/paddle/phi/kernels/affine_grid_impl.h b/paddle/phi/kernels/funcs/affine_grid_utils.h similarity index 100% rename from paddle/phi/kernels/affine_grid_impl.h rename to paddle/phi/kernels/funcs/affine_grid_utils.h diff --git a/paddle/phi/kernels/funcs/common_shape.h b/paddle/phi/kernels/funcs/common_shape.h index 139341536de..2daf8ab0bd9 100644 --- a/paddle/phi/kernels/funcs/common_shape.h +++ b/paddle/phi/kernels/funcs/common_shape.h @@ -231,5 +231,16 @@ inline DDim GetOutputDims(const DDim &s_dims, const DDim &l_dims) { return phi::make_ddim(shapes); } +inline int64_t CalStride(phi::DDim dim) { + int rank = dim.size(); + int64_t dimsum = 1; + int64_t strides = 0; + for (int i = rank - 1; i >= 0; i--) { + strides += dimsum; + dimsum *= dim[i]; + } + return strides; +} + } // namespace funcs } // namespace phi diff --git a/paddle/phi/kernels/gpu/affine_grid_grad_kernel.cu b/paddle/phi/kernels/gpu/affine_grid_grad_kernel.cu index baa2616267d..b2cb0f2ad73 100644 --- a/paddle/phi/kernels/gpu/affine_grid_grad_kernel.cu +++ b/paddle/phi/kernels/gpu/affine_grid_grad_kernel.cu @@ -15,6 +15,7 @@ #pragma once #include "paddle/phi/kernels/affine_grid_grad_kernel.h" + #include "paddle/fluid/platform/device/gpu/gpu_device_function.h" #include "paddle/fluid/platform/device/gpu/gpu_info.h" #include "paddle/fluid/platform/device/gpu/gpu_primitives.h" @@ -22,6 +23,7 @@ #include "paddle/phi/backends/gpu/gpu_context.h" #include "paddle/phi/common/int_array.h" #include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/affine_grid_utils.h" namespace phi { diff --git a/paddle/phi/kernels/gpu/affine_grid_kernel.cu b/paddle/phi/kernels/gpu/affine_grid_kernel.cu index ad5072f4bac..4e5c326be7b 100644 --- a/paddle/phi/kernels/gpu/affine_grid_kernel.cu +++ b/paddle/phi/kernels/gpu/affine_grid_kernel.cu @@ -15,6 +15,7 @@ #pragma once #include "paddle/phi/kernels/affine_grid_kernel.h" + #include "paddle/fluid/platform/device/gpu/gpu_device_function.h" #include "paddle/fluid/platform/device/gpu/gpu_info.h" #include "paddle/fluid/platform/device/gpu/gpu_primitives.h" @@ -22,6 +23,7 @@ #include "paddle/phi/backends/gpu/gpu_context.h" #include "paddle/phi/common/int_array.h" #include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/affine_grid_utils.h" namespace phi { diff --git a/paddle/phi/kernels/gpu/fill_diagonal_grad_kernel.cu b/paddle/phi/kernels/gpu/fill_diagonal_grad_kernel.cu index 8884dfae178..0a1069cf3a9 100644 --- a/paddle/phi/kernels/gpu/fill_diagonal_grad_kernel.cu +++ b/paddle/phi/kernels/gpu/fill_diagonal_grad_kernel.cu @@ -18,6 +18,7 @@ #include #include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/common_shape.h" namespace phi { @@ -60,7 +61,7 @@ void FillDiagonalGradKernel(const Context& ctx, auto size = x_grad->numel(); auto out_dims = x_grad->dims(); - auto strides = CalStride(out_dims); + auto strides = funcs::CalStride(out_dims); auto wrapsize = std::min(size, out_dims[1] * out_dims[1]); // The wrap mode supported only the dims equels to 2; In wrap mode, the diff --git a/paddle/phi/kernels/gpu/fill_diagonal_kernel.cu b/paddle/phi/kernels/gpu/fill_diagonal_kernel.cu index 3116842002a..1d342abc317 100644 --- a/paddle/phi/kernels/gpu/fill_diagonal_kernel.cu +++ b/paddle/phi/kernels/gpu/fill_diagonal_kernel.cu @@ -19,6 +19,7 @@ #include "paddle/fluid/framework/convert_utils.h" #include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/common_shape.h" namespace phi { @@ -63,7 +64,7 @@ void FillDiagonalKernel(const Context& ctx, auto size = out->numel(); auto out_dims = out->dims(); - auto strides = CalStride(out_dims); + auto strides = funcs::CalStride(out_dims); // The wrap mode supported only the dims equels to 2; In wrap mode, the // value will be filled in cycles diff --git a/paddle/phi/kernels/impl/fill_diagonal_kernel_impl.h b/paddle/phi/kernels/impl/fill_diagonal_kernel_impl.h deleted file mode 100644 index 65383176a0f..00000000000 --- a/paddle/phi/kernels/impl/fill_diagonal_kernel_impl.h +++ /dev/null @@ -1,32 +0,0 @@ -// 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 { - -inline int64_t CalStride(phi::DDim dim) { - int rank = dim.size(); - int64_t dimsum = 1; - int64_t strides = 0; - for (int i = rank - 1; i >= 0; i--) { - strides += dimsum; - dimsum *= dim[i]; - } - return strides; -} - -} // namespace phi -- GitLab