Commit 342663c5 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Final Fixes

- Removed Test Notebooks
- Fixed PeriodicityHandling API
- Added GPU and OpenCL Periodic Pipe tests
- A few more minor tweaks
parent f5ff4df4
Pipeline #27641 passed with stage
in 24 minutes and 10 seconds
...@@ -2,6 +2,7 @@ from pystencils import Field, Assignment ...@@ -2,6 +2,7 @@ from pystencils import Field, Assignment
from pystencils.slicing import shift_slice, get_slice_before_ghost_layer, normalize_slice from pystencils.slicing import shift_slice, get_slice_before_ghost_layer, normalize_slice
from lbmpy.advanced_streaming.utility import is_inplace, get_accessor, numeric_index, \ from lbmpy.advanced_streaming.utility import is_inplace, get_accessor, numeric_index, \
numeric_offsets, Timestep, get_timesteps numeric_offsets, Timestep, get_timesteps
from lbmpy.stencils import get_stencil
from pystencils.datahandling import SerialDataHandling from pystencils.datahandling import SerialDataHandling
from itertools import chain from itertools import chain
...@@ -142,7 +143,7 @@ def periodic_pdf_copy_kernel(pdf_field, src_slice, dst_slice, ...@@ -142,7 +143,7 @@ def periodic_pdf_copy_kernel(pdf_field, src_slice, dst_slice,
class LBMPeriodicityHandling: class LBMPeriodicityHandling:
def __init__(self, stencil, data_handling, pdf_field_name, def __init__(self, stencil, data_handling, pdf_field_name,
streaming_pattern='pull', ghost_layers=1, target='cpu', streaming_pattern='pull', ghost_layers=1,
opencl_queue=None, opencl_ctx=None, opencl_queue=None, opencl_ctx=None,
pycuda_direct_copy=True): pycuda_direct_copy=True):
""" """
...@@ -163,10 +164,15 @@ class LBMPeriodicityHandling: ...@@ -163,10 +164,15 @@ class LBMPeriodicityHandling:
if not isinstance(data_handling, SerialDataHandling): if not isinstance(data_handling, SerialDataHandling):
raise ValueError('Only serial data handling is supported!') raise ValueError('Only serial data handling is supported!')
assert target in ['cpu', 'gpu', 'opencl'] if isinstance(stencil, str):
stencil = get_stencil(stencil)
self.stencil = stencil self.stencil = stencil
self.dh = data_handling self.dh = data_handling
target = data_handling.default_target
assert target in ['cpu', 'gpu', 'opencl']
self.pdf_field_name = pdf_field_name self.pdf_field_name = pdf_field_name
self.ghost_layers = ghost_layers self.ghost_layers = ghost_layers
periodicity = data_handling.periodicity periodicity = data_handling.periodicity
......
...@@ -72,8 +72,8 @@ def numeric_index(field_access: ps.Field.Access): ...@@ -72,8 +72,8 @@ def numeric_index(field_access: ps.Field.Access):
return tuple(int(i) for i in field_access.index) return tuple(int(i) for i in field_access.index)
def inverse_dir_index(stencil, dir): def inverse_dir_index(stencil, direction):
return stencil.index(tuple(-d for d in stencil[dir])) return stencil.index(tuple(-d for d in stencil[direction]))
class AccessPdfValues: class AccessPdfValues:
......
...@@ -127,7 +127,7 @@ def test_fully_periodic_flow(target, stencil, streaming_pattern): ...@@ -127,7 +127,7 @@ def test_fully_periodic_flow(target, stencil, streaming_pattern):
getter_kernels.append(create_kernel(getter, ghost_layers=1, target=target).compile()) getter_kernels.append(create_kernel(getter, ghost_layers=1, target=target).compile())
# Periodicity # Periodicity
periodicity_handler = LBMPeriodicityHandling(stencil, dh, pdfs.name, streaming_pattern=streaming_pattern, target=target) periodicity_handler = LBMPeriodicityHandling(stencil, dh, pdfs.name, streaming_pattern=streaming_pattern)
# Initialization and Timestep # Initialization and Timestep
current_timestep = zeroth_timestep current_timestep = zeroth_timestep
......
...@@ -18,13 +18,32 @@ from numpy.testing import assert_allclose ...@@ -18,13 +18,32 @@ from numpy.testing import assert_allclose
all_results = dict() all_results = dict()
targets = ['cpu']
try:
import pycuda.autoinit
targets += ['gpu']
except Exception:
pass
try:
import pystencils.opencl.autoinit
from pystencils.opencl.opencljit import get_global_cl_queue
if get_global_cl_queue() is not None:
targets += ['opencl']
except Exception:
pass
class PeriodicPipeFlow: class PeriodicPipeFlow:
def __init__(self, stencil, streaming_pattern, wall_boundary=None): def __init__(self, stencil, streaming_pattern, wall_boundary=None, target='cpu'):
if wall_boundary is None: if wall_boundary is None:
wall_boundary = NoSlip() wall_boundary = NoSlip()
self.target = target
self.gpu = target in ['gpu', 'opencl']
# Stencil # Stencil
self.stencil = stencil self.stencil = stencil
self.q = len(self.stencil) self.q = len(self.stencil)
...@@ -43,7 +62,8 @@ class PeriodicPipeFlow: ...@@ -43,7 +62,8 @@ class PeriodicPipeFlow:
self.periodicity = (True, ) + (False, ) * (self.dim - 1) self.periodicity = (True, ) + (False, ) * (self.dim - 1)
self.force = (0.0001, ) + (0.0,) * (self.dim - 1) self.force = (0.0001, ) + (0.0,) * (self.dim - 1)
self.dh = create_data_handling(domain_size=self.domain_size, periodicity=self.periodicity) self.dh = create_data_handling(domain_size=self.domain_size,
periodicity=self.periodicity, default_target=self.target)
self.pdfs = self.dh.add_array('pdfs', self.q) self.pdfs = self.dh.add_array('pdfs', self.q)
if not self.inplace: if not self.inplace:
...@@ -60,7 +80,7 @@ class PeriodicPipeFlow: ...@@ -60,7 +80,7 @@ class PeriodicPipeFlow:
optimization = { optimization = {
'symbolic_field': self.pdfs, 'symbolic_field': self.pdfs,
'target': 'cpu' 'target': self.target
} }
if not self.inplace: if not self.inplace:
...@@ -99,21 +119,24 @@ class PeriodicPipeFlow: ...@@ -99,21 +119,24 @@ class PeriodicPipeFlow:
setter = macroscopic_values_setter( setter = macroscopic_values_setter(
self.lb_method, self.density, self.velocity, self.pdfs, self.lb_method, self.density, self.velocity, self.pdfs,
streaming_pattern=self.streaming_pattern, previous_timestep=self.zeroth_timestep) streaming_pattern=self.streaming_pattern, previous_timestep=self.zeroth_timestep)
self.init_kernel = create_kernel(setter, ghost_layers=1).compile() self.init_kernel = create_kernel(setter, ghost_layers=1, target=self.target).compile()
self.getter_kernels = [] self.getter_kernels = []
for t in self.timesteps: for t in self.timesteps:
getter = macroscopic_values_getter( getter = macroscopic_values_getter(
self.lb_method, self.density_field, self.velocity_field, self.pdfs, self.lb_method, self.density_field, self.velocity_field, self.pdfs,
streaming_pattern=self.streaming_pattern, previous_timestep=t) streaming_pattern=self.streaming_pattern, previous_timestep=t)
self.getter_kernels.append(create_kernel(getter, ghost_layers=1).compile()) self.getter_kernels.append(create_kernel(getter, ghost_layers=1, target=self.target).compile())
# Periodicity # Periodicity
self.periodicity_handler = LBMPeriodicityHandling(self.stencil, self.dh, self.pdfs.name, streaming_pattern=self.streaming_pattern) self.periodicity_handler = LBMPeriodicityHandling(
self.stencil, self.dh, self.pdfs.name, streaming_pattern=self.streaming_pattern)
# Boundary Handling # Boundary Handling
self.wall = wall_boundary self.wall = wall_boundary
self.bh = LatticeBoltzmannBoundaryHandling(self.lb_method, self.dh, self.pdfs.name, streaming_pattern=self.streaming_pattern) self.bh = LatticeBoltzmannBoundaryHandling(
self.lb_method, self.dh, self.pdfs.name,
streaming_pattern=self.streaming_pattern, target=self.target)
self.bh.set_boundary(boundary_obj=self.wall, mask_callback=self.mask_callback) self.bh.set_boundary(boundary_obj=self.wall, mask_callback=self.mask_callback)
...@@ -156,9 +179,13 @@ class PeriodicPipeFlow: ...@@ -156,9 +179,13 @@ class PeriodicPipeFlow:
@property @property
def velocity_array(self): def velocity_array(self):
if self.gpu:
self.dh.to_cpu(self.velocity_field.name)
return self.dh.gather_array(self.velocity_field.name) return self.dh.gather_array(self.velocity_field.name)
def get_trimmed_velocity_array(self): def get_trimmed_velocity_array(self):
if self.gpu:
self.dh.to_cpu(self.velocity_field.name)
u = np.copy(self.dh.gather_array(self.velocity_field.name)) u = np.copy(self.dh.gather_array(self.velocity_field.name))
mask = self.bh.get_mask(None, self.wall) mask = self.bh.get_mask(None, self.wall)
for idx in np.ndindex(u.shape[:-1]): for idx in np.ndindex(u.shape[:-1]):
...@@ -169,9 +196,10 @@ class PeriodicPipeFlow: ...@@ -169,9 +196,10 @@ class PeriodicPipeFlow:
@pytest.mark.parametrize('stencil', ['D2Q9', 'D3Q19', 'D3Q27']) @pytest.mark.parametrize('stencil', ['D2Q9', 'D3Q19', 'D3Q27'])
@pytest.mark.parametrize('streaming_pattern', streaming_patterns) @pytest.mark.parametrize('streaming_pattern', streaming_patterns)
def test_periodic_pipe(stencil, streaming_pattern): @pytest.mark.parametrize('target', targets)
def test_periodic_pipe(stencil, streaming_pattern, target):
stencil = get_stencil(stencil) stencil = get_stencil(stencil)
pipeflow = PeriodicPipeFlow(stencil, streaming_pattern) pipeflow = PeriodicPipeFlow(stencil, streaming_pattern, target=target)
pipeflow.init() pipeflow.init()
pipeflow.run(100) pipeflow.run(100)
u = pipeflow.get_trimmed_velocity_array() u = pipeflow.get_trimmed_velocity_array()
......
Markdown is supported
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