Skip to content

Instantly share code, notes, and snippets.

View tehrengruber's full-sized avatar

Till Ehrengruber tehrengruber

  • ETH Zuerich
  • Zürich
View GitHub Profile
@tehrengruber
tehrengruber / stencil.py
Created April 4, 2023 13:50
Stencil decorator parallel compilation
# -*- coding: utf-8 -*-
from __future__ import annotations
from concurrent.futures import ThreadPoolExecutor
import multiprocessing
import threading
from typing import TYPE_CHECKING
import gt4py as gt
from gt4py.cartesian import gtscript, definitions
@tehrengruber
tehrengruber / upstream_advection_stencil_ir.txt
Created November 2, 2022 16:17
Upstream Advection Stencil IR
__field_operator_fvm_advect(
__sym_1,
__sym_2,
__sym_3,
__sym_4,
__sym_5,
__sym_6,
__sym_7,
__sym_8,
__sym_9,
@tehrengruber
tehrengruber / iterator_example.py
Last active November 2, 2022 16:20
Iterator Example
from __future__ import annotations
import numpy as np
from functional.iterator.embedded import MDIterator, np_as_located_field, lift, shift, deref, NeighborTableOffsetProvider
from fvm_advection_sphere.common import *
# v-e-v-e-v
# c c
num_vertices = 10
num_edges = num_vertices-1
num_cells = num_vertices-1
@tehrengruber
tehrengruber / .py
Created August 2, 2022 15:35
Strides check
import itertools
import ctypes
import numpy as np
import gt4py as gt
from gt4py.backend import REGISTRY
backend = "gt:cpu_kfirst" # (0, 1, 2)
#backend = "gt:cpu_ifirst" # (2, 0, 1)
@tehrengruber
tehrengruber / playground11_mr.py
Created July 13, 2021 15:52
playground11_mr.py
import ast
from copy import copy
import types
from types import LambdaType
from typing import List, Callable, Tuple, Any, Union, Literal
import inspect
import textwrap
import tempfile
import eve.datamodels as datamodels
import typing_inspect
@tehrengruber
tehrengruber / playground11.py
Created July 9, 2021 21:11
Field/Local execution model
import ast
from copy import copy
import types
from types import LambdaType
from typing import List, Callable, Tuple, Any, Union, Literal
import inspect
import textwrap
import tempfile
import eve.datamodels as datamodels
import typing_inspect
@tehrengruber
tehrengruber / benchmark.md
Last active June 24, 2021 16:01
Benchmark

Benchmarks

Laptop:

CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (6 cores)

Memory: 16 GB DDR4 2667 MT/s

GPU: NVIDIA GeForce GTX 1650 Max-Q (4 GB, GDDR5)

import numpy as np
import cupy as cp
import gt4py as gt
test = gt.storage.zeros(backend="gtcuda", dtype=np.float32,
shape=(14, 15, 16), default_origin=(0, 0, 0))
test[0:8, 0:8, 0:8] = 1
test.synchronize()
slic = test[4:12, 4:12, 4:12]
@tehrengruber
tehrengruber / bla.py
Last active May 28, 2021 13:21
bla.py
def laplacian(grid: Grid, f: Field[I, J, K, Matrix[3, 3, dtype]]):
def stencil((i, j, k), m):
return l2_norm(m @ [1, 2, 3])
#def stencil(i, j, k, val):
# if (i, j, k) in grid[(I, J, K), "interior"]:
# return -4*f[i, j, k]+f[i-1, j, k]+f[i+1, j, k]+f[i, j-1, k]+f[i, j+1, k]
# else:
...
#return Field(f.domain, stencil)
@stencil
def flux_x(phi):
return flux(phi[I - 1], phi)
@stencil
def flux_y(phi):
return flux(phi[J - 1], phi)
@stencil
def step(phi, fx, fy, dx, dy, dt):