[Roccc-discussion] compilation problems with C-code
Jason Villarreal
jason at jacquardcomputing.com
Wed Feb 3 12:12:27 PST 2010
> Hi!
>
> I'm student at Karlsruhe Institute for Technology (KIT, Germany) writing
> my diploma thesis under supervision of Prof. Dr. Heuveline. My subject
> is about testing C-to-VHDL-compilers for numerical computations.
>
> I'm pretty new to the subject of FPGAs so I'm not sure what's going
> wrong with my code as I don't think that I'm violating any of the
> constraints given in the UsersManual.
>
> Hope this is the right place to ask :-)
>
> I'm trying to implement a Matrix-Vector multiplication but compilation
> (using the scripts, not the GUI) fails in the second phase
> (compile_llvmtovhdl.sh).
>
> Any ideas what I'm doing wrong in this code?
>
> -------------------------------------------------------------------------------------
>
> /* System Code to multiply a matrix with a vector
> depends on MultVec (-> Sum, Mult) */
>
> #include "roccc-library.h"
>
> void MatVecMult() {
>
> int i, j, solution, interResult;
> int zero = 0;
>
> int matA[20][20];
> int vecB[20];
> int vecC[20]; // matA * vecB = vecC
>
> for (i=0; i<20; ++i) { //for each row
>
> solution = zero;
>
> for (j=0; j<20; ++j) {
>
> //multiply matA*vecB
>
> // MULT(in 32, in 32, out 32); module implementing a
> simple multiplication
> MULT(matA[i][j], vecB[j], interResult);
>
> // SUM(in 32, in 32, out 32); module implementing a
> simple multiplication
> SUM(interResult, solution, solution);
> }
>
> vecC[i] = solution;
>
> }
> }
> ------------------------------------------------------------------------------
> I'd be glad for any help!
Thank you very much for this example as it shows a lot of issues that we are working to correct. First, ROCCC system code currently only supports perfectly nested loops. This means that there can be no statements between the for statements, such as "solution = zero ;" and "vecC[i] = solution ;" in your example.
To get around this, you will need to unroll the innermost loop fully. However this example also exposes two more issues that we are working on solving. Namely, unrolling a loop with module calls currently does not work correctly and mixing two-dimensional and one-dimensional arrays does not currently work correctly.
Also, we very recently discovered some issues with feedback variables (such as "solution" in your code).
All of these issues (other than supporting non-perfectly nested loops) should be handled in the next bugfix release, which we estimate to happen sometime in the next couple of weeks.
In the meantime, the following code will perform the same task and does go through ROCCC. The solution requires the matrix A to be streamed in in chunks of 20 in a one dimensional fashion as well as the vector B.
for (i = 0 ; i < 20 ; i +=20)
{
MULT(matA[i], vecB[i], interResult0) ;
SUM(interResult0, 0, solution0) ;
MULT(matA[i+1], vecB[i+1], interResult1) ;
SUM(interResult1, solution0, solution1) ;
// ...
MULT(matA[i+19], vecB[i+19], interResult19) ;
SUM(interResult19, solution18, finalSolution) ;
vecC[i] = finalSolution ;
}
Also, we will no longer be supporting the scripts for compilation in the future and will only be supporting compilation through the GUI. New optimizations and current optimizations such as loop unrolling will only be available through the GUI and not the scripts.
Thanks,
Jason
More information about the Roccc-discussion
mailing list