cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
evanslatyer
Explorer
Explorer
6,494 Views
Registered: ‎07-13-2015

HLS bug? Array initialisation.

Hello everyone (and in particular HLS engineers),

 

I've hit something that appears to be a bug in HLS 2015.4.1 and 2015.2, and probably earlier versions too. However, I'm not totally sure whether it's (a) HLS not following the C specifications due to a bug, (b) HLS not following the C specifications because it doesn't make sense on an FPGA, or (c) HLS following the C standards perfectly, while every other compiler implements a slightly different approach that's become a de-facto standard.

 

Really simple test code:

 

 

#include "ap_int.h"

int main(void) {

	ap_uint<1> hugeArray[100] = {0};

	for (int i = 0; i < 100; i++) {
		printf("%d",(int) hugeArray[i]);
	}
}

 

This appears to be conventional, valid C code for initialising an array with every element set to zero.

 

The result:

 

   Compiling ../../../src/test.cpp in debug mode
   Generating csim.exe
0000000000000001000100000001000001110111010100000000000001000000010001001001001001110111010101000100
@I [SIM-1] CSim done with 0 errors.

 

Doesn't look like all zeros to me!

 

If I change the array type to int (instead of ap_uint<1>) then I get all zeros. If I explicitly initialise the array as below then I get all zeros:

 

ap_uint<1> hugeArray[100] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

 

If I manually initialise the array (ie a loop that sets every element) then I get all zeros. If I make the array static then I get all zeros.

 

 

Cosimulation verifies this behaviour to some extent:

 

 

#include "ap_int.h"

int arrayInit(void) {

	ap_uint<1> hugeArray[100] = {0};

	int internalSum = 0;
	for (int i = 0; i < 100; i++) {
		internalSum += hugeArray[i];
	}
	return internalSum;
}
#include "ap_int.h"

int arrayInit(void);

int main(void) {

	int result = arrayInit();
	printf("Array sum: %d\n",result);

	result = arrayInit();
	printf("Array sum: %d\n",result);

	result = arrayInit();
	printf("Array sum: %d\n",result);
}

Result:

 

 

@W [SIM-201] RTL produces unknown value 'X' on port 'ap_return', possible cause: There are uninitialized variables in the C design.
@W [SIM-201] RTL produces unknown value 'X' on port 'ap_return', possible cause: There are uninitialized variables in the C design.
@W [SIM-201] RTL produces unknown value 'X' on port 'ap_return', possible cause: There are uninitialized variables in the C design.
Array sum: 0
Array sum: 0
Array sum: 0

 

Essentially, there are unknowns because HLS is only initialising the first array element.

 

 

Any chance of a fix in 2016.1?

0 Kudos
2 Replies
neeruajith
Visitor
Visitor
1,597 Views
Registered: ‎06-12-2018

I am also facing a similar issue. Did you solve it?

0 Kudos
u4223374
Advisor
Advisor
1,587 Views
Registered: ‎04-26-2015

@neeruajith The "solution" is to explicitly initialize every element that you need, rather than relying on the compiler to set everything to zero.

0 Kudos