Skip to content

Commit 6f628ad

Browse files
committed
inference acc patch: add saturate handling for AVE pooling.
1 parent 7a4d681 commit 6f628ad

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/caffe/layers/pooling_layer.cu

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include "caffe/layers/pooling_layer.hpp"
66
#include "caffe/util/math_functions.hpp"
77

8+
#define SATURATE_MAX 4095
9+
#define SATURATE_MIN -4096
10+
811
namespace caffe {
912

1013
template <typename Dtype>
@@ -86,6 +89,10 @@ __global__ void AvePoolForward(const int nthreads,
8689
if (output_shift_instead_division != Dtype(0)) {
8790
top_data[index] = aveval / output_shift_instead_division;
8891
top_data[index] = rint(top_data[index]);
92+
if(top_data[index] > SATURATE_MAX)
93+
top_data[index] = SATURATE_MAX;
94+
if(top_data[index] < SATURATE_MIN)
95+
top_data[index] = SATURATE_MIN;
8996
}
9097
else{
9198
top_data[index] = aveval / pool_size;
@@ -138,6 +145,10 @@ __global__ void AvePoolForward_TF(const int nthreads,
138145
else
139146
top_data[index] = aveval / output_shift_instead_division * full_pool_size / pool_size;
140147
top_data[index] = rint(top_data[index]);
148+
if(top_data[index] > SATURATE_MAX)
149+
top_data[index] = SATURATE_MAX;
150+
if(top_data[index] < SATURATE_MIN)
151+
top_data[index] = SATURATE_MIN;
141152
}
142153
else{
143154
top_data[index] = aveval / pool_size;

0 commit comments

Comments
 (0)