Hot!How to use properly the DSP library functions?

Author
thoraz
Starting Member
  • Total Posts : 69
  • Reward points : 0
  • Joined: 2013/06/01 18:37:43
  • Location: 0
  • Status: offline
2017/10/03 17:08:24 (permalink)
0

How to use properly the DSP library functions?

I'm working with the matricial operation and I want to use for my first time the dsplib_dsp.h library. I'm in the Harmony framework. From the XC32 I found the mips_vec_dotp32 function:
int32
mips_vec_dotp32
(
    int32 *indata1,
    int32 *indata2,
    int N,
    int scale
);

where indata1 and indata2 are in Q31 format. I haven't confidence with this format and I don't understand how to use the function. My original basic code for a dot product between vectors is the following 

uint32_t i, N = 100;
double vectorA[100], vectorB[100];
double mul = 0;
 
//...Fill the vectors with double values...
 
for ( i = 0; i < N; i++ )
    mul +=vectorA[i] * vectorB[i];

and for the matrix product

uint32_t i, j, k, N = 100;
double matrixA[100][100], matrixB[100][100], result[100][100];
 
//...Fill the matrix with double values...
 
for(i=0; i<N; ++i)
    for(j=0; j<N; ++j)
        for(k=0; k<N; ++k)
        {
            result[i][j]+=a[i][k]*b[k][j];
         }

Now, how can I the mips_vec_dotp32 function in this code to improve the performance (if there will be an improvement)? Can anyone show me a little example?
#1

5 Replies Related Threads

    Paul Bjork
    Super Member
    • Total Posts : 201
    • Reward points : 0
    • Joined: 2011/09/21 14:08:10
    • Location: 0
    • Status: offline
    Re: How to use properly the DSP library functions? 2017/10/04 08:28:33 (permalink)
    0
    Unfortunately, I believe that this mips function is for the mips fixed point multiplier hardware, not floating point (double) like it appears that your original code was.  So it won't help you at all.  
     
    Are you using a controller with an FPU?  There are other libraries out there that will help you with a vector multiply on an FPU.
    #2
    thoraz
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2013/06/01 18:37:43
    • Location: 0
    • Status: offline
    Re: How to use properly the DSP library functions? 2017/10/04 17:02:40 (permalink)
    +1 (1)
    I have seen that all the mips function accept inputs in Q format so I have supposed that there was some kind of conversion from "normal" data like float/double in the fixed point format Q.
    Anyway, I'm using an PIC32MZ0512EFE64 which implements an FPU. You can tell me that there are other libraryes that will help me? Can you link me these?
     
     
    #3
    LostInSpace
    Senior Member
    • Total Posts : 102
    • Reward points : 0
    • Joined: 2016/03/11 22:47:59
    • Location: 0
    • Status: offline
    Re: How to use properly the DSP library functions? 2017/10/07 19:47:54 (permalink)
    +2 (2)
    All the Microchip supplied DSP functions contain sample calling code in the help files. I have found these very useful in figuring out how exactly to call the functions.
     
    Because of speed and size almost all DSP code for microprocessors is written in fixed point format. The format most common in the DSP libraries is Q15 and Q31 (for 16 and 32 bit number widths respectively).
     
    Q format is just a way of thinking about how to change a signed int into a fixed point representation. As another poster has suggested it is just a mental exercise.
     
    When I learned about Q formats I just did a search for "Q number format" and "fixed point format" numbering systems and I found many tutorials.
     
    If you really want to use floating point, then you will have to write your own functions - again there are many tutorials on the web on how to calculate everything.
     
    HTH
     
    post edited by LostInSpace - 2017/10/07 19:51:15
    #4
    simong123
    Lab Member No. 003
    • Total Posts : 1114
    • Reward points : 0
    • Joined: 2012/02/07 18:21:03
    • Location: Future Gadget Lab (UK Branch)
    • Status: offline
    Re: How to use properly the DSP library functions? 2017/10/07 20:31:44 (permalink)
    +2 (2)
    On an 'EF there is little benefit to using the dsp functions for floats. The FPU has a throughput of 1 single precision FMA/clock. You'd spend more time converting to/from Q31. At optimisation level -O1 or greater the compiler should produce reasonably decent code.
    You could search for my previous posts on the EF FPU, I think I posted a hand optimised dot product assembly code (maybe only for 1-dimensional vectors, I cannot remember, but you should get the general idea).
     
    Edit:-
    Found the library I wrote. Does vector dot product and n x n matrix multiply.
    post edited by simong123 - 2017/10/07 20:33:52

    Attachment(s)

    Attachments are not available: Download requirements not met
    #5
    thoraz
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2013/06/01 18:37:43
    • Location: 0
    • Status: offline
    Re: How to use properly the DSP library functions? 2017/10/08 10:04:13 (permalink)
    0
    simong123
    On an 'EF there is little benefit to using the dsp functions for floats. The FPU has a throughput of 1 single precision FMA/clock. You'd spend more time converting to/from Q31. At optimisation level -O1 or greater the compiler should produce reasonably decent code.
    You could search for my previous posts on the EF FPU, I think I posted a hand optimised dot product assembly code (maybe only for 1-dimensional vectors, I cannot remember, but you should get the general idea).
     
    Edit:-
    Found the library I wrote. Does vector dot product and n x n matrix multiply.



    Great! I am very grateful to you. Thanks!
    #6
    Jump to:
    © 2017 APG vNext Commercial Version 4.5