diff --git a/src/walberla/codegen/build_config.py b/src/walberla/codegen/build_config.py index c47539d357be23d5c922ebd728e45061282a8eaf..8a0fbea1a2dc328e9c9bf178bdfaf03b74915cf3 100644 --- a/src/walberla/codegen/build_config.py +++ b/src/walberla/codegen/build_config.py @@ -2,7 +2,7 @@ from __future__ import annotations from dataclasses import dataclass -from pystencils import CreateKernelConfig +from pystencils import CreateKernelConfig, Target from pystencils.types.quick import Fp from pystencils.jit import no_jit @@ -66,9 +66,22 @@ class WalberlaBuildConfig: ) def get_pystencils_config(self) -> CreateKernelConfig: - dtype = Fp(64) if self.use_double_precision else Fp(32) + cfg = CreateKernelConfig() + cfg.default_dtype = Fp(64) if self.use_double_precision else Fp(32) + cfg.jit = no_jit + + if self.cuda_enabled: + cfg.target = Target.CUDA + elif self.hip_enabled: + cfg.target = Target.GPU # TODO: Target.HIP + else: + # CPU target + if self.optimize_for_localhost: + cfg.target = Target.CurrentCPU + else: + cfg.target = Target.GenericCPU + + if self.openmp_enabled: + cfg.cpu.openmp.enable = True - return CreateKernelConfig( - default_dtype=dtype, - jit=no_jit, - ) + return cfg diff --git a/src/walberla/codegen/sweep.py b/src/walberla/codegen/sweep.py index 07d037d7708a7ea94a6b520f02eb6a77a037b329..dcf18b3842bd29fcc8265492831e5c5c04e08842 100644 --- a/src/walberla/codegen/sweep.py +++ b/src/walberla/codegen/sweep.py @@ -31,6 +31,7 @@ from pystencilssfg.lang import ( strip_ptr_ref, SupportsVectorExtraction, ) +from .build_config import WalberlaBuildConfig from .reflection import GeneratedClassWrapperBase from .api import ( StructuredBlockForest, @@ -83,9 +84,7 @@ class SweepClassProperties: methods.append( sfg.method(f"{self.name}") .returns(Ref(self.dtype)) - .inline()( - f"return {self.name}_;" - ) + .inline()(f"return {self.name}_;") ) return methods @@ -513,9 +512,12 @@ class Sweep(CustomGenerator): knamespace = sfg.kernel_namespace(f"{self._name}_kernels") assignments = BlockforestParameters.process(self._assignments) - # TODO: Get default config from waLBerla build system and override its entries - # from the user-provided config - khandle = knamespace.create(assignments, self._name, self._gen_config) + + build_config = WalberlaBuildConfig.from_sfg(sfg) + gen_config = build_config.get_pystencils_config() + gen_config.override(self._gen_config) + + khandle = knamespace.create(assignments, self._name, gen_config) all_fields: dict[str, FieldInfo] = { f.name: FieldInfo( @@ -591,6 +593,7 @@ class Sweep(CustomGenerator): ), # Extract geometry information *(blockforest_params.render_extractions(sfg)), + # Invoke the kernel sfg.call(khandle), # Perform field swaps *( @@ -617,6 +620,7 @@ class Sweep(CustomGenerator): gen_class = sfg._cursor.get_entity(self._name) assert gen_class is not None from pystencilssfg.ir.entities import SfgClass + assert isinstance(gen_class, SfgClass) class GenClassWrapper(GeneratedClassWrapperBase):