Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
41f15537
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
41f15537
编写于
11月 29, 2022
作者:
H
HongyuJia
提交者:
GitHub
11月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename use_cudnn to use_gpudnn in phi (#48443)
上级
a559a664
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
40 addition
and
40 deletion
+40
-40
paddle/fluid/pybind/eager_method.cc
paddle/fluid/pybind/eager_method.cc
+12
-12
paddle/phi/api/lib/kernel_dispatch.cc
paddle/phi/api/lib/kernel_dispatch.cc
+2
-2
paddle/phi/api/lib/kernel_dispatch.h
paddle/phi/api/lib/kernel_dispatch.h
+4
-4
paddle/phi/core/dense_tensor.cc
paddle/phi/core/dense_tensor.cc
+1
-1
paddle/phi/core/dense_tensor_impl.cc
paddle/phi/core/dense_tensor_impl.cc
+1
-1
paddle/phi/core/tensor_meta.cc
paddle/phi/core/tensor_meta.cc
+4
-4
paddle/phi/core/tensor_meta.h
paddle/phi/core/tensor_meta.h
+3
-3
python/paddle/fluid/dygraph/nn.py
python/paddle/fluid/dygraph/nn.py
+1
-1
python/paddle/fluid/dygraph/varbase_patch_methods.py
python/paddle/fluid/dygraph/varbase_patch_methods.py
+3
-3
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+1
-1
python/paddle/fluid/tests/unittests/test_egr_python_api.py
python/paddle/fluid/tests/unittests/test_egr_python_api.py
+4
-4
python/paddle/nn/functional/pooling.py
python/paddle/nn/functional/pooling.py
+3
-3
python/paddle/nn/functional/vision.py
python/paddle/nn/functional/vision.py
+1
-1
未找到文件。
paddle/fluid/pybind/eager_method.cc
浏览文件 @
41f15537
...
...
@@ -1450,28 +1450,28 @@ static PyObject* tensor__copy_gradient_from(TensorObject* self,
EAGER_CATCH_AND_THROW_RETURN_NULL
}
static
PyObject
*
tensor__use_
c
udnn
(
TensorObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
static
PyObject
*
tensor__use_
gp
udnn
(
TensorObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
EAGER_TRY
PADDLE_ENFORCE
(
self
->
tensor
.
defined
()
&&
self
->
tensor
.
is_dense_tensor
(),
paddle
::
platform
::
errors
::
Fatal
(
"function _use_
c
udnn is only effective for DenseTensor"
));
"function _use_
gp
udnn is only effective for DenseTensor"
));
bool
use_
c
udnn
=
pybind
::
CastPyArg2AttrBoolean
(
PyTuple_GET_ITEM
(
args
,
0
),
0
);
bool
use_
gp
udnn
=
pybind
::
CastPyArg2AttrBoolean
(
PyTuple_GET_ITEM
(
args
,
0
),
0
);
// Set the same use_
c
udnn attribute, return directly
// Set the same use_
gp
udnn attribute, return directly
phi
::
DenseTensor
*
dense_tensor
=
static_cast
<
phi
::
DenseTensor
*>
(
self
->
tensor
.
impl
().
get
());
phi
::
DenseTensorMeta
*
dense_tensor_meta
=
phi
::
DenseTensorUtils
::
GetMutableMeta
(
dense_tensor
);
if
(
use_
cudnn
==
dense_tensor_meta
->
use_c
udnn
)
{
if
(
use_
gpudnn
==
dense_tensor_meta
->
use_gp
udnn
)
{
return
ToPyObject
(
self
->
tensor
);
}
// Share all other members of Tensor except use_
c
udnn
// Share all other members of Tensor except use_
gp
udnn
phi
::
DenseTensorMeta
target_dense_meta
=
*
dense_tensor_meta
;
target_dense_meta
.
use_
cudnn
=
use_c
udnn
;
target_dense_meta
.
use_
gpudnn
=
use_gp
udnn
;
phi
::
DenseTensor
target_dense_tensor
;
target_dense_tensor
.
ShareDataWith
(
*
dense_tensor
);
target_dense_tensor
.
set_meta
(
target_dense_meta
);
...
...
@@ -1481,7 +1481,7 @@ static PyObject* tensor__use_cudnn(TensorObject* self,
self
->
tensor
.
name
());
target_tensor
.
set_autograd_meta
(
self
->
tensor
.
mutable_autograd_meta
());
VLOG
(
4
)
<<
"Tensor: "
<<
target_tensor
.
name
()
<<
" set use_
cudnn = "
<<
use_c
udnn
;
<<
" set use_
gpudnn = "
<<
use_gp
udnn
;
return
ToPyObject
(
target_tensor
);
EAGER_CATCH_AND_THROW_RETURN_NULL
...
...
@@ -2053,8 +2053,8 @@ PyMethodDef variable_methods[] = {
(
PyCFunction
)(
void
(
*
)(
void
))
tensor__copy_gradient_from
,
METH_VARARGS
|
METH_KEYWORDS
,
NULL
},
{
"_tensor_use_
c
udnn"
,
(
PyCFunction
)(
void
(
*
)(
void
))
tensor__use_
c
udnn
,
{
"_tensor_use_
gp
udnn"
,
(
PyCFunction
)(
void
(
*
)(
void
))
tensor__use_
gp
udnn
,
METH_VARARGS
|
METH_KEYWORDS
,
NULL
},
/** the methods to adapt old dygraph, will be removed in the future **/
...
...
paddle/phi/api/lib/kernel_dispatch.cc
浏览文件 @
41f15537
...
...
@@ -57,7 +57,7 @@ BackendSet GetTensorBackendSet(const phi::TensorBase& t) {
phi
::
Backend
backend_key
=
phi
::
TransToPhiBackend
(
t
.
place
());
BackendSet
backend_set
(
backend_key
);
if
(
backend_key
==
Backend
::
GPU
&&
phi
::
DenseTensor
::
classof
(
&
t
)
&&
static_cast
<
const
phi
::
DenseTensor
&>
(
t
).
meta
().
use_
c
udnn
)
{
static_cast
<
const
phi
::
DenseTensor
&>
(
t
).
meta
().
use_
gp
udnn
)
{
backend_set
=
backend_set
|
BackendSet
(
Backend
::
GPUDNN
);
}
return
backend_set
;
...
...
@@ -126,7 +126,7 @@ Backend ParseBackend(const Tensor& tensor) {
Backend
backend_key
=
phi
::
TransToPhiBackend
(
tensor
.
place
());
if
(
backend_key
==
Backend
::
GPU
&&
phi
::
DenseTensor
::
classof
(
tensor
.
impl
().
get
())
&&
static_cast
<
phi
::
DenseTensor
*>
(
tensor
.
impl
().
get
())
->
meta
().
use_
c
udnn
)
{
static_cast
<
phi
::
DenseTensor
*>
(
tensor
.
impl
().
get
())
->
meta
().
use_
gp
udnn
)
{
return
Backend
::
GPUDNN
;
}
return
backend_key
;
...
...
paddle/phi/api/lib/kernel_dispatch.h
浏览文件 @
41f15537
...
...
@@ -90,7 +90,7 @@ struct ArgsIterator {
struct
KernelKeyParser
:
ArgsIterator
<
KernelKeyParser
>
{
KernelKeySet
key_set
;
bool
disable_
c
udnn
=
false
;
bool
disable_
gp
udnn
=
false
;
// this dtype_set is used for cache multi-inputs dtype and used for
// data_promote
DataTypeSet
dtype_set
{
DataType
::
UNDEFINED
};
...
...
@@ -101,9 +101,9 @@ struct KernelKeyParser : ArgsIterator<KernelKeyParser> {
// assign Backend
BackendSet
tensor_backend_set
=
detail
::
GetTensorBackendSet
(
tensor
);
key_set
.
backend_set
=
key_set
.
backend_set
|
tensor_backend_set
;
// tensor's attribute use_
cudnn=False, explicitly disable c
udnn kernel
if
(
tensor_backend_set
==
BackendSet
(
Backend
::
GPU
)
||
disable_
c
udnn
)
{
disable_
c
udnn
=
true
;
// tensor's attribute use_
gpudnn=False, explicitly disable gp
udnn kernel
if
(
tensor_backend_set
==
BackendSet
(
Backend
::
GPU
)
||
disable_
gp
udnn
)
{
disable_
gp
udnn
=
true
;
key_set
.
backend_set
=
key_set
.
backend_set
-
BackendSet
(
Backend
::
GPUDNN
);
}
// assign DataLayout
...
...
paddle/phi/core/dense_tensor.cc
浏览文件 @
41f15537
...
...
@@ -200,7 +200,7 @@ void DenseTensor::set_meta(const DenseTensorMeta& meta) {
meta_
.
layout
=
meta
.
layout
;
meta_
.
lod
=
meta
.
lod
;
meta_
.
offset
=
meta
.
offset
;
meta_
.
use_
cudnn
=
meta
.
use_c
udnn
;
meta_
.
use_
gpudnn
=
meta
.
use_gp
udnn
;
}
/* @jim19930609: This interface will be further modified until we finalized the
...
...
paddle/phi/core/dense_tensor_impl.cc
浏览文件 @
41f15537
...
...
@@ -357,7 +357,7 @@ DenseTensor& DenseTensor::ShareDataWith(const DenseTensor& src) {
meta_
.
dtype
=
src
.
meta_
.
dtype
;
meta_
.
layout
=
src
.
meta_
.
layout
;
meta_
.
offset
=
src
.
meta_
.
offset
;
meta_
.
use_
cudnn
=
src
.
meta_
.
use_c
udnn
;
meta_
.
use_
gpudnn
=
src
.
meta_
.
use_gp
udnn
;
storage_properties_
=
std
::
move
(
CopyStorageProperties
(
src
.
storage_properties_
));
#ifdef PADDLE_WITH_MKLDNN
...
...
paddle/phi/core/tensor_meta.cc
浏览文件 @
41f15537
...
...
@@ -16,11 +16,11 @@ limitations under the License. */
namespace
phi
{
DenseTensorMeta
::
DenseTensorMeta
()
{
use_
c
udnn
=
true
;
}
DenseTensorMeta
::
DenseTensorMeta
()
{
use_
gp
udnn
=
true
;
}
DenseTensorMeta
::
DenseTensorMeta
(
DataType
dtype
,
const
DDim
&
dims
)
:
dims
(
dims
),
dtype
(
dtype
)
{
use_
c
udnn
=
true
;
use_
gp
udnn
=
true
;
}
DenseTensorMeta
::
DenseTensorMeta
(
DataType
dtype
,
...
...
@@ -28,7 +28,7 @@ DenseTensorMeta::DenseTensorMeta(DataType dtype,
DataLayout
layout
,
size_t
offset
)
:
dims
(
dims
),
dtype
(
dtype
),
layout
(
layout
),
offset
(
offset
)
{
use_
c
udnn
=
true
;
use_
gp
udnn
=
true
;
}
DenseTensorMeta
::
DenseTensorMeta
(
DataType
dtype
,
...
...
@@ -37,7 +37,7 @@ DenseTensorMeta::DenseTensorMeta(DataType dtype,
const
LoD
&
lod
,
size_t
offset
)
:
dims
(
dims
),
dtype
(
dtype
),
layout
(
layout
),
lod
(
lod
),
offset
(
offset
)
{
use_
c
udnn
=
true
;
use_
gp
udnn
=
true
;
}
bool
DenseTensorMeta
::
valid
()
const
noexcept
{
...
...
paddle/phi/core/tensor_meta.h
浏览文件 @
41f15537
...
...
@@ -65,9 +65,9 @@ struct DenseTensorMeta {
bool
valid
()
const
noexcept
;
bool
is_scalar
{
false
};
/// \brief Determine whether using
CuDNN
speed-up library in the new dygraph.
/// \brief Determine whether using
gpudnn
speed-up library in the new dygraph.
/// It maybe also support MKLDNN library in the near future.
bool
use_
c
udnn
{
true
};
bool
use_
gp
udnn
{
true
};
DDim
dims
;
DataType
dtype
{
DataType
::
UNDEFINED
};
DataLayout
layout
{
DataLayout
::
NCHW
};
...
...
@@ -76,7 +76,7 @@ struct DenseTensorMeta {
};
inline
bool
operator
==
(
const
DenseTensorMeta
&
lhs
,
const
DenseTensorMeta
&
rhs
)
{
return
(
lhs
.
is_scalar
==
rhs
.
is_scalar
)
&&
lhs
.
use_
cudnn
==
rhs
.
use_c
udnn
&&
return
(
lhs
.
is_scalar
==
rhs
.
is_scalar
)
&&
lhs
.
use_
gpudnn
==
rhs
.
use_gp
udnn
&&
(
lhs
.
dims
==
rhs
.
dims
)
&&
(
lhs
.
dtype
==
rhs
.
dtype
)
&&
(
lhs
.
layout
==
rhs
.
layout
)
&&
(
lhs
.
lod
==
rhs
.
lod
)
&&
(
lhs
.
offset
==
rhs
.
offset
);
...
...
python/paddle/fluid/dygraph/nn.py
浏览文件 @
41f15537
...
...
@@ -671,7 +671,7 @@ class Pool2D(layers.Layer):
def
forward
(
self
,
input
):
if
_non_static_mode
():
if
not
self
.
_use_mkldnn
and
in_dygraph_mode
():
input
=
input
.
_use_
c
udnn
(
self
.
_use_cudnn
)
input
=
input
.
_use_
gp
udnn
(
self
.
_use_cudnn
)
return
_C_ops
.
pool2d
(
input
,
self
.
_pool_size
,
...
...
python/paddle/fluid/dygraph/varbase_patch_methods.py
浏览文件 @
41f15537
...
...
@@ -886,8 +886,8 @@ def monkey_patch_varbase():
self
.
get_tensor
().
_clear
()
@
framework
.
dygraph_only
def
_use_
cudnn
(
self
,
use_c
udnn
=
True
):
return
self
.
_tensor_use_
cudnn
(
use_c
udnn
)
def
_use_
gpudnn
(
self
,
use_gp
udnn
=
True
):
return
self
.
_tensor_use_
gpudnn
(
use_gp
udnn
)
@
framework
.
dygraph_only
def
_uva
(
self
,
device_id
=
0
):
...
...
@@ -1073,7 +1073,7 @@ def monkey_patch_varbase():
setattr
(
core
.
eager
.
Tensor
,
"_uva"
,
_uva
)
setattr
(
core
.
eager
.
Tensor
,
"_clear_data"
,
_clear_data
)
setattr
(
core
.
eager
.
Tensor
,
"__hash__"
,
__hash__
)
setattr
(
core
.
eager
.
Tensor
,
"_use_
cudnn"
,
_use_c
udnn
)
setattr
(
core
.
eager
.
Tensor
,
"_use_
gpudnn"
,
_use_gp
udnn
)
else
:
setattr
(
core
.
VarBase
,
"__name__"
,
"Tensor"
)
setattr
(
core
.
VarBase
,
"grad"
,
grad
)
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
41f15537
...
...
@@ -1852,7 +1852,7 @@ def pool2d(
pool_padding
=
update_padding
(
pool_padding
,
data_format
)
if
in_dygraph_mode
():
input
=
input
.
_use_
c
udnn
(
use_cudnn
)
input
=
input
.
_use_
gp
udnn
(
use_cudnn
)
return
_C_ops
.
pool2d
(
input
,
pool_size
,
...
...
python/paddle/fluid/tests/unittests/test_egr_python_api.py
浏览文件 @
41f15537
...
...
@@ -899,20 +899,20 @@ class EagerVariablePropertiesAndMethodsTestCase(unittest.TestCase):
x
.
_clear
()
self
.
assertFalse
(
x
.
_is_initialized
())
def
test_use_
c
udnn
(
self
):
def
test_use_
gp
udnn
(
self
):
np_x
=
np
.
random
.
random
((
3
,
8
,
8
))
with
_test_eager_guard
():
self
.
assertTrue
(
in_dygraph_mode
())
x
=
paddle
.
to_tensor
(
np_x
,
dtype
=
"float64"
)
y
=
x
.
_use_
c
udnn
(
False
)
y
=
x
.
_use_
gp
udnn
(
False
)
np
.
testing
.
assert_array_equal
(
x
.
numpy
(),
y
.
numpy
())
y
=
x
.
_use_
c
udnn
(
True
)
y
=
x
.
_use_
gp
udnn
(
True
)
np
.
testing
.
assert_array_equal
(
x
.
numpy
(),
y
.
numpy
())
self
.
assertFalse
(
in_dygraph_mode
())
x
=
paddle
.
to_tensor
(
np_x
,
dtype
=
"float64"
)
with
self
.
assertRaises
(
AttributeError
):
x
=
x
.
_use_
c
udnn
(
False
)
x
=
x
.
_use_
gp
udnn
(
False
)
class
EagerParamBaseUsageTestCase
(
unittest
.
TestCase
):
...
...
python/paddle/nn/functional/pooling.py
浏览文件 @
41f15537
...
...
@@ -1690,7 +1690,7 @@ def adaptive_avg_pool1d(x, output_size, name=None):
x
=
unsqueeze
(
x
,
[
2
])
if
in_dygraph_mode
():
x
=
x
.
_use_
c
udnn
(
False
)
x
=
x
.
_use_
gp
udnn
(
False
)
pool_out
=
_C_ops
.
pool2d
(
x
,
pool_size
,
...
...
@@ -1827,7 +1827,7 @@ def adaptive_avg_pool2d(x, output_size, data_format='NCHW', name=None):
output_size
=
utils
.
_convert_to_tensor_list
(
output_size
)
if
in_dygraph_mode
():
x
=
x
.
_use_
c
udnn
(
False
)
x
=
x
.
_use_
gp
udnn
(
False
)
return
_C_ops
.
pool2d
(
x
,
output_size
,
...
...
@@ -1972,7 +1972,7 @@ def adaptive_avg_pool3d(x, output_size, data_format='NCDHW', name=None):
output_size
[
2
]
=
in_w
if
in_dygraph_mode
():
x
=
x
.
_use_
c
udnn
(
False
)
x
=
x
.
_use_
gp
udnn
(
False
)
return
_C_ops
.
pool3d
(
x
,
output_size
,
...
...
python/paddle/nn/functional/vision.py
浏览文件 @
41f15537
...
...
@@ -91,7 +91,7 @@ def affine_grid(theta, out_shape, align_corners=True, name=None):
if
isinstance
(
out_shape
,
Variable
)
else
out_shape
)
theta
=
theta
.
_use_
c
udnn
(
use_cudnn
)
theta
=
theta
.
_use_
gp
udnn
(
use_cudnn
)
return
_C_ops
.
affine_grid
(
theta
,
_out_shape
,
align_corners
)
elif
in_dynamic_mode
():
_out_shape
=
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录