Add dilations for conv2d and optimize conv2d code#5472
Add dilations for conv2d and optimize conv2d code#5472chengduoZH merged 11 commits intoPaddlePaddle:developfrom
Conversation
10101ea to
27805c2
Compare
607e0e8 to
520dec7
Compare
520dec7 to
97e9dd7
Compare
b125570 to
bd73642
Compare
b2d5245 to
caf24f3
Compare
caf24f3 to
93551bd
Compare
a5bbe8d to
3e60b6b
Compare
a3e15fd to
7d73b8f
Compare
paddle/operators/conv_op.h
Outdated
| filter_1 &= (static_cast<int>(filter_dim[j]) == 1); | ||
| strides_1 &= (strides[j] == 1); | ||
| padding_0 &= (paddings[j] == 0); | ||
| dilation_1 &= (dilations[j] == 1); |
There was a problem hiding this comment.
没有这种表示&&=,我改成了strides_1 = strides_1 && (strides[j] == 1)
paddle/operators/conv_op.h
Outdated
| vol2col(context.device_context(), in_slice, col, strides[0], | ||
| strides[1], strides[2], paddings[0], paddings[1], | ||
| paddings[2]); | ||
| if (!not_expand) { |
There was a problem hiding this comment.
! not expand = expand, the logic is a little complex,
How about rename NotExpand to IsExpand? Then return True, means that it needs to expand, ortherwise, not expand.
paddle/operators/conv_op.h
Outdated
| for (int i = 0; i < batch_size; i++) { | ||
| Tensor in_batch = input->Slice(i, i + 1).Resize(input_shape); | ||
| Tensor out_batch = output->Slice(i, i + 1).Resize(output_matrix_shape); | ||
| for (int g = 0; g < groups; g++) { |
There was a problem hiding this comment.
for (int i = 0; i < batch_size; i++) {
// ....
for (int g = 0; g < groups; g++) {
if(!IsExpand) {
ShareDataWith();
} else if () {
im2col();
} else if () {
im2vol();
}
}
}
paddle/operators/conv_op.h
Outdated
|
|
||
| math::matmul<Place, T>(context.device_context(), filter_slice, true, | ||
| out_grad_slice, false, T(1.0), &col_matrix, | ||
| T(0.0)); |
There was a problem hiding this comment.
The code structure is same as above.
| 1, | ||
| col_width, | ||
| "col_width and padding(padding_left, padding_right) are " | ||
| "inconsistent."); |
There was a problem hiding this comment.
写functor的���候,我也在考虑functor里面是否还有必要再次check shape的正确性,因为要么是在Op里计算得到的,要么InferShape里也已经check过。
There was a problem hiding this comment.
是的,我也有想过这些,比如在Op里面检测过了,在GradOp中就不用检测了吧
paddle/operators/math/im2col.cc
Outdated
| int padding_down, int padding_left, int padding_right) { | ||
| int dilation_h, int dilation_w, int stride_height, | ||
| int stride_width, int padding_up, int padding_down, | ||
| int padding_left, int padding_right) { |
There was a problem hiding this comment.
Maybe std::vector<int>& dilations, std::vector<int>& strides, std::vector<int>& paddings are short. And the op also uses std::vector<int>.
paddle/operators/conv_op.h
Outdated
| int output_size = (input_size + padding_up + padding_down - | ||
| (dilation * (filter_size - 1) + 1)) / | ||
| stride + | ||
| 1; |
There was a problem hiding this comment.
const int dkernel = dilation * (filter_size - 1) + 1;
const int output_size = (input_size + padding_up + padding_down - dkernel)/stride + 1;
paddle/operators/math/vol2col.cc
Outdated
| 1, | ||
| output_width, | ||
| "input_width and output_width are " | ||
| "Mismatching."); |
There was a problem hiding this comment.
Same as above, whether it needs to check again?
There was a problem hiding this comment.
I think we can write in this way first, and discuss it later. Because other functors also have similar problem.
| output_height + | ||
| h_col) * | ||
| output_width + | ||
| w_col; |
There was a problem hiding this comment.
data_col_index的计算太长,不容易看清楚。一些计算可以移到各自循环里。
There was a problem hiding this comment.
把这个公式分成了两个,现在可能会好一点
1607de4 to
8fffa9e
Compare
8fffa9e to
31dc019
Compare
fix #5495
fix #5507
fix #5550