Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds fetching of particle addresses API to OpenCL implementation #130

Conversation

martinschwinzerl
Copy link
Contributor

Adds API to the track job specialization for OpenCL to fetch the start address of the fields in the Particles instance and allows to directly interact with the data. Cf. examples/python/opencl_cpu_particle_addr.py for an example of using this API

Note: the example is currently only expected to work with CPU devices. There is currently no implementation available to setup pyopencl from the host side to share the particle data via this addresses. libraries implementing the data sharing on the device side in their own kernels would work, though.

Martin Schwinzerl and others added 30 commits January 17, 2020 22:33
- adds feature flags, pairs of key-value strings that can be translated
  into compiler options for the OpenCL runtime compiler
- adds handling for the default compiler options stored in the Controller
… compile option handling

- removes "enable/disable" beam-beam tracking boolean flag - this is now
  handled as a combination of the SIXTRL_TRACK_BEAMBEAM4D and SIXTRL_TRACK_BEAMBEAM6D
  feature flags

- adds a skip beam-beam tracking setter
- uses feature flags for all compiler option generation
- properly uses the default compiler options
- exposes the default compiler options to C99 api
… to the ClController python implementation
…CubData)

- adds two functions to return the object type for these two elements -
  these are used to keep the object id's sync between the python and C/C++
  implementation

- adds two functions that return the offeset relative to the begin of the elements
  of the src and dest addresses for the assignment item. These will replace
  the hard-coded values in the Python implementation of tricub.py and hopefully
  make this more robust
…reciated NS(OpenCL_get_available_node_id_strs_detailed) API
…lNodeId to no longer rely on the depreciated NS(OpenCL_get_available_node_id_strs_detailed) API

- Note: The conversion of a ptr to a NS(ComputeNodeId) to a node id str is now done
  once via a staticmethod in the ClNodeId class rather than duplicated throughout the
  code. this will have to be changed once the NS(NodeId) implemmentation is used
  for both CUDA and OpenCL!
…tation

- uses the C API to set the type id and the src/dest addr offset
  for these two elements. this should hopefully make the whole thing
  more robust in case something changes and is a kind of test run
  on how to handle other address assignment items
-- Note: changed to use black -l 79 instead of autopep8 to be compatible with
   the linter script in pysixtrack
python/sixtracklib: fixes wrong calculated offset to TriCubData element
…thon

- adds two helper functions to stcommon which encode and decode
  python (unicode) strings to bytes strings compatible with ctypes.c_char_p

- Avoid explicit encoding / decoding in all parts of python/sixtracklib
  and use the helper functions instead

- re-apply the linter after reformating and simplyfing the source code
@martinschwinzerl
Copy link
Contributor Author

merged PR #130 with PR #132 to allow integration once #132 lands. Passes all tests on my workstation.
@aoeftiger : could you please, in your own time, verify whether this version would work for you both with respect to the features of #132 as also with the OpenCL CPU address sharing from #130? Thanks you!

@aoeftiger
Copy link
Contributor

When compiling with CUDA support on, I get the following error upon import:

    import sixtracklib
  File ".../sixtracklib/python/sixtracklib/__init__.py", line 12, in <module>
    from .beam_elements import *
  File ".../sixtracklib/python/sixtracklib/beam_elements.py", line 15, in <module>
    from .stcommon import (
  File ".../sixtracklib/python/sixtracklib/stcommon.py", line 8, in <module>
    sixtracklib = ct.CDLL(stconf.SHARED_LIB)
  File ".../anaconda3/envs/stl_pr130/lib/python3.7/ctypes/__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: .../sixtracklib/python/sixtracklib/libsixtrack.so: undefined symbol: __cudaRegisterLinkedBinary_64_tmpxft_00023082_00000000_6_be_monitors_assign_out_buffer_cpp1_ii_54dd6e05

@aoeftiger
Copy link
Contributor

Besides the CUDA import thing, everything works for me -- both the full SIS100 setup with 'Bunched' and 'Interpolated' mode of space charge as well as the new feature of sharing memory addresses in an openCL trackjob and writing to them from the python level via numpy exposed buffers (just as in your new example mentioned above, just within the SIS100 setup)!

@martinschwinzerl
Copy link
Contributor Author

Thanks for testing, I'm trying to reproduce the problem with the CUDA API

@martinschwinzerl
Copy link
Contributor Author

Fixed two minor issues that should however not be the cause for your problem. On my machine (CUDA 10.1), the symbol in question is indeed exported via libsixtrack.so:

nm  sixtracklib/libsixtrack.so | grep "be_monitors_assign_out_buffer"
000000000031546c T __cudaRegisterLinkedBinary_64_tmpxft_00059fce_00000000_6_be_monitors_assign_out_buffer_cpp1_ii_54dd6e05

Stupid question: have you re-run cmake .. before attempting to install?
Could you also please verify if the symbol is present in the library located in build/sixtracklib before attempting to perform the python installation? Sorry for the hassles & thanks again for reporting the issue!

@aoeftiger
Copy link
Contributor

Indeed, issue #109 is the explanation -- I had a cmake v3.16.3 due to the host OS ubuntu 20.04! When explicitly installing cmake v3.14.4 via pip, the compilation and import in python works flawlessly. Thanks and sorry for the hassle from my side!

- The flag CUDA_RESOLVE_DEVICE_SYMBOLS should be enabled by default on
  shared libraries like SixTrackLib. The property does not work on
  OBJECT libraries like sixtrack_cuda_device. It seems that starting
  with cmake 3.15, cmake did not pick up the property for the resulting
  compound SHARED library just by inferring the dependency on the CUDA
  device part.

  This fix attempts to rectify this by adding the property explicitly
  to the SHARED sixtracklib library if the sixtrack_cuda_device
  target is present.

  Tested on CMake 3.14, 3.16 und 3.18 -> seems to work

- Note: this would fix issue SixTrack#109 but more investigation is required whether
  this solves all problems encountered therein
@martinschwinzerl
Copy link
Contributor Author

@aoeftiger Could you please verify whether the updated PR (especially after commit 1ce557c) would solve the issue with CMake newer than 3.14 for you as well?

@aoeftiger
Copy link
Contributor

aoeftiger commented Oct 22, 2020

Very nice! 1ce557c does solve the issue, I can compile and import in python including the CUDA support without a problem using the system cmake v3.16.3!! Thanks @martinschwinzerl !!

@martinschwinzerl
Copy link
Contributor Author

Merged into PR #132 ->close

@martinschwinzerl martinschwinzerl deleted the feature/opencl_particle_addr branch November 5, 2020 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants