MCPcopy Create free account
hub / github.com/alibaba/MNN / updateDistribution

Method updateDistribution

tools/quantization/TensorStatistic.cpp:92–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90 // fabsf(mRangePerChannel[0].first)));
91}
92void TensorStatistic::updateDistribution() {
93 if (mUpdatedDistributionFlag) {
94 return;
95 }
96 mUpdatedDistributionFlag = true;
97 auto tmpTensor = mOriginTensor;
98 bool res = mOriginTensor->copyToHostTensor(mHostTensor.get());
99 if (res) {
100 tmpTensor = mHostTensor.get();
101 }
102// float midValue = (mRange.second + mRange.first) / 2.0f;
103 float midValue = 0.f;
104 auto ptr = tmpTensor->host<float>();
105 for (int i = 0; i < tmpTensor->elementSize(); ++i) {
106 auto data = ptr[i] - midValue;
107 if (abs(data) <= 1e-6) {
108 continue;
109 }
110 int index = static_cast<int>(fabs(data) * mInterval);
111 index = std::min(index, mBinNumber - 1);
112 mDistribution[index] += 1.0f;
113 }
114}
115
116void TensorStatistic::setThresholdMethod(GET_THRESHOLD_METHOD thresholdMethod) {
117 mThresholdMethod = thresholdMethod;

Callers 1

Calls 5

fabsFunction · 0.85
copyToHostTensorMethod · 0.80
absFunction · 0.50
minFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected