Skip to content

Commit

Permalink
remove zero initialize gradients (weight_diff, bias_diff) BVLC/caffe#…
Browse files Browse the repository at this point in the history
  • Loading branch information
antran89 committed Apr 15, 2017
1 parent f790848 commit 7b9b298
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/caffe/layers/convolution3d_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ void Convolution3DLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,

if (bias_term_) {
bias_diff = this->blobs_[1]->mutable_cpu_diff();
memset(bias_diff, 0, sizeof(Dtype) * this->blobs_[1]->count());
for (int n = 0; n < num_; ++n) {
caffe_cpu_gemv<Dtype>(CblasNoTrans, num_output_, N_,
1., top_diff + top[0]->offset(n),
Expand All @@ -196,7 +195,6 @@ void Convolution3DLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
int weight_offset = M_ * K_;
int top_offset = M_ * N_;

memset(weight_diff, 0, sizeof(Dtype) * this->blobs_[0]->count());
for (int n = 0; n < num_; ++n) {
// since we saved memory in the forward pass by not storing all col data,
// we will need to recompute them.
Expand Down
4 changes: 0 additions & 4 deletions src/caffe/layers/convolution3d_layer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ void Convolution3DLayer<Dtype>::Backward_gpu (const vector<Blob<Dtype>*>& top,

if (bias_term_) {
bias_diff = this->blobs_[1]->mutable_gpu_diff();
CUDA_CHECK(cudaMemset(bias_diff, 0,
sizeof(Dtype) * this->blobs_[1]->count()));
// indices for calling offset function of a blob [n,c,l,h,w]
vector<int> indices(5, 0);
for (int n = 0; n < num_; ++n) {
Expand All @@ -97,8 +95,6 @@ void Convolution3DLayer<Dtype>::Backward_gpu (const vector<Blob<Dtype>*>& top,
int weight_offset = M_ * K_;
int top_offset = M_ * N_;

CUDA_CHECK(cudaMemset(weight_diff, 0,
sizeof(Dtype) * this->blobs_[0]->count()));
// indices for calling offset function of a blob [n,c,l,h,w]
vector<int> indices(5, 0);
for (int n = 0; n < num_; ++n) {
Expand Down

0 comments on commit 7b9b298

Please sign in to comment.