spcl/hls_tutorial_examples

Matrix_multiplication not co_simulatable

Malarius1999 opened this issue · 7 comments

While synthesising example 05/06 I've encountered the problem that the Interface wasn't correctly generated for
void MatrixMultiplication(const double A[], const double B[], double C[])

I had to explicitly add the sizes for the arrays
void MatrixMultiplication(double const A[N * K], double const B[K * M], double C[N * M])

to get the right results in the Co-Simulation. I'm still a newbie so i'm not quite sure if this is a bug.

Could you share your Vitis version and the exact issue you're seeing? 🙂

Vitis Version 2022.2

Well, the mistake is probably on me, because i've changed a few things for the co-simulation. In the headerfile Example5.h there is a function-declaration:
void Entry(double const A[], double const B[], double C[]);

but this function is nowhere to be found. Therefore I assumed that
void Example5_Reordered(double const A[], double const B[], double C[]);

is the correct entry function, which i've chosen as top-function. But to be co-simulated i need to call the top-function in the testbench. But in Test.cpp there was the call of the subfunction

// Run simulation
MatrixMultiplication(a.data(), b.data(), c.data());

So for the co-simulation i've replaced that call with

// Run simulation
Example5_Reordered(a.data(), b.data(), c.data());

Additionally i got a funny error message:
INFO: [COSIM 212-47] Using XSIM for RTL simulation.
INFO: [COSIM 212-14] Instrumenting C test bench ...
Build using "C:/Xilinx/Vitis_HLS/2022.2/tps/win64/msys64/mingw64/bin/g++"
Compiling Example5_Reordered.cpp_pre.cpp.tb.cpp
Compiling Test.cpp_pre.cpp.tb.cpp
Compiling Example5.cpp_pre.cpp.tb.cpp
Compiling apatb_Example5_Reordered.cpp
Compiling Entry.cpp_pre.cpp.tb.cpp
Compiling apatb_Example5_Reordered_ir.ll
Generating cosim.tv.exe
INFO: [COSIM 212-302] Starting C TB testing ...
ERROR: [COSIM 212-360] Aborting co-simulation: C TB simulation failed.
ERROR: [COSIM 212-320] C TB testing failed, stop generating test vectors. Please check C TB or re-run cosim.
ERROR: [COSIM 212-5] *** C/RTL co-simulation file generation failed. ***
ERROR: [COSIM 212-4] *** C/RTL co-simulation finished: FAIL ***
INFO: [HLS 200-111] Finished Command cosim_design CPU user time: 0 seconds. CPU system time: 1 seconds. Elapsed time: 4.13 seconds; current allocated memory: 8.152 MB.
command 'ap_source' returned error code
while executing
"source D:/Projekte/Vitis_HLS/ETH_hls_tutorial_examples/example_5_old/xilinx/build/prj/solution1/cosim.tcl"
invoked from within
"hls::main D:/Projekte/Vitis_HLS/ETH_hls_tutorial_examples/example_5_old/xilinx/build/prj/solution1/cosim.tcl"
("uplevel" body line 1)
invoked from within
"uplevel 1 hls::main {*}$newargs"
(procedure "hls_proc" line 16)
invoked from within
"hls_proc [info nameofexecutable] $argv"

That obviously meant that i had to lower the Matrix sizes (N,M,K) to 8 each (for some magic reason)

Now i get the error message:
INFO: [COSIM 212-302] Starting C TB testing ...
Mismatch at (0, 0): 0.0417684 (should be 1.65434).
ERROR: [COSIM 212-359] Aborting co-simulation: C TB simulation failed, nonzero return value '1'.
ERROR: [COSIM 212-320] C TB testing failed, stop generating test vectors. Please check C TB or re-run cosim.
ERROR: [COSIM 212-5] *** C/RTL co-simulation file generation failed. ***
ERROR: [COSIM 212-4] *** C/RTL co-simulation finished: FAIL ***

The only way i found to fix the last error message is to replace the code as seen in my first post...

I've also just saw that this allows me again to co-simulate Matrices of size 32

Ah, sorry, I missed that you are trying to do co-simulation. Co-simulation has traditionally not worked with hlslib that the examples use underneath, so this is generally not supported/expected to work 🙂

Ok thanks. Great tutorial btw.

But does the synthisised IP Block work? Especially if I don't use an axi interface.

grafik

I wouldn't know how to insert all matrix elements before starting the application.

Ok thanks. Great tutorial btw.

I'm happy that it's useful to you!

But does the synthisised IP Block work? Especially if I don't use an axi interface.
I wouldn't know how to insert all matrix elements before starting the application.

This matrix multiplication example is not a self-contained kernel that you can run on a real device etc., but we have a full high-performance GEMM implementations here: https://github.com/spcl/gemm_hls

Unfortunately it seems to have issues with newer versions of Vitis, but you can give it a try!

Cool, I just saw how many optimized examples you have. This will be of great help to understand HLS better :)