Skip to content

Commit

Permalink
use Blob directly instead of shared_ptr for EltwiseLayer::max_idx_
Browse files Browse the repository at this point in the history
This is in keeping with BVLC#742.
  • Loading branch information
longjon authored and shelhamer committed Sep 18, 2014
1 parent 318cd96 commit b513321
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/caffe/common_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class EltwiseLayer : public Layer<Dtype> {

EltwiseParameter_EltwiseOp op_;
vector<Dtype> coeffs_;
shared_ptr<Blob<int> > max_idx_;
Blob<int> max_idx_;

bool stable_prod_grad_;
};
Expand Down
7 changes: 3 additions & 4 deletions src/caffe/layers/eltwise_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ void EltwiseLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
// If max operation, we will initialize the vector index part.
if (this->layer_param_.eltwise_param().operation() ==
EltwiseParameter_EltwiseOp_MAX && top->size() == 1) {
max_idx_.reset(new Blob<int>(bottom[0]->num(), channels,
height, width));
max_idx_.Reshape(bottom[0]->num(), channels, height, width);
}
}

Expand Down Expand Up @@ -69,7 +68,7 @@ void EltwiseLayer<Dtype>::Forward_cpu(
break;
case EltwiseParameter_EltwiseOp_MAX:
// Initialize
mask = max_idx_->mutable_cpu_data();
mask = max_idx_.mutable_cpu_data();
caffe_set(count, -1, mask);
caffe_set(count, Dtype(-FLT_MAX), top_data);
// bottom 0 & 1
Expand Down Expand Up @@ -138,7 +137,7 @@ void EltwiseLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
}
break;
case EltwiseParameter_EltwiseOp_MAX:
mask = max_idx_->cpu_data();
mask = max_idx_.cpu_data();
for (int index = 0; index < count; ++index) {
Dtype gradient = 0;
if (mask[index] == i) {
Expand Down
4 changes: 2 additions & 2 deletions src/caffe/layers/eltwise_layer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void EltwiseLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
}
break;
case EltwiseParameter_EltwiseOp_MAX:
mask = max_idx_->mutable_gpu_data();
mask = max_idx_.mutable_gpu_data();
// NOLINT_NEXT_LINE(whitespace/operators)
MaxForward<Dtype> <<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
count, bottom[0]->gpu_data(), bottom[1]->gpu_data(), 0, top_data, mask);
Expand Down Expand Up @@ -118,7 +118,7 @@ void EltwiseLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
}
break;
case EltwiseParameter_EltwiseOp_MAX:
mask = max_idx_->gpu_data();
mask = max_idx_.gpu_data();
MaxBackward<Dtype> // NOLINT_NEXT_LINE(whitespace/operators)
<<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
count, top_diff, i, mask, bottom_diff);
Expand Down

0 comments on commit b513321

Please sign in to comment.