diff --git a/hls4ml/templates/vivado/nnet_utils/nnet_activation_stream.h b/hls4ml/templates/vivado/nnet_utils/nnet_activation_stream.h index b72809eff9..03ae5fd2fd 100644 --- a/hls4ml/templates/vivado/nnet_utils/nnet_activation_stream.h +++ b/hls4ml/templates/vivado/nnet_utils/nnet_activation_stream.h @@ -58,6 +58,39 @@ template void relu(hls::stream +void relu_max(hls::stream &data, hls::stream &res) { +ReLUActLoop: + for (int i = 0; i < CONFIG_T::n_in / res_T::size; i++) { + #pragma HLS PIPELINE + + data_T in_data = data.read(); + res_T out_data; + PRAGMA_DATA_PACK(out_data) + + ReLUPackLoop: + for (int j = 0; j < res_T::size; j++) { + #pragma HLS UNROLL + if (in_data[j] < 0) + out_data[j] = 0; + else if (in_data[j] > MAX_INT) + out_data[j] = MAX_INT; + else + out_data[j] = in_data[j]; + } + + res.write(out_data); + } +} + +template void relu6(hls::stream &data, hls::stream &res) { + relu_max(data, res); +} + +template void relu1(hls::stream &data, hls::stream &res) { + relu_max(data, res); +} + // ************************************************* // Sigmoid Activation // *************************************************