Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:22

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