Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D Stencil Indexing Method #54

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
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
19 changes: 19 additions & 0 deletions ndsl/dsl/stencil.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,25 @@ def get_origin_domain(
domain[i] += 2 * n
return tuple(origin), tuple(domain)

def get_2d_compute_origin_domain(
self,
klevel: int = 0,
) -> Tuple[Tuple[int, ...], Tuple[int, ...]]:
"""
Get the origin and domain for a computation that occurs on the lowest klevel over a certain grid
configuration (given by dims) and a certain number of halo points.

Args:
klevel: the vertical level of the domain, defaults to zero

Returns:
origin: origin of the computation
domain: shape of the computation
"""
origin = (self.isc, self.jsc, klevel)
domain = (self.iec + 1 - self.isc, self.jec + 1 - self.jsc, 1)
return (origin, domain)

def _origin_from_dims(self, dims: Iterable[str]) -> List[int]:
return_origin = []
for dim in dims:
Expand Down
34 changes: 34 additions & 0 deletions tests/dsl/test_stencil_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,40 @@ def test_stencil_factory_numpy_comparison_from_origin_domain(enabled: bool):
assert isinstance(stencil, FrozenStencil)


@pytest.mark.parametrize("enabled", [True, False])
def test_stencil_factory_numpy_comparison_from_origin_domain_2d(enabled: bool):
backend = "numpy"
dace_config = DaceConfig(communicator=None, backend=backend)
config = StencilConfig(
compilation_config=CompilationConfig(
backend=backend,
rebuild=False,
validate_args=False,
format_source=False,
device_sync=False,
),
compare_to_numpy=enabled,
dace_config=dace_config,
)
indexing = GridIndexing(
domain=(12, 12, 79),
n_halo=3,
south_edge=True,
north_edge=True,
west_edge=True,
east_edge=True,
)
origin, domain = indexing.get_2d_compute_origin_domain(klevel=1)
factory = StencilFactory(config=config, grid_indexing=indexing)
stencil = factory.from_origin_domain(
func=copy_stencil, origin=origin, domain=domain
)
if enabled:
assert isinstance(stencil, CompareToNumpyStencil)
else:
assert isinstance(stencil, FrozenStencil)


def test_stencil_factory_numpy_comparison_runs_without_exceptions():
backend = "numpy"
dace_config = DaceConfig(communicator=None, backend=backend)
Expand Down
Loading