|
|
|||
File indexing completed on 2026-11-07 10:11:44
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/user/ActionTimes.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <string> 0010 #include <unordered_map> 0011 #include <vector> 0012 0013 #include "corecel/Types.hh" 0014 #include "corecel/data/AuxInterface.hh" 0015 #include "corecel/data/AuxStateVec.hh" 0016 0017 namespace celeritas 0018 { 0019 class ActionRegistry; 0020 struct ActionTimesState; 0021 class AuxParamsRegistry; 0022 0023 //---------------------------------------------------------------------------// 0024 /*! 0025 * Manage state data for accumulating action times. 0026 * 0027 * This class allocates thread-local state data that can be used to accumulate 0028 * the time of each step action on each stream over the run. Because the class 0029 * that invokes the sequence of step actions should be shared across threads, 0030 * the action times are stored as auxiliary data rather than locally in that 0031 * class. 0032 * 0033 * \todo Add an end-gather action to merge across states? 0034 */ 0035 class ActionTimes : public AuxParamsInterface 0036 { 0037 public: 0038 //!@{ 0039 //! \name Type aliases 0040 using SPActionRegistry = std::shared_ptr<ActionRegistry>; 0041 using SPAuxParamsRegistry = std::shared_ptr<AuxParamsRegistry>; 0042 using MapStrDbl = std::unordered_map<std::string, double>; 0043 //!@} 0044 0045 public: 0046 // Construct and add to the aux registry 0047 static std::shared_ptr<ActionTimes> make_and_insert( 0048 SPActionRegistry const&, SPAuxParamsRegistry const&, std::string label); 0049 0050 // Construct from ID, actions and label 0051 ActionTimes(AuxId, SPActionRegistry const&, std::string label); 0052 0053 //!@{ 0054 //! \name Aux interface 0055 0056 //! Short name for the aux data 0057 std::string_view label() const final { return label_; } 0058 //! Index of this class instance in its registry 0059 AuxId aux_id() const final { return aux_id_; } 0060 // Build core state data for a stream 0061 UPState create_state(MemSpace, StreamId, size_type) const final; 0062 //!@} 0063 0064 // Access the state 0065 ActionTimesState const& state(AuxStateVec const&) const; 0066 0067 // Access the state (mutable) 0068 ActionTimesState& state(AuxStateVec&) const; 0069 0070 // Create a map of action label to accumulated time 0071 MapStrDbl get_action_times(AuxStateVec const&) const; 0072 0073 // Clear accumulated times 0074 void clear_action_times(AuxStateVec&) const; 0075 0076 private: 0077 AuxId aux_id_; 0078 std::weak_ptr<ActionRegistry> action_reg_; 0079 std::string label_; 0080 }; 0081 0082 //---------------------------------------------------------------------------// 0083 /*! 0084 * Accumulated action times on each thread. 0085 * 0086 * \todo Always report CPU times and add a second vector for device runs that 0087 * uses the CUDA event API to record GPU times. 0088 */ 0089 struct ActionTimesState : public AuxStateInterface 0090 { 0091 std::vector<double> accum_time; 0092 }; 0093 0094 //---------------------------------------------------------------------------// 0095 } // namespace celeritas
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|