Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions documentation/PARAMETERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ N/A : No default value is set.
| `--occupancy` | ✅ | false | System will define the best occupancy for kernel. | `--occupancy=<true\|false>` |
| `--internal_loop` | ✅ | 1 | Set internal loop for kernel. | `--internal_loop=1` |
| `--internal_kernel_count` | ✅ | 100 | Set internal loop for kernel. This defines the minimum number of times the kernel must be called to display statistics | `--internal_kernel_count=1` |
| `--internal_accumulate_hash` | ✅ | true | Accumulate the hash count across job and constant updates instead of resetting between jobs (a memory rebuild always resets). Keeps the dashboard hashrate from reading 0 H/s on slow / memory-hard kernels. | `--internal_accumulate_hash=<true\|false>` |
| `--cuda_context` | ✅ | auto | Set CUDA context. | `--cuda_context=<auto\|blocking\|yield\|spin>` |

## Smart Mining
Expand Down
7 changes: 7 additions & 0 deletions sources/common/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ common::Cli::Cli()
"called to display statistics.\n"
"Default is value is 100.\n"
"--internal_kernel_count=100")(
"internal_accumulate_hash",
value<bool>(),
"[OPTIONAL] Accumulate the hash count across job and constant updates instead of resetting it "
"between jobs. A memory update (e.g. DAG rebuild) always resets. Keeps the dashboard hashrate from "
"reading 0 H/s on slow / memory-hard kernels.\n"
"Default value is true.\n"
"--internal_accumulate_hash=<true|false>")(
"cuda_context",
value<std::string>(),
"[OPTIONAL] Set CUDA context.\n"
Expand Down
1 change: 1 addition & 0 deletions sources/common/cli/cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace common
bool isAutoOccupancy() const;
uint32_t getInternalLoop() const;
uint32_t getMinimunKernelExecuted() const;
bool getAccumulateHash() const;
std::string getCudaContext() const;

// Algorithm
Expand Down
11 changes: 11 additions & 0 deletions sources/common/cli/cli_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ uint32_t common::Cli::getMinimunKernelExecuted() const
}


bool common::Cli::getAccumulateHash() const
{
bool accumulateHash{ true };
if (true == contains("internal_accumulate_hash"))
{
accumulateHash = params["internal_accumulate_hash"].as<bool>();
}
return accumulateHash;
}


std::string common::Cli::getCudaContext() const
{
std::string context{ "auto" };
Expand Down
2 changes: 2 additions & 0 deletions sources/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,13 @@ bool common::Config::loadCli(int argc, char** argv)
auto const occupancyBlocks{ cli.getOccupancyBlocks() };
auto const internalLoop{ cli.getInternalLoop() };
auto const kernelMinimunExecuteNeeded{ cli.getMinimunKernelExecuted() };
auto const accumulateHash{ cli.getAccumulateHash() };
auto const cudaContext{ cli.getCudaContext() };
occupancy.isAuto = isAutoOccupancy;
occupancy.internalLoop = internalLoop;
occupancy.cudaContext = cudaContext;
occupancy.kernelMinimunExecuteNeeded = kernelMinimunExecuteNeeded;
occupancy.accumulateHash = accumulateHash;
if (0u != occupancyThreads || 0u != occupancyBlocks)
{
if (0u != occupancyThreads)
Expand Down
1 change: 1 addition & 0 deletions sources/common/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace common
std::optional<uint32_t> internalLoop{};
std::optional<uint32_t> kernelMinimunExecuteNeeded{};
std::optional<std::string> cudaContext{};
bool accumulateHash{ true };
};

struct DeviceAlgorithmConfig
Expand Down
23 changes: 18 additions & 5 deletions sources/device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,13 @@ bool device::Device::updateJob()
uint64_t const currentAtomicMemory{ synchronizer.memory.get() };

////////////////////////////////////////////////////////////////////////////
common::Config const& config{ common::Config::instance() };
if (nextjobInfo.epoch != currentJobInfo.epoch || nextjobInfo.period != currentJobInfo.period)
{
miningStats.reset();
if (false == config.occupancy.accumulateHash)
{
miningStats.reset();
}
}
currentJobInfo.copy(nextjobInfo);
synchronizer.job.update(currentAtomicJob);
Expand Down Expand Up @@ -636,13 +640,14 @@ bool device::Device::updateJob()
}

////////////////////////////////////////////////////////////////////////////
updateBatchNonce();
bool const resetStats{ false == config.occupancy.accumulateHash || true == needUpdateMemory };
updateBatchNonce(resetStats);

return true;
}


void device::Device::updateBatchNonce()
void device::Device::updateBatchNonce(bool const resetStats)
{
////////////////////////////////////////////////////////////////////////////
common::Config const& config{ common::Config::instance() };
Expand All @@ -656,8 +661,13 @@ void device::Device::updateBatchNonce()

////////////////////////////////////////////////////////////////////////////
miningStats.setBatchNonce(resolver->getBlocks() * resolver->getThreads() * internalLoop);
miningStats.resetHashrate();
miningStats.reset();

////////////////////////////////////////////////////////////////////////////

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remve comment

if (true == resetStats)
{
miningStats.resetHashrate();
miningStats.reset();
}
}


Expand Down Expand Up @@ -691,6 +701,9 @@ void device::Device::loopDoWork()
////////////////////////////////////////////////////////////////////////////
computing.store(true, boost::memory_order::seq_cst);

////////////////////////////////////////////////////////////////////////////
miningStats.reset();

////////////////////////////////////////////////////////////////////////////
deviceDebug() << "Start working!";
while (true == isAlive() && nullptr != resolver)
Expand Down
2 changes: 1 addition & 1 deletion sources/device/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace device
bool updateJob();
void waitJob();
void loopDoWork();
void updateBatchNonce();
void updateBatchNonce(bool const resetStats);
void submit(common::PROFILE const profile);

private:
Expand Down
3 changes: 3 additions & 0 deletions sources/statistical/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ if (BUILD_EXE_UNIT_TEST)
)
endif()

add_subdirectory(tests)

set(SOURCES_STRATISTICAL ${HEADERS} ${SOURCES} PARENT_SCOPE)
set(SOURCES_STATISTICAL_TESTS ${SOURCES_STATISTICAL_TESTS} PARENT_SCOPE)
11 changes: 11 additions & 0 deletions sources/statistical/tests/CMakeLists.txt
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)
79 changes: 79 additions & 0 deletions sources/statistical/tests/statistical.cpp
Comment thread
luminousmining marked this conversation as resolved.
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());
}
Loading