/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #pragma once #ifdef PADDLE_EXECUTOR_MULTITHREAD #include #include #include #include "framework/operator.h" namespace paddle_mobile { class depCore { public: template void analysisDep( const std::vector>>& ops) { std::unordered_map vars; size_t nop = ops.size(); deps.resize(nop); next.resize(nop); for (size_t i = 0; i < nop; i++) { const auto& op = ops[i]; for (const auto& kv : op->Inputs()) { for (const auto& v : kv.second) { if (vars.find(v) == vars.end()) { continue; } int di = vars[v]; if (di == i) { continue; } if (std::find(deps[i].begin(), deps[i].end(), di) != deps[i].end()) { continue; } deps[i].push_back(di); next[di].push_back(i); } } for (const auto& kv : op->Outputs()) { for (const auto& v : kv.second) { vars[v] = i; } } } } const std::vector& getNext(int i) { return next[i]; } const std::vector& getDeps(int i) { return deps[i]; } std::vector> deps; std::vector> next; }; } // namespace paddle_mobile #endif