From 020ef4b81132eaa3071f3f49de338debd0ec6dc9 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 8 Jul 2015 21:44:09 +0200 Subject: [PATCH 1/3] ethashcl doesnt depend on ethcore At least not anymore. Moved global constants into ethash_cl_miner class instead of being in Ethash class. --- ethminer/MinerAux.h | 26 ++++++++++++++++++++------ libethash-cl/ethash_cl_miner.cpp | 12 +++++++----- libethash-cl/ethash_cl_miner.h | 8 ++++++++ libethcore/Ethash.cpp | 3 --- libethcore/Ethash.h | 6 ------ 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index d5145b97c..edfd2ad3f 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -40,6 +40,9 @@ #include #include #include +#if ETH_ETHASHCL || !ETH_TRUE +#include +#endif #if ETH_JSONRPC || !ETH_TRUE #include #include @@ -128,6 +131,7 @@ public: cerr << "Bad " << arg << " option: " << argv[i] << endl; BOOST_THROW_EXCEPTION(BadArgument()); } +#if ETH_ETHASHCL || !ETH_TRUE else if (arg == "--cl-global-work" && i + 1 < argc) try { m_globalWorkSizeMultiplier = stol(argv[++i]); @@ -155,6 +159,7 @@ public: cerr << "Bad " << arg << " option: " << argv[i] << endl; BOOST_THROW_EXCEPTION(BadArgument()); } +#endif else if (arg == "--list-devices") m_shouldListDevices = true; else if (arg == "--allow-opencl-cpu") @@ -292,6 +297,7 @@ public: ProofOfWork::CPUMiner::setNumInstances(m_miningThreads); else if (m_minerType == MinerType::GPU) { +#if ETH_ETHASHCL || !ETH_TRUE if (!ProofOfWork::GPUMiner::configureGPU( m_localWorkSize, m_globalWorkSizeMultiplier, @@ -304,6 +310,10 @@ public: )) exit(1); ProofOfWork::GPUMiner::setNumInstances(m_miningThreads); +#else + cerr << "Selected GPU mining without having compiled with -DETHASHCL=1" << endl; + exit(1); +#endif } if (mode == OperationMode::DAGInit) doInitDAG(m_initDAG); @@ -344,10 +354,12 @@ public: << " --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 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 +#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-local-work Set the OpenCL local work size. Default is " << toString(dev::eth::Ethash::defaultLocalWorkSize) << endl - << " --cl-global-work Set the OpenCL global work size as a multiple of the local work size. Default is " << toString(dev::eth::Ethash::defaultGlobalWorkSizeMultiplier) << " * " << toString(dev::eth::Ethash::defaultLocalWorkSize) << endl - << " --cl-ms-per-batch Set the OpenCL target milliseconds per batch (global workgroup size). Default is " << toString(dev::eth::Ethash::defaultMSPerBatch) << ". If 0 is given then no autoadjustment of global work size will happen" << endl + << " --cl-local-work Set the OpenCL local work size. Default is " << toString(ethash_cl_miner::defaultLocalWorkSize) << endl + << " --cl-global-work Set the OpenCL global work size as a multiple of the local work size. Default is " << toString(ethash_cl_miner::defaultGlobalWorkSizeMultiplier) << " * " << toString(ethash_cl_miner::defaultLocalWorkSize) << endl + << " --cl-ms-per-batch Set the OpenCL target milliseconds per batch (global workgroup size). Default is " << toString(ethash_cl_miner::defaultMSPerBatch) << ". If 0 is given then no autoadjustment of global work size will happen" << endl +#endif ; } @@ -536,9 +548,11 @@ private: unsigned m_miningThreads = UINT_MAX; bool m_shouldListDevices = false; bool m_clAllowCPU = false; - unsigned m_globalWorkSizeMultiplier = dev::eth::Ethash::defaultGlobalWorkSizeMultiplier; - unsigned m_localWorkSize = dev::eth::Ethash::defaultLocalWorkSize; - unsigned m_msPerBatch = dev::eth::Ethash::defaultMSPerBatch; +#if ETH_ETHASHCL || !ETH_TRUE + unsigned m_globalWorkSizeMultiplier = ethash_cl_miner::defaultGlobalWorkSizeMultiplier; + unsigned m_localWorkSize = ethash_cl_miner::defaultLocalWorkSize; + unsigned m_msPerBatch = ethash_cl_miner::defaultMSPerBatch; +#endif boost::optional m_currentBlock; // default value is 350MB of GPU memory for other stuff (windows system rendering, e.t.c.) unsigned m_extraGPUMemory = 350000000; diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index 8b8cb0b51..0e5e8a214 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include "ethash_cl_miner.h" #include "ethash_cl_miner_kernel.h" @@ -50,7 +49,10 @@ #undef max using namespace std; -using namespace dev::eth; + +const unsigned ethash_cl_miner::defaultLocalWorkSize = 64; +const unsigned ethash_cl_miner::defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE +const unsigned ethash_cl_miner::defaultMSPerBatch = 0; // TODO: If at any point we can use libdevcore in here then we should switch to using a LogChannel #define ETHCL_LOG(_contents) cout << "[OPENCL]:" << _contents << endl @@ -183,9 +185,9 @@ bool ethash_cl_miner::configureGPU( bool ethash_cl_miner::s_allowCPU = false; unsigned ethash_cl_miner::s_extraRequiredGPUMem; -unsigned ethash_cl_miner::s_msPerBatch = Ethash::defaultMSPerBatch; -unsigned ethash_cl_miner::s_workgroupSize = Ethash::defaultLocalWorkSize; -unsigned ethash_cl_miner::s_initialGlobalWorkSize = Ethash::defaultGlobalWorkSizeMultiplier * Ethash::defaultLocalWorkSize; +unsigned ethash_cl_miner::s_msPerBatch = ethash_cl_miner::defaultMSPerBatch; +unsigned ethash_cl_miner::s_workgroupSize = ethash_cl_miner::defaultLocalWorkSize; +unsigned ethash_cl_miner::s_initialGlobalWorkSize = ethash_cl_miner::defaultGlobalWorkSizeMultiplier * ethash_cl_miner::defaultLocalWorkSize; bool ethash_cl_miner::searchForAllDevices(function _callback) { diff --git a/libethash-cl/ethash_cl_miner.h b/libethash-cl/ethash_cl_miner.h index d1cb53ef9..06e8550b1 100644 --- a/libethash-cl/ethash_cl_miner.h +++ b/libethash-cl/ethash_cl_miner.h @@ -65,6 +65,14 @@ public: void hash_chunk(uint8_t* _ret, uint8_t const* _header, uint64_t _nonce, unsigned _count); void search_chunk(uint8_t const*_header, uint64_t _target, search_hook& _hook); + /* -- default values -- */ + /// Default value of the local work size. Also known as workgroup size. + static const unsigned defaultLocalWorkSize; + /// Default value of the global work size as a multiplier of the local work size + static const unsigned defaultGlobalWorkSizeMultiplier; + /// Default value of the milliseconds per global work size (per batch) + static const unsigned defaultMSPerBatch; + private: static std::vector getDevices(std::vector const& _platforms, unsigned _platformId); diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index d24c8454e..fc0e07f12 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -54,9 +54,6 @@ namespace dev namespace eth { -const unsigned Ethash::defaultLocalWorkSize = 64; -const unsigned Ethash::defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE -const unsigned Ethash::defaultMSPerBatch = 0; const Ethash::WorkPackage Ethash::NullWorkPackage = Ethash::WorkPackage(); std::string Ethash::name() diff --git a/libethcore/Ethash.h b/libethcore/Ethash.h index 804c92984..e9ddf16ca 100644 --- a/libethcore/Ethash.h +++ b/libethcore/Ethash.h @@ -150,12 +150,6 @@ public: #else using GPUMiner = CPUMiner; #endif - /// Default value of the local work size. Also known as workgroup size. - static const unsigned defaultLocalWorkSize; - /// Default value of the global work size as a multiplier of the local work size - static const unsigned defaultGlobalWorkSizeMultiplier; - /// Default value of the milliseconds per global work size (per batch) - static const unsigned defaultMSPerBatch; }; } From 4eeb90e81344bde707d8e8a1cb6309a661ae16d2 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 9 Jul 2015 09:16:47 +0200 Subject: [PATCH 2/3] Style regarding public class constants --- ethminer/MinerAux.h | 12 ++++++------ libethash-cl/ethash_cl_miner.cpp | 12 ++++++------ libethash-cl/ethash_cl_miner.h | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index edfd2ad3f..964a23635 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -356,9 +356,9 @@ public: << " --current-block Let the miner know the current block number at configuration time. Will help determine DAG size and required GPU memory." << endl #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-local-work Set the OpenCL local work size. Default is " << toString(ethash_cl_miner::defaultLocalWorkSize) << endl - << " --cl-global-work Set the OpenCL global work size as a multiple of the local work size. Default is " << toString(ethash_cl_miner::defaultGlobalWorkSizeMultiplier) << " * " << toString(ethash_cl_miner::defaultLocalWorkSize) << endl - << " --cl-ms-per-batch Set the OpenCL target milliseconds per batch (global workgroup size). Default is " << toString(ethash_cl_miner::defaultMSPerBatch) << ". If 0 is given then no autoadjustment of global work size will happen" << endl + << " --cl-local-work Set the OpenCL local work size. Default is " << toString(ethash_cl_miner::c_defaultLocalWorkSize) << endl + << " --cl-global-work Set the OpenCL global work size as a multiple of the local work size. Default is " << toString(ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier) << " * " << toString(ethash_cl_miner::c_defaultLocalWorkSize) << endl + << " --cl-ms-per-batch Set the OpenCL target milliseconds per batch (global workgroup size). Default is " << toString(ethash_cl_miner::c_defaultMSPerBatch) << ". If 0 is given then no autoadjustment of global work size will happen" << endl #endif ; } @@ -549,9 +549,9 @@ private: bool m_shouldListDevices = false; bool m_clAllowCPU = false; #if ETH_ETHASHCL || !ETH_TRUE - unsigned m_globalWorkSizeMultiplier = ethash_cl_miner::defaultGlobalWorkSizeMultiplier; - unsigned m_localWorkSize = ethash_cl_miner::defaultLocalWorkSize; - unsigned m_msPerBatch = ethash_cl_miner::defaultMSPerBatch; + unsigned m_globalWorkSizeMultiplier = ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier; + unsigned m_localWorkSize = ethash_cl_miner::c_defaultLocalWorkSize; + unsigned m_msPerBatch = ethash_cl_miner::c_defaultMSPerBatch; #endif boost::optional m_currentBlock; // default value is 350MB of GPU memory for other stuff (windows system rendering, e.t.c.) diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index 0e5e8a214..44cbf65e9 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -50,9 +50,9 @@ using namespace std; -const unsigned ethash_cl_miner::defaultLocalWorkSize = 64; -const unsigned ethash_cl_miner::defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE -const unsigned ethash_cl_miner::defaultMSPerBatch = 0; +const unsigned ethash_cl_miner::c_defaultLocalWorkSize = 64; +const unsigned ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE +const unsigned ethash_cl_miner::c_defaultMSPerBatch = 0; // TODO: If at any point we can use libdevcore in here then we should switch to using a LogChannel #define ETHCL_LOG(_contents) cout << "[OPENCL]:" << _contents << endl @@ -185,9 +185,9 @@ bool ethash_cl_miner::configureGPU( bool ethash_cl_miner::s_allowCPU = false; unsigned ethash_cl_miner::s_extraRequiredGPUMem; -unsigned ethash_cl_miner::s_msPerBatch = ethash_cl_miner::defaultMSPerBatch; -unsigned ethash_cl_miner::s_workgroupSize = ethash_cl_miner::defaultLocalWorkSize; -unsigned ethash_cl_miner::s_initialGlobalWorkSize = ethash_cl_miner::defaultGlobalWorkSizeMultiplier * ethash_cl_miner::defaultLocalWorkSize; +unsigned ethash_cl_miner::s_msPerBatch = ethash_cl_miner::c_defaultMSPerBatch; +unsigned ethash_cl_miner::s_workgroupSize = ethash_cl_miner::c_defaultLocalWorkSize; +unsigned ethash_cl_miner::s_initialGlobalWorkSize = ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier * ethash_cl_miner::c_defaultLocalWorkSize; bool ethash_cl_miner::searchForAllDevices(function _callback) { diff --git a/libethash-cl/ethash_cl_miner.h b/libethash-cl/ethash_cl_miner.h index 06e8550b1..1dd1ea406 100644 --- a/libethash-cl/ethash_cl_miner.h +++ b/libethash-cl/ethash_cl_miner.h @@ -67,11 +67,11 @@ public: /* -- default values -- */ /// Default value of the local work size. Also known as workgroup size. - static const unsigned defaultLocalWorkSize; + static const unsigned c_defaultLocalWorkSize; /// Default value of the global work size as a multiplier of the local work size - static const unsigned defaultGlobalWorkSizeMultiplier; + static const unsigned c_defaultGlobalWorkSizeMultiplier; /// Default value of the milliseconds per global work size (per batch) - static const unsigned defaultMSPerBatch; + static const unsigned c_defaultMSPerBatch; private: From 35174e2798a7e92a63a6f2eaaf91efc64b0792b5 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 9 Jul 2015 11:36:05 +0200 Subject: [PATCH 3/3] More style: change const location --- libethash-cl/ethash_cl_miner.cpp | 6 +++--- libethash-cl/ethash_cl_miner.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index 44cbf65e9..8e2a7dc4d 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -50,9 +50,9 @@ using namespace std; -const unsigned ethash_cl_miner::c_defaultLocalWorkSize = 64; -const unsigned ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE -const unsigned ethash_cl_miner::c_defaultMSPerBatch = 0; +unsigned const ethash_cl_miner::c_defaultLocalWorkSize = 64; +unsigned const ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE +unsigned const ethash_cl_miner::c_defaultMSPerBatch = 0; // TODO: If at any point we can use libdevcore in here then we should switch to using a LogChannel #define ETHCL_LOG(_contents) cout << "[OPENCL]:" << _contents << endl diff --git a/libethash-cl/ethash_cl_miner.h b/libethash-cl/ethash_cl_miner.h index 1dd1ea406..094541cf9 100644 --- a/libethash-cl/ethash_cl_miner.h +++ b/libethash-cl/ethash_cl_miner.h @@ -67,11 +67,11 @@ public: /* -- default values -- */ /// Default value of the local work size. Also known as workgroup size. - static const unsigned c_defaultLocalWorkSize; + static unsigned const c_defaultLocalWorkSize; /// Default value of the global work size as a multiplier of the local work size - static const unsigned c_defaultGlobalWorkSizeMultiplier; + static unsigned const c_defaultGlobalWorkSizeMultiplier; /// Default value of the milliseconds per global work size (per batch) - static const unsigned c_defaultMSPerBatch; + static unsigned const c_defaultMSPerBatch; private: