使用 RTL 编程逻辑的设计流程 - 2023.2 简体中文

AI 引擎内核与计算图编程指南 (UG1079)

Document ID
UG1079
Release Date
2023-12-04
Version
2023.2 简体中文

在 ADF 计算图内不支持 RTL 块。RTL 块与 ADF 计算图之间的通信需要 PLIO 接口。在以下示例中,interpolatorclassify 均为 AI 引擎内核。interpolator AI 引擎内核将数据串流至 PL RTL 块,此块则将数据串流回 AI 引擎 classify 内核。

class clipped : public graph {  
  private:
    kernel interpolator;
    kernel classify;
   
  public: 
    input_plio in;
    output_plio out;
    output_plio clip_in;
    input_plio clip_out; 

    clipped() {
      in  = input_plio::create("DataIn1", plio_32_bits,"data/input.txt");
      out = output_plio::create("DataOut1", plio_32_bits,"data/output.txt");
      clip_out = input_plio::create("clip_out",plio_32_bits,"data/input1.txt");
      clip_in  = output_plio::create("clip_in", plio_32_bits,"data/output1.txt"); 

      interpolator = kernel::create(fir_27t_sym_hb_2i);
      classify     = kernel::create(classifier);

      connect(in.out[0], interpolator.in[0]);
      connect(interpolator.out[0], clip_in.in[0]);
      connect(clip_out.out[0], classify.in[0]);
      connect(classify.out[0], out.in[0]);

      std::vector<std::string> myheaders;
      myheaders.push_back("include.h");

      adf::headers(interpolator) = myheaders;
      adf::headers(classify) = myheaders;

      source(interpolator) = "kernels/interpolators/hb27_2i.cc";
      source(classify)    = "kernels/classifiers/classify.cc";

      runtime<ratio>(interpolator) = 0.8;
      runtime<ratio>(classify) = 0.8;
    };
};

clip_inclip_out 属于往来 polar_clip PL RTL 内核的端口,此内核连接至计算图中的 AI 引擎内核。例如,clip_in 端口是 interpolator AI 引擎内核的输出,此内核连接至 polar_clip RTL 内核的输入。clip_out 端口是 classify AI 引擎内核的输入和 polar_clip RTL 内核的输出。

RTL 块和 AI 引擎

应用代码如以下示例所示。

#include "graph.h"

clipped clipgraph;

#if defined(__AIESIM__ ) || defined(__X86SIM__)
int main(int argc, char ** argv) {
    clipgraph.init();
    clipgraph.run();
    clipgraph.end();
    return 0;
}
#endif

为了正常运行 aiesimulator,您必须创建与 RTL 内核相关的输入测试激励文件。data/output_interp.txt 是输入 RTL 内核的测试激励文件。aiesimulator 会从 interpolator AI 引擎内核生成输出文件。data/input_classify.txt 文件包含来自 polar_clip 内核的数据,此内核是 AI 引擎 classify 内核的输入。请注意,PLIO 可能包含可选属性 PL 时钟频率,对于 polar_clip,该属性为 100。

硬件仿真流程和硬件流程中的 RTL 块

在硬件仿真流程和硬件流程中完全支持 RTL 内核。您需要添加 RTL 内核作为 nk 选项,并将接口与 sc 选项相链接,如以下代码所示。如果需要,请使用 freqHz 调整任意时钟频率。以下是 Vitis 配置文件的示例。

[connectivity]
nk=mm2s:1:mm2s
nk=s2mm:1:s2mm
nk=polar_clip:1:polar_clip
sc=mm2s.s:ai_engine_0.DataIn1
sc=ai_engine_0.clip_in:polar_clip.in_sample
sc=polar_clip.out_sample:ai_engine_0.clip_out
sc=ai_engine_0.DataOut1:s2mm.s
[clock]
freqHz=100000000:polar_clip.ap_clk

如需了解有关 RTL 内核与 Vitis 流程的更多信息,请参阅 AI 引擎工具和流程用户指南(UG1076) 中的构建和运行系统。SystemC 内核同样可按仅限仿真形式来使用。如需了解此流程,请参阅 Vitis 统一软件平台文档:应用加速开发(UG1393) 中的处理 SystemC 模型

AI 引擎计算图内的 PL 内核

系统与 AI 引擎计算图及 PL 内核链接后,可在 AI 引擎计算图视图内显示 AI 引擎计算图与 PL 内核连接的系统框图。使用以下命令在 Vitis IDE 中打开连接器汇总:

vitis -a <USER_NAME>.xsa.link_summary
图 1. AI 引擎计算图内的 PL 内核