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

don't merge: proper memory layout for connectivities #578

Draft
wants to merge 1 commit into
base: main
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
2 changes: 1 addition & 1 deletion model/common/src/icon4py/model/common/grid/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _get_offset_provider(self, dim, from_dim, to_dim):
dim, self.connectivities[dim].dtype
)
return gtx.NeighborTableOffsetProvider(
xp.asarray(self.connectivities[dim]),
gtx.as_field([from_dim, gtx.Dimension("neigh", kind=gtx.DimensionKind.LOCAL)], xp.asarray(self.connectivities[dim])).ndarray,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a hack to get the memory layout that the backend likes (horizontal with stride 1 for gpu). The proper fix should probably use gtx.as_connectivity() somewhere. GT4Py currently doesn't really help to get this clean...

from_dim,
to_dim,
self.size[dim],
Expand Down
2 changes: 2 additions & 0 deletions model/common/src/icon4py/model/common/grid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from gt4py.next import Dimension, NeighborTableOffsetProvider

from icon4py.model.common.settings import xp
from gt4py.next import constructors


def neighbortable_offset_provider_for_1d_sparse_fields(
Expand All @@ -18,6 +19,7 @@ def neighbortable_offset_provider_for_1d_sparse_fields(
has_skip_values: bool,
):
table = xp.arange(old_shape[0] * old_shape[1], dtype=gtx.int32).reshape(old_shape)
table = gtx.as_field([origin_axis, gtx.Dimension("neigh", kind=gtx.DimensionKind.LOCAL)], table).ndarray
assert (
table.dtype == gtx.int32
), 'Neighbor table\'s ("{}" to "{}") data type for 1d sparse fields must be gtx.int32. Instead it\'s "{}"'.format(
Expand Down
Loading