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.

TDA4VM: program gets stuck when deployed on SDK 8.2

Part Number: TDA4VM


Hi Team,

Issue: When deploying a model of face critical point detection on the 8.6 SDK will work and get the right results, but the program will get stuck in the tivxAlgiVisionProcess function when deploy it on the 8.2 SDK. 

Using the EVM board J784S4XG01EVM and perform the following steps:

1) Prepare the bin file for the face critical Point Detection Model (PFLD) for SDK 8.2 and SDK 8.6 and the running cfg file, which is tidl_io_pfld_1.bin and tidl_net_pfld.bin. the .cfg file is app_my.cfg. Consumer has uploaded to Google Drive at the following link: 

SDK 8.2: https://drive.google.com/file/d/1ZSKoRsou3eC7-526ZADT2MKcRb0XOaIY/view?usp=drive_link

SDK 8.6: https://drive.google.com/file/d/1mAoLMCnnGSjdvKkEUfxBxur28pCd6ny4/view?usp=drive_link

2) Modifying vision_apps/kernels/img_proc/c66/vx_draw_box_detections_target.c as follows:

#include <TI/tivx.h>
#include <TI/tivx_img_proc.h>
#include <TI/tivx_target_kernel.h>
#include <tivx_kernels_target_utils.h>
#include <utils/udma/include/app_udma.h>
#include <utils/mem/include/app_mem.h>

#include <tivx_draw_box_detections_host.h>
#include "itidl_ti.h"
#include <math.h>

static tivx_target_kernel vx_DrawBoxDetections_kernel = NULL;

static void drawPoints(vx_uint8 *data_ptr_1, vx_uint8 *data_ptr_2, vx_uint32 width, vx_uint32 height, vx_uint32 x_offset, vx_uint32 y_offset,
                       vx_uint32 *kp_ptr, vx_uint32 num_points, vx_uint8 dim, vx_uint8 color_map[][3]);

static vx_float32 prob[196];
static vx_uint32 point[196];

#if defined(SOC_J721E) || defined(SOC_J721S2)
#ifndef x86_64
#if CPU_COPY    /* Not enabled - change to 1 for doing CPU copy */
static void memcpyC66(uint8_t *restrict pOut, uint8_t *restrict pIn, int32_t size)
{
    int32_t remSize = size - ((size >> 3) << 3);
    int32_t i;

    for(i = 0; i < size; i+=8)
    {
        _mem8(&pOut[i]) = _mem8(&pIn[i]);
    }
    if(remSize > 0)
    {
        i-=8;
        for(; i < size; i++)
        {
            pOut[i] = pIn[i];
        }
    }
}
#else
static void memcpyC66(uint8_t *pOut, uint8_t *pIn, int32_t size)
{
    app_udma_copy_1d_prms_t prms_1d;

    appUdmaCopy1DPrms_Init(&prms_1d);
    prms_1d.dest_addr   = appMemGetVirt2PhyBufPtr((uint64_t) pOut, APP_MEM_HEAP_DDR);
    prms_1d.src_addr    = appMemGetVirt2PhyBufPtr((uint64_t) pIn, APP_MEM_HEAP_DDR);
    prms_1d.length      = (uint32_t) size;
    appUdmaCopy1D(NULL, &prms_1d);
}
#endif
#else
#define memcpyC66 memcpy
#endif
#else
#define memcpyC66 memcpy
#endif

static vx_status VX_CALLBACK tivxKernelDrawBoxDetectionsCreate
(
    tivx_target_kernel_instance kernel,
    tivx_obj_desc_t *obj_desc[],
    vx_uint16 num_params,
    void *priv_arg
)
{
    vx_status status = VX_SUCCESS;
    uint32_t i;

    for (i = 0U; i < num_params; i ++)
    {
        if (NULL == obj_desc[i])
        {
            status = VX_FAILURE;
            break;
        }
    }

    return(status);
}

static vx_status VX_CALLBACK tivxKernelDrawBoxDetectionsDelete(
    tivx_target_kernel_instance kernel, tivx_obj_desc_t *obj_desc[],
    vx_uint16 num_params, void *priv_arg)
{
    vx_status status = VX_SUCCESS;
    uint32_t i;

    for (i = 0U; i < num_params; i ++)
    {
        if (NULL == obj_desc[i])
        {
            status = VX_FAILURE;
            break;
        }
    }

    return (status);
}

static vx_status VX_CALLBACK tivxKernelDrawBoxDetectionsProcess
(
    tivx_target_kernel_instance kernel,
    tivx_obj_desc_t *obj_desc[],
    vx_uint16 num_params,
    void *priv_arg
)
{
    vx_status status = VX_SUCCESS;
    vx_int32 i;

    for (i = 0U; i < num_params; i ++)
    {
        if (NULL == obj_desc[i])
        {
            status = VX_FAILURE;
            break;
        }
    }

    if (VX_SUCCESS == status)
    {
        tivx_obj_desc_user_data_object_t* config_desc;
        void * config_target_ptr = NULL;

        tivx_obj_desc_tensor_t* input_tensor_desc;
        void * input_tensor_target_ptr = NULL;

        tivx_obj_desc_image_t* input_image_desc;
        void * input_image_target_ptr[2];

        tivx_obj_desc_image_t* output_image_desc;
        void * output_image_target_ptr[2];

        input_image_target_ptr[0] = NULL;
        input_image_target_ptr[1] = NULL;

        output_image_target_ptr[0] = NULL;
        output_image_target_ptr[1] = NULL;

        config_desc = (tivx_obj_desc_user_data_object_t *)obj_desc[TIVX_KERNEL_DRAW_BOX_DETECTIONS_CONFIGURATION_IDX];
        config_target_ptr = tivxMemShared2TargetPtr(&config_desc->mem_ptr);
        tivxMemBufferMap(config_target_ptr, config_desc->mem_size, VX_MEMORY_TYPE_HOST,VX_READ_ONLY);

        input_tensor_desc = (tivx_obj_desc_tensor_t *)obj_desc[TIVX_KERNEL_DRAW_BOX_DETECTIONS_INPUT_TENSOR_IDX];
        input_tensor_target_ptr = tivxMemShared2TargetPtr(&input_tensor_desc->mem_ptr);
        tivxMemBufferMap(input_tensor_target_ptr, input_tensor_desc->mem_size, VX_MEMORY_TYPE_HOST,VX_READ_ONLY);

        input_image_desc = (tivx_obj_desc_image_t *)obj_desc[TIVX_KERNEL_DRAW_BOX_DETECTIONS_INPUT_IMAGE_IDX];
        input_image_target_ptr[0] = tivxMemShared2TargetPtr(&input_image_desc->mem_ptr[0]);
        tivxMemBufferMap(input_image_target_ptr[0], input_image_desc->mem_size[0], VX_MEMORY_TYPE_HOST,VX_READ_ONLY);
        input_image_target_ptr[1] = NULL;
        if(input_image_desc->mem_ptr[1].shared_ptr != 0)
        {
            input_image_target_ptr[1] = tivxMemShared2TargetPtr(&input_image_desc->mem_ptr[1]);
            tivxMemBufferMap(input_image_target_ptr[1], input_image_desc->mem_size[1], VX_MEMORY_TYPE_HOST,VX_READ_ONLY);
        }

        output_image_desc = (tivx_obj_desc_image_t *)obj_desc[TIVX_KERNEL_DRAW_BOX_DETECTIONS_OUTPUT_IMAGE_IDX];
        output_image_target_ptr[0] = tivxMemShared2TargetPtr(&output_image_desc->mem_ptr[0]);
        tivxMemBufferMap(output_image_target_ptr[0], output_image_desc->mem_size[0], VX_MEMORY_TYPE_HOST,VX_WRITE_ONLY);
        if(output_image_desc->mem_ptr[1].shared_ptr != 0)
        {
            output_image_target_ptr[1] = tivxMemShared2TargetPtr(&output_image_desc->mem_ptr[1]);
            tivxMemBufferMap(output_image_target_ptr[1], output_image_desc->mem_size[1], VX_MEMORY_TYPE_HOST,VX_WRITE_ONLY);
        }

        if(output_image_desc->mem_size[0] == input_image_desc->mem_size[0])
        {
            memcpyC66(output_image_target_ptr[0], input_image_target_ptr[0], output_image_desc->mem_size[0]);
        }

        if(output_image_desc->mem_size[1] == input_image_desc->mem_size[1])
        {
            memcpyC66(output_image_target_ptr[1], input_image_target_ptr[1], output_image_desc->mem_size[1]);
        }

        tivxDrawBoxDetectionsParams *params;
        params = (tivxDrawBoxDetectionsParams *)config_target_ptr;

        vx_uint32 point_num = 0;
        for (i = 0; i < 196; i++)
        {
            prob[i] = ((vx_float32)(((vx_uint16 *)input_tensor_target_ptr)[i])) / 16384.0;
        }
        for (i = 0, point_num = 0; i < 98; i++, point_num++)
        {
            point[2 * point_num] = prob[2 * i] * 448;
            point[2 * point_num + 1] = prob[2 * i + 1] * 448;
        }

        drawPoints((vx_uint8 *)output_image_target_ptr[0], (vx_uint8 *)output_image_target_ptr[1], 448, 448,
                    0, 0, point, point_num, 1, &params->color_map[0]);

        tivxMemBufferUnmap(config_target_ptr, config_desc->mem_size, VX_MEMORY_TYPE_HOST, VX_READ_ONLY);
        tivxMemBufferUnmap(input_tensor_target_ptr, input_tensor_desc->mem_size, VX_MEMORY_TYPE_HOST, VX_READ_ONLY);

        tivxMemBufferUnmap(input_image_target_ptr[0], input_image_desc->mem_size[0], VX_MEMORY_TYPE_HOST, VX_READ_ONLY);
        if(input_image_target_ptr[1] != NULL)
        {
            tivxMemBufferUnmap(input_image_target_ptr[1], input_image_desc->mem_size[1], VX_MEMORY_TYPE_HOST, VX_READ_ONLY);
        }

        tivxMemBufferUnmap(output_image_target_ptr[0], output_image_desc->mem_size[0], VX_MEMORY_TYPE_HOST, VX_WRITE_ONLY);
        if(output_image_target_ptr[1] != NULL)
        {
            tivxMemBufferUnmap(output_image_target_ptr[1], output_image_desc->mem_size[1], VX_MEMORY_TYPE_HOST, VX_WRITE_ONLY);
        }
    }

    return (status);
}
void tivxAddTargetKernelDrawBoxDetections()
{
    vx_status status = (vx_status)VX_FAILURE;
    char target_name[TIVX_TARGET_MAX_NAME];
    vx_enum self_cpu;

    self_cpu = tivxGetSelfCpuId();

    if (self_cpu == TIVX_CPU_ID_A72_0)
    {
        strncpy(target_name, TIVX_TARGET_A72_0, TIVX_TARGET_MAX_NAME);
        status = (vx_status)VX_SUCCESS;
    }
    else
    {
        status = tivxKernelsTargetUtilsAssignTargetNameDsp(target_name);
    }

    if( (vx_status)VX_SUCCESS == status)
    {
        vx_DrawBoxDetections_kernel = tivxAddTargetKernelByName
                                     (
                                        TIVX_KERNEL_DRAW_BOX_DETECTIONS_NAME,
                                        target_name,
                                        tivxKernelDrawBoxDetectionsProcess,
                                        tivxKernelDrawBoxDetectionsCreate,
                                        tivxKernelDrawBoxDetectionsDelete,
                                        NULL,
                                        NULL
                                     );
    }
}

void tivxRemoveTargetKernelDrawBoxDetections()
{
    vx_status status = VX_SUCCESS;

    status = tivxRemoveTargetKernel(vx_DrawBoxDetections_kernel);
    if (status == VX_SUCCESS)
    {
        vx_DrawBoxDetections_kernel = NULL;
    }
}
static void drawPoints(vx_uint8 *data_ptr_1, vx_uint8 *data_ptr_2, vx_uint32 width, vx_uint32 height, vx_uint32 x_offset, vx_uint32 y_offset,
                       vx_uint32 *kp_ptr, vx_uint32 num_points, vx_uint8 dim, vx_uint8 color_map[][3])
{
    vx_uint8 color[3];
    vx_uint32 kp_x, kp_y;

    color[0] = color_map[0][0];
    color[1] = color_map[0][1];
    color[2] = color_map[0][2];

    vx_int32 i = 0, j = 0, k = 0;
    for (i = 0; i < num_points; i++)
    {
        kp_x = (vx_uint32)((vx_float32)kp_ptr[2 * i]) + x_offset;
        kp_y = (vx_uint32)((vx_float32)kp_ptr[2 * i + 1]) + y_offset;
        for (j = -((dim - 1) / 2); j < ((dim + 1) / 2); j++)
        {
            for (k = -((dim - 1) / 2); k < ((dim + 1) / 2); k++)
            {
                data_ptr_1[(kp_y * width) + kp_x + (j * width) + k] = color[0];
            }
        }
        for (j = -((dim - 1) / 2); j < ((dim + 1) / 2); j++)
        {
            for (k = -((dim - 1) / 2); k < ((dim + 1) / 2); k++)
            {
                data_ptr_2[((kp_y + j) >> 1) * width + (kp_x + k)] = color[1];
                data_ptr_2[((kp_y + j) >> 1) * width + (kp_x + k) + 1] = color[2];
            }
        }
    }
}

3) Build the SDK.

4) The routine used is vision_apps/dl_demos/app_tidl_od, the generated executable is VX_app_tidl_od.out, run VX_app_tidl_od.out on the EVM board -- Cfg app_my.cfg.

5) The log information obtained on SDK 8.2 is as follows, and the program will get stuck at this time:

The screen appears as follows:

Could you please help check this case? Thanks.

Best Regards,

Cherry