create_graph_runner - 3.5 简体中文

Vitis AI Library 用户指南 (UG1354)

Document ID
UG1354
Release Date
2023-06-29
Version
3.5 简体中文

工厂函数,用于根据计算图和属性创建运行器的实例。

用法:

auto graph = xir::Graph::deserialize(xmodel_file);
auto attrs = xir::Attrs::create();
auto runner = vitis::ai::GraphRunner::create_graph_runner(graph.get(), attrs.get());
auto input_tensor_buffers = runner->get_inputs();

计算图运行器示例

代码样本:

// The way to create graph runner and the APIs usage of runner are shown below.
auto graph = xir::Graph::deserialize(xmodel_file);
auto attrs = xir::Attrs::create();
auto runner = vitis::ai::GraphRunner::create_graph_runner(graph.get(), attrs.get());
// get input and output tensor buffers
auto input_tensor_buffers = runner->get_inputs();
auto output_tensor_buffers = runner->get_outputs();
// sync input tensor buffers
for (auto& input : input_tensor_buffers) { input->sync_for_write(0, input->get_tensor()->get_data_size() / input->get_tensor()->get_shape()[0]);
}
// run graph runner
auto v = runner->execute_async(input_tensor_buffers, output_tensor_buffers);
auto status = runner->wait((int)v.first, 1000000000);
// sync output tensor buffers
for (auto& output : output_tensor_buffers) { output->sync_for_read(0, output->get_tensor()->get_data_size() / output->get_tensor()->get_shape()[0]);
}

原型设计

std::unique_ptr< vart::RunnerExt > create_graph_runner(const xir::Graph *graph, xir::Attrs *attrs);

参数

下表列出了 create_graph_runner 函数实参。

表 1. create_graph_runner 实参
类型 成员 描述
const xir::Graph * graph XIR 计算图
xir::Attrs * attrs XIR attrs 对象,同一计算图上的所有运行器共享此对象。

返回

运行器的实例。