Skip to content
Snippets Groups Projects
Commit 890811d8 authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Execute LBM scenario with OpenCL

It compiles so it's correct I guess... :shrug:
parent d4679714
No related branches found
No related tags found
1 merge request!13Execute LBM scenario with OpenCL
...@@ -18,7 +18,7 @@ from pystencils.timeloop import TimeLoop ...@@ -18,7 +18,7 @@ from pystencils.timeloop import TimeLoop
class LatticeBoltzmannStep: class LatticeBoltzmannStep:
def __init__(self, domain_size=None, lbm_kernel=None, periodicity=False, def __init__(self, domain_size=None, lbm_kernel=None, periodicity=False,
kernel_params=MappingProxyType({}), data_handling=None, name="lbm", optimization=None, kernel_params=MappingProxyType({}), data_handling=None, name="lbm", optimization={},
velocity_data_name=None, density_data_name=None, density_data_index=None, velocity_data_name=None, density_data_name=None, density_data_index=None,
compute_velocity_in_every_step=False, compute_density_in_every_step=False, compute_velocity_in_every_step=False, compute_density_in_every_step=False,
velocity_input_array_name=None, time_step_order='stream_collide', flag_interface=None, velocity_input_array_name=None, time_step_order='stream_collide', flag_interface=None,
...@@ -29,11 +29,15 @@ class LatticeBoltzmannStep: ...@@ -29,11 +29,15 @@ class LatticeBoltzmannStep:
if domain_size is not None: if domain_size is not None:
raise ValueError("When passing a data_handling, the domain_size parameter can not be specified") raise ValueError("When passing a data_handling, the domain_size parameter can not be specified")
target = optimization.get('target', 'cpu')
if data_handling is None: if data_handling is None:
if domain_size is None: if domain_size is None:
raise ValueError("Specify either domain_size or data_handling") raise ValueError("Specify either domain_size or data_handling")
data_handling = create_data_handling(domain_size, default_ghost_layers=1, data_handling = create_data_handling(domain_size,
periodicity=periodicity, parallel=False) default_ghost_layers=1,
periodicity=periodicity,
default_target=target,
parallel=False)
if 'stencil' not in method_parameters: if 'stencil' not in method_parameters:
method_parameters['stencil'] = 'D2Q9' if data_handling.dim == 2 else 'D3Q27' method_parameters['stencil'] = 'D2Q9' if data_handling.dim == 2 else 'D3Q27'
...@@ -47,7 +51,6 @@ class LatticeBoltzmannStep: ...@@ -47,7 +51,6 @@ class LatticeBoltzmannStep:
q = len(lbm_kernel.method.stencil) q = len(lbm_kernel.method.stencil)
else: else:
q = len(get_stencil(method_parameters['stencil'])) q = len(get_stencil(method_parameters['stencil']))
target = optimization['target']
self.name = name self.name = name
self._data_handling = data_handling self._data_handling = data_handling
...@@ -58,7 +61,7 @@ class LatticeBoltzmannStep: ...@@ -58,7 +61,7 @@ class LatticeBoltzmannStep:
self.density_data_index = density_data_index self.density_data_index = density_data_index
self._optimization = optimization self._optimization = optimization
self._gpu = target == 'gpu' self._gpu = target == 'gpu' or target == 'opencl'
layout = optimization['field_layout'] layout = optimization['field_layout']
alignment = False alignment = False
......
...@@ -85,7 +85,13 @@ def create_lid_driven_cavity(domain_size=None, lid_velocity=0.005, lbm_kernel=No ...@@ -85,7 +85,13 @@ def create_lid_driven_cavity(domain_size=None, lid_velocity=0.005, lbm_kernel=No
""" """
assert domain_size is not None or data_handling is not None assert domain_size is not None or data_handling is not None
if data_handling is None: if data_handling is None:
data_handling = create_data_handling(domain_size, periodicity=False, default_ghost_layers=1, parallel=parallel) optimization = kwargs.get('optimization', None)
target = optimization.get('target', None) if optimization else None
data_handling = create_data_handling(domain_size,
periodicity=False,
default_ghost_layers=1,
parallel=parallel,
default_target=target)
step = LatticeBoltzmannStep(data_handling=data_handling, lbm_kernel=lbm_kernel, name="ldc", **kwargs) step = LatticeBoltzmannStep(data_handling=data_handling, lbm_kernel=lbm_kernel, name="ldc", **kwargs)
my_ubb = UBB(velocity=[lid_velocity, 0, 0][:step.method.dim]) my_ubb = UBB(velocity=[lid_velocity, 0, 0][:step.method.dim])
...@@ -99,7 +105,7 @@ def create_lid_driven_cavity(domain_size=None, lid_velocity=0.005, lbm_kernel=No ...@@ -99,7 +105,7 @@ def create_lid_driven_cavity(domain_size=None, lid_velocity=0.005, lbm_kernel=No
def create_channel(domain_size=None, force=None, pressure_difference=None, u_max=None, diameter_callback=None, def create_channel(domain_size=None, force=None, pressure_difference=None, u_max=None, diameter_callback=None,
duct=False, wall_boundary=NoSlip(), parallel=False, data_handling=None, **kwargs): duct=False, wall_boundary=NoSlip(), parallel=False, data_handling=None, **kwargs):
"""Create a channel scenario (2D or 3D). """Create a channel scenario (2D or 3D).
The channel can be driven either by force, velocity inflow or pressure difference. Choose one and pass The channel can be driven either by force, velocity inflow or pressure difference. Choose one and pass
exactly one of the parameters 'force', 'pressure_difference' or 'u_max'. exactly one of the parameters 'force', 'pressure_difference' or 'u_max'.
......
...@@ -48,6 +48,35 @@ def test_data_handling_3d(): ...@@ -48,6 +48,35 @@ def test_data_handling_3d():
np.testing.assert_almost_equal(results[0], arr) np.testing.assert_almost_equal(results[0], arr)
def test_data_handling_2d_opencl():
pytest.importorskip('pyopencl')
import pystencils.opencl.opencljit
pystencils.opencl.opencljit.init_globally()
print("--- LDC 2D test ---")
results = []
for parallel in [True, False] if parallel_available else [False]:
for gpu in [True, False] if gpu_available else [False]:
if parallel and gpu and not hasattr(wLB, 'cuda'):
continue
print("Testing parallel: %s\tgpu: %s" % (parallel, gpu))
opt_params = {'target': 'opencl' if gpu else 'cpu',
'gpu_indexing_params': {'block_size': (8, 4, 2)}}
if parallel:
from pystencils.datahandling import ParallelDataHandling
blocks = wLB.createUniformBlockGrid(blocks=(2, 3, 1), cellsPerBlock=(5, 5, 1),
oneBlockPerProcess=False)
dh = ParallelDataHandling(blocks, dim=2)
rho = ldc_setup(data_handling=dh, optimization=opt_params)
results.append(rho)
else:
rho = ldc_setup(domain_size=(10, 15), parallel=False, optimization=opt_params)
results.append(rho)
for i, arr in enumerate(results[1:]):
print("Testing equivalence version 0 with version %d" % (i + 1,))
np.testing.assert_almost_equal(results[0], arr)
def test_data_handling_2d(): def test_data_handling_2d():
print("--- LDC 2D test ---") print("--- LDC 2D test ---")
results = [] results = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment