Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

add --cuda-usleep flag to optionally usleep between search iterations #2281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions ethminer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ class MinerCLI
app.add_option("--cuda-streams,--cu-streams", m_CUSettings.streams, "", true)
->check(CLI::Range(1, 99));

app.add_option("--cuda-usleep,--cu-usleep", m_CUSettings.usleep, "", true)
->check(CLI::Range(-1, 1000000));
Comment on lines +347 to +348
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably worth improving the documentation on this, just to make it more clear what this actually does.

Suggested change
app.add_option("--cuda-usleep,--cu-usleep", m_CUSettings.usleep, "", true)
->check(CLI::Range(-1, 1000000));
// adds an optional usleep between batches. Can be used to slow down mining.
app.add_option("--cuda-usleep,--cu-usleep", m_CUSettings.usleep, "Sleep time in μs between batches (default: no sleep)", true)
->check(CLI::Range(-1, 1000000));


#endif

#if ETH_ETHASHCPU
Expand Down
5 changes: 5 additions & 0 deletions libethash-cuda/CUDAMiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,13 @@ void CUDAMiner::search(
// restart the stream on the next batch of nonces
// unless we are done for this round.
if (!done)
{
if (m_settings.usleep >= 0) {
usleep(m_settings.usleep);
}
run_ethash_search(
m_settings.gridSize, m_settings.blockSize, stream, &buffer, start_nonce);
}

if (found_count)
{
Expand Down
1 change: 1 addition & 0 deletions libethcore/Miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct CUSettings : public MinerSettings
unsigned schedule = 4;
unsigned gridSize = 8192;
unsigned blockSize = 128;
int usleep = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

C and C++ are annoying languages, and even though int is usually 32-bits large, on some platforms, it can be 16-bits, so it's better to use one of the types in <cstdint> instead.

The following should work if you include #include <cstdint> at the top of the file. Alternatively, you could replace the CLI::Range(-1, 1000000)) to a smaller range that will fit in a int16 like CLI::Range(-1, 10000)).

Suggested change
int usleep = -1;
int_fast32_t usleep = -1;

};

// Holds settings for OpenCL Miner
Expand Down