Skip to content
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

Crop layer remove redundance #5138

Merged
merged 2 commits into from
Jan 18, 2017

Conversation

xmyqsh
Copy link
Contributor

@xmyqsh xmyqsh commented Dec 30, 2016

remove the redundancy for loop in crop.cpp
remove the redundancy compute in crop.cu

@williford
Copy link
Contributor

The change in the crop_layer.cpp file looks good to me. The code was in a for-loop when it does the same thing every loop (index is used and nothing is incremented).

I haven't figured out how the crop_layer.cu changes are equivalent yet. Can you give some explanation?

@xmyqsh
Copy link
Contributor Author

xmyqsh commented Jan 13, 2017

@williford glad to see you interesting my PR
case
const int lines = top[0]->shape(cur_dim);
const int height = top[0]->shape(cur_dim);
so
lines is equal to height
from
__global__ void copy_kernel(const int n, const int height, const int width,
copy_kernel<<<CAFFE_GET_BLOCKS(lines), CAFFE_CUDA_NUM_THREADS>>>( lines, height, width,
we know n is equal to lines
from
CUDA_KERNEL_LOOP(index, n) {
we know index is less than n
so index is also less than height
so index / height is always zero
and index % height is always index

so
int src_start = index / height * src_outer_stride + index % height * src_inner_stride;
is equivalent to
int src_start = index * src_inner_stride;

these simplicity can remove N*C*H*2 times division, multiply, mod and add operations in one forward or backwark process

@shelhamer
Copy link
Member

@BlGene could you take a look when you have the chance?

@BlGene
Copy link
Contributor

BlGene commented Jan 18, 2017

It makes sense that we don't need to iterate over the size of the last spatial dimension because we are copying it in one go, as it is stored in memory continuously.

Sorry for overlooking this before.

@xmyqsh: Thanks for finding this, can you please squash the PR.
@shelhamer: This looks correct to me.

@shelhamer shelhamer merged commit e744056 into BVLC:master Jan 18, 2017
@shelhamer
Copy link
Member

Thanks @xmyqsh for the simplification and removal of the redundant operations.

nagadomi pushed a commit to nagadomi/caffe that referenced this pull request May 19, 2017
acmiyaguchi pushed a commit to acmiyaguchi/caffe that referenced this pull request Nov 13, 2017
volgy pushed a commit to Fazecast/caffe that referenced this pull request Jan 17, 2018
oscarriddle pushed a commit to oscarriddle/caffe that referenced this pull request Mar 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants