Browse Source

Merge branch 'Genoil-multiple-gpu' into develop

cl-refactor
Gav Wood 10 years ago
parent
commit
2717db6713
  1. 39
      eth/main.cpp
  2. 9
      libdevcore/Log.cpp
  3. 131
      libdevcore/Terminal.h
  4. 21
      libethash-cl/ethash_cl_miner.cpp
  5. 2
      libethash-cl/ethash_cl_miner.h
  6. 13
      libethcore/Ethash.cpp
  7. 14
      libethcore/Ethash.h
  8. 7
      libethereum/BlockChain.cpp
  9. 4
      libethereum/BlockQueue.cpp
  10. 7
      libethereum/Client.cpp
  11. 14
      libp2p/Common.cpp

39
eth/main.cpp

@ -136,6 +136,7 @@ void help()
<< " -G,--opencl When mining use the GPU via OpenCL." << endl << " -G,--opencl When mining use the GPU via OpenCL." << endl
<< " --opencl-platform <n> When mining using -G/--opencl use OpenCL platform n (default: 0)." << endl << " --opencl-platform <n> When mining using -G/--opencl use OpenCL platform n (default: 0)." << endl
<< " --opencl-device <n> When mining using -G/--opencl use OpenCL device n (default: 0)." << endl << " --opencl-device <n> When mining using -G/--opencl use OpenCL device n (default: 0)." << endl
<< " -t, --mining-threads <n> Limit number of CPU/GPU miners to n (default: use everything available on selected platform)" << endl
<< "Client networking:" << endl << "Client networking:" << endl
<< " --client-name <name> Add a name to your client's version string (default: blank)." << endl << " --client-name <name> Add a name to your client's version string (default: blank)." << endl
<< " -b,--bootstrap Connect to the default Ethereum peerserver." << endl << " -b,--bootstrap Connect to the default Ethereum peerserver." << endl
@ -482,6 +483,7 @@ int main(int argc, char** argv)
MinerType minerType = MinerType::CPU; MinerType minerType = MinerType::CPU;
unsigned openclPlatform = 0; unsigned openclPlatform = 0;
unsigned openclDevice = 0; unsigned openclDevice = 0;
unsigned miningThreads = UINT_MAX;
/// File name for import/export. /// File name for import/export.
string filename; string filename;
@ -600,13 +602,13 @@ int main(int argc, char** argv)
} }
else if (arg == "--opencl-platform" && i + 1 < argc) else if (arg == "--opencl-platform" && i + 1 < argc)
try { try {
openclPlatform= stol(argv[++i]); openclPlatform = stol(argv[++i]);
} }
catch (...) catch (...)
{ {
cerr << "Bad " << arg << " option: " << argv[i] << endl; cerr << "Bad " << arg << " option: " << argv[i] << endl;
return -1; return -1;
} }
else if (arg == "--opencl-device" && i + 1 < argc) else if (arg == "--opencl-device" && i + 1 < argc)
try { try {
openclDevice = stol(argv[++i]); openclDevice = stol(argv[++i]);
@ -850,6 +852,17 @@ int main(int argc, char** argv)
return -1; return -1;
} }
} }
else if ((arg == "-t" || arg == "--mining-threads") && i + 1 < argc)
{
try {
miningThreads = stol(argv[++i]);
}
catch (...)
{
cerr << "Bad " << arg << " option: " << argv[i] << endl;
return -1;
}
}
else if (arg == "-b" || arg == "--bootstrap") else if (arg == "-b" || arg == "--bootstrap")
bootstrap = true; bootstrap = true;
else if (arg == "-f" || arg == "--force-mining") else if (arg == "-f" || arg == "--force-mining")
@ -905,8 +918,16 @@ int main(int argc, char** argv)
if (sessionSecret) if (sessionSecret)
sigKey = KeyPair(sessionSecret); sigKey = KeyPair(sessionSecret);
ProofOfWork::GPUMiner::setDefaultPlatform(openclPlatform);
ProofOfWork::GPUMiner::setDefaultDevice(openclDevice);
if (minerType == MinerType::CPU)
ProofOfWork::CPUMiner::setNumInstances(miningThreads);
else if (minerType == MinerType::GPU)
{
ProofOfWork::GPUMiner::setDefaultPlatform(openclPlatform);
ProofOfWork::GPUMiner::setDefaultDevice(openclDevice);
ProofOfWork::GPUMiner::setNumInstances(miningThreads);
}
// Two codepaths is necessary since named block require database, but numbered // Two codepaths is necessary since named block require database, but numbered
// blocks are superuseful to have when database is already open in another process. // blocks are superuseful to have when database is already open in another process.

9
libdevcore/Log.cpp

@ -34,12 +34,21 @@ using namespace dev;
int dev::g_logVerbosity = 5; int dev::g_logVerbosity = 5;
map<type_info const*, bool> dev::g_logOverride; map<type_info const*, bool> dev::g_logOverride;
#ifdef _WIN32
const char* LogChannel::name() { return EthGray "..."; }
const char* LeftChannel::name() { return EthNavy "<--"; }
const char* RightChannel::name() { return EthGreen "-->"; }
const char* WarnChannel::name() { return EthOnRed EthBlackBold " X"; }
const char* NoteChannel::name() { return EthBlue " i"; }
const char* DebugChannel::name() { return EthWhite " D"; }
#else
const char* LogChannel::name() { return EthGray "···"; } const char* LogChannel::name() { return EthGray "···"; }
const char* LeftChannel::name() { return EthNavy "◀▬▬"; } const char* LeftChannel::name() { return EthNavy "◀▬▬"; }
const char* RightChannel::name() { return EthGreen "▬▬▶"; } const char* RightChannel::name() { return EthGreen "▬▬▶"; }
const char* WarnChannel::name() { return EthOnRed EthBlackBold ""; } const char* WarnChannel::name() { return EthOnRed EthBlackBold ""; }
const char* NoteChannel::name() { return EthBlue ""; } const char* NoteChannel::name() { return EthBlue ""; }
const char* DebugChannel::name() { return EthWhite ""; } const char* DebugChannel::name() { return EthWhite ""; }
#endif
LogOutputStreamBase::LogOutputStreamBase(char const* _id, std::type_info const* _info, unsigned _v, bool _autospacing): LogOutputStreamBase::LogOutputStreamBase(char const* _id, std::type_info const* _info, unsigned _v, bool _autospacing):
m_autospacing(_autospacing), m_autospacing(_autospacing),

131
libdevcore/Terminal.h

@ -9,75 +9,70 @@ namespace con
#define EthReset "" // Text Reset #define EthReset "" // Text Reset
// Regular Colors #define EthReset "" // Text Reset
#define EthBlack "" // Black
#define EthRed "" // Red
#define EthGreen "" // Green
#define EthYellow "" // Yellow
#define EthBlue "" // Blue
#define EthPurple "" // Purple
#define EthCyan "" // Cyan
#define EthWhite "" // White
// Bold
#define EthBlackB "" // Black
#define EthRedB "" // Red
#define EthGreenB "" // Green
#define EthYellowB "" // Yellow
#define EthBlueB "" // Blue
#define EthPurpleB "" // Purple
#define EthCyanB "" // Cyan
#define EthWhiteB "" // White
// Underline
#define EthBlackU "" // Black
#define EthRedU "" // Red
#define EthGreenU "" // Green
#define EthYellowU "" // Yellow
#define EthBlueU "" // Blue
#define EthPurpleU "" // Purple
#define EthCyanU "" // Cyan
#define EthWhiteU "" // White
// Background // Regular Colors
#define EthBlackOn "" // Black #define EthBlack "" // Black
#define EthRedOn "" // Red #define EthCoal "" // Black
#define EthGreenOn "" // Green #define EthGray "" // White
#define EthYellowOn "" // Yellow #define EthWhite "" // White
#define EthBlueOn "" // Blue #define EthMaroon "" // Red
#define EthPurpleOn "" // Purple #define EthRed "" // Red
#define EthCyanOn "" // Cyan #define EthGreen "" // Green
#define EthWhiteOn "" // White #define EthLime "" // Green
#define EthOrange "" // Yellow
// High Intensity #define EthYellow "" // Yellow
#define EthCoal "" // Black #define EthNavy "" // Blue
#define EthRedI "" // Red #define EthBlue "" // Blue
#define EthLime "" // Green #define EthViolet "" // Purple
#define EthYellowI "" // Yellow #define EthPurple "" // Purple
#define EthBlueI "" // Blue #define EthTeal "" // Cyan
#define EthPurpleI "" // Purple #define EthCyan "" // Cyan
#define EthCyanI "" // Cyan
#define EthWhiteI "" // White #define EthBlackBold "" // Black
#define EthCoalBold "" // Black
// Bold High Intensity #define EthGrayBold "" // White
#define EthBlackBI "" // Black #define EthWhiteBold "" // White
#define EthRedBI "" // Red #define EthMaroonBold "" // Red
#define EthGreenBI "" // Green #define EthRedBold "" // Red
#define EthYellowBI "" // Yellow #define EthGreenBold "" // Green
#define EthBlueBI "" // Blue #define EthLimeBold "" // Green
#define EthPurpleBI "" // Purple #define EthOrangeBold "" // Yellow
#define EthCyanBI "" // Cyan #define EthYellowBold "" // Yellow
#define EthWhiteBI "" // White #define EthNavyBold "" // Blue
#define EthBlueBold "" // Blue
// High Intensity backgrounds #define EthVioletBold "" // Purple
#define EthBlackOnI "" // Black #define EthPurpleBold "" // Purple
#define EthRedOnI "" // Red #define EthTealBold "" // Cyan
#define EthGreenOnI "" // Green #define EthCyanBold "" // Cyan
#define EthYellowOnI "" // Yellow
#define EthBlueOnI "" // Blue // Background
#define EthPurpleOnI "" // Purple #define EthOnBlack "" // Black
#define EthCyanOnI "" // Cyan #define EthOnCoal "" // Black
#define EthWhiteOnI "" // White #define EthOnGray "" // White
#define EthOnWhite "" // White
#define EthOnMaroon "" // Red
#define EthOnRed "" // Red
#define EthOnGreen "" // Green
#define EthOnLime "" // Green
#define EthOnOrange "" // Yellow
#define EthOnYellow "" // Yellow
#define EthOnNavy "" // Blue
#define EthOnBlue "" // Blue
#define EthOnViolet "" // Purple
#define EthOnPurple "" // Purple
#define EthOnTeal "" // Cyan
#define EthOnCyan "" // Cyan
// Underline
#define EthBlackUnder "" // Black
#define EthGrayUnder "" // White
#define EthMaroonUnder "" // Red
#define EthGreenUnder "" // Green
#define EthOrangeUnder "" // Yellow
#define EthNavyUnder "" // Blue
#define EthVioletUnder "" // Purple
#define EthTealUnder "" // Cyan
#else #else

21
libethash-cl/ethash_cl_miner.cpp

@ -85,6 +85,27 @@ std::string ethash_cl_miner::platform_info(unsigned _platformId, unsigned _devic
return "{ \"platform\": \"" + platforms[platform_num].getInfo<CL_PLATFORM_NAME>() + "\", \"device\": \"" + device.getInfo<CL_DEVICE_NAME>() + "\", \"version\": \"" + device_version + "\" }"; return "{ \"platform\": \"" + platforms[platform_num].getInfo<CL_PLATFORM_NAME>() + "\", \"device\": \"" + device.getInfo<CL_DEVICE_NAME>() + "\", \"version\": \"" + device_version + "\" }";
} }
unsigned ethash_cl_miner::get_num_devices(unsigned _platformId)
{
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
if (platforms.empty())
{
debugf("No OpenCL platforms found.\n");
return 0;
}
std::vector<cl::Device> devices;
unsigned platform_num = std::min<unsigned>(_platformId, platforms.size() - 1);
platforms[platform_num].getDevices(CL_DEVICE_TYPE_ALL, &devices);
if (devices.empty())
{
debugf("No OpenCL devices found.\n");
return 0;
}
return devices.size();
}
void ethash_cl_miner::finish() void ethash_cl_miner::finish()
{ {
if (m_queue()) if (m_queue())

2
libethash-cl/ethash_cl_miner.h

@ -33,6 +33,8 @@ public:
bool init(ethash_params const& params, std::function<void(void*)> _fillDAG, unsigned workgroup_size = 64, unsigned _platformId = 0, unsigned _deviceId = 0); bool init(ethash_params const& params, std::function<void(void*)> _fillDAG, unsigned workgroup_size = 64, unsigned _platformId = 0, unsigned _deviceId = 0);
static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0); static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0);
static unsigned get_num_devices(unsigned _platformId = 0);
void finish(); void finish();
void hash(uint8_t* ret, uint8_t const* header, uint64_t nonce, unsigned count); void hash(uint8_t* ret, uint8_t const* header, uint64_t nonce, unsigned count);

13
libethcore/Ethash.cpp

@ -121,6 +121,8 @@ bool Ethash::verify(BlockInfo const& _header)
return slow; return slow;
} }
unsigned Ethash::CPUMiner::s_numInstances = 1;
void Ethash::CPUMiner::workLoop() void Ethash::CPUMiner::workLoop()
{ {
auto tid = std::this_thread::get_id(); auto tid = std::this_thread::get_id();
@ -264,10 +266,11 @@ private:
unsigned Ethash::GPUMiner::s_platformId = 0; unsigned Ethash::GPUMiner::s_platformId = 0;
unsigned Ethash::GPUMiner::s_deviceId = 0; unsigned Ethash::GPUMiner::s_deviceId = 0;
unsigned Ethash::GPUMiner::s_numInstances = 1;
Ethash::GPUMiner::GPUMiner(ConstructionInfo const& _ci): Ethash::GPUMiner::GPUMiner(ConstructionInfo const& _ci):
Miner(_ci), Miner(_ci),
Worker("gpuminer"), Worker("gpuminer" + toString(index())),
m_hook(new EthashCLHook(this)) m_hook(new EthashCLHook(this))
{ {
} }
@ -308,7 +311,8 @@ void Ethash::GPUMiner::workLoop()
auto p = EthashAux::params(m_minerSeed); auto p = EthashAux::params(m_minerSeed);
auto cb = [&](void* d) { EthashAux::full(m_minerSeed, bytesRef((byte*)d, p.full_size)); }; auto cb = [&](void* d) { EthashAux::full(m_minerSeed, bytesRef((byte*)d, p.full_size)); };
m_miner->init(p, cb, 32, s_platformId, s_deviceId); unsigned device = instances() > 0 ? index() : s_deviceId;
m_miner->init(p, cb, 32, s_platformId, device);
} }
uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)w.boundary >> 192); uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)w.boundary >> 192);
@ -331,6 +335,11 @@ std::string Ethash::GPUMiner::platformInfo()
return ethash_cl_miner::platform_info(s_platformId, s_deviceId); return ethash_cl_miner::platform_info(s_platformId, s_deviceId);
} }
unsigned Ethash::GPUMiner::getNumDevices()
{
return ethash_cl_miner::get_num_devices(s_platformId);
}
#endif #endif
} }

14
libethcore/Ethash.h

@ -78,17 +78,18 @@ public:
static bool preVerify(BlockInfo const& _header); static bool preVerify(BlockInfo const& _header);
static WorkPackage package(BlockInfo const& _header); static WorkPackage package(BlockInfo const& _header);
static void assignResult(Solution const& _r, BlockInfo& _header) { _header.nonce = _r.nonce; _header.mixHash = _r.mixHash; } static void assignResult(Solution const& _r, BlockInfo& _header) { _header.nonce = _r.nonce; _header.mixHash = _r.mixHash; }
class CPUMiner: public Miner, Worker class CPUMiner: public Miner, Worker
{ {
public: public:
CPUMiner(ConstructionInfo const& _ci): Miner(_ci), Worker("miner" + toString(index())) {} CPUMiner(ConstructionInfo const& _ci): Miner(_ci), Worker("miner" + toString(index())) {}
static unsigned instances() { return std::thread::hardware_concurrency(); } static unsigned instances() { return s_numInstances > 0 ? s_numInstances : std::thread::hardware_concurrency(); }
static std::string platformInfo(); static std::string platformInfo();
static void setDefaultPlatform(unsigned) {} static void setDefaultPlatform(unsigned) {}
static void setDefaultDevice(unsigned) {} static void setDefaultDevice(unsigned) {}
static void setNumInstances(unsigned _instances) { s_numInstances = std::min<unsigned>(_instances, std::thread::hardware_concurrency()); }
protected: protected:
void kickOff() override void kickOff() override
{ {
@ -100,7 +101,7 @@ public:
private: private:
void workLoop() override; void workLoop() override;
static unsigned s_deviceId; static unsigned s_numInstances;
}; };
#if ETH_ETHASHCL || !ETH_TRUE #if ETH_ETHASHCL || !ETH_TRUE
@ -112,11 +113,13 @@ public:
GPUMiner(ConstructionInfo const& _ci); GPUMiner(ConstructionInfo const& _ci);
~GPUMiner(); ~GPUMiner();
static unsigned instances() { return 1; } static unsigned instances() { return s_numInstances > 0 ? s_numInstances : 1; }
static std::string platformInfo(); static std::string platformInfo();
static unsigned getNumDevices();
static void setDefaultPlatform(unsigned _id) { s_platformId = _id; } static void setDefaultPlatform(unsigned _id) { s_platformId = _id; }
static void setDefaultDevice(unsigned _id) { s_deviceId = _id; } static void setDefaultDevice(unsigned _id) { s_deviceId = _id; }
static void setNumInstances(unsigned _instances) { s_numInstances = std::min<unsigned>(_instances, getNumDevices()); }
protected: protected:
void kickOff() override; void kickOff() override;
void pause() override; void pause() override;
@ -133,6 +136,7 @@ public:
h256 m_minerSeed; ///< Last seed in m_miner h256 m_minerSeed; ///< Last seed in m_miner
static unsigned s_platformId; static unsigned s_platformId;
static unsigned s_deviceId; static unsigned s_deviceId;
static unsigned s_numInstances;
}; };
#else #else
using GPUMiner = CPUMiner; using GPUMiner = CPUMiner;

7
libethereum/BlockChain.cpp

@ -48,10 +48,17 @@ namespace js = json_spirit;
#define ETH_CATCH 1 #define ETH_CATCH 1
#define ETH_TIMED_IMPORTS 0 #define ETH_TIMED_IMPORTS 0
#ifdef _WIN32
const char* BlockChainDebug::name() { return EthBlue "8" EthWhite " <>"; }
const char* BlockChainWarn::name() { return EthBlue "8" EthOnRed EthBlackBold " X"; }
const char* BlockChainNote::name() { return EthBlue "8" EthBlue " i"; }
const char* BlockChainChat::name() { return EthBlue "8" EthWhite " o"; }
#else
const char* BlockChainDebug::name() { return EthBlue "" EthWhite ""; } const char* BlockChainDebug::name() { return EthBlue "" EthWhite ""; }
const char* BlockChainWarn::name() { return EthBlue "" EthOnRed EthBlackBold ""; } const char* BlockChainWarn::name() { return EthBlue "" EthOnRed EthBlackBold ""; }
const char* BlockChainNote::name() { return EthBlue "" EthBlue ""; } const char* BlockChainNote::name() { return EthBlue "" EthBlue ""; }
const char* BlockChainChat::name() { return EthBlue "" EthWhite ""; } const char* BlockChainChat::name() { return EthBlue "" EthWhite ""; }
#endif
std::ostream& dev::eth::operator<<(std::ostream& _out, BlockChain const& _bc) std::ostream& dev::eth::operator<<(std::ostream& _out, BlockChain const& _bc)
{ {

4
libethereum/BlockQueue.cpp

@ -29,7 +29,11 @@ using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;
#ifdef _WIN32
const char* BlockQueueChannel::name() { return EthOrange "[]>"; }
#else
const char* BlockQueueChannel::name() { return EthOrange "▣┅▶"; } const char* BlockQueueChannel::name() { return EthOrange "▣┅▶"; }
#endif
ImportResult BlockQueue::import(bytesConstRef _block, BlockChain const& _bc, bool _isOurs) ImportResult BlockQueue::import(bytesConstRef _block, BlockChain const& _bc, bool _isOurs)
{ {

7
libethereum/Client.cpp

@ -124,10 +124,17 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, ActivityReport const& _r)
return _out; return _out;
} }
#ifdef _WIN32
const char* ClientNote::name() { return EthTeal "^" EthBlue " i"; }
const char* ClientChat::name() { return EthTeal "^" EthWhite " o"; }
const char* ClientTrace::name() { return EthTeal "^" EthGray " O"; }
const char* ClientDetail::name() { return EthTeal "^" EthCoal " 0"; }
#else
const char* ClientNote::name() { return EthTeal "" EthBlue ""; } const char* ClientNote::name() { return EthTeal "" EthBlue ""; }
const char* ClientChat::name() { return EthTeal "" EthWhite ""; } const char* ClientChat::name() { return EthTeal "" EthWhite ""; }
const char* ClientTrace::name() { return EthTeal "" EthGray ""; } const char* ClientTrace::name() { return EthTeal "" EthGray ""; }
const char* ClientDetail::name() { return EthTeal "" EthCoal ""; } const char* ClientDetail::name() { return EthTeal "" EthCoal ""; }
#endif
Client::Client(p2p::Host* _extNet, std::string const& _dbPath, WithExisting _forceAction, u256 _networkId): Client::Client(p2p::Host* _extNet, std::string const& _dbPath, WithExisting _forceAction, u256 _networkId):
Worker("eth"), Worker("eth"),

14
libp2p/Common.cpp

@ -34,6 +34,19 @@ bool dev::p2p::NodeIPEndpoint::test_allowLocal = false;
//⊳⊲◀▶■▣▢□▷◁▧▨▩▲◆◉◈◇◎●◍◌○◼☑☒☎☢☣☰☀♽♥♠✩✭❓✔✓✖✕✘✓✔✅⚒⚡⦸⬌∅⁕«««»»»⚙━┅┉▬ //⊳⊲◀▶■▣▢□▷◁▧▨▩▲◆◉◈◇◎●◍◌○◼☑☒☎☢☣☰☀♽♥♠✩✭❓✔✓✖✕✘✓✔✅⚒⚡⦸⬌∅⁕«««»»»⚙━┅┉▬
#ifdef _WIN32
const char* NetWarn::name() { return EthYellow "N" EthRed " X"; }
const char* NetImpolite::name() { return EthYellow "N" EthRed " !"; }
const char* NetNote::name() { return EthYellow "N" EthBlue " i"; }
const char* NetConnect::name() { return EthYellow "N" EthYellow " C"; }
const char* NetMessageSummary::name() { return EthYellow "N" EthWhite " ."; }
const char* NetMessageDetail::name() { return EthYellow "N" EthGray " o"; }
const char* NetTriviaSummary::name() { return EthYellow "N" EthGray " O"; }
const char* NetTriviaDetail::name() { return EthYellow "N" EthCoal " 0"; }
const char* NetAllDetail::name() { return EthYellow "N" EthCoal " A"; }
const char* NetRight::name() { return EthYellow "N" EthGreen "->"; }
const char* NetLeft::name() { return EthYellow "N" EthNavy "<-"; }
#else
const char* NetWarn::name() { return EthYellow "" EthRed ""; } const char* NetWarn::name() { return EthYellow "" EthRed ""; }
const char* NetImpolite::name() { return EthYellow "" EthRed " !"; } const char* NetImpolite::name() { return EthYellow "" EthRed " !"; }
const char* NetNote::name() { return EthYellow "" EthBlue ""; } const char* NetNote::name() { return EthYellow "" EthBlue ""; }
@ -45,6 +58,7 @@ const char* NetTriviaDetail::name() { return EthYellow "⧎" EthCoal " ◍"; }
const char* NetAllDetail::name() { return EthYellow "" EthCoal ""; } const char* NetAllDetail::name() { return EthYellow "" EthCoal ""; }
const char* NetRight::name() { return EthYellow "" EthGreen "▬▶"; } const char* NetRight::name() { return EthYellow "" EthGreen "▬▶"; }
const char* NetLeft::name() { return EthYellow "" EthNavy "◀▬"; } const char* NetLeft::name() { return EthYellow "" EthNavy "◀▬"; }
#endif
bool p2p::isPublicAddress(std::string const& _addressToCheck) bool p2p::isPublicAddress(std::string const& _addressToCheck)
{ {

Loading…
Cancel
Save