Skip to content

Commit 9bdac9a

Browse files
metax666duqimengStareAtYoujxwangmetaxzhang-chenyi
authored
【metax】Fix bug updata paddle change patch (#1932)
Co-authored-by: sw <1640472053@qq.com> Co-authored-by: duqimeng <77875733+duqimeng@users.noreply.github.com> Co-authored-by: Mingkun.Zhang <2496808993@qq.com> Co-authored-by: jiaxinWang-metax <189149612@qq.com> Co-authored-by: MingkunZhang <39252862+StareAtYou@users.noreply.github.com> Co-authored-by: chezhang <1376507468@qq.com> Co-authored-by: zhang-chenyi <74278535+zhang-chenyi@users.noreply.github.com> Co-authored-by: ZhouDuan <1184319564@qq.com>
1 parent 8218e6c commit 9bdac9a

54 files changed

Lines changed: 6050 additions & 1175 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backends/metax_gpu/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,11 @@ file(
463463
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/unpool_kernel.cu
464464
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/lstsq_kernel.cu
465465
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/unpool_grad_kernel.cu
466-
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/unstack_grad_kernel_register.cu
466+
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/unstack_grad_kernel.cu
467+
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/lgamma_grad_kernel.cu
468+
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/linspace_kernel.cu
469+
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/kron_kernel.cu
470+
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/kron_grad_kernel.cu
467471
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/stack_grad_kernel.cu
468472
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/unstack_kernel.cu
469473
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/viterbi_decode_kernel.cu
@@ -736,7 +740,7 @@ target_include_directories(
736740
${TARGET_NAME}
737741
PRIVATE ${PADDLE_SOURCE_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/kernels
738742
${CUDA_INCLUDE_DIRS} ${PADDLE_SOURCE_DIR}/third_party/pybind/include
739-
${PADDLE_SOURCE_DIR}/paddle/phi/api/include/compat/)
743+
${PADDLE_SOURCE_DIR}/paddle/phi/api/include/compat)
740744

741745
target_link_libraries(
742746
${TARGET_NAME}

backends/metax_gpu/kernels/cuda_kernels/assign_kernel_register.cu

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ PD_CUSTOM_KERNEL_REGISTER(assign_value,
3939
bool,
4040
int,
4141
float,
42+
double,
4243
int8_t,
4344
int64_t,
4445
phi::dtype::float16,
4546
phi::dtype::bfloat16,
46-
phi::dtype::complex<float>) {}
47+
phi::dtype::complex<float>,
48+
phi::dtype::complex<double>) {}

backends/metax_gpu/kernels/cuda_kernels/batch_norm_kernel_register.cu

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,25 +1287,6 @@ void BatchNormKernel(const Context &dev_ctx,
12871287

12881288
} // namespace phi
12891289

1290-
#ifdef PADDLE_WITH_HIP
1291-
PD_REGISTER_PLUGIN_KERNEL(batch_norm,
1292-
metax_gpu,
1293-
ALL_LAYOUT,
1294-
phi::BatchNormKernel,
1295-
float,
1296-
phi::dtype::bfloat16,
1297-
phi::dtype::float16) {
1298-
kernel->InputAt(1).SetDataType(phi::DataType::FLOAT32);
1299-
kernel->InputAt(2).SetDataType(phi::DataType::FLOAT32);
1300-
kernel->InputAt(3).SetDataType(phi::DataType::FLOAT32);
1301-
kernel->InputAt(4).SetDataType(phi::DataType::FLOAT32);
1302-
kernel->OutputAt(1).SetDataType(phi::DataType::FLOAT32);
1303-
kernel->OutputAt(2).SetDataType(phi::DataType::FLOAT32);
1304-
kernel->OutputAt(3).SetDataType(phi::DataType::FLOAT32);
1305-
kernel->OutputAt(4).SetDataType(phi::DataType::FLOAT32);
1306-
}
1307-
#else
1308-
#if CUDNN_VERSION_MIN(8, 1, 0)
13091290
PD_REGISTER_PLUGIN_KERNEL(batch_norm,
13101291
metax_gpu,
13111292
ALL_LAYOUT,
@@ -1325,32 +1306,5 @@ PD_REGISTER_PLUGIN_KERNEL(batch_norm,
13251306
kernel->OutputAt(3).SetDataType(phi::DataType::FLOAT32);
13261307
kernel->OutputAt(4).SetDataType(phi::DataType::FLOAT32);
13271308
}
1328-
#if CUDNN_VERSION_MIN(7, 4, 1)
1329-
kernel->OutputAt(5).SetDataType(phi::DataType::UINT8);
1330-
#endif
1331-
}
1332-
#else
1333-
PD_REGISTER_PLUGIN_KERNEL(batch_norm,
1334-
metax_gpu,
1335-
ALL_LAYOUT,
1336-
phi::BatchNormKernel,
1337-
float,
1338-
double,
1339-
phi::dtype::float16) {
1340-
if (kernel_key.dtype() == phi::DataType::FLOAT16) {
1341-
kernel->InputAt(1).SetDataType(phi::DataType::FLOAT32);
1342-
kernel->InputAt(2).SetDataType(phi::DataType::FLOAT32);
1343-
kernel->InputAt(3).SetDataType(phi::DataType::FLOAT32);
1344-
kernel->InputAt(4).SetDataType(phi::DataType::FLOAT32);
1345-
kernel->OutputAt(1).SetDataType(phi::DataType::FLOAT32);
1346-
kernel->OutputAt(2).SetDataType(phi::DataType::FLOAT32);
1347-
kernel->OutputAt(3).SetDataType(phi::DataType::FLOAT32);
1348-
kernel->OutputAt(4).SetDataType(phi::DataType::FLOAT32);
1349-
}
1350-
#if CUDNN_VERSION_MIN(7, 4, 1)
13511309
kernel->OutputAt(5).SetDataType(phi::DataType::UINT8);
1352-
#endif
13531310
}
1354-
#endif
1355-
1356-
#endif

backends/metax_gpu/kernels/cuda_kernels/conv_transpose_grad_kernel_register.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "paddle/phi/core/kernel_registry.h"
1516
#include "paddle/phi/kernels/gpu/conv_transpose_grad_kernel.cu" // NOLINT
16-
1717
PD_CUSTOM_KERNEL_REGISTER(conv2d_transpose_grad,
1818
metax_gpu,
1919
ALL_LAYOUT,
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "kernels/impl/conv_transpose_kernel_impl.h"
16+
#include "paddle/common/ddim.h"
17+
#include "paddle/common/layout.h"
18+
#include "paddle/phi/core/kernel_registry.h"
19+
#include "paddle/phi/kernels/conv_transpose_kernel.h"
20+
#include "paddle/phi/kernels/cpu/conv_util.h"
21+
#include "paddle/phi/kernels/funcs/math_function.h"
22+
#include "paddle/phi/kernels/gpu/depthwise_conv.h"
23+
24+
namespace phi {
25+
26+
template <typename T, typename Context>
27+
void DepthwiseConv2dTransposeKernel(const Context& dev_ctx,
28+
const DenseTensor& x,
29+
const DenseTensor& filter,
30+
const std::vector<int>& strides,
31+
const std::vector<int>& paddings,
32+
const std::vector<int>& output_padding,
33+
const IntArray& output_size,
34+
const std::string& padding_algorithm,
35+
int groups,
36+
const std::vector<int>& dilations,
37+
const std::string& data_format,
38+
DenseTensor* out) {
39+
if (x.numel() == 0 || filter.numel() == 0) {
40+
phi::Full<T, Context>(
41+
dev_ctx, phi::IntArray(common::vectorize(out->dims())), 0, out);
42+
return;
43+
}
44+
const DataLayout data_layout = common::StringToDataLayout(data_format);
45+
DenseTensor filter_ = filter;
46+
dev_ctx.template Alloc<T>(out);
47+
48+
PADDLE_ENFORCE_EQ(
49+
groups,
50+
filter_.dims()[0],
51+
errors::InvalidArgument(
52+
"groups should be error to the 1st dimension of filter_. But "
53+
"received groups is %d and filter dimension[0] is %d",
54+
groups,
55+
filter_.dims()[0]));
56+
57+
std::vector<int> paddings_ = paddings;
58+
std::vector<int> dilations_ = dilations;
59+
60+
for (auto v : dilations_) {
61+
PADDLE_ENFORCE_EQ(
62+
v,
63+
1,
64+
errors::InvalidArgument("dilations should be 1 in depthwise conv. "
65+
"But received dilations is %d",
66+
v));
67+
}
68+
69+
auto x_dims = x.dims();
70+
auto filter_dims = filter_.dims();
71+
72+
DDim in_data_dims;
73+
if (data_layout != DataLayout::kNHWC) {
74+
in_data_dims = slice_ddim(x_dims, 2, x_dims.size());
75+
} else {
76+
in_data_dims = slice_ddim(x_dims, 1, x_dims.size() - 1);
77+
}
78+
DDim filter_data_dims = slice_ddim(filter_dims, 2, filter_dims.size());
79+
std::vector<int> ksize = common::vectorize<int>(filter_data_dims);
80+
UpdatePaddingAndDilation(
81+
&paddings_, &dilations_, padding_algorithm, in_data_dims, strides, ksize);
82+
83+
dev_ctx.template Alloc<T>(out);
84+
85+
funcs::SetConstant<Context, T> set_zero;
86+
set_zero(dev_ctx, out, static_cast<T>(0));
87+
88+
phi::math::DepthwiseConvInputGradFunctor<Context, T> depthwiseConvInputGrad;
89+
depthwiseConvInputGrad(
90+
dev_ctx,
91+
*out,
92+
filter,
93+
x,
94+
strides,
95+
std::vector<int>{paddings_[0], paddings_[2], paddings_[1], paddings_[3]},
96+
dilations_,
97+
out,
98+
data_layout);
99+
}
100+
101+
} // namespace phi
102+
103+
PD_REGISTER_PLUGIN_KERNEL(depthwise_conv2d_transpose,
104+
metax_gpu,
105+
ALL_LAYOUT,
106+
phi::DepthwiseConv2dTransposeKernel,
107+
float,
108+
double) {}

0 commit comments

Comments
 (0)