Skip to content

Commit

Permalink
Add support for Geant4 navigator through offload interface (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj authored Jan 10, 2025
1 parent 56a2ea5 commit 96d4e58
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-spack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ jobs:
${{
( (matrix.special == 'minimal')
|| (matrix.special == 'float')
|| (matrix.geometry == 'geant4')
|| !matrix.geant
) && '1' || ''
}}
Expand Down
2 changes: 1 addition & 1 deletion app/celer-g4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if(NOT CELERITAS_USE_HepMC3 OR NOT CELERITAS_USE_Geant4)
set(_props DISABLED true)
endif()
if(CELERITAS_CORE_GEO STREQUAL "Geant4")
# FIXME: geant4 navigator doesn't work at scale, nor through accel
# FIXME: geant4 navigator doesn't work with field navigator
set(_props DISABLED true)
endif()
if(CELERITAS_REAL_TYPE STREQUAL "float")
Expand Down
26 changes: 15 additions & 11 deletions src/accel/LocalTransporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,6 @@ LocalTransporter::LocalTransporter(SetupOptions const& options,
}
}

if (CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_GEANT4)
{
/*!
* \todo Add support for Geant4 navigation wrapper, which requires
* calling \c state.ref().geometry.reset() on the local transporter
* thread due to thread-allocated navigator data.
*/
CELER_NOT_IMPLEMENTED(
"offloading when using Celeritas Geant4 navigation wrapper");
}

// Create hit processor on the local thread so that it's deallocated when
// this object is destroyed
StreamId stream_id{static_cast<size_type>(thread_id)};
Expand All @@ -168,6 +157,8 @@ LocalTransporter::LocalTransporter(SetupOptions const& options,

// Save state for reductions at the end
params.set_state(stream_id.get(), step_->sp_state());

CELER_ENSURE(*this);
}

//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -311,6 +302,19 @@ void LocalTransporter::Finalize()
<< "offloaded tracks (" << buffer_.size()
<< " in buffer) were not flushed");

if constexpr (CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_GEANT4)
{
// Geant4 navigation states *MUST* be deallocated on the thread in
// which they're allocated
auto state = std::dynamic_pointer_cast<CoreState<MemSpace::host>>(
step_->sp_state());
CELER_ASSERT(state);
#if CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_GEANT4
CELER_LOG_LOCAL(debug) << "Deallocating navigation states";
state->ref().geometry.reset();
#endif
}

// Reset all data
CELER_LOG_LOCAL(debug) << "Resetting local transporter";
*this = {};
Expand Down
6 changes: 4 additions & 2 deletions src/accel/detail/HitManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ HitManager::HitManager(SPConstGeo geo,
}
}

// Hit processors *must* be allocated on the thread they're used because of
// geant4 thread-local SDs. There must be one per thread.
// Hit processors MUST be allocated on the thread they're used because of
// geant4 thread-local SDs. They MUST also be DEallocated on the same
// thread they're created due to Geant4 thread-local allocators.
// There must be one hit processor per thread.
processor_weakptrs_.resize(num_streams);
processors_.resize(num_streams);

Expand Down

0 comments on commit 96d4e58

Please sign in to comment.