-
Notifications
You must be signed in to change notification settings - Fork 124
[L0 v2] Add latency tracker #1892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| //===--------- ur_latency_tracker.cpp - common ---------------------------===// | ||
| // | ||
| // Copyright (C) 2024 Intel Corporation | ||
| // | ||
| // Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM | ||
| // Exceptions. See LICENSE.TXT | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <chrono> | ||
| #include <cstdint> | ||
| #include <limits> | ||
| #include <memory> | ||
|
|
||
| #include "logger/ur_logger.hpp" | ||
|
|
||
| namespace v2 { | ||
|
|
||
| static inline bool trackLatency = []() { | ||
| return std::getenv("UR_ENABLE_LATENCY_TRACKING") != nullptr; | ||
| }(); | ||
|
|
||
| class rolling_stats { | ||
| public: | ||
| rolling_stats(const char *name) : name(name) {} | ||
|
|
||
| ~rolling_stats() { | ||
| if (trackLatency) { | ||
| logger::info("[{}] average latency: {}ns", name, estimate()); | ||
| logger::info("[{}] number of samples: {}", name, count()); | ||
| } | ||
| } | ||
|
|
||
| // track latency by taking the value of duration directly. | ||
| void trackValue(double value) { | ||
| auto ratio = static_cast<double>(cnt) / (cnt + 1); | ||
| avg *= ratio; | ||
| ++cnt; | ||
| avg += value / cnt; | ||
| } | ||
|
|
||
| // Return the rolling average. | ||
| uint64_t estimate() { return static_cast<uint64_t>(avg); } | ||
|
|
||
| // Number of samples tracked. | ||
| uint64_t count() { return cnt; } | ||
|
|
||
| private: | ||
| const char *name; | ||
| double avg{0}; | ||
| uint64_t cnt{0}; | ||
| }; | ||
|
|
||
| class rolling_latency_tracker { | ||
| public: | ||
| explicit rolling_latency_tracker(rolling_stats &stats) | ||
| : stats_(trackLatency ? &stats : nullptr), begin_() { | ||
| if (trackLatency) { | ||
| begin_ = std::chrono::steady_clock::now(); | ||
| } | ||
| } | ||
| rolling_latency_tracker() {} | ||
| ~rolling_latency_tracker() { | ||
| if (stats_) { | ||
| auto tp = std::chrono::steady_clock::now(); | ||
| auto diffNanos = | ||
| std::chrono::duration_cast<std::chrono::nanoseconds>(tp - begin_) | ||
| .count(); | ||
| stats_->trackValue(static_cast<double>(diffNanos)); | ||
| } | ||
| } | ||
|
|
||
| rolling_latency_tracker(const rolling_latency_tracker &) = delete; | ||
| rolling_latency_tracker &operator=(const rolling_latency_tracker &) = delete; | ||
|
|
||
| rolling_latency_tracker(rolling_latency_tracker &&rhs) noexcept | ||
| : stats_(rhs.stats_), begin_(rhs.begin_) { | ||
| rhs.stats_ = nullptr; | ||
| } | ||
|
|
||
| rolling_latency_tracker &operator=(rolling_latency_tracker &&rhs) noexcept { | ||
| if (this != &rhs) { | ||
| this->~rolling_latency_tracker(); | ||
| new (this) rolling_latency_tracker(std::move(rhs)); | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| private: | ||
| rolling_stats *stats_{nullptr}; | ||
| std::chrono::time_point<std::chrono::steady_clock> begin_; | ||
| }; | ||
|
|
||
| } // namespace v2 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.