What is the shape of bottom[0]->mutable_gpu_diff() ?

6 views
Skip to first unread message

Chun-Hsien Lin

unread,
Aug 22, 2017, 4:42:07 AM8/22/17
to Caffe Users
What is the shape of bottom[0]->mutable_gpu_diff()?

When I implement a new layer based on SoftmaxWithLossLayer, there is a segmentation fail in the GPU mode.

The CPU mode is fine.

The code below is the way to access prob_.cpu_data() in CPU mode.

const Dtype* prob_data = prob_.cpu_data();
int dim = prob_.count() / outer_num_;

for (int i = 0; i < outer_num_; ++i) {

    loss_mem[i] = Dtype(0);

    for (int j = 0; j < inner_num_; j++) {
      const int label_value = static_cast<int>(label[i * inner_num_ + j]);
      if (has_ignore_label_ && label_value == ignore_label_) {
        continue;
      }
      DCHECK_GE(label_value, 0);
      DCHECK_LT(label_value, prob_.shape(softmax_axis_));

      loss_tmp = -log(std::max(prob_data[i * dim + label_value * inner_num_ + j], Dtype(FLT_MIN)));

      loss              += loss_tmp 
      loss_mem[i] += loss_tmp;

      ++count;
    }
  }

I use the same way to access bottom[0]->mutable_gpu_diff(), but the idex seems out of range.

The shape of it may not be the same.

Can anyone help me?

Thank you.
Reply all
Reply to author
Forward
0 new messages