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.

PROCESSOR-SDK-TDAX: Convert PC based C code to Embbeded code for SoC

Part Number: PROCESSOR-SDK-TDAX

Hi all,

I have a PC based C code for my application. I need to convert it to a format that can be run on target hardware.

Also, I referred about the PyTIOVX tool, but it generates OpenVX C code when given .py file with TIOVX module as input.

Please tell me if my understanding on PyTIOVX is correct and also suggest me a solution to convert C code to OpenVX C code to be run on target device.

Thanks in Advance!

Regards,

Padmasree N.

  • Hello Padmasree,

    It looks like there may be a bug when using the vx_array in this way.  We will need to investigate this further on our end to ensure that this is working properly.

    In the meantime, it looks like from the code that there will just be a single array element from this output, which makes it seem like a vx_scalar will work instead of a vx_array.  In that case, I would recommend using a vx_scalar instead of a vx_array.  We have several test cases using this, so this should work fine.  Please let me know if this will work with your solution.

    Regards,

    Lucas

  • Hello Lucas,

    Thanks for your reply!

    Please let me know the bug fixing is done. Please update here.

    While I will parallely try with vx_scalar and will update here tomorrow.

    Please confirm me if this is the right way to get output from scalar object.

    float *output =(float*)malloc(1*sizeof(float));
    vxCopyScalar(uc.median_out,(void*)output,VX_READ_ONLY,VX_MEMORY_TYPE_HOST);
    printf("output from app graph is %f\n",output);

    Thanks and Regards,

    Padmasree N.

  • Hello Lucas,

    I have built and compiled my C source code and added as a static library to my kernel. Is there any way that I can include my C source code directly without compiling?

    If so, Please tell me how to do it.

    Regards,

    Padmasree N.

  • Hello Lucas,

    I have tried with vx_scalar as you mentioned.Yet, the output shows 0.0000 in the graph.

    I am using PSDK j7_07_00_00_11.

    Please help me in solving the issue and also tell me a way to include the C source file directly onto the application without building and compiling as a static library.

    Regards,

    Padmasree N.

  • Hello Padmasree,

    Could you please provide your full source so that I can see what is going wrong?

    Regarding the including of the C source file onto the application, could you elaborate on what exactly you want to do?  I am not understanding the request.

    Regards,

    Lucas

  • Hi Lucas,

    I have built and compiled my C source code (which has function definition of my Kernel) as a STATIC LIBRARY. Since larger number of Static Libs load the core and slower down, please tell me a way to include the C source code directly in my Kernel and application graph.

    Regards,

    Padmasree N.

  • Hello Lucas,

    Please have a look at the above query and advice me where I am going wrong.

    Hoping to get the reply soon Slight smile

    Regards,

    Padmasree N.

  • Hello Padmasree,

    The scalar value needs to be set in a slightly different way in the kernel code.  You can set the float value as shown below:

    median_desc->data.f32 = <float value>

    You can also reference the kernel shown below for how this can be done:

    tiovx/kernels/openvx-core/c66x/vx_meanstddev_target.c

    Regarding building your C source, you can build it in with the kernel code by simply adding it into the concerto.mak located at median_demo/cam_calib/a72/concerto.mak and moving your source file to this directory.  It is currently setting CSOURCES to all C files in this directory.  Since it looks like you are using a cpp file, you would need to add the below to this file as well.

    CPPSOURCES  := $(call all-cpp-files)

    Regards,

    Lucas

  • Hello Lucas,

    Thanks for your reply!

    median_desc->data.f32 = <float value>

    I did not understand in vx_median_target.c ,where I need to include the above line.

    Please do throw some light on this. 

    Regarding CPP building through concerto, I tried the way you mentioned and it is working.

    Thanks and Regards,

    Padmasree N.

  • Hello Padmasree,

    You don't need the median_target_ptr anymore.  You just need the below:

    median_desc->data.f32 =getmedian((float*)values_target_ptr,10);

    Regards,

    Lucas

  • Hello Lucas,

    I tried the same and yet I am getting 0.0000 only as the output.

    Regards,

    Padmasree N.

  • Hello,

    Can you try modifying the application where you are doing the copy to the below?

           vx_float32 output;
           vxCopyScalar(uc.median_out,&output,VX_READ_ONLY,VX_MEMORY_TYPE_HOST);

    Regards,

    Lucas

  • Hi Lucas,

    The issue remains the same after modifications. Please help me in resolving this.

    Regards,

    Padmasree N.

  • Hello,

    Can you send a zip file of all your latest changes, including moving the cpp file to the target kernel, so that I can try on my end?

    Lucas

  • Hi Lucas,

    I am now building the same way as I have shared already by making two modifications (median_desc->data.f32) and application graph changes mentioned by you.

    Regards,

    Padmasree N.

  • Hello Lucas,

    Is it working fine at your end?

    Regards,

    Padmasree N.

  • Hello Padmasree,

    I took your original zip file and tried it on my end.  I was having trouble compiling the getmedian function given that I am not familiar with CMake.  However, I modified the kernel source to the below for test purposes and added a print in the kernel code:

            median_desc->data.f32 = 1.0f;

    With your previous vxCopyScalar implementation, I saw 0.000f.  However, with the below change to the application, I saw the scalar value set to 1.0f in the application:

           vx_float32 output;
           vxCopyScalar(uc.median_out,&output,VX_READ_ONLY,VX_MEMORY_TYPE_HOST);

    Please confirm you have tried with the above implementation.

    Regards,

    Lucas

  • Hi Lucas,

    Thanks for your reply!

    I tried the same and got 1.0f from my application graph. So, it means that there's some issue with my CPP source code when passing computed output back to calling kernel.

    I have checked the code and it is fine.But I dont have an idea of why this issue occurs with my CPP code.

    Please verify if there is any issue with my source code.

    Thanks and Regards,

    Padmasree N.

  • Hi Padmasree,

    I don't see any obvious issues with your code.  It looks like all the headers starting with "ut_*" were not included in the code you provided so that is why I wasn't able to build the source to confirm.

    Regards,

    Lucas

  • Hello Lucas,

    Please find the updated code and provide me with the best solution.

    Thanks in Advance! Slight smile

    Regards,

    Padmasree N.

  • Hello Padmasree,

    It looks like you just commented out these includes, but that causes a compilation issue as shown below.  Can you send me the version where you have integrated this with the concerto.mak as was mentioned earlier?

    /ti/j7presi/workarea/vision_apps/kernels/cam_calib/a72/median.cpp:6:9: error: ‘ptrdiff_t’ does not name a type
     typedef ptrdiff_t ut_Size;
             ^
    /ti/j7presi/workarea/vision_apps/kernels/cam_calib/a72/median.cpp: In function ‘float32_t getmedian(std::vector<float>&)’:
    /ti/j7presi/workarea/vision_apps/kernels/cam_calib/a72/median.cpp:17:19: error: ‘ut_Size’ does not name a type
                 const ut_Size leftIdx = (values.size() - 1) / 2;
                       ^
    /ti/j7presi/workarea/vision_apps/kernels/cam_calib/a72/median.cpp:18:19: error: ‘ut_Size’ does not name a type
                 const ut_Size rightIdx = (values.size() - 1) / 2 + 1;
                       ^
    /ti/j7presi/workarea/vision_apps/kernels/cam_calib/a72/median.cpp:19:30: error: ‘leftIdx’ was not declared in this scope
                 median = (values[leftIdx] + values[rightIdx]) / 2.f;
                                  ^
    /ti/j7presi/workarea/vision_apps/kernels/cam_calib/a72/median.cpp:19:48: error: ‘rightIdx’ was not declared in this scope
                 median = (values[leftIdx] + values[rightIdx]) / 2.f;

  • Hello Lucas,

    I have built the static library only and it is succesfull without the headers as I have included the corresponding typedefs directly onto the median.cpp. 

    And I request you to please try building as a static library and then include in the application graph concerto.mak file to avoid these errors.

    Also, ptrdiff_t is used for pointer arithmetic and array indexing and is available under <stddef.h> 

    Please try the same and let me know the issues if any.

    Regards,

    Padmasree N.

  • Hello Padmasree,

    It seems like I am unable to build this.  Please send the updates we mentioned before where this file has been added to the concerto.mak and the median_demo/cam_calib/a72/ folder, otherwise, I won't be able to run this to test.

    Regards,

    Lucas

  • Hello Lucas,

    Please try if this works.

    It seems to work fine from my end now.

    Regards,

    Padmasree N.

  • Hello Padmasree,

    I see this issue on my end as well.  Could you try modifying the getmedian function to use pass by reference as shown below and setting the *ret to the output value?  I tried this on my end and it worked.

    void getmedian(float* arr, int n, float* ret);

    Regards,

    Lucas

  • Hello Lucas,

    Thanks for your reply!

    I tried modifying the kernel to 

    getmedian(values_target_ptr,3,median_target_ptr);

    and I am getting 

    Segmentation fault(core dumped) from my application graph.

    Is this all the changes or are there any changes need to be made?

    Regards,

    Padmasree N.

  • Hello,

    In the kernel, please add the following.  You don't need median_target_ptr at all.

    vx_float32 tmp;

    getmedian(values_target_ptr, 3, &tmp);

    median_desc->data.f32 = tmp;

    Regards,

    Lucas

  • Hello Lucas,

    Thanks for your reply!

    It is working from my end as well..

    Thanks for your time in providing the best solution!

    Regards,

    Padmasree N

  • Hi Lucas,

    Please suggest me a data object to pass input of the form

    ut_Vec3F32 input[3]={{0.228500 ,0.374200 ,0.000000} ,{0.112500 ,0.387800 ,0.000000} ,{0.041200 ,0.363200 ,0.000000} };

    where,

    typedef struct

    { float data[3];

    }ut_Vec3F32;

    Also I am facing the same issue output=0.0000 with array object. Please verify if the below lines for kernel call is right or do I need to make any modifications?

    {
    vx_array temp,temp1;


    rotationaxisandangle_desc->num_items = 8;

    ut_solvePnP(objectpoints_target_ptr,imagepoints_target_ptr,npoints_target_ptr,&cameramatrix_target_ptr,distcoeffs_target_ptr,
    ndistcoeffs_target_ptr,&temp,&temp1,memorysolvepnp_target_ptr);

    }

    where temp and temp1 contains the output. How do I assign the values stored in them to display in my graph?

    Regards,

    Padmasree N.

  • Hello Padmasree,

    Since we were able to resolve your previous issues, can you start a new forum thread for these issues?  I want to be sure that each question is answered appropriately.

    Regards,

    Lucas

  • Hello Lucas, 

    Any updates on the above thread?

    Hoping for a sooner reply Slight smile

    Regards,

    Padmasree N.

  • Hello Lucas,

    Any updates on the thread?

    Regards,

    Padmasree N.