3
\$\begingroup\$

I have used Intel VTune in order to find the hotspots in my code. I wrote comments next to the worst lines.

Can you please review my code? General review or performance issues is more than welcome.

void ALGO::computeSADs(int (&nbr_SAD_RES)[ALGO_NBR_SZ][ALGO_NBR_SZ], int (&SAD)[ALGO_NUM_CANDIDATE])
{
    // Computes SAD values between P and each candidate in the neighborhood.
    //
    // Type  | Name        | Size                      | Precision      |
    // ------+-------------+---------------------------+----------------|
    // Input | Nbr_SAD_RES | ALGO_NBR_SZ x ALGO_NBR_SZ | ALGO_SIM_RES   |
    // Output| SAD         | 1 x ALGO_NUM_CANDIDATE    | ALGO_SAD_RES   |
    //

    int candLocX[ALGO_NUM_CANDIDATE];
    int candLocY[ALGO_NUM_CANDIDATE];   

    // init inner candidate position vectors
    candLocX[0 ]  = ALGO_CAND00_LOC_X;
    candLocY[0 ]  = ALGO_CAND00_LOC_Y;
    candLocX[1 ]  = ALGO_CAND01_LOC_X;
    candLocY[1 ]  = ALGO_CAND01_LOC_Y;
    candLocX[2 ]  = ALGO_CAND02_LOC_X;
    candLocY[2 ]  = ALGO_CAND02_LOC_Y;
    candLocX[3 ]  = ALGO_CAND03_LOC_X;
    candLocY[3 ]  = ALGO_CAND03_LOC_Y;
    candLocX[4 ]  = ALGO_CAND04_LOC_X;
    candLocY[4 ]  = ALGO_CAND04_LOC_Y;
    candLocX[5 ]  = ALGO_CAND05_LOC_X;
    candLocY[5 ]  = ALGO_CAND05_LOC_Y;
    candLocX[6 ]  = ALGO_CAND06_LOC_X;
    candLocY[6 ]  = ALGO_CAND06_LOC_Y;
    candLocX[7 ]  = ALGO_CAND07_LOC_X;
    candLocY[7 ]  = ALGO_CAND07_LOC_Y;
    if (m_CandConstellation==0) {
        candLocX[8 ]  = ALGO_CAND08_0_LOC_X;
        candLocY[8 ]  = ALGO_CAND08_0_LOC_Y;
        candLocX[9 ]  = ALGO_CAND09_0_LOC_X;
        candLocY[9 ]  = ALGO_CAND09_0_LOC_Y;
        candLocX[10]  = ALGO_CAND10_0_LOC_X;
        candLocY[10]  = ALGO_CAND10_0_LOC_Y;
        candLocX[11]  = ALGO_CAND11_0_LOC_X;
        candLocY[11]  = ALGO_CAND11_0_LOC_Y;
        candLocX[12]  = ALGO_CAND12_0_LOC_X;
        candLocY[12]  = ALGO_CAND12_0_LOC_Y;
        candLocX[13]  = ALGO_CAND13_0_LOC_X;
        candLocY[13]  = ALGO_CAND13_0_LOC_Y;
        candLocX[14]  = ALGO_CAND14_0_LOC_X;
        candLocY[14]  = ALGO_CAND14_0_LOC_Y;
        candLocX[15]  = ALGO_CAND15_0_LOC_X;
        candLocY[15]  = ALGO_CAND15_0_LOC_Y;
    } else if (m_CandConstellation==1) {
        candLocX[8 ]  = ALGO_CAND08_1_LOC_X;
        candLocY[8 ]  = ALGO_CAND08_1_LOC_Y;
        candLocX[9 ]  = ALGO_CAND09_1_LOC_X;
        candLocY[9 ]  = ALGO_CAND09_1_LOC_Y;
        candLocX[10]  = ALGO_CAND10_1_LOC_X;
        candLocY[10]  = ALGO_CAND10_1_LOC_Y;
        candLocX[11]  = ALGO_CAND11_1_LOC_X;
        candLocY[11]  = ALGO_CAND11_1_LOC_Y;
        candLocX[12]  = ALGO_CAND12_1_LOC_X;
        candLocY[12]  = ALGO_CAND12_1_LOC_Y;
        candLocX[13]  = ALGO_CAND13_1_LOC_X;
        candLocY[13]  = ALGO_CAND13_1_LOC_Y;
        candLocX[14]  = ALGO_CAND14_1_LOC_X;
        candLocY[14]  = ALGO_CAND14_1_LOC_Y;
        candLocX[15]  = ALGO_CAND15_1_LOC_X;
        candLocY[15]  = ALGO_CAND15_1_LOC_Y;
    } else if (m_CandConstellation==2) {
        candLocX[8 ]  = ALGO_CAND08_2_LOC_X;
        candLocY[8 ]  = ALGO_CAND08_2_LOC_Y;
        candLocX[9 ]  = ALGO_CAND09_2_LOC_X;
        candLocY[9 ]  = ALGO_CAND09_2_LOC_Y;
        candLocX[10]  = ALGO_CAND10_2_LOC_X;
        candLocY[10]  = ALGO_CAND10_2_LOC_Y;
        candLocX[11]  = ALGO_CAND11_2_LOC_X;
        candLocY[11]  = ALGO_CAND11_2_LOC_Y;
        candLocX[12]  = ALGO_CAND12_2_LOC_X;
        candLocY[12]  = ALGO_CAND12_2_LOC_Y;
        candLocX[13]  = ALGO_CAND13_2_LOC_X;
        candLocY[13]  = ALGO_CAND13_2_LOC_Y;
        candLocX[14]  = ALGO_CAND14_2_LOC_X;
        candLocY[14]  = ALGO_CAND14_2_LOC_Y;
        candLocX[15]  = ALGO_CAND15_2_LOC_X;
        candLocY[15]  = ALGO_CAND15_2_LOC_Y;
    } else {
        ErrMsg("ALGO:\\Internal error!! Unsupported Constellation!");
    }


    // Compute SADs for inner candidates

    int fast_SAD_index_i = 0;
    bool exit_loop_sad_max = false;
    int candLocY_index_i ;
    int candLocX_index_i ;
    int * nbr_SAD_RES_index_ALGO_PATCH_LOC_Y_plus_k_offset_ALGO_PATCH_LOC_X;
    int * nbr_SAD_RES_candLocY_index_iplus_k_offset_candLocX_index_i;       
    int patch_pixel_value   ;                                               
    int cand_pixel_value    ;
    int i,j,k;
    int temp1 = ((1<<(ALGO_SAD_RES-1)) - 1));

    for (i = 0; i < ALGO_NUM_CANDIDATE; ++i)
    {
        fast_SAD_index_i = 0;
        exit_loop_sad_max = false;
        //SAD[i] = 0;
        if (m_CandEnable[i]) 
        {
            candLocY_index_i = candLocY[i];
            candLocX_index_i = candLocX[i];
            for (k = 0; !exit_loop_sad_max && ( k < ALGO_PATCH_SZ); ++k)
            {
                nbr_SAD_RES_index_ALGO_PATCH_LOC_Y_plus_k_offset_ALGO_PATCH_LOC_X   = nbr_SAD_RES[ALGO_PATCH_LOC_Y+k ]+ALGO_PATCH_LOC_X;
                nbr_SAD_RES_candLocY_index_iplus_k_offset_candLocX_index_i          = nbr_SAD_RES[candLocY_index_i+k]+candLocX_index_i;


                patch_pixel_value                                                   =*nbr_SAD_RES_index_ALGO_PATCH_LOC_Y_plus_k_offset_ALGO_PATCH_LOC_X;
                cand_pixel_value                                                    = *nbr_SAD_RES_candLocY_index_iplus_k_offset_candLocX_index_i;

                for (j=0; !exit_loop_sad_max && (j<ALGO_PATCH_SZ); ++j)     
                {


                    if(patch_pixel_value<cand_pixel_value)
                    {
                        fast_SAD_index_i -= patch_pixel_value-cand_pixel_value; 
                    }
                    else
                    {
                        fast_SAD_index_i += patch_pixel_value-cand_pixel_value; 
                    }
                    if (fast_SAD_index_i >= temp1)
                    {
                        fast_SAD_index_i = temp1;
                        exit_loop_sad_max = true;
                    }
                    else
                    {
                        patch_pixel_value =*(++nbr_SAD_RES_index_ALGO_PATCH_LOC_Y_plus_k_offset_ALGO_PATCH_LOC_X); // worst line
                        cand_pixel_value = *(++nbr_SAD_RES_candLocY_index_iplus_k_offset_candLocX_index_i);
                    }
                }
            }
        }
        SAD[i] = fast_SAD_index_i;
    }// End for i
}
\$\endgroup\$
  • \$\begingroup\$ Did the change to int temp1 ... make a difference? \$\endgroup\$ – rolfl Mar 15 '14 at 16:11
  • \$\begingroup\$ yes i'm not computing it over and over again \$\endgroup\$ – Gilad Mar 15 '14 at 16:11
  • \$\begingroup\$ Isn't ALGO_SAD_RES a constant? Where is it defined? \$\endgroup\$ – rolfl Mar 15 '14 at 16:12
  • \$\begingroup\$ still i have some hard performance issues. in this line patch_pixel_value =*(++nbr_SAD_RES_index_BNLM_PATCH_LOC_Y_plus_k_offset_BNLM_PATCH_LOC_X); i'm spending a lot of time i don't know why \$\endgroup\$ – Gilad Mar 15 '14 at 16:13
  • \$\begingroup\$ Meh, you have edited your question and moved the 'worst-lines' \$\endgroup\$ – rolfl Mar 15 '14 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.