Xilinx

[Vitis-AI] Compiling the Model

shvtr159 2022. 11. 1. 18:25

Vitis AI 컴파일러(VAI_C)는 네트워크 모델을 최적화된 DPU instruction sequence에 매핑합니다. 간략하게는 아래와 같습니다. Optimize 되고 quantize 된 입력 model의 topology를 parsing 한 뒤 VAI_C는 internal computation graph를 intermediate representation(IR)으로 구성합니다. 즉 control flow와 data flow representation에 대응됩니다. 그리고 batch norm과 convolution 결합과 같은 computation node fusion, 병렬 처리를 이용한 효율적인 instruction 스케줄링과 같은 다양한 optimization을 수행합니다.

Vitis AI Compiler Framework

XIR-based 툴체인으로 컴파일 하기

Xilinx Intermediate Representation(XIR)은 FPGA 플랫폼에서 DPU의 컴파일 및 효율적인 deployment를 위해 설계된 AI 알고리즘의 graph 기반 IR 입니다.

XIR

XIR에는 computational graph의 명확하고 유연한(flexible) 표시법을 제공하는 Op, Tensor, Graph, Subgraph library가 포함되어있습니다. Op 라이브러리에는 유명한 딥러닝 프레임 워크와 모든 내장 DPU 연산자를 다루는 연산자 세트가 있습니다. In-memory 형식의 XIR은 graph object이고, file format은 xmodel입니다. 이는 서로 serialize/deserialize 될 수 있습니다. XIR은 또한 PyXIR이라는 Python API를 제공하여 다른 언어 간의 격차를 수정합니다. 

XIR Based Flow

xir::Graph::serialize, xir:Op::set_attr 등이 있습니다.(https://docs.xilinx.com/r/en-US/ug1414-vitis-ai/XIR)

Compiling for DPU

XIR 기반 컴파일러는 각 플랫폼의 DPU를 지원하고 이 플랫폼에 대한 arch.json 파일은 /opt/vitis_ai/compiler/arch에 있습니다(ZCU104의 경우 /opt/vitis_ai/compiler/arch/DPUCZDX8G/ZCU104/arch.json). Pytorch는 quantization 단계에서 모델을 XIR 형식으로 바로 출력하여 이를 이용합니다. vai_c_xir을 사용해 컴파일할 수 있습니다.

vai_c_xir -x /PATH/TO/quantized.xmodel -a /PATH/TO/arch.json -o /OUTPUTPATH -n netname

모델에 DPU가 지원할 수 없는 작업이 포함된 경우 일부 하위 그래프가 생성되어 CPU에 매핑됩니다. FPGA는 특정한 IP를 만들어 이러한 operation을 가속할 수도 있습니다. XIR 기반 toolchain으로 customize 된 가속 IP들을 활성화하려면 plugin이라는 pipeline을 활용해 XIR 및 컴파일러 확장이 가능합니다.

각 DPU 별 지원되는 연산자는 https://docs.xilinx.com/r/en-US/ug1414-vitis-ai/Supported-Operators-and-DPU-Limitations를 확인하시면 됩니다.

 

Supported Operators and DPU Limitations - 2.5 English

Xilinx is continuously improving the DPU IP and the compiler to support more operators with better performance. The following table lists some typical operations and the configurations such as kernel size, stride, etc. that the DPU can support. If the oper

docs.xilinx.com