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

Method encode

source/core/Pipeline.cpp:202–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200
201}
202ErrorCode Pipeline::encode(bool supportDebug, bool permitCodegen) {
203 auto& mBackend = mInfo.first.cache.first;
204 auto& mBackupBackend = mInfo.first.cache.second;
205 // Static Model just copy info to command buffer
206 if (!mInfo.first.needComputeGeometry) {
207 for (int i=0; i<mInfo.second.size(); ++i) {
208 auto& info = mInfo.second[i];
209 std::shared_ptr<Command> cmd(new Command);
210 cmd->op = info.op;
211 if (cmd->op->type() == OpType_Raster) {
212 // Compability for Origin Static Model
213 cmd->outputs = info.outputs;
214 if (TensorUtils::getDescribe(info.outputs[0])->regions.empty() && info.inputs.size() > 0 && TensorUtils::getDescribe(info.inputs[0])->regions.size() > 0) {
215 TensorUtils::getDescribe(info.outputs[0])->regions = std::move(TensorUtils::getDescribe(info.inputs[0])->regions);
216 TensorUtils::setRasterInputs(cmd.get());
217 } else {
218 cmd->inputs = info.inputs;
219 }
220 } else {
221 cmd->inputs = info.inputs;
222 cmd->outputs = info.outputs;
223 }
224 info.executeBuffer.command = {cmd};
225 }
226 } else {
227#ifndef MNN_SKIPBUILD_GEOMETRY
228 mBackend->onClearBuffer();
229 mBackupBackend->onClearBuffer();
230 mContext.clear();
231 mContext.mNeedRelease = mGeometryNeedRelease;
232 FileLoader l(mExternalFile.c_str());
233 /** Size Compute and compute Const Begin */
234 auto res = GeometryComputerUtils::shapeComputeAndGeometryTransform(mCpuRuntime, &l, mInfo.second, mContext, mInfo.first.cache.second, mUseGeometry, !mInfo.first.needComputeShape, permitCodegen);
235 if (res != NO_ERROR) {
236 return res;
237 }
238#endif
239 }
240 // Propagate Scale and insert new command
241 const RuntimeCreator* creator = nullptr;
242 if (mIsQuantModel) {
243 auto type = mBackend->type();
244 if (MNN_FORWARD_CPU_EXTENSION == type) {
245 type = MNN_FORWARD_CPU;
246 }
247 creator = MNNGetExtraRuntimeCreator(type);
248 }
249 if (mIsQuantModel && creator && creator->onSetQuantInfo(nullptr, {}, {})) {
250 // get propagate map
251 using PropagateMap = std::map<const MNN::Tensor*, std::set<const MNN::Tensor*>>;
252 PropagateMap forwardMap, backwardMap;
253 auto insertPropagateMap = [](PropagateMap& propagateMap, const Tensor* s, const Tensor* t) {
254 if (propagateMap.find(s) == propagateMap.end()) {
255 propagateMap[s] = std::set<const Tensor*>({t});
256 } else {
257 propagateMap[s].insert(t);
258 }
259 };

Callers 1

resizeMethod · 0.45

Calls 15

_getQuantPropagateOpFunction · 0.85
ReleaseRawMethod · 0.80
sizeMethod · 0.45
typeMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45
onClearBufferMethod · 0.45
clearMethod · 0.45
c_strMethod · 0.45
onSetQuantInfoMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected