This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] J784S4XEVM: Performance Benchmarking of a Custom Vision Apps Kernel Using GTC Timer and TSC Across Various Optimization Levels

Part Number: J784S4XEVM

Hi Team,

How can the performance of a custom kernel be benchmarked using GTC Timer and TSC, and how can the results be evaluated across different optimization levels?


  • The custom benchmark is integrated into the vision_apps framework using Concerto build files and C7x firmware updates. The patch adds the benchmark source files, updates the firmware integration flow, and enables execution of the benchmark during C7x startup. The integration involves adding the benchmark source and header files, configuring the concerto.mak build file, updating the firmware link configuration, and invoking the benchmark function from the C7x startup flow. 

    For adding the library to the C7x_1 firmware link modify the vision_apps/platform/j784s4/rtos/concerto_c7x_inc.mak and add the new library to the STATIC_LIBS list 

    The following steps describe the integration of a custom C7x kernel with GTC timer-based profiling support, building the SDK with the modified implementation, preparing the SD card for booting, and executing the application on the target platform. 

    PSDK_PATH = <PATH_TO_RTOS_SDK > 

    Steps for setting up the GTC timer 

    1) Include the required GTC timer header 

    • #include <utils/console_io/include/app_log.h> 

    2) Use the GTC timer API to measure execution time

    uint64_t t_start, t_end; 
    
    t_start = appLogGetGlobalTimeInUsec(); 
    
    /* code under test */ 
    
    t_end = appLogGetGlobalTimeInUsec(); 
    
    elapsed_us = t_end - t_start; 

    3) Invoke the benchmark function after appInit() and before appRun() in vision_apps/platform/j784s4/rtos/c7x_1/main.c

    4) Allocate benchmark data in L2 SRAM

    float *l2_mat = (float *)appMemAlloc(APP_MEM_HEAP_L2, size_in_bytes,alignment) 

    Steps for implementing the custom c7x kernel  

    1) Copy the patch file to the SDK root directory

    • cp apply_c7x_opt_benchmark.patch $PSDK_PATH

    2) Navigate to the SDK root Directory 

    • cd $PSDK_PATH 

    3) Apply the Patch 

    4) Verify the patch is applied correctly 

    • cd $PSDK_PATH/vision_apps/apps/basic_demos/app_c7x_opt_benchmark

    Steps for building the SDK 

    1) Clean the previous SDK build

    • make sdk_scrub 

    2) Build the SDK with the required optimization level

    • make sdk BENCHMARK_OPT_LEVEL=0 -j8 

    Steps for SD Card Partition 

    1) Insert SD card device

    2) Identify SD card device

    • df -h 

    3) Unmount SD card partitions

    • sudo umount /dev/sda1
    • sudo umount /dev/sda2

    4) Partition and format SD card

    • cd $PSDK_PATH 
    • sudo sdk_builder/scripts/mk-linux-card.sh /dev/sda 

    5) Remove and Reinsert the SD card into the SD card slot

    6) Install bootloader and roofs to SD card

    • sdk_builder/scripts/install_to_sd_card.sh

    7) Copy executable to the SD card

    • cd $PSDK_PATH/sdk_builder 
    • make linux_fs_install_sd 

    8) Remove the SD card and insert it back into the board

    Steps for running on EVM 

    Setup   

    1) Connect to UART Port  

    2) Configure in SD BOOT using the BOOT pins 

    1) Opens a UART serial console to the target device

    2) Login as root  

    3) Navigate to vision_apps and initialise it

    • cd /opt/vision_apps 
    • source ./vision_apps_init.sh 

    4) Verify the optimization results in the terminal output.

    The optimization levels achieved by running this kernel for different optimization levels(0 to 4) are as follows: 

    Optimisation Level Cycle count
    0 1889
    1 1622
    2 47
    3 24
    4 24

    Steps for iterative build 

    1) Navigate to the SDK builder directory

    • cd $PSDK_PATH/sdk_builder 

    2) Delete only the benchmark artifacts

    • rm -rf ../vision_apps/out/J784S4/C7120/FREERTOS/release/module/apps.basic_demos.app_c7x_opt_benchmark.c7x
    • rm -f  ../vision_apps/out/J784S4/C7120/FREERTOS/release/vx_app_c7x_opt_benchmark.lib 

    3) Rebuild only for vision_apps 

    • make vision_apps BENCHMARK_OPT_LEVEL=0 -j8   # change 0 → 1, 2, 3 each time 

    4) Copy firmware to SD card

    • make linux_fs_install_sd 

    5) Repeat the steps for running on EVM for testing on the other optimization levels



    Implementation of TSC counter in standalone code:

    extern volatile __cregister unsigned long __TSC;
    
    unsigned long start_time;
    
    unsigned long stop_time;
    
    start_time = __TSC;
     
    <Test code>
     
    stop_time = __TSC;
    
    printf("\nClock cycles elapsed = %lu",stop_time - start_time);

    The code for the implementation of TSC counter on standalone code is

     standalone_code.cpp

    The optimization levels achieved by running this standalone kernel for different optimization levels(0 to 4) are as follows: 

    Optimisation level Cycle count
    0 2147341
    1 1817727
    2 105121
    3 105184
    4 103445


    Regards,
    Shabary S Sundar