mirror of
https://github.com/open-mmlab/mmdeploy.git
synced 2025-01-14 08:09:43 +08:00
* minor changes * support windows * fix GCC build * fix lint * reformat * fix Windows build * fix GCC build * search backend ops for onnxruntime * fix lint * fix lint * code clean-up * code clean-up * fix clang build * fix trt support * fix cmake for ncnn * fix cmake for openvino * fix SDK Python API * handle ops for other backends (ncnn, trt) * handle SDK Python API library location * robustify linkage * fix cuda * minor fix for openvino & ncnn * use CMAKE_CUDA_ARCHITECTURES if set * fix cuda preprocessor * fix misc * fix pplnn & pplcv, drop support for pplcv<0.6.0 * robustify cmake * update build.md (#2) * build dynamic modules as module library & fix demo (partially) * fix candidate path for mmdeploy_python * move "enable CUDA" to cmake config for demo * refine demo cmake * add comment * fix ubuntu build * revert docs/en/build.md * fix C API * fix lint * Windows build doc (#3) * check in docs related to mmdeploy build on windows * update build guide on windows platform * update build guide on windows platform * make path of thirdparty libraries consistent * make path consistency * correct build command for custom ops * correct build command for sdk * update sdk build instructions * update doc * correct build command * fix lint * correct build command and fix lint Co-authored-by: lvhan <lvhan@pjlab.org> * trailing whitespace (#4) * minor fix * fix sr sdk model * fix type deduction * fix cudaFree after driver shutting down * update ppl.cv installation warning (#5) * fix device allocator threshold & fix lint * update doc (#6) * update ppl.cv installation warning * missing 'git clone' Co-authored-by: chenxin <chenxin2@sensetime.com> Co-authored-by: zhangli <zhangli@sensetime.com> Co-authored-by: lvhan028 <lvhan_028@163.com> Co-authored-by: lvhan <lvhan@pjlab.org>
96 lines
3.2 KiB
C++
96 lines
3.2 KiB
C++
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
#include "graph/pipeline.h"
|
|
|
|
#include "archive/value_archive.h"
|
|
#include "core/operator.h"
|
|
#include "graph/common.h"
|
|
|
|
namespace mmdeploy::graph {
|
|
|
|
Pipeline::Pipeline(const Value& cfg) : BaseNode(cfg["pipeline"]) {
|
|
input_idx_ = UpdateBindings(inputs(), kWrite);
|
|
for (auto task_config : cfg["pipeline"]["tasks"]) {
|
|
auto name = task_config.value("name", std::string{});
|
|
auto type = task_config.value("type", std::string{});
|
|
if (cfg.contains("context")) {
|
|
task_config["context"].update(cfg["context"]);
|
|
}
|
|
if (auto node = CreateFromRegistry<Node>(task_config); node) {
|
|
nodes_.push_back(std::move(node).value());
|
|
node_input_idx_.push_back(UpdateBindings(nodes_.back()->inputs(), kRead));
|
|
node_output_idx_.push_back(UpdateBindings(nodes_.back()->outputs(), kWrite));
|
|
} else {
|
|
MMDEPLOY_ERROR("could not create {}:{}", name, type);
|
|
throw_exception(eFail);
|
|
}
|
|
}
|
|
output_idx_ = UpdateBindings(outputs(), kRead);
|
|
}
|
|
|
|
void Pipeline::Build(TaskGraph& graph) {
|
|
graph
|
|
.Add([this](Context& ctx) -> Result<void> {
|
|
ctx.current().array().resize(binding_name_to_idx_.size());
|
|
return success();
|
|
})
|
|
->set_name(fmt::format("{}.call", name()));
|
|
;
|
|
for (int index = 0; index < nodes_.size(); ++index) {
|
|
graph.Add([this, index](Context& ctx) { return Call(ctx, index); })
|
|
->set_name(fmt::format("{}.call", nodes_[index]->name()));
|
|
nodes_[index]->Build(graph);
|
|
graph.Add([this, index](Context& ctx) { return Ret(ctx, index); })
|
|
->set_name(fmt::format("{}.ret", nodes_[index]->name()));
|
|
}
|
|
graph
|
|
.Add([this](Context& ctx) -> Result<void> {
|
|
auto vars = std::move(ctx.current()).array();
|
|
return Gather(std::move(vars), output_idx_, ctx.current().array());
|
|
})
|
|
->set_name(fmt::format("{}.ret", name()));
|
|
}
|
|
|
|
std::vector<int> Pipeline::UpdateBindings(const vector<std::string>& names, BindingType type) {
|
|
std::vector<int> idxs;
|
|
for (const auto& name : names) {
|
|
auto it = binding_name_to_idx_.lower_bound(name);
|
|
if (it == binding_name_to_idx_.end() || it->first != name) {
|
|
if (type == kRead) {
|
|
MMDEPLOY_ERROR("unknown binding name: {}", name);
|
|
throw_exception(eEntryNotFound);
|
|
} else {
|
|
auto index = static_cast<int>(binding_name_to_idx_.size());
|
|
it = binding_name_to_idx_.emplace_hint(it, name, index);
|
|
binding_idx_to_name_.emplace(index, name);
|
|
}
|
|
}
|
|
idxs.push_back(it->second);
|
|
}
|
|
return idxs;
|
|
}
|
|
|
|
Result<void> Pipeline::Call(Context& ctx, int idx) {
|
|
OUTCOME_TRY(auto&& args, Gather(ctx.current().array(), node_input_idx_[idx]));
|
|
ctx.push(std::move(args));
|
|
return success();
|
|
}
|
|
|
|
Result<void> Pipeline::Ret(Context& ctx, int idx) {
|
|
auto rets = ctx.pop().array();
|
|
return Scatter(std::move(rets), node_output_idx_[idx], ctx.current().array());
|
|
}
|
|
|
|
class PipelineCreator : public Creator<Node> {
|
|
public:
|
|
const char* GetName() const override { return "Pipeline"; }
|
|
int GetVersion() const override { return 0; }
|
|
std::unique_ptr<Node> Create(const Value& value) override {
|
|
return std::make_unique<Pipeline>(value);
|
|
}
|
|
};
|
|
|
|
REGISTER_MODULE(Node, PipelineCreator);
|
|
|
|
} // namespace mmdeploy::graph
|