未验证 提交 4940a525 编写于 作者: R Ruibiao Chen 提交者: GitHub

Add gpudnn yaml config for some OPs (#41773)

* Add gpudnn yaml config for some OPs

* Add grad gpudnn config

* Fix CI errors

* Fix CI errors

* Fix CI errors

* Fix conflicts
上级 cca57c4a
...@@ -79,7 +79,7 @@ bool KernelFactory::HasKernel(const std::string& kernel_name, ...@@ -79,7 +79,7 @@ bool KernelFactory::HasKernel(const std::string& kernel_name,
const Kernel& KernelFactory::SelectKernelOrThrowError( const Kernel& KernelFactory::SelectKernelOrThrowError(
const std::string& kernel_name, const std::string& kernel_name,
const KernelKey& kernel_key, const KernelKey& kernel_key,
bool use_cudnn) const { bool use_gpudnn) const {
auto iter = kernels_.find(kernel_name); auto iter = kernels_.find(kernel_name);
PADDLE_ENFORCE_NE( PADDLE_ENFORCE_NE(
iter, iter,
...@@ -87,7 +87,7 @@ const Kernel& KernelFactory::SelectKernelOrThrowError( ...@@ -87,7 +87,7 @@ const Kernel& KernelFactory::SelectKernelOrThrowError(
phi::errors::NotFound("The kernel `%s` is not registered.", kernel_name)); phi::errors::NotFound("The kernel `%s` is not registered.", kernel_name));
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #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( auto kernel_iter = iter->second.find(
{Backend::GPUDNN, kernel_key.layout(), kernel_key.dtype()}); {Backend::GPUDNN, kernel_key.layout(), kernel_key.dtype()});
if (kernel_iter == iter->second.end() && if (kernel_iter == iter->second.end() &&
......
...@@ -247,7 +247,7 @@ class KernelFactory { ...@@ -247,7 +247,7 @@ class KernelFactory {
const Kernel& SelectKernelOrThrowError(const std::string& kernel_name, const Kernel& SelectKernelOrThrowError(const std::string& kernel_name,
const KernelKey& kernel_key, const KernelKey& kernel_key,
bool use_cudnn = false) const; bool use_gpudnn = false) const;
const Kernel& SelectKernelOrThrowError(const std::string& kernel_name, const Kernel& SelectKernelOrThrowError(const std::string& kernel_name,
Backend backend, Backend backend,
......
...@@ -1401,9 +1401,9 @@ def adaptive_avg_pool2d(x, output_size, data_format='NCHW', name=None): ...@@ -1401,9 +1401,9 @@ def adaptive_avg_pool2d(x, output_size, data_format='NCHW', name=None):
output_size[1] = in_w output_size[1] = in_w
if in_dygraph_mode(): if in_dygraph_mode():
return _C_ops.final_state_pool2d(x, output_size, [1, 1], [0, 0], False, return _C_ops.final_state_pool2d_gpudnn_unused(
True, data_format, 'avg', False, True, x, output_size, [1, 1], [0, 0], False, True, data_format, 'avg',
"EXPLICIT") False, True, "EXPLICIT")
if _in_legacy_dygraph(): if _in_legacy_dygraph():
return _C_ops.pool2d(x, 'pooling_type', 'avg', 'ksize', output_size, return _C_ops.pool2d(x, 'pooling_type', 'avg', 'ksize', output_size,
......
...@@ -382,6 +382,7 @@ ...@@ -382,6 +382,7 @@
func : ConvTransposeInferMeta func : ConvTransposeInferMeta
kernel : kernel :
func : conv2d_transpose func : conv2d_transpose
use_gpudnn : true
backward : conv2d_transpose_grad backward : conv2d_transpose_grad
- api : conv3d_transpose - api : conv3d_transpose
...@@ -391,6 +392,7 @@ ...@@ -391,6 +392,7 @@
func : ConvTransposeInferMeta func : ConvTransposeInferMeta
kernel : kernel :
func : conv3d_transpose func : conv3d_transpose
use_gpudnn : true
backward : conv3d_transpose_grad backward : conv3d_transpose_grad
- api : copy_to - api : copy_to
...@@ -1556,8 +1558,20 @@ ...@@ -1556,8 +1558,20 @@
func : PoolInferMeta func : PoolInferMeta
kernel : kernel :
func : pool2d func : pool2d
use_gpudnn : true
backward : pool2d_grad 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 - 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) 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) output : Tensor(out)
...@@ -1565,6 +1579,7 @@ ...@@ -1565,6 +1579,7 @@
func : PoolInferMeta func : PoolInferMeta
kernel : kernel :
func : pool3d func : pool3d
use_gpudnn : true
backward : pool3d_grad backward : pool3d_grad
- api : pow - api : pow
...@@ -1923,6 +1938,7 @@ ...@@ -1923,6 +1938,7 @@
func : SoftmaxInferMeta func : SoftmaxInferMeta
kernel : kernel :
func : softmax func : softmax
use_gpudnn : true
backward : softmax_grad backward : softmax_grad
- api : split - api : split
......
...@@ -238,7 +238,7 @@ class BaseAPI(object): ...@@ -238,7 +238,7 @@ class BaseAPI(object):
'backend': None, 'backend': None,
'layout': None, 'layout': None,
'data_type': None, 'data_type': None,
'use_cudnn': 'false' 'use_gpudnn': 'false'
} }
if 'backend' in kernel_config and len(kernel_config['backend']) > 0: if 'backend' in kernel_config and len(kernel_config['backend']) > 0:
kernel['backend'] = kernel_config['backend'] kernel['backend'] = kernel_config['backend']
...@@ -248,10 +248,10 @@ class BaseAPI(object): ...@@ -248,10 +248,10 @@ class BaseAPI(object):
kernel['data_type'] = kernel_config['data_type'] kernel['data_type'] = kernel_config['data_type']
if 'param' in kernel_config: if 'param' in kernel_config:
kernel['param'] = kernel_config['param'] kernel['param'] = kernel_config['param']
if 'use_cudnn' in kernel_config: if 'use_gpudnn' in kernel_config:
kernel['use_cudnn'] = kernel_config['use_cudnn'] kernel['use_gpudnn'] = kernel_config['use_gpudnn']
if isinstance(kernel['use_cudnn'], bool): if isinstance(kernel['use_gpudnn'], bool):
kernel['use_cudnn'] = str(kernel['use_cudnn']).lower() kernel['use_gpudnn'] = str(kernel['use_gpudnn']).lower()
kernel['func'] = [ kernel['func'] = [
kernel_fn.strip() for kernel_fn in kernel_config['func'].split(',') 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 ...@@ -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) self.outputs['types'], 'SetKernelOutput', code_indent, inplace_flag)
api_func_name = self.get_api_func_name() + ('_' if inplace_flag else '') api_func_name = self.get_api_func_name() + ('_' if inplace_flag else '')
cudnn_args = '' if self.kernel[ cudnn_args = '' if self.kernel[
'use_cudnn'] == 'false' else ', ' + self.kernel['use_cudnn'] 'use_gpudnn'] == 'false' else ', ' + self.kernel['use_gpudnn']
return f""" return f"""
{code_indent} VLOG(6) << "{self.api} API kernel key: [" << kernel_backend << ", " << kernel_layout << ", "<< kernel_data_type << "]"; {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( {code_indent} const auto& kernel = phi::KernelFactory::Instance().SelectKernelOrThrowError(
......
...@@ -272,7 +272,7 @@ ...@@ -272,7 +272,7 @@
param: [input, filter, grad_out] param: [input, filter, grad_out]
kernel : kernel :
func : conv2d_grad_grad func : conv2d_grad_grad
use_cudnn : true use_gpudnn : true
optional : grad_input_grad, grad_filter_grad optional : grad_input_grad, grad_filter_grad
- backward_api : conv2d_transpose_grad - backward_api : conv2d_transpose_grad
...@@ -283,6 +283,7 @@ ...@@ -283,6 +283,7 @@
func : ConvTransposeGradInferMeta func : ConvTransposeGradInferMeta
kernel : kernel :
func : conv2d_transpose_grad func : conv2d_transpose_grad
use_gpudnn : true
- backward_api : conv3d_transpose_grad - 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) 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 @@ ...@@ -292,6 +293,7 @@
func : ConvTransposeGradInferMeta func : ConvTransposeGradInferMeta
kernel : kernel :
func : conv3d_transpose_grad func : conv3d_transpose_grad
use_gpudnn : true
- backward_api : cos_grad - backward_api : cos_grad
forward : cos (Tensor x) -> Tensor(out) forward : cos (Tensor x) -> Tensor(out)
...@@ -1234,6 +1236,17 @@ ...@@ -1234,6 +1236,17 @@
func : PoolGradInferMeta func : PoolGradInferMeta
kernel : kernel :
func : pool2d_grad 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 - 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) 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 @@ ...@@ -1243,6 +1256,7 @@
func : PoolGradInferMeta func : PoolGradInferMeta
kernel : kernel :
func : pool3d_grad func : pool3d_grad
use_gpudnn : true
- backward_api : pow_grad - backward_api : pow_grad
forward : pow(Tensor x, Scalar s) -> Tensor(out) forward : pow(Tensor x, Scalar s) -> Tensor(out)
...@@ -1578,6 +1592,7 @@ ...@@ -1578,6 +1592,7 @@
param : [out] param : [out]
kernel : kernel :
func : softmax_grad func : softmax_grad
use_gpudnn : true
- backward_api : split_grad - backward_api : split_grad
forward : split (Tensor x, IntArray num_or_sections, Scalar axis) -> Tensor[](out) forward : split (Tensor x, IntArray num_or_sections, Scalar axis) -> Tensor[](out)
......
...@@ -141,7 +141,8 @@ def generate_wrapped_infermeta_and_register(api_yaml_path, header_file_path, ...@@ -141,7 +141,8 @@ def generate_wrapped_infermeta_and_register(api_yaml_path, header_file_path,
api_item) api_item)
header_file.write(declare_code) header_file.write(declare_code)
source_file.write(defind_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]) header_file.write(namespace[1])
source_file.write(namespace[1]) source_file.write(namespace[1])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册