Skip to content
Snippets Groups Projects
Commit be73180b authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Adapt default codegen config to build system. Use config from build system in Sweep.

parent eb1c83d6
No related merge requests found
Pipeline #75640 passed with stages
in 7 minutes and 30 seconds
......@@ -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
......@@ -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):
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment