From 804e15d65e32479a476ef212238c25ada4865e3f Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 18 Jun 2019 14:47:13 +0200 Subject: Expand square expressions Yields another ~5-10 MLUPS in the simple D2Q9 example. Now averaging at ~840 MLUPS for D2Q9 and ~ 400 MLUPS for D3Q19 on a K2200. --- symbolic/optimizations.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 symbolic/optimizations.py (limited to 'symbolic/optimizations.py') diff --git a/symbolic/optimizations.py b/symbolic/optimizations.py new file mode 100644 index 0000000..93dad09 --- /dev/null +++ b/symbolic/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