Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
9437ce36
P
Paddle
项目概览
Crayon鑫
/
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看板
未验证
提交
9437ce36
编写于
9月 14, 2020
作者:
J
Jack Zhou
提交者:
GitHub
9月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Error description optimize for math dir
Error description optimize for math dir
上级
5c1bafbb
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
271 addition
and
123 deletion
+271
-123
paddle/fluid/operators/math/math_function.cc
paddle/fluid/operators/math/math_function.cc
+16
-2
paddle/fluid/operators/math/math_function.cu
paddle/fluid/operators/math/math_function.cu
+29
-4
paddle/fluid/operators/math/math_function_impl.h
paddle/fluid/operators/math/math_function_impl.h
+55
-10
paddle/fluid/operators/math/math_function_test.cc
paddle/fluid/operators/math/math_function_test.cc
+5
-1
paddle/fluid/operators/math/math_function_test.cu
paddle/fluid/operators/math/math_function_test.cu
+6
-1
paddle/fluid/operators/math/padding.h
paddle/fluid/operators/math/padding.h
+6
-4
paddle/fluid/operators/math/sampler.h
paddle/fluid/operators/math/sampler.h
+6
-1
paddle/fluid/operators/math/vol2col.cc
paddle/fluid/operators/math/vol2col.cc
+74
-50
paddle/fluid/operators/math/vol2col.cu
paddle/fluid/operators/math/vol2col.cu
+74
-50
未找到文件。
paddle/fluid/operators/math/math_function.cc
浏览文件 @
9437ce36
...
...
@@ -128,9 +128,23 @@ struct RowwiseAdd<platform::CPUDeviceContext, T> {
const
framework
::
Tensor
&
input
,
const
framework
::
Tensor
&
vector
,
framework
::
Tensor
*
output
)
{
auto
in_dims
=
input
.
dims
();
auto
out_dims
=
output
->
dims
();
auto
size
=
input
.
numel
()
/
in_dims
[
0
];
PADDLE_ENFORCE_EQ
(
vector
.
numel
(),
size
);
PADDLE_ENFORCE_EQ
(
output
->
dims
(),
in_dims
);
PADDLE_ENFORCE_EQ
(
vector
.
numel
(),
size
,
platform
::
errors
::
InvalidArgument
(
"The input vector size"
" should be equal to the size of each row of input tensor."
" Expected vector size=%d, but received %d"
,
size
,
vector
.
numel
()));
const
char
*
in_dims_cstr
=
in_dims
.
to_str
().
c_str
();
const
char
*
out_dims_cstr
=
out_dims
.
to_str
().
c_str
();
PADDLE_ENFORCE_EQ
(
out_dims
,
in_dims
,
platform
::
errors
::
InvalidArgument
(
"The output tensor shape should be same as the input"
" tensor shape. Expected output tensor shape: %s,"
" but received %s"
,
in_dims_cstr
,
out_dims_cstr
));
auto
in
=
framework
::
EigenMatrix
<
T
>::
From
(
input
);
auto
vec
=
framework
::
EigenVector
<
T
>::
Flatten
(
vector
);
...
...
paddle/fluid/operators/math/math_function.cu
浏览文件 @
9437ce36
...
...
@@ -88,9 +88,24 @@ struct RowwiseAdd<platform::CUDADeviceContext, T> {
const
framework
::
Tensor
&
input
,
const
framework
::
Tensor
&
vector
,
framework
::
Tensor
*
output
)
{
auto
in_dims
=
input
.
dims
();
auto
out_dims
=
output
->
dims
();
auto
size
=
input
.
numel
()
/
in_dims
[
0
];
PADDLE_ENFORCE_EQ
(
vector
.
numel
(),
size
);
PADDLE_ENFORCE_EQ
(
output
->
dims
(),
in_dims
);
PADDLE_ENFORCE_EQ
(
vector
.
numel
(),
size
,
platform
::
errors
::
InvalidArgument
(
"The input vector size"
" should be equal to the size of each row of input tensor."
" Expected vector size=%d, but received %d"
,
size
,
vector
.
numel
()));
const
char
*
in_dims_cstr
=
in_dims
.
to_str
().
c_str
();
const
char
*
out_dims_cstr
=
out_dims
.
to_str
().
c_str
();
PADDLE_ENFORCE_EQ
(
out_dims
,
in_dims
,
platform
::
errors
::
InvalidArgument
(
"The output tensor shape should be same as the input tensor"
" shape. Expected output tensor shape: %s,"
" but received %s"
,
in_dims_cstr
,
out_dims_cstr
));
int
blocks
=
512
;
int
grids
=
(
input
.
numel
()
+
blocks
-
1
)
/
blocks
;
RowwiseAddKernel
<
T
><<<
grids
,
blocks
,
0
,
context
.
stream
()
>>>
(
...
...
@@ -113,7 +128,12 @@ void ColwiseSum<platform::CUDADeviceContext, double>::operator()(
framework
::
Tensor
*
vector
)
{
auto
in_dims
=
input
.
dims
();
auto
size
=
input
.
numel
()
/
in_dims
[
0
];
PADDLE_ENFORCE_EQ
(
vector
->
numel
(),
size
);
PADDLE_ENFORCE_EQ
(
vector
->
numel
(),
size
,
platform
::
errors
::
InvalidArgument
(
"The size of input vector"
" should be equal to the size of input tensor column"
" dimension. Expected vector size=%d, but received %d"
,
size
,
vector
->
numel
()));
framework
::
Tensor
one
;
one
.
mutable_data
<
double
>
({
in_dims
[
0
]},
context
.
GetPlace
());
SetConstant
<
platform
::
CUDADeviceContext
,
double
>
set
;
...
...
@@ -134,7 +154,12 @@ void RowwiseSum<platform::CUDADeviceContext, double>::operator()(
framework
::
Tensor
*
vector
)
{
auto
in_dims
=
input
.
dims
();
auto
size
=
input
.
numel
()
/
in_dims
[
0
];
PADDLE_ENFORCE_EQ
(
vector
->
numel
(),
in_dims
[
0
]);
PADDLE_ENFORCE_EQ
(
vector
->
numel
(),
in_dims
[
0
],
platform
::
errors
::
InvalidArgument
(
"The size of input vector"
" should be equal to the size of input tensor row"
" dimension. Expected vector size=%d, but received %d"
,
in_dims
[
0
],
vector
->
numel
()));
framework
::
Tensor
one
;
one
.
mutable_data
<
double
>
({
size
},
context
.
GetPlace
());
SetConstant
<
platform
::
CUDADeviceContext
,
double
>
set
;
...
...
paddle/fluid/operators/math/math_function_impl.h
浏览文件 @
9437ce36
...
...
@@ -59,7 +59,12 @@ void ColwiseSum<DeviceContext, T>::operator()(const DeviceContext& context,
framework
::
Tensor
*
out
)
{
auto
in_dims
=
input
.
dims
();
auto
size
=
input
.
numel
()
/
in_dims
[
0
];
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
size
);
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
size
,
platform
::
errors
::
InvalidArgument
(
"The size of output tensor "
"should be equal to the size of input tensor column"
" dimension. Expected output size=%d, but received %d"
,
size
,
out
->
numel
()));
auto
in
=
framework
::
EigenMatrix
<
T
>::
From
(
input
);
auto
vec
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
out
);
...
...
@@ -78,7 +83,13 @@ class ColwiseSum<platform::CPUDeviceContext, T> {
auto
&
in_dims
=
input
.
dims
();
auto
height
=
in_dims
[
0
];
auto
size
=
in_dims
[
1
];
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
size
);
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
size
,
platform
::
errors
::
InvalidArgument
(
"The size of output tensor "
"should be equal to the size of input tensor column"
" dimension. Expected output size=%d, but received %d"
,
size
,
out
->
numel
()));
T
*
out_buf
=
out
->
mutable_data
<
T
>
(
out
->
place
());
const
T
*
in_buf
=
input
.
data
<
T
>
();
...
...
@@ -100,8 +111,16 @@ void RowwiseMean<DeviceContext, T>::operator()(const DeviceContext& context,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
*
out
)
{
auto
in_dims
=
input
.
dims
();
PADDLE_ENFORCE_EQ
(
in_dims
.
size
(),
2U
);
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
in_dims
[
0
]);
PADDLE_ENFORCE_EQ
(
in_dims
.
size
(),
2U
,
platform
::
errors
::
InvalidArgument
(
"The rank of input tensor "
"should be 2, but received %d"
,
in_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
in_dims
[
0
],
platform
::
errors
::
InvalidArgument
(
"The size of output tensor "
"should be equal to the size of input tensor row"
" dimension. Expected output size=%d, but received %d"
,
in_dims
[
0
],
out
->
numel
()));
auto
in
=
framework
::
EigenMatrix
<
T
>::
From
(
input
);
auto
vec
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
out
);
...
...
@@ -118,10 +137,19 @@ class RowwiseMean<platform::CPUDeviceContext, T> {
void
operator
()(
const
platform
::
CPUDeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
*
out
)
{
auto
&
in_dims
=
input
.
dims
();
PADDLE_ENFORCE_EQ
(
in_dims
.
size
(),
2U
);
PADDLE_ENFORCE_EQ
(
in_dims
.
size
(),
2U
,
platform
::
errors
::
InvalidArgument
(
"The rank of input tensor "
"should be 2, but received %d"
,
in_dims
.
size
()));
auto
height
=
in_dims
[
0
];
auto
size
=
in_dims
[
1
];
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
height
);
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
height
,
platform
::
errors
::
InvalidArgument
(
"The size of output tensor "
"should be equal to the size of input tensor row"
" dimension. Expected output size=%d, but received %d"
,
height
,
out
->
numel
()));
auto
inv_size
=
1.0
/
size
;
T
*
out_buf
=
out
->
mutable_data
<
T
>
(
out
->
place
());
const
T
*
in_buf
=
input
.
data
<
T
>
();
...
...
@@ -141,8 +169,16 @@ void RowwiseSum<DeviceContext, T>::operator()(const DeviceContext& context,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
*
out
)
{
auto
in_dims
=
input
.
dims
();
PADDLE_ENFORCE_EQ
(
in_dims
.
size
(),
2U
);
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
in_dims
[
0
]);
PADDLE_ENFORCE_EQ
(
in_dims
.
size
(),
2U
,
platform
::
errors
::
InvalidArgument
(
"The rank of input tensor "
"should be 2, but received %d"
,
in_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
in_dims
[
0
],
platform
::
errors
::
InvalidArgument
(
"The size of output tensor "
"should be equal to the size of input tensor row"
" dimension. Expected output size=%d, but received %d"
,
in_dims
[
0
],
out
->
numel
()));
auto
in
=
framework
::
EigenMatrix
<
T
>::
From
(
input
);
auto
vec
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
out
);
...
...
@@ -159,10 +195,19 @@ class RowwiseSum<platform::CPUDeviceContext, T> {
void
operator
()(
const
platform
::
CPUDeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
*
out
)
{
auto
&
in_dims
=
input
.
dims
();
PADDLE_ENFORCE_EQ
(
in_dims
.
size
(),
2U
);
PADDLE_ENFORCE_EQ
(
in_dims
.
size
(),
2U
,
platform
::
errors
::
InvalidArgument
(
"The rank of input tensor "
"should be 2, but received %d"
,
in_dims
.
size
()));
auto
height
=
in_dims
[
0
];
auto
size
=
in_dims
[
1
];
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
height
);
PADDLE_ENFORCE_EQ
(
out
->
numel
(),
height
,
platform
::
errors
::
InvalidArgument
(
"The size of output tensor "
"should be equal to the size of input tensor row"
" dimension. Expected output size=%d, but received %d"
,
height
,
out
->
numel
()));
T
*
out_buf
=
out
->
mutable_data
<
T
>
(
out
->
place
());
const
T
*
in_buf
=
input
.
data
<
T
>
();
...
...
paddle/fluid/operators/math/math_function_test.cc
浏览文件 @
9437ce36
...
...
@@ -224,7 +224,11 @@ TEST(math_funciton, set_constant) {
auto
*
ctx
=
new
paddle
::
platform
::
CPUDeviceContext
();
paddle
::
operators
::
math
::
set_constant
(
*
ctx
,
&
t
,
10
);
for
(
int64_t
i
=
0
;
i
<
t
.
numel
();
++
i
)
{
PADDLE_ENFORCE_EQ
(
10
,
t
.
data
<
int
>
()[
i
]);
PADDLE_ENFORCE_EQ
(
10
,
t
.
data
<
int
>
()[
i
],
paddle
::
platform
::
errors
::
InvalidArgument
(
"Each value of input"
"tensor should be 10, but received %d."
,
t
.
data
<
int
>
()[
i
]));
}
delete
ctx
;
}
...
...
paddle/fluid/operators/math/math_function_test.cu
浏览文件 @
9437ce36
...
...
@@ -18,7 +18,12 @@
void
fill_fp16_data
(
paddle
::
platform
::
float16
*
in_ptr
,
size_t
size
,
const
std
::
vector
<
float
>&
data
)
{
PADDLE_ENFORCE_EQ
(
size
,
data
.
size
());
PADDLE_ENFORCE_EQ
(
size
,
data
.
size
(),
paddle
::
platform
::
errors
::
InvalidArgument
(
"The size of argument data should"
" be equal to the argument size. Expected %d, but received %d."
,
size
,
data
.
size
()));
for
(
size_t
i
=
0
;
i
<
data
.
size
();
++
i
)
{
in_ptr
[
i
]
=
paddle
::
platform
::
float16
(
data
[
i
]);
}
...
...
paddle/fluid/operators/math/padding.h
浏览文件 @
9437ce36
...
...
@@ -85,8 +85,9 @@ void PaddingFunctor(int rank, const framework::ExecutionContext& context,
PadFunction
<
DeviceContext
,
T
,
6
>
(
context
,
pads
,
src
,
pad_value
,
out
);
break
;
default:
PADDLE_THROW
(
"PadOp only support tensors with no more than 6 dimensions."
);
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"PadOp only support tensors with no more"
" than 6 dimensions currently."
));
}
}
...
...
@@ -114,8 +115,9 @@ void PaddingGradFunctor(int rank, const framework::ExecutionContext& context,
PadGradFunction
<
DeviceContext
,
T
,
6
>
(
context
,
pads
,
src
,
out
);
break
;
default:
PADDLE_THROW
(
"PadOp only support tensors with no more than 6 dimensions."
);
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"PadOp only support tensors with no more"
" than 6 dimensions currently."
));
}
}
...
...
paddle/fluid/operators/math/sampler.h
浏览文件 @
9437ce36
...
...
@@ -19,6 +19,8 @@ limitations under the License. */
#include <random>
#include <vector>
#include "paddle/fluid/platform/enforce.h"
namespace
paddle
{
namespace
operators
{
namespace
math
{
...
...
@@ -31,7 +33,10 @@ namespace math {
class
Sampler
{
public:
explicit
Sampler
(
int64_t
range
,
unsigned
int
seed
=
0UL
)
:
range_
(
range
)
{
// PADDLE_ENFORCE_GT(range, 0, "Range should be greater than 0.");
PADDLE_ENFORCE_GT
(
range
,
0
,
platform
::
errors
::
InvalidArgument
(
"Range should be"
" greater than 0, but recevied %d."
,
range
));
if
(
seed
==
0
)
{
std
::
random_device
r
;
seed_
=
r
();
...
...
paddle/fluid/operators/math/vol2col.cc
浏览文件 @
9437ce36
...
...
@@ -34,10 +34,16 @@ class Vol2ColFunctor<platform::CPUDeviceContext, T> {
const
std
::
vector
<
int
>&
strides
,
const
std
::
vector
<
int
>&
paddings
,
framework
::
Tensor
*
col
,
const
DataLayout
data_layout
)
const
{
PADDLE_ENFORCE_EQ
(
vol
.
dims
().
size
(),
4
,
"The dimension of vol should be 4."
);
PADDLE_ENFORCE_EQ
(
col
->
dims
().
size
(),
7
,
"The dimension of col should be 7."
);
PADDLE_ENFORCE_EQ
(
vol
.
dims
().
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"The dimension of"
" vol should be 4, but received %d."
,
vol
.
dims
().
size
()));
PADDLE_ENFORCE_EQ
(
col
->
dims
().
size
(),
7
,
platform
::
errors
::
InvalidArgument
(
"The dimension of"
"col should be 7, but received %d."
,
col
->
dims
().
size
()));
int
input_channels
=
(
data_layout
!=
DataLayout
::
kNHWC
?
vol
.
dims
()[
0
]
:
vol
.
dims
()[
3
]);
...
...
@@ -65,27 +71,33 @@ class Vol2ColFunctor<platform::CPUDeviceContext, T> {
int
pad_w_left
=
paddings_size_is_6
?
paddings
[
4
]
:
paddings
[
2
];
int
pad_w_right
=
paddings_size_is_6
?
paddings
[
5
]
:
paddings
[
2
];
PADDLE_ENFORCE_EQ
((
input_depth
+
pad_d_forth
+
pad_d_back
-
((
dilations
[
0
]
*
(
filter_depth
-
1
)
+
1
)))
/
strides
[
0
]
+
1
,
output_depth
,
"input_depth and output_depth are "
"mismatching."
);
PADDLE_ENFORCE_EQ
((
input_height
+
pad_h_up
+
pad_h_down
-
((
dilations
[
1
]
*
(
filter_height
-
1
)
+
1
)))
/
strides
[
1
]
+
1
,
output_height
,
"input_height and output_height are "
"mismatching."
);
PADDLE_ENFORCE_EQ
((
input_width
+
pad_w_left
+
pad_w_right
-
((
dilations
[
2
]
*
(
filter_width
-
1
)
+
1
)))
/
strides
[
2
]
+
1
,
output_width
,
"input_width and output_width are "
"mismatching."
);
auto
input_depth_tmp
=
(
input_depth
+
pad_d_forth
+
pad_d_back
-
((
dilations
[
0
]
*
(
filter_depth
-
1
)
+
1
)))
/
strides
[
0
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_depth_tmp
,
output_depth
,
platform
::
errors
::
InvalidArgument
(
"input_depth(%d) and output_depth(%d) are mismatching."
,
input_depth_tmp
,
output_depth
));
auto
input_height_tmp
=
(
input_height
+
pad_h_up
+
pad_h_down
-
((
dilations
[
1
]
*
(
filter_height
-
1
)
+
1
)))
/
strides
[
1
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_height_tmp
,
output_height
,
platform
::
errors
::
InvalidArgument
(
"input_height(%d) and output_height(%d) are mismatching."
,
input_height_tmp
,
output_height
));
auto
input_width_tmp
=
(
input_width
+
pad_w_left
+
pad_w_right
-
((
dilations
[
2
]
*
(
filter_width
-
1
)
+
1
)))
/
strides
[
2
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_width_tmp
,
output_width
,
platform
::
errors
::
InvalidArgument
(
"input_width(%d) and output_width(%d) are mismatching."
,
input_width_tmp
,
output_width
));
const
T
*
vol_data
=
vol
.
data
<
T
>
();
T
*
col_data
=
col
->
data
<
T
>
();
...
...
@@ -140,10 +152,16 @@ class Col2VolFunctor<platform::CPUDeviceContext, T> {
const
std
::
vector
<
int
>&
strides
,
const
std
::
vector
<
int
>&
paddings
,
framework
::
Tensor
*
vol
,
const
DataLayout
data_layout
)
const
{
PADDLE_ENFORCE_EQ
(
vol
->
dims
().
size
(),
4
,
"The dimension of vol should be 4."
);
PADDLE_ENFORCE_EQ
(
col
.
dims
().
size
(),
7
,
"The dimension of col should be 7."
);
PADDLE_ENFORCE_EQ
(
vol
->
dims
().
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"The dimension of vol"
" should be 4, but received %d."
,
vol
->
dims
().
size
()));
PADDLE_ENFORCE_EQ
(
col
.
dims
().
size
(),
7
,
platform
::
errors
::
InvalidArgument
(
"The dimension of col"
" should be 7, but received %d."
,
col
.
dims
().
size
()));
int
input_channels
=
(
data_layout
!=
DataLayout
::
kNHWC
?
vol
->
dims
()[
0
]
:
vol
->
dims
()[
3
]);
...
...
@@ -170,27 +188,33 @@ class Col2VolFunctor<platform::CPUDeviceContext, T> {
int
pad_w_left
=
paddings_size_is_6
?
paddings
[
4
]
:
paddings
[
2
];
int
pad_w_right
=
paddings_size_is_6
?
paddings
[
5
]
:
paddings
[
2
];
PADDLE_ENFORCE_EQ
((
input_depth
+
pad_d_forth
+
pad_d_back
-
((
dilations
[
0
]
*
(
filter_depth
-
1
)
+
1
)))
/
strides
[
0
]
+
1
,
output_depth
,
"input_depth and output_depth are "
"mismatching."
);
PADDLE_ENFORCE_EQ
((
input_height
+
pad_h_up
+
pad_h_down
-
((
dilations
[
1
]
*
(
filter_height
-
1
)
+
1
)))
/
strides
[
1
]
+
1
,
output_height
,
"input_height and output_height are "
"mismatching."
);
PADDLE_ENFORCE_EQ
((
input_width
+
pad_w_left
+
pad_w_right
-
((
dilations
[
2
]
*
(
filter_width
-
1
)
+
1
)))
/
strides
[
2
]
+
1
,
output_width
,
"input_width and output_width are "
"mismatching."
);
auto
input_depth_tmp
=
(
input_depth
+
pad_d_forth
+
pad_d_back
-
((
dilations
[
0
]
*
(
filter_depth
-
1
)
+
1
)))
/
strides
[
0
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_depth_tmp
,
output_depth
,
platform
::
errors
::
InvalidArgument
(
"input_depth(%d)"
" and output_depth(%d) are mismatching."
,
input_depth_tmp
,
output_depth
));
auto
input_height_tmp
=
(
input_height
+
pad_h_up
+
pad_h_down
-
((
dilations
[
1
]
*
(
filter_height
-
1
)
+
1
)))
/
strides
[
1
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_height_tmp
,
output_height
,
platform
::
errors
::
InvalidArgument
(
"input_height(%d)"
" and output_height(%d) are mismatching."
,
input_height_tmp
,
output_height
));
auto
input_width_tmp
=
(
input_width
+
pad_w_left
+
pad_w_right
-
((
dilations
[
2
]
*
(
filter_width
-
1
)
+
1
)))
/
strides
[
2
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_width_tmp
,
output_width
,
platform
::
errors
::
InvalidArgument
(
"input_width(%d)"
" and output_width(%d) are mismatching."
,
input_width_tmp
,
output_width
));
T
*
vol_data
=
vol
->
data
<
T
>
();
const
T
*
col_data
=
col
.
data
<
T
>
();
...
...
paddle/fluid/operators/math/vol2col.cu
浏览文件 @
9437ce36
...
...
@@ -90,10 +90,16 @@ class Vol2ColFunctor<platform::CUDADeviceContext, T> {
const
std
::
vector
<
int
>&
strides
,
const
std
::
vector
<
int
>&
paddings
,
framework
::
Tensor
*
col
,
const
DataLayout
data_layout
)
const
{
PADDLE_ENFORCE_EQ
(
vol
.
dims
().
size
(),
4
,
"The dimension of vol should be 4."
);
PADDLE_ENFORCE_EQ
(
col
->
dims
().
size
(),
7
,
"The dimension of col should be 7."
);
PADDLE_ENFORCE_EQ
(
vol
.
dims
().
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"The dimension of"
" vol should be 4, but received %d."
,
vol
.
dims
().
size
()));
PADDLE_ENFORCE_EQ
(
col
->
dims
().
size
(),
7
,
platform
::
errors
::
InvalidArgument
(
"The dimension of"
"col should be 7, but received %d."
,
col
->
dims
().
size
()));
int
input_channels
=
(
data_layout
!=
DataLayout
::
kNHWC
?
vol
.
dims
()[
0
]
:
vol
.
dims
()[
3
]);
...
...
@@ -117,27 +123,33 @@ class Vol2ColFunctor<platform::CUDADeviceContext, T> {
int
pad_h_down
=
paddings_size_is_6
?
paddings
[
3
]
:
paddings
[
1
];
int
pad_w_left
=
paddings_size_is_6
?
paddings
[
4
]
:
paddings
[
2
];
int
pad_w_right
=
paddings_size_is_6
?
paddings
[
5
]
:
paddings
[
2
];
PADDLE_ENFORCE_EQ
((
input_depth
+
pad_d_forth
+
pad_d_back
-
((
dilations
[
0
]
*
(
filter_depth
-
1
)
+
1
)))
/
strides
[
0
]
+
1
,
output_depth
,
"input_depth and output_depth are "
"mismatching."
);
PADDLE_ENFORCE_EQ
((
input_height
+
pad_h_up
+
pad_h_down
-
((
dilations
[
1
]
*
(
filter_height
-
1
)
+
1
)))
/
strides
[
1
]
+
1
,
output_height
,
"input_height and output_height are "
"mismatching."
);
PADDLE_ENFORCE_EQ
((
input_width
+
pad_w_left
+
pad_w_right
-
((
dilations
[
2
]
*
(
filter_width
-
1
)
+
1
)))
/
strides
[
2
]
+
1
,
output_width
,
"input_width and output_width are "
"mismatching."
);
auto
input_depth_tmp
=
(
input_depth
+
pad_d_forth
+
pad_d_back
-
((
dilations
[
0
]
*
(
filter_depth
-
1
)
+
1
)))
/
strides
[
0
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_depth_tmp
,
output_depth
,
platform
::
errors
::
InvalidArgument
(
"input_depth(%d) and output_depth(%d) are mismatching."
,
input_depth_tmp
,
output_depth
));
auto
input_height_tmp
=
(
input_height
+
pad_h_up
+
pad_h_down
-
((
dilations
[
1
]
*
(
filter_height
-
1
)
+
1
)))
/
strides
[
1
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_height_tmp
,
output_height
,
platform
::
errors
::
InvalidArgument
(
"input_height(%d) and output_height(%d) are mismatching."
,
input_height_tmp
,
output_height
));
auto
input_width_tmp
=
(
input_width
+
pad_w_left
+
pad_w_right
-
((
dilations
[
2
]
*
(
filter_width
-
1
)
+
1
)))
/
strides
[
2
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_width_tmp
,
output_width
,
platform
::
errors
::
InvalidArgument
(
"input_width(%d) and output_width(%d) are mismatching."
,
input_width_tmp
,
output_width
));
int
num_outputs
=
input_channels
*
output_depth
*
output_height
*
output_width
;
...
...
@@ -241,10 +253,16 @@ class Col2VolFunctor<platform::CUDADeviceContext, T> {
const
std
::
vector
<
int
>&
strides
,
const
std
::
vector
<
int
>&
paddings
,
framework
::
Tensor
*
vol
,
const
DataLayout
data_layout
)
const
{
PADDLE_ENFORCE_EQ
(
vol
->
dims
().
size
(),
4
,
"The dimension of vol should be 4."
);
PADDLE_ENFORCE_EQ
(
col
.
dims
().
size
(),
7
,
"The dimension of col should be 7."
);
PADDLE_ENFORCE_EQ
(
vol
->
dims
().
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"The dimension of vol"
" should be 4, but received %d."
,
vol
->
dims
().
size
()));
PADDLE_ENFORCE_EQ
(
col
.
dims
().
size
(),
7
,
platform
::
errors
::
InvalidArgument
(
"The dimension of col"
" should be 7, but received %d."
,
col
.
dims
().
size
()));
int
input_channels
=
(
data_layout
!=
DataLayout
::
kNHWC
?
vol
->
dims
()[
0
]
:
vol
->
dims
()[
3
]);
...
...
@@ -269,27 +287,33 @@ class Col2VolFunctor<platform::CUDADeviceContext, T> {
int
pad_w_left
=
paddings_size_is_6
?
paddings
[
4
]
:
paddings
[
2
];
int
pad_w_right
=
paddings_size_is_6
?
paddings
[
5
]
:
paddings
[
2
];
PADDLE_ENFORCE_EQ
((
input_depth
+
pad_d_forth
+
pad_d_back
-
((
dilations
[
0
]
*
(
filter_depth
-
1
)
+
1
)))
/
strides
[
0
]
+
1
,
output_depth
,
"input_depth and output_depth are "
"mismatching."
);
PADDLE_ENFORCE_EQ
((
input_height
+
pad_h_up
+
pad_h_down
-
((
dilations
[
1
]
*
(
filter_height
-
1
)
+
1
)))
/
strides
[
1
]
+
1
,
output_height
,
"input_height and output_height are "
"mismatching."
);
PADDLE_ENFORCE_EQ
((
input_width
+
pad_w_left
+
pad_w_right
-
((
dilations
[
2
]
*
(
filter_width
-
1
)
+
1
)))
/
strides
[
2
]
+
1
,
output_width
,
"input_width and output_width are "
"mismatching."
);
auto
input_depth_tmp
=
(
input_depth
+
pad_d_forth
+
pad_d_back
-
((
dilations
[
0
]
*
(
filter_depth
-
1
)
+
1
)))
/
strides
[
0
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_depth_tmp
,
output_depth
,
platform
::
errors
::
InvalidArgument
(
"input_depth(%d)"
" and output_depth(%d) are mismatching."
,
input_depth_tmp
,
output_depth
));
auto
input_height_tmp
=
(
input_height
+
pad_h_up
+
pad_h_down
-
((
dilations
[
1
]
*
(
filter_height
-
1
)
+
1
)))
/
strides
[
1
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_height_tmp
,
output_height
,
platform
::
errors
::
InvalidArgument
(
"input_height(%d)"
" and output_height(%d) are mismatching."
,
input_height_tmp
,
output_height
));
auto
input_width_tmp
=
(
input_width
+
pad_w_left
+
pad_w_right
-
((
dilations
[
2
]
*
(
filter_width
-
1
)
+
1
)))
/
strides
[
2
]
+
1
;
PADDLE_ENFORCE_EQ
(
input_width_tmp
,
output_width
,
platform
::
errors
::
InvalidArgument
(
"input_width(%d)"
" and output_width(%d) are mismatching."
,
input_width_tmp
,
output_width
));
int
num_kernels
=
input_channels
*
input_depth
*
input_height
*
input_width
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录