10-15-2020 12:33 AM
Hi,
i do a simple HLS module and a test bench for it. It is very simple but the test result seems wrong. It is my first time using the HLS and I have no knowledge of C/C++ language. So can anyone help to see what is the problem?
///detect_top.cpp file ///////
////test bench file ////
///detect_h.h file///
///C simulation result ////
INFO: [SIM 2] *************** CSIM start ***************
INFO: [SIM 4] CSIM will launch GCC as the compiler.
Compiling ../../../detect_tb.cpp in debug mode
Compiling ../../../detect_top.cpp in debug mode
Generating csim.exe
hello my test
ERROR HW and SW results mismatch
mag_sf = 25
flag_sf = 1
flag_out = 0
hd_mag = 7404576
INFO: [SIM 1] CSim done with 0 errors.
INFO: [SIM 3] *************** CSIM finish ***************
11-03-2020 08:20 PM
Hi @sungh ,
The '>>' operator is overloaded to allow use similar to the stream extraction operator for C++ stream (for example, iostreams and filestreams). The hls::stream is supplied as the LHS argument and the destination variable the RHS.
// Usage of void operator >> (T & rdata) hls::stream<int> my_stream; int dst_var; my_stream >> dst_var;
But we cannot assign the value ap_uint using the '>>' operator. Please use the '=' operator instead.
istream_in << 0x3; qstream_in << 0x4;
#include "header.h"
void detect_top(
stream<uint16_md> &adcIStream, // [in]
stream<uint16_md> &adcQStream, // [in]
stream<uint16_md> &MagStream, // [out]
short detect_threshold, // [in]
bool *pass_flag // [out]
)
{
#pragma HLS INTERFACE s_axilite port=detect_threshold
#pragma HLS INTERFACE s_axilite port=pass_flag
#pragma HLS INTERFACE axis reverse port=adcIStream
#pragma HLS INTERFACE axis reverse port=adcQStream
#pragma HLS INTERFACE axis forward port=MagStream
uint16_md inI = 0;
uint16_md inQ = 0;
uint16_md outMag = 0;
// read inputs data
adcIStream >> inI;
adcQStream >> inQ;
outMag = inI*inI + inQ*inQ;
#ifndef __SYNTHESIS__
std::cout<<"kernel outMag\t"<<std::dec<< outMag<<std::endl;
#endif
if(outMag > detect_threshold)
*pass_flag = 1;
else
*pass_flag = 0;
MagStream << outMag;
}
#include "header.h"
void detect_top(
stream<uint16_md> &adcIStream, // [in]
stream<uint16_md> &adcQStream, // [in]
stream<uint16_md> &MagStream, // [out]
short detect_threshold, // [in]
bool *pass_flag // [out]
);
int main()
{
stream<uint16_md> istream;
stream<uint16_md> qstream;
stream<uint16_md> ostream;
uint16_md istream_in;
uint16_md qstream_in;
uint16_md ostream_out;
uint16_md hd_mag;
unsigned int Ai;
unsigned int Aq;
short B_threshold;
unsigned int mag_out;
bool flag_out;
unsigned int mag_sf;
bool flag_sf;
//put data into hardware function
istream_in = 0x3;
qstream_in = 0x4;
istream << istream_in;
qstream << qstream_in;
printf("hello my test\n");
//Put data into A
Ai = 3;
Aq = 4;
B_threshold = 10;
//Call the hardware function
detect_top(istream,qstream,ostream,B_threshold, &flag_out);
ostream >> hd_mag;
std::cout<<"hd_mag\t"<<std::hex<< hd_mag.range(15,0)<<std::endl;
//Run a software version of the hardware function to validate results
mag_sf = Ai*Ai + Aq*Aq;
if(mag_sf > B_threshold)
flag_sf = true;
else
flag_sf = false;
//Compare results
if(flag_sf != flag_out)
printf("ERROR HW and SW results mismatch\n");
else
printf("Success HW and SW results match\n");
printf("mag_sf = %d\n", mag_sf);
printf("flag_sf = %d\n", flag_sf);
printf("flag_out = %d\n", flag_out);
std::cout<<"hd_mag\t"<<std::dec<< hd_mag.range(15,0)<<std::endl;
return 0;
}
INFO: [SIM 2] *************** CSIM start *************** INFO: [SIM 4] CSIM will launch GCC as the compiler. Compiling ../../../test.cpp in debug mode Generating csim.exe hello my test kernel outMag 25 hd_mag 0x19 Success HW and SW results match mag_sf = 25 flag_sf = 1 flag_out = 1 hd_mag 25 INFO: [SIM 1] CSim done with 0 errors. INFO: [SIM 3] *************** CSIM finish ***************
Thanks,
Wen
11-03-2020 08:20 PM
Hi @sungh ,
The '>>' operator is overloaded to allow use similar to the stream extraction operator for C++ stream (for example, iostreams and filestreams). The hls::stream is supplied as the LHS argument and the destination variable the RHS.
// Usage of void operator >> (T & rdata) hls::stream<int> my_stream; int dst_var; my_stream >> dst_var;
But we cannot assign the value ap_uint using the '>>' operator. Please use the '=' operator instead.
istream_in << 0x3; qstream_in << 0x4;
#include "header.h"
void detect_top(
stream<uint16_md> &adcIStream, // [in]
stream<uint16_md> &adcQStream, // [in]
stream<uint16_md> &MagStream, // [out]
short detect_threshold, // [in]
bool *pass_flag // [out]
)
{
#pragma HLS INTERFACE s_axilite port=detect_threshold
#pragma HLS INTERFACE s_axilite port=pass_flag
#pragma HLS INTERFACE axis reverse port=adcIStream
#pragma HLS INTERFACE axis reverse port=adcQStream
#pragma HLS INTERFACE axis forward port=MagStream
uint16_md inI = 0;
uint16_md inQ = 0;
uint16_md outMag = 0;
// read inputs data
adcIStream >> inI;
adcQStream >> inQ;
outMag = inI*inI + inQ*inQ;
#ifndef __SYNTHESIS__
std::cout<<"kernel outMag\t"<<std::dec<< outMag<<std::endl;
#endif
if(outMag > detect_threshold)
*pass_flag = 1;
else
*pass_flag = 0;
MagStream << outMag;
}
#include "header.h"
void detect_top(
stream<uint16_md> &adcIStream, // [in]
stream<uint16_md> &adcQStream, // [in]
stream<uint16_md> &MagStream, // [out]
short detect_threshold, // [in]
bool *pass_flag // [out]
);
int main()
{
stream<uint16_md> istream;
stream<uint16_md> qstream;
stream<uint16_md> ostream;
uint16_md istream_in;
uint16_md qstream_in;
uint16_md ostream_out;
uint16_md hd_mag;
unsigned int Ai;
unsigned int Aq;
short B_threshold;
unsigned int mag_out;
bool flag_out;
unsigned int mag_sf;
bool flag_sf;
//put data into hardware function
istream_in = 0x3;
qstream_in = 0x4;
istream << istream_in;
qstream << qstream_in;
printf("hello my test\n");
//Put data into A
Ai = 3;
Aq = 4;
B_threshold = 10;
//Call the hardware function
detect_top(istream,qstream,ostream,B_threshold, &flag_out);
ostream >> hd_mag;
std::cout<<"hd_mag\t"<<std::hex<< hd_mag.range(15,0)<<std::endl;
//Run a software version of the hardware function to validate results
mag_sf = Ai*Ai + Aq*Aq;
if(mag_sf > B_threshold)
flag_sf = true;
else
flag_sf = false;
//Compare results
if(flag_sf != flag_out)
printf("ERROR HW and SW results mismatch\n");
else
printf("Success HW and SW results match\n");
printf("mag_sf = %d\n", mag_sf);
printf("flag_sf = %d\n", flag_sf);
printf("flag_out = %d\n", flag_out);
std::cout<<"hd_mag\t"<<std::dec<< hd_mag.range(15,0)<<std::endl;
return 0;
}
INFO: [SIM 2] *************** CSIM start *************** INFO: [SIM 4] CSIM will launch GCC as the compiler. Compiling ../../../test.cpp in debug mode Generating csim.exe hello my test kernel outMag 25 hd_mag 0x19 Success HW and SW results match mag_sf = 25 flag_sf = 1 flag_out = 1 hd_mag 25 INFO: [SIM 1] CSim done with 0 errors. INFO: [SIM 3] *************** CSIM finish ***************
Thanks,
Wen
11-05-2020 10:02 PM
Thanks for your detail reply. I will have a try.
Best regards,