Skip to content

Commit d10d1e4

Browse files
committed
Merge branch 'development' of https://github.com/foss-for-synopsys-dwc-arc-processors/synopsys-caffe into development
2 parents ef00b5e + 3bef117 commit d10d1e4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

include/caffe/layers/softmax_layer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class SoftmaxLayer : public Layer<Dtype> {
4545
Blob<Dtype> scale_;
4646
Dtype input_scale_; //CUSTOMIZATION
4747
Dtype output_scale_; //CUSTOMIZATION
48+
int input_zero_point_; //CUSTOMIZATION
49+
int output_zero_point_; //CUSTOMIZATION
4850
};
4951

5052
} // namespace caffe

src/caffe/layers/softmax_layer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@ void SoftmaxLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
2323
scale_.Reshape(scale_dims);
2424
input_scale_ = this->layer_param_.softmax_param().input_scale(); //CUSTOMIZATION
2525
output_scale_ = this->layer_param_.softmax_param().output_scale(); //CUSTOMIZATION
26+
input_zero_point_ = this->layer_param_.softmax_param().input_zero_point(); //CUSTOMIZATION
27+
output_zero_point_ = this->layer_param_.softmax_param().output_zero_point(); //CUSTOMIZATION
2628
}
2729

2830
template <typename Dtype>
2931
void SoftmaxLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
3032
const vector<Blob<Dtype>*>& top) {
33+
const bool quant_in = (input_scale_ != Dtype(1.0) || input_zero_point_ != 0);
34+
const bool quant_out = (output_scale_ != Dtype(1.0) || output_zero_point_ != 0);
35+
if (quant_in) {
36+
caffe_cpu_dequantize<Dtype>(bottom[0]->count(), bottom[0]->mutable_cpu_data(),
37+
input_scale_, input_zero_point_);
38+
}
3139
const Dtype* bottom_data = bottom[0]->cpu_data();
3240
Dtype* top_data = top[0]->mutable_cpu_data();
3341
Dtype* scale_data = scale_.mutable_cpu_data();
@@ -59,6 +67,14 @@ void SoftmaxLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
5967
top_data += inner_num_;
6068
}
6169
}
70+
if (quant_out) {
71+
// do not reuse "top_data"; it is shifted during the computation
72+
caffe_cpu_quantize<Dtype>(top[0]->count(), top[0]->mutable_cpu_data(), output_scale_, output_zero_point_);
73+
}
74+
if (quant_in) {
75+
caffe_cpu_quantize<Dtype>(bottom[0]->count(), bottom[0]->mutable_cpu_data(),
76+
input_scale_, input_zero_point_);
77+
}
6278
}
6379

6480
template <typename Dtype>

0 commit comments

Comments
 (0)