CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
114 lines
2.8 KiB
C++
114 lines
2.8 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
/*
|
|
* Timer for microbenchmarking the translator.
|
|
*/
|
|
|
|
#include <iomanip>
|
|
#include <sstream>
|
|
|
|
#include <rocRoller/Utilities/Timer.hpp>
|
|
|
|
namespace rocRoller
|
|
{
|
|
TimerPool& TimerPool::getInstance()
|
|
{
|
|
static TimerPool pool;
|
|
return pool;
|
|
}
|
|
|
|
std::string TimerPool::summary()
|
|
{
|
|
std::stringstream ss;
|
|
for(auto const& kv : getInstance().m_elapsed)
|
|
{
|
|
ss << std::left << std::setw(60) << kv.first << std::right << std::setw(9)
|
|
<< milliseconds(kv.first) << "ms" << std::endl;
|
|
}
|
|
return ss.str();
|
|
}
|
|
|
|
std::string TimerPool::CSV()
|
|
{
|
|
std::stringstream ss;
|
|
ss << "timer,nanoseconds" << std::endl;
|
|
for(auto const& kv : getInstance().m_elapsed)
|
|
{
|
|
ss << kv.first << "," << nanoseconds(kv.first) << std::endl;
|
|
}
|
|
return ss.str();
|
|
}
|
|
|
|
size_t TimerPool::nanoseconds(std::string const& name)
|
|
{
|
|
if(getInstance().m_elapsed.count(name) == 0)
|
|
return 0;
|
|
auto elapsed = getInstance().m_elapsed.at(name).load();
|
|
return std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count();
|
|
}
|
|
|
|
size_t TimerPool::milliseconds(std::string const& name)
|
|
{
|
|
if(getInstance().m_elapsed.count(name) == 0)
|
|
return 0;
|
|
auto elapsed = getInstance().m_elapsed.at(name).load();
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
|
|
}
|
|
|
|
void TimerPool::clear()
|
|
{
|
|
getInstance().m_elapsed.clear();
|
|
}
|
|
|
|
void TimerPool::accumulate(std::string const& name,
|
|
std::chrono::steady_clock::duration const& elapsed)
|
|
{
|
|
m_elapsed[name].store(m_elapsed[name].load() + elapsed);
|
|
}
|
|
|
|
Timer::Timer(std::string name)
|
|
: m_name(std::move(name))
|
|
, m_elapsed(0)
|
|
{
|
|
Timer::tic();
|
|
}
|
|
|
|
Timer::~Timer()
|
|
{
|
|
Timer::toc();
|
|
}
|
|
|
|
void Timer::tic()
|
|
{
|
|
m_start = std::chrono::steady_clock::now();
|
|
}
|
|
|
|
void Timer::toc()
|
|
{
|
|
if(m_start.time_since_epoch().count() <= 0)
|
|
return;
|
|
|
|
auto elapsedTime = std::chrono::steady_clock::now() - m_start;
|
|
m_start = {};
|
|
|
|
m_elapsed += elapsedTime;
|
|
TimerPool::getInstance().accumulate(m_name, elapsedTime);
|
|
}
|
|
|
|
std::chrono::steady_clock::duration Timer::elapsed() const
|
|
{
|
|
return m_elapsed;
|
|
}
|
|
|
|
size_t Timer::nanoseconds() const
|
|
{
|
|
return std::chrono::duration_cast<std::chrono::nanoseconds>(m_elapsed).count();
|
|
}
|
|
|
|
size_t Timer::milliseconds() const
|
|
{
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(m_elapsed).count();
|
|
}
|
|
}
|