Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
45c8f9b2
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
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看板
提交
45c8f9b2
编写于
9月 04, 2017
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add context parameter and math namespace.
上级
abfac74c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
11 deletion
+21
-11
paddle/operators/math/im2col.cc
paddle/operators/math/im2col.cc
+6
-4
paddle/operators/math/im2col.cu
paddle/operators/math/im2col.cu
+11
-5
paddle/operators/math/im2col.h
paddle/operators/math/im2col.h
+4
-2
未找到文件。
paddle/operators/math/im2col.cc
浏览文件 @
45c8f9b2
...
...
@@ -15,6 +15,7 @@ limitations under the License. */
#include "paddle/operators/math/im2col.h"
namespace
paddle
{
namespace
math
{
/*
* im = [input_channels, input_height, input_width]
...
...
@@ -26,7 +27,7 @@ class Im2ColFunctor<kCFO, platform::CPUPlace, T> {
public:
void
operator
()(
const
framework
::
Tensor
&
im
,
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
)
{
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
...
...
@@ -77,7 +78,7 @@ class Col2ImFunctor<kCFO, platform::CPUPlace, T> {
public:
void
operator
()(
framework
::
Tensor
&
im
,
const
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
)
{
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
int
input_channels
=
im
.
dims
()[
0
];
...
...
@@ -130,7 +131,7 @@ class Im2ColFunctor<kOCF, platform::CPUPlace, T> {
public:
void
operator
()(
const
framework
::
Tensor
&
im
,
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
)
{
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
int
input_channels
=
im
.
dims
()[
0
];
...
...
@@ -189,7 +190,7 @@ class Col2ImFunctor<kOCF, platform::CPUPlace, T> {
public:
void
operator
()(
framework
::
Tensor
&
im
,
const
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
)
{
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
int
input_channels
=
im
.
dims
()[
0
];
...
...
@@ -241,4 +242,5 @@ template class Im2ColFunctor<kOCF, platform::CPUPlace, double>;
template
class
Col2ImFunctor
<
kOCF
,
platform
::
CPUPlace
,
float
>;
template
class
Col2ImFunctor
<
kOCF
,
platform
::
CPUPlace
,
double
>;
}
// namespace math
}
// namespace paddle
paddle/operators/math/im2col.cu
浏览文件 @
45c8f9b2
...
...
@@ -16,6 +16,7 @@ limitations under the License. */
#include "paddle/platform/cuda_helper.h"
namespace
paddle
{
namespace
math
{
template
<
class
T
>
__global__
void
im2col
(
const
T
*
data_im
,
int
num_outs
,
int
height
,
int
width
,
...
...
@@ -63,7 +64,7 @@ class Im2ColFunctor<kCFO, platform::GPUPlace, T> {
public:
void
operator
()(
const
framework
::
Tensor
&
im
,
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
)
{
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
...
...
@@ -81,6 +82,7 @@ class Im2ColFunctor<kCFO, platform::GPUPlace, T> {
int
block_y
=
(
blocks
+
512
-
1
)
/
512
;
dim3
threads
(
1024
,
1
);
dim3
grid
(
block_x
,
block_y
);
// TODO(hedaoyuan): launch kernel on specified stream
im2col
<
T
><<<
grid
,
threads
>>>
(
im
.
data
<
T
>
(),
num_outputs
,
input_height
,
input_width
,
filter_height
,
filter_width
,
stride_height
,
stride_width
,
padding_height
,
...
...
@@ -145,7 +147,7 @@ class Col2ImFunctor<kCFO, platform::GPUPlace, T> {
public:
void
operator
()(
framework
::
Tensor
&
im
,
const
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
)
{
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
...
...
@@ -168,6 +170,7 @@ class Col2ImFunctor<kCFO, platform::GPUPlace, T> {
// To avoid involving atomic operations, we will launch one kernel per
// bottom dimension, and then in the kernel add up the top dimensions.
// TODO(hedaoyuan): launch kernel on specified stream
col2im
<
T
><<<
grid
,
threads
>>>
(
num_kernels
,
col
.
data
<
T
>
(),
input_height
+
2
*
padding_height
,
input_width
+
2
*
padding_width
,
input_channels
,
filter_height
,
...
...
@@ -224,7 +227,7 @@ class Im2ColFunctor<kOCF, platform::GPUPlace, T> {
public:
void
operator
()(
const
framework
::
Tensor
&
im
,
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
)
{
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
int
input_channels
=
im
.
dims
()[
0
];
...
...
@@ -255,6 +258,7 @@ class Im2ColFunctor<kOCF, platform::GPUPlace, T> {
dim3
threads
(
block_dim_x
,
block_dim_y
,
std
::
min
(
block_dim_z
,
input_channels
));
dim3
grid
(
output_width
,
output_height
);
// TODO(hedaoyuan): launch kernel on specified stream
im2colOCF
<
T
><<<
grid
,
threads
>>>
(
im
.
data
<
T
>
(),
col
.
data
<
T
>
(),
input_channels
,
input_height
,
input_width
,
filter_height
,
filter_width
,
stride_height
,
stride_width
,
...
...
@@ -304,7 +308,7 @@ class Col2ImFunctor<kOCF, platform::GPUPlace, T> {
public:
void
operator
()(
framework
::
Tensor
&
im
,
const
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
)
{
int
padding_width
,
platform
::
DeviceContext
*
context
)
{
PADDLE_ENFORCE
(
im
.
dims
().
size
()
==
3
);
PADDLE_ENFORCE
(
col
.
dims
().
size
()
==
5
);
int
input_channels
=
im
.
dims
()[
0
];
...
...
@@ -335,7 +339,8 @@ class Col2ImFunctor<kOCF, platform::GPUPlace, T> {
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
>>>
(
// TODO(hedaoyuan): launch kernel on specified stream
col2imOCF
<
T
><<<
grid
,
threads
>>>
(
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
);
...
...
@@ -347,4 +352,5 @@ template class Im2ColFunctor<kOCF, platform::GPUPlace, double>;
template
class
Col2ImFunctor
<
kOCF
,
platform
::
GPUPlace
,
float
>;
template
class
Col2ImFunctor
<
kOCF
,
platform
::
GPUPlace
,
double
>;
}
// namespace math
}
// namespace paddle
paddle/operators/math/im2col.h
浏览文件 @
45c8f9b2
...
...
@@ -18,6 +18,7 @@ limitations under the License. */
#include "paddle/platform/device_context.h"
namespace
paddle
{
namespace
math
{
/* The storage format of the coldata in the Im2ColFunctor and Col2ImFunctor. */
enum
ColFormat
{
kCFO
=
0
,
kOCF
=
1
};
...
...
@@ -72,7 +73,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
);
int
padding_width
,
platform
::
DeviceContext
*
context
);
};
template
<
ColFormat
Format
,
typename
Place
,
typename
T
>
...
...
@@ -80,7 +81,8 @@ class Col2ImFunctor {
public:
void
operator
()(
framework
::
Tensor
&
im
,
const
framework
::
Tensor
&
col
,
int
stride_height
,
int
stride_width
,
int
padding_height
,
int
padding_width
);
int
padding_width
,
platform
::
DeviceContext
*
context
);
};
}
// namespace math
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录