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.

CCS/C6000-CGT: Bug of DSPF_sp_svd_cmplx() function

Part Number: C6000-CGT
Other Parts Discussed in Thread: TMS320C6678

Tool/software: Code Composer Studio

Dear sir,

When I use the DSPF_sp_svd_cmplx() function provided in DSPLIB, I find a problem that some value of the resulted eigenvalue is nan. 

Called sample: status = DSPF_sp_svd_cmplx(Nrows,Ncols,RAA,U,V,U1,diag,superdiag), the input and output result are as follows: 

Nrows = Ncols = 4

RAA =
0.886855 + (0.000000)i 0.251336 + (-0.792338)i 0.100687 + (-0.392239)i 0.849384 + (-0.318991)i
0.251336 + (0.792338)i 1.254295 + (0.000000)i 0.715988 + (0.433667)i 0.490456 + (0.871547)i
0.100687 + (0.392239)i 0.715988 + (-0.433667)i 0.861023 + (0.000000)i 0.407068 + (0.517872)i
0.849384 + (0.318991)i 0.490456 + (-0.871547)i 0.407068 + (-0.517872)i 1.018099 + (0.000000)i

U =
-0.454249 + (-0.000000)i 0.542353 + (-0.000000)i nan + (nan)i nan + (nan)i
-0.099857 + (-0.578181)i 0.279047 + (-0.259791)i nan + (nan)i nan + (nan)i
-0.196158 + (-0.351059)i -0.563637 + (-0.408845)i nan + (nan)i nan + (nan)i
-0.511001 + (-0.162943)i 0.191617 + (0.197324)i nan + (nan)i nan + (nan)i

diag =
3.367160 + (-0.000000)i 0.652464 + (0.000000)i nan + (nan)i nan + (nan)i

V =
-0.454249 + (0.000000)i 0.542353 + (-0.000000)i nan + (nan)i nan + (nan)i
-0.099857 + (-0.578181)i 0.279046 + (-0.259791)i nan + (nan)i nan + (nan)i
-0.196158 + (-0.351059)i -0.563637 + (-0.408845)i nan + (nan)i nan + (nan)i
-0.511001 + (-0.162943)i 0.191617 + (0.197324)i nan + (nan)i nan + (nan)i

As shown in the above, you will find some nan value but the result is OK when calling svd() function in MATLAB.

So could you help me for solving this problem? Thank you very much.

[Note]: tools I used list as follows:

IDE:  CCS 9.0.1.00004

DSP: TMS320C6678

DSPLIB: dsplib_c66x_3_4_0_0_Win32

  • Kee Wong,

    There is no direct relationship between the svd() in MATLAB and DSPF_sp_svd_cmplx() in DSPLIB other than the two functions implement the same algorithm. The DSPLIB implementation is designed for the DSP architecture while the MATLAB function execute on X86 platform.

    If you check the documentation for the function in the DSPLIB, it clearly documents the assumptions made to optimize the performance of the function on the DSP. Can you try to use the natural C implementation of the function and indicate if you see the same issue

    Our compiler team has indicated what floating point operations resulting in NAN result:
    processors.wiki.ti.com/.../Floating_Point_Optimization

    Can you check if you are running into any of these conditions.

    Regards,
    Rahul
  • Dear Rahul,

    Thank your for your timely reply.

    Before I use the DSPF_sp_svd_cmplx() function, I have paid more attention to the parameter definition and assumptions. I have tried some test cases and found that the NAN value appears in the first case as mentioned in the question.

    I will do some further testing according to your precious suggest.

    Best regards!

  • Dear Rahul ,

    Recently, I have done some test to verify the problem of DSPF_sp_svd_cmplx() function in DSPLIB. I have found a interesting phenomenon. As to the call sample, status = DSPF_sp_svd_cmplx(Nrows,Ncols,RAA,U,V,U1,diag,superdiag). When RAA is calculated as the result shows as follows:

    RAA =
    0.886855 + (0.000000)i 0.251336 + (-0.792338)i 0.100687 + (-0.392239)i 0.849384 + (-0.318991)i
    0.251336 + (0.792338)i 1.254295 + (0.000000)i 0.715988 + (0.433667)i 0.490456 + (0.871547)i
    0.100687 + (0.392239)i 0.715988 + (-0.433667)i 0.861023 + (0.000000)i 0.407068 + (0.517872)i
    0.849384 + (0.318991)i 0.490456 + (-0.871547)i 0.407068 + (-0.517872)i 1.018099 + (0.000000)i

    The DSPF_sp_svd_cmplx() function returns the status (3) and some NAN value are in the result of  diag, U, V as follows:

    U =
    -0.454249 + (-0.000000)i 0.542353 + (-0.000000)i nan + (nan)i nan + (nan)i
    -0.099857 + (-0.578181)i 0.279047 + (-0.259791)i nan + (nan)i nan + (nan)i
    -0.196158 + (-0.351059)i -0.563637 + (-0.408845)i nan + (nan)i nan + (nan)i
    -0.511001 + (-0.162943)i 0.191617 + (0.197324)i nan + (nan)i nan + (nan)i

    diag =
    3.367160 + (-0.000000)i 0.652464 + (0.000000)i nan + (nan)i nan + (nan)i

    V =
    -0.454249 + (0.000000)i 0.542353 + (-0.000000)i nan + (nan)i nan + (nan)i
    -0.099857 + (-0.578181)i 0.279046 + (-0.259791)i nan + (nan)i nan + (nan)i
    -0.196158 + (-0.351059)i -0.563637 + (-0.408845)i nan + (nan)i nan + (nan)i
    -0.511001 + (-0.162943)i 0.191617 + (0.197324)i nan + (nan)i nan + (nan)i

    But, when I manually set RAA to the same value as the calculated value, the result of the U, S and V is valid as follows:

    U =
    -0.454249 + (-0.000000)i 0.542354 + (0.000000)i -0.465265 + (0.000096)i 0.532014 + (0.000019)i
    -0.099857 + (-0.578181)i 0.279047 + (-0.259792)i 0.617994 + (0.312055)i 0.170670 + (0.044194)i
    -0.196158 + (-0.351059)i -0.563637 + (-0.408844)i -0.431384 + (0.241919)i 0.029790 + (0.328535)i
    -0.511001 + (-0.162943)i 0.191617 + (0.197323)i -0.127295 + (0.208357)i -0.743005 + (-0.158118)i

    diag =
    3.367159 + (-0.000000)i 0.652464 + (-0.000000)i 0.000534 + (0.000000)i 0.000115 + (0.000000)i

    V =
    -0.454249 + (-0.000000)i 0.542353 + (0.000000)i -0.465219 + (0.000000)i 0.532055 + (-0.000000)i
    -0.099857 + (-0.578181)i 0.279046 + (-0.259792)i 0.617973 + (0.312125)i 0.170642 + (0.044107)i
    -0.196158 + (-0.351059)i -0.563637 + (-0.408844)i -0.431389 + (0.241891)i 0.029876 + (0.328541)i
    -0.511001 + (-0.162943)i 0.191618 + (0.197323)i -0.127397 + (0.208379)i -0.742994 + (-0.158055)i

    So why does it happen and what should I do to solve this problem? 

    Look forward to your reply.

    Regards,

    Kee Wong

  • Kee Wong,

    I don`t think that I understand the work around or the second scenario that you are describing here. what do you mean by following:

    Kee Wong said:
    But, when I manually set RAA to the same value as the calculated value, the result of the U, S and V is valid as follows:

    Please clarify the above statement. Also, indicate on the DSP where are the RAA, U, V and diag buffers are defined in memory. Is there a cache operation or some initialization that is missing in your setup. 

    Regards,

    Rahul

  • // DSP and CCS here used
    DSP : TMS320C6678
    CCS : V9.0.1.00004
    DSPLIB : 3.4

    // Macro definition
    #define MAX_NROWS 64 /* max is 168 for L2SRAM */
    #define MAX_NCOLS 64 /* max is 168 for L2SRAM */
    #define MAX_SIZE (MAX_NROWS*2*MAX_NCOLS)
    #define MAX_U_SIZE (MAX_NROWS*2*MAX_NROWS)
    #define MAX_V_SIZE (MAX_NCOLS*2*MAX_NCOLS)

    // Buffer definition
    #pragma DATA_ALIGN(RAA,8);
    float RAA[MAX_SIZE];

    #pragma DATA_ALIGN(U,8);
    float U[MAX_U_SIZE];

    #pragma DATA_ALIGN(V,8);
    float V[MAX_V_SIZE];

    #pragma DATA_ALIGN(U1,8);
    float U1[MAX_U_SIZE];

    #pragma DATA_ALIGN(diag,8);
    float diag[2*MAX_NROWS];

    #pragma DATA_ALIGN(superdiag,8);
    float superdiag[2*MAX_NROWS];


    /***************************************************************
    [The first condition which gets the NAN value]
    ***************************************************************/
    // Step1:func1 is for calculating the result of RAA
    // Input: input parameter
    // RAA :output result
    func1(In, RAA);

    // Now when debugged, the result of RAA watched from the memory and printed is as follows:
    0.886855 + (0.000000)i 0.251336 + (-0.792338)i 0.100687 + (-0.392239)i 0.849384 + (-0.318991)i
    0.251336 + (0.792338)i 1.254295 + (0.000000)i 0.715988 + (0.433667)i 0.490456 + (0.871547)i
    0.100687 + (0.392239)i 0.715988 + (-0.433667)i 0.861023 + (0.000000)i 0.407068 + (0.517872)i
    0.849384 + (0.318991)i 0.490456 + (-0.871547)i 0.407068 + (-0.517872)i 1.018099 + (0.000000)i

    // Step2:Then Call SVD() function
    Nrows=4;
    Ncols=4;
    status = DSPF_sp_svd_cmplx(Nrows,Ncols,RAA,U,V,U1,diag,superdiag);

    // Now UNFORTUNATELY, some NAN value are in U, V and diag as follows:
    U =
    -0.454249 + (-0.000000)i 0.542353 + (-0.000000)i nan + (nan)i nan + (nan)i
    -0.099857 + (-0.578181)i 0.279047 + (-0.259791)i nan + (nan)i nan + (nan)i
    -0.196158 + (-0.351059)i -0.563637 + (-0.408845)i nan + (nan)i nan + (nan)i
    -0.511001 + (-0.162943)i 0.191617 + (0.197324)i nan + (nan)i nan + (nan)i

    diag =
    3.367160 + (-0.000000)i 0.652464 + (0.000000)i nan + (nan)i nan + (nan)i

    V =
    -0.454249 + (0.000000)i 0.542353 + (-0.000000)i nan + (nan)i nan + (nan)i
    -0.099857 + (-0.578181)i 0.279046 + (-0.259791)i nan + (nan)i nan + (nan)i
    -0.196158 + (-0.351059)i -0.563637 + (-0.408845)i nan + (nan)i nan + (nan)i
    -0.511001 + (-0.162943)i 0.191617 + (0.197324)i nan + (nan)i nan + (nan)i

    /***************************************************************
    [The second condition which gains the correct value]
    ***************************************************************/
    // Step1:Just fetch the result of func1 and manually assign it to RAA
    Nrows=4;Ncols=4;

    RAA[ 0]= 0.886855; RAA[ 1]= 0; RAA[ 2]= 0.251336; RAA[ 3]= -0.792338; RAA[ 4]= 0.100687; RAA[ 5]= -0.392239; RAA[ 6]= 0.849384; RAA[ 7]= -0.318991;
    RAA[ 8]= 0.251336; RAA[ 9]= 0.792338; RAA[10]= 1.254295; RAA[11]=0; RAA[12]= 0.715988; RAA[13]=0.433667; RAA[14]= 0.490456; RAA[15]= 0.871547;
    RAA[16]= 0.100687; RAA[17]= 0.392239; RAA[18]= 0.715988; RAA[19]=-0.433667; RAA[20]= 0.861023; RAA[21]=0; RAA[22]= 0.407068; RAA[23]=0.517872;
    RAA[24]= 0.849384; RAA[25]= 0.318991; RAA[26]= 0.490456; RAA[27]=-0.871547; RAA[28]= 0.407068; RAA[29]=-0.517872; RAA[30]= 1.018099; RAA[31]=0;

    // Step2:Then Call SVD() function
    status = DSPF_sp_svd_cmplx(Nrows,Ncols,RAA,U,V,U1,diag,superdiag);

    // Now SUCCESSFULLY, correct value are in U, V and diag as follows:
    U =
    -0.454249 + (-0.000000)i 0.542354 + (0.000000)i -0.465265 + (0.000096)i 0.532014 + (0.000019)i
    -0.099857 + (-0.578181)i 0.279047 + (-0.259792)i 0.617994 + (0.312055)i 0.170670 + (0.044194)i
    -0.196158 + (-0.351059)i -0.563637 + (-0.408844)i -0.431384 + (0.241919)i 0.029790 + (0.328535)i
    -0.511001 + (-0.162943)i 0.191617 + (0.197323)i -0.127295 + (0.208357)i -0.743005 + (-0.158118)i

    diag =
    3.367159 + (-0.000000)i 0.652464 + (-0.000000)i 0.000534 + (0.000000)i 0.000115 + (0.000000)i

    V =
    -0.454249 + (-0.000000)i 0.542353 + (0.000000)i -0.465219 + (0.000000)i 0.532055 + (-0.000000)i
    -0.099857 + (-0.578181)i 0.279046 + (-0.259792)i 0.617973 + (0.312125)i 0.170642 + (0.044107)i
    -0.196158 + (-0.351059)i -0.563637 + (-0.408844)i -0.431389 + (0.241891)i 0.029876 + (0.328541)i
    -0.511001 + (-0.162943)i 0.191618 + (0.197323)i -0.127397 + (0.208379)i -0.742994 + (-0.158055)i


    Comparing the result between the first and second condition, we could find the obvious difference. I want to know why this happens and how to solve this problem? Please help me and I will appreciate your support and help.

    Best regards,

    Kee Wong.