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

Merge branch 'opencl-fixes' into 'master'

Opencl fixes

Closes lbmpy#9

See merge request !148
parents dba69a74 573f728f
Branches
Tags
No related merge requests found
...@@ -96,21 +96,21 @@ class BoundaryHandling: ...@@ -96,21 +96,21 @@ class BoundaryHandling:
fi = flag_interface fi = flag_interface
self.flag_interface = fi if fi is not None else FlagInterface(data_handling, name + "Flags") self.flag_interface = fi if fi is not None else FlagInterface(data_handling, name + "Flags")
if ParallelDataHandling and isinstance(self.data_handling, ParallelDataHandling):
array_handler = PyCudaArrayHandler()
else:
array_handler = self.data_handling.array_handler
def to_cpu(gpu_version, cpu_version): def to_cpu(gpu_version, cpu_version):
gpu_version = gpu_version.boundary_object_to_index_list gpu_version = gpu_version.boundary_object_to_index_list
cpu_version = cpu_version.boundary_object_to_index_list cpu_version = cpu_version.boundary_object_to_index_list
for obj, cpu_arr in cpu_version.items(): for obj, cpu_arr in cpu_version.items():
gpu_version[obj].get(cpu_arr) array_handler.download(gpu_version[obj], cpu_arr)
def to_gpu(gpu_version, cpu_version): def to_gpu(gpu_version, cpu_version):
gpu_version = gpu_version.boundary_object_to_index_list gpu_version = gpu_version.boundary_object_to_index_list
cpu_version = cpu_version.boundary_object_to_index_list cpu_version = cpu_version.boundary_object_to_index_list
if ParallelDataHandling and isinstance(self.data_handling, ParallelDataHandling):
array_handler = PyCudaArrayHandler()
else:
array_handler = self.data_handling.array_handler
for obj, cpu_arr in cpu_version.items(): for obj, cpu_arr in cpu_version.items():
if obj not in gpu_version or gpu_version[obj].shape != cpu_arr.shape: if obj not in gpu_version or gpu_version[obj].shape != cpu_arr.shape:
gpu_version[obj] = array_handler.to_gpu(cpu_arr) gpu_version[obj] = array_handler.to_gpu(cpu_arr)
......
...@@ -226,7 +226,7 @@ class SerialDataHandling(DataHandling): ...@@ -226,7 +226,7 @@ class SerialDataHandling(DataHandling):
def swap(self, name1, name2, gpu=None): def swap(self, name1, name2, gpu=None):
if gpu is None: if gpu is None:
gpu = self.default_target == "gpu" gpu = self.default_target in self._GPU_LIKE_TARGETS
arr = self.gpu_arrays if gpu else self.cpu_arrays arr = self.gpu_arrays if gpu else self.cpu_arrays
arr[name1], arr[name2] = arr[name2], arr[name1] arr[name1], arr[name2] = arr[name2], arr[name1]
......
...@@ -35,13 +35,14 @@ def get_periodic_boundary_functor(stencil, domain_size, index_dimensions=0, inde ...@@ -35,13 +35,14 @@ def get_periodic_boundary_functor(stencil, domain_size, index_dimensions=0, inde
assert target in ['gpu', 'opencl'] assert target in ['gpu', 'opencl']
src_dst_slice_tuples = get_periodic_boundary_src_dst_slices(stencil, ghost_layers, thickness) src_dst_slice_tuples = get_periodic_boundary_src_dst_slices(stencil, ghost_layers, thickness)
kernels = [] kernels = []
index_dimensions = index_dimensions
for src_slice, dst_slice in src_dst_slice_tuples: for src_slice, dst_slice in src_dst_slice_tuples:
ast = 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': if target == 'gpu':
kernels.append(pystencils.gpucuda.make_python_function(ast)) kernels.append(pystencils.gpucuda.make_python_function(ast))
else: else:
ast._target = 'opencl'
ast._backend = 'opencl'
kernels.append(pystencils.opencl.make_python_function(ast, opencl_queue, opencl_ctx)) kernels.append(pystencils.opencl.make_python_function(ast, opencl_queue, opencl_ctx))
def functor(pdfs, **_): def functor(pdfs, **_):
......
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