Skip to content

Commit f93aab9

Browse files
authored
Merge pull request #1040 from JanFSchulte/updatepytests
Add Vitis to pytorch API tests
2 parents 75b0b0d + 3fc0302 commit f93aab9

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

test/pytest/test_pytorch_api.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def forward(self, x):
2222
return self.linear(x)
2323

2424

25-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
25+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
2626
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
2727
def test_linear(backend, io_type):
2828
model = LinearModel()
@@ -73,7 +73,7 @@ def test_linear(backend, io_type):
7373
nn.Threshold(threshold=1.0, value=0.0),
7474
],
7575
)
76-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
76+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
7777
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
7878
def test_activations(activation_function, backend, io_type):
7979
model = torch.nn.Sequential(nn.Linear(1, 1), activation_function).to()
@@ -164,7 +164,7 @@ def forward(self, x):
164164
ThresholdModel(),
165165
],
166166
)
167-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
167+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
168168
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
169169
def test_activation_functionals(activation_function, backend, io_type):
170170
model = activation_function
@@ -201,7 +201,7 @@ def test_activation_functionals(activation_function, backend, io_type):
201201

202202

203203
@pytest.mark.parametrize('padds', padds_options)
204-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
204+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
205205
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
206206
def test_conv1d(padds, backend, io_type):
207207
n_in = 2
@@ -242,7 +242,7 @@ def test_conv1d(padds, backend, io_type):
242242

243243
if io_type == 'io_stream':
244244
# Vivado inserts and additional layer for 'same' padding in io_stream
245-
if backend == "Vivado" and padds == 1:
245+
if (backend == "Vivado" or backend == "Vitis") and padds == 1:
246246
assert nNodes == len(hls_model.get_layers())
247247
else:
248248
assert nNodes - 1 == len(hls_model.get_layers())
@@ -269,13 +269,13 @@ def test_conv1d(padds, backend, io_type):
269269
# if not (backend == 'Vivado' and io_type == 'io_stream' and padds == 1):
270270
conv_index = 2
271271
act_index = 3
272-
if io_type == "io_stream" and not (backend == "Vivado" and padds == 1):
272+
if io_type == "io_stream" and not ((backend == "Vivado" or backend == "Vitis") and padds == 1):
273273
conv_index = 1
274274
act_index = 2
275275
assert list(hls_model.get_layers())[conv_index].attributes['name'] == convNode.name
276276
assert list(hls_model.get_layers())[conv_index].attributes['class_name'] == 'Conv1D'
277277
assert list(hls_model.get_layers())[act_index].attributes['activation'] == class_object_relu.__class__.__name__
278-
if io_type == "io_stream" and backend == "Vivado" and padds == 1:
278+
if io_type == "io_stream" and (backend == "Vivado" or backend == "Vitis") and padds == 1:
279279
assert list(hls_model.get_layers())[conv_index].attributes["in_width"] == size_in + 2
280280
else:
281281
assert list(hls_model.get_layers())[conv_index].attributes["in_width"] == size_in
@@ -287,7 +287,7 @@ def test_conv1d(padds, backend, io_type):
287287
padding = 0
288288
else:
289289
padding = 1
290-
if io_type == "io_stream" and backend == "Vivado" and padds == 1:
290+
if io_type == "io_stream" and (backend == "Vivado" or backend == "Vitis") and padds == 1:
291291
padding = 1
292292
padds = 0
293293

@@ -311,7 +311,7 @@ def test_conv1d(padds, backend, io_type):
311311

312312

313313
@pytest.mark.parametrize('padds', padds_options)
314-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
314+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
315315
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
316316
def test_conv2d(padds, backend, io_type):
317317
n_in = 2
@@ -409,7 +409,7 @@ def test_conv2d(padds, backend, io_type):
409409
# results are not very good at the moment
410410
np.testing.assert_allclose(hls_prediction, pytorch_prediction, rtol=0, atol=5e-2)
411411

412-
if not (backend == 'Vivado' and io_type == 'io_stream' and padds == 1):
412+
if not ((backend == 'Vivado' or backend == 'Vitis') and io_type == 'io_stream' and padds == 1):
413413
# Vivado inserts and additional layer for 'same' padding in io_stream
414414
conv_index = 2
415415
act_index = 3
@@ -464,7 +464,7 @@ def test_conv2d(padds, backend, io_type):
464464

465465
@pytest.mark.parametrize('pooling', pooling_layers)
466466
@pytest.mark.parametrize('padds', padds_options)
467-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
467+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
468468
def test_pooling(pooling, padds, backend):
469469
assert '1d' in pooling.__name__ or '2d' in pooling.__name__
470470

@@ -588,7 +588,7 @@ def forward(self, x):
588588
return self.bn(x)
589589

590590

591-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
591+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
592592
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
593593
def test_bn(backend, io_type):
594594
model = BatchNormModel()
@@ -631,7 +631,7 @@ def forward(self, x):
631631
return x
632632

633633

634-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
634+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
635635
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
636636
def test_squeeze(backend, io_type):
637637
model = SqueezeModel()
@@ -667,7 +667,7 @@ def test_squeeze(backend, io_type):
667667
assert list(hls_model.get_layers())[3].attributes['target_shape'] == [3]
668668

669669

670-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
670+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
671671
def test_flatten(backend):
672672
input = torch.randn(1, 1, 5, 5)
673673
model = nn.Sequential(nn.Conv2d(1, 32, 5, 1, 1), nn.Flatten(), nn.ReLU())
@@ -711,7 +711,7 @@ def forward(self, x):
711711
return x
712712

713713

714-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
714+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
715715
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
716716
def test_skipped_layers(backend, io_type):
717717
model = ModelSkippedLayers()
@@ -742,7 +742,7 @@ def test_skipped_layers(backend, io_type):
742742
np.testing.assert_allclose(hls_prediction, pytorch_prediction, rtol=0, atol=5e-2)
743743

744744

745-
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
745+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
746746
@pytest.mark.parametrize('io_type', ['io_parallel']) # Only io_parallel for now
747747
@pytest.mark.parametrize('tensor_rank', [2, 3])
748748
def test_remove_transpose(backend, io_type, tensor_rank):

0 commit comments

Comments
 (0)