From 95cc458631a739755eafc924c3833902771cefb2 Mon Sep 17 00:00:00 2001 From: Paolo Cretaro <paolo.cretaro@roma1.infn.it> Date: Thu, 2 Jul 2020 18:49:49 +0200 Subject: [PATCH 1/2] Fix access to the number of elements for the inputs of the concatenate3d function The compiler embedded in Vivado HLS (tried both 2018.3 and 2020.1) does not like the n_elem1[0] notation to access the first element of the config struct. Change to n_elem1_0 to fix it (as it was alreay done for the other dimensions). --- hls4ml/templates/vivado/nnet_utils/nnet_merge.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hls4ml/templates/vivado/nnet_utils/nnet_merge.h b/hls4ml/templates/vivado/nnet_utils/nnet_merge.h index 50d181ce1..3c73f62db 100644 --- a/hls4ml/templates/vivado/nnet_utils/nnet_merge.h +++ b/hls4ml/templates/vivado/nnet_utils/nnet_merge.h @@ -244,9 +244,9 @@ input1_T data1[CONFIG_T::n_elem1_0 * CONFIG_T::n_elem1_1 * CONFIG_T::n_elem1_2], template<class input1_T, class input2_T, class res_T, typename CONFIG_T> void concatenate3d( - input1_T data1[CONFIG_T::n_elem1[0] * CONFIG_T::n_elem1_1 * CONFIG_T::n_elem1_2], - input2_T data2[CONFIG_T::n_elem2[0] * CONFIG_T::n_elem2_1 * CONFIG_T::n_elem2_2], - res_T res[CONFIG_T::n_elem1[0] * CONFIG_T::n_elem1_1 * CONFIG_T::n_elem1_2 + CONFIG_T::n_elem2[0] * CONFIG_T::n_elem2_1 * CONFIG_T::n_elem2_2]) + input1_T data1[CONFIG_T::n_elem1_0 * CONFIG_T::n_elem1_1 * CONFIG_T::n_elem1_2], + input2_T data2[CONFIG_T::n_elem2_0 * CONFIG_T::n_elem2_1 * CONFIG_T::n_elem2_2], + res_T res[CONFIG_T::n_elem1_0 * CONFIG_T::n_elem1_1 * CONFIG_T::n_elem1_2 + CONFIG_T::n_elem2_0 * CONFIG_T::n_elem2_1 * CONFIG_T::n_elem2_2]) { if (CONFIG_T::axis == 2 || CONFIG_T::axis == -1) { concatenate3d_2<input1_T, input2_T, res_T, CONFIG_T>(data1, data2, res); -- GitLab From c687a2b62d4dd7361a69475b3639f80021aae868 Mon Sep 17 00:00:00 2001 From: Paolo Cretaro <paolo.cretaro@roma1.infn.it> Date: Thu, 2 Jul 2020 18:55:31 +0200 Subject: [PATCH 2/2] Fix shape calculation for the concatenate layer The resulting shape of a concatenation should be the sum of the input shapes only for the specified axis, leaving the other dimensions untouched. The assumption is that the two inputs have the same shape, except for the dimension on which the concatenation should be done. FIX #202 --- hls4ml/model/hls_layers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hls4ml/model/hls_layers.py b/hls4ml/model/hls_layers.py index 60b92aa84..39db535fd 100644 --- a/hls4ml/model/hls_layers.py +++ b/hls4ml/model/hls_layers.py @@ -764,7 +764,9 @@ class Concatenate(Merge): assert(len(self.inputs) == 2) inp1 = self.get_input_variable(self.inputs[0]) inp2 = self.get_input_variable(self.inputs[1]) - shape = [sum(x) for x in zip(inp1.shape, inp2.shape)] + axis = self.attributes['axis'] + shape = inp1.shape[:] + shape[axis] += inp2.shape[axis] rank = len(shape) if rank > 1: dims = ['OUT_CONCAT_{}_{}'.format(i, self.index) for i in range(rank)] -- GitLab