我要评分
获取效率
正确性
完整性
易理解

Integrating KONNX with ONNX Runtime

This section describes how to integrate KONNX with ONNX Runtime to enable Kunpeng operator acceleration.

KONNX does not provide open development API. Therefore, no API description is provided.

Environment Requirements

Table 1 Software requirements

Item

Version

Description

How to Obtain

ONNX Runtime

1.19.2

Official open source code of ONNX Runtime 1.19.2.

Link

konnx.patch

1.0.0

Kunpeng BoostKit operator optimization patch file for ONNX Runtime based on Kunpeng 920 series processors.

Link

Adaptation Procedure

  1. Obtain the ONNX Runtime source package as instructed in Obtaining the Source Code in the ONNX Runtime Porting Guide.
  2. Obtain the patch file of ONNX Runtime.
    1. Download the ONNX Runtime patch file konnx.patch by following instructions in Table 1.
    2. Upload the konnx.patch patch file to the /path/to/ONNX_Runtime directory.
  3. Go to the /path/to/ONNX_Runtime/onnxruntime-1.19.2 directory.
    1
    cd /path/to/ONNX_Runtime/onnxruntime-1.19.2
    
  4. Initialize the repository.
    1
    2
    3
    git init
    git add .
    git commit -m "code init"
    
  5. Apply the konnx.patch file to the repository.
    1
    git apply ../konnx.patch
    
  6. Check whether the files are modified as shown in the following figure. If yes, the patch is successfully installed.
    1
    2
    git add .
    git status
    

  7. Compile and install ONNX Runtime. For details, see Compiling the Source Code in the ONNX Runtime Porting Guide.

Verification After Adaptation

After ONNX Runtime is compiled and installed, use the official unit test (UT) program onnxruntime_test_all to run and verify ONNX Runtime. This program, automatically built during CMake compilation, executes comprehensive tests validating functionality including: core operators, executors, serialization/deserialization, model loading, and hardware accelerator integrations.

  1. Set environment variables.
    export ONNX_INTRA_NUM=6 
    export ONNX_INTER_NUM=6 
    • ONNX_INTRA_NUM: intra-operator parallel thread count, controlling thread parallelism within an operator
    • ONNX_INTER_NUM: inter-operator parallel thread count, controlling concurrent execution across multiple operators

    The thread count can be set as required.

  2. Go to the /path/to/ONNX_Runtime/build/RelWithDebInfo directory.
    cd /path/to/ONNX_Runtime-1.19.2/build/RelWithDebInfo
  3. Run the following command to run onnxruntime_test_all:
    ./onnxruntime_test_all

    If the following information is displayed and no error is reported during the test, the ONNX Runtime verification is complete.