diff --git a/paddle/phi/core/kernel_factory.cc b/paddle/phi/core/kernel_factory.cc index d3fd2e0204e54f1cbaed8049ac83abcad7efed7a..6d71c5016bda4ee5e8b4cc9be9716260766bea06 100644 --- a/paddle/phi/core/kernel_factory.cc +++ b/paddle/phi/core/kernel_factory.cc @@ -79,7 +79,7 @@ bool KernelFactory::HasKernel(const std::string& kernel_name, const Kernel& KernelFactory::SelectKernelOrThrowError( const std::string& kernel_name, const KernelKey& kernel_key, - bool use_cudnn) const { + bool use_gpudnn) const { auto iter = kernels_.find(kernel_name); PADDLE_ENFORCE_NE( iter, @@ -87,7 +87,7 @@ const Kernel& KernelFactory::SelectKernelOrThrowError( phi::errors::NotFound("The kernel `%s` is not registered.", kernel_name)); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) - if (use_cudnn && kernel_key.backend() == Backend::GPU) { + if (use_gpudnn && kernel_key.backend() == Backend::GPU) { auto kernel_iter = iter->second.find( {Backend::GPUDNN, kernel_key.layout(), kernel_key.dtype()}); if (kernel_iter == iter->second.end() && diff --git a/paddle/phi/core/kernel_factory.h b/paddle/phi/core/kernel_factory.h index 812b6222cb5e293ffdaa1051462dcf945052fef9..3ac99a426319dd82a97ca2dafe407b01244a8419 100644 --- a/paddle/phi/core/kernel_factory.h +++ b/paddle/phi/core/kernel_factory.h @@ -247,7 +247,7 @@ class KernelFactory { const Kernel& SelectKernelOrThrowError(const std::string& kernel_name, const KernelKey& kernel_key, - bool use_cudnn = false) const; + bool use_gpudnn = false) const; const Kernel& SelectKernelOrThrowError(const std::string& kernel_name, Backend backend, diff --git a/python/paddle/nn/functional/pooling.py b/python/paddle/nn/functional/pooling.py index b9cae4784725da049cc50a58c8b8bd4d906f0fbd..3160f04e830d2e948d2635a1af08dbcca2716e4c 100755 --- a/python/paddle/nn/functional/pooling.py +++ b/python/paddle/nn/functional/pooling.py @@ -1401,9 +1401,9 @@ def adaptive_avg_pool2d(x, output_size, data_format='NCHW', name=None): output_size[1] = in_w if in_dygraph_mode(): - return _C_ops.final_state_pool2d(x, output_size, [1, 1], [0, 0], False, - True, data_format, 'avg', False, True, - "EXPLICIT") + return _C_ops.final_state_pool2d_gpudnn_unused( + x, output_size, [1, 1], [0, 0], False, True, data_format, 'avg', + False, True, "EXPLICIT") if _in_legacy_dygraph(): return _C_ops.pool2d(x, 'pooling_type', 'avg', 'ksize', output_size, diff --git a/python/paddle/utils/code_gen/api.yaml b/python/paddle/utils/code_gen/api.yaml index 58b80950e552975ac7cda1d595873d6fb2075d10..d401e7c5190fe9bcaaf6ab7a77aaa0051f282da9 100644 --- a/python/paddle/utils/code_gen/api.yaml +++ b/python/paddle/utils/code_gen/api.yaml @@ -382,6 +382,7 @@ func : ConvTransposeInferMeta kernel : func : conv2d_transpose + use_gpudnn : true backward : conv2d_transpose_grad - api : conv3d_transpose @@ -391,6 +392,7 @@ func : ConvTransposeInferMeta kernel : func : conv3d_transpose + use_gpudnn : true backward : conv3d_transpose_grad - api : copy_to @@ -1556,8 +1558,20 @@ func : PoolInferMeta kernel : func : pool2d + use_gpudnn : true backward : pool2d_grad +# Used in adaptive_avg_pool2d API +- api : pool2d_gpudnn_unused + args : (Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) + output : Tensor(out) + infer_meta : + func : PoolInferMeta + kernel : + func : pool2d + use_gpudnn : false + backward : pool2d_grad_gpudnn_unused + - api : pool3d args : (Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) output : Tensor(out) @@ -1565,6 +1579,7 @@ func : PoolInferMeta kernel : func : pool3d + use_gpudnn : true backward : pool3d_grad - api : pow @@ -1923,6 +1938,7 @@ func : SoftmaxInferMeta kernel : func : softmax + use_gpudnn : true backward : softmax_grad - api : split diff --git a/python/paddle/utils/code_gen/api_base.py b/python/paddle/utils/code_gen/api_base.py index 378ead7ff20aa9d29e69a36129cd5dd011ca4ebb..717870ee01d0a04fa4b9c31a0d6582a851ed3bd6 100644 --- a/python/paddle/utils/code_gen/api_base.py +++ b/python/paddle/utils/code_gen/api_base.py @@ -238,7 +238,7 @@ class BaseAPI(object): 'backend': None, 'layout': None, 'data_type': None, - 'use_cudnn': 'false' + 'use_gpudnn': 'false' } if 'backend' in kernel_config and len(kernel_config['backend']) > 0: kernel['backend'] = kernel_config['backend'] @@ -248,10 +248,10 @@ class BaseAPI(object): kernel['data_type'] = kernel_config['data_type'] if 'param' in kernel_config: kernel['param'] = kernel_config['param'] - if 'use_cudnn' in kernel_config: - kernel['use_cudnn'] = kernel_config['use_cudnn'] - if isinstance(kernel['use_cudnn'], bool): - kernel['use_cudnn'] = str(kernel['use_cudnn']).lower() + if 'use_gpudnn' in kernel_config: + kernel['use_gpudnn'] = kernel_config['use_gpudnn'] + if isinstance(kernel['use_gpudnn'], bool): + kernel['use_gpudnn'] = str(kernel['use_gpudnn']).lower() kernel['func'] = [ kernel_fn.strip() for kernel_fn in kernel_config['func'].split(',') ] @@ -729,7 +729,7 @@ PADDLE_API {self.gene_return_type_code()} {self.get_api_func_name() + '_'}({self self.outputs['types'], 'SetKernelOutput', code_indent, inplace_flag) api_func_name = self.get_api_func_name() + ('_' if inplace_flag else '') cudnn_args = '' if self.kernel[ - 'use_cudnn'] == 'false' else ', ' + self.kernel['use_cudnn'] + 'use_gpudnn'] == 'false' else ', ' + self.kernel['use_gpudnn'] return f""" {code_indent} VLOG(6) << "{self.api} API kernel key: [" << kernel_backend << ", " << kernel_layout << ", "<< kernel_data_type << "]"; {code_indent} const auto& kernel = phi::KernelFactory::Instance().SelectKernelOrThrowError( diff --git a/python/paddle/utils/code_gen/backward.yaml b/python/paddle/utils/code_gen/backward.yaml index dfdc2335ae180258cefc0b17262d8ebcf9aa37af..3b47470139b909f751c4aa0a0989d7c82a3d4b95 100644 --- a/python/paddle/utils/code_gen/backward.yaml +++ b/python/paddle/utils/code_gen/backward.yaml @@ -272,7 +272,7 @@ param: [input, filter, grad_out] kernel : func : conv2d_grad_grad - use_cudnn : true + use_gpudnn : true optional : grad_input_grad, grad_filter_grad - backward_api : conv2d_transpose_grad @@ -283,6 +283,7 @@ func : ConvTransposeGradInferMeta kernel : func : conv2d_transpose_grad + use_gpudnn : true - backward_api : conv3d_transpose_grad forward : conv3d_transpose(Tensor x, Tensor filter, int[] strides, int[] paddings, int[] output_padding, int[] output_size, str padding_algorithm, int groups, int[] dilations, str data_format) -> Tensor(out) @@ -292,6 +293,7 @@ func : ConvTransposeGradInferMeta kernel : func : conv3d_transpose_grad + use_gpudnn : true - backward_api : cos_grad forward : cos (Tensor x) -> Tensor(out) @@ -1234,6 +1236,17 @@ func : PoolGradInferMeta kernel : func : pool2d_grad + use_gpudnn : true + +- backward_api : pool2d_grad_gpudnn_unused + forward : pool2d_gpudnn_unused(Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(out) + args : (Tensor x, Tensor out, Tensor out_grad, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) + output : Tensor(x_grad) + infer_meta : + func : PoolGradInferMeta + kernel : + func : pool2d_grad + use_gpudnn : false - backward_api : pool3d_grad forward : pool3d(Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(out) @@ -1243,6 +1256,7 @@ func : PoolGradInferMeta kernel : func : pool3d_grad + use_gpudnn : true - backward_api : pow_grad forward : pow(Tensor x, Scalar s) -> Tensor(out) @@ -1578,6 +1592,7 @@ param : [out] kernel : func : softmax_grad + use_gpudnn : true - backward_api : split_grad forward : split (Tensor x, IntArray num_or_sections, Scalar axis) -> Tensor[](out) diff --git a/python/paddle/utils/code_gen/wrapped_infermeta_gen.py b/python/paddle/utils/code_gen/wrapped_infermeta_gen.py index b50db007d92e97c33c41f7044b7f6a477391c10a..dd077552b79623747bc3f9867cff6d9b49b2d9c2 100644 --- a/python/paddle/utils/code_gen/wrapped_infermeta_gen.py +++ b/python/paddle/utils/code_gen/wrapped_infermeta_gen.py @@ -141,7 +141,8 @@ def generate_wrapped_infermeta_and_register(api_yaml_path, header_file_path, api_item) header_file.write(declare_code) source_file.write(defind_code) - infermeta_register_code = infermeta_register_code + register_code + if infermeta_register_code.find(register_code) == -1: + infermeta_register_code = infermeta_register_code + register_code header_file.write(namespace[1]) source_file.write(namespace[1])