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

Method updateRange

tools/quantization/TensorStatistic.cpp:52–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50 }
51}
52void TensorStatistic::updateRange() {
53 if (mUpdatedRangeFlags) {
54 return;
55 }
56 mUpdatedRangeFlags = true;
57 auto tmpTensor = mOriginTensor;
58 bool res = mOriginTensor->copyToHostTensor(mHostTensor.get());
59 if (res) {
60 tmpTensor = mHostTensor.get();
61 }
62 int size = tmpTensor->elementSize();
63 float* dataPtr = tmpTensor->host<float>();
64 auto minValue = mRange.first;
65 auto maxValue = mRange.second;
66 for (int i = 0; i < size; ++i) {
67 minValue = std::min(minValue, dataPtr[i]);
68 maxValue = std::max(maxValue, dataPtr[i]);
69 }
70 mRange.first = minValue;
71 mRange.second = maxValue;
72// if (mRange.first > 0.0f) {
73// mRange.first = 0.0f;
74// }
75// if (mRange.second < 0.0f) {
76// mRange.second = 0.0f;
77// }
78 mVisited = true;
79}
80
81void TensorStatistic::resetDistribution() {
82 auto maxValue = std::max(fabsf(mRange.second), fabsf(mRange.first));

Callers 1

Calls 4

copyToHostTensorMethod · 0.80
minFunction · 0.50
maxFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected