AMD Vitis™ AI 提供了 C++ DpuRunner 类,其中包含以下接口:
-
std::pair<uint32_t, int> execute_async( const std::vector<TensorBuffer*>& input, const std::vector<TensorBuffer*>& output);
提交输入张量以供执行,提交输出张量则用于存储结果。主机指针是使用 TensorBuffer 对象来传递的。该函数会返回作业 ID 以及函数调用的状态。
-
int wait(int jobid, int timeout);
由
execute_async
返回的作业 ID 将被传递给wait()
以供阻塞,直至作业完成且结果就绪为止。 -
TensorFormat get_tensor_format()
查询 DpuRunner 可知其期望的张量格式。
返回 DpuRunner::TensorFormat::NCHW 或 DpuRunner::TensorFormat::NHWC
-
std::vector<Tensor*> get_input_tensors() std::vector<Tensor*> get_output_tensors()
查询 DpuRunner 可知其针对加载的 Vitis AI 模型所期望的输入和输出张量的形状和名称。
- 要创建 DpuRunner 对象,请调用以下函数
create_runner(const xir::Subgraph* subgraph, const std::string& mode = "")
它会返回:
std::unique_ptr<Runner>
create_runner 的输入为由 Vitis AI 编译器生成的 XIR 子计算图。
提示: 要随 VART 启用多线程,请为每个线程创建 1 个运行器。
注释: 如果模型有多个子计算图,请参阅
https://github.com/Xilinx/Vitis-AI-Tutorials/tree/3.0/Tutorials/pytorch-subgraphs/。