From a29c9cace2968bd0191afd44c6e219d53087e6e6 Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Thu, 25 Jan 2024 23:05:04 +0100 Subject: [PATCH] refactor weirdness in skip list for embedded --- src/gt4py/next/common.py | 2 + tests/next_tests/definitions.py | 25 +++++++---- .../ffront_tests/ffront_test_utils.py | 42 ++++++------------- .../ffront_tests/test_embedded_regression.py | 2 +- 4 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/gt4py/next/common.py b/src/gt4py/next/common.py index 840b0e8bbc..62ba4a7967 100644 --- a/src/gt4py/next/common.py +++ b/src/gt4py/next/common.py @@ -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 diff --git a/tests/next_tests/definitions.py b/tests/next_tests/definitions.py index c193a05057..e8c3460ccf 100644 --- a/tests/next_tests/definitions.py +++ b/tests/next_tests/definitions.py @@ -19,6 +19,8 @@ import pytest +from gt4py.next import allocators as next_allocators + # Skip definitions XFAIL = pytest.xfail @@ -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): @@ -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 @@ -150,12 +161,8 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum): #: Skip matrix, contains for each backend processor a list of tuples with following fields: #: (, ) 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 + [ diff --git a/tests/next_tests/integration_tests/feature_tests/ffront_tests/ffront_test_utils.py b/tests/next_tests/integration_tests/feature_tests/ffront_tests/ffront_test_utils.py index 1612cd8671..9649f38c3e 100644 --- a/tests/next_tests/integration_tests/feature_tests/ffront_tests/ffront_test_utils.py +++ b/tests/next_tests/integration_tests/feature_tests/ffront_tests/ffront_test_utils.py @@ -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, @@ -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): """ @@ -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 diff --git a/tests/next_tests/integration_tests/multi_feature_tests/ffront_tests/test_embedded_regression.py b/tests/next_tests/integration_tests/multi_feature_tests/ffront_tests/test_embedded_regression.py index ba4b1b0cdb..6a8f30bdb4 100644 --- a/tests/next_tests/integration_tests/multi_feature_tests/ffront_tests/test_embedded_regression.py +++ b/tests/next_tests/integration_tests/multi_feature_tests/ffront_tests/test_embedded_regression.py @@ -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