bef14ad1b2
* Support for binary temporary files * clang formatting * formating ring buffer.hpp * Update source/lib/common/container/ring_buffer.hpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fixing bugs * fix loop range * Fix for v3 test failures * bug fix * fix bug * fix memory leaks * destructing agent_info * Update CMakeLists.txt * clang-tidy fixes * Fix data race on destructor of rocprofiler_agent_t map in rocprofiler-sdk-tool library * Create lib/rocproifler-sdk-tool/tmp_file.* - move tmp_file class into separate header/implementation * Agent Info CSV in rocprofiler-sdk-tool - update tests to use agent_info.csv instead of rocminfo * Update lib/rocprofiler-sdk-tool/tool.cpp - use logical_node_id instead of node_id * Adding stats file * Adding tests for stats * Update scratch memory support - convert scratch memory support to use binary output * Tool Update: scratch memory stats + extended statistics - replace generate_*_csv with generate_csv overloads - added generate_csv for scratch memory - enable stats for scratch memory - replace ROCPROF_*_STATS env variables with ROCPROF_STATS env variable * rocprofv3 update - simple --stats option - add scratch memory trace to --sys-trace * Update tests/rocprofv3/tracing-hip-in-libraries - extend validate.py to test stats data - fix conftest.py for memory_copy_stats_data * Code coverage fixes - invoke __gcov_dump to ensure that code coverage is flushed after finalization --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Ammar ELWazir <ammar.elwazir@amd.com> Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
232 строки
6.2 KiB
C++
232 строки
6.2 KiB
C++
// MIT License
|
|
//
|
|
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
// copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
// SOFTWARE.
|
|
|
|
#pragma once
|
|
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <iomanip>
|
|
#include <iostream>
|
|
#include <limits>
|
|
#include <type_traits>
|
|
|
|
namespace rocprofiler
|
|
{
|
|
namespace tool
|
|
{
|
|
/// \struct statistics
|
|
/// \tparam Tp data type for statistical accumulation
|
|
/// \tparam Fp floating point data type to use for division
|
|
/// \brief A generic class for statistical accumulation.
|
|
///
|
|
template <typename Tp, typename Fp = double>
|
|
struct statistics
|
|
{
|
|
public:
|
|
using value_type = Tp;
|
|
using float_type = Fp;
|
|
using this_type = statistics<Tp, Fp>;
|
|
static_assert(std::is_arithmetic<Tp>::value, "only supports arithmetic types");
|
|
|
|
public:
|
|
inline statistics() = default;
|
|
inline ~statistics() = default;
|
|
inline statistics(const statistics&) = default;
|
|
inline statistics(statistics&&) noexcept = default;
|
|
inline statistics& operator=(const statistics&) = default;
|
|
inline statistics& operator=(statistics&&) noexcept = default;
|
|
|
|
explicit statistics(value_type val)
|
|
: m_cnt(1)
|
|
, m_sum(val)
|
|
, m_sqr(val * val)
|
|
, m_min(val)
|
|
, m_max(val)
|
|
{}
|
|
|
|
statistics& operator=(value_type val)
|
|
{
|
|
m_cnt = 1;
|
|
m_sum = val;
|
|
m_min = val;
|
|
m_max = val;
|
|
m_sqr = (val * val);
|
|
return *this;
|
|
}
|
|
|
|
public:
|
|
// Accumulated values
|
|
inline int64_t get_count() const { return m_cnt; }
|
|
inline value_type get_min() const { return m_min; }
|
|
inline value_type get_max() const { return m_max; }
|
|
inline value_type get_sum() const { return m_sum; }
|
|
inline value_type get_sqr() const { return m_sqr; }
|
|
inline float_type get_mean() const { return static_cast<float_type>(m_sum) / m_cnt; }
|
|
inline float_type get_variance() const
|
|
{
|
|
if(m_cnt < 2) return (m_sum - m_sum);
|
|
|
|
auto _sum_of_squared_samples = m_sqr;
|
|
auto _sum_squared_mean = (m_sum * m_sum) / static_cast<float_type>(m_cnt);
|
|
return (_sum_of_squared_samples - _sum_squared_mean) / static_cast<float_type>(m_cnt - 1);
|
|
}
|
|
|
|
inline float_type get_stddev() const { return ::std::sqrt(::std::abs(get_variance())); }
|
|
|
|
// Modifications
|
|
inline void reset()
|
|
{
|
|
m_cnt = 0;
|
|
m_sum = value_type{};
|
|
m_sqr = value_type{};
|
|
m_min = value_type{};
|
|
m_max = value_type{};
|
|
}
|
|
|
|
public:
|
|
// Operators (value_type)
|
|
inline statistics& operator+=(value_type val)
|
|
{
|
|
if(m_cnt == 0)
|
|
{
|
|
m_sum = val;
|
|
m_sqr = (val * val);
|
|
m_min = val;
|
|
m_max = val;
|
|
}
|
|
else
|
|
{
|
|
m_sum += val;
|
|
m_sqr += (val * val);
|
|
m_min = ::std::min(m_min, val);
|
|
m_max = ::std::max(m_max, val);
|
|
}
|
|
++m_cnt;
|
|
|
|
return *this;
|
|
}
|
|
|
|
inline statistics& operator-=(value_type val)
|
|
{
|
|
if(m_cnt > 1) --m_cnt;
|
|
m_sum -= val;
|
|
m_sqr -= (val * val);
|
|
m_min -= val;
|
|
m_max -= val;
|
|
return *this;
|
|
}
|
|
|
|
inline statistics& operator*=(value_type val)
|
|
{
|
|
m_sum *= val;
|
|
m_sqr *= (val * val);
|
|
m_min *= val;
|
|
m_max *= val;
|
|
return *this;
|
|
}
|
|
|
|
inline statistics& operator/=(value_type val)
|
|
{
|
|
m_sum /= val;
|
|
m_sqr /= (val * val);
|
|
m_min /= val;
|
|
m_max /= val;
|
|
return *this;
|
|
}
|
|
|
|
public:
|
|
// Operators (this_type)
|
|
inline statistics& operator+=(const statistics& rhs)
|
|
{
|
|
if(m_cnt == 0)
|
|
{
|
|
m_sum = rhs.m_sum;
|
|
m_sqr = rhs.m_sqr;
|
|
m_min = rhs.m_min;
|
|
m_max = rhs.m_max;
|
|
}
|
|
else
|
|
{
|
|
m_sum += rhs.m_sum;
|
|
m_sqr += rhs.m_sqr;
|
|
m_min = ::std::min(m_min, rhs.m_min);
|
|
m_max = ::std::max(m_max, rhs.m_max);
|
|
}
|
|
m_cnt += rhs.m_cnt;
|
|
return *this;
|
|
}
|
|
|
|
// Operators (this_type)
|
|
inline statistics& operator-=(const statistics& rhs)
|
|
{
|
|
if(m_cnt > 0)
|
|
{
|
|
m_sum -= rhs.m_sum;
|
|
m_sqr -= rhs.m_sqr;
|
|
m_min = ::std::min(m_min, rhs.m_min);
|
|
m_max = ::std::max(m_max, rhs.m_max);
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
// summation of each history^1
|
|
int64_t m_cnt = 0;
|
|
value_type m_sum = value_type{};
|
|
value_type m_sqr = value_type{};
|
|
value_type m_min = value_type{};
|
|
value_type m_max = value_type{};
|
|
|
|
public:
|
|
// friend operator for addition
|
|
friend statistics operator+(const statistics& lhs, const statistics& rhs)
|
|
{
|
|
return statistics(lhs) += rhs;
|
|
}
|
|
|
|
friend statistics operator-(const statistics& lhs, const statistics& rhs)
|
|
{
|
|
return statistics(lhs) -= rhs;
|
|
}
|
|
};
|
|
} // namespace tool
|
|
} // namespace rocprofiler
|
|
|
|
namespace std
|
|
{
|
|
template <typename Tp>
|
|
::rocprofiler::tool::statistics<Tp>
|
|
max(::rocprofiler::tool::statistics<Tp> lhs, const Tp& rhs)
|
|
{
|
|
return lhs.get_max(rhs);
|
|
}
|
|
|
|
template <typename Tp>
|
|
::rocprofiler::tool::statistics<Tp>
|
|
min(::rocprofiler::tool::statistics<Tp> lhs, const Tp& rhs)
|
|
{
|
|
return lhs.get_min(rhs);
|
|
}
|
|
} // namespace std
|