-
Notifications
You must be signed in to change notification settings - Fork 11
feat(stats): keep the hashrate meter alive across jobs (--internal_accumulate_hash) #174
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
Merged
luminousmining
merged 2 commits into
luminousmining:main
from
yuzi-co:feat/hashrate-time-windowed-meter
Jun 14, 2026
Merged
Changes from all commits
Commits
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
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,11 @@ | ||
| file(GLOB HEADERS "*.hpp") | ||
| file(GLOB SOURCES "*.cpp") | ||
|
|
||
| if (BUILD_EXE_UNIT_TEST) | ||
| target_sources(${UNIT_TEST_EXE} PUBLIC | ||
| ${HEADERS} | ||
| ${SOURCES} | ||
| ) | ||
| endif() | ||
|
|
||
| set(SOURCES_STATISTICAL_TESTS ${HEADERS} ${SOURCES} PARENT_SCOPE) |
|
luminousmining marked this conversation as resolved.
|
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,79 @@ | ||
| #include <chrono> | ||
| #include <thread> | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <statistical/statistical.hpp> | ||
|
|
||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| // A window that completed real launches publishes a positive hashrate: | ||
| // rate = batchNonce * kernelExecuted / elapsed. | ||
| //////////////////////////////////////////////////////////////////////////////// | ||
| TEST(StatisticalHashrate, workedWindowPublishesPositiveHashrate) | ||
| { | ||
| statistical::Statistical stats{}; | ||
| stats.reset(); | ||
|
|
||
| stats.setBatchNonce(1000000ull); | ||
| stats.increaseKernelExecuted(); | ||
| stats.increaseKernelExecuted(); | ||
|
|
||
| std::this_thread::sleep_for(std::chrono::milliseconds(2)); // guarantee elapsed > 0 | ||
| stats.stop(); | ||
| stats.updateHashrate(); | ||
|
|
||
| EXPECT_LT(0.0, stats.getHashrate()); | ||
| } | ||
|
|
||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| // Non-accumulate path: a job update resets the meter. A slow / memory-hard | ||
| // kernel that has not yet reached the publish threshold then reads 0 H/s, and | ||
| // the dashboard hides the device -- the bug --internal_accumulate_hash fixes. | ||
| //////////////////////////////////////////////////////////////////////////////// | ||
| TEST(StatisticalHashrate, resetHashrateZeroesDisplayedValue) | ||
| { | ||
| statistical::Statistical stats{}; | ||
| stats.reset(); | ||
|
|
||
| stats.setBatchNonce(1000000ull); | ||
| stats.increaseKernelExecuted(); | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(2)); | ||
| stats.stop(); | ||
| stats.updateHashrate(); | ||
| ASSERT_LT(0.0, stats.getHashrate()); | ||
|
|
||
| stats.resetHashrate(); | ||
| EXPECT_DOUBLE_EQ(0.0, stats.getHashrate()); | ||
| EXPECT_EQ(0u, stats.getKernelExecutedCount()); | ||
| } | ||
|
|
||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| // Accumulate path: a job update does NOT reset the meter, so the launch count | ||
| // and elapsed window carry across the boundary and the kernel keeps publishing | ||
| // a non-zero hashrate even when each job window is far shorter than the | ||
| // publish threshold. | ||
| //////////////////////////////////////////////////////////////////////////////// | ||
| TEST(StatisticalHashrate, accumulateAcrossJobUpdatePreservesHashrate) | ||
| { | ||
| statistical::Statistical stats{}; | ||
| stats.reset(); | ||
| stats.setBatchNonce(1000000ull); | ||
|
|
||
| // First job window. | ||
| stats.increaseKernelExecuted(); | ||
| stats.increaseKernelExecuted(); | ||
| EXPECT_EQ(2u, stats.getKernelExecutedCount()); | ||
|
|
||
| // A new job arrives; in accumulate mode the meter is not reset, so the count | ||
| // keeps growing rather than dropping back to zero. | ||
| stats.increaseKernelExecuted(); | ||
| EXPECT_EQ(3u, stats.getKernelExecutedCount()); | ||
|
|
||
| std::this_thread::sleep_for(std::chrono::milliseconds(2)); | ||
| stats.stop(); | ||
| stats.updateHashrate(); | ||
| EXPECT_LT(0.0, stats.getHashrate()); | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remve comment