Closed
Description
The following code does not validate using the gtx86
and gtmc
backends (and probably gtcuda
):
import numpy as np
import gt4py
from gt4py.gtscript import stencil, computation, BACKWARD, Field
def foo(out: Field[float]):
with computation(BACKWARD), interval(...):
tmp = 1.0
with computation(BACKWARD):
with interval(-1, None):
out = tmp + tmp[0, 0, -1]
with interval(0, -1):
out = out[0, 0, 1]
def validate_with_backend(backend):
data = gt4py.storage.zeros(backend=backend,
default_origin=(0, 0, 0),
shape=(1, 1, 10),
dtype=float)
stencil(backend=backend, definition=foo)(data)
result = 'validates' if np.allclose(np.asarray(data), 2) else 'fails'
print(f'{result} with backend {backend}')
validate_with_backend('debug')
validate_with_backend('numpy')
validate_with_backend('gtx86')
validate_with_backend('gtmc')
In the GT backends, the first and second computation are merged into a single backward loop, introducing a read before write on tmp[0, 0, -1]
in the second computation.