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

Function initConstTensorsNoAlloc

tools/cpp/compilefornpu.cpp:32–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30static std::string gCacheDir = "res";
31static MNNForwardType gNPUType = MNN_FORWARD_NN;
32static bool initConstTensorsNoAlloc(std::vector<std::shared_ptr<Tensor>>& tensors, const Net* net) {
33 bool valid = true;
34 tensors.resize(net->tensorName()->size());
35 // Set up const
36 for (int opIndex = 0; opIndex < net->oplists()->size(); ++opIndex) {
37 auto op = net->oplists()->GetAs<Op>(opIndex);
38 if (OpType_Const == op->type() || OpType_TrainableParam == op->type()) {
39 MNN_ASSERT(nullptr != op->outputIndexes());
40 auto index = op->outputIndexes()->data()[0];
41 tensors[index].reset(new Tensor);
42 TensorUtils::getDescribe(tensors[index].get())->index = index;
43 auto output = tensors[index].get();
44 if (op->type() == OpType_TrainableParam) {
45 TensorUtils::getDescribe(output)->usage = Tensor::InsideDescribe::TRAINABLE;
46 }
47 TensorUtils::getDescribe(output)->usage = Tensor::InsideDescribe::CONSTANT;
48 TensorUtils::getDescribe(output)->isMutable = false;
49 }
50 }
51 return true;
52}
53struct SubModuleInfo {
54 std::vector<int> opList;
55 std::vector<int> inputs;;

Callers 1

mainFunction · 0.85

Calls 6

resizeMethod · 0.45
sizeMethod · 0.45
typeMethod · 0.45
dataMethod · 0.45
resetMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected