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

Configuring the beam-beam is not possible with a GPU context #450

Open
ColasDroin opened this issue Jan 11, 2024 · 2 comments
Open

Configuring the beam-beam is not possible with a GPU context #450

ColasDroin opened this issue Jan 11, 2024 · 2 comments

Comments

@ColasDroin
Copy link
Contributor

One can not call Multiline.configure_beambeam_interactions() if the corresponding collider uses trackers with a GPU context (cupy or opencl). Otherwise, the following error gets triggered.

Full stack trace

  File "/home/HPC/cdroin/example_DA_study_dev/master_study/scans/example_HL_tunescan/base_collider/xtrack_0029/2_configure_and_track.py", line 337, in configure_beam_beam
    collider.configure_beambeam_interactions(
  File "/usr/local/DA_study/miniforge_docker/lib/python3.10/site-packages/xtrack/multiline/multiline.py", line 484, in configure_beambeam_interactions
    xf.configure_beam_beam_elements(
  File "/usr/local/DA_study/miniforge_docker/lib/python3.10/site-packages/xfields/config_tools/beambeam_config_tools/config_tools.py", line 150, in configure_beam_beam_elements
    xf.configure_orbit_dependent_parameters_for_bb(line=line_cw,
  File "/usr/local/DA_study/miniforge_docker/lib/python3.10/site-packages/xfields/config_tools/beambeam_config_tools/orbit_dependent_configuration_tools.py", line 81, in configure_orbit_dependent_parameters_for_bb
    ee.track(temp_particles)
  File "/usr/local/DA_study/miniforge_docker/lib/python3.10/site-packages/xtrack/base_element.py", line 299, in track
    _track_kernel(el=self._xobject, particles=particles,
  File "/usr/local/DA_study/miniforge_docker/lib/python3.10/site-packages/xobjects/context_pyopencl.py", line 507, in __call__
    arg_list.append(self.to_function_arg(arg, vv))
  File "/usr/local/DA_study/miniforge_docker/lib/python3.10/site-packages/xobjects/context_pyopencl.py", line 490, in to_function_arg
    value._buffer.context is self.context
AssertionError: Incompatible context for argument `particles`

Apparently, a temporary particles object is instantiated in the stack trace with a CPU tracker, even when the collider uses a GPU tracker.

Easy workaround:

  • Build collider trackers with CPU context
  • Configure beam-beam
  • Discard trackers
  • Build trackers with GPU context
  • Build particles with GPU context
  • track
@giadarol
Copy link
Member

giadarol commented Jan 11, 2024

Thank you! This is in fact how it is intended to be used, since the twiss and survey that you use to configure the bb lenses are significantly slower on GPU (too few particles).

We should check the context when Multiline.configure_beambeam_interactions() is called and give a proper error message suggesting to move to CPU. @ColasDroin could you please make a PR with that modification?

If it is more convenient to generate the particles on CPU, you can do that and then use Particles.move to move them to the GPU memory.

@ColasDroin
Copy link
Contributor Author

Thank you for the quick answer!
As suggested, I did a PR with the xtrack repo to improve the error message here, and also another PR in the xmask repo to test for the new error message here.

Although the PRs are still open to change, I believe we can close the issue here.

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

No branches or pull requests

2 participants