Skip to content

Commit 5d8bdf8

Browse files
committed
Add new Example20 with interaction queues instead of SOAData
This revives an old concept from the toy examples 1, 2, and 4 (deleted in commit 9230c4a) to have one queue per discrete interaction. This appears to be equally fast as the quite complex scheduling kernel based on SOAData.
1 parent 1bc7c3d commit 5d8bdf8

File tree

9 files changed

+1864
-0
lines changed

9 files changed

+1864
-0
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_subdirectory(Example16)
2121
add_subdirectory(Example17)
2222
add_subdirectory(Example18)
2323
add_subdirectory(Example19)
24+
add_subdirectory(Example20)
2425
add_subdirectory(TestEm3)
2526
add_subdirectory(TestEm3MT)
2627
add_subdirectory(TestEm3Compact)

examples/Example20/CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: 2022 CERN
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
set(TargetName example20)
5+
6+
if(NOT TARGET G4HepEm::g4HepEm)
7+
message(STATUS "Disabling ${TargetName} (needs G4HepEm)")
8+
return()
9+
endif()
10+
11+
if(Geant4_FOUND)
12+
if(NOT Geant4_gdml_FOUND)
13+
message(STATUS "Disabling ${TargetName} (needs Geant4 with GDML support)")
14+
return()
15+
endif()
16+
else()
17+
message(STATUS "Disabling ${TargetName} (needs Geant4)")
18+
return()
19+
endif()
20+
21+
add_executable(${TargetName}
22+
main.cpp
23+
main.cu
24+
electrons.cu
25+
gammas.cu)
26+
target_link_libraries(${TargetName}
27+
PRIVATE
28+
AdePT
29+
CopCore::CopCore
30+
VecGeom::vecgeom
31+
VecGeom::vecgeomcuda_static
32+
VecGeom::vgdml
33+
${Geant4_LIBRARIES}
34+
G4HepEm::g4HepEmData
35+
G4HepEm::g4HepEmInit
36+
G4HepEm::g4HepEmRun
37+
CUDA::cudart)
38+
39+
set_target_properties(${TargetName} PROPERTIES CUDA_SEPARABLE_COMPILATION ON CUDA_RESOLVE_DEVICE_SYMBOLS ON)
40+
41+
# NVTX
42+
target_link_libraries(${TargetName} PRIVATE NVTX)
43+
44+
# Tests
45+
add_test(NAME ${TargetName}
46+
COMMAND $<TARGET_FILE:${TargetName}> -gdml_file ${CMAKE_BINARY_DIR}/cms2018.gdml)
47+

examples/Example20/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2022 CERN
3+
SPDX-License-Identifier: CC-BY-4.0
4+
-->
5+
6+
## Example 20
7+
8+
Example based on Example 19, but smaller kernels are fed with queues instead of the `SOAData` structure.
9+
10+
* arbitrary geometry via gdml file (tested with cms2018.gdml from VecGeom persistency/gdml/gdmls folder) and optionally a magnetic field with constant Bz,
11+
* geometry read as Geant4 geometry, reading in regions and cuts, to initialize G4HepEm data
12+
* geometry read then into VecGeom, and synchronized to GPU
13+
* G4HepEm material-cuts couple indices mapped to VecGeom logical volume id's
14+
* physics processes for e-/e+ (including MSC) and gammas using G4HepEm.
15+
* scoring per placed volume, no sensitive detector feature
16+
* configurable particle gun via command line arguments
17+
* E.g., use `-gunpos -220,0,0 -gundir 1,0,0` for `testEm3.gdml`. For `cms2018.gdml`, the default gun is correct.
18+
19+
Electrons, positrons, and gammas are stored in separate containers in device memory.
20+
Free positions in the storage are handed out with monotonic slot numbers, slots are not reused.
21+
Active tracks are passed via three queues per particle type (see `struct ParticleQueues`).
22+
Results are reproducible using one RANLUX++ state per track.
23+
24+
Additionally, the kernels score energy deposit and the charged track length per volume.
25+
26+
### Kernels
27+
28+
This example uses one stream per particle type to launch kernels asynchronously.
29+
They are synchronized via a fourth stream using CUDA events.
30+
31+
#### `TransportElectrons<bool IsElectron>`
32+
33+
1. Obtain safety unless the track is currently on a boundary.
34+
2. Determine physics step limit, including conversion to geometric step length according to MSC.
35+
3. Query geometry (or optionally magnetic field) to get geometry step length.
36+
4. Convert geometry to true step length according to MSC, apply net direction change and displacement.
37+
5. Apply continuous effects; kill track if stopped.
38+
6. If the particle reaches a boundary, perform relocation.
39+
7. If not, and if there is a discrete process, hand over to interaction kernel.
40+
41+
#### `TransportGammas`
42+
43+
1. Determine the physics step limit.
44+
2. Query VecGeom to get geometry step length (no magnetic field for neutral particles!).
45+
3. If the particle reaches a boundary, perform relocation.
46+
4. If not, and if there is a discrete process, hand over to interaction kernel.
47+
48+
#### Interaction kernels
49+
In electrons.cu and gammas.cu, there is dedicated kernels for all discrete processes. These were
50+
extracted from the main transport kernels in example18.
51+
1. Sample the final state.
52+
2. Update the primary and produce secondaries.
53+
54+
#### `FinishIteration`
55+
56+
Clear the queues and return the tracks in flight.
57+
This kernel runs after all secondary particles were produced.
58+
59+
#### `InitPrimaries` and `InitParticleQueues`
60+
61+
Used to initialize multiple primary particles with separate seeds.

0 commit comments

Comments
 (0)