Browse Source

Merge branch 'Genoil-multiple-gpu' into develop

cl-refactor
Gav Wood 10 years ago
parent
commit
2717db6713
  1. 21
      eth/main.cpp
  2. 9
      libdevcore/Log.cpp
  3. 111
      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. 12
      libethcore/Ethash.h
  8. 7
      libethereum/BlockChain.cpp
  9. 4
      libethereum/BlockQueue.cpp
  10. 7
      libethereum/Client.cpp
  11. 14
      libp2p/Common.cpp

21
eth/main.cpp

@ -136,6 +136,7 @@ void help()
<< " -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-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-name <name> Add a name to your client's version string (default: blank)." << endl
<< " -b,--bootstrap Connect to the default Ethereum peerserver." << endl
@ -482,6 +483,7 @@ int main(int argc, char** argv)
MinerType minerType = MinerType::CPU;
unsigned openclPlatform = 0;
unsigned openclDevice = 0;
unsigned miningThreads = UINT_MAX;
/// File name for import/export.
string filename;
@ -850,6 +852,17 @@ int main(int argc, char** argv)
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")
bootstrap = true;
else if (arg == "-f" || arg == "--force-mining")
@ -905,8 +918,16 @@ int main(int argc, char** argv)
if (sessionSecret)
sigKey = KeyPair(sessionSecret);
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
// 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;
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* LeftChannel::name() { return EthNavy "◀▬▬"; }
const char* RightChannel::name() { return EthGreen "▬▬▶"; }
const char* WarnChannel::name() { return EthOnRed EthBlackBold ""; }
const char* NoteChannel::name() { return EthBlue ""; }
const char* DebugChannel::name() { return EthWhite ""; }
#endif
LogOutputStreamBase::LogOutputStreamBase(char const* _id, std::type_info const* _info, unsigned _v, bool _autospacing):
m_autospacing(_autospacing),

111
libdevcore/Terminal.h

@ -7,77 +7,72 @@ namespace con
#ifdef _WIN32
#define EthReset "" // Text Reset
#define EthReset "" // Text Reset
// Regular Colors
#define EthBlack "" // Black
#define EthCoal "" // Black
#define EthGray "" // White
#define EthWhite "" // White
#define EthMaroon "" // Red
#define EthRed "" // Red
#define EthGreen "" // Green
#define EthLime "" // Green
#define EthOrange "" // Yellow
#define EthYellow "" // Yellow
#define EthNavy "" // Blue
#define EthBlue "" // Blue
#define EthViolet "" // Purple
#define EthPurple "" // Purple
#define EthTeal "" // Cyan
#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
#define EthBlackBold "" // Black
#define EthCoalBold "" // Black
#define EthGrayBold "" // White
#define EthWhiteBold "" // White
#define EthMaroonBold "" // Red
#define EthRedBold "" // Red
#define EthGreenBold "" // Green
#define EthLimeBold "" // Green
#define EthOrangeBold "" // Yellow
#define EthYellowBold "" // Yellow
#define EthNavyBold "" // Blue
#define EthBlueBold "" // Blue
#define EthVioletBold "" // Purple
#define EthPurpleBold "" // Purple
#define EthTealBold "" // Cyan
#define EthCyanBold "" // Cyan
// Background
#define EthBlackOn "" // Black
#define EthRedOn "" // Red
#define EthGreenOn "" // Green
#define EthYellowOn "" // Yellow
#define EthBlueOn "" // Blue
#define EthPurpleOn "" // Purple
#define EthCyanOn "" // Cyan
#define EthWhiteOn "" // White
// High Intensity
#define EthCoal "" // Black
#define EthRedI "" // Red
#define EthLime "" // Green
#define EthYellowI "" // Yellow
#define EthBlueI "" // Blue
#define EthPurpleI "" // Purple
#define EthCyanI "" // Cyan
#define EthWhiteI "" // White
// Bold High Intensity
#define EthBlackBI "" // Black
#define EthRedBI "" // Red
#define EthGreenBI "" // Green
#define EthYellowBI "" // Yellow
#define EthBlueBI "" // Blue
#define EthPurpleBI "" // Purple
#define EthCyanBI "" // Cyan
#define EthWhiteBI "" // White
// High Intensity backgrounds
#define EthBlackOnI "" // Black
#define EthRedOnI "" // Red
#define EthGreenOnI "" // Green
#define EthYellowOnI "" // Yellow
#define EthBlueOnI "" // Blue
#define EthPurpleOnI "" // Purple
#define EthCyanOnI "" // Cyan
#define EthWhiteOnI "" // White
#define EthOnBlack "" // Black
#define EthOnCoal "" // Black
#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

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 + "\" }";
}
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()
{
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);
static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0);
static unsigned get_num_devices(unsigned _platformId = 0);
void finish();
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;
}
unsigned Ethash::CPUMiner::s_numInstances = 1;
void Ethash::CPUMiner::workLoop()
{
auto tid = std::this_thread::get_id();
@ -264,10 +266,11 @@ private:
unsigned Ethash::GPUMiner::s_platformId = 0;
unsigned Ethash::GPUMiner::s_deviceId = 0;
unsigned Ethash::GPUMiner::s_numInstances = 1;
Ethash::GPUMiner::GPUMiner(ConstructionInfo const& _ci):
Miner(_ci),
Worker("gpuminer"),
Worker("gpuminer" + toString(index())),
m_hook(new EthashCLHook(this))
{
}
@ -308,7 +311,8 @@ void Ethash::GPUMiner::workLoop()
auto p = EthashAux::params(m_minerSeed);
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);
@ -331,6 +335,11 @@ std::string Ethash::GPUMiner::platformInfo()
return ethash_cl_miner::platform_info(s_platformId, s_deviceId);
}
unsigned Ethash::GPUMiner::getNumDevices()
{
return ethash_cl_miner::get_num_devices(s_platformId);
}
#endif
}

12
libethcore/Ethash.h

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

7
libethereum/BlockChain.cpp

@ -48,10 +48,17 @@ namespace js = json_spirit;
#define ETH_CATCH 1
#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* BlockChainWarn::name() { return EthBlue "" EthOnRed EthBlackBold ""; }
const char* BlockChainNote::name() { return EthBlue "" EthBlue ""; }
const char* BlockChainChat::name() { return EthBlue "" EthWhite ""; }
#endif
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::eth;
#ifdef _WIN32
const char* BlockQueueChannel::name() { return EthOrange "[]>"; }
#else
const char* BlockQueueChannel::name() { return EthOrange "▣┅▶"; }
#endif
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;
}
#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* ClientChat::name() { return EthTeal "" EthWhite ""; }
const char* ClientTrace::name() { return EthTeal "" EthGray ""; }
const char* ClientDetail::name() { return EthTeal "" EthCoal ""; }
#endif
Client::Client(p2p::Host* _extNet, std::string const& _dbPath, WithExisting _forceAction, u256 _networkId):
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* NetImpolite::name() { return EthYellow "" EthRed " !"; }
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* NetRight::name() { return EthYellow "" EthGreen "▬▶"; }
const char* NetLeft::name() { return EthYellow "" EthNavy "◀▬"; }
#endif
bool p2p::isPublicAddress(std::string const& _addressToCheck)
{

Loading…
Cancel
Save