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

Allow geometry selection independent of VecGeom being enabled #726

Merged
merged 19 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 30 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ endif()
if(CMAKE_VERSION VERSION_LESS 3.22 AND CELERITAS_USE_HIP)
message(WARNING "HIP support is immature; CMake 3.22+ is recommended.")
endif()
if(CELERITAS_USE_HIP AND CELERITAS_USE_VecGeom)
message(SEND_ERROR "HIP is incompatible with VecGeom.")
endif()

# Library
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
Expand All @@ -104,27 +101,23 @@ if(DEFINED CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE)
unset(_default_build_type)
endif()

# RNG selection
set(CELERITAS_RNG_OPTIONS XORWOW)
if(CELERITAS_USE_CUDA)
list(APPEND CELERITAS_RNG_OPTIONS CURAND)
elseif(CELERITAS_USE_HIP)
list(APPEND CELERITAS_RNG_OPTIONS HIPRAND)
elseif(NOT (CELERITAS_USE_CUDA OR CELERITAS_USE_HIP))
# TODO: allow wrapper to standard library RNG when not building for device?
# TODO: maybe even add wrapper to Geant4 RNG??
endif()
list(GET CELERITAS_RNG_OPTIONS 0 _DEFAULT_RNG)
set(CELERITAS_RNG "${_DEFAULT_RNG}" CACHE STRING
# Define CELERITAS_CORE_RNG option for random number generator selection
celeritas_setup_option(CELERITAS_CORE_RNG xorwow)
celeritas_setup_option(CELERITAS_CORE_RNG cuRAND CELERITAS_USE_CUDA)
celeritas_setup_option(CELERITAS_CORE_RNG hipRAND CELERITAS_USE_HIP)
# TODO: allow wrapper to standard library RNG when not building for device?
# TODO: maybe even add wrapper to Geant4 RNG??
celeritas_define_options(CELERITAS_CORE_RNG
"Celeritas runtime random number generator")
set_property(CACHE CELERITAS_RNG PROPERTY STRINGS "${CELERITAS_RNG_OPTIONS}")
list(FIND CELERITAS_RNG_OPTIONS "${CELERITAS_RNG}" _rng_index)
if(_rng_index EQUAL -1)
message(SEND_ERROR "Invalid value CELERITAS_RNG=${CELERITAS_RNG}: must be "
"${CELERITAS_RNG_OPTIONS}; overriding for next configure")
set(CELERITAS_RNG "${_DEFAULT_RNG}" CACHE STRING
"Celeritas runtime random number generator" FORCE)

# Runtime geometry selection: default to VecGeom if available
set(_allow_vecgeom FALSE)
if(CELERITAS_USE_VecGeom AND NOT CELERITAS_USE_HIP)
set(_allow_vecgeom TRUE)
endif()
celeritas_setup_option(CELERITAS_CORE_GEO VecGeom _allow_vecgeom)
celeritas_setup_option(CELERITAS_CORE_GEO ORANGE)
celeritas_define_options(CELERITAS_CORE_GEO "Celeritas runtime geometry")

cmake_dependent_option(CELERITAS_LAUNCH_BOUNDS
"Use kernel launch bounds generated from launch-bounds.json" "OFF"
Expand Down Expand Up @@ -223,10 +216,11 @@ endif()
if(CELERITAS_USE_VecGeom)
find_package(VecGeom 1.1.17 REQUIRED)

if((CELERITAS_USE_CUDA AND NOT VecGeom_CUDA_FOUND))
message(SEND_ERROR "CUDA mismatch between the VecGeom installation "
"at ${VECGEOM_INSTALL_DIR} (VecGeom_CUDA_FOUND=${VecGeom_CUDA_FOUND}) "
"and Celeritas (CELERITAS_USE_CUDA=${CELERITAS_USE_CUDA})"
if(CELERITAS_USE_CUDA AND NOT VecGeom_CUDA_FOUND)
celeritas_error_incompatible_option(
"VecGeom installation at ${VECGEOM_INSTALL_DIR} is not CUDA-enabled"
CELERITAS_USE_CUDA
"${VecGeom_CUDA_FOUND}"
)
endif()
if(NOT VecGeom_GDML_FOUND)
Expand All @@ -238,10 +232,11 @@ if(CELERITAS_BUILD_TESTS AND NOT GTest_FOUND)
# TODO: download and build GTest as a subproject if not available
find_package(GTest)
if(NOT GTest_FOUND)
message(SEND_ERROR "Googletest (GTest) is required for testing: setting "
"CELERITAS_BUILD_TESTS=OFF for next build")
set(CELERITAS_BUILD_TESTS OFF CACHE BOOL
"Disabled because of missing GTest" FORCE)
celeritas_error_incompatible_option(
"Googletest (GTest) is required for testing but was not found"
CELERITAS_BUILD_TESTS
OFF
)
endif()
endif()

Expand All @@ -263,10 +258,11 @@ if(CELERITAS_BUILD_DOCS)
endif()
endif()
if(NOT Doxygen_FOUND)
message(SEND_ERROR "Doxygen is required for building documentation: setting "
"CELERITAS_BUILD_DOCS=OFF for next build")
set(CELERITAS_BUILD_DOCS OFF CACHE BOOL
"Disabled because of missing Doxygen" FORCE)
celeritas_error_incompatible_option(
"Doxygen is required for building documentation but was not found"
CELERITAS_BUILD_DOCS
OFF
)
endif()
endif()

Expand Down
27 changes: 17 additions & 10 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,22 @@ endif()
# DEMO: geometry tracking
#-----------------------------------------------------------------------------#

if(CELERITAS_BUILD_DEMOS AND CELERITAS_USE_CUDA AND CELERITAS_USE_VecGeom)
if(CELERITAS_BUILD_DEMOS AND CELERITAS_USE_CUDA)
add_executable(demo-rasterizer
demo-rasterizer/demo-rasterizer.cc
demo-rasterizer/RDemoRunner.cc
demo-rasterizer/RDemoKernel.cu
demo-rasterizer/ImageIO.cc
demo-rasterizer/ImageStore.cc
)
celeritas_target_link_libraries(demo-rasterizer
set(_rasterizer_libs
Celeritas::celeritas
nlohmann_json::nlohmann_json
VecGeom::vecgeom
)
if(CELERITAS_CORE_GEO STREQUAL "VecGeom")
list(APPEND _rasterizer_libs VecGeom::vecgeom)
endif()
celeritas_target_link_libraries(demo-rasterizer ${_rasterizer_libs})

if(CELERITAS_BUILD_TESTS)
set(_driver "${CMAKE_CURRENT_SOURCE_DIR}/demo-rasterizer/simple-driver.py")
Expand All @@ -203,6 +206,12 @@ if(CELERITAS_BUILD_DEMOS AND CELERITAS_USE_CUDA AND CELERITAS_USE_VecGeom)
REQUIRED_FILES "${_driver};${_gdml_inp}"
LABELS "app;nomemcheck;gpu"
)
if(NOT CELERITAS_CORE_GEO STREQUAL "VecGeom")
# two-boxes.org.json isn't set up in the test directory
set_tests_properties("app/demo-rasterizer" PROPERTIES
DISABLED true
)
endif()
endif()
endif()

Expand Down Expand Up @@ -233,7 +242,7 @@ if(CELERITAS_BUILD_DEMOS)
nlohmann_json::nlohmann_json
Celeritas::DeviceToolkit
)
if(CELERITAS_USE_CUDA AND CELERITAS_USE_VecGeom)
if(CELERITAS_USE_CUDA AND CELERITAS_CORE_GEO STREQUAL "VecGeom")
list(APPEND _demo_loop_libs VecGeom::vecgeom)
endif()
if(CELERITAS_USE_OpenMP)
Expand Down Expand Up @@ -275,7 +284,7 @@ if(CELERITAS_BUILD_DEMOS)
"${_geant_exporter_env}"
"CELER_DISABLE_PARALLEL=1"
)
if(NOT CELERITAS_USE_VecGeom)
if(NOT CELERITAS_CORE_GEO STREQUAL "VecGeom")
list(APPEND _env "CELER_DISABLE_VECGEOM=1")
endif()
set_tests_properties("app/demo-loop" PROPERTIES
Expand All @@ -286,8 +295,6 @@ if(CELERITAS_BUILD_DEMOS)
)

# Disable test when prereqs are not available
# Note that this test has been known to fail for CUDA architecture 3.5
# when using VecGeom and a debug build
if(NOT (CELERITAS_USE_CUDA OR CELERITAS_USE_HIP)
OR NOT CELERITAS_USE_Geant4
OR NOT CELERITAS_USE_HepMC3
Expand All @@ -314,7 +321,7 @@ if(CELERITAS_BUILD_DEMOS)
"CELER_DISABLE_PARALLEL=1"
${_omp_env}
)
if(NOT CELERITAS_USE_VecGeom)
if(NOT CELERITAS_CORE_GEO STREQUAL "VecGeom")
list(APPEND _env "CELER_DISABLE_VECGEOM=1")
endif()
set_tests_properties("app/demo-loop-cpu" PROPERTIES
Expand Down Expand Up @@ -465,7 +472,7 @@ if(CELERITAS_BUILD_DEMOS)
nlohmann_json::nlohmann_json
Celeritas::DeviceToolkit
)
if(CELERITAS_USE_VecGeom)
if(CELERITAS_CORE_GEO STREQUAL "VecGeom")
list(APPEND _geo_check_libs VecGeom::vecgeom)
endif()

Expand All @@ -486,7 +493,7 @@ if(CELERITAS_BUILD_DEMOS)
RESOURCE_LOCK gpu
LABELS "app;gpu"
)
if (NOT (CELERITAS_USE_VecGeom AND CELERITAS_USE_CUDA))
if(NOT (CELERITAS_CORE_GEO STREQUAL "VecGeom" AND CELERITAS_USE_CUDA))
set_tests_properties("app/geo-check" PROPERTIES
DISABLED true
)
Expand Down
2 changes: 1 addition & 1 deletion app/demo-geant-integration/RunAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void RunAction::BeginOfRunAction(G4Run const* run)
{
// This worker (or master thread) is responsible for initializing
// celeritas
if (!CELERITAS_USE_VECGEOM)
if (CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_ORANGE)
{
// To allow ORANGE to work for testing purposes, pass the GDML
// input filename to Celeritas
Expand Down
4 changes: 2 additions & 2 deletions app/demo-loop/diagnostic/EnergyDiagnostic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ EnergyDiagnosticLauncher<M>::operator()(TrackSlotId tid) const
// Create grid from EnergyBinPointers
celeritas::NonuniformGrid<real_type> grid(pointers_.bounds);

#if CELERITAS_USE_VECGEOM
#if CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_VECGEOM
real_type pos = states_.geometry.pos[tid][static_cast<int>(pointers_.axis)];
#else
celeritas::LevelStateAccessor lsa(
Expand All @@ -251,7 +251,7 @@ EnergyDiagnosticLauncher<M>::operator()(TrackSlotId tid) const
// XXX at the time being the "step" we've hacked into here may not be
// the same as the geometry step or the true step.

#if CELERITAS_USE_VECGEOM
#if CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_VECGEOM
real_type dir
= states_.geometry.dir[tid][static_cast<int>(pointers_.axis)];
#else
Expand Down
4 changes: 2 additions & 2 deletions app/geo-check/GCheckKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ __global__ void gcheck_kernel(const GeoParamsCRefDevice params,
// KERNEL INTERFACE
//---------------------------------------------------------------------------//
/*!
* Run tracking on the GPU
* Run tracking on the GPU.
*/
GCheckOutput run_gpu(GCheckInput input)
GCheckOutput run_gpu(GCheckInput const& input)
{
CELER_EXPECT(input.params);
CELER_EXPECT(input.state);
Expand Down
6 changes: 3 additions & 3 deletions app/geo-check/GCheckKernel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ CELER_FORCEINLINE_FUNCTION int physid(celeritas::GeoTrackView const& geo)
{
if (geo.is_outside())
return 0;
#if CELERITAS_USE_VECGEOM
#if CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_VECGEOM
return geo.volume_physid();
#else
return geo.volume_id().get();
Expand All @@ -66,10 +66,10 @@ GCheckOutput run_cpu(SPConstGeo const& geo_params,
int max_steps);

//! Run tracking on the GPU
GCheckOutput run_gpu(GCheckInput init);
GCheckOutput run_gpu(GCheckInput const& init);

#if !CELERITAS_USE_CUDA
inline GCheckOutput run_gpu(GCheckInput)
inline GCheckOutput run_gpu(GCheckInput const&)
{
CELER_NOT_CONFIGURED("CUDA");
}
Expand Down
4 changes: 2 additions & 2 deletions cmake/CeleritasAddTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function(celeritas_add_test SOURCE_FILE)
${ARGN}
)
if(PARSE_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Unknown keywords given to scale_add_regression_tests(): "
message(SEND_ERROR "Unknown keywords given to celeritas_add_test(): "
"\"${PARSE_UNPARSED_ARGUMENTS}\"")
endif()

Expand All @@ -262,7 +262,7 @@ function(celeritas_add_test SOURCE_FILE)
endif()

if(PARSE_INPUTS)
message(FATAL_ERROR "INPUTS argument to celeritas_add_test is not implemented" )
message(FATAL_ERROR "INPUTS argument to celeritas_add_test is not implemented")
endif()

if(NOT PARSE_NP)
Expand Down
3 changes: 1 addition & 2 deletions cmake/CeleritasConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ endif()
if(CELERITAS_USE_VecGeom)
find_dependency(VecGeom @VecGeom_VERSION@ REQUIRED)

if((CELERITAS_USE_CUDA AND NOT VecGeom_CUDA_FOUND)
OR (NOT CELERITAS_USE_CUDA AND VecGeom_CUDA_FOUND))
if(CELERITAS_USE_CUDA AND NOT VecGeom_CUDA_FOUND)
message(SEND_ERROR "CUDA mismatch between the VecGeom installation "
"at ${VECGEOM_INSTALL_DIR} (VecGeom_CUDA_FOUND=${VecGeom_CUDA_FOUND}) "
"and Celeritas (CELERITAS_USE_CUDA=${CELERITAS_USE_CUDA})"
Expand Down
Loading