Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:39

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/global/detail/CoreStateThreadOffsets.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Types.hh"
0010 #include "corecel/data/Collection.hh"
0011 #include "corecel/data/CollectionBuilder.hh"
0012 #include "corecel/sys/ThreadId.hh"
0013 #include "celeritas/Types.hh"
0014 
0015 namespace celeritas
0016 {
0017 namespace detail
0018 {
0019 //---------------------------------------------------------------------------//
0020 template<MemSpace M>
0021 class CoreStateThreadOffsets;
0022 
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Holds Collections used by CoreState to store thread offsets.
0026  *
0027  * Note that \c ActionThreads is not "actions by thread" but is "threads by
0028  * action": it's indexed into using the action ID, and its value is the thread
0029  * ID at which the sorted state vector begins having an action.
0030  */
0031 template<>
0032 class CoreStateThreadOffsets<MemSpace::host>
0033 {
0034   public:
0035     //!@{
0036     //! \name Type aliases
0037     using NativeActionThreads
0038         = Collection<ThreadId, Ownership::value, MemSpace::host, ActionId>;
0039     using HostActionThreads = NativeActionThreads;
0040     //!@}
0041 
0042   public:
0043     auto& host_action_thread_offsets() { return thread_offsets_; }
0044     auto const& host_action_thread_offsets() const { return thread_offsets_; }
0045     auto& native_action_thread_offsets() { return thread_offsets_; }
0046     auto const& native_action_thread_offsets() const
0047     {
0048         return thread_offsets_;
0049     }
0050 
0051     //! Initialize using the number of actions
0052     void resize(size_type n) { celeritas::resize(&thread_offsets_, n); }
0053 
0054     //! Whether any offsets are present
0055     bool empty() const { return thread_offsets_.empty(); }
0056 
0057   private:
0058     NativeActionThreads thread_offsets_;
0059 };
0060 
0061 //---------------------------------------------------------------------------//
0062 /*!
0063  * Holds Collections used by CoreState to store thread offsets.
0064  *
0065  * This is specialized for device memory space as two collections are needed,
0066  * one for the host and one for the device. Using pinned mapped memory would be
0067  * less efficient.
0068  */
0069 template<>
0070 class CoreStateThreadOffsets<MemSpace::device>
0071 {
0072   public:
0073     //!@{
0074     //! \name Type aliases
0075     using NativeActionThreads
0076         = Collection<ThreadId, Ownership::value, MemSpace::device, ActionId>;
0077     using HostActionThreads
0078         = Collection<ThreadId, Ownership::value, MemSpace::mapped, ActionId>;
0079     //!@}
0080 
0081   public:
0082     auto& host_action_thread_offsets() { return host_thread_offsets_; }
0083     auto const& host_action_thread_offsets() const
0084     {
0085         return host_thread_offsets_;
0086     }
0087     auto& native_action_thread_offsets() { return thread_offsets_; }
0088     auto const& native_action_thread_offsets() const
0089     {
0090         return thread_offsets_;
0091     }
0092     void resize(size_type n)
0093     {
0094         celeritas::resize(&thread_offsets_, n);
0095         celeritas::resize(&host_thread_offsets_, n);
0096     }
0097 
0098     //! Whether any offsets are present
0099     bool empty() const { return thread_offsets_.empty(); }
0100 
0101   private:
0102     NativeActionThreads thread_offsets_;
0103     HostActionThreads host_thread_offsets_;
0104 };
0105 
0106 //---------------------------------------------------------------------------//
0107 }  // namespace detail
0108 }  // namespace celeritas