Skip to content

Move initialization of General and UniformMagneticField to InitializeGPU#467

Merged
JuanGonzalezCaminero merged 1 commit intoapt-sim:masterfrom
JuanGonzalezCaminero:gmfield
Jan 13, 2026
Merged

Move initialization of General and UniformMagneticField to InitializeGPU#467
JuanGonzalezCaminero merged 1 commit intoapt-sim:masterfrom
JuanGonzalezCaminero:gmfield

Conversation

@JuanGonzalezCaminero
Copy link
Copy Markdown
Contributor

@JuanGonzalezCaminero JuanGonzalezCaminero commented Jan 8, 2026

GeneralMagneticField.h was being included by non-CUDA headers, and compiled by gcc, despite containing CUDA API calls and __device__ functions. This worked since, for the API calls, the correct headers and library were provided, so the linking was done correctly, and for the __device__ functions since the copcore Macros.h header defines the __host__ and __device__ keywords when compiling with gcc.
These functions would not work when called from host however, but this was never done, GeneralMagneticField.h was also being compiled by nvcc in a different translation unit, and the correct versions of these functions were linked with the kernels using them.

The file has been renamed to GeneralMagneticField.cuh, and the initialization moved to InitializeGPU in AdePTTransport.cuh and AsyncAdePTTransport.cuh, the pointer to the general magnetic field, which was held by the host instance of AdePT Transport, is now stored by GPUState.

The same situation occurred with UniformMagneticField.h, which has now also been renamed and its initialization moved.

@phsft-bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@JuanGonzalezCaminero JuanGonzalezCaminero force-pushed the gmfield branch 3 times, most recently from 1a55794 to e8bb5b7 Compare January 13, 2026 09:18
@JuanGonzalezCaminero JuanGonzalezCaminero changed the title Move initialization of GeneralMagneticField to InitializeGPU Move initialization of General and UniformMagneticField to InitializeGPU Jan 13, 2026
Copy link
Copy Markdown
Collaborator

@SeverinDiederichs SeverinDiederichs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleaning!
See two very minor leftovers

Comment thread include/AdePT/core/AsyncAdePTTransport.hh Outdated
Comment thread include/AdePT/magneticfield/UniformMagneticField.cuh Outdated
@SeverinDiederichs SeverinDiederichs added the cleaning improves code clarity, readability or other label Jan 13, 2026
@JuanGonzalezCaminero JuanGonzalezCaminero merged commit 1183007 into apt-sim:master Jan 13, 2026
3 checks passed
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.

3 participants