diff --git a/main/include/AllenMonitoring.h b/main/include/AllenMonitoring.h index b52c379aa5e27a2d03ff75a45f1d95684cfdd84d..fd4b91893053ca9729c9c9356be6573053ed92cd 100644 --- a/main/include/AllenMonitoring.h +++ b/main/include/AllenMonitoring.h @@ -26,6 +26,9 @@ namespace Allen::Monitoring { template<typename T> struct Counter; + template<typename T> + struct AveragingCounter; + struct AccumulatorInfosAndPointers { std::size_t offset {0}; std::size_t size {0}; @@ -98,6 +101,7 @@ namespace Allen::Monitoring { void registerAccumulator(AccumulatorBase* acc); void registerCounter(Counter<unsigned>* c) { m_counters.push_back(c); } + void registerAveragingCounter(AveragingCounter<unsigned>* c) { m_av_counters.push_back(c); } void initAccumulators(unsigned number_of_streams); void mergeAndReset(bool singlethreaded = false); char* bufferForStream(unsigned stream_id) const { return m_dev_buffer_ptr[m_stream_current_buffer[stream_id]]; } @@ -124,6 +128,7 @@ namespace Allen::Monitoring { std::vector<AccumulatorBase*> m_registered_accumulators; std::vector<Counter<unsigned>*> m_counters; + std::vector<AveragingCounter<unsigned>*> m_av_counters; std::map<std::string, AccumulatorInfosAndPointers> m_accumulators; }; @@ -251,7 +256,10 @@ namespace Allen::Monitoring { using type = T; using DeviceType = DeviceAveragingCounter<T>; - AveragingCounter(const Allen::Algorithm* owner, std::string name) : AccumulatorBase(owner, name) {} + AveragingCounter(const Allen::Algorithm* owner, std::string name) : AccumulatorBase(owner, name) + { + if constexpr (std::is_same<T, unsigned>::value) AccumulatorManager::get()->registerAveragingCounter(this); + } std::size_t size() const override { return 2; } std::size_t elementSize() const override { return sizeof(T); } DeviceType data(const Allen::Context& ctx) const { return reinterpret_cast<T*>(currentDevicePtr(ctx.stream_id)); } diff --git a/main/src/AllenMonitoring.cpp b/main/src/AllenMonitoring.cpp index 80b01e67208a77f8dc3d766e0e8ab2741dfe7bf1..34dde5382a4bb1bcc41089ec5509de6ad5b13dff 100644 --- a/main/src/AllenMonitoring.cpp +++ b/main/src/AllenMonitoring.cpp @@ -30,6 +30,10 @@ namespace Allen::Monitoring { m_counters_histogram.addCounter(counter->uniqueName()); } + for (auto counter : m_av_counters) { + m_counters_histogram.addCounter(counter->uniqueName()); + } + m_counters_histogram.registerHistogram(); // Algorithms have finished their initializations for all streams @@ -109,5 +113,10 @@ namespace Allen::Monitoring { m_counters_histogram.updateBin(counter_index, counter->m_entries); counter_index++; } + + for (auto counter : m_av_counters) { + m_counters_histogram.updateBin(counter_index, static_cast<unsigned>(counter->m_sum / counter->m_entries)); + counter_index++; + } } } // namespace Allen::Monitoring