Remove alternative C++ operator
Created by: KOVI89alipes
Hi,
One of the HLS template files uses old-style, alternative logical C++ operator and
and not
template<class data_T, class res_T, typename CONFIG_T>
inline typename std::enable_if<std::is_same<data_T, ap_uint<1>>::value
and std::is_same<typename CONFIG_T::weight_t, ap_uint<1>>::value, ap_int<nnet::ceillog2(CONFIG_T::n_in) + 2>>::type
cast(typename CONFIG_T::accum_t x){
return (ap_int<nnet::ceillog2(CONFIG_T::n_in) + 2>) (x - CONFIG_T::n_in / 2) * 2;
}
template<class data_T, class res_T, typename CONFIG_T>
inline typename std::enable_if<(not std::is_same<data_T, ap_uint<1>>::value), res_T>::type
cast(typename CONFIG_T::accum_t x){
return (res_T) x;
}
These are alternative tokens https://en.cppreference.com/w/cpp/language/operator_alternative
And they are not supported by the MSVC compiler https://stackoverflow.com/questions/24414124/why-does-vs-not-define-the-alternative-tokens-for-logical-operators
It prevents HLS4ML kernel code to be compiled in Windows with MSVC and gives an error
firmware\nnet_utils\nnet_mult.h(88): error C2146: syntax error: missing '>' before identifier 'and'
Suggestion: replace alternative logical operators with standard ones and
-> &&
, not
->~
template<class data_T, class res_T, typename CONFIG_T>
inline typename std::enable_if<std::is_same<data_T, ap_uint<1>>::value
&& std::is_same<typename CONFIG_T::weight_t, ap_uint<1>>::value, ap_int<nnet::ceillog2(CONFIG_T::n_in) + 2>>::type
cast(typename CONFIG_T::accum_t x){
return (ap_int<nnet::ceillog2(CONFIG_T::n_in) + 2>) (x - CONFIG_T::n_in / 2) * 2;
}
template<class data_T, class res_T, typename CONFIG_T>
inline typename std::enable_if<(! std::is_same<data_T, ap_uint<1>>::value), res_T>::type
cast(typename CONFIG_T::accum_t x){
return (res_T) x;
}
Code with these changes can be compiled in MSVC and is still valid in GCC, Vivado HLS
Why to bother - we are using HLS4ML kernels in Windows and it's nice to have bittrue model of the kernel for verification purposes.