Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
这是一个图像
Paddle
提交
134eaf21
P
Paddle
项目概览
这是一个图像
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
134eaf21
编写于
11月 20, 2017
作者:
C
chengduo
提交者:
GitHub
11月 20, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5602 from chengduoZH/add_cudnn_pool3d
Add cudnn pool3d
上级
f350be3e
3bd3cc0c
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
235 addition
and
180 deletion
+235
-180
paddle/operators/conv_cudnn_op.cc
paddle/operators/conv_cudnn_op.cc
+4
-3
paddle/operators/conv_cudnn_op.cu.cc
paddle/operators/conv_cudnn_op.cu.cc
+4
-2
paddle/operators/conv_transpose_cudnn_op.cc
paddle/operators/conv_transpose_cudnn_op.cc
+8
-4
paddle/operators/conv_transpose_cudnn_op.cu.cc
paddle/operators/conv_transpose_cudnn_op.cu.cc
+8
-4
paddle/operators/pool_cudnn_op.cc
paddle/operators/pool_cudnn_op.cc
+14
-2
paddle/operators/pool_cudnn_op.cu.cc
paddle/operators/pool_cudnn_op.cu.cc
+23
-4
paddle/operators/pool_op.cc
paddle/operators/pool_op.cc
+8
-4
paddle/operators/pool_op.cu.cc
paddle/operators/pool_op.cu.cc
+8
-4
paddle/operators/pool_with_index_op.cc
paddle/operators/pool_with_index_op.cc
+8
-4
paddle/operators/pool_with_index_op.cu.cc
paddle/operators/pool_with_index_op.cu.cc
+8
-4
paddle/platform/cudnn_helper.h
paddle/platform/cudnn_helper.h
+4
-2
paddle/platform/cudnn_helper_test.cc
paddle/platform/cudnn_helper_test.cc
+34
-0
python/paddle/v2/fluid/tests/test_pool2d_op.py
python/paddle/v2/fluid/tests/test_pool2d_op.py
+26
-108
python/paddle/v2/fluid/tests/test_pool3d_op.py
python/paddle/v2/fluid/tests/test_pool3d_op.py
+78
-35
未找到文件。
paddle/operators/conv_cudnn_op.cc
浏览文件 @
134eaf21
...
...
@@ -40,7 +40,8 @@ REGISTER_OP(conv_cudnn, ops::ConvOp, ops::CudnnConvOpMaker, conv_cudnn_grad,
ops
::
ConvOpGrad
);
REGISTER_OP_CPU_KERNEL
(
conv_cudnn
,
ops
::
GemmConvKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
GemmConvKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
GemmConvKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
conv_cudnn_grad
,
ops
::
GemmConvGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
conv_cudnn_grad
,
ops
::
GemmConvGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
GemmConvGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
paddle/operators/conv_cudnn_op.cu.cc
浏览文件 @
134eaf21
...
...
@@ -259,6 +259,8 @@ class CudnnConvGradOpKernel : public framework::OpKernel<T> {
}
// namespace operators
}
// namespace paddle
REGISTER_OP_GPU_KERNEL
(
conv_cudnn
,
paddle
::
operators
::
CudnnConvOpKernel
<
float
>
);
REGISTER_OP_GPU_KERNEL
(
conv_cudnn
,
paddle
::
operators
::
CudnnConvOpKernel
<
float
>
,
paddle
::
operators
::
CudnnConvOpKernel
<
double
>
);
REGISTER_OP_GPU_KERNEL
(
conv_cudnn_grad
,
paddle
::
operators
::
CudnnConvGradOpKernel
<
float
>
);
paddle
::
operators
::
CudnnConvGradOpKernel
<
float
>
,
paddle
::
operators
::
CudnnConvGradOpKernel
<
double
>
);
paddle/operators/conv_transpose_cudnn_op.cc
浏览文件 @
134eaf21
...
...
@@ -61,10 +61,12 @@ REGISTER_OP(conv2d_transpose_cudnn, ops::ConvTransposeOp,
REGISTER_OP_CPU_KERNEL
(
conv2d_transpose_cudnn
,
ops
::
GemmConvTransposeKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
GemmConvTransposeKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
GemmConvTransposeKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
conv2d_transpose_cudnn_grad
,
ops
::
GemmConvTransposeGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
GemmConvTransposeGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
GemmConvTransposeGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP
(
conv3d_transpose_cudnn
,
ops
::
ConvTransposeOp
,
ops
::
CudnnConv3DTransposeOpMaker
,
conv3d_transpose_cudnn_grad
,
...
...
@@ -72,7 +74,9 @@ REGISTER_OP(conv3d_transpose_cudnn, ops::ConvTransposeOp,
REGISTER_OP_CPU_KERNEL
(
conv3d_transpose_cudnn
,
ops
::
GemmConvTransposeKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
GemmConvTransposeKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
GemmConvTransposeKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
conv3d_transpose_cudnn_grad
,
ops
::
GemmConvTransposeGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
GemmConvTransposeGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
GemmConvTransposeGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
paddle/operators/conv_transpose_cudnn_op.cu.cc
浏览文件 @
134eaf21
...
...
@@ -235,11 +235,15 @@ class CudnnConvTransposeGradOpKernel : public framework::OpKernel<T> {
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
conv2d_transpose_cudnn
,
ops
::
CudnnConvTransposeOpKernel
<
float
>
);
ops
::
CudnnConvTransposeOpKernel
<
float
>
,
ops
::
CudnnConvTransposeOpKernel
<
double
>
);
REGISTER_OP_GPU_KERNEL
(
conv2d_transpose_cudnn_grad
,
ops
::
CudnnConvTransposeGradOpKernel
<
float
>
);
ops
::
CudnnConvTransposeGradOpKernel
<
float
>
,
ops
::
CudnnConvTransposeGradOpKernel
<
double
>
);
REGISTER_OP_GPU_KERNEL
(
conv3d_transpose_cudnn
,
ops
::
CudnnConvTransposeOpKernel
<
float
>
);
ops
::
CudnnConvTransposeOpKernel
<
float
>
,
ops
::
CudnnConvTransposeOpKernel
<
double
>
);
REGISTER_OP_GPU_KERNEL
(
conv3d_transpose_cudnn_grad
,
ops
::
CudnnConvTransposeGradOpKernel
<
float
>
);
ops
::
CudnnConvTransposeGradOpKernel
<
float
>
,
ops
::
CudnnConvTransposeGradOpKernel
<
double
>
);
paddle/operators/pool_cudnn_op.cc
浏览文件 @
134eaf21
...
...
@@ -20,6 +20,18 @@ REGISTER_OP(pool2d_cudnn, ops::PoolOp, ops::Pool2dOpMaker, pool2d_cudnn_grad,
ops
::
PoolOpGrad
);
REGISTER_OP_CPU_KERNEL
(
pool2d_cudnn
,
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
pool2d_cudnn_grad
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
)
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
)
REGISTER_OP
(
pool3d_cudnn
,
ops
::
PoolOp
,
ops
::
Pool3dOpMaker
,
pool3d_cudnn_grad
,
ops
::
PoolOpGrad
);
REGISTER_OP_CPU_KERNEL
(
pool3d_cudnn
,
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
pool3d_cudnn_grad
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
)
paddle/operators/pool_cudnn_op.cu.cc
浏览文件 @
134eaf21
...
...
@@ -52,7 +52,13 @@ class PoolCudnnOpKernel : public framework::OpKernel<T> {
ScopedTensorDescriptor
input_desc
;
ScopedTensorDescriptor
output_desc
;
ScopedPoolingDescriptor
pool_desc
;
DataLayout
layout
=
DataLayout
::
kNCHW
;
DataLayout
layout
;
if
(
strides
.
size
()
==
2U
)
{
layout
=
DataLayout
::
kNCHW
;
}
else
{
layout
=
DataLayout
::
kNCDHW
;
}
cudnnTensorDescriptor_t
cudnn_input_desc
=
input_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
input
->
dims
()));
...
...
@@ -112,7 +118,13 @@ class PoolCudnnGradOpKernel : public framework::OpKernel<T> {
ScopedTensorDescriptor
input_desc
;
ScopedTensorDescriptor
output_desc
;
ScopedPoolingDescriptor
pool_desc
;
DataLayout
layout
=
DataLayout
::
kNCHW
;
DataLayout
layout
;
if
(
strides
.
size
()
==
2U
)
{
layout
=
DataLayout
::
kNCHW
;
}
else
{
layout
=
DataLayout
::
kNCDHW
;
}
cudnnTensorDescriptor_t
cudnn_input_desc
=
input_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
input
->
dims
()));
...
...
@@ -150,5 +162,12 @@ class PoolCudnnGradOpKernel : public framework::OpKernel<T> {
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
pool2d_cudnn
,
ops
::
PoolCudnnOpKernel
<
float
>
);
REGISTER_OP_GPU_KERNEL
(
pool2d_cudnn_grad
,
ops
::
PoolCudnnGradOpKernel
<
float
>
);
REGISTER_OP_GPU_KERNEL
(
pool2d_cudnn
,
ops
::
PoolCudnnOpKernel
<
float
>
,
ops
::
PoolCudnnOpKernel
<
double
>
);
REGISTER_OP_GPU_KERNEL
(
pool2d_cudnn_grad
,
ops
::
PoolCudnnGradOpKernel
<
float
>
,
ops
::
PoolCudnnGradOpKernel
<
double
>
);
REGISTER_OP_GPU_KERNEL
(
pool3d_cudnn
,
ops
::
PoolCudnnOpKernel
<
float
>
,
ops
::
PoolCudnnOpKernel
<
double
>
);
REGISTER_OP_GPU_KERNEL
(
pool3d_cudnn_grad
,
ops
::
PoolCudnnGradOpKernel
<
float
>
,
ops
::
PoolCudnnGradOpKernel
<
double
>
);
paddle/operators/pool_op.cc
浏览文件 @
134eaf21
...
...
@@ -217,14 +217,18 @@ REGISTER_OP(pool2d, ops::PoolOp, ops::Pool2dOpMaker, pool2d_grad,
ops
::
PoolOpGrad
);
REGISTER_OP_CPU_KERNEL
(
pool2d
,
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
pool2d_grad
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
)
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
)
REGISTER_OP
(
pool3d
,
ops
::
PoolOp
,
ops
::
Pool3dOpMaker
,
pool3d_grad
,
ops
::
PoolOpGrad
);
REGISTER_OP_CPU_KERNEL
(
pool3d
,
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
PoolKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
pool3d_grad
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
paddle/operators/pool_op.cu.cc
浏览文件 @
134eaf21
...
...
@@ -17,11 +17,15 @@ limitations under the License. */
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
pool2d
,
ops
::
PoolKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
PoolKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
,
ops
::
PoolKernel
<
paddle
::
platform
::
GPUPlace
,
double
>
);
REGISTER_OP_GPU_KERNEL
(
pool2d_grad
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
PoolGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
GPUPlace
,
double
>
);
REGISTER_OP_GPU_KERNEL
(
pool3d
,
ops
::
PoolKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
PoolKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
,
ops
::
PoolKernel
<
paddle
::
platform
::
GPUPlace
,
double
>
);
REGISTER_OP_GPU_KERNEL
(
pool3d_grad
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
PoolGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
,
ops
::
PoolGradKernel
<
paddle
::
platform
::
GPUPlace
,
double
>
);
paddle/operators/pool_with_index_op.cc
浏览文件 @
134eaf21
...
...
@@ -250,10 +250,12 @@ REGISTER_OP(max_pool2d_with_index, ops::MaxPoolWithIndexOp,
REGISTER_OP_CPU_KERNEL
(
max_pool2d_with_index
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
max_pool2d_with_index_grad
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
)
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
)
REGISTER_OP
(
max_pool3d_with_index
,
ops
::
MaxPoolWithIndexOp
,
ops
::
MaxPool3dWithIndexOpMaker
,
max_pool3d_with_index_grad
,
...
...
@@ -261,7 +263,9 @@ REGISTER_OP(max_pool3d_with_index, ops::MaxPoolWithIndexOp,
REGISTER_OP_CPU_KERNEL
(
max_pool3d_with_index
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
max_pool3d_with_index_grad
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
)
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
)
paddle/operators/pool_with_index_op.cu.cc
浏览文件 @
134eaf21
...
...
@@ -18,14 +18,18 @@ namespace ops = paddle::operators;
REGISTER_OP_GPU_KERNEL
(
max_pool2d_with_index
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
GPUPlace
,
double
>
);
REGISTER_OP_GPU_KERNEL
(
max_pool2d_with_index_grad
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
)
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
GPUPlace
,
double
>
)
REGISTER_OP_GPU_KERNEL
(
max_pool3d_with_index
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
GPUPlace
,
double
>
);
REGISTER_OP_GPU_KERNEL
(
max_pool3d_with_index_grad
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
)
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
GPUPlace
,
double
>
)
paddle/platform/cudnn_helper.h
浏览文件 @
134eaf21
...
...
@@ -224,13 +224,15 @@ class ScopedConvolutionDescriptor {
PADDLE_ENFORCE_EQ
(
pads
.
size
(),
strides
.
size
());
PADDLE_ENFORCE_EQ
(
pads
.
size
(),
dilations
.
size
());
#if
CUDNN_VERSION < 6000
#if
!CUDNN_VERSION_MIN(6, 0, 0)
// cudnn v5 does not support dilation conv, the argument is called upscale
// instead of dilations and it is must be one.
for
(
size_t
i
=
0
;
i
<
dilations
.
size
();
++
i
)
{
PADDLE_ENFORCE_EQ
(
dilations
[
i
],
1
,
"Dilations conv is not supported in this cuDNN version"
);
"Dilations conv is not supported in this cuDNN version(%d.%d.%d)."
,
CUDNN_VERSION
/
1000
,
CUDNN_VERSION
%
1000
/
100
,
CUDNN_VERSION
%
100
);
}
#endif
...
...
paddle/platform/cudnn_helper_test.cc
浏览文件 @
134eaf21
...
...
@@ -38,6 +38,26 @@ TEST(CudnnHelper, ScopedTensorDescriptor) {
EXPECT_EQ
(
strides
[
2
],
6
);
EXPECT_EQ
(
strides
[
1
],
36
);
EXPECT_EQ
(
strides
[
0
],
144
);
// test tensor5d: ScopedTensorDescriptor
ScopedTensorDescriptor
tensor5d_desc
;
std
::
vector
<
int
>
shape_5d
=
{
2
,
4
,
6
,
6
,
6
};
auto
desc_5d
=
tensor5d_desc
.
descriptor
<
float
>
(
DataLayout
::
kNCDHW
,
shape_5d
);
std
::
vector
<
int
>
dims_5d
(
5
);
std
::
vector
<
int
>
strides_5d
(
5
);
paddle
::
platform
::
dynload
::
cudnnGetTensorNdDescriptor
(
desc_5d
,
5
,
&
type
,
&
nd
,
dims_5d
.
data
(),
strides_5d
.
data
());
EXPECT_EQ
(
nd
,
5
);
for
(
size_t
i
=
0
;
i
<
dims_5d
.
size
();
++
i
)
{
EXPECT_EQ
(
dims_5d
[
i
],
shape_5d
[
i
]);
}
EXPECT_EQ
(
strides_5d
[
4
],
1
);
EXPECT_EQ
(
strides_5d
[
3
],
6
);
EXPECT_EQ
(
strides_5d
[
2
],
36
);
EXPECT_EQ
(
strides_5d
[
1
],
216
);
EXPECT_EQ
(
strides_5d
[
0
],
864
);
}
TEST
(
CudnnHelper
,
ScopedFilterDescriptor
)
{
...
...
@@ -60,6 +80,20 @@ TEST(CudnnHelper, ScopedFilterDescriptor) {
for
(
size_t
i
=
0
;
i
<
shape
.
size
();
++
i
)
{
EXPECT_EQ
(
kernel
[
i
],
shape
[
i
]);
}
ScopedFilterDescriptor
filter_desc_4d
;
std
::
vector
<
int
>
shape_4d
=
{
2
,
3
,
3
,
3
};
auto
desc_4d
=
filter_desc
.
descriptor
<
float
>
(
DataLayout
::
kNCDHW
,
shape_4d
);
std
::
vector
<
int
>
kernel_4d
(
4
);
paddle
::
platform
::
dynload
::
cudnnGetFilterNdDescriptor
(
desc_4d
,
4
,
&
type
,
&
format
,
&
nd
,
kernel_4d
.
data
());
EXPECT_EQ
(
GetCudnnTensorFormat
(
DataLayout
::
kNCHW
),
format
);
EXPECT_EQ
(
nd
,
4
);
for
(
size_t
i
=
0
;
i
<
shape_4d
.
size
();
++
i
)
{
EXPECT_EQ
(
kernel_4d
[
i
],
shape_4d
[
i
]);
}
}
TEST
(
CudnnHelper
,
ScopedConvolutionDescriptor
)
{
...
...
python/paddle/v2/fluid/tests/test_pool2d_op.py
浏览文件 @
134eaf21
...
...
@@ -3,8 +3,7 @@ import numpy as np
from
op_test
import
OpTest
def
max_pool2D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
],
global_pool
=
0
):
def
max_pool2D_forward_naive
(
x
,
ksize
,
strides
,
paddings
,
global_pool
=
0
):
N
,
C
,
H
,
W
=
x
.
shape
if
global_pool
==
1
:
ksize
=
[
H
,
W
]
...
...
@@ -23,8 +22,7 @@ def max_pool2D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0):
return
out
def
avg_pool2D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
],
global_pool
=
0
):
def
avg_pool2D_forward_naive
(
x
,
ksize
,
strides
,
paddings
,
global_pool
=
0
):
N
,
C
,
H
,
W
=
x
.
shape
if
global_pool
==
1
:
ksize
=
[
H
,
W
]
...
...
@@ -47,6 +45,7 @@ def avg_pool2D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0):
class
TestPool2d_Op
(
OpTest
):
def
setUp
(
self
):
self
.
init_test_case
()
self
.
init_global_pool
()
self
.
init_op_type
()
self
.
init_pool_type
()
if
self
.
global_pool
:
...
...
@@ -75,8 +74,6 @@ class TestPool2d_Op(OpTest):
self
.
check_grad
(
set
([
'X'
]),
'Out'
,
max_relative_error
=
0.07
)
def
init_test_case
(
self
):
self
.
global_pool
=
True
self
.
pool2D_forward_naive
=
avg_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
...
...
@@ -87,12 +84,14 @@ class TestPool2d_Op(OpTest):
def
init_pool_type
(
self
):
self
.
pool_type
=
"avg"
self
.
pool2D_forward_naive
=
avg_pool2D_forward_naive
def
init_global_pool
(
self
):
self
.
global_pool
=
True
class
TestCase1
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
self
.
pool2D_forward_naive
=
avg_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
...
...
@@ -103,12 +102,14 @@ class TestCase1(TestPool2d_Op):
def
init_pool_type
(
self
):
self
.
pool_type
=
"avg"
self
.
pool2D_forward_naive
=
avg_pool2D_forward_naive
def
init_global_pool
(
self
):
self
.
global_pool
=
False
class
TestCase2
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
self
.
pool2D_forward_naive
=
avg_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
...
...
@@ -119,152 +120,69 @@ class TestCase2(TestPool2d_Op):
def
init_pool_type
(
self
):
self
.
pool_type
=
"avg"
self
.
pool2D_forward_naive
=
avg_pool2D_forward_naive
def
init_global_pool
(
self
):
self
.
global_pool
=
False
class
TestCase3
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
True
self
.
pool2D_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
0
,
0
]
class
TestCase3
(
TestPool2d_Op
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool2d"
def
init_pool_type
(
self
):
self
.
pool_type
=
"max"
class
TestCase4
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
self
.
pool2D_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
0
,
0
]
class
TestCase4
(
TestCase1
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool2d"
def
init_pool_type
(
self
):
self
.
pool_type
=
"max"
class
TestCase5
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
self
.
pool2D_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
1
,
1
]
class
TestCase5
(
TestCase2
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool2d"
def
init_pool_type
(
self
):
self
.
pool_type
=
"max"
self
.
pool2D_forward_naive
=
max_pool2D_forward_naive
#--------------------test pool2d_cudnn--------------------
class
TestCaseCudnn1
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
True
self
.
pool2D_forward_naive
=
avg_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
0
,
0
]
class
TestCudnnCase1
(
TestPool2d_Op
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool2d_cudnn"
def
init_pool_type
(
self
):
self
.
pool_type
=
"avg"
class
TestCaseCudnn2
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
self
.
pool2D_forward_naive
=
avg_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
0
,
0
]
class
TestCudnnCase2
(
TestCase1
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool2d_cudnn"
def
init_pool_type
(
self
):
self
.
pool_type
=
"avg"
class
TestCaseCudnn3
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
self
.
pool2D_forward_naive
=
avg_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
1
,
1
]
class
TestCudnnCase3
(
TestCase2
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool2d_cudnn"
def
init_pool_type
(
self
):
self
.
pool_type
=
"avg"
class
TestCaseCudnn4
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
True
self
.
pool2D_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
0
,
0
]
class
TestCudnnCase4
(
TestCase3
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool2d_cudnn"
def
init_pool_type
(
self
):
self
.
pool_type
=
"max"
class
TestCaseCudnn5
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
self
.
pool2D_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
0
,
0
]
class
TestCudnnCase5
(
TestCase4
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool2d_cudnn"
def
init_pool_type
(
self
):
self
.
pool_type
=
"max"
class
TestCaseCudnn6
(
TestPool2d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
self
.
pool2D_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
1
,
1
]
class
TestCudnnCase6
(
TestCase5
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool2d_cudnn"
def
init_pool_type
(
self
):
self
.
pool_type
=
"max"
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/v2/fluid/tests/test_pool3d_op.py
浏览文件 @
134eaf21
...
...
@@ -3,8 +3,7 @@ import numpy as np
from
op_test
import
OpTest
def
max_pool3D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
],
global_pool
=
0
):
def
max_pool3D_forward_naive
(
x
,
ksize
,
strides
,
paddings
,
global_pool
=
0
):
N
,
C
,
D
,
H
,
W
=
x
.
shape
if
global_pool
==
1
:
ksize
=
[
D
,
H
,
W
]
...
...
@@ -27,8 +26,7 @@ def max_pool3D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0):
return
out
def
avg_pool3D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
],
global_pool
=
0
):
def
avg_pool3D_forward_naive
(
x
,
ksize
,
strides
,
paddings
,
global_pool
=
0
):
N
,
C
,
D
,
H
,
W
=
x
.
shape
if
global_pool
==
1
:
ksize
=
[
D
,
H
,
W
]
...
...
@@ -55,6 +53,10 @@ def avg_pool3D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0):
class
TestPool3d_Op
(
OpTest
):
def
setUp
(
self
):
self
.
init_test_case
()
self
.
init_global_pool
()
self
.
init_op_type
()
self
.
init_pool_type
()
if
self
.
global_pool
:
self
.
paddings
=
[
0
for
_
in
range
(
len
(
self
.
paddings
))]
input
=
np
.
random
.
random
(
self
.
shape
).
astype
(
"float32"
)
...
...
@@ -81,74 +83,115 @@ class TestPool3d_Op(OpTest):
self
.
check_grad
(
set
([
'X'
]),
'Out'
,
max_relative_error
=
0.07
)
def
init_test_case
(
self
):
self
.
global_pool
=
True
self
.
op_type
=
"pool3d"
self
.
pool_type
=
"avg"
self
.
pool3D_forward_naive
=
avg_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
,
5
]
self
.
ksize
=
[
3
,
3
,
3
]
self
.
strides
=
[
1
,
1
,
1
]
self
.
paddings
=
[
0
,
0
,
0
]
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d"
def
init_pool_type
(
self
):
self
.
pool_type
=
"avg"
self
.
pool3D_forward_naive
=
avg_pool3D_forward_naive
def
init_global_pool
(
self
):
self
.
global_pool
=
True
class
TestCase1
(
TestPool3d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
self
.
op_type
=
"pool3d"
self
.
pool_type
=
"avg"
self
.
pool3D_forward_naive
=
avg_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
,
7
]
self
.
ksize
=
[
3
,
3
,
3
]
self
.
strides
=
[
1
,
1
,
1
]
self
.
paddings
=
[
0
,
0
,
0
]
class
TestCase2
(
TestPool3d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d"
def
init_pool_type
(
self
):
self
.
pool_type
=
"avg"
self
.
pool3D_forward_naive
=
avg_pool3D_forward_naive
def
init_global_pool
(
self
):
self
.
global_pool
=
False
class
TestCase2
(
TestPool3d_Op
):
def
init_test_case
(
self
):
self
.
shape
=
[
2
,
3
,
7
,
7
,
7
]
self
.
ksize
=
[
3
,
3
,
3
]
self
.
strides
=
[
1
,
1
,
1
]
self
.
paddings
=
[
1
,
1
,
1
]
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d"
def
init_pool_type
(
self
):
self
.
pool_type
=
"avg"
self
.
pool3D_forward_naive
=
avg_pool3D_forward_naive
def
init_global_pool
(
self
):
self
.
global_pool
=
False
class
TestCase3
(
TestPool3d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
True
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d"
def
init_pool_type
(
self
):
self
.
pool_type
=
"max"
self
.
pool3D_forward_naive
=
max_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
,
5
]
self
.
ksize
=
[
3
,
3
,
3
]
self
.
strides
=
[
1
,
1
,
1
]
self
.
paddings
=
[
0
,
0
,
0
]
class
TestCase4
(
TestPool3d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
class
TestCase4
(
TestCase1
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d"
def
init_pool_type
(
self
):
self
.
pool_type
=
"max"
self
.
pool3D_forward_naive
=
max_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
,
7
]
self
.
ksize
=
[
3
,
3
,
3
]
self
.
strides
=
[
1
,
1
,
1
]
self
.
paddings
=
[
0
,
0
,
0
]
class
TestCase5
(
TestPool3d_Op
):
def
init_test_case
(
self
):
self
.
global_pool
=
False
class
TestCase5
(
TestCase2
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d"
def
init_pool_type
(
self
):
self
.
pool_type
=
"max"
self
.
pool3D_forward_naive
=
max_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
,
7
]
self
.
ksize
=
[
3
,
3
,
3
]
self
.
strides
=
[
1
,
1
,
1
]
self
.
paddings
=
[
1
,
1
,
1
]
#--------------------test pool3d_cudnn--------------------
class
TestCudnnCase1
(
TestPool3d_Op
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d_cudnn"
class
TestCudnnCase2
(
TestCase1
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d_cudnn"
class
TestCudnnCase3
(
TestCase2
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d_cudnn"
class
TestCudnnCase4
(
TestCase3
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d_cudnn"
class
TestCudnnCase5
(
TestCase4
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d_cudnn"
class
TestCudnnCase6
(
TestCase5
):
def
init_op_type
(
self
):
self
.
op_type
=
"pool3d_cudnn"
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录