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

Function initGetMaxValue

tools/cpp/getLinearInput.hpp:187–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187inline void initGetMaxValue(const std::string& maxValueFileName) {
188 initMaxValueFile(maxValueFileName);
189
190 static bool registered = false;
191 if (!registered) {
192 std::atexit(cleanupAtExit);
193 registered = true;
194 }
195
196 MNN::TensorCallBackWithInfo beforeCallBack = [](const std::vector<MNN::Tensor*>& ntensors, const MNN::OperatorInfo* info) {
197 auto opName = info->name();
198 if (info->type() == "Copy") {
199 return true;
200 }
201 if (opName.find("Linear") == std::string::npos || opName.find("raster") != std::string::npos) {
202 return true;
203 }
204
205 for (int i = 0; i < ntensors.size(); ++i) {
206 auto ntensor = ntensors[i];
207 auto outDimType = ntensor->getDimensionType();
208 std::shared_ptr<MNN::Tensor> expectTensor(new MNN::Tensor(ntensor, outDimType));
209 bool res = ntensor->copyToHostTensor(expectTensor.get());
210 if (res) {
211 ntensor = expectTensor.get();
212 }
213 {
214 auto ninput = MNN::Express::Variable::create(MNN::Express::Expr::create(ntensor));
215 if (nullptr == ninput->getInfo()) {
216 MNN_ERROR("Alloc memory or compute size error\n");
217 return false;
218 }
219 ninput = MNN::Express::_Convert(ninput, MNN::Express::NHWC);
220 ninput = MNN::Express::_Abs(ninput);
221 ninput = MNN::Express::_Reshape(ninput, {-1});
222
223 auto kv = MNN::Express::_TopKV2(ninput, MNN::Express::_Scalar<int>(1));
224 auto maxValues = kv[0];
225 auto maxValueFloat = maxValues->readMap<float>()[0];
226
227 writeMaxValueRealtime(opName, maxValueFloat);
228 }
229 }
230 return true;
231 };
232
233 MNN::TensorCallBackWithInfo callBack = [](const std::vector<MNN::Tensor*>& ntensors, const MNN::OperatorInfo* info) {
234 return true;
235 };
236
237 MNN::Express::ExecutorScope::Current()->setCallBack(std::move(beforeCallBack), std::move(callBack));
238}
239
240inline void closeAllFiles() {
241 closeThresholdFile();

Callers 1

Calls 15

initMaxValueFileFunction · 0.85
_ConvertFunction · 0.85
_AbsFunction · 0.85
_ReshapeFunction · 0.85
_TopKV2Function · 0.85
writeMaxValueRealtimeFunction · 0.85
getDimensionTypeMethod · 0.80
copyToHostTensorMethod · 0.80
setCallBackMethod · 0.80
createFunction · 0.50
nameMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected