Skip to content

Commit 94ea9be

Browse files
authored
template and test fix (#1319)
* template and test fix * intel/ac_types/ac_int.hpp:156:30: error: unsigned _BitInt must have a bit size of at least 1 * more oneapi fix
1 parent c0e9611 commit 94ea9be

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

hls4ml/templates/oneapi/firmware/nnet_utils/nnet_merge.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ template <class input1_T, class input2_T, class res_T, typename CONFIG_T>
6868
void maximum(const input1_T &data1, const input2_T &data2, res_T &res) {
6969
#pragma unroll
7070
for (int i = 0; i < CONFIG_T::n_elem; i++) {
71-
res[i] = static_cast<typename res_T::value_type>((data1[i] > data2[i]) ? static_cast<res_T>(data1[i])
72-
: static_cast<res_T>(data2[i]));
71+
res[i] = (data1[i] > data2[i]) ? static_cast<typename res_T::value_type>(data1[i])
72+
: static_cast<typename res_T::value_type>(data2[i]);
7373
}
7474
}
7575

7676
template <class input1_T, class input2_T, class res_T, typename CONFIG_T>
7777
void minimum(const input1_T &data1, const input2_T &data2, res_T &res) {
7878
#pragma unroll
7979
for (int i = 0; i < CONFIG_T::n_elem; i++) {
80-
res[i] = static_cast<typename res_T::value_type>((data1[i] < data2[i]) ? static_cast<res_T>(data1[i])
81-
: static_cast<res_T>(data2[i]));
80+
res[i] = (data1[i] < data2[i]) ? static_cast<typename res_T::value_type>(data1[i])
81+
: static_cast<typename res_T::value_type>(data2[i]);
8282
}
8383
}
8484

hls4ml/templates/oneapi/firmware/nnet_utils/nnet_merge_stream.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ template <class input1_pipe, class input2_pipe, class res_pipe, typename CONFIG_
8585
#pragma unroll
8686
for (int j = 0; j < outputSize; j++) {
8787
out_data[j] = static_cast<typename ExtractPipeType<res_pipe>::value_type::value_type>(
88-
(in_data1[j] + in_data2[j]) * ac_fixed<1, 0, false>(0.5));
88+
(in_data1[j] + in_data2[j]) * ac_fixed<2, 1, false>(0.5));
8989
}
9090

9191
res_pipe::write(out_data);
@@ -107,8 +107,9 @@ template <class input1_pipe, class input2_pipe, class res_pipe, typename CONFIG_
107107
MaxPack:
108108
#pragma unroll
109109
for (int j = 0; j < outputSize; j++) {
110-
out_data[j] = static_cast<typename ExtractPipeType<res_pipe>::value_type::value_type>(
111-
(in_data1[j] > in_data2[j]) ? static_cast<res_T>(in_data1[j]) : static_cast<res_T>(in_data2[j]));
110+
out_data[j] = (in_data1[j] > in_data2[j])
111+
? static_cast<typename ExtractPipeType<res_pipe>::value_type::value_type>(in_data1[j])
112+
: static_cast<typename ExtractPipeType<res_pipe>::value_type::value_type>(in_data2[j]);
112113
}
113114

114115
res_pipe::write(out_data);
@@ -130,8 +131,9 @@ template <class input1_pipe, class input2_pipe, class res_pipe, typename CONFIG_
130131
MinPack:
131132
#pragma unroll
132133
for (int j = 0; j < outputSize; j++) {
133-
out_data[j] = static_cast<typename ExtractPipeType<res_pipe>::value_type::value_type>(
134-
(in_data1[j] < in_data2[j]) ? static_cast<res_T>(in_data1[j]) : static_cast<res_T>(in_data2[j]););
134+
out_data[j] = (in_data1[j] < in_data2[j])
135+
? static_cast<typename ExtractPipeType<res_pipe>::value_type::value_type>(in_data1[j])
136+
: static_cast<typename ExtractPipeType<res_pipe>::value_type::value_type>(in_data2[j]);
135137
}
136138

137139
res_pipe::write(out_data);

test/pytest/test_time_distributed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_time_distributed_layer(io_type, backend, use_h5):
4040
config['IOType'] = io_type
4141
config['HLSConfig'] = hls4ml.utils.config_from_keras_model(keras_model, default_precision='fixed<10,8>')
4242

43-
hls_model = hls4ml.converters.keras_to_hls(config)
43+
hls_model = hls4ml.converters.keras_v2_to_hls(config)
4444
hls_model.compile()
4545

4646
x = np.random.randint(0, 5, size=(10, *input_shape)).astype('float')
@@ -80,7 +80,7 @@ def test_time_distributed_layer_lstm(io_type, backend, use_h5):
8080
config['IOType'] = io_type
8181
config['HLSConfig'] = hls4ml.utils.config_from_keras_model(keras_model, default_precision='fixed<32,16>')
8282

83-
hls_model = hls4ml.converters.keras_to_hls(config)
83+
hls_model = hls4ml.converters.keras_v2_to_hls(config)
8484
hls_model.compile()
8585

8686
x = np.random.rand(10, *input_shape) - 0.5
@@ -127,7 +127,7 @@ def test_time_distributed_model(io_type, backend, use_h5):
127127
config['IOType'] = io_type
128128
config['HLSConfig'] = hls4ml.utils.config_from_keras_model(keras_model, default_precision='fixed<10,8>')
129129

130-
hls_model = hls4ml.converters.keras_to_hls(config)
130+
hls_model = hls4ml.converters.keras_v2_to_hls(config)
131131
hls_model.compile()
132132

133133
x = np.random.randint(0, 5, size=(10, *input_shape)).astype('float')

0 commit comments

Comments
 (0)