From 8e968727a9c2c5a1b3be858b1102e70651f34168 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 26 Oct 2019 12:40:35 +0200 Subject: Generalize floating point precision argument --- boltzgen.py | 2 +- boltzgen/kernel/generator.py | 5 ++++- boltzgen/kernel/template/basic.cpp.mako | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/boltzgen.py b/boltzgen.py index e5a8588..b487b07 100644 --- 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('--layout', dest = 'layout', help = 'Memory layout ("AOS" or "SOA")', required = True) -argparser.add_argument('--precision', dest = 'precision', help = 'Floating precision ("float" or "double")', required = True) +argparser.add_argument('--precision', dest = 'precision', help = 'Floating precision ("single" or "double")', required = True) args = argparser.parse_args() diff --git a/boltzgen/kernel/generator.py b/boltzgen/kernel/generator.py index e897325..d91ddd5 100644 --- a/boltzgen/kernel/generator.py +++ b/boltzgen/kernel/generator.py @@ -35,7 +35,10 @@ class Generator: collision_subexpr = self.collision[0], collision_assignment = self.collision[1], - float_type = precision, + float_type = { + 'single': 'float', + 'double': 'double' + }.get(precision), boundary_src = Template(self.boundary).render( descriptor = self.descriptor, diff --git a/boltzgen/kernel/template/basic.cpp.mako b/boltzgen/kernel/template/basic.cpp.mako index 529c1de..1036c8f 100644 --- a/boltzgen/kernel/template/basic.cpp.mako +++ b/boltzgen/kernel/template/basic.cpp.mako @@ -131,7 +131,7 @@ void test(std::size_t nStep) std::cout << "MLUPS: " << nStep*${geometry.volume}/(1e6*duration.count()) << std::endl; // calculate average rho as a basic quality check - double rho_sum = 0.0; + ${float_type} rho_sum = 0.0; for (std::size_t i = 0; i < ${geometry.volume*descriptor.q}; ++i) { rho_sum += f_next[i]; -- cgit v1.2.3