From a0438d434a8dde45e6fdab38d44181f0cd0cb2c6 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 29 Oct 2019 19:30:50 +0100 Subject: Rename target module to memory --- boltzgen.py | 4 ++-- boltzgen/kernel/__init__.py | 2 +- boltzgen/kernel/generator.py | 12 ++++++------ boltzgen/kernel/memory/__init__.py | 3 +++ boltzgen/kernel/memory/index.py | 18 ++++++++++++++++++ boltzgen/kernel/memory/layout/AOS.py | 14 ++++++++++++++ boltzgen/kernel/memory/layout/SOA.py | 14 ++++++++++++++ boltzgen/kernel/memory/layout/__init__.py | 2 ++ boltzgen/kernel/memory/precision.py | 16 ++++++++++++++++ boltzgen/kernel/target/__init__.py | 3 --- boltzgen/kernel/target/index.py | 18 ------------------ boltzgen/kernel/target/layout/AOS.py | 14 -------------- boltzgen/kernel/target/layout/SOA.py | 14 -------------- boltzgen/kernel/target/layout/__init__.py | 2 -- boltzgen/kernel/target/precision.py | 16 ---------------- 15 files changed, 76 insertions(+), 76 deletions(-) create mode 100644 boltzgen/kernel/memory/__init__.py create mode 100644 boltzgen/kernel/memory/index.py create mode 100644 boltzgen/kernel/memory/layout/AOS.py create mode 100644 boltzgen/kernel/memory/layout/SOA.py create mode 100644 boltzgen/kernel/memory/layout/__init__.py create mode 100644 boltzgen/kernel/memory/precision.py delete mode 100644 boltzgen/kernel/target/__init__.py delete mode 100644 boltzgen/kernel/target/index.py delete mode 100644 boltzgen/kernel/target/layout/AOS.py delete mode 100644 boltzgen/kernel/target/layout/SOA.py delete mode 100644 boltzgen/kernel/target/layout/__init__.py delete mode 100644 boltzgen/kernel/target/precision.py diff --git a/boltzgen.py b/boltzgen.py index 1c8e931..b4a9fe8 100755 --- a/boltzgen.py +++ b/boltzgen.py @@ -6,7 +6,7 @@ from boltzgen import * argparser = argparse.ArgumentParser( description = 'Generate LBM kernels in various languages using a symbolic description.') -argparser.add_argument('language', help = 'Target language (currently either "cl" or "cpp")') +argparser.add_argument('target', help = 'Target language (currently either "cl" or "cpp")') argparser.add_argument('--lattice', required = True, help = 'Lattice type (D2Q9, D3Q7, D3Q19, D3Q27)') argparser.add_argument('--layout', required = True, help = 'Memory layout ("AOS" or "SOA")') @@ -31,7 +31,7 @@ generator = Generator( descriptor = lattice, moments = lbm.moments(optimize = not args.disable_cse), collision = lbm.bgk(f_eq = lbm.equilibrium(), tau = float(args.tau), optimize = not args.disable_cse), - language = args.language, + target = args.target, precision = args.precision, index = args.index, layout = args.layout) diff --git a/boltzgen/kernel/__init__.py b/boltzgen/kernel/__init__.py index 92d1853..78f6ecb 100644 --- a/boltzgen/kernel/__init__.py +++ b/boltzgen/kernel/__init__.py @@ -1,2 +1,2 @@ from . import generator -from . import target +from . import memory diff --git a/boltzgen/kernel/generator.py b/boltzgen/kernel/generator.py index b2a632c..30e2c04 100644 --- a/boltzgen/kernel/generator.py +++ b/boltzgen/kernel/generator.py @@ -3,23 +3,23 @@ import sympy from mako.template import Template from pathlib import Path -from . import target +from . import memory class Generator: - def __init__(self, descriptor, moments, collision, language, precision, index, layout): + def __init__(self, descriptor, moments, collision, target, precision, index, layout): self.descriptor = descriptor self.moments = moments self.collision = collision - self.target = language - self.float_type = eval("target.precision.%s" % language).get_float_type(precision) + self.target = target + self.float_type = eval("memory.precision.%s" % target).get_float_type(precision) try: - self.index_impl = eval("target.index.%s" % index) + self.index_impl = eval("memory.index.%s" % index) except AttributeError: raise Exception("There is no cell indexing scheme '%s'" % index) from None try: - self.layout_impl = eval("target.layout.%s" % layout) + self.layout_impl = eval("memory.layout.%s" % layout) except AttributeError: raise Exception("There is no layout '%s'" % layout) from None diff --git a/boltzgen/kernel/memory/__init__.py b/boltzgen/kernel/memory/__init__.py new file mode 100644 index 0000000..5927d1b --- /dev/null +++ b/boltzgen/kernel/memory/__init__.py @@ -0,0 +1,3 @@ +from . import layout +from . import precision +from . import index diff --git a/boltzgen/kernel/memory/index.py b/boltzgen/kernel/memory/index.py new file mode 100644 index 0000000..e89e9ee --- /dev/null +++ b/boltzgen/kernel/memory/index.py @@ -0,0 +1,18 @@ +class CellIndex: + def __init__(self, geometry): + self.geometry = geometry + + def neighbor(self, c_i): + return self.gid(*[ c for _, c in enumerate(c_i) ]) + +class XYZ(CellIndex): + pass + + def gid(self, x, y, z=0): + return x*self.geometry.size_y*self.geometry.size_z + y*self.geometry.size_z + z + +class ZYX(CellIndex): + pass + + def gid(self, x, y, z=0): + return z*self.geometry.size_x*self.geometry.size_y + y*self.geometry.size_x + x diff --git a/boltzgen/kernel/memory/layout/AOS.py b/boltzgen/kernel/memory/layout/AOS.py new file mode 100644 index 0000000..88e5377 --- /dev/null +++ b/boltzgen/kernel/memory/layout/AOS.py @@ -0,0 +1,14 @@ +class AOS: + def __init__(self, descriptor, index, geometry): + self.descriptor = descriptor + self.index = index(geometry) + self.geometry = geometry + + def cell_preshift(self, gid): + return "(%s)*%d" % (gid, self.descriptor.q) + + def pop_offset(self, i): + return i + + def neighbor_offset(self, c_i): + return self.descriptor.q * self.index.neighbor(c_i) diff --git a/boltzgen/kernel/memory/layout/SOA.py b/boltzgen/kernel/memory/layout/SOA.py new file mode 100644 index 0000000..05e9e84 --- /dev/null +++ b/boltzgen/kernel/memory/layout/SOA.py @@ -0,0 +1,14 @@ +class SOA: + def __init__(self, descriptor, index, geometry): + self.descriptor = descriptor + self.index = index(geometry) + self.geometry = geometry + + def cell_preshift(self, gid): + return gid + + def pop_offset(self, i): + return i * self.geometry.volume + + def neighbor_offset(self, c_i): + return self.index.neighbor(c_i) diff --git a/boltzgen/kernel/memory/layout/__init__.py b/boltzgen/kernel/memory/layout/__init__.py new file mode 100644 index 0000000..731fbe8 --- /dev/null +++ b/boltzgen/kernel/memory/layout/__init__.py @@ -0,0 +1,2 @@ +from .AOS import AOS +from .SOA import SOA diff --git a/boltzgen/kernel/memory/precision.py b/boltzgen/kernel/memory/precision.py new file mode 100644 index 0000000..d22e922 --- /dev/null +++ b/boltzgen/kernel/memory/precision.py @@ -0,0 +1,16 @@ +class common: + @classmethod + def get_float_type(self, precision): + if precision not in ['single', 'double']: + raise Exception("Precision must be either 'single' or 'double'") + + return { + 'single': 'float', + 'double': 'double' + }.get(precision) + +class cpp(common): + pass + +class cl(common): + pass diff --git a/boltzgen/kernel/target/__init__.py b/boltzgen/kernel/target/__init__.py deleted file mode 100644 index 5927d1b..0000000 --- a/boltzgen/kernel/target/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from . import layout -from . import precision -from . import index diff --git a/boltzgen/kernel/target/index.py b/boltzgen/kernel/target/index.py deleted file mode 100644 index e89e9ee..0000000 --- a/boltzgen/kernel/target/index.py +++ /dev/null @@ -1,18 +0,0 @@ -class CellIndex: - def __init__(self, geometry): - self.geometry = geometry - - def neighbor(self, c_i): - return self.gid(*[ c for _, c in enumerate(c_i) ]) - -class XYZ(CellIndex): - pass - - def gid(self, x, y, z=0): - return x*self.geometry.size_y*self.geometry.size_z + y*self.geometry.size_z + z - -class ZYX(CellIndex): - pass - - def gid(self, x, y, z=0): - return z*self.geometry.size_x*self.geometry.size_y + y*self.geometry.size_x + x diff --git a/boltzgen/kernel/target/layout/AOS.py b/boltzgen/kernel/target/layout/AOS.py deleted file mode 100644 index 88e5377..0000000 --- a/boltzgen/kernel/target/layout/AOS.py +++ /dev/null @@ -1,14 +0,0 @@ -class AOS: - def __init__(self, descriptor, index, geometry): - self.descriptor = descriptor - self.index = index(geometry) - self.geometry = geometry - - def cell_preshift(self, gid): - return "(%s)*%d" % (gid, self.descriptor.q) - - def pop_offset(self, i): - return i - - def neighbor_offset(self, c_i): - return self.descriptor.q * self.index.neighbor(c_i) diff --git a/boltzgen/kernel/target/layout/SOA.py b/boltzgen/kernel/target/layout/SOA.py deleted file mode 100644 index 05e9e84..0000000 --- a/boltzgen/kernel/target/layout/SOA.py +++ /dev/null @@ -1,14 +0,0 @@ -class SOA: - def __init__(self, descriptor, index, geometry): - self.descriptor = descriptor - self.index = index(geometry) - self.geometry = geometry - - def cell_preshift(self, gid): - return gid - - def pop_offset(self, i): - return i * self.geometry.volume - - def neighbor_offset(self, c_i): - return self.index.neighbor(c_i) diff --git a/boltzgen/kernel/target/layout/__init__.py b/boltzgen/kernel/target/layout/__init__.py deleted file mode 100644 index 731fbe8..0000000 --- a/boltzgen/kernel/target/layout/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .AOS import AOS -from .SOA import SOA diff --git a/boltzgen/kernel/target/precision.py b/boltzgen/kernel/target/precision.py deleted file mode 100644 index d22e922..0000000 --- a/boltzgen/kernel/target/precision.py +++ /dev/null @@ -1,16 +0,0 @@ -class common: - @classmethod - def get_float_type(self, precision): - if precision not in ['single', 'double']: - raise Exception("Precision must be either 'single' or 'double'") - - return { - 'single': 'float', - 'double': 'double' - }.get(precision) - -class cpp(common): - pass - -class cl(common): - pass -- cgit v1.2.3