Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/development/ADRs/next/0015-Test_Exclusion_Matrices.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ In the context of Field View testing, lacking support for specific ITIR features
is being developed, we decided to use `pytest` fixtures to exclude unsupported tests.

> [!NOTE]
> The processor list and the exclusion-matrix example below reflect the state when this ADR was written: `GTFN_CPU_IMPERATIVE` and `GTFN_CPU_WITH_TEMPORARIES` no longer exist. The current processors and their exclusion lists are in `tests/next_tests/definitions.py`. The mechanism described here is unchanged.
> The processor list and the exclusion-matrix example below reflect the state when this ADR was written: `GTFN_CPU_IMPERATIVE` and `GTFN_CPU_WITH_TEMPORARIES` no longer exist. The current processors and their exclusion lists are in `tests/next_tests/definitions.py`. The mechanism described here is unchanged, except that `XFAIL` entries are applied as strict `xfail` markers, so a test that passes on a backend listed as unsupported fails as an unexpected pass.

## Context

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ markers = [
'uses_max_over: tests that use the max_over builtin',
'uses_mesh_with_skip_values: tests that use a mesh with skip values',
'uses_concat_where: tests that use the concat_where builtin',
'uses_concat_where_mixed_local_dims: tests that use concat_where on branches with different local dimensions',
'embedded_concat_where_infinite_domain: tests with concat_where resulting in an infinite domain',
'embedded_concat_where_non_contiguous_domain: tests with concat_where on non-contiguous domains',
'uses_program_metrics: tests that require backend support for program metrics',
Expand Down
62 changes: 33 additions & 29 deletions tests/next_tests/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class ProgramBackendId(_PythonObjectIdMixin, str, enum.Enum):
ROUNDTRIP = "gt4py.next.program_processors.runners.roundtrip.default"
ROUNDTRIP_NO_TRANSFORMS = "gt4py.next.program_processors.runners.roundtrip.no_transforms"
GTIR_EMBEDDED = "gt4py.next.program_processors.runners.roundtrip.gtir"
ROUNDTRIP_WITH_TEMPORARIES = "gt4py.next.program_processors.runners.roundtrip.with_temporaries"
DOUBLE_ROUNDTRIP = "gt4py.next.program_processors.runners.double_roundtrip.backend"


Expand Down Expand Up @@ -185,6 +184,7 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum):
USES_PROGRAM_METRICS = "uses_program_metrics"
USES_SCALAR_IN_DOMAIN_AND_FO = "uses_scalar_in_domain_and_fo"
USES_CONCAT_WHERE = "uses_concat_where"
USES_CONCAT_WHERE_MIXED_LOCAL_DIMS = "uses_concat_where_mixed_local_dims"
EMBEDDED_CONCAT_WHERE_INFINITE_DOMAIN = "embedded_concat_where_infinite_domain"
EMBEDDED_CONCAT_WHERE_NON_CONTIGUOUS_DOMAIN = "embedded_concat_where_non_contiguous_domain"
USES_PROGRAM_WITH_SLICED_OUT_ARGUMENTS = "uses_program_with_sliced_out_arguments"
Expand Down Expand Up @@ -223,9 +223,7 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum):
COMMON_SKIP_TEST_LIST = [
(USES_APPLIED_SHIFTS, XFAIL, UNSUPPORTED_MESSAGE),
(USES_NEGATIVE_MODULO, XFAIL, UNSUPPORTED_MESSAGE),
(USES_REDUCTION_WITH_ONLY_SPARSE_FIELDS, XFAIL, REDUCTION_WITH_ONLY_SPARSE_FIELDS_MESSAGE),
(USES_SPARSE_FIELDS_AS_OUTPUT, XFAIL, UNSUPPORTED_MESSAGE),
(USES_TUPLES_ARGS_WITH_DIFFERENT_BUT_PROMOTABLE_DIMS, XFAIL, UNSUPPORTED_MESSAGE),
]
# Markers to skip because of missing features in the domain inference
DOMAIN_INFERENCE_SKIP_LIST = [
Expand All @@ -239,6 +237,7 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum):
(USES_COMPOSITE_SHIFTS, XFAIL, UNSUPPORTED_MESSAGE),
(USES_LIFT, XFAIL, UNSUPPORTED_MESSAGE),
(USES_REDUCE_WITH_LAMBDA, XFAIL, UNSUPPORTED_MESSAGE),
(USES_REDUCTION_WITH_ONLY_SPARSE_FIELDS, XFAIL, REDUCTION_WITH_ONLY_SPARSE_FIELDS_MESSAGE),
(USES_SPARSE_FIELDS, XFAIL, UNSUPPORTED_MESSAGE),
(USES_TUPLE_ITERATOR, XFAIL, UNSUPPORTED_MESSAGE),
(
Expand All @@ -255,11 +254,6 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum):
)
EMBEDDED_SKIP_LIST = [
(CHECKS_SPECIFIC_ERROR, XFAIL, UNSUPPORTED_MESSAGE),
(
USES_SCAN_WITHOUT_FIELD_ARGS,
XFAIL,
UNSUPPORTED_MESSAGE,
), # we can't extract the field type from scan args
(EMBEDDED_CONCAT_WHERE_INFINITE_DOMAIN, XFAIL, UNSUPPORTED_MESSAGE),
(EMBEDDED_CONCAT_WHERE_NON_CONTIGUOUS_DOMAIN, XFAIL, UNSUPPORTED_MESSAGE),
(
Expand All @@ -268,7 +262,11 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum):
OFFSET_TAG_DIFFERING_FROM_LOCAL_DIM_MESSAGE,
),
]
JAX_EMBEDDED_SKIP_LIST = EMBEDDED_SKIP_LIST + [
#: a scan without field arguments has no buffer to take the array type from, so it allocates with NumPy
NON_NUMPY_EMBEDDED_SKIP_LIST = EMBEDDED_SKIP_LIST + [
(USES_SCAN_WITHOUT_FIELD_ARGS, XFAIL, UNSUPPORTED_MESSAGE),
]
JAX_EMBEDDED_SKIP_LIST = NON_NUMPY_EMBEDDED_SKIP_LIST + [
(USES_PROGRAM_WITH_SLICED_OUT_ARGUMENTS, XFAIL, UNSUPPORTED_MESSAGE),
]
#: under a tracing compiler, scalar arguments are traced unless they are in `static_params`
Expand All @@ -278,19 +276,19 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum):
(USES_SCAN_CARRY_IN_CONTROL_FLOW, XFAIL, UNSUPPORTED_MESSAGE),
]
JAX_JIT_SKIP_LIST = JAX_EMBEDDED_SKIP_LIST + TRACED_SCALARS_SKIP_LIST
TORCH_COMPILE_SKIP_LIST = EMBEDDED_SKIP_LIST + TRACED_SCALARS_SKIP_LIST
TORCH_COMPILE_SKIP_LIST = NON_NUMPY_EMBEDDED_SKIP_LIST + TRACED_SCALARS_SKIP_LIST
# TODO(havogt): inductor builds CPU code with `$CXX`, which is `hipcc` on the ROCm CI and fails
TORCH_COMPILE_CPU_MESSAGE = "'torch.compile' on CPU is skipped for now."
ARRAY_API_STRICT_EMBEDDED_SKIP_LIST = EMBEDDED_SKIP_LIST + [
ARRAY_API_STRICT_EMBEDDED_SKIP_LIST = NON_NUMPY_EMBEDDED_SKIP_LIST + [
(USES_MATH_OUTSIDE_ARRAY_API, XFAIL, "Not in the Array API standard."),
]
ROUNDTRIP_SKIP_LIST = DOMAIN_INFERENCE_SKIP_LIST + [
(USES_PROGRAM_METRICS, XFAIL, UNSUPPORTED_MESSAGE),
(USES_SPARSE_FIELDS_AS_OUTPUT, XFAIL, UNSUPPORTED_MESSAGE),
(USES_TUPLES_ARGS_WITH_DIFFERENT_BUT_PROMOTABLE_DIMS, XFAIL, UNSUPPORTED_MESSAGE),
(USES_CONCAT_WHERE, XFAIL, UNSUPPORTED_MESSAGE),
(USES_CONCAT_WHERE_MIXED_LOCAL_DIMS, XFAIL, UNSUPPORTED_MESSAGE),
]
GTIR_EMBEDDED_SKIP_LIST = ROUNDTRIP_SKIP_LIST + [
(USES_CONCAT_WHERE, XFAIL, UNSUPPORTED_MESSAGE),
# NOTE: not in `ROUNDTRIP_SKIP_LIST`: the roundtrip backend passes this, only the
# lower-level `iterator/embedded.py` execution keys on the local dimension's name.
(
Expand Down Expand Up @@ -321,32 +319,38 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum):
#: (<test_marker>, <skip_definition, <skip_message>)
BACKEND_SKIP_TEST_MATRIX = {
EmbeddedIds.NUMPY_EXECUTION: EMBEDDED_SKIP_LIST,
EmbeddedIds.CUPY_EXECUTION: EMBEDDED_SKIP_LIST,
EmbeddedIds.CUPY_EXECUTION: NON_NUMPY_EMBEDDED_SKIP_LIST,
EmbeddedIds.JAX_NUMPY_EXECUTION: JAX_EMBEDDED_SKIP_LIST,
EmbeddedIds.ARRAY_API_STRICT_EXECUTION: ARRAY_API_STRICT_EMBEDDED_SKIP_LIST,
EmbeddedIds.TORCH_EXECUTION: EMBEDDED_SKIP_LIST,
EmbeddedIds.TORCH_CUDA_EXECUTION: EMBEDDED_SKIP_LIST,
EmbeddedIds.TORCH_EXECUTION: NON_NUMPY_EMBEDDED_SKIP_LIST,
EmbeddedIds.TORCH_CUDA_EXECUTION: NON_NUMPY_EMBEDDED_SKIP_LIST,
OptionalProgramBackendId.DACE_CPU: DACE_SKIP_TEST_LIST,
OptionalProgramBackendId.DACE_GPU: DACE_SKIP_TEST_LIST,
OptionalProgramBackendId.DACE_CPU_NO_OPT: DACE_SKIP_TEST_LIST,
OptionalProgramBackendId.JAX_JIT: JAX_JIT_SKIP_LIST,
OptionalProgramBackendId.TORCH_COMPILE: [(ALL, SKIP, TORCH_COMPILE_CPU_MESSAGE)],
OptionalProgramBackendId.TORCH_COMPILE_CUDA: TORCH_COMPILE_SKIP_LIST,
ProgramBackendId.GTFN_CPU: GTFN_SKIP_TEST_LIST
+ [(USES_SCAN_NESTED, XFAIL, UNSUPPORTED_MESSAGE)],
ProgramBackendId.GTFN_GPU: GTFN_SKIP_TEST_LIST
+ [(USES_SCAN_NESTED, XFAIL, UNSUPPORTED_MESSAGE)],
ProgramFormatterId.GTFN_CPP_FORMATTER: DOMAIN_INFERENCE_SKIP_LIST
+ [
(USES_REDUCTION_WITH_ONLY_SPARSE_FIELDS, XFAIL, REDUCTION_WITH_ONLY_SPARSE_FIELDS_MESSAGE),
],
ProgramBackendId.GTFN_CPU: GTFN_SKIP_TEST_LIST,
ProgramBackendId.GTFN_GPU: GTFN_SKIP_TEST_LIST,
ProgramFormatterId.GTFN_CPP_FORMATTER: DOMAIN_INFERENCE_SKIP_LIST,
ProgramFormatterId.LISP_FORMATTER: DOMAIN_INFERENCE_SKIP_LIST,
ProgramBackendId.ROUNDTRIP: ROUNDTRIP_SKIP_LIST,
ProgramBackendId.DOUBLE_ROUNDTRIP: ROUNDTRIP_SKIP_LIST,
ProgramBackendId.ROUNDTRIP_WITH_TEMPORARIES: ROUNDTRIP_SKIP_LIST
+ [
(ALL, XFAIL, UNSUPPORTED_MESSAGE),
(USES_STRIDED_NEIGHBOR_OFFSET, XFAIL, UNSUPPORTED_MESSAGE),
],
ProgramBackendId.GTIR_EMBEDDED: GTIR_EMBEDDED_SKIP_LIST,
}


def apply_backend_exclusions(request: pytest.FixtureRequest, backend_id: object) -> None:
"""Apply the first entry of `BACKEND_SKIP_TEST_MATRIX` matching the test's markers.

`XFAIL` entries are applied as markers, not raised, so that the test still runs and a
passing test is reported as an unexpected pass (failure under `xfail_strict`).
"""
for marker, skip_mark, msg in BACKEND_SKIP_TEST_MATRIX.get(backend_id, []):
if marker == ALL or request.node.get_closest_marker(marker):
reason = msg.format(marker=marker, backend=backend_id)
if skip_mark is XFAIL:
request.applymarker(pytest.mark.xfail(reason=reason, strict=True))
else:
skip_mark(reason)
return
6 changes: 1 addition & 5 deletions tests/next_tests/integration_tests/cases_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ def exec_alloc_descriptor(request):
backend_id = request.param
backend = backend_id.load()

for marker, skip_mark, msg in next_tests.definitions.BACKEND_SKIP_TEST_MATRIX.get(
backend_id, []
):
if marker == next_tests.definitions.ALL or request.node.get_closest_marker(marker):
skip_mark(msg.format(marker=marker, backend=backend_id))
next_tests.definitions.apply_backend_exclusions(request, 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 @@ -29,10 +29,13 @@
mesh_descriptor,
)

pytestmark = pytest.mark.uses_concat_where
_DYNAMIC_DOMAINS = pytest.param(False, marks=pytest.mark.uses_concat_where, id="dynamic_domains")
_STATIC_DOMAINS = pytest.param(True, marks=pytest.mark.uses_concat_where, id="static_domains")
# With static domains the empty branch is pruned before lowering: no `concat_where` reaches the backend.
_STATIC_DOMAINS_PRUNED = pytest.param(True, id="static_domains")


@pytest.fixture(params=[False, True], ids=["dynamic_domains", "static_domains"])
@pytest.fixture(params=[_DYNAMIC_DOMAINS, _STATIC_DOMAINS])
def static_domains(request) -> bool:
"""Fixture to select compilation with dynamic or statically known domain bounds."""
return request.param
Expand Down Expand Up @@ -208,6 +211,7 @@ def testee(interior: cases.IJKField, boundary: cases.IJField) -> cases.IJKField:
)


@pytest.mark.parametrize("static_domains", [_DYNAMIC_DOMAINS, _STATIC_DOMAINS_PRUNED])
def test_boundary_single_layer_2d_bc_on_empty_branch(cartesian_case, static_domains: bool):
@gtx.field_operator(static_domains=static_domains)
def testee(interior: cases.IJKField, boundary: cases.IJField) -> cases.IJKField:
Expand Down Expand Up @@ -495,6 +499,7 @@ def testee(


@pytest.mark.uses_unstructured_shift
@pytest.mark.uses_concat_where_mixed_local_dims
def test_with_local_and_nonlocal_field(unstructured_case, static_domains: bool):
@gtx.field_operator(static_domains=static_domains)
def testee(a: cases.EField, b: cases.VField) -> cases.VField:
Expand Down Expand Up @@ -552,6 +557,7 @@ def testee(
@pytest.mark.uses_tuple_returns
@pytest.mark.uses_unstructured_shift
@pytest.mark.embedded_concat_where_infinite_domain
@pytest.mark.uses_concat_where_mixed_local_dims
def test_with_local_field_and_scalar(unstructured_case, static_domains: bool):
@gtx.field_operator(static_domains=static_domains)
def testee(a: cases.EField) -> tuple[cases.VField, cases.VField]:
Expand Down Expand Up @@ -585,6 +591,7 @@ def testee(a: cases.EField) -> tuple[cases.VField, cases.VField]:
@pytest.mark.uses_tuple_returns
@pytest.mark.uses_unstructured_shift
@pytest.mark.embedded_concat_where_infinite_domain
@pytest.mark.uses_concat_where_mixed_local_dims
def test_with_tuples_of_local_and_nonlocal_leaves(unstructured_case, static_domains: bool):
@gtx.field_operator(static_domains=static_domains)
def testee(
Expand Down Expand Up @@ -662,6 +669,7 @@ def ref(interior0, boundary0, interior1, boundary1):
cases.verify_with_default_data(cartesian_case, testee, ref)


@pytest.mark.parametrize("static_domains", [_DYNAMIC_DOMAINS, _STATIC_DOMAINS_PRUNED])
def test_concat_where_field_broadcast_on_empty_branch(cartesian_case, static_domains: bool):
"""
A field branch with fewer dimensions than the expression is implicitly broadcast.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ def testee(a: cases.IField, out: cases.IField):
[
(metrics.DISABLED, ()),
(metrics.MINIMAL, ("total",)),
(metrics.PERFORMANCE, ("total", "compute")),
(metrics.ALL, ("compute", "total")),
pytest.param(
metrics.PERFORMANCE, ("total", "compute"), marks=pytest.mark.uses_program_metrics
),
pytest.param(metrics.ALL, ("compute", "total"), marks=pytest.mark.uses_program_metrics),
],
)
@pytest.mark.uses_program_metrics
def test_collect_metrics(cartesian_case, metrics_level, expected_names):
if cases.runs_embedded(cartesian_case):
pytest.skip("Precompiled program with embedded execution is not possible.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ def testee(size: gtx.IndexType, out: gtx.Field[[IDim], gtx.IndexType]):
def test_single_value_field(cartesian_case):
@gtx.field_operator
def testee_fo(a: cases.IKField) -> cases.IKField:
return a
return a + 1

@gtx.program
def testee_prog(a: cases.IKField):
testee_fo(a, out=a[1:2, 3:4])

a = cases.allocate(cartesian_case, testee_prog, "a")()
ref = a[1, 3]
ref = a.asnumpy()[1:2, 3:4] + 1

cases.verify(cartesian_case, testee_prog, a, inout=a[1, 3], ref=ref)
cases.verify(cartesian_case, testee_prog, a, inout=a[1:2, 3:4], ref=ref)


@pytest.mark.uses_scalar_in_domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ def slice_sparse_stencil(sparse):
return list_get(1, deref(sparse))


@pytest.mark.uses_sparse_fields
def test_slice_sparse(program_processor):
program_processor, validate = program_processor
inp = gtx.as_field([Vertex, V2VDim], v2v_arr)
Expand Down
7 changes: 1 addition & 6 deletions tests/next_tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ def _program_processor(request) -> tuple[ProgramProcessor, bool]:

processor = processor_id.load()

for marker, skip_mark, msg in next_tests.definitions.BACKEND_SKIP_TEST_MATRIX.get(
processor_id, []
):
if marker == next_tests.definitions.ALL or request.node.get_closest_marker(marker):
skip_mark(msg.format(marker=marker, backend=processor_id))
next_tests.definitions.apply_backend_exclusions(request, processor_id)

return processor, is_backend

Expand All @@ -56,7 +52,6 @@ def _program_processor(request) -> tuple[ProgramProcessor, bool]:
params=[
(None, True),
(next_tests.definitions.ProgramBackendId.ROUNDTRIP, True),
(next_tests.definitions.ProgramBackendId.ROUNDTRIP_WITH_TEMPORARIES, True),
(next_tests.definitions.ProgramBackendId.GTIR_EMBEDDED, True),
(next_tests.definitions.ProgramBackendId.DOUBLE_ROUNDTRIP, True),
(next_tests.definitions.ProgramBackendId.GTFN_CPU, True),
Expand Down