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

Function _collectNeededOps

express/module/PipelineModule.cpp:349–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347}
348
349static std::vector<int> _collectNeededOps(const MNN::Net* net, const std::set<int>& inputIndexes, const std::set<int>& outputIndexes) {
350 // 0: not set, 1: output, 2:input
351 std::vector<int> tensorMask(net->tensorName()->size());
352 ::memset(tensorMask.data(), 0, tensorMask.size() * sizeof(int));
353
354 // 0: use, 1: no use
355 std::vector<int> opMask(net->oplists()->size());
356 ::memset(opMask.data(), 0, opMask.size() * sizeof(int));
357
358 // Set Initial Status
359 for (auto v : outputIndexes) {
360 tensorMask[v] = 1;
361 }
362 for (auto v : inputIndexes) {
363 // If both input/output, set as input
364 tensorMask[v] = 2;
365 }
366 bool change = false;
367 do {
368 change = false;
369 for (int i=0; i<opMask.size(); ++i) {
370 if (opMask[i] > 0) {
371 continue;
372 }
373 auto op = net->oplists()->GetAs<Op>(i);
374 if (nullptr != op->outputIndexes()) {
375 for (int j=0; j<op->outputIndexes()->size(); ++j) {
376 auto index = op->outputIndexes()->data()[j];
377 if (tensorMask[index] == 1) {
378 opMask[i] = 1;
379 change = true;
380 }
381 }
382 }
383 if (nullptr != op->inputIndexes() && opMask[i]) {
384 for (int j=0; j<op->inputIndexes()->size(); ++j) {
385 auto index = op->inputIndexes()->data()[j];
386 if (tensorMask[index] != 2) {
387 tensorMask[index] = 1;
388 }
389 }
390 }
391 }
392 } while (change);
393
394 std::vector<int> ops;
395 for (int i=0; i<opMask.size(); ++i) {
396 if (opMask[i] > 0) {
397 auto op = net->oplists()->GetAs<Op>(i);
398 if (needComputeOp(op)) {
399 ops.emplace_back(i);
400 continue;
401 }
402 }
403 }
404 return ops;
405}
406

Callers 1

_createSubModuleInfoFunction · 0.70

Calls 3

needComputeOpFunction · 0.85
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected