Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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: 2 additions & 0 deletions ndsl/dsl/stencil_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections.abc import Callable, Hashable, Iterable, Sequence
from typing import Any, Self

from gt4py.cartesian.backend import from_name as check_backend_existence
from gt4py.cartesian.gtc.passes.oir_pipeline import DefaultPipeline, OirPipeline

from ndsl.comm.communicator import Communicator
Expand Down Expand Up @@ -43,6 +44,7 @@ def __init__(
if "gpu" not in backend and device_sync is True:
raise RuntimeError("Device sync is true on a CPU based backend")
# GT4Py backend args
check_backend_existence(backend)
self.backend = backend
self.rebuild = rebuild
self.validate_args = validate_args
Expand Down
32 changes: 23 additions & 9 deletions tests/dsl/test_stencil_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,24 +313,38 @@ def test_frozen_field_after_parameter() -> None:
)


@pytest.mark.parametrize("backend", ("numpy", "gt:gpu"))
def test_backend_options(
backend: str,
rebuild: bool = True,
validate_args: bool = True,
) -> None:
backend = "numpy"
expected_options = {
"backend": "numpy",
"rebuild": True,
"format_source": False,
"name": "tests.dsl.test_stencil_wrapper.copy_stencil",
"numpy": {
"backend": "numpy",
"rebuild": True,
"format_source": False,
"name": "tests.dsl.test_stencil_wrapper.copy_stencil",
},
"gt:gpu": {
"backend": "gt:gpu",
"rebuild": True,
"device_sync": False,
"format_source": False,
"name": "tests.dsl.test_stencil_wrapper.copy_stencil",
},
}

actual = get_stencil_config(
backend=backend,
rebuild=rebuild,
validate_args=validate_args,
backend=backend, rebuild=rebuild, validate_args=validate_args
).stencil_kwargs(func=copy_stencil)
assert actual == expected_options
expected = expected_options[backend]
assert actual == expected


def test_illegal_backend_options():
with pytest.raises(ValueError):
get_stencil_config(backend="illegal")


def get_mock_quantity():
Expand Down
Loading