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.

Linux/TDA2PXEVM: Regarding file read to buffer in Linux

Part Number: TDA2PXEVM

Tool/software: Linux

Dear,

I'd like to read a *.bin file to buffer to use new weight for object detection.

Related thread is here : 

https://e2e.ti.com/support/processors/f/791/p/777039/2874228#2874228

So, in usecase I wrote this code.

Void Chains_ReadAdaboostFromFile(AlgorithmLink_ObjectDetectionCreateParams *pOdPrm, char *fileName)
{
Int32 status;
UInt32 dataSize = 0;

pOdPrm->pWeightPDBuf
= OSA_memAllocSR(OSA_HEAPID_DDR_CACHED_SR1, PD_FILE_MAX_SIZE, 128);
if(!pOdPrm->pWeightPDBuf)
{
Vps_printf("Adaboost memory alloc error!!\n");
}

status = OSA_fileReadFile(
fileName,
pOdPrm->pWeightPDBuf,
PD_FILE_MAX_SIZE,
&dataSize
);
if(status == OSA_EFAIL)
{
Vps_printf("Adaboost file read error!!\n");
}

}

Do I need virtual to physics address using OSA_memVirt2Phys()?

The pOdPrm->pWeightPDBuf is used for AlgorithLink_objectDetectionInitIOBuffers() in objectDetectionLink_algPlugin.c.

Best regards,

Heechang

  • Kim,

    Since you are using Linux, you require virtual address for the file read operation.. Userspace cannot directly access physical address..

    Rgds,
    Brijesh
  • Hi Brijesh,

    Yes, so, I used OSA_fileReadFile() function.
    The "pOdPrm->pWeightPDBuf" has a virtual address if I use OSA_fileReadFile(), right?
    Then, the algorithm uses this buffer address.

    Best regards,
    Heechang
  • Hi Kim,

    is you algorithm running on A15? If yes, then you would require virtual address.

    Rgds,
    Brijesh
  • Hi Brijesh,

    The algorithm which is your algorithm of object detection for analytics2 is running on EVE and DSP, right?
    Then, should I use "OSA_memVirt2Phys()"?

    Best regards,
    Heechang
  • Hi Kim,

    This algorithm require physical address and this is why is stored in the system_frame.
    Phys2Virt is required only if you want to access this buffer in Linux application..

    Rgds,
    Brijesh
  • Hi Brijesh,

    Please, check this code.

    First, I read the binary file like below.

    Void Chains_ReadAdaboostFromFile(AlgorithmLink_ObjectDetectionCreateParams *pOdPrm, char *fileName)
    {
    Int32 status;
    UInt32 dataSize = 0;

    pOdPrm->pTransBuf = OSA_memAllocSR(OSA_HEAPID_DDR_CACHED_SR1, PD_FILE_MAX_SIZE, 128);
    if(!pOdPrm->pTransBuf)
    {
    Vps_printf("Adaboost memory alloc error!!\n");
    }

    status = OSA_fileReadFile(
    fileName,
    pOdPrm->pTransBuf,
    PD_FILE_MAX_SIZE,
    &dataSize
    );
    if(status == OSA_EFAIL)
    {
    Vps_printf("Adaboost file read error!!\n");
    }

    pOdPrm->pWeightPDBuf = OSA_memVirt2Phys((UInt32)pOdPrm->pTransBuf, OSA_MEM_REGION_TYPE_AUTO);

    }

    The structure of "AlgorithmLink_ObjectDetectionCreateParams" is like below.

    {
    ....
    UInt8 *pTransBuf;
    UInt32 pWeightPDBuf;
    } AlgorithmLink_ObjectDetectionCreateParams;


    Finally, I inserted the code in the function "AlgorithmLink_objectDetectionInitIOBuffers()" in objectDetectionLink_algPlugin.c like below.

    pInBufs->bufDesc[TI_OD_IN_BUFDESC_PD_ADABOOST_WEIGHTS]->numPlanes = 1;
    pInBufs->bufDesc[TI_OD_IN_BUFDESC_PD_ADABOOST_WEIGHTS]->bufPlanes[0].frameROI.topLeft.x = 0;
    pInBufs->bufDesc[TI_OD_IN_BUFDESC_PD_ADABOOST_WEIGHTS]->bufPlanes[0].frameROI.topLeft.y = 0;
    pInBufs->bufDesc[TI_OD_IN_BUFDESC_PD_ADABOOST_WEIGHTS]->bufPlanes[0].width = 40*1024;
    pInBufs->bufDesc[TI_OD_IN_BUFDESC_PD_ADABOOST_WEIGHTS]->bufPlanes[0].height = 1;
    pInBufs->bufDesc[TI_OD_IN_BUFDESC_PD_ADABOOST_WEIGHTS]->bufPlanes[0].frameROI.width = 40*1024;
    pInBufs->bufDesc[TI_OD_IN_BUFDESC_PD_ADABOOST_WEIGHTS]->bufPlanes[0].frameROI.height = 1;
    pInBufs->bufDesc[TI_OD_IN_BUFDESC_PD_ADABOOST_WEIGHTS]->bufPlanes[0].planeType = 0;
    pInBufs->bufDesc[TI_OD_IN_BUFDESC_PD_ADABOOST_WEIGHTS]->bufPlanes[0].buf = (void *)pObj->algLinkCreateParams.pWeightPDBuf;


    But, if I ran the app.out, the result is same.
    It looks that the "pd_adaboost_weights.bin" is not taking effect.

    Should I insert the additional code?

    Best regards,
    Heechang
  • Hi Kim,

    can you please also call OSA_memCacheWb after filling buffer with the file data?

    Rgds,
    Brijesh
  • Hi Brijesh,

    I call the OSA_memCacheWb() like below.

    But, it looks that it is not taking effect still.

    Void Chains_ReadAdaboostFromFile(AlgorithmLink_ObjectDetectionCreateParams *pOdPrm, char *fileName)
    {
    Int32 status;
    UInt32 dataSize = 0;

    pOdPrm->pTransBuf = OSA_memAllocSR(OSA_HEAPID_DDR_CACHED_SR1, PD_FILE_MAX_SIZE, 128);
    if(!pOdPrm->pTransBuf)
    {
    Vps_printf("Adaboost memory alloc error!!\n");
    }

    status = OSA_fileReadFile(
    fileName,
    pOdPrm->pTransBuf,
    PD_FILE_MAX_SIZE,
    &dataSize
    );
    if(status == OSA_EFAIL)
    {
    Vps_printf("Adaboost file read error!!\n");
    }
    OSA_memCacheWb((Uint32)pOdPrm->pTransBuf, (Uint32)pOdPrm->pTransBuf + (PD_FILE_MAX_SIZE));

    pOdPrm->pWeightPDBuf = OSA_memVirt2Phys((UInt32)pOdPrm->pTransBuf, OSA_MEM_REGION_TYPE_AUTO);

    }

    Best regards,

    Heechang

  • Hi Kim,

    Are you sure that the file is getting written correctly to the allocated buffer? could you please connect to one of the other core and check the contents of the buffer memory and confirm if it is written correctly?

    Rgds,

    Brijesh

  • Hi Brijesh,

    I write the buffer to file and I confirmed the file is correct.
    Is this code is right?
    {
    ....
    UInt8 *pTransBuf;
    UInt8 pWeightPDBuf;

    } AlgorithmLink_ObjectDetectionCreateParams;

    UInt32 AlgorithmLink_objectDetectionInitIOBuffers(AlgorithmLink_ObjectDetectionObj *pObj )
    {
    ...
    ...
    pInBufs->bufDesc[TI_OD_IN_BUFDESC_PD_ADABOOST_WEIGHTS]->bufPlanes[0].buf = (UInt8*)pObj->algLinkCreateParams.pWeightPDBuf;
    ...
    }

    Best regards,
    Heechang
  • Hi Kim,

    Which means file io and buffer logic is working fine.. correct?

    Rgds,
    Brijesh
  • Hi Brijesh,

    Yes and I found something strange.
    The training file of binary is every same although I put into different input dataset.
    I'm using AdaboostTableGen.exe for converting *.descriptor to *.bin file.
    Is this correct?

    Best regards,
    Heechang
  • Hi Kim,

    I am not familiar with this tool, so will not be help much for this tool. Can you please check on the other thread, where you are talking about adaboost algo?

    Rgds,
    Brijesh
  • Hi Brijesh,

    OK, thank you.

    Best regards,
    Heechang