diff --git a/paddle/phi/kernels/funcs/im2col.cc b/paddle/phi/kernels/funcs/im2col.cc index bbdb9fa49edeaa..b19431a13f2bf9 100644 --- a/paddle/phi/kernels/funcs/im2col.cc +++ b/paddle/phi/kernels/funcs/im2col.cc @@ -27,7 +27,7 @@ namespace phi::funcs { * [input_channels, filter_height, filter_width, output_height, output_width] */ template -class Im2ColFunctor { +class Im2ColFunctor { public: void operator()(const DeviceContext& dev_ctx UNUSED, const DenseTensor& im, @@ -72,7 +72,7 @@ class Im2ColFunctor { * [input_channels, filter_height, filter_width, output_height, output_width] */ template -class Col2ImFunctor { +class Col2ImFunctor { public: void operator()(const DeviceContext& dev_ctx UNUSED, const DenseTensor& col, @@ -154,21 +154,21 @@ class Col2ImFunctor { }; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; /* * im = [input_channels, input_height, input_width] @@ -176,7 +176,7 @@ template class PADDLE_API * [output_height, output_width, input_channels, filter_height, filter_width] */ template -class Im2ColFunctor { +class Im2ColFunctor { public: void operator()(const DeviceContext& dev_ctx UNUSED, const DenseTensor& im, @@ -249,7 +249,7 @@ class Im2ColFunctor { * [output_height, output_width, input_channels, filter_height, filter_width] */ template -class Col2ImFunctor { +class Col2ImFunctor { public: void operator()(const DeviceContext& dev_ctx UNUSED, const DenseTensor& col, @@ -329,19 +329,19 @@ class Col2ImFunctor { }; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; } // namespace phi::funcs diff --git a/paddle/phi/kernels/funcs/im2col.cu b/paddle/phi/kernels/funcs/im2col.cu index a7100f63dcf4f2..ebacfbe44554e8 100644 --- a/paddle/phi/kernels/funcs/im2col.cu +++ b/paddle/phi/kernels/funcs/im2col.cu @@ -87,7 +87,7 @@ __global__ void im2col(const T* data_im, * [input_channels, filter_height, filter_width, output_height, output_width] */ template -class Im2ColFunctor { +class Im2ColFunctor { public: void operator()(const DeviceContext& dev_ctx, const DenseTensor& im, @@ -233,7 +233,7 @@ __global__ void col2im(int64_t n, * [input_channels, filter_height, filter_width, output_height, output_width] */ template -class Col2ImFunctor { +class Col2ImFunctor { public: void operator()(const DeviceContext& dev_ctx, const DenseTensor& col, @@ -324,29 +324,29 @@ class Col2ImFunctor { }; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template __global__ void im2colOCF(const T* im_data, @@ -394,7 +394,7 @@ __global__ void im2colOCF(const T* im_data, * [output_height, output_width, input_channels, filter_height, filter_width] */ template -class Im2ColFunctor { +class Im2ColFunctor { public: void operator()(const DeviceContext& dev_ctx, const DenseTensor& im, @@ -506,7 +506,7 @@ __global__ void col2imOCF(const T* col_data, * [output_height, output_width, input_channels, filter_height, filter_width] */ template -class Col2ImFunctor { +class Col2ImFunctor { public: void operator()(const DeviceContext& dev_ctx, const DenseTensor& col, @@ -591,29 +591,29 @@ class Col2ImFunctor { }; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Im2ColFunctor; + Im2ColFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; template class PADDLE_API - Col2ImFunctor; + Col2ImFunctor; } // namespace funcs } // namespace phi diff --git a/paddle/phi/kernels/funcs/im2col.h b/paddle/phi/kernels/funcs/im2col.h index ea7464d97dfaaa..7c6436a10db850 100644 --- a/paddle/phi/kernels/funcs/im2col.h +++ b/paddle/phi/kernels/funcs/im2col.h @@ -25,7 +25,7 @@ namespace phi { namespace funcs { /* The storage format of the coldata in the Im2ColFunctor and Col2ImFunctor. */ -enum class ColFormat { kCFO = 0, kOCF = 1 }; +enum class ColFormat { CFO = 0, OCF = 1 }; /* * \brief Converts the image data of three dimensions(CHW) into a colData of @@ -47,7 +47,7 @@ enum class ColFormat { kCFO = 0, kOCF = 1 }; * \param paddings padding data. * \param 4-dimension [up_pad, left_pad, down_pad, right_pad]. * - * If the template argument Format is kCFO, the shape of colData is: + * If the template argument Format is CFO, the shape of colData is: * [input_channels, filter_height, filter_width, output_height, output_width] * So, it is easy to reshape into a convolution matrix for convolution * calculation based on matrix multiplication. @@ -63,7 +63,7 @@ enum class ColFormat { kCFO = 0, kOCF = 1 }; * output_height, * output_width] * - * If the template argument Format is kOCF, the shape of colData is: + * If the template argument Format is OCF, the shape of colData is: * [output_height, output_width, input_channels, filter_height, filter_width] * So, it is easy to reshape into a sequence matrix for rnn calculation. * The shape of sequence matrix is [seq_length, step_size], where the seq_length diff --git a/paddle/phi/kernels/funcs/math/context_project.h b/paddle/phi/kernels/funcs/math/context_project.h index aa97abe1287812..86a08028716632 100644 --- a/paddle/phi/kernels/funcs/math/context_project.h +++ b/paddle/phi/kernels/funcs/math/context_project.h @@ -94,7 +94,7 @@ class ContextProjectFunctor { DenseTensor* col) { auto lod_level_0 = in.lod()[0]; - funcs::Im2ColFunctor + funcs::Im2ColFunctor im2col_ocf; std::vector dilation({1, 1}); @@ -223,7 +223,7 @@ class ContextProjectGradFunctor { DenseTensor* col) { auto lod_level_0 = in.lod()[0]; - funcs::Col2ImFunctor + funcs::Col2ImFunctor col2im_ocf; std::vector dilation({1, 1}); diff --git a/paddle/phi/kernels/impl/conv_grad_kernel_impl.h b/paddle/phi/kernels/impl/conv_grad_kernel_impl.h index cbbb79e394ff62..af9ed3ed4b802e 100644 --- a/paddle/phi/kernels/impl/conv_grad_kernel_impl.h +++ b/paddle/phi/kernels/impl/conv_grad_kernel_impl.h @@ -160,7 +160,7 @@ void ConvGradKernel(const Context& dev_ctx, if (is_expand) { set_zero(dev_ctx, &transformed_input_grad, static_cast(0)); } - funcs::Col2ImFunctor col2im; + funcs::Col2ImFunctor col2im; funcs::Col2VolFunctor col2vol; for (int64_t i = 0; i < batch_size; i++) { @@ -214,7 +214,7 @@ void ConvGradKernel(const Context& dev_ctx, Tensor filter_grad_ = *filter_grad; filter_grad_.Resize(filter_matrix_shape); set_zero(dev_ctx, filter_grad, static_cast(0)); - funcs::Im2ColFunctor im2col; + funcs::Im2ColFunctor im2col; funcs::Vol2ColFunctor vol2col; for (int i = 0; i < batch_size; i++) { DenseTensor out_grad_batch = @@ -391,7 +391,7 @@ void ConvGradGradKernel(const Context& dev_ctx, if (is_expand) { set_zero(dev_ctx, &transformed_dX, static_cast(0)); } - funcs::Col2ImFunctor col2im; + funcs::Col2ImFunctor col2im; funcs::Col2VolFunctor col2vol; for (int64_t i = 0; i < batch_size; i++) { @@ -436,7 +436,7 @@ void ConvGradGradKernel(const Context& dev_ctx, set_zero(dev_ctx, dW, static_cast(0)); DenseTensor dW_arr = *dW; dW_arr.Resize(filter_matrix_shape); - funcs::Im2ColFunctor im2col; + funcs::Im2ColFunctor im2col; funcs::Vol2ColFunctor vol2col; for (int i = 0; i < batch_size; ++i) { DenseTensor dy_batch = @@ -483,7 +483,7 @@ void ConvGradGradKernel(const Context& dev_ctx, } set_zero(dev_ctx, &transformed_ddY, static_cast(0)); - funcs::Im2ColFunctor im2col; + funcs::Im2ColFunctor im2col; funcs::Vol2ColFunctor vol2col; for (int i = 0; i < batch_size; ++i) { DenseTensor ddy_batch = diff --git a/paddle/phi/kernels/impl/conv_kernel_impl.h b/paddle/phi/kernels/impl/conv_kernel_impl.h index 7945389e11988b..a4a4d3bb7ab042 100644 --- a/paddle/phi/kernels/impl/conv_kernel_impl.h +++ b/paddle/phi/kernels/impl/conv_kernel_impl.h @@ -140,7 +140,7 @@ void ConvKernelImpl(const Context& dev_ctx, int64_t in_step = transformed_input.dims()[1] / groups; int64_t out_step = transformed_output.dims()[1] / groups; - funcs::Im2ColFunctor im2col; + funcs::Im2ColFunctor im2col; funcs::Vol2ColFunctor vol2col; auto blas = funcs::GetBlas(dev_ctx); diff --git a/paddle/phi/kernels/impl/conv_transpose_grad_kernel_impl.h b/paddle/phi/kernels/impl/conv_transpose_grad_kernel_impl.h index a439b6049a0244..f133c34ad1f96f 100644 --- a/paddle/phi/kernels/impl/conv_transpose_grad_kernel_impl.h +++ b/paddle/phi/kernels/impl/conv_transpose_grad_kernel_impl.h @@ -164,7 +164,7 @@ void ConvTransposeGradRawKernel(const Context& dev_ctx, DenseTensor dfilter_; funcs::SetConstant set_zero; - funcs::Im2ColFunctor im2col; + funcs::Im2ColFunctor im2col; funcs::Vol2ColFunctor vol2col; funcs::ConcatFunctor concat_functor; diff --git a/paddle/phi/kernels/impl/conv_transpose_kernel_impl.h b/paddle/phi/kernels/impl/conv_transpose_kernel_impl.h index 3c05deb3666589..0af28152669713 100644 --- a/paddle/phi/kernels/impl/conv_transpose_kernel_impl.h +++ b/paddle/phi/kernels/impl/conv_transpose_kernel_impl.h @@ -142,7 +142,7 @@ void ConvTransposeRawKernel(const Context& dev_ctx, (data_layout != DataLayout::NHWC ? static_cast(out_dims[1]) / groups : static_cast(out_dims[out_dims.size() - 1]) / groups); - funcs::Col2ImFunctor col2im; + funcs::Col2ImFunctor col2im; funcs::Col2VolFunctor col2vol; funcs::ConcatFunctor concat_functor; diff --git a/paddle/phi/kernels/impl/fold_grad_kernel_impl.h b/paddle/phi/kernels/impl/fold_grad_kernel_impl.h index fda4bdcc848ca5..95ecf8f8379a5c 100644 --- a/paddle/phi/kernels/impl/fold_grad_kernel_impl.h +++ b/paddle/phi/kernels/impl/fold_grad_kernel_impl.h @@ -57,7 +57,7 @@ void FoldGradKernel(const Context& dev_ctx, DDim input_matrix_shape = common::make_ddim( {1, kernel_sizes[0], kernel_sizes[1], output_height, output_width}); - funcs::Im2ColFunctor im2col; + funcs::Im2ColFunctor im2col; for (int64_t i = 0; i < batch_size; i++) { DenseTensor out_grad_batch = out_grad.Slice(i, i + 1).Resize(out_shape); diff --git a/paddle/phi/kernels/impl/fold_kernel_impl.h b/paddle/phi/kernels/impl/fold_kernel_impl.h index 94db6fc9c4247b..da4f0884402065 100644 --- a/paddle/phi/kernels/impl/fold_kernel_impl.h +++ b/paddle/phi/kernels/impl/fold_kernel_impl.h @@ -36,7 +36,7 @@ void FoldKernel(const Context& dev_ctx, const int64_t batch_size = x.dims()[0]; dev_ctx.template Alloc(out); - funcs::Col2ImFunctor col2im; + funcs::Col2ImFunctor col2im; const auto& x_dims = x.dims(); int output_height = (output_sizes[0] + 2 * paddings[0] - diff --git a/paddle/phi/kernels/impl/im2sequence_kernel_impl.h b/paddle/phi/kernels/impl/im2sequence_kernel_impl.h index 536612a16f91f7..c21f167058eb8c 100644 --- a/paddle/phi/kernels/impl/im2sequence_kernel_impl.h +++ b/paddle/phi/kernels/impl/im2sequence_kernel_impl.h @@ -97,7 +97,7 @@ void Im2SequenceKernel(const Context& dev_ctx, kernels[1]}); offset_out += output_height[i] * output_width[i]; - funcs::Im2ColFunctor f; + funcs::Im2ColFunctor f; f(dev_ctx, src, dilations, strides, paddings, &dst); } phi::LegacyLoD lod(1); @@ -127,7 +127,7 @@ void Im2SequenceKernel(const Context& dev_ctx, DenseTensor dst = out->Slice(i, i + 1).Resize( {output_height, output_width, img_channels, kernels[0], kernels[1]}); - funcs::Im2ColFunctor f; + funcs::Im2ColFunctor f; f(dev_ctx, src, dilations, strides, paddings, &dst); } out->Resize(out_dims); @@ -184,7 +184,7 @@ void Im2SequenceGradKernel(const Context& dev_ctx, d_x->Slice(i, i + 1).Resize({img_channels, img_height, img_width}); const DenseTensor src = d_out->Slice(i, i + 1).Resize( {output_height, output_width, img_channels, kernels[0], kernels[1]}); - funcs::Col2ImFunctor f; + funcs::Col2ImFunctor f; f(dev_ctx, src, dilations, strides, paddings, &dst); } d_out->Resize(d_out_dims); diff --git a/paddle/phi/kernels/impl/unfold_grad_kernel_impl.h b/paddle/phi/kernels/impl/unfold_grad_kernel_impl.h index 5150b55feaecd9..3b00abb53ddedb 100644 --- a/paddle/phi/kernels/impl/unfold_grad_kernel_impl.h +++ b/paddle/phi/kernels/impl/unfold_grad_kernel_impl.h @@ -57,7 +57,7 @@ void UnfoldGradKernel(const Context& dev_ctx, DDim out_matrix_shape = common::make_ddim( {x_dims[1], kernel_sizes[0], kernel_sizes[1], out_height, out_width}); - funcs::Col2ImFunctor col2im; + funcs::Col2ImFunctor col2im; funcs::SetConstant set_zero; set_zero(dev_ctx, x_grad, static_cast(0)); diff --git a/paddle/phi/kernels/impl/unfold_kernel_impl.h b/paddle/phi/kernels/impl/unfold_kernel_impl.h index 73fb4d366d04bf..a4d739872ed0f0 100644 --- a/paddle/phi/kernels/impl/unfold_kernel_impl.h +++ b/paddle/phi/kernels/impl/unfold_kernel_impl.h @@ -37,7 +37,7 @@ void UnfoldKernel(const Context& dev_ctx, return; } - funcs::Im2ColFunctor im2col; + funcs::Im2ColFunctor im2col; const auto& x_dims = x.dims(); int64_t out_height = funcs::CalcOutputSize(x_dims[2], diff --git a/test/cpp/fluid/math/im2col_test.cc b/test/cpp/fluid/math/im2col_test.cc index 765c819c31cf60..d27d010d146288 100644 --- a/test/cpp/fluid/math/im2col_test.cc +++ b/test/cpp/fluid/math/im2col_test.cc @@ -78,9 +78,9 @@ void testIm2col() { {output_height, output_width, 1, filter_size, filter_size}, *place); // Im2Col - phi::funcs::Im2ColFunctor + phi::funcs::Im2ColFunctor im2col; - phi::funcs::Im2ColFunctor + phi::funcs::Im2ColFunctor im2col_ocf; im2col(*context, input, dilation, stride, padding, &output_cfo); @@ -112,10 +112,10 @@ void testIm2col() { EXPECT_EQ(out_ocf_ptr[i], out_ocf_data[i]); } - // Col2Im: kCFO - phi::funcs::Col2ImFunctor + // Col2Im: CFO + phi::funcs::Col2ImFunctor col2im; - phi::funcs::Col2ImFunctor + phi::funcs::Col2ImFunctor col2im_ocf; std::array col2im_data = {0, 2, 2, 3, 8, 5}; @@ -139,7 +139,7 @@ void testIm2col() { EXPECT_EQ(in_ptr[i], col2im_data[i]); } - // Col2Im: kOCF + // Col2Im: OCF memset(input_ptr, 0, 6 * sizeof(float)); if (phi::is_cpu_place(*place)) { input = input_tmp; @@ -223,9 +223,9 @@ void testIm2col() { {output_height, output_width, 1, filter_size, filter_size}, *place); // Im2Col - phi::funcs::Im2ColFunctor + phi::funcs::Im2ColFunctor im2col; - phi::funcs::Im2ColFunctor + phi::funcs::Im2ColFunctor im2col_ocf; im2col(*context, input, dilation, stride, padding, &output_cfo); @@ -257,10 +257,10 @@ void testIm2col() { EXPECT_EQ(out_ocf_ptr[i], out_ocf_data[i]); } - // Col2Im: kCFO - phi::funcs::Col2ImFunctor + // Col2Im: CFO + phi::funcs::Col2ImFunctor col2im; - phi::funcs::Col2ImFunctor + phi::funcs::Col2ImFunctor col2im_ocf; std::array col2im_data = {0, 2, 2, 3, 8, 5}; @@ -284,7 +284,7 @@ void testIm2col() { EXPECT_EQ(in_ptr[i], col2im_data[i]); } - // Col2Im: kOCF + // Col2Im: OCF memset(input_ptr, 0, 6 * sizeof(float)); if (phi::is_cpu_place(*place)) { input = input_tmp; @@ -334,7 +334,7 @@ TEST(math, im2col) { out.mutable_data({ic, fh, fw, output_height, output_width}, place); \ ref.mutable_data({ic, fh, fw, output_height, output_width}, place); \ phi::funcs:: \ - Im2ColFunctor \ + Im2ColFunctor \ im2col void testIm2colCPU(int ic, int ih, int iw, int fh, int fw, int ph, int pw) {