赛灵思提供了 event::io_stream_running_event_count
枚举,用于对运行中的事件进行计数,其数量对应于通过信号线发送的样本数。运行 event::start_profiling()
时,性能计数器会启动。每次有数据样本穿过 AI 引擎到 PL 接口时,性能计数器就会递增。event::read_profiling()
读回的值是已穿过该接口发送的样本数量。
已发送和已接受的样本的计数方法
此方法可用于对 graph
stall
之前已发送或已接收的样本数量进行计数。以下示例可用于对发送至 AI 引擎端口的样本数量进行计数:event::handle handle = event::start_profiling(gr_pl.dataout, event::io_stream_running_event_count);
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);
sleep(2);//Wait for enough time
long long cycle_count = event::read_profiling(handle);
printf("Sample number: %d\n", cycle_count);
event::stop_profiling(handle);//Performance counter is released and cleared
以下示例可用于对接收到来自 AI 引擎端口的样本数量进行计数:
event::handle handle = event::start_profiling(gr_pl.in, event::io_stream_running_event_count);
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);//After start profiling, send data from mm2s
gr_pl.run(iterations);
sleep(2);//Wait for enough time
long long cycle_count = event::read_profiling(handle);
printf("Sample number: %d\n", cycle_count);
event::stop_profiling(handle);//Performance counter is released and cleared
端口吞吐量剖析
端口吞吐量定义为特定时间段内传输的样本数。运行 graph 后,可在主机代码中插入以下代码以测量端口吞吐量。为了剖析稳定状态下设计的端口吞吐量,您必须确保数据传输处于稳定状态后才能剖析端口吞吐量。
int wait_time_us=20000;
event::handle handle = event::start_profiling(gr_pl.dataout, event::io_stream_running_event_count);
if(handle==event::invalid_handle){
printf("ERROR:Invalid handle. Only two performance counter in a AIE-PL interface tile\n");
return 1;
}
long long count0 = event::read_profiling(handle);
usleep(wait_time_us);
long long count1 = event::read_profiling(handle);
event::stop_profiling(handle);
long long samples = count1 - count0;
std::cout << "num runnning samples: " << samples << std::endl;
std::cout << "Throughput: " << (double)samples / wait_time_us << " MSPS " << std::endl;
赛灵思建议您在硬件中运行设计并多次迭代以确保准确性。此方法的准确性可能因硬件仿真而异。
对于 AI 引擎仿真器,此剖析方法也同样适用。在 SystemC 中您需要将
usleep
替换为 wait
函数,等待时间必须大幅缩短,因为在仿真下它要慢得多。例如,对于 AI 引擎仿真器,前述代码中的 sleep
函数可替换为以下函数调用。wait(20,SC_US);