未验证 提交 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,
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() &&
......
......@@ -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,
......
......@@ -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,
......
......@@ -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
......
......@@ -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(
......
......@@ -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)
......
......@@ -141,6 +141,7 @@ def generate_wrapped_infermeta_and_register(api_yaml_path, header_file_path,
api_item)
header_file.write(declare_code)
source_file.write(defind_code)
if infermeta_register_code.find(register_code) == -1:
infermeta_register_code = infermeta_register_code + register_code
header_file.write(namespace[1])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册