Zero size array is nnet_common.h
Created by: KOVI89alipes
In C++ it is illegal to declare an array of zero length. https://stackoverflow.com/a/6180200/14582299
But it's allowed in the GNU C extension https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
Zero size array appears in the reduce
template function
template<class T, int N, class Op>
T reduce(T* x, Op op){
static constexpr int leftN = pow2(floorlog2(N - 1)) > 0 ? pow2(floorlog2(N - 1)) : 0;
static constexpr int rightN = N - leftN > 0 ? N - leftN : 0;
if(N == 1){
return x[0];
}else if(N == 2){
return op(x[0],x[1]);
}else{
T left[leftN];
T right[rightN]; <<<<<<<<<<<<
#pragma HLS array_partition variable=left complete
#pragma HLS array_partition variable=right complete
ReduceLeft: for(int i = 0; i < leftN; i++){
left[i] = x[i];
}
ReduceRight: for(int i = 0; i < rightN; i++){
right[i] = x[i+leftN];
}
return op(reduce<T,leftN,Op>(left, op), reduce<T,rightN,Op>(right, op));
}
}
And it gives an error in MSVC compilation
Possible fix - replace if
with if constexpr
template<class T, int N, class Op>
T reduce(T* x, Op op){
static constexpr int leftN = pow2(floorlog2(N - 1)) > 0 ? pow2(floorlog2(N - 1)) : 0;
static constexpr int rightN = N - leftN > 0 ? N - leftN : 0;
if constexpr(N == 1){
return x[0];
}else if constexpr (N == 2){
return op(x[0],x[1]);
}else{
T left[leftN];
T right[rightN];
#pragma HLS array_partition variable=left complete
#pragma HLS array_partition variable=right complete
ReduceLeft: for(int i = 0; i < leftN; i++){
left[i] = x[i];
}
ReduceRight: for(int i = 0; i < rightN; i++){
right[i] = x[i+leftN];
}
return op(reduce<T,leftN,Op>(left, op), reduce<T,rightN,Op>(right, op));
}
}