Skip to content
Snippets Groups Projects

Opencl datahandling

Closed Stephan Seitz requested to merge seitz/pystencils:opencl-datahandling into master
All threads resolved!

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.

Edited by Michael Kuron

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Michael Kuron
  • Michael Kuron
  • Michael Kuron
  • Michael Kuron
  • dh.synchronization_function also still calls into pycuda:

    ./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'
  • Stephan Seitz added 5 commits

    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

    Compare with previous version

  • Stephan Seitz added 2 commits

    added 2 commits

    • 8478ff52 - Add two helper functions to manage global cl ctx
    • fc5b2f75 - Add pystencils.opencl.autoinit

    Compare with previous version

  • Stephan Seitz added 1 commit

    added 1 commit

    • b50b18e7 - Add pystencils.opencl.autoinit

    Compare with previous version

  • Stephan Seitz added 3 commits

    added 3 commits

    • 60525a66 - Make SerialDataHandling.serialization_function work with OpenCL
    • 68b49078 - Add two helper functions to manage global cl ctx
    • 05a2f354 - Add pystencils.opencl.autoinit

    Compare with previous version

  • Stephan Seitz added 3 commits

    added 3 commits

    • 94629aed - Make SerialDataHandling.serialization_function work with OpenCL
    • e433c9d0 - Add two helper functions to manage global cl ctx
    • ba3ac96d - Add pystencils.opencl.autoinit

    Compare with previous version

  • Stephan Seitz added 3 commits

    added 3 commits

    • b2757b6c - Make SerialDataHandling.serialization_function work with OpenCL
    • a57c1547 - Add two helper functions to manage global cl ctx
    • b560624c - Add pystencils.opencl.autoinit

    Compare with previous version

  • Stephan Seitz added 7 commits

    added 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

    Compare with previous version

  • Stephan Seitz added 1 commit

    added 1 commit

    • aae0b5d6 - Add pystencils.opencl.autoinit

    Compare with previous version

  • Stephan Seitz added 1 commit

    added 1 commit

    • 2bd8fced - Protect pystencils.opencl.autoinit with try..except

    Compare with previous version

  • Stephan Seitz added 1 commit

    added 1 commit

    • b1c4889f - Protect pystencils.opencl.autoinit with try..except

    Compare with previous version

  • Stephan Seitz added 1 commit
  • Stephan Seitz added 5 commits

    added 5 commits

    • 890c1f38 - Make SerialDataHandling.serialization_function work with OpenCL
    • aa8ff4ac - Add two helper functions to manage global cl ctx
    • 1fd2120b - Add pystencils.opencl.autoinit
    • 7c78efa8 - Protect pystencils.opencl.autoinit with try..except
    • ae05dd41 - Add pycuda.autoinit to GPU test

    Compare with previous version

    • 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 between create_kernel and DataHandling. 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'
  • Stephan Seitz added 1 commit

    added 1 commit

    • 16451a74 - Allow default_target=='opencl' in SerialDataHandling

    Compare with previous version

  • Okay, then I think we're ready to merge.

  • Stephan Seitz added 1 commit

    added 1 commit

    • e8523f07 - Allow default_target=='opencl' in SerialDataHandling

    Compare with previous version

  • Stephan Seitz added 2 commits

    added 2 commits

    • 0cabc121 - Add friendly hint when calling OpenCL kernels with PyCUDA/Numpy arrays
    • d601db96 - Add weird construction to handle OpenCL boundary handling (don't show

    Compare with previous version

  • Author Maintainer

    @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
  • Stephan Seitz added 1 commit
  • Stephan Seitz added 1 commit
  • Stephan Seitz added 19 commits

    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

    Compare with previous version

  • Stephan Seitz resolved all threads

    resolved all threads

  • Michael Kuron changed the description

    changed the description

  • 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
  • closed

  • Please register or sign in to reply
    Loading