From 21d9b914580850ee53523a9f5138838618b906db Mon Sep 17 00:00:00 2001 From: Stephan Seitz <stephan.seitz@fau.de> Date: Tue, 12 Nov 2019 15:17:10 +0100 Subject: [PATCH] Allow creation of indexed kernels with opencl --- pystencils/kernelcreation.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pystencils/kernelcreation.py b/pystencils/kernelcreation.py index 759435ed..73b45b84 100644 --- a/pystencils/kernelcreation.py +++ b/pystencils/kernelcreation.py @@ -142,7 +142,9 @@ def create_indexed_kernel(assignments, cpu_openmp=True, gpu_indexing='block', gpu_indexing_params=MappingProxyType({}), - use_textures_for_interpolation=True): + use_textures_for_interpolation=True, + opencl_queue=None, + opencl_ctx=None): """ Similar to :func:`create_kernel`, but here not all cells of a field are updated but only cells with coordinates which are stored in an index field. This traversal method can e.g. be used for boundary handling. @@ -192,7 +194,7 @@ def create_indexed_kernel(assignments, return ast elif target == 'llvm': raise NotImplementedError("Indexed kernels are not yet supported in LLVM backend") - elif target == 'gpu': + elif target == 'gpu' or target == 'opencl': from pystencils.gpucuda import created_indexed_cuda_kernel idx_creator = indexing_creator_from_params(gpu_indexing, gpu_indexing_params) ast = created_indexed_cuda_kernel(assignments, @@ -201,6 +203,12 @@ def create_indexed_kernel(assignments, coordinate_names=coordinate_names, indexing_creator=idx_creator, use_textures_for_interpolation=use_textures_for_interpolation) + if target == 'opencl': + from pystencils.opencl.opencljit import make_python_function + ast._backend = 'opencl' + ast.compile = functools.partial(make_python_function, ast, opencl_queue, opencl_ctx) + ast._target = 'opencl' + ast._backend = 'opencl' return ast else: raise ValueError("Unknown target %s. Has to be either 'cpu' or 'gpu'" % (target,)) -- GitLab