diff --git a/paddle/phi/kernels/affine_grid_grad_kernel.h b/paddle/phi/kernels/affine_grid_grad_kernel.h index 061b763ed33f0ef422f8175f0daa7da6a3100777..df2dfca10b0b33d7b4a183ccaf5fc8c26ef160ed 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 febd5be0a36617c64fdd2f13372bab338aa6b84c..57ac0007b1c021eb34632acca0a5e69728fdb055 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 778a0adc9ca934f237fc76ab548599b60ef79bd3..7bea3ff476b7d6606d4ec21b65ba27ab5da2cb92 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 6584a8eb263ea6eda970a68f81c85faacfdfff3e..712c2a192771982dc4b67b39744a7592270c64c4 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 1291a677bf9de265b079a26aa1fdcd9cade07600..0fe9c50dc15e85d04159dc58d852f2534efe2868 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 232f2444cf4092f3f3c456bf408b5061cc9e4fd7..c5888f5d30ed2eb5909102f2a588b4a8315a5b23 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 23f2ae577c2cb384b3538a75af4c830b3eab1fa4..e1d55364945e65672977dda3b8585f6eac22b890 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 ecd3ffbe5ccfb8f01f44d846c3ae6e7ffa7f7175..6d4dc78e8240f04019e7f829113adda621f1ffad 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 139341536debf068b82704d5e7d70a3edbe045e0..2daf8ab0bd97e7e9577cd046c3936274afad3224 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 baa2616267d537dd7e016274f67abb5a110ac7bb..b2cb0f2ad73195d733b8a4c3d1d3140cbbeded05 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 ad5072f4bacd1d40f7368d64e15cabe113df8d80..4e5c326be7b5eb5d10a967bb448a53d632250cc8 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 8884dfae1782062e32c03c41a017942dfe01f347..0a1069cf3a90a4fc10a7cac8351a3a0bfa64ed78 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 3116842002abda9b8c39c48f8134f3f82bca1a1b..1d342abc3174599758fce01af2a852ba5305f6c7 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 65383176a0f7a12351b2171191556c6dd49df7a8..0000000000000000000000000000000000000000 --- 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