Opencl datahandling
Closes #15 (closed)
OpenCL kernels are now integrated in the normal create_kernel
workflow. Also there exists a created a opencljit.init_globally
function that just creates some CL queue/contex if you do not want to give it as a parameter to every kernel.
SerialDatahandling is extended to work with alternative GPU array libraries to PyCuda.
There is now some overlapping code with the _custom_transfer_functions
but I suppose they are for certain quantities that have a separate transfer function as oppose to using a whole different backend.
@kuron can you have a look on it? I think the solution is not as elegant as I thought it would be.
pycuda.gpuarray.GPUArrays are not wrapped. So if you use dh.gpuarrays['foo']
you get either a pycuda array or a opencl array. I thought this step would be to drastic for one PR. Using OpenCL should still be a lot easier now.
Merge request reports
Activity
added 1 commit
- 491f84ce - Fix test_kernel to work with quicktest again
added 1 commit
- 0a35ee9b - Fix test_kernel to work with quicktest again
added 1 commit
- 2adf1984 - Extend SerialDataHandling to handle alternative GPU libraries
added 1 commit
- 45d9bf5d - Extend SerialDataHandling to handle alternative GPU libraries
- Resolved by Michael Kuron
- Resolved by Stephan Seitz
- Resolved by Stephan Seitz
- Resolved by Stephan Seitz
- Resolved by Stephan Seitz
dh.synchronization_function
also still calls intopycuda
:./pystencils/pystencils/datahandling/serial_datahandling.py in synchronization_function(self, names, stencil, target, **_) 318 index_dim_shape=values_per_cell, 319 dtype=self.fields[name].dtype.numpy_dtype, --> 320 ghost_layers=gls)) 321 322 if target == 'cpu': ./pystencils/pystencils/gpucuda/periodicity.py in get_periodic_boundary_functor(stencil, domain_size, index_dimensions, index_dim_shape, ghost_layers, thickness, dtype) 35 index_dimensions = index_dimensions 36 for src_slice, dst_slice in src_dst_slice_tuples: ---> 37 kernels.append(create_copy_kernel(domain_size, src_slice, dst_slice, index_dimensions, index_dim_shape, dtype)) 38 39 def functor(pdfs, **_): ./pystencils/pystencils/gpucuda/periodicity.py in create_copy_kernel(domain_size, from_slice, to_slice, index_dimensions, index_dim_shape, dtype) 26 27 ast = create_cuda_kernel(update_eqs, iteration_slice=to_slice, skip_independence_check=True) ---> 28 return make_python_function(ast) 29 30 ./pystencils/pystencils/gpucuda/cudajit.py in make_python_function(kernel_function_node, argument_dict, custom_backend) 27 compiled kernel as Python function 28 """ ---> 29 import pycuda.autoinit # NOQA 30 from pycuda.compiler import SourceModule 31 ModuleNotFoundError: No module named 'pycuda'
- Resolved by Michael Kuron
Should I change
create_copy_kernel
to return an AST. Might correlate better to the normalcreate_kernel
functions? Though a breaking change.Edited by Stephan Seitz
added 5 commits
- 5ea958c6 - Extend SerialDataHandling to handle alternative GPU libraries
- 3d68eeb5 - Allow creation of indexed kernels with opencl
- b7861977 - Let SerialDataHandling.synchronization_function work with target OpenCL
- da9a4852 - Teach SympyPrinters how to print Type
- 0940124f - Make SerialDataHandling.serialization_function work with OpenCL
Toggle commit listadded 7 commits
- d50a59f6 - Extend SerialDataHandling to handle alternative GPU libraries
- 305ef514 - Allow creation of indexed kernels with opencl
- 8346e686 - Let SerialDataHandling.synchronization_function work with target OpenCL
- 8ac8c1ef - Teach SympyPrinters how to print Type
- 4beb4151 - Make SerialDataHandling.serialization_function work with OpenCL
- d712410d - Add two helper functions to manage global cl ctx
- 79e33121 - Add pystencils.opencl.autoinit
Toggle commit listadded 1 commit
- 2bd8fced - Protect pystencils.opencl.autoinit with try..except
added 1 commit
- b1c4889f - Protect pystencils.opencl.autoinit with try..except
added 5 commits
Toggle commit list- Resolved by Stephan Seitz
The current state of this merge request works well for me, except for the
dh.default_target
thing. I think the target names should be consistent betweencreate_kernel
andDataHandling
. This could be achieved with--- a/pystencils/datahandling/serial_datahandling.py +++ b/pystencils/datahandling/serial_datahandling.py @@ -57,5 +57,4 @@ class SerialDataHandling(DataHandling): - self.array_handler = None - - if default_target == 'opencl' or opencl_queue: - default_target = 'gpu' - self.array_handler = PyOpenClArrayHandler(opencl_queue) + try: + self.array_handler = PyOpenClArrayHandler(opencl_queue) + except Exception: + self.array_handler = None @@ -102 +101 @@ class SerialDataHandling(DataHandling): - gpu = self.default_target == 'gpu' + gpu = self.default_target == 'gpu' or self.default_target == 'opencl' @@ -227 +226 @@ class SerialDataHandling(DataHandling): - gpu = self.default_target == "gpu" + gpu = self.default_target == "gpu" or self.default_target == 'opencl'
added 1 commit
- 16451a74 - Allow default_target=='opencl' in SerialDataHandling
added 1 commit
- e8523f07 - Allow default_target=='opencl' in SerialDataHandling
@kuron I extended the PR to regard boundary handling. An example that a lot of code checks whether the target of the data handling is 'gpu'. Basic LBM scenarios can run now on OpenCL. lbmpy!13 (merged)
Edited by Stephan Seitz- Resolved by Stephan Seitz
I started the full integration test, and there are test failures when using these changes in lbmpy
added 19 commits
-
f9225965...974febd7 - 6 commits from branch
pycodegen:master
- 65c8db0a - Improve OpenCL integration via create_kernel
- ff03108b - Extend SerialDataHandling to handle alternative GPU libraries
- 38d88ddf - Allow creation of indexed kernels with opencl
- f1537570 - Let SerialDataHandling.synchronization_function work with target OpenCL
- c5f59fed - Teach SympyPrinters how to print Type
- 45922ae5 - Make SerialDataHandling.serialization_function work with OpenCL
- 3f142a0e - Add two helper functions to manage global cl ctx
- ae004cfe - Add pystencils.opencl.autoinit
- c045b3ad - Protect pystencils.opencl.autoinit with try..except
- 207381b1 - Add pycuda.autoinit to GPU test
- 4418f31d - Allow default_target=='opencl' in SerialDataHandling
- 65d4c6d1 - Add friendly hint when calling OpenCL kernels with PyCUDA/Numpy arrays
- 85484500 - Add weird construction to handle OpenCL boundary handling (don't show
Toggle commit list-
f9225965...974febd7 - 6 commits from branch
Is this merge request still under consideration or has it been superseded by https://i10git.cs.fau.de/pycodegen/pystencils/tree/target_dh_refactoring?
Yes, the data handling and the kernel targets need a major refactoring. The target_dh_refactoring branch introduces some severe API changes, which will not all be necessary. I plan to something like in this branch, but with less API changes. It's on my list, but will take some time :)
The plan is to
- remove 'backend' attribute of kernel, only have 'target' that can either be 'cpu', 'cuda', 'opencl', 'llvm_cpu', 'llvm_gpu'
- the data handling receives a 'target' upon construction (instead of 'default_target')
- in the branch I renamed all 'gpu' arguments in the data handling to 'accelerator' which is not necessary and would break a lot
- we can also leave a deprecated target called 'gpu' that is a synonym for 'cuda'
Edited by Martin Bauer