Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
659f2f71
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
659f2f71
编写于
9月 21, 2017
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Bug fix for get device_context.
上级
d827359c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
34 addition
and
35 deletion
+34
-35
paddle/operators/gemm_conv2d_op.h
paddle/operators/gemm_conv2d_op.h
+10
-11
paddle/operators/math/im2col.cc
paddle/operators/math/im2col.cc
+4
-4
paddle/operators/math/im2col.cu
paddle/operators/math/im2col.cu
+16
-16
paddle/operators/math/im2col.h
paddle/operators/math/im2col.h
+2
-2
paddle/operators/math/im2col_test.cc
paddle/operators/math/im2col_test.cc
+2
-2
未找到文件。
paddle/operators/gemm_conv2d_op.h
浏览文件 @
659f2f71
...
...
@@ -75,8 +75,7 @@ class GemmConv2DKernel : public framework::OpKernel {
framework
::
DDim
output_matrix_shape
=
{
output_channels
,
output_height
*
output_width
};
auto
*
device_context
=
const_cast
<
platform
::
DeviceContext
*>
(
context
.
device_context_
);
auto
device_context
=
context
.
device_context
();
// convolution operator: im2col + gemm
int
in_step
=
input_channels
/
groups
;
...
...
@@ -93,8 +92,8 @@ class GemmConv2DKernel : public framework::OpKernel {
// gemm
Tensor
out_slice
=
out_batch
.
Slice
<
T
>
(
g
*
out_step
,
(
g
+
1
)
*
out_step
);
Tensor
filter_slice
=
filter
.
Slice
<
T
>
(
g
*
out_step
,
(
g
+
1
)
*
out_step
);
math
::
matmul
<
Place
,
T
>
(
filter_slice
,
false
,
col_matrix
,
false
,
T
(
1.0
)
,
&
out_slice
,
T
(
0.0
),
device_context
);
math
::
matmul
<
Place
,
T
>
(
device_context
,
filter_slice
,
false
,
col_matrix
,
false
,
T
(
1.0
),
&
out_slice
,
T
(
0.0
)
);
}
}
}
...
...
@@ -160,8 +159,7 @@ class GemmConvGrad2DKernel : public framework::OpKernel {
filter
.
numel
()
/
filter
.
dims
()[
0
]};
filter
.
Resize
(
filter_matrix_shape
);
auto
*
device_context
=
const_cast
<
platform
::
DeviceContext
*>
(
context
.
device_context_
);
auto
device_context
=
context
.
device_context
();
// convolution backward input operator: gemm + col2im
// convolution backward weight operator: im2col + gemm
...
...
@@ -184,8 +182,9 @@ class GemmConvGrad2DKernel : public framework::OpKernel {
out_grad_batch
.
Slice
<
T
>
(
g
*
out_step
,
(
g
+
1
)
*
out_step
);
Tensor
filter_slice
=
filter
.
Slice
<
T
>
(
g
*
out_step
,
(
g
+
1
)
*
out_step
);
math
::
matmul
<
Place
,
T
>
(
filter_slice
,
true
,
out_grad_slice
,
false
,
T
(
1.0
),
&
col_matrix
,
T
(
0.0
),
device_context
);
math
::
matmul
<
Place
,
T
>
(
device_context
,
filter_slice
,
true
,
out_grad_slice
,
false
,
T
(
1.0
),
&
col_matrix
,
T
(
0.0
));
// col2im
Tensor
in_grad_slice
=
...
...
@@ -218,9 +217,9 @@ class GemmConvGrad2DKernel : public framework::OpKernel {
// gemm
Tensor
filter_grad_slice
=
filter_grad_
.
Slice
<
T
>
(
g
*
out_step
,
(
g
+
1
)
*
out_step
);
math
::
matmul
<
Place
,
T
>
(
out_grad_slice
,
false
,
col_matrix
,
tru
e
,
T
(
1.0
),
&
filter_grad_slice
,
T
(
1.0
)
,
device_context
);
math
::
matmul
<
Place
,
T
>
(
device_context
,
out_grad_slice
,
fals
e
,
col_matrix
,
true
,
T
(
1.0
),
&
filter_grad_slice
,
T
(
1.0
)
);
}
}
}
...
...
paddle/operators/math/im2col.cc
浏览文件 @
659f2f71
...
...
@@ -29,7 +29,7 @@ class Im2ColFunctor<paddle::operators::math::ColFormat::kCFO,
public:
void
operator
()(
const
framework
::
Tensor
&
im
,
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
int
padding_width
,
const
platform
::
DeviceContext
&
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
...
...
@@ -81,7 +81,7 @@ class Col2ImFunctor<paddle::operators::math::ColFormat::kCFO,
public:
void
operator
()(
framework
::
Tensor
&
im
,
const
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
int
padding_width
,
const
platform
::
DeviceContext
&
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
int
input_channels
=
im
.
dims
()[
0
];
...
...
@@ -139,7 +139,7 @@ class Im2ColFunctor<paddle::operators::math::ColFormat::kOCF,
public:
void
operator
()(
const
framework
::
Tensor
&
im
,
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
int
padding_width
,
const
platform
::
DeviceContext
&
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
int
input_channels
=
im
.
dims
()[
0
];
...
...
@@ -199,7 +199,7 @@ class Col2ImFunctor<paddle::operators::math::ColFormat::kOCF,
public:
void
operator
()(
framework
::
Tensor
&
im
,
const
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
int
padding_width
,
const
platform
::
DeviceContext
&
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
int
input_channels
=
im
.
dims
()[
0
];
...
...
paddle/operators/math/im2col.cu
浏览文件 @
659f2f71
...
...
@@ -66,7 +66,7 @@ class Im2ColFunctor<paddle::operators::math::ColFormat::kCFO,
public:
void
operator
()(
const
framework
::
Tensor
&
im
,
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
int
padding_width
,
const
platform
::
DeviceContext
&
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
...
...
@@ -84,9 +84,9 @@ class Im2ColFunctor<paddle::operators::math::ColFormat::kCFO,
int
block_y
=
(
blocks
+
512
-
1
)
/
512
;
dim3
threads
(
1024
,
1
);
dim3
grid
(
block_x
,
block_y
);
im2col
<
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
platform
::
CUDADeviceContext
*>
(
context
)
->
stream
()
>>>
(
im2col
<
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
context
)
.
stream
()
>>>
(
im
.
data
<
T
>
(),
num_outputs
,
input_height
,
input_width
,
filter_height
,
filter_width
,
stride_height
,
stride_width
,
padding_height
,
padding_width
,
output_height
,
output_width
,
col
.
data
<
T
>
());
...
...
@@ -151,7 +151,7 @@ class Col2ImFunctor<paddle::operators::math::ColFormat::kCFO,
public:
void
operator
()(
framework
::
Tensor
&
im
,
const
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
int
padding_width
,
const
platform
::
DeviceContext
&
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
...
...
@@ -174,9 +174,9 @@ class Col2ImFunctor<paddle::operators::math::ColFormat::kCFO,
// To avoid involving atomic operations, we will launch one kernel per
// bottom dimension, and then in the kernel add up the top dimensions.
col2im
<
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
platform
::
CUDADeviceContext
*>
(
context
)
->
stream
()
>>>
(
col2im
<
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
context
)
.
stream
()
>>>
(
num_kernels
,
col
.
data
<
T
>
(),
input_height
+
2
*
padding_height
,
input_width
+
2
*
padding_width
,
input_channels
,
filter_height
,
filter_width
,
stride_height
,
stride_width
,
padding_height
,
...
...
@@ -237,7 +237,7 @@ class Im2ColFunctor<paddle::operators::math::ColFormat::kOCF,
public:
void
operator
()(
const
framework
::
Tensor
&
im
,
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
int
padding_width
,
const
platform
::
DeviceContext
&
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
int
input_channels
=
im
.
dims
()[
0
];
...
...
@@ -268,9 +268,9 @@ class Im2ColFunctor<paddle::operators::math::ColFormat::kOCF,
dim3
threads
(
block_dim_x
,
block_dim_y
,
std
::
min
(
block_dim_z
,
input_channels
));
dim3
grid
(
output_width
,
output_height
);
im2colOCF
<
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
platform
::
CUDADeviceContext
*>
(
context
)
->
stream
()
>>>
(
im2colOCF
<
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
context
)
.
stream
()
>>>
(
im
.
data
<
T
>
(),
col
.
data
<
T
>
(),
input_channels
,
input_height
,
input_width
,
filter_height
,
filter_width
,
stride_height
,
stride_width
,
padding_height
,
padding_width
,
output_height
,
output_width
);
...
...
@@ -320,7 +320,7 @@ class Col2ImFunctor<paddle::operators::math::ColFormat::kOCF,
public:
void
operator
()(
framework
::
Tensor
&
im
,
const
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
int
padding_width
,
const
platform
::
DeviceContext
&
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
int
input_channels
=
im
.
dims
()[
0
];
...
...
@@ -351,9 +351,9 @@ class Col2ImFunctor<paddle::operators::math::ColFormat::kOCF,
dim3
threads
(
block_dim_x
,
block_dim_y
,
std
::
min
(
block_dim_z
,
input_channels
));
dim3
grid
(
output_width
,
output_height
);
col2imOCF
<
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
platform
::
CUDADeviceContext
*>
(
context
)
->
stream
()
>>>
(
col2imOCF
<
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
context
)
.
stream
()
>>>
(
im
.
data
<
T
>
(),
col
.
data
<
T
>
(),
input_channels
,
input_height
,
input_width
,
filter_height
,
filter_width
,
stride_height
,
stride_width
,
padding_height
,
padding_width
,
output_height
,
output_width
);
...
...
paddle/operators/math/im2col.h
浏览文件 @
659f2f71
...
...
@@ -74,7 +74,7 @@ class Im2ColFunctor {
public:
void
operator
()(
const
framework
::
Tensor
&
im
,
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
,
platform
::
DeviceContext
*
context
);
int
padding_width
,
const
platform
::
DeviceContext
&
context
);
};
template
<
ColFormat
Format
,
typename
Place
,
typename
T
>
...
...
@@ -82,7 +82,7 @@ class Col2ImFunctor {
public:
void
operator
()(
framework
::
Tensor
&
im
,
const
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
,
platform
::
DeviceContext
*
context
);
int
padding_width
,
const
platform
::
DeviceContext
&
context
);
};
}
// namespace math
...
...
paddle/operators/math/im2col_test.cc
浏览文件 @
659f2f71
...
...
@@ -78,8 +78,8 @@ void testIm2col() {
PADDLE_THROW
(
"no GPU support"
);
#endif // PADDLE_ONLY_CPU
}
im2col
(
input
,
output_cfo
,
stride
,
stride
,
padding
,
padding
,
context
);
im2col_ocf
(
input
,
output_ocf
,
stride
,
stride
,
padding
,
padding
,
context
);
im2col
(
input
,
output_cfo
,
stride
,
stride
,
padding
,
padding
,
*
context
);
im2col_ocf
(
input
,
output_ocf
,
stride
,
stride
,
padding
,
padding
,
*
context
);
float
*
out_cfo_ptr
;
if
(
paddle
::
platform
::
is_cpu_place
(
*
place
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录