Web Analytics

Convert ONNX & NPU Data on the KL730 Platform

Note: For the conversion C implementation please refer the ex_common/helper_functions.c and src/kp_inference.c.
Note: For the conversion Python implementation please refer the python/example/utils/ExampleHelper.py.
Note: For the KL730 NPU data layout information please refer the Supported NPU Data Layout Format (KL730).

To manually convert ONNX/NPU data, we can utilize the helper functions (C-helper_convert_onnx_data_to_npu_data; Python-convert_onnx_data_to_npu_data) and the inference retrieve result functions (C-kp_generic_inference_retrieve_fixed_node/kp_generic_inference_retrieve_float_node; Python-kp.generic_inference_retrieve_fixed_node/kp.generic_inference_retrieve_float_node). However, in most model deployments, it's essential to enhance conversion efficiency and eliminate unnecessary processes significantly. This section briefly overviews the conversion process of ONNX/NPU data conversion.

You can refer to the helper function's implementation to better understand the conversion process. Then, you can modify and optimize the code in the helper function to improve your conversion flow.

Conversion Flow

The figure below illustrates the data conversion flow: (A) from ONNX input data to NPU inference input data and (B) from NPU inference output data to ONNX output data.

Block A: From ONNX Input Data to NPU Inference Input Data

Block B: From NPU Inference Output Data to ONNX Output Data

ONNX and NPU Data Mapping Index Calculation

We will explain how the ONNX and NPU data mapping index is calculated. To determine the mapping index between ONNX and NPU data, we need the stride values from the tensor information. These values represent the stride offsets for each axis step.