From 82a44e0d64afb8818ea98d68dc08108885d503c2 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 21 Oct 2019 18:42:24 +0200 Subject: Pull in basics from symlbm_playground It's time to extract the generator-part of my GPU LBM playground and turn it into a nice reusable library. The goal is to produce a framework that can be used to generate collision and streaming programs from symbolic descriptions. i.e. it should be possible to select a LB model, the desired boundary conditions as well as a data structure / streaming model and use this information to automatically generate matching OpenCL / CUDA / C++ programs. --- boltzgen/utility/ndindex.py | 14 ++++++++++++++ boltzgen/utility/optimizations.py | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 boltzgen/utility/ndindex.py create mode 100644 boltzgen/utility/optimizations.py (limited to 'boltzgen/utility') diff --git a/boltzgen/utility/ndindex.py b/boltzgen/utility/ndindex.py new file mode 100644 index 0000000..0c5ed9b --- /dev/null +++ b/boltzgen/utility/ndindex.py @@ -0,0 +1,14 @@ +import numpy +from numpy.lib.stride_tricks import as_strided +import numpy.core.numeric as _nx + +class ndindex(numpy.ndindex): + pass + + def __init__(self, *shape, order): + if len(shape) == 1 and isinstance(shape[0], tuple): + shape = shape[0] + x = as_strided(_nx.zeros(1), shape=shape, + strides=_nx.zeros_like(shape)) + self._it = _nx.nditer(x, flags=['multi_index', 'zerosize_ok'], + order=order) diff --git a/boltzgen/utility/optimizations.py b/boltzgen/utility/optimizations.py new file mode 100644 index 0000000..93dad09 --- /dev/null +++ b/boltzgen/utility/optimizations.py @@ -0,0 +1,10 @@ +from sympy import * + +from sympy.codegen.rewriting import ReplaceOptim + +expand_square = ReplaceOptim( + lambda e: e.is_Pow and e.exp.is_integer and e.exp == 2, + lambda p: UnevaluatedExpr(Mul(p.base, p.base, evaluate = False)) +) + +custom = [ (expand_square, expand_square) ] + cse_main.basic_optimizations -- cgit v1.2.3