Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch LB to pull scheme (un-optimized) #4769

Open
wants to merge 8 commits into
base: python
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions maintainer/walberla_kernels/generate_lb_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import lbmpy.enums

import lbmpy_walberla
import lbmpy_espresso
import lbmpy_walberla.additional_data_handler

import lees_edwards
import relaxation_rates
Expand All @@ -52,7 +52,7 @@
target = ps.Target.CPU

# Make sure we have the correct versions of the required dependencies
for module, requirement in [(ps, "==1.2"), (lbmpy, "==1.2")]:
for module, requirement in [(ps, "==1.2"), (lbmpy, "==1.3.1")]:
assert pkg_resources.packaging.specifiers.SpecifierSet(requirement).contains(module.__version__), \
f"{module.__name__} version {module.__version__} doesn't match requirement {requirement}"

Expand Down Expand Up @@ -105,14 +105,6 @@ def paramlist(parameters, keys):
force_model=lbmpy.forcemodels.Schiller(force_field.center_vector)
)

# generate stream kernels
for params, target_suffix in paramlist(parameters, ("GPU", "CPU", "AVX")):
pystencils_espresso.generate_stream_sweep(
ctx,
method,
f"StreamSweep{precision_prefix}{target_suffix}",
params)

# generate initial densities
for params, target_suffix in paramlist(parameters, (default_key,)):
pystencils_walberla.codegen.generate_sweep(
Expand All @@ -121,6 +113,14 @@ def paramlist(parameters, keys):
pystencils_espresso.generate_setters(ctx, method, params),
**params)

# generate velocity field update kernel
for params, target_suffix in paramlist(parameters, (default_key,)):
pystencils_walberla.codegen.generate_sweep(
ctx,
f"VelFieldUpdate{precision_prefix}{target_suffix}",
pystencils_espresso.generate_vel_field_update(ctx, method, params),
**params)

# generate unthermalized Lees-Edwards collision rule
le_config = lbmpy.LBMConfig(stencil=stencil,
method=lbmpy.Method.TRT,
Expand All @@ -129,7 +129,7 @@ def paramlist(parameters, keys):
zero_centered=False,
force_model=lbmpy.ForceModel.GUO,
force=force_field.center_vector,
kernel_type="collide_only")
kernel_type="default_stream_collide")
lbm_opt = lbmpy.LBMOptimisation(symbolic_field=fields["pdfs"])
le_collision_rule_unthermalized = lbmpy.create_lb_update_rule(
lbm_config=le_config,
Expand All @@ -138,11 +138,11 @@ def paramlist(parameters, keys):
config, le_collision_rule_unthermalized,
fields["pdfs"], stencil, 1) # shear_dir_normal y
for params, target_suffix in paramlist(parameters, ("GPU", "CPU", "AVX")):
pystencils_espresso.generate_collision_sweep(
pystencils_espresso.generate_streaming_collision_sweep(
ctx,
le_config,
le_collision_rule_unthermalized,
f"CollideSweep{precision_prefix}LeesEdwards{target_suffix}",
f"StreamCollideSweep{precision_prefix}LeesEdwards{target_suffix}",
params
)

Expand All @@ -159,11 +159,11 @@ def paramlist(parameters, keys):
"double_precision": ctx.double_accuracy}
)
for params, target_suffix in paramlist(parameters, ("GPU", "CPU", "AVX")):
pystencils_espresso.generate_collision_sweep(
pystencils_espresso.generate_streaming_collision_sweep(
ctx,
method,
collision_rule_thermalized,
f"CollideSweep{precision_prefix}Thermalized{target_suffix}",
f"StreamCollideSweep{precision_prefix}Thermalized{target_suffix}",
params
)

Expand All @@ -184,17 +184,17 @@ def paramlist(parameters, keys):
)

# boundary conditions
ubb_dynamic = lbmpy_espresso.UBB(
lambda *args: None, dim=3, data_type=config.data_type.default_factory())
ubb_data_handler = lbmpy_espresso.BounceBackSlipVelocityUBB(
method.stencil, ubb_dynamic)

ubb = lbmpy.boundaries.boundaryconditions.UBB(
lambda *args: None, dim=3, data_type=config.data_type.default_factory(), adapt_velocity_to_force=True)
ubb_data_handler = lbmpy_walberla.additional_data_handler.default_additional_data_handler(
ubb, method, fields["pdfs"], target=target)
for _, target_suffix in paramlist(parameters, ("GPU", "CPU")):
lbmpy_walberla.generate_boundary(
ctx, f"Dynamic_UBB_{precision_suffix}{target_suffix}", ubb_dynamic,
ctx, f"Dynamic_UBB_{precision_suffix}{target_suffix}", ubb,
method, additional_data_handler=ubb_data_handler,
streaming_pattern="push", target=target)
streaming_pattern="pull", target=target)

# replace Walberla-specific real_t by float/double.
with open(f"Dynamic_UBB_{precision_suffix}{target_suffix}.h", "r+") as f:
content = f.read()
f.seek(0)
Expand Down
81 changes: 0 additions & 81 deletions maintainer/walberla_kernels/lbmpy_espresso.py

This file was deleted.

34 changes: 14 additions & 20 deletions maintainer/walberla_kernels/pystencils_espresso.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def generate_config(ctx, params):
return pystencils_walberla.codegen.config_from_context(ctx, **params)


def generate_collision_sweep(
def generate_streaming_collision_sweep(
ctx, lb_method, collision_rule, class_name, params):
config = generate_config(ctx, params)

Expand All @@ -122,7 +122,7 @@ def generate_collision_sweep(
collision_rule,
fields['pdfs'],
fields['pdfs_tmp'],
lbmpy.fieldaccess.CollideOnlyInplaceAccessor())
lbmpy.fieldaccess.StreamPullTwoFieldsAccessor())
collide_ast = ps.create_kernel(
collide_update_rule, config=config, **params)
collide_ast.function_name = 'kernel_collide'
Expand All @@ -131,24 +131,6 @@ def generate_collision_sweep(
ctx, class_name, collide_ast, **params)


def generate_stream_sweep(ctx, lb_method, class_name, params):
config = generate_config(ctx, params)

# Symbols for PDF (twice, due to double buffering)
fields = generate_fields(config, lb_method.stencil)

# Generate stream kernel
stream_update_rule = lbmpy.updatekernels.create_stream_pull_with_output_kernel(
lb_method, fields['pdfs'], fields['pdfs_tmp'],
output={'velocity': fields['velocity']})
stream_ast = ps.create_kernel(stream_update_rule, config=config, **params)
stream_ast.function_name = 'kernel_stream'
stream_ast.assumed_inner_stride_one = True
pystencils_walberla.codegen.generate_sweep(
ctx, class_name, stream_ast,
field_swaps=[(fields['pdfs'], fields['pdfs_tmp'])], **params)


def generate_setters(ctx, lb_method, params):
config = generate_config(ctx, params)
fields = generate_fields(config, lb_method.stencil)
Expand All @@ -160,3 +142,15 @@ def generate_setters(ctx, lb_method, params):
fields['velocity'].center_vector,
fields['pdfs'].center_vector)
return pdfs_setter


def generate_vel_field_update(ctx, lb_method, params):
config = generate_config(ctx, params)
fields = generate_fields(config, lb_method.stencil)

vel_updater = lbmpy.macroscopic_value_kernels.macroscopic_values_getter(
lb_method,
None, # denisty
fields['velocity'].center_vector,
fields['pdfs'].center_vector)
return vel_updater
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! \\author lbmpy
//======================================================================================================================

// kernel generated with pystencils v1.2, lbmpy v1.2, lbmpy_walberla/pystencils_walberla from waLBerla commit ref: a839fac6ef7d0c58e7710e4d50490e9dd7146b4a
// kernel generated with pystencils v1.2, lbmpy v1.3.1, lbmpy_walberla/pystencils_walberla from waLBerla commit 065ce5f311850371a97ac4766f47dbb5ca8424ba

#include <cmath>

Expand Down Expand Up @@ -1625,8 +1625,8 @@ static FUNC_PREFIX void advectivefluxkernel_double_precision_advectivefluxkernel
} // namespace internal_5255e1c780a944d646f270232511968b

void AdvectiveFluxKernel_double_precision::run(IBlock *block) {
auto u = block->getData<field::GhostLayerField<double, 3>>(uID);
auto rho = block->getData<field::GhostLayerField<double, 1>>(rhoID);
auto u = block->getData<field::GhostLayerField<double, 3>>(uID);
auto j = block->getData<field::GhostLayerField<double, 13>>(jID);

WALBERLA_ASSERT_GREATER_EQUAL(-1, -int_c(j->nrOfGhostLayers()));
Expand Down Expand Up @@ -1664,8 +1664,8 @@ void AdvectiveFluxKernel_double_precision::runOnCellInterval(const shared_ptr<St
if (ci.empty())
return;

auto u = block->getData<field::GhostLayerField<double, 3>>(uID);
auto rho = block->getData<field::GhostLayerField<double, 1>>(rhoID);
auto u = block->getData<field::GhostLayerField<double, 3>>(uID);
auto j = block->getData<field::GhostLayerField<double, 13>>(jID);

WALBERLA_ASSERT_GREATER_EQUAL(ci.xMin() - 1, -int_c(j->nrOfGhostLayers()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
//! \\author pystencils
//======================================================================================================================

// kernel generated with pystencils v1.2, lbmpy v1.2,
// lbmpy_walberla/pystencils_walberla from waLBerla commit ref:
// a839fac6ef7d0c58e7710e4d50490e9dd7146b4a
// kernel generated with pystencils v1.2, lbmpy v1.3.1,
// lbmpy_walberla/pystencils_walberla from waLBerla commit
// 065ce5f311850371a97ac4766f47dbb5ca8424ba

#pragma once
#include "core/DataTypes.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! \\author lbmpy
//======================================================================================================================

// kernel generated with pystencils v1.2, lbmpy v1.2, lbmpy_walberla/pystencils_walberla from waLBerla commit ref: a839fac6ef7d0c58e7710e4d50490e9dd7146b4a
// kernel generated with pystencils v1.2, lbmpy v1.3.1, lbmpy_walberla/pystencils_walberla from waLBerla commit 065ce5f311850371a97ac4766f47dbb5ca8424ba

#include <cmath>

Expand Down Expand Up @@ -1626,8 +1626,8 @@ static FUNC_PREFIX void advectivefluxkernel_single_precision_advectivefluxkernel

void AdvectiveFluxKernel_single_precision::run(IBlock *block) {
auto u = block->getData<field::GhostLayerField<float, 3>>(uID);
auto j = block->getData<field::GhostLayerField<float, 13>>(jID);
auto rho = block->getData<field::GhostLayerField<float, 1>>(rhoID);
auto j = block->getData<field::GhostLayerField<float, 13>>(jID);

WALBERLA_ASSERT_GREATER_EQUAL(-1, -int_c(j->nrOfGhostLayers()));
float *RESTRICT const _data_j = j->dataAt(-1, -1, -1, 0);
Expand Down Expand Up @@ -1665,8 +1665,8 @@ void AdvectiveFluxKernel_single_precision::runOnCellInterval(const shared_ptr<St
return;

auto u = block->getData<field::GhostLayerField<float, 3>>(uID);
auto j = block->getData<field::GhostLayerField<float, 13>>(jID);
auto rho = block->getData<field::GhostLayerField<float, 1>>(rhoID);
auto j = block->getData<field::GhostLayerField<float, 13>>(jID);

WALBERLA_ASSERT_GREATER_EQUAL(ci.xMin() - 1, -int_c(j->nrOfGhostLayers()));
WALBERLA_ASSERT_GREATER_EQUAL(ci.yMin() - 1, -int_c(j->nrOfGhostLayers()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
//! \\author pystencils
//======================================================================================================================

// kernel generated with pystencils v1.2, lbmpy v1.2,
// lbmpy_walberla/pystencils_walberla from waLBerla commit ref:
// a839fac6ef7d0c58e7710e4d50490e9dd7146b4a
// kernel generated with pystencils v1.2, lbmpy v1.3.1,
// lbmpy_walberla/pystencils_walberla from waLBerla commit
// 065ce5f311850371a97ac4766f47dbb5ca8424ba

#pragma once
#include "core/DataTypes.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! \\author lbmpy
//======================================================================================================================

// kernel generated with pystencils v1.2, lbmpy v1.2, lbmpy_walberla/pystencils_walberla from waLBerla commit ref: a839fac6ef7d0c58e7710e4d50490e9dd7146b4a
// kernel generated with pystencils v1.2, lbmpy v1.3.1, lbmpy_walberla/pystencils_walberla from waLBerla commit 065ce5f311850371a97ac4766f47dbb5ca8424ba

#include <cmath>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
//! \\author pystencils
//======================================================================================================================

// kernel generated with pystencils v1.2, lbmpy v1.2,
// lbmpy_walberla/pystencils_walberla from waLBerla commit ref:
// a839fac6ef7d0c58e7710e4d50490e9dd7146b4a
// kernel generated with pystencils v1.2, lbmpy v1.3.1,
// lbmpy_walberla/pystencils_walberla from waLBerla commit
// 065ce5f311850371a97ac4766f47dbb5ca8424ba

#pragma once
#include "core/DataTypes.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! \\author lbmpy
//======================================================================================================================

// kernel generated with pystencils v1.2, lbmpy v1.2, lbmpy_walberla/pystencils_walberla from waLBerla commit ref: a839fac6ef7d0c58e7710e4d50490e9dd7146b4a
// kernel generated with pystencils v1.2, lbmpy v1.3.1, lbmpy_walberla/pystencils_walberla from waLBerla commit 065ce5f311850371a97ac4766f47dbb5ca8424ba

#include <cmath>

Expand Down Expand Up @@ -108,8 +108,8 @@ static FUNC_PREFIX void continuitykernel_single_precision_continuitykernel_singl
} // namespace internal_990034b4e4dd57d2802b4bcb5f716e46

void ContinuityKernel_single_precision::run(IBlock *block) {
auto j = block->getData<field::GhostLayerField<float, 13>>(jID);
auto rho = block->getData<field::GhostLayerField<float, 1>>(rhoID);
auto j = block->getData<field::GhostLayerField<float, 13>>(jID);

WALBERLA_ASSERT_GREATER_EQUAL(-1, -int_c(j->nrOfGhostLayers()));
float *RESTRICT const _data_j = j->dataAt(-1, -1, -1, 0);
Expand Down Expand Up @@ -140,8 +140,8 @@ void ContinuityKernel_single_precision::runOnCellInterval(const shared_ptr<Struc
if (ci.empty())
return;

auto j = block->getData<field::GhostLayerField<float, 13>>(jID);
auto rho = block->getData<field::GhostLayerField<float, 1>>(rhoID);
auto j = block->getData<field::GhostLayerField<float, 13>>(jID);

WALBERLA_ASSERT_GREATER_EQUAL(ci.xMin() - 1, -int_c(j->nrOfGhostLayers()));
WALBERLA_ASSERT_GREATER_EQUAL(ci.yMin() - 1, -int_c(j->nrOfGhostLayers()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
//! \\author pystencils
//======================================================================================================================

// kernel generated with pystencils v1.2, lbmpy v1.2,
// lbmpy_walberla/pystencils_walberla from waLBerla commit ref:
// a839fac6ef7d0c58e7710e4d50490e9dd7146b4a
// kernel generated with pystencils v1.2, lbmpy v1.3.1,
// lbmpy_walberla/pystencils_walberla from waLBerla commit
// 065ce5f311850371a97ac4766f47dbb5ca8424ba

#pragma once
#include "core/DataTypes.h"
Expand Down
Loading