Skip to content

[next] gtfn: fails to compile negative shifts on cartesian unit-stride dimension with static strides #3071

In review
GridTools/gridtools
#1833

Description

@edopao

Description

#3063 derives static unit strides from the backend allocator layout and, unlike main, applies them to programs on Cartesian grids too: with the default allocators, the first horizontal dimension (e.g. IDim in (IDim, JDim, KDim)) gets a static stride of 1 in the GTFN bindings.

With that change and GT4PY_USE_BACKEND_ALLOCATOR_LAYOUT=1, the GTFN backend fails to compile Cartesian programs that apply a negative shift on the unit-stride dimension (e.g. IDim - 1). The compiler reports no matching function for call to 'shift' in gridtools/fn/cartesian.hpp, with a narrowing error on a non-type template argument.

main is not affected: there, the static unit stride is only applied to unstructured programs, which do not shift by negative offsets on the horizontal dimension.

Cause

GridTools' nanobind_adapter.hpp represents static strides as integral_constant<std::size_t, ...>, so the offset computation for a negative shift is unsigned and does not fit int_t.

Present in gridtools-cpp 2.3.9 and on GridTools master.

Reproduce

On the #3063 branch, CPU:

GT4PY_USE_BACKEND_ALLOCATOR_LAYOUT=1 uv run pytest -k gtfn \
  tests/next_tests/integration_tests/multi_feature_tests/ffront_tests/test_laplacian.py \
  tests/next_tests/integration_tests/feature_tests/ffront_tests/test_staggered.py

Failing tests:

  • test_laplacian.py: test_ffront_lap, test_ffront_skewedlap, test_ffront_laplap
  • test_staggered.py: test_cartesian_half_shift_minus, test_cartesian_half_shift_back

Proposed fix

Represent static strides with a signed type (e.g. std::ptrdiff_t) in GridTools' nanobind_adapter.hpp, then bump gridtools-cpp in gt4py. Not yet tested.

Until then, GT4PY_USE_BACKEND_ALLOCATOR_LAYOUT stays off by default; it can be enabled by default once the fix is available.

Activity

  1. changed the title [-]GTFN fails to compile negative shifts on cartesian unit-stride dimension with static strides[/-] [+]next[gtfn]: fails to compile negative shifts on cartesian unit-stride dimension with static strides[/+] on Dec 2, 2026
  2. changed the title [-]next[gtfn]: fails to compile negative shifts on cartesian unit-stride dimension with static strides[/-] [+][next] gtfn: fails to compile negative shifts on cartesian unit-stride dimension with static strides[/+] on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions