Skip to content

Refactor AdePT into 2 libraries 5: Refactor G4HepEm data management, unify initialization#520

Open
SeverinDiederichs wants to merge 5 commits intoapt-sim:masterfrom
SeverinDiederichs:refactor_hepem_datamanagement
Open

Refactor AdePT into 2 libraries 5: Refactor G4HepEm data management, unify initialization#520
SeverinDiederichs wants to merge 5 commits intoapt-sim:masterfrom
SeverinDiederichs:refactor_hepem_datamanagement

Conversation

@SeverinDiederichs
Copy link
Collaborator

@SeverinDiederichs SeverinDiederichs commented Mar 18, 2026

This PR belongs to the refactor of AdePT described in #516.
This PR is baed on #521 and should not be reviewed before that one is merged.

This PR moves the G4HepEm host-data preparation out of AsyncAdePTTransport into a dedicated host-side helper and unifies the initialization.

Before the initialization was:

  1. Initialization of AdePTTransport. This created the G4HepEmState and uploaded already to the GPU
  2. Initialization of VecGeom and InitVolAuxData on CPU, using the G4HepEmState.
  3. Initialization of the rest on the GPU.

With this PR, the G4HepEm initialization is factored out of the AdePTTransport initialization.
This allows for a cleaner workflow:

  1. Initialize all the host data. The CheckGeometry and InitVolAuxData functions use the G4HepEmData directly that was prepared on the host
  2. Upload the host-initialized data to the GPU, which includes the G4HepEmData as well as geometry and InitVolAuxArray.

Until now, the transport rebuilt the HepEm host data internally and then also used it to steer the remaining host-side initialization. This made the initialization flow harder to follow and mixed host preparation with device-side transport setup.

The G4HepEm data is now factored out into a HepEmHostData class, which takes care of the initialization and life-time management.

It was verified that this PR

  • Changes physics results
  • Does not change physics results

@SeverinDiederichs SeverinDiederichs added the cleaning improves code clarity, readability or other label Mar 18, 2026
@phsft-bot
Copy link

Can one of the admins verify this patch?

@SeverinDiederichs SeverinDiederichs force-pushed the refactor_hepem_datamanagement branch from d523d78 to 959482a Compare March 19, 2026 07:25
@SeverinDiederichs SeverinDiederichs changed the title Refactor AdePT into 2 libraries 4: Refactor G4HepEm data management, unify initialization Refactor AdePT into 2 libraries 5: Refactor G4HepEm data management, unify initialization Mar 19, 2026
@SeverinDiederichs
Copy link
Collaborator Author

SeverinDiederichs commented Mar 19, 2026

Solved: Drift test with WDT failed, this needs to be investigated first.

The issue was the ownership of the G4HepEmParameters: while the G4HepEmData was created freshly for the AdePTTransport, the parameters were only borrowed from the owning G4 worker thread. This could cause a crash in the tear down, as other threads may finish later and it would cause a destruction order bug.

This is fixed by doing a deep copy of the G4HepEmParameters.

That means: each G4 worker owns a G4HepEmTrackingManager, which owns G4HepEmParameters. At the same time, the global AdePTTransport owns its own G4HepEmParameters, which it needs it for the GPU upload.

… it from worker, as data might be deleted before the AdePTTransport is
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleaning improves code clarity, readability or other

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants