graph 带宽剖析 - 2022.1 简体中文

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

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

event::io_total_stream_running_to_idle_cycles 枚举可用于累积已剖析的 AI 引擎到 PL 接口上发生的运行中事件和停滞事件,这意味着它将对有数据传递的周期数和接口停滞的周期数进行计数。但它将忽略空闲状态。

执行 event::start_profiling() 后,性能计数器会等待运行数据开始,如果串流处于空闲状态,那么它将暂停。性能暂停后,有新数据传入时将恢复。执行 event::stop_profiling() 后,性能计数器将清零并释放。

使用输入端口剖析 graph 带宽

graph 带宽可定义为 graph 可接受数据的时间的百分比。

以下提供了通过 graph 输入端口测量 graph 带宽的代码示例:
const int WINDOW_SIZE_in_bytes=8192;
int iterations=999;
event::handle handle = event::start_profiling(gr_pl.in, event::io_total_stream_running_to_idle_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.run(iterations);
gr_pl.wait(); 
long long cycle_count = event::read_profiling(handle);
double bandwidth = (double) (WINDOW_SIZE_in_bytes*iterations/4) / cycle_count; 
event::stop_profiling(handle);//Performance counter is released and cleared

其中,运行总周期数可根据传输的字节数来计算。如果每个周期传输 4 字节,那么运行总周期数即为 WINDOW_SIZE_in_bytes*iterations/4event::read_profiling() 会从性能计数器读取运行中和已停滞的总周期数。

如果剖析的带宽为 1,这表示 graph 运行速度高于 PL 内核 mm2s,输入端口尚未停滞。

如果剖析的带宽小于 1,这表示 PL 内核 mm2s 发送数据的速度可能高于 graph 或 PL 内核 s2mm 的接收速度。您可能需要评估带宽下降是否是由 graph 或 PL 内核 s2mm 导致的。

使用输出端口剖析 graph 带宽

graph 带宽可定义为 graph 可发送数据的时间的百分比。如果剖析的带宽为 1,这表示 PL 内核 s2mm 并未阻塞 graph。如果剖析的带宽小于 1,这表示由于反压,s2mm 给 graph 造成了一定比例的阻塞。以下提供了通过 graph 输出端口剖析 graph 带宽的代码示例:
const int WINDOW_SIZE_in_bytes=8192;
int iterations=999;
event::handle handle = event::start_profiling(gr_pl.dataout, event::io_total_stream_running_to_idle_cycles);
if(handle==event::invalid_handle){
    printf("ERROR:Invalid handle. Only two performance counter in a AIE-PL interface tile\n");
    return 1;
} 
gr_pl.run(iterations);
gr_pl.wait(); 
long long cycle_count = event::read_profiling(handle);
double bandwidth = (double) (WINDOW_SIZE_in_bytes*iterations/4) / cycle_count; 
event::stop_profiling(handle);//Performance counter is released and cleared