Skip to content

Commit 82d059b

Browse files
jmitrevsvloncar
andauthored
Change indexing in filling result for io_parallel convolutions, Vitis (#1102)
* fix conv*d_resource indexing * fix indexing, add a pytest --------- Co-authored-by: Vladimir <vloncar@users.noreply.github.com>
1 parent 25b08cf commit 82d059b

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

hls4ml/templates/vitis/nnet_utils/nnet_conv1d_resource.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ void conv_1d_resource_cl(data_T data[CONFIG_T::in_width * CONFIG_T::n_chan],
9494
ResultLoop:
9595
for (unsigned i_res = 0; i_res < mult_n_out; i_res++) {
9696
#pragma HLS UNROLL
97-
*(res++) = cast<data_T, res_T, typename CONFIG_T::mult_config>(acc[i_pxl][i_res]);
97+
res[i_part * CONFIG_T::n_pixels * mult_n_out + i_pxl * mult_n_out + i_res] =
98+
cast<data_T, res_T, typename CONFIG_T::mult_config>(acc[i_pxl][i_res]);
9899
}
99100
}
100101
}

hls4ml/templates/vitis/nnet_utils/nnet_conv2d_resource.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ void conv_2d_resource_cl(
9797
ResultLoop:
9898
for (unsigned i_res = 0; i_res < mult_n_out; i_res++) {
9999
#pragma HLS UNROLL
100-
*(res++) = cast<data_T, res_T, typename CONFIG_T::mult_config>(acc[i_pxl][i_res]);
100+
res[i_part * CONFIG_T::n_pixels * mult_n_out + i_pxl * mult_n_out + i_res] =
101+
cast<data_T, res_T, typename CONFIG_T::mult_config>(acc[i_pxl][i_res]);
101102
}
102103
}
103104
}

test/pytest/test_keras_api.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,19 @@ def test_activations(activation_function, backend, io_type):
119119

120120

121121
@pytest.mark.parametrize('padds', padds_options)
122-
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus', 'oneAPI'])
122+
@pytest.mark.parametrize(
123+
'backend,strategy',
124+
[
125+
('Vivado', 'Resource'),
126+
('Vivado', 'Latency'),
127+
('Vitis', 'Resource'),
128+
('Vitis', 'Latency'),
129+
('Quartus', 'Resource'),
130+
('oneAPI', 'Resource'),
131+
],
132+
)
123133
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
124-
def test_conv1d(padds, backend, io_type):
134+
def test_conv1d(padds, backend, strategy, io_type):
125135
model = tf.keras.models.Sequential()
126136
input_shape = (10, 128, 4)
127137
model.add(
@@ -144,7 +154,8 @@ def test_conv1d(padds, backend, io_type):
144154
keras_prediction = model.predict(X_input)
145155

146156
config = hls4ml.utils.config_from_keras_model(model)
147-
output_dir = str(test_root_path / f'hls4mlprj_keras_api_conv1d_{padds}_{backend}_{io_type}')
157+
config['Model']['Strategy'] = strategy
158+
output_dir = str(test_root_path / f'hls4mlprj_keras_api_conv1d_{padds}_{backend}_{strategy}_{io_type}')
148159
hls_model = hls4ml.converters.convert_from_keras_model(
149160
model, hls_config=config, output_dir=output_dir, backend=backend, io_type=io_type
150161
)
@@ -192,9 +203,19 @@ def test_conv1d(padds, backend, io_type):
192203

193204
@pytest.mark.parametrize('chans', chans_options)
194205
@pytest.mark.parametrize('padds', padds_options)
195-
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus', 'oneAPI'])
206+
@pytest.mark.parametrize(
207+
'backend,strategy',
208+
[
209+
('Vivado', 'Resource'),
210+
('Vivado', 'Latency'),
211+
('Vitis', 'Resource'),
212+
('Vitis', 'Latency'),
213+
('Quartus', 'Resource'),
214+
('oneAPI', 'Resource'),
215+
],
216+
)
196217
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
197-
def test_conv2d(chans, padds, backend, io_type):
218+
def test_conv2d(chans, padds, backend, strategy, io_type):
198219
model = tf.keras.models.Sequential()
199220
input_shape = (28, 28, 3)
200221
model.add(
@@ -215,7 +236,8 @@ def test_conv2d(chans, padds, backend, io_type):
215236
keras_prediction = model.predict(X_input)
216237

217238
config = hls4ml.utils.config_from_keras_model(model)
218-
output_dir = str(test_root_path / f'hls4mlprj_keras_api_conv2d_{backend}_{chans}_{padds}_{io_type}')
239+
config['Model']['Strategy'] = strategy
240+
output_dir = str(test_root_path / f'hls4mlprj_keras_api_conv2d_{backend}_{strategy}_{chans}_{padds}_{io_type}')
219241
hls_model = hls4ml.converters.convert_from_keras_model(
220242
model, hls_config=config, output_dir=output_dir, backend=backend, io_type=io_type
221243
)

0 commit comments

Comments
 (0)