Skip to content

Commit

Permalink
Merge branch 'main' into vivado_codegen_namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
calad0i authored Oct 31, 2024
2 parents b209365 + 82d059b commit f95b34f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
3 changes: 2 additions & 1 deletion hls4ml/templates/vitis/nnet_utils/nnet_conv1d_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ void conv_1d_resource_cl(data_T data[CONFIG_T::in_width * CONFIG_T::n_chan],
ResultLoop:
for (unsigned i_res = 0; i_res < mult_n_out; i_res++) {
#pragma HLS UNROLL
*(res++) = cast<data_T, res_T, typename CONFIG_T::mult_config>(acc[i_pxl][i_res]);
res[i_part * CONFIG_T::n_pixels * mult_n_out + i_pxl * mult_n_out + i_res] =
cast<data_T, res_T, typename CONFIG_T::mult_config>(acc[i_pxl][i_res]);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion hls4ml/templates/vitis/nnet_utils/nnet_conv2d_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ void conv_2d_resource_cl(
ResultLoop:
for (unsigned i_res = 0; i_res < mult_n_out; i_res++) {
#pragma HLS UNROLL
*(res++) = cast<data_T, res_T, typename CONFIG_T::mult_config>(acc[i_pxl][i_res]);
res[i_part * CONFIG_T::n_pixels * mult_n_out + i_pxl * mult_n_out + i_res] =
cast<data_T, res_T, typename CONFIG_T::mult_config>(acc[i_pxl][i_res]);
}
}
}
Expand Down
34 changes: 28 additions & 6 deletions test/pytest/test_keras_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,19 @@ def test_activations(activation_function, backend, io_type):


@pytest.mark.parametrize('padds', padds_options)
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus', 'oneAPI'])
@pytest.mark.parametrize(
'backend,strategy',
[
('Vivado', 'Resource'),
('Vivado', 'Latency'),
('Vitis', 'Resource'),
('Vitis', 'Latency'),
('Quartus', 'Resource'),
('oneAPI', 'Resource'),
],
)
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
def test_conv1d(padds, backend, io_type):
def test_conv1d(padds, backend, strategy, io_type):
model = tf.keras.models.Sequential()
input_shape = (10, 128, 4)
model.add(
Expand All @@ -144,7 +154,8 @@ def test_conv1d(padds, backend, io_type):
keras_prediction = model.predict(X_input)

config = hls4ml.utils.config_from_keras_model(model)
output_dir = str(test_root_path / f'hls4mlprj_keras_api_conv1d_{padds}_{backend}_{io_type}')
config['Model']['Strategy'] = strategy
output_dir = str(test_root_path / f'hls4mlprj_keras_api_conv1d_{padds}_{backend}_{strategy}_{io_type}')
hls_model = hls4ml.converters.convert_from_keras_model(
model, hls_config=config, output_dir=output_dir, backend=backend, io_type=io_type
)
Expand Down Expand Up @@ -192,9 +203,19 @@ def test_conv1d(padds, backend, io_type):

@pytest.mark.parametrize('chans', chans_options)
@pytest.mark.parametrize('padds', padds_options)
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus', 'oneAPI'])
@pytest.mark.parametrize(
'backend,strategy',
[
('Vivado', 'Resource'),
('Vivado', 'Latency'),
('Vitis', 'Resource'),
('Vitis', 'Latency'),
('Quartus', 'Resource'),
('oneAPI', 'Resource'),
],
)
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
def test_conv2d(chans, padds, backend, io_type):
def test_conv2d(chans, padds, backend, strategy, io_type):
model = tf.keras.models.Sequential()
input_shape = (28, 28, 3)
model.add(
Expand All @@ -215,7 +236,8 @@ def test_conv2d(chans, padds, backend, io_type):
keras_prediction = model.predict(X_input)

config = hls4ml.utils.config_from_keras_model(model)
output_dir = str(test_root_path / f'hls4mlprj_keras_api_conv2d_{backend}_{chans}_{padds}_{io_type}')
config['Model']['Strategy'] = strategy
output_dir = str(test_root_path / f'hls4mlprj_keras_api_conv2d_{backend}_{strategy}_{chans}_{padds}_{io_type}')
hls_model = hls4ml.converters.convert_from_keras_model(
model, hls_config=config, output_dir=output_dir, backend=backend, io_type=io_type
)
Expand Down

0 comments on commit f95b34f

Please sign in to comment.