CVCell Framework

From OpenCV on the Cell

Jump to: navigation, search

We use the programming model which the PPE is used for execution of the main program and the SPEs for execution of a sub-program. In this model, the main program executed on the PPE divides a sequence of processes or data and distributes a segment to every SPE for processing by the sub-program running on the SPEs. Upon completion of the requested operation, the SPE program returns the processed result to the PPE program.

You will be able to image that OpenCV application calls OpenCV Library. You can also think that OpenCV Library calls IPP(Integrated Performance Primitives), MKL(Math Kernel Library), and CVCell Library(PPE and SPE modules for optimization). SPE module processes as PPE module calls.


Function call flow

We can show you the function flow as follows. The following figure show you what CVCell module (PPE module and SPE module) does. OpenCV application calls OpenCV API. PPE module that is called by OpenCV API sends a function code to SPE Dispatcher. SPE function called by SPE Dispatcher processes.

The following figure explains the case of a cvRandArr function call.

  1. OpenCV application calls OpenCV API.
  2. OpenCV API calls PPE module.
  3. PPE function sends a function code CV_RANDARR to SPE Dispatcher. SPE Dispatcher calls SPE module. SPE function is loaded at application starting, and waiting completion, and receive result.
  4. SPE function processes Image Data of main memory.


Sample code

The sample code of ppu/cxrand.cpp is shown below:

#include "ppubase.h"

CV_IMPL void
cvRandArr( CvRNG* rng, CvArr* arr, int disttype, CvScalar param1, CvScalar param2 )
{
    ...
    SpeAllocatorResult spes[1];
    unsigned int funccode = CV_RANDARR;
    ...
    // allocate one spe
    speAllocatorAllocSpe( &cvCellSpeAllocator, 1, spes, -1 );
    // call spe method
    cvCellSpeCallFunc( spes[0], CV_RANDARR);
    // send parameter
    cvCellSpeWriteParamAddr( spes[0].spe, &param[0] );
    ...
    // receive 64bit return code
    uint32_t hi,lo;
    spe_out_intr_mbox_read( spes[0].spe, &lo, 1, SPE_MBOX_ALL_BLOCKING );
    spe_out_mbox_read( spes[0].spe, &hi, 1 );
    ...
    // free one spe
    speAllocatorFreeSpe( &cvCellSpeAllocator, 1, spes );
}

First, it allocates SPE which CVCell manages and sends function code CV_RANDARR to SPE. Next, it sends a parameters using cvCellSpeWriteParamAddr() and waits for a return code using spe_out_intr_mbox_read().


The sample code of spu/cvRandArr_spu.cpp is shown below:

extern "C" int cvRandArr_spu()
{
    // clear .bss section (because of overlay)
    CLEAR_BSS;
    ...

    // get param
    cvCellSpeReadParam( &param );
    ...

    // process the region specified as parameter
    while(remain){
        // get image data
        spu_mfcdma64(..., MFC_GET_CMD);
        ...
        // call the cvRandArr function in org/cxrand.cpp
        cvRandArr(&param.rng, &mat, param.disttype, param.param1, param.param2);
        ...
        // put image data
        spu_mfcdma64(..., MFC_PUT_CMD);
        ...
    }

    // send result to PPE
    spu_write_out_mbox( (uint32_t)((param.rng)>>32) );
    spu_write_out_intr_mbox( (uint32_t)(param.rng) );
}

It performs a DMA transfer for get/put image data, and calls cvRandArr function in org/cxrand.cpp.


Note:In this case, org/cxrand.cpp is not optimized.

Views
Personal tools
Toolbox