Skip to content

Commit

Permalink
Single-thread debugging now possible.
Browse files Browse the repository at this point in the history
 * AdePT must be configured in Debug mode and DEBUG_SINGLE_THREAD=ON

 * Added colors to cmake messages.
  • Loading branch information
agheata committed Aug 14, 2024
1 parent 5d26d27 commit 65a325d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
# Options
option(ADEPT_USE_SURF "Enable surface model navigation on GPU" OFF)
option(ADEPT_USE_SURF_SINGLE "Use surface model in single precision" OFF)
option(DEBUG_SINGLE_THREAD "Run transport kernels in single thread mode" OFF)

#----------------------------------------------------------------------------#
# Dependencies
Expand All @@ -59,7 +60,7 @@ find_package(CUDAToolkit REQUIRED)
set(VecCore_VERSION 0.5.2)
set(VecCore_BACKEND CUDA)
find_package(VecCore ${VecCore_VERSION} REQUIRED COMPONENTS ${VecCore_BACKEND})
message(STATUS "Using VecCore version ${VecCore_VERSION}")
message(STATUS "Using VecCore version ${Cyan}${VecCore_VERSION}${ColorReset}")

# Before looking for other packages, try to find XercesC explicitly to avoid
# problems with G4HepEm not finding Geant4 11.1 even though we find it here.
Expand All @@ -75,32 +76,37 @@ endif()
if(VecGeom_VERSION_STRING STRLESS VecGeom_VERSION_REQ)
message(FATAL_ERROR "AdePT requires at least VecGeom ${VecGeom_VERSION_REQ}, found ${VecGeom_VERSION_STRING}" )
else()
message(STATUS "Using VecGeom version ${VecGeom_VERSION_STRING}")
message(STATUS "Using VecGeom version ${Cyan}${VecGeom_VERSION_STRING}${ColorReset}")
endif()
# Make sure VecGeom::vgdml is enabled
if(NOT TARGET VecGeom::vgdml)
message(FATAL_ERROR "AdePT requires VecGeom compiled with GDML support")
endif()
# Debugging in single-thread mode
if (DEBUG_SINGLE_THREAD)
add_compile_definitions("$<$<CONFIG:Debug>:DEBUG_SINGLE_THREAD>")
message(STATUS "${Magenta}Transport is running in single-thread mode${ColorReset}")
endif()
# Check for surface model support in VecGeom
if(ADEPT_USE_SURF)
if(VecGeom_SURF_FOUND)
if (ADEPT_USE_SURF_SINGLE)
message(STATUS "Surface model in VecGeom uses single precision")
message(STATUS "${Green}Surface model in VecGeom uses single precision${ColorReset}")
add_compile_definitions(ADEPT_USE_SURF_SINGLE)
else()
message(STATUS "Surface model in VecGeom uses double precision")
message(STATUS "${Green}Surface model in VecGeom uses double precision${ColorReset}")
endif()
add_compile_definitions(ADEPT_USE_SURF)
else()
message(STATUS "Forcing ADEPT_USE_SURF to OFF (surface support not found in VecGeom)")
message(STATUS "${Magenta}No VecGeom surface support. Forcing ADEPT_USE_SURF to OFF${ColorReset}")
set(ADEPT_USE_SURF OFF CACHE BOOL "Disable using the surface model" FORCE)
endif()
endif()

# Find Geant4, optional for now
find_package(Geant4 QUIET)
if(Geant4_FOUND)
message(STATUS "Using Geant4 version ${Geant4_VERSION} from ${Geant4_INCLUDE_DIRS}")
message(STATUS "Using Geant4 version ${Cyan}${Geant4_VERSION}${ColorReset} from ${Geant4_INCLUDE_DIRS}")
set(CMAKE_REQUIRED_INCLUDES ${Geant4_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${Geant4_LIBRARIES})
check_cxx_source_compiles("
Expand Down
22 changes: 22 additions & 0 deletions cmake/CMakeSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,25 @@ foreach(_conftype ${CMAKE_CONFIGURATION_TYPES})
)
endforeach()

# - Support for colors in cmake message.
# Credits: https://stackoverflow.com/questions/18968979/how-to-make-colorized-message-with-cmake
# Use:
# message("This is normal")
# message("${Red}This is Red${ColorReset}")
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(ColorBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
20 changes: 13 additions & 7 deletions include/AdePT/core/AdePTTransport.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,13 @@ void ShowerGPU(IntegrationLayer &integration, int event, adeptint::TrackBuffer &
gpuState.allmgr_h.trackmgr[ParticleType::Gamma]->fStats.fInFlight = buffer.ngammas;

constexpr float compactThreshold = 0.9;
constexpr int MaxBlocks = 1024;
constexpr int TransportThreads = 32;
int transportBlocks;

#ifdef DEBUG_SINGLE_THREAD
constexpr int TransportThreads = 1;
#else
constexpr int MaxBlocks = 1024;
constexpr int TransportThreads = 32;
#endif
int transportBlocks = 1;
int inFlight = 0;
int killed = 0;
int numLeaked = 0;
Expand Down Expand Up @@ -361,9 +364,10 @@ void ShowerGPU(IntegrationLayer &integration, int event, adeptint::TrackBuffer &
// *** ELECTRONS ***
int numElectrons = gpuState.allmgr_h.trackmgr[ParticleType::Electron]->fStats.fInFlight;
if (numElectrons > 0) {
#ifndef DEBUG_SINGLE_THREAD
transportBlocks = (numElectrons + TransportThreads - 1) / TransportThreads;
transportBlocks = std::min(transportBlocks, MaxBlocks);

#endif
TransportElectrons<AdeptScoring><<<transportBlocks, TransportThreads, 0, electrons.stream>>>(
electrons.trackmgr, secondaries, electrons.leakedTracks, scoring_dev,
VolAuxArray::GetInstance().fAuxData_dev);
Expand All @@ -375,9 +379,10 @@ void ShowerGPU(IntegrationLayer &integration, int event, adeptint::TrackBuffer &
// *** POSITRONS ***
int numPositrons = gpuState.allmgr_h.trackmgr[ParticleType::Positron]->fStats.fInFlight;
if (numPositrons > 0) {
#ifndef DEBUG_SINGLE_THREAD
transportBlocks = (numPositrons + TransportThreads - 1) / TransportThreads;
transportBlocks = std::min(transportBlocks, MaxBlocks);

#endif
TransportPositrons<AdeptScoring><<<transportBlocks, TransportThreads, 0, positrons.stream>>>(
positrons.trackmgr, secondaries, positrons.leakedTracks, scoring_dev,
VolAuxArray::GetInstance().fAuxData_dev);
Expand All @@ -389,9 +394,10 @@ void ShowerGPU(IntegrationLayer &integration, int event, adeptint::TrackBuffer &
// *** GAMMAS ***
int numGammas = gpuState.allmgr_h.trackmgr[ParticleType::Gamma]->fStats.fInFlight;
if (numGammas > 0) {
#ifndef DEBUG_SINGLE_THREAD
transportBlocks = (numGammas + TransportThreads - 1) / TransportThreads;
transportBlocks = std::min(transportBlocks, MaxBlocks);

#endif
TransportGammas<AdeptScoring><<<transportBlocks, TransportThreads, 0, gammas.stream>>>(
gammas.trackmgr, secondaries, gammas.leakedTracks, scoring_dev, VolAuxArray::GetInstance().fAuxData_dev);

Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ target_link_libraries(test_copcore_link PRIVATE CopCore)

# - Check G4VG links as expected
if(VecGeom_SURF_FOUND)
message(STATUS "Disabled g4vg when using VecGeom surface model")
message(STATUS "${Magenta}Disabled g4vg when using VecGeom surface model${ColorReset}")
else()
message(STATUS "Fetching and compiling g4vg ...")
include(FetchContent)
Expand Down

0 comments on commit 65a325d

Please sign in to comment.