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

Method onForward

express/module/Module.cpp:211–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209 }
210
211 virtual std::vector<Express::VARP> onForward(const std::vector<Express::VARP>& inputs) override {
212 auto mModule = mChildren[0];
213 // Reset resize staus
214 mInfo->runTimeManager->getInside()->mResizeStatus = 0;
215#ifdef MNN_INTERNAL_ENABLED
216 Timer _time;
217 auto glo = ExecutorScope::Current();
218 glo->getDebugTools()->flops = 0.0f;
219#endif
220 std::vector<VARP> outputs;
221 {
222 Executor::RuntimeExecuteWrap wrap(mInfo->runTimeManager->getInside()->mRuntime);
223 outputs = mModule->onForward(inputs);
224 }
225
226 // Check execution status after forward
227 if (!outputs.empty()) {
228 bool hasNoExecution = false;
229 for (auto& v : outputs) {
230 auto t = Utils::getTensor(v);
231 if (nullptr != t) {
232 auto backend = TensorUtils::getDescribeOrigin(t)->getBackend();
233 if (nullptr != backend) {
234 // Try to sync to check execution status
235 int syncResult = backend->onSync(Tensor::MAP_TENSOR_READ, false, t);
236 if (NO_EXECUTION == syncResult) {
237 hasNoExecution = true;
238 break;
239 }
240 }
241 }
242 }
243 if (hasNoExecution) {
244 MNN_PRINT("Warning, Backend has stop execute, return empty output vector varps\n");
245 outputs.clear();
246 }
247 }
248
249#ifdef MNN_INTERNAL_ENABLED
250 do {
251 if (outputs.empty()) {
252 break;
253 }
254 if (!shouldLog(FREQ_LOW)) {
255 break;
256 }
257 for (auto& v : outputs) {
258 auto t = Utils::getTensor(v);
259 t->wait(Tensor::MAP_TENSOR_READ, true);
260 }
261 auto metrics = mLogInfo;
262 metrics.emplace("Time", std::to_string((float)_time.durationInUs() / 1000.0f));
263 metrics.emplace("API", "NetModule::onForward");
264 if (mInfo->runTimeManager.get() != nullptr) {
265 float memory = 0.0f;
266 mInfo->runTimeManager->getInfo(Interpreter::MEMORY, &memory);
267 metrics.emplace("Flops", std::to_string(glo->getDebugTools()->flops));
268 metrics.emplace("Memory", std::to_string(memory));

Callers 1

forwardMethod · 0.45

Calls 11

getTensorFunction · 0.85
durationInUsMethod · 0.80
clearCacheMethod · 0.80
to_stringFunction · 0.50
emptyMethod · 0.45
getBackendMethod · 0.45
onSyncMethod · 0.45
clearMethod · 0.45
waitMethod · 0.45
getMethod · 0.45
getInfoMethod · 0.45

Tested by

no test coverage detected