-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Add vol2col functor #4462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add vol2col functor #4462
Conversation
paddle/operators/math/vol2col.cc
Outdated
void operator()(const platform::DeviceContext& context, | ||
const framework::Tensor& im, framework::Tensor& col, | ||
int stride_height, int stride_width, int padding_height, | ||
int padding_width) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void operator()(...) const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
b7e0607
to
651ad05
Compare
275e6cd
to
159ac9c
Compare
4191948
to
ba791f7
Compare
paddle/operators/math/CMakeLists.txt
Outdated
@@ -1,13 +1,15 @@ | |||
if(WITH_GPU) | |||
nv_library(math_function SRCS math_function.cc math_function.cu im2col.cc im2col.cu pooling.cc pooling.cu DEPS cblas device_context operator) | |||
nv_library(math_function SRCS math_function.cc math_function.cu im2col.cc im2col.cu vol2col.cc vol2col.cu pooling.cc pooling.cu DEPS cblas device_context operator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
依赖math_function
的op,不一定需要依赖vol2col
,所以觉得像softmax
一样和math_function
分开好一些
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/operators/math/vol2col.cc
Outdated
((c * output_depth + d) * output_height + h) * output_width + w; | ||
if (h_pad < 0 || h_pad >= input_height || w_pad < 0 || | ||
w_pad >= input_width || d_pad < 0 || d_pad >= input_depth) { | ||
col_data[col_idx] = T(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast<T>(0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
context = | ||
new paddle::platform::CPUDeviceContext(paddle::platform::CPUPlace()); | ||
} else { | ||
#ifndef PADDLE_ONLY_CPU |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
较新的代码去掉了PADDLE_ONLY_CPU
宏定义,需要更新代码。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
EXPECT_EQ(out_cfo_ptr[12], 9); | ||
EXPECT_EQ(out_cfo_ptr[13], 10); | ||
EXPECT_EQ(out_cfo_ptr[14], 10); | ||
EXPECT_EQ(out_cfo_ptr[15], 11); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是不是0,1,1,2,3, ... 等常量存在数组里,这里用for
循环比较,代码行数少一些?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!!!
Done
int d_pad = d * stride_depth - padding_depth + d_offset; | ||
for (int h = 0; h < output_height; ++h) { | ||
int h_pad = h * stride_height - padding_height + h_offset; | ||
for (int w = 0; w < output_width; ++w) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这几层循环,其实觉得完全可以和 im2col
实现统一成一个实现,不过这样也行吧,看着清晰一些~
79d6689
to
0913609
Compare
0913609
to
c85d777
Compare
|
||
TEST(math, vol2col) { | ||
testVol2col<paddle::platform::CPUPlace>(); | ||
#ifndef PADDLE_ONLY_CPU |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PADDLE_ONLY_CPU
is still not changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/operators/math/CMakeLists.txt
Outdated
@@ -3,11 +3,15 @@ if(WITH_GPU) | |||
nv_test(math_function_test SRCS math_function_test.cc DEPS math_function tensor) | |||
nv_library(softmax SRCS softmax.cc softmax.cu DEPS operator) | |||
nv_library(cross_entropy SRCS cross_entropy.cc cross_entropy.cu DEPS operator) | |||
nv_library(vol2col SRCS vol2col.cc vol2col.cu DEPS device_context operator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why depend on operator
when compiling in this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
fix #4669