Skip to content

Commit

Permalink
refactor weirdness in skip list for embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
havogt committed Jan 25, 2024
1 parent 0a0dc50 commit a29c9ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src/gt4py/next/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,8 @@ def _field(
domain: Optional[DomainLike] = None,
dtype: Optional[core_defs.DType] = None,
) -> Field:
# Utility function to construct a `Field` from different buffer representations.
# Consider removing this function and using `Field` constructor directly.
raise NotImplementedError


Expand Down
25 changes: 16 additions & 9 deletions tests/next_tests/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import pytest

from gt4py.next import allocators as next_allocators


# Skip definitions
XFAIL = pytest.xfail
Expand Down Expand Up @@ -55,9 +57,13 @@ class ProgramBackendId(_PythonObjectIdMixin, str, enum.Enum):
DOUBLE_ROUNDTRIP = "gt4py.next.program_processors.runners.double_roundtrip.backend"


class AllocatorId(_PythonObjectIdMixin, str, enum.Enum):
CPU_ALLOCATOR = "gt4py.next.allocators.default_cpu_allocator"
GPU_ALLOCATOR = "gt4py.next.allocators.default_gpu_allocator"
numpy_execution = (None, next_allocators.default_cpu_allocator)
cupy_execution = (None, next_allocators.default_gpu_allocator)


class EmbeddedIds(_PythonObjectIdMixin, str, enum.Enum):
NUMPY_EXECUTION = "next_tests.definitions.numpy_execution"
CUPY_EXECUTION = "next_tests.definitions.cupy_execution"


class OptionalProgramBackendId(_PythonObjectIdMixin, str, enum.Enum):
Expand Down Expand Up @@ -140,6 +146,11 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum):
EMBEDDED_SKIP_LIST = [
(USES_DYNAMIC_OFFSETS, XFAIL, UNSUPPORTED_MESSAGE),
(CHECKS_SPECIFIC_ERROR, XFAIL, UNSUPPORTED_MESSAGE),
(
USES_SCAN_WITHOUT_FIELD_ARGS,
XFAIL,
UNSUPPORTED_MESSAGE,
), # we can't extract the field type from scan args
]
GTFN_SKIP_TEST_LIST = COMMON_SKIP_TEST_LIST + [
# floordiv not yet supported, see https://github.com/GridTools/gt4py/issues/1136
Expand All @@ -150,12 +161,8 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum):
#: Skip matrix, contains for each backend processor a list of tuples with following fields:
#: (<test_marker>, <skip_definition, <skip_message>)
BACKEND_SKIP_TEST_MATRIX = {
AllocatorId.CPU_ALLOCATOR: EMBEDDED_SKIP_LIST,
AllocatorId.GPU_ALLOCATOR: EMBEDDED_SKIP_LIST
+ [
# we can't extract the type of the output field
(USES_SCAN_WITHOUT_FIELD_ARGS, XFAIL, UNSUPPORTED_MESSAGE)
],
EmbeddedIds.NUMPY_EXECUTION: EMBEDDED_SKIP_LIST,
EmbeddedIds.CUPY_EXECUTION: EMBEDDED_SKIP_LIST,
OptionalProgramBackendId.DACE_CPU: DACE_SKIP_TEST_LIST,
OptionalProgramBackendId.DACE_GPU: DACE_SKIP_TEST_LIST
+ [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,6 @@ def no_backend(program: itir.FencilDefinition, *args: Any, **kwargs: Any) -> Non
_ExecutorAndAllocator = namedtuple("_ExecutorAndAllocator", ["executor", "allocator"])


def _backend_name(
p: next_tests.definitions._PythonObjectIdMixin
| tuple[
Optional[next_tests.definitions._PythonObjectIdMixin],
next_tests.definitions._PythonObjectIdMixin,
]
):
if isinstance(p, tuple):
executor = p[0].short_id() if p[0] is not None else "None"
allocator = p[1].short_id()
return f"{executor}-{allocator}"
else:
return p.short_id()


@pytest.fixture(
params=[
next_tests.definitions.ProgramBackendId.ROUNDTRIP,
Expand All @@ -80,13 +65,13 @@ def _backend_name(
next_tests.definitions.ProgramBackendId.GTFN_GPU, marks=pytest.mark.requires_gpu
),
# will use the default (embedded) execution, but input/output allocated with the provided allocator
(None, next_tests.definitions.AllocatorId.CPU_ALLOCATOR),
next_tests.definitions.EmbeddedIds.NUMPY_EXECUTION,
pytest.param(
(None, next_tests.definitions.AllocatorId.GPU_ALLOCATOR), marks=pytest.mark.requires_gpu
next_tests.definitions.EmbeddedIds.CUPY_EXECUTION, marks=pytest.mark.requires_gpu
),
]
+ OPTIONAL_PROCESSORS,
ids=_backend_name,
ids=lambda p: p.short_id(),
)
def fieldview_backend(request):
"""
Expand All @@ -95,24 +80,21 @@ def fieldview_backend(request):
Notes:
Check ADR 15 for details on the test-exclusion matrices.
"""
backend_or_allocator_id = request.param
if isinstance(backend_or_allocator_id, tuple):
backend_id, allocator_id = backend_or_allocator_id
assert backend_id is None # revisit if we have need for backend_id != None
executor = None
allocator = allocator_id.load()
exclusion_matrix_id = backend_or_allocator_id[1]
backend_id = request.param
backend = backend_id.load()
# we support ppi.ProgramBackends and a tuple of executor and allocator
# the use case for the latter is embedded with executor == None
if isinstance(backend, tuple):
executor, allocator = backend
else:
backend = backend_or_allocator_id.load()
executor = backend.executor
executor = backend
allocator = backend
exclusion_matrix_id = backend_or_allocator_id

for marker, skip_mark, msg in next_tests.definitions.BACKEND_SKIP_TEST_MATRIX.get(
exclusion_matrix_id, []
backend_id, []
):
if request.node.get_closest_marker(marker):
skip_mark(msg.format(marker=marker, backend=_backend_name(backend_or_allocator_id)))
skip_mark(msg.format(marker=marker, backend=backend_id))

backup_backend = decorator.DEFAULT_BACKEND
decorator.DEFAULT_BACKEND = no_backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_default_backend_is_respected_scan_operator(cartesian_case): # noqa: F8
def sum(state: float, a: float) -> float:
return state + a

a = gtx.ones({KDim: 10}, allocator=cartesian_case.backend)
a = gtx.ones({KDim: 10}, allocator=cartesian_case.allocator)

with pytest.raises(ValueError, match="No backend selected!"):
# see comment in field_operator test
Expand Down

0 comments on commit a29c9ca

Please sign in to comment.