Skip to content

Commit fa1ff24

Browse files
committed
Reorder loops in im2col_2d_cl given resource strategy issue. Reenable relevant test. Use 5000 MNIST samples rather than full dataset for faster testing
1 parent 7f75add commit fa1ff24

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

hls4ml/templates/vivado/nnet_utils/nnet_conv2d_resource.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,18 @@ void im2col_2d_cl(
154154
const int col)
155155
{
156156
int index = 0;
157-
for (int channel = CONFIG_T::n_chan; channel--; data++) {
157+
for (int kernel_row = 0; kernel_row < CONFIG_T::filt_height; kernel_row++) {
158158
#pragma HLS UNROLL
159-
for (int kernel_row = 0; kernel_row < CONFIG_T::filt_height; kernel_row++) {
160-
int input_row = -CONFIG_T::pad_top + kernel_row * CONFIG_T::dilation_height + row * CONFIG_T::stride_height;
161-
for (int kernel_col = 0; kernel_col < CONFIG_T::filt_width; kernel_col++) {
159+
int input_row = -CONFIG_T::pad_top + kernel_row * CONFIG_T::dilation_height + row * CONFIG_T::stride_height;
160+
for (int kernel_col = 0; kernel_col < CONFIG_T::filt_width; kernel_col++) {
161+
for (int channel = 0; channel < CONFIG_T::n_chan; channel++) {
162162
if (input_row < 0 || input_row >= CONFIG_T::in_height) {
163163
data_col[index++] = 0;
164164
} else {
165165
int input_col = -CONFIG_T::pad_left + kernel_col * CONFIG_T::dilation_width + col * CONFIG_T::stride_width;
166166
if (input_col >= 0 && input_col < CONFIG_T::in_width) {
167-
//*(data_col++) = data[input_row * CONFIG_T::in_width * CONFIG_T::n_chan + input_col * CONFIG_T::n_chan];
168-
data_col[index++] = data[input_row * CONFIG_T::in_width * CONFIG_T::n_chan + input_col * CONFIG_T::n_chan];
167+
data_col[index++] = data[input_row * CONFIG_T::in_width * CONFIG_T::n_chan + input_col * CONFIG_T::n_chan + channel];
169168
} else {
170-
//*(data_col++) = 0;
171169
data_col[index++] = 0;
172170
}
173171
}
@@ -209,7 +207,6 @@ void conv_2d_resource_cl(
209207
FiltLoop:
210208
for (int k = 0; k < CONFIG_T::n_filt; k++) {
211209
res[i * CONFIG_T::out_width * CONFIG_T::n_filt + j * CONFIG_T::n_filt + k] = res_col[k];
212-
//res[k * CONFIG_T::out_height * CONFIG_T::out_width + i * CONFIG_T::out_width + j] = res_col[k]; // Transposed order
213210
}
214211
}
215212
}

test/pytest/test_cnn_mnist.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ def mnist_model():
2828
model.load_weights('../../example-models/keras/qkeras_mnist_cnn_weights.h5')
2929
return model
3030

31-
# TODO: add ('io_parallel', 'resource') when it can pass
32-
# https://github.com/fastmachinelearning/hls4ml/issues/375
3331
@pytest.fixture
3432
@pytest.mark.parametrize('settings', [('io_parallel', 'latency'),
33+
('io_parallel', 'resource'),
3534
('io_stream', 'latency'),
3635
('io_stream', 'resource')])
3736
def hls_model(settings):
@@ -49,10 +48,12 @@ def hls_model(settings):
4948
return hls_model
5049

5150
@pytest.mark.parametrize('settings', [('io_parallel', 'latency'),
51+
('io_parallel', 'resource'),
5252
('io_stream', 'latency'),
5353
('io_stream', 'resource')])
5454
def test_accuracy(mnist_data, mnist_model, hls_model):
5555
x_train, y_train, x_test, y_test = mnist_data
56+
x_test, y_test = x_test[:5000], y_test[:5000]
5657
model = mnist_model
5758
# model under test predictions and accuracy
5859
y_keras = model.predict(x_test)

0 commit comments

Comments
 (0)