-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_erwan.py
45 lines (29 loc) · 1.13 KB
/
example_erwan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from gt4py.cartesian import gtscript
import numpy as np
backend = "gt:cpu_ifirst"
#backend = "numpy"
#backend = "dace:gpu"
@gtscript.stencil(backend=backend, rebuild=True)
def example_1(
foo: gtscript.Field[np.float64],
inn: gtscript.Field[np.float64],
bar: gtscript.Field[np.float64]):
with computation(PARALLEL), interval(...):
foo[0, 0, 0] = inn[1, 0, 0] - inn[0, 0, 0]
@gtscript.stencil(backend=backend, rebuild=True)
def example_2(
bar: gtscript.Field[np.float64],
foo: gtscript.Field[np.float64]
):
with computation(PARALLEL), interval(...):
bar[0, 0, 0] = foo[1, 0, 0] - foo[0, 0, 0]
if __name__ == "__main__":
from gt4py.storage import ones, zeros
inn = ones((12, 12, 1), dtype=np.float64, backend=backend)
inn[...] = np.random.rand(12, 12, 1)
foo = ones((12, 12, 1), dtype=np.float64, backend=backend)
foo[...] = np.random.rand(12, 12, 1)
bar = ones((12, 12, 1), dtype=np.float64, backend=backend)
bar[...] = np.random.rand(12, 12, 1)
example_1(foo, inn, bar)
example_2(bar, foo)