使用 Vitis 工具或 aiecompiler 编译计算图后,可监控每个 AI 引擎阵列接口(或 shim 接口拼块)以计算特定事件数量。您可使用一些剖析事件来计算 AI 引擎阵列接口内有效的 AXI4‑Stream 数据传输事务数量。调用 API 时,PS 会发出一系列 AXI4-MM 命令,以将 AI 引擎阵列接口配置为计算有效事件数。AI 引擎阵列接口中的事件计数提供了一种实用的方法,无需对系统添加任何额外硬件即可对系统进行测量。
注释: 每个 AI 引擎阵列接口仅含 2 个性能计数器,但每个 AI 引擎阵列接口中都有 14 个 64b 串流。因此,每次使用这些探测 API 只能监控 2 个 AI 引擎 PL 接口。
以下示例使用 io_stream_start_to_bytes_transferred_cycles
事件 API 来测量计算图的吞吐量。此 API 使用 2 个性能计数器来追踪传输的字节数和耗用的周期数。此事件 API 可捕获并计算通过计算图传输指定量的数据的活动、停滞和空闲周期总数之和。此 API 可在输入和输出串流上使用。
gr.init();
event::handle handle = event::start_profiling(plio_out,
event::io_stream_start_to_bytes_transferred_cycles, 256*sizeof(int32));
gr.run(8);
gr.wait();
long long cycle_count = event::read_profiling(handle);
event::stop_profiling(handle);
double throughput = (double)256 * sizeof(int32) / (cycle_count * 1e-9); //
byte per second
当要传输的字节数未知时,您可使用另一个事件 API。以下示例使用 io_stream_running_event_count
事件 API 来测量计算图的吞吐量。串流将按指定时间间隔运行,并捕获串流的活动事件数量。
...
...
using namespace adf;
event::handle handle_0;
PLIO duc_plio[2] = {*duc_in0, *duc_out0};
d=0;
while(d < NUM_DUC_SLAVES) {
long long throughput_out_min = 990000000; // initial value to some high number
long long throughput_out_max = 0;
int iter=0;
while(iter < 5) {
long long count_start, count_end;
long long throughput;
handle_0 = event::start_profiling(duc_plio[d], event::io_stream_running_event_count);
count_start = event::read_profiling(handle_0);
//precision of usleep is dependent on linux system call
usleep(1000000); //1s
count_end = event::read_profiling(handle_0);
event::stop_profiling(handle_0);
if (count_end > count_start) throughput = (count_end-count_start);
else throughput = (count_end-count_start+0x100000000); //roll over correction for 32b performance counter
if (throughput<throughput_out_min) throughput_out_min = throughput;
if (throughput>throughput_out_max) throughput_out_max = throughput;
iter++;
}
printf("[throughput] %d\tMin:%llu\tMax:%llu\tRange:%llu\n", d, throughput_out_min, throughput_out_max, throughput_out_max-throughput_out_min );
d++;
}
printf("[main] Performance measurements Done ... \n");
...
...