graph 时延剖析 - 2022.1 简体中文

Versal ACAP AI 引擎编程环境 用户指南 (UG1076)

Document ID
UG1076
Release Date
2022-05-25
Version
2022.1 简体中文

event::io_stream_start_difference_cycles 枚举可用于测量两个 PLIO 或 GMIO 端口之间的时延。执行 event::start_profiling() API 后,两个性能计数器会开始逐个周期递增,等待两条独立信号线接收其第一项数据。当第一项数据经过任一信号线后,对应的性能计数器将停止。由 event::read_profiling() 读回的值表示两个性能计数器之间的差值。

执行 event::stop_profiling() 后,性能计数器会清零并释放。

graph 时延剖析

graph 时延可定义为从接收到第一项输入数据到生成第一项输出数据之间所耗费的时间。以下示例显示了如何使用事件 API 来剖析 graph 时延。

注释: event::start_profiling() 具有两个不同的 PLIO 参数。
auto s2mm_run = s2mm(out_bo, nullptr, OUTPUT_SIZE);
gr_pl.run(iterations);
event::handle handle = event::start_profiling(gr_pl.in, gr_pl.dataout, event::event::io_stream_start_difference_cycles);
if(handle==event::invalid_handle){
    printf("ERROR:Invalid handle. Only two performance counter in a AIE-PL interface tile\n");
    return 1;
} 
auto mm2s_run = mm2s(nullptr, OUTPUT_SIZE_MM2S);
gr_pl.wait();//make sure both ports have stopped
long long cycle_count = event::read_profiling(handle);
printf("Latency cycles=: %d\n", cycle_count);
event::stop_profiling(handle);//Performance counter is released and cleared

其中,先调用 graph.run(),后调用 event::start_profiling(),以避免 graph.run() 在剖析 graph 时延过程中可能引发的任何开销。

剖析两个端口之间的时延差

此方法不限于剖析相同 graph 的输入端口和输出端口之间的时延。它可用于剖析任意两个端口之间的时延。例如,它可剖析具有公用输入端口的两个输出端口之间的时延。代码示例如下:
gr_pl.run(iterations);
event::handle handle = event::start_profiling(gr_pl.dataout, gr_pl.dataout2, event::event::io_stream_start_difference_cycles);
if(handle==event::invalid_handle){
    printf("ERROR:Invalid handle. Only two performance counter in a AIE-PL interface tile\n");
    return 1;
} 
auto mm2s_run = mm2s(nullptr, OUTPUT_SIZE_MM2S);
gr_pl.wait();//make sure both ports have stopped
long long cycle_count = event::read_profiling(handle);
printf("Latency cycles=: %d\n", cycle_count);
event::stop_profiling(handle);//Performance counter is released and cleared

其中,正值表示数据到达 gr_pl.dataout2 的时间晚于 gr_pl.dataout,负值则表示数据到达 gr_pl.dataout2 的时间早于 gr_pl.dataout