| 1070 | return code; |
| 1071 | } |
| 1072 | ErrorCode Pipeline::allocMemory(bool firstMalloc, bool forbidReplace) { |
| 1073 | // MNN_PRINT("allocMemory mtype:%d, cpubackendType:%d, cpuBackend runtime:%p\n", mBackend->type(), mBackupBackend->type(), mBackupBackend->getRuntime()); |
| 1074 | if (!firstMalloc) { |
| 1075 | if (OpCommonUtils::supportDynamicInputMemory(mInfo.first.cache.first->type()) && (!mInfo.first.inputBackendChange)) { |
| 1076 | return NO_ERROR; |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | /* Create Execution Begin */ |
| 1081 | auto& mBackend = mInfo.first.cache.first; |
| 1082 | auto& mBackupBackend = mInfo.first.cache.second; |
| 1083 | // Check If we need a lone time for init |
| 1084 | if (mBackend->type() != MNN_FORWARD_CPU && mBackend->type() != MNN_FORWARD_CPU_EXTENSION && mTuneAttr.autoSetOpType) { |
| 1085 | Runtime::OpInfo dstInfo; |
| 1086 | int currentInitCount = 0; |
| 1087 | std::vector<Schedule::OpCacheInfo> initInfos; |
| 1088 | for (auto& info : mInfo.second) { |
| 1089 | if (info.type == Schedule::CONSTANT) { |
| 1090 | continue; |
| 1091 | } |
| 1092 | auto& buffer = info.executeBuffer; |
| 1093 | for (auto& iterP : buffer.command) { |
| 1094 | auto& iter = *iterP; |
| 1095 | dstInfo.initCostLong = false; |
| 1096 | mRuntime->onMeasure(iter.inputs, iter.outputs, iter.op, dstInfo); |
| 1097 | if (dstInfo.initCostLong) { |
| 1098 | initInfos.emplace_back(info); |
| 1099 | currentInitCount++; |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
| 1103 | if (currentInitCount >= mTuneAttr.maxTuningNumber) { |
| 1104 | break; |
| 1105 | } |
| 1106 | } |
| 1107 | if (currentInitCount > 0) { |
| 1108 | MNN_PRINT("Turn back to cpu\n"); |
| 1109 | // Reset execution |
| 1110 | for (auto& info : mInfo.second) { |
| 1111 | info.executionCache.clear(); |
| 1112 | for (auto& iterP : info.executeBuffer.command) { |
| 1113 | iterP->execution = nullptr; |
| 1114 | iterP->execution = nullptr; |
| 1115 | _recycleDynamicMemory(iterP.get()); |
| 1116 | } |
| 1117 | } |
| 1118 | if (!mRuntime->hasAsyncWork()) { |
| 1119 | _pushTuningTask(std::move(initInfos)); |
| 1120 | } |
| 1121 | mBackend.reset(mCpuRuntime->onCreate(nullptr, mBackupBackend.get())); |
| 1122 | } |
| 1123 | } |
| 1124 | { |
| 1125 | auto code = _createExecutions(mInfo, mExternalFile, mExternalStorage); |
| 1126 | if (NO_ERROR != code) { |
| 1127 | return code; |
| 1128 | } |
| 1129 | } |
no test coverage detected