Browse Source

old dag deletion

cl-refactor
Genoil 9 years ago
parent
commit
2a8b09350f
  1. 54
      ethminer/MinerAux.h
  2. 47
      libethcore/EthashAux.cpp
  3. 15
      libethcore/EthashAux.h

54
ethminer/MinerAux.h

@ -109,7 +109,6 @@ public:
Stratum Stratum
}; };
MinerCLI(OperationMode _mode = OperationMode::None): mode(_mode) {} MinerCLI(OperationMode _mode = OperationMode::None): mode(_mode) {}
bool interpretOption(int& i, int argc, char** argv) bool interpretOption(int& i, int argc, char** argv)
@ -314,6 +313,19 @@ public:
{ {
strcpy(s_dagDir, argv[++i]); strcpy(s_dagDir, argv[++i]);
} }
else if ((arg == "-E" || arg == "--erase-dags") && i + 1 < argc)
{
string m = string(argv[++i]);
if (m == "none") m_eraseMode = DAGEraseMode::None;
else if (m == "old") m_eraseMode = DAGEraseMode::Old;
else if (m == "bench") m_eraseMode = DAGEraseMode::Bench;
else if (m == "all") m_eraseMode = DAGEraseMode::All;
else
{
cerr << "Bad " << arg << " option: " << argv[i] << endl;
BOOST_THROW_EXCEPTION(BadArgument());
}
}
else if (arg == "--no-precompute") else if (arg == "--no-precompute")
m_precompute = false; m_precompute = false;
else if ((arg == "-D" || arg == "--create-dag") && i + 1 < argc) else if ((arg == "-D" || arg == "--create-dag") && i + 1 < argc)
@ -429,6 +441,11 @@ public:
void execute() void execute()
{ {
EthashAux::setCustomDirName(s_dagDir);
EthashAux::setDAGEraseMode(m_eraseMode);
EthashAux::eraseDAGs();
if (m_shouldListDevices) if (m_shouldListDevices)
{ {
#if ETH_ETHASHCL || !ETH_TRUE #if ETH_ETHASHCL || !ETH_TRUE
@ -513,6 +530,12 @@ public:
#if ETH_JSONRPC || !ETH_TRUE #if ETH_JSONRPC || !ETH_TRUE
<< "Work farming mode:" << endl << "Work farming mode:" << endl
<< " -F,--farm <url> Put into mining farm mode with the work server at URL (default: http://127.0.0.1:8545)" << endl << " -F,--farm <url> Put into mining farm mode with the work server at URL (default: http://127.0.0.1:8545)" << endl
#endif
#if ETH_STRATUM || !ETH_TRUE
<< " -S, --stratum <host:port> Put into stratum mode with the stratum server at host:port" << endl
<< " -O, --userpass <username.workername:password> Stratum login credentials" << endl
#endif
#if ETH_JSONRPC || ETH_STRATUM || !ETH_TRUE
<< " --farm-recheck <n> Leave n ms between checks for changed work (default: 500)." << endl << " --farm-recheck <n> Leave n ms between checks for changed work (default: 500)." << endl
<< " --no-precompute Don't precompute the next epoch's DAG." << endl << " --no-precompute Don't precompute the next epoch's DAG." << endl
#endif #endif
@ -525,12 +548,18 @@ public:
<< " --benchmark-trial <seconds> Set the duration for each trial for the benchmark tests (default: 3)." << endl << " --benchmark-trial <seconds> Set the duration for each trial for the benchmark tests (default: 3)." << endl
<< " --benchmark-trials <n> Set the duration of warmup for the benchmark tests (default: 5)." << endl << " --benchmark-trials <n> Set the duration of warmup for the benchmark tests (default: 5)." << endl
<< "Simulation mode:" << endl << "Simulation mode:" << endl
<< " -S [<n>],--simulation [<n>] Mining test mode. Used to validate kernel optimizations. Optionally specify block number." << endl << " -Z [<n>],--simulation [<n>] Mining test mode. Used to validate kernel optimizations. Optionally specify block number." << endl
#if ETH_JSONRPC || !ETH_TRUE #if ETH_JSONRPC || !ETH_TRUE
<< " --phone-home <on/off> When benchmarking, publish results (default: off)" << endl << " --phone-home <on/off> When benchmarking, publish results (default: off)" << endl
#endif #endif
<< "DAG creation mode:" << endl << "DAG file management:" << endl
<< " -D,--create-dag <number> Create the DAG in preparation for mining on given block and exit." << endl << " -D,--create-dag <number> Create the DAG in preparation for mining on given block and exit." << endl
<< " -R <s>, --dag-dir <s> Store/Load DAG files in/from the specified directory. Useful for running multiple instances with different configurations." << endl
<< " -E <mode>, --erase-dags <mode> Erase unneeded DAG files. Default is 'none'. Possible values are:" << endl
<< " none - don't erase DAG files (default)" << endl
<< " old - erase all DAG files older than current epoch" << endl
<< " bench - like old, but keep epoch 0 for benchmarking" << endl
<< " all - erase all DAG files" << endl
<< "Mining configuration:" << endl << "Mining configuration:" << endl
<< " -C,--cpu When mining, use the CPU." << endl << " -C,--cpu When mining, use the CPU." << endl
<< " -G,--opencl When mining use the GPU via OpenCL." << endl << " -G,--opencl When mining use the GPU via OpenCL." << endl
@ -542,7 +571,6 @@ public:
<< " --allow-opencl-cpu Allows CPU to be considered as an OpenCL device if the OpenCL platform supports it." << endl << " --allow-opencl-cpu Allows CPU to be considered as an OpenCL device if the OpenCL platform supports it." << endl
<< " --list-devices List the detected OpenCL/CUDA devices and exit." << endl << " --list-devices List the detected OpenCL/CUDA devices and exit." << endl
<< " --current-block Let the miner know the current block number at configuration time. Will help determine DAG size and required GPU memory." << endl << " --current-block Let the miner know the current block number at configuration time. Will help determine DAG size and required GPU memory." << endl
<< " -R <s>, --dag-dir <s> Store/Load DAG files in/from the specified directory. Useful for running multiple instances with different configurations." << endl
#if ETH_ETHASHCL || !ETH_TRUE #if ETH_ETHASHCL || !ETH_TRUE
<< " --cl-extragpu-mem Set the memory (in MB) you believe your GPU requires for stuff other than mining. Windows rendering e.t.c.." << endl << " --cl-extragpu-mem Set the memory (in MB) you believe your GPU requires for stuff other than mining. Windows rendering e.t.c.." << endl
<< " --cl-local-work Set the OpenCL local work size. Default is " << toString(ethash_cl_miner::c_defaultLocalWorkSize) << endl << " --cl-local-work Set the OpenCL local work size. Default is " << toString(ethash_cl_miner::c_defaultLocalWorkSize) << endl
@ -553,7 +581,7 @@ public:
<< " --cuda-block-size Set the CUDA block work size. Default is " << toString(ethash_cuda_miner::c_defaultBlockSize) << endl << " --cuda-block-size Set the CUDA block work size. Default is " << toString(ethash_cuda_miner::c_defaultBlockSize) << endl
<< " --cuda-grid-size Set the CUDA grid size. Default is " << toString(ethash_cuda_miner::c_defaultGridSize) << endl << " --cuda-grid-size Set the CUDA grid size. Default is " << toString(ethash_cuda_miner::c_defaultGridSize) << endl
<< " --cuda-streams Set the number of CUDA streams. Default is " << toString(ethash_cuda_miner::c_defaultNumStreams) << endl << " --cuda-streams Set the number of CUDA streams. Default is " << toString(ethash_cuda_miner::c_defaultNumStreams) << endl
<< " --cuda-schedule <mode> Set the schedule mode for CUDA threads waiting for CUDA devices to finish work. Default is sync. Possible values are:" << endl << " --cuda-schedule <mode> Set the schedule mode for CUDA threads waiting for CUDA devices to finish work. Default is 'sync'. Possible values are:" << endl
<< " auto - Uses a heuristic based on the number of active CUDA contexts in the process C and the number of logical processors in the system P. If C > P, then yield else spin." << endl << " auto - Uses a heuristic based on the number of active CUDA contexts in the process C and the number of logical processors in the system P. If C > P, then yield else spin." << endl
<< " spin - Instruct CUDA to actively spin when waiting for results from the device." << endl << " spin - Instruct CUDA to actively spin when waiting for results from the device." << endl
<< " yield - Instruct CUDA to yield its thread when waiting for results from the device." << endl << " yield - Instruct CUDA to yield its thread when waiting for results from the device." << endl
@ -569,16 +597,16 @@ public:
private: private:
void doInitDAG(unsigned _n) void doInitDAG(unsigned _n)
{ {
EthashAux::setCustomDirName(s_dagDir);
h256 seedHash = EthashAux::seedHash(_n); h256 seedHash = EthashAux::seedHash(_n);
cout << "Initializing DAG for epoch beginning #" << (_n / 30000 * 30000) << " (seedhash " << seedHash.abridged() << "). This will take a while." << endl; cout << "Initializing DAG for epoch beginning #" << (_n / 30000 * 30000) << " (seedhash " << seedHash.abridged() << "). This will take a while." << endl;
EthashAux::full(seedHash, true); EthashAux::full(seedHash, true);
exit(0); exit(0);
} }
void doBenchmark(MinerType _m, bool _phoneHome, unsigned _warmupDuration = 15, unsigned _trialDuration = 3, unsigned _trials = 5) void doBenchmark(MinerType _m, bool _phoneHome, unsigned _warmupDuration = 15, unsigned _trialDuration = 3, unsigned _trials = 5)
{ {
EthashAux::setCustomDirName(s_dagDir);
Ethash::BlockHeader genesis; Ethash::BlockHeader genesis;
genesis.setNumber(m_benchmarkBlock); genesis.setNumber(m_benchmarkBlock);
genesis.setDifficulty(1 << 18); genesis.setDifficulty(1 << 18);
@ -663,8 +691,6 @@ private:
void doSimulation(MinerType _m, int difficulty = 20) void doSimulation(MinerType _m, int difficulty = 20)
{ {
EthashAux::setCustomDirName(s_dagDir);
Ethash::BlockHeader genesis; Ethash::BlockHeader genesis;
genesis.setNumber(m_benchmarkBlock); genesis.setNumber(m_benchmarkBlock);
genesis.setDifficulty(1 << 18); genesis.setDifficulty(1 << 18);
@ -756,8 +782,6 @@ private:
void doFarm(MinerType _m, string const& _remote, unsigned _recheckPeriod) void doFarm(MinerType _m, string const& _remote, unsigned _recheckPeriod)
{ {
EthashAux::setCustomDirName(s_dagDir);
map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers; map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers;
sealers["cpu"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{&EthashCPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCPUMiner(ci); }}; sealers["cpu"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{&EthashCPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCPUMiner(ci); }};
#if ETH_ETHASHCL #if ETH_ETHASHCL
@ -866,10 +890,9 @@ private:
exit(0); exit(0);
} }
#if ETH_STRATUM || !ETH_TRUE
void doStratum(MinerType _m, unsigned _recheckPeriod, string const & host, string const & port, string const & user, string const & pass) void doStratum(MinerType _m, unsigned _recheckPeriod, string const & host, string const & port, string const & user, string const & pass)
{ {
EthashAux::setCustomDirName(s_dagDir);
map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers; map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers;
sealers["cpu"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashCPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCPUMiner(ci); } }; sealers["cpu"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashCPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCPUMiner(ci); } };
#if ETH_ETHASHCL #if ETH_ETHASHCL
@ -888,7 +911,7 @@ private:
client.submit(sol); client.submit(sol);
return false; return false;
}); });
while (true) while (true)
{ {
auto mp = f.miningProgress(); auto mp = f.miningProgress();
@ -903,10 +926,11 @@ private:
this_thread::sleep_for(chrono::milliseconds(_recheckPeriod)); this_thread::sleep_for(chrono::milliseconds(_recheckPeriod));
} }
} }
#endif
/// Operating mode. /// Operating mode.
OperationMode mode; OperationMode mode;
DAGEraseMode m_eraseMode = DAGEraseMode::None;
/// Mining options /// Mining options
MinerType m_minerType = MinerType::CPU; MinerType m_minerType = MinerType::CPU;

47
libethcore/EthashAux.cpp

@ -38,11 +38,13 @@ using namespace std;
using namespace chrono; using namespace chrono;
using namespace dev; using namespace dev;
using namespace eth; using namespace eth;
using namespace boost::filesystem;
const char* DAGChannel::name() { return EthGreen "DAG"; } const char* DAGChannel::name() { return EthGreen "DAG"; }
EthashAux* dev::eth::EthashAux::s_this = nullptr; EthashAux* dev::eth::EthashAux::s_this = nullptr;
char dev::eth::EthashAux::s_customDirName[256] = ""; char dev::eth::EthashAux::s_customDirName[256] = "";
dev::eth::DAGEraseMode dev::eth::EthashAux::s_dagEraseMode = DAGEraseMode::None;
const unsigned EthashProofOfWork::defaultLocalWorkSize = 64; const unsigned EthashProofOfWork::defaultLocalWorkSize = 64;
const unsigned EthashProofOfWork::defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE const unsigned EthashProofOfWork::defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE
@ -81,6 +83,48 @@ char * EthashAux::customDirName()
return s_customDirName; return s_customDirName;
} }
void EthashAux::setDAGEraseMode(DAGEraseMode mode)
{
s_dagEraseMode = mode;
}
void EthashAux::eraseDAGs()
{
if (s_dagEraseMode == DAGEraseMode::None) return;
path p(s_customDirName);
vector<path> files;
directory_iterator end_itr;
for (directory_iterator itr(p); itr != end_itr; ++itr)
{
if (is_regular_file(itr->path())) {
files.push_back(itr->path());
}
}
std::sort(files.begin(), files.end(),
[](const path& p1, const path& p2)
{
return file_size(p1) < file_size(p2);
});
size_t dagcount = files.size();
size_t dagcounter = 0;
for (std::vector<path>::const_iterator path = files.begin(); path != files.end(); ++path)
{
if (s_dagEraseMode == DAGEraseMode::Bench && path->filename() == "full-R23-0000000000000000") {}
else if ((s_dagEraseMode == DAGEraseMode::Old || s_dagEraseMode == DAGEraseMode::Bench) && dagcount - dagcounter <= 2) {}
else
{
cnote << "Deleting DAG file " << path->string();
remove(*path);
}
dagcounter++;
}
}
h256 EthashAux::seedHash(unsigned _number) h256 EthashAux::seedHash(unsigned _number)
{ {
unsigned epoch = _number / ETHASH_EPOCH_LENGTH; unsigned epoch = _number / ETHASH_EPOCH_LENGTH;
@ -238,6 +282,7 @@ unsigned EthashAux::computeFull(h256 const& _seedHash, bool _createIfMissing)
get()->m_fullGenerator = unique_ptr<thread>(new thread([=](){ get()->m_fullGenerator = unique_ptr<thread>(new thread([=](){
cnote << "Loading full DAG of seedhash: " << _seedHash; cnote << "Loading full DAG of seedhash: " << _seedHash;
get()->full(_seedHash, true, [](unsigned p){ get()->m_fullProgress = p; return 0; }); get()->full(_seedHash, true, [](unsigned p){ get()->m_fullProgress = p; return 0; });
eraseDAGs(); // delete any old DAG files
cnote << "Full DAG loaded"; cnote << "Full DAG loaded";
get()->m_fullProgress = 0; get()->m_fullProgress = 0;
get()->m_generatingFullNumber = NotGenerating; get()->m_generatingFullNumber = NotGenerating;
@ -247,6 +292,8 @@ unsigned EthashAux::computeFull(h256 const& _seedHash, bool _createIfMissing)
return (get()->m_generatingFullNumber == blockNumber) ? get()->m_fullProgress : 0; return (get()->m_generatingFullNumber == blockNumber) ? get()->m_fullProgress : 0;
} }
EthashProofOfWork::Result EthashAux::FullAllocation::compute(h256 const& _headerHash, Nonce const& _nonce) const EthashProofOfWork::Result EthashAux::FullAllocation::compute(h256 const& _headerHash, Nonce const& _nonce) const
{ {
ethash_return_value_t r = ethash_full_compute(full, *(ethash_h256_t*)_headerHash.data(), (uint64_t)(u64)_nonce); ethash_return_value_t r = ethash_full_compute(full, *(ethash_h256_t*)_headerHash.data(), (uint64_t)(u64)_nonce);

15
libethcore/EthashAux.h

@ -75,6 +75,14 @@ struct EthashProofOfWork
static const unsigned defaultMSPerBatch; static const unsigned defaultMSPerBatch;
}; };
enum class DAGEraseMode
{
None,
Old,
Bench,
All
};
class EthashAux class EthashAux
{ {
public: public:
@ -111,6 +119,10 @@ public:
static uint64_t dataSize(uint64_t _blockNumber); static uint64_t dataSize(uint64_t _blockNumber);
static void setCustomDirName(const char * custom_dir_name); static void setCustomDirName(const char * custom_dir_name);
static char * customDirName(); static char * customDirName();
static void setDAGEraseMode(DAGEraseMode mode);
static void EthashAux::eraseDAGs();
static LightType light(h256 const& _seedHash); static LightType light(h256 const& _seedHash);
static const uint64_t NotGenerating = (uint64_t)-1; static const uint64_t NotGenerating = (uint64_t)-1;
@ -120,6 +132,8 @@ public:
static std::pair<uint64_t, unsigned> fullGeneratingProgress() { return std::make_pair(get()->m_generatingFullNumber, get()->m_fullProgress); } static std::pair<uint64_t, unsigned> fullGeneratingProgress() { return std::make_pair(get()->m_generatingFullNumber, get()->m_fullProgress); }
/// Kicks off generation of DAG for @a _blocknumber and blocks until ready; @returns result or empty pointer if not existing and _createIfMissing is false. /// Kicks off generation of DAG for @a _blocknumber and blocks until ready; @returns result or empty pointer if not existing and _createIfMissing is false.
static FullType full(h256 const& _seedHash, bool _createIfMissing = false, std::function<int(unsigned)> const& _f = std::function<int(unsigned)>()); static FullType full(h256 const& _seedHash, bool _createIfMissing = false, std::function<int(unsigned)> const& _f = std::function<int(unsigned)>());
static EthashProofOfWork::Result eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce); static EthashProofOfWork::Result eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce);
@ -132,6 +146,7 @@ private:
static EthashAux* s_this; static EthashAux* s_this;
static char s_customDirName[256]; static char s_customDirName[256];
static DAGEraseMode s_dagEraseMode;
SharedMutex x_lights; SharedMutex x_lights;
std::unordered_map<h256, std::shared_ptr<LightAllocation>> m_lights; std::unordered_map<h256, std::shared_ptr<LightAllocation>> m_lights;

Loading…
Cancel
Save