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

Make SerialDataHandling.serialization_function work with OpenCL

parent 585084e7
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ class SerialDataHandling(DataHandling):
periodicity: Union[bool, Sequence[bool]] = False,
default_target: str = 'cpu',
opencl_queue=None,
opencl_ctx=None,
array_handler=None) -> None:
"""
Creates a data handling for single node simulations.
......@@ -44,6 +45,8 @@ class SerialDataHandling(DataHandling):
self.custom_data_cpu = DotDict()
self.custom_data_gpu = DotDict()
self._custom_data_transfer_functions = {}
self._opencl_queue = opencl_queue
self._opencl_ctx = opencl_ctx
if array_handler:
self.array_handler = array_handler
......@@ -315,11 +318,15 @@ class SerialDataHandling(DataHandling):
result.append(get_periodic_boundary_functor(filtered_stencil, ghost_layers=gls))
else:
from pystencils.gpucuda.periodicity import get_periodic_boundary_functor as boundary_func
target = 'gpu' if not isinstance(self.array_handler, PyOpenClArrayHandler) else 'opencl'
result.append(boundary_func(filtered_stencil, self._domainSize,
index_dimensions=self.fields[name].index_dimensions,
index_dim_shape=values_per_cell,
dtype=self.fields[name].dtype.numpy_dtype,
ghost_layers=gls))
ghost_layers=gls,
target=target,
opencl_queue=self._opencl_queue,
opencl_ctx=self._opencl_ctx))
if target == 'cpu':
def result_functor():
......
import numpy as np
import pystencils.gpucuda
import pystencils.opencl
from pystencils import Assignment, Field
from pystencils.gpucuda import make_python_function
from pystencils.gpucuda.kernelcreation import create_cuda_kernel
from pystencils.slicing import get_periodic_boundary_src_dst_slices, normalize_slice
......@@ -25,16 +26,22 @@ def create_copy_kernel(domain_size, from_slice, to_slice, index_dimensions=0, in
update_eqs.append(eq)
ast = create_cuda_kernel(update_eqs, iteration_slice=to_slice, skip_independence_check=True)
return make_python_function(ast)
return ast
def get_periodic_boundary_functor(stencil, domain_size, index_dimensions=0, index_dim_shape=1, ghost_layers=1,
thickness=None, dtype=float):
thickness=None, dtype=float, target='gpu', opencl_queue=None, opencl_ctx=None):
assert target in ['gpu', 'opencl']
src_dst_slice_tuples = get_periodic_boundary_src_dst_slices(stencil, ghost_layers, thickness)
kernels = []
index_dimensions = index_dimensions
for src_slice, dst_slice in src_dst_slice_tuples:
kernels.append(create_copy_kernel(domain_size, src_slice, dst_slice, index_dimensions, index_dim_shape, dtype))
ast = create_copy_kernel(domain_size, src_slice, dst_slice, index_dimensions, index_dim_shape, dtype)
if target == 'gpu':
kernels.append(pystencils.gpucuda.make_python_function(ast))
else:
kernels.append(pystencils.opencl.make_python_function(ast, opencl_queue, opencl_ctx))
def functor(pdfs, **_):
for kernel in kernels:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment