Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/foss-for-synopsys-dw…
Browse files Browse the repository at this point in the history
  • Loading branch information
vera121 committed Apr 13, 2021
2 parents ef00b5e + 3bef117 commit d10d1e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/caffe/layers/softmax_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class SoftmaxLayer : public Layer<Dtype> {
Blob<Dtype> scale_;
Dtype input_scale_; //CUSTOMIZATION
Dtype output_scale_; //CUSTOMIZATION
int input_zero_point_; //CUSTOMIZATION
int output_zero_point_; //CUSTOMIZATION
};

} // namespace caffe
Expand Down
16 changes: 16 additions & 0 deletions src/caffe/layers/softmax_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ void SoftmaxLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
scale_.Reshape(scale_dims);
input_scale_ = this->layer_param_.softmax_param().input_scale(); //CUSTOMIZATION
output_scale_ = this->layer_param_.softmax_param().output_scale(); //CUSTOMIZATION
input_zero_point_ = this->layer_param_.softmax_param().input_zero_point(); //CUSTOMIZATION
output_zero_point_ = this->layer_param_.softmax_param().output_zero_point(); //CUSTOMIZATION
}

template <typename Dtype>
void SoftmaxLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
const bool quant_in = (input_scale_ != Dtype(1.0) || input_zero_point_ != 0);
const bool quant_out = (output_scale_ != Dtype(1.0) || output_zero_point_ != 0);
if (quant_in) {
caffe_cpu_dequantize<Dtype>(bottom[0]->count(), bottom[0]->mutable_cpu_data(),
input_scale_, input_zero_point_);
}
const Dtype* bottom_data = bottom[0]->cpu_data();
Dtype* top_data = top[0]->mutable_cpu_data();
Dtype* scale_data = scale_.mutable_cpu_data();
Expand Down Expand Up @@ -59,6 +67,14 @@ void SoftmaxLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
top_data += inner_num_;
}
}
if (quant_out) {
// do not reuse "top_data"; it is shifted during the computation
caffe_cpu_quantize<Dtype>(top[0]->count(), top[0]->mutable_cpu_data(), output_scale_, output_zero_point_);
}
if (quant_in) {
caffe_cpu_quantize<Dtype>(bottom[0]->count(), bottom[0]->mutable_cpu_data(),
input_scale_, input_zero_point_);
}
}

template <typename Dtype>
Expand Down

0 comments on commit d10d1e4

Please sign in to comment.