14
14
# SPDX-License-Identifier: GPL-3.0-or-later
15
15
16
16
from collections import namedtuple
17
- from typing import Any , TypeVar
17
+ from typing import Any , Optional , TypeVar
18
18
19
19
import numpy as np
20
20
import pytest
@@ -52,6 +52,23 @@ def no_backend(program: itir.FencilDefinition, *args: Any, **kwargs: Any) -> Non
52
52
)
53
53
),
54
54
55
+ _ExecutorAndAllocator = namedtuple ("_ExecutorAndAllocator" , ["executor" , "allocator" ])
56
+
57
+
58
+ def _backend_name (
59
+ p : next_tests .definitions ._PythonObjectIdMixin
60
+ | tuple [
61
+ Optional [next_tests .definitions ._PythonObjectIdMixin ],
62
+ next_tests .definitions ._PythonObjectIdMixin ,
63
+ ]
64
+ ):
65
+ if isinstance (p , tuple ):
66
+ executor = p [0 ].short_id () if p [0 ] is not None else "None"
67
+ allocator = p [1 ].short_id ()
68
+ return f"{ executor } -{ allocator } "
69
+ else :
70
+ return p .short_id ()
71
+
55
72
56
73
@pytest .fixture (
57
74
params = [
@@ -63,13 +80,13 @@ def no_backend(program: itir.FencilDefinition, *args: Any, **kwargs: Any) -> Non
63
80
next_tests .definitions .ProgramBackendId .GTFN_GPU , marks = pytest .mark .requires_gpu
64
81
),
65
82
# will use the default (embedded) execution, but input/output allocated with the provided allocator
66
- next_tests .definitions .AllocatorId .CPU_ALLOCATOR ,
83
+ ( None , next_tests .definitions .AllocatorId .CPU_ALLOCATOR ) ,
67
84
pytest .param (
68
- next_tests .definitions .AllocatorId .GPU_ALLOCATOR , marks = pytest .mark .requires_gpu
85
+ ( None , next_tests .definitions .AllocatorId .GPU_ALLOCATOR ) , marks = pytest .mark .requires_gpu
69
86
),
70
87
]
71
88
+ OPTIONAL_PROCESSORS ,
72
- ids = lambda p : p . short_id () if p is not None else "None" ,
89
+ ids = _backend_name ,
73
90
)
74
91
def fieldview_backend (request ):
75
92
"""
@@ -79,17 +96,27 @@ def fieldview_backend(request):
79
96
Check ADR 15 for details on the test-exclusion matrices.
80
97
"""
81
98
backend_or_allocator_id = request .param
82
- backend_or_allocator = backend_or_allocator_id .load ()
99
+ if isinstance (backend_or_allocator_id , tuple ):
100
+ backend_id , allocator_id = backend_or_allocator_id
101
+ assert backend_id is None # revisit if we have need for backend_id != None
102
+ executor = None
103
+ allocator = allocator_id .load ()
104
+ exclusion_matrix_id = backend_or_allocator_id [1 ]
105
+ else :
106
+ backend = backend_or_allocator_id .load ()
107
+ executor = backend .executor
108
+ allocator = backend
109
+ exclusion_matrix_id = backend_or_allocator_id
83
110
84
111
for marker , skip_mark , msg in next_tests .definitions .BACKEND_SKIP_TEST_MATRIX .get (
85
- backend_or_allocator_id , []
112
+ exclusion_matrix_id , []
86
113
):
87
114
if request .node .get_closest_marker (marker ):
88
- skip_mark (msg .format (marker = marker , backend = backend_or_allocator_id ))
115
+ skip_mark (msg .format (marker = marker , backend = _backend_name ( backend_or_allocator_id ) ))
89
116
90
117
backup_backend = decorator .DEFAULT_BACKEND
91
118
decorator .DEFAULT_BACKEND = no_backend
92
- yield backend_or_allocator
119
+ yield _ExecutorAndAllocator ( executor , allocator )
93
120
decorator .DEFAULT_BACKEND = backup_backend
94
121
95
122
0 commit comments