Run Examples for Kneron PLUS Enterprise

Other than the examples briefed in Run Examples, Kneron PLUS Enterprise also provides few examples for demonstrating the usage of advanced features.

Note: If you are using Windows, please execute all the instruction below in MSYS2 MinGW 64-bit.

Note: In the inference related examples, we are using KL520 for most demo. If you wish to use KL720, just change the prefix of the example name from kl520 to kl720. (There might be no KL520 version or KL720 version on certain examples.)

Note: Few examples will auto connect multiple devices to run inference. If you put hybrid types of devices on host, the inference may fail.

Note: If you modify code to change different test image file. Input image aspect ratio is suggested to be aligned to model input aspect ratio.

1. Build PLUS

  1. Download the latest kneron_plus_enterprise_vXXX.zip into Ubuntu from https://www.kneron.com/tw/support/developers/. It is located at Kneron PLUS - enterprise section.

  2. Decompress the kneron_plus_enterprise_vXXX.zip

    $ unzip kneron_plus_enterprise_vX.X.X.zip
    
  3. Build code - Please reference Run Examples

2. Update KDP Firmware to KDP2 Usb Boot (KL520 only)

This example is to show how to connect a Kneron AI device in KDP firmware via kp_connect_device(), and the sequence of kp_load_firmware_from_file(), kp_update_kdp2_usb_loader_from_file() and kp_switch_to_kdp2_usb_boot() to update Kneron AI device from KDP firmware to KDP2 Usb boot.

$ sudo ./kl520_update_kdp_to_kdp2_usb_boot
connect device ... succeeded, return code: 0
update to kdp2 usb loader ... succeeded, return code: 0
upload to kdp2 firmware ... succeeded, return code: 0
switch to kdp2 usb boot ... succeeded, return code: 0
disconnecting device ...

3. Update KDP2 Firmware to KDP2 Usb Boot (KL520 only)

This example is to show the sequence of kp_load_firmware_from_file() and kp_switch_to_kdp2_usb_boot() to update Kneron AI device from KDP2 firmware (both Usb boot and Flash boot are acceptable) to KDP2 Usb boot.

$ ./kl520_update_kdp2_to_kdp2_usb_boot
connect device ... OK
upload firmware ... OK
update to kdp2 usb boot ... OK

4. Update KDP Firmware to KDP2 Flash Boot

This example is to show how to connect a Kneron AI device in KDP firmware via kp_connect_device(), and the sequence of kp_update_kdp2_usb_loader_from_file(), kp_load_firmware_from_file() and kp_update_kdp2_firmware_from_files() to update Kneron AI device from KDP firmware to KDP2 Flash boot.

$ sudo ./kl520_update_kdp_to_kdp2_flash_boot
connect device ... succeeded, return code: 0
update to kdp2 usb boot ... succeeded, return code: 0
upload firmware ... succeeded, return code: 0
update to kdp2 flash boot ... succeeded, return code: 0
disconnecting device ...

5. Update KDP2 Firmware to KDP2 Flash Boot

This example is to show the sequence of kp_load_firmware_from_file() and kp_update_kdp2_firmware_from_files() to update Kneron AI device from KDP2 firmware (both Usb boot and Flash boot are acceptable) to KDP2 Flash boot.

$ ./kl520_update_kdp2_to_kdp2_flash_boot
connect device ... OK
upload firmware ... OK
update kdp2 firmware ... OK

6. Update Model to Flash

This example is to show the usage of kp_update_model_from_file() to update the model into Kneron AI device's flash.

$ sudo ./kl520_update_flash_model
connect device ... OK
upload firmware ... OK
update model ... OK

7. Load Firmware through UART (KL520 only)

This example shows the usage of loading firmware into device via UART instead of loading through USB or loading from Flash.

No matter loading firmware through USB or from Flash, we need the flash of Kneron AI device to assist the process.

For those who does not import the flash module, loading firmware through UART would be the best solution.

$ sudo ./kl520_uart_boot_firmware ${COM_PORT_IDX}
com port number \\.\COM5 !!......
To program
 > SCPU FW: ../../res/firmware/KL520/kdp2_fw_scpu.bin
 > NCPU FW: ../../res/firmware/KL520/kdp2_fw_ncpu.bin

opening serial port successfulGetCommState successful!
SetCommState 115200 successful!
GetCommState successful!
Please press RESET btn!!......
sent 2 successful
Sending Minion through XModem...
Xmodem successfully transmitted 2688 bytes
SetCommState 115200 successful!
SetCommState 921600 successful
Writing KDP2 flag value at 0x10100100
Sending SCPU bin to addr 0x10104000...
Sending NCPU bin to addr 0x28000000...
Run code from addr 0x10104000...
SetCommState 115200 successful!
SetCommState 115200 successful

[0.000]
[0.000] starting KDP2 middleware ...
[0.000] creating image queue with size 10
[0.000] creating result queue with size 10
[0.000] KDP2 FW is running in flash-boot mode
[0.000] boot ncpu fw from flash
kdp2 ncpu: Ready!


CloseHandle...

8. Read / Write Device Memory

This example is to show the usage of kp_memory_read() and kp_memory_write() for reading or writing a given size of data in Kneron AI device memory.


9. Access Firmware Log via USB

This example is to show the usage of kp_enable_firmware_log() for enabling the firmware log via USB.

$ ./kl720_demo_app_yolo_inference_multithread_print_log.exe
-h     : help
-port  : [port id] = 0 (0 for auto-search)
-loop  : [test loops] = 100

connect device ... OK
upload model ... OK
read image ... OK

starting inference loop 100 times:
......................[CRITICAL] Current TDC Temperature is about [44]
..............................................................................

10. HICO Camera Inference (KL720 only)

Note: (hardware)96-Board with KL720 11x11 chip is required.

Note: (hardware)Kneron LW 3D module is required.

Note: (firmware)HICO mode is a special firmware different from the regular one. (KL720_SDK/firmware/build/solution_kdp2_hico_mipi)

In most of the previous examples, we introduced the usage of the software side to send image to device and receive the inference result from device via USB.

However, Kneron PLUS provides the HICO mode (Host In Companion Out) to make the Kneron AI device directly obtain the image to inference from the camera connected to the device. Software side can receive the inference result and the inference image from the device via USB under the HICO mode.

This example is using MIPI camera and to demonstrate the usage of activating HICO process and showing the images and inference results received from the device.

$ sudo ./kl720_demo_hico_cam_inference

# Pushing the reset button on 96board is required before rerun the example