Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
极客李华
Paddle
提交
cadee843
P
Paddle
项目概览
极客李华
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cadee843
编写于
10月 27, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
df48b43b
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
49 addition
and
66 deletion
+49
-66
paddle/framework/ddim.cc
paddle/framework/ddim.cc
+8
-0
paddle/framework/ddim.h
paddle/framework/ddim.h
+1
-0
paddle/operators/conv_cudnn_op.cu
paddle/operators/conv_cudnn_op.cu
+14
-24
paddle/operators/pool_cudnn_op.cu
paddle/operators/pool_cudnn_op.cu
+8
-17
paddle/operators/pool_cudnn_op.h
paddle/operators/pool_cudnn_op.h
+0
-3
paddle/operators/pool_op.cc
paddle/operators/pool_op.cc
+10
-12
paddle/operators/pool_with_index_op.cc
paddle/operators/pool_with_index_op.cc
+6
-8
python/paddle/v2/framework/layers.py
python/paddle/v2/framework/layers.py
+2
-2
未找到文件。
paddle/framework/ddim.cc
浏览文件 @
cadee843
...
...
@@ -195,6 +195,14 @@ std::vector<int64_t> vectorize(const DDim& ddim) {
return
result
;
}
// NOTE: framework::vectorize converts to type int64_t
// which does not fit cudnn inputs.
std
::
vector
<
int
>
vectorize2int
(
const
DDim
&
ddim
)
{
std
::
vector
<
int64_t
>
temp
=
vectorize
(
ddim
);
std
::
vector
<
int
>
result
(
temp
.
begin
(),
temp
.
end
());
return
result
;
}
struct
ProductVisitor
:
public
boost
::
static_visitor
<
int64_t
>
{
template
<
int
D
>
int64_t
operator
()(
const
Dim
<
D
>&
dim
)
{
...
...
paddle/framework/ddim.h
浏览文件 @
cadee843
...
...
@@ -93,6 +93,7 @@ int64_t get(const DDim& dim, int idx);
void
set
(
DDim
&
dim
,
int
idx
,
int
val
);
std
::
vector
<
int64_t
>
vectorize
(
const
DDim
&
ddim
);
std
::
vector
<
int
>
vectorize2int
(
const
DDim
&
ddim
);
int64_t
product
(
const
DDim
&
ddim
);
...
...
paddle/operators/conv_cudnn_op.cu
浏览文件 @
cadee843
...
...
@@ -31,16 +31,6 @@ using CUDADeviceContext = platform::CUDADeviceContext;
static
constexpr
size_t
kCONV_CUDNN_WORKSPACE_LIMIT_BYTES
=
1024
*
1024
*
1024
;
// NOTE: framework::vectorize converts to type int64_t
// which does not fit cudnn inputs.
std
::
vector
<
int
>
Dims2Vector
(
const
framework
::
DDim
&
dims
)
{
std
::
vector
<
int
>
ret
;
for
(
int
i
=
0
;
i
<
dims
.
size
();
i
++
)
{
ret
.
push_back
(
dims
[
i
]);
}
return
ret
;
}
template
<
typename
T
>
class
CudnnConvOpKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
...
...
@@ -68,12 +58,12 @@ class CudnnConvOpKernel : public framework::OpKernel<T> {
ScopedConvolutionDescriptor
conv_desc
;
DataLayout
layout
=
DataLayout
::
kNCHW
;
cudnnTensorDescriptor_t
cudnn_input_desc
=
input_desc
.
descriptor
<
T
>
(
layout
,
Dims2Vector
(
input
->
dims
()),
groups
);
cudnnTensorDescriptor_t
cudnn_output_desc
=
output_desc
.
descriptor
<
T
>
(
layout
,
Dims2Vector
(
output
->
dims
()),
groups
);
cudnnFilterDescriptor_t
cudnn_filter_desc
=
filter_desc
.
descriptor
<
T
>
(
layout
,
Dims2Vector
(
filter
->
dims
()),
groups
);
cudnnTensorDescriptor_t
cudnn_input_desc
=
input_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
input
->
dims
()),
groups
);
cudnnTensorDescriptor_t
cudnn_output_desc
=
output_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
output
->
dims
()),
groups
);
cudnnFilterDescriptor_t
cudnn_filter_desc
=
filter_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
filter
->
dims
()),
groups
);
cudnnConvolutionDescriptor_t
cudnn_conv_desc
=
conv_desc
.
descriptor
<
T
>
(
paddings
,
strides
,
dilations
);
...
...
@@ -156,13 +146,13 @@ class CudnnConvGradOpKernel : public framework::OpKernel<T> {
ScopedConvolutionDescriptor
conv_desc
;
DataLayout
layout
=
DataLayout
::
kNCHW
;
cudnnTensorDescriptor_t
cudnn_input_desc
=
input_desc
.
descriptor
<
T
>
(
layout
,
Dims2Vector
(
input
->
dims
()),
groups
);
cudnnTensorDescriptor_t
cudnn_input_desc
=
input_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
input
->
dims
()),
groups
);
cudnnTensorDescriptor_t
cudnn_output_grad_desc
=
output_grad_desc
.
descriptor
<
T
>
(
layout
,
Dims2Vector
(
output_grad
->
dims
()),
groups
);
cudnnFilterDescriptor_t
cudnn_filter_desc
=
filter_desc
.
descriptor
<
T
>
(
layout
,
Dims2Vector
(
filter
->
dims
()),
groups
);
output_grad_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
output_grad
->
dims
()),
groups
);
cudnnFilterDescriptor_t
cudnn_filter_desc
=
filter_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
filter
->
dims
()),
groups
);
cudnnTensorDescriptor_t
cudnn_input_grad_desc
=
nullptr
;
cudnnFilterDescriptor_t
cudnn_filter_grad_desc
=
nullptr
;
...
...
@@ -192,7 +182,7 @@ class CudnnConvGradOpKernel : public framework::OpKernel<T> {
auto
handle
=
ctx
.
cuda_device_context
().
cudnn_handle
();
if
(
input_grad
)
{
cudnn_input_grad_desc
=
input_grad_desc
.
descriptor
<
T
>
(
layout
,
Dims2Vector
(
input_grad
->
dims
()),
groups
);
layout
,
framework
::
vectorize2int
(
input_grad
->
dims
()),
groups
);
PADDLE_ENFORCE
(
platform
::
dynload
::
cudnnGetConvolutionBackwardDataAlgorithm
(
handle
,
cudnn_filter_desc
,
...
...
@@ -213,7 +203,7 @@ class CudnnConvGradOpKernel : public framework::OpKernel<T> {
if
(
filter_grad
)
{
cudnn_filter_grad_desc
=
filter_grad_desc
.
descriptor
<
T
>
(
layout
,
Dims2Vector
(
filter_grad
->
dims
()),
groups
);
layout
,
framework
::
vectorize2int
(
filter_grad
->
dims
()),
groups
);
PADDLE_ENFORCE
(
platform
::
dynload
::
cudnnGetConvolutionBackwardFilterAlgorithm
(
handle
,
cudnn_input_desc
,
cudnn_output_grad_desc
,
cudnn_conv_desc
,
...
...
paddle/operators/pool_cudnn_op.cu
浏览文件 @
cadee843
...
...
@@ -24,15 +24,6 @@ using ScopedPoolingDescriptor = platform::ScopedPoolingDescriptor;
using
DataLayout
=
platform
::
DataLayout
;
using
PoolingMode
=
platform
::
PoolingMode
;
// NOTE: copy from conv_cudnn
std
::
vector
<
int
>
Dims2VectorPool
(
const
framework
::
DDim
&
dims
)
{
std
::
vector
<
int
>
ret
;
for
(
int
i
=
0
;
i
<
dims
.
size
();
i
++
)
{
ret
.
push_back
(
dims
[
i
]);
}
return
ret
;
}
template
<
typename
T
>
class
PoolCudnnOpKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
...
...
@@ -62,10 +53,10 @@ class PoolCudnnOpKernel : public framework::OpKernel<T> {
ScopedPoolingDescriptor
pool_desc
;
DataLayout
layout
=
DataLayout
::
kNCHW
;
cudnnTensorDescriptor_t
cudnn_input_desc
=
input_desc
.
descriptor
<
T
>
(
layout
,
Dims2VectorPool
(
input
->
dims
()));
cudnnTensorDescriptor_t
cudnn_output_desc
=
output_desc
.
descriptor
<
T
>
(
layout
,
Dims2VectorPool
(
output
->
dims
()));
cudnnTensorDescriptor_t
cudnn_input_desc
=
input_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
input
->
dims
()));
cudnnTensorDescriptor_t
cudnn_output_desc
=
output_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
output
->
dims
()));
PoolingMode
pooling_mode
;
if
(
pooling_type
==
"max"
)
{
...
...
@@ -120,10 +111,10 @@ class PoolCudnnGradOpKernel : public framework::OpKernel<T> {
ScopedPoolingDescriptor
pool_desc
;
DataLayout
layout
=
DataLayout
::
kNCHW
;
cudnnTensorDescriptor_t
cudnn_input_desc
=
input_desc
.
descriptor
<
T
>
(
layout
,
Dims2VectorPool
(
input
->
dims
()));
cudnnTensorDescriptor_t
cudnn_output_desc
=
output_desc
.
descriptor
<
T
>
(
layout
,
Dims2VectorPool
(
output
->
dims
()));
cudnnTensorDescriptor_t
cudnn_input_desc
=
input_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
input
->
dims
()));
cudnnTensorDescriptor_t
cudnn_output_desc
=
output_desc
.
descriptor
<
T
>
(
layout
,
framework
::
vectorize2int
(
output
->
dims
()));
PoolingMode
pooling_mode
;
if
(
pooling_type
==
"max"
)
{
...
...
paddle/operators/pool_cudnn_op.h
浏览文件 @
cadee843
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
...
paddle/operators/pool_op.cc
浏览文件 @
cadee843
...
...
@@ -81,8 +81,8 @@ Pool2dOpMaker::Pool2dOpMaker(framework::OpProto *proto,
"width of feature."
);
AddAttr
<
std
::
string
>
(
"poolingType"
,
"(string), pooling
Type of pooling operator.
"
"
Str constant equal to 'max' or 'avg'
."
)
"(string), pooling
type, can be
\"
max
\"
for max-pooling
"
"
and
\"
avg
\"
for average-pooling
."
)
.
InEnum
({
"max"
,
"avg"
});
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
...
...
@@ -90,10 +90,9 @@ Pool2dOpMaker::Pool2dOpMaker(framework::OpProto *proto,
"If globalPooling = true, ksize is ignored and need not be "
"specified."
);
// TODO(Chengduo): Add checker. (Currently,
// TypedAttrChecker don't support vector type.)
AddAttr
<
bool
>
(
"globalPooling"
,
"(bool default: false), whether to use the global pooling."
"If globalPooling = true, ksize is ignored and need not be specified."
)
AddAttr
<
bool
>
(
"globalPooling"
,
"(bool default: false), whether to use the global pooling."
"If globalPooling = true, ksize is ignored."
)
.
SetDefault
(
false
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
...
...
@@ -143,8 +142,8 @@ Pool3dOpMaker::Pool3dOpMaker(framework::OpProto *proto,
"width of feature."
);
AddAttr
<
std
::
string
>
(
"poolingType"
,
"(string), pooling
Type of pooling operator.
"
"
Str constant equal to 'max' or 'avg'
."
)
"(string), pooling
type, can be
\"
max
\"
for max-pooling
"
"
and
\"
avg
\"
for average-pooling
."
)
.
InEnum
({
"max"
,
"avg"
});
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
...
...
@@ -153,10 +152,9 @@ Pool3dOpMaker::Pool3dOpMaker(framework::OpProto *proto,
"If globalPooling = true, ksize is ignored and need not be "
"specified."
);
// TODO(Chengduo): Add checker. (Currently,
// TypedAttrChecker don't support vector type.)
AddAttr
<
bool
>
(
"globalPooling"
,
"(bool default: false), whether to use the global pooling."
"If globalPooling = true, ksize is ignored and need not be specified."
)
AddAttr
<
bool
>
(
"globalPooling"
,
"(bool default: false), whether to use the global pooling."
"If globalPooling = true, ksize is ignored."
)
.
SetDefault
(
false
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"(vector, default:{1,1,1}), strides(depth, height, "
...
...
paddle/operators/pool_with_index_op.cc
浏览文件 @
cadee843
...
...
@@ -109,10 +109,9 @@ class MaxPool2dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker {
"If globalPooling = true, ksize is ignored and need not be "
"specified."
);
// TODO(Chengduo): Add checker. (Currently,
// TypedAttrChecker don't support vector type.)
AddAttr
<
bool
>
(
"globalPooling"
,
"(bool default: false), whether to use the global pooling."
"If globalPooling = true, ksize is ignored and need not be specified."
)
AddAttr
<
bool
>
(
"globalPooling"
,
"(bool default: false), whether to use the global pooling."
"If globalPooling = true, ksize is ignored."
)
.
SetDefault
(
false
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
...
...
@@ -178,10 +177,9 @@ class MaxPool3dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker {
"If globalPooling = true, ksize is ignored and need not be "
"specified."
);
// TODO(Chengduo): Add checker. (Currently,
// TypedAttrChecker don't support vector type.)
AddAttr
<
bool
>
(
"globalPooling"
,
"(bool default: false), whether to use the global pooling."
"If globalPooling = true, ksize is ignored and need not be specified."
)
AddAttr
<
bool
>
(
"globalPooling"
,
"(bool default: false), whether to use the global pooling."
"If globalPooling = true, ksize is ignored."
)
.
SetDefault
(
false
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"(vector, default:{1,1,1}), strides(depth, "
...
...
python/paddle/v2/framework/layers.py
浏览文件 @
cadee843
...
...
@@ -266,9 +266,9 @@ def pool2d(input,
inputs
=
{
"X"
:
input
},
outputs
=
{
"Out"
:
pool_out
},
attrs
=
{
"pooling
_t
ype"
:
pool_type
,
"pooling
T
ype"
:
pool_type
,
"ksize"
:
pool_size
,
"global
_p
ooling"
:
global_pooling
,
"global
P
ooling"
:
global_pooling
,
"strides"
:
pool_stride
,
"paddings"
:
pool_padding
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录