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 / void_cb.cpp
Created March 22, 2017 20:09
Optional callback in C++
/**
* Functor behaving like an unset function pointer (nullptr) with
* arbitrary number of arguments.
*
* Usage:
* ```
* #include "Utils/void_cb.hpp"
*
* template <typename CB=void_cb>
* void f(CB callback=nullptr) {
@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 / 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 / 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 / .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)
julia> c=b.args[2]^C
julia> c = Condition()
@Condition(Any[])
julia> @as^C
julia> @async begin
wait(c)
println("im notifyed")
@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]