#pragma once #define __CL_ENABLE_EXCEPTIONS #define CL_USE_DEPRECATED_OPENCL_2_0_APIS #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-parameter" #include "cl.hpp" #pragma clang diagnostic pop #else #include "cl.hpp" #endif #include #include #include #include class ethash_cl_miner { private: enum { c_maxSearchResults = 63, c_bufferCount = 2, c_hashBatchSize = 1024, c_searchBatchSize = 1024 * 16 }; public: struct search_hook { virtual ~search_hook(); // always a virtual destructor for a class with virtuals. // reports progress, return true to abort virtual bool found(uint64_t const* nonces, uint32_t count) = 0; virtual bool searched(uint64_t start_nonce, uint32_t count) = 0; }; ethash_cl_miner(); ~ethash_cl_miner(); static bool searchForAllDevices(unsigned _platformId, std::function _callback); static bool searchForAllDevices(std::function _callback); static void doForAllDevices(unsigned _platformId, std::function _callback); static void doForAllDevices(std::function _callback); static unsigned getNumPlatforms(); static unsigned getNumDevices(unsigned _platformId = 0); static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0); static void listDevices(); static bool configureGPU( bool _allowCPU, unsigned _extraGPUMemory, boost::optional _currentBlock ); bool init( uint8_t const* _dag, uint64_t _dagSize, unsigned _workgroupSize = 64, unsigned _platformId = 0, unsigned _deviceId = 0 ); void finish(); void search(uint8_t const* _header, uint64_t _target, search_hook& _hook, unsigned _msPerBatch = 100); 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); private: static std::vector getDevices(std::vector const& _platforms, unsigned _platformId); cl::Context m_context; cl::CommandQueue m_queue; cl::Kernel m_hashKernel; cl::Kernel m_searchKernel; unsigned int m_dagChunksCount; std::vector m_dagChunks; cl::Buffer m_header; cl::Buffer m_hashBuffer[c_bufferCount]; cl::Buffer m_searchBuffer[c_bufferCount]; unsigned m_workgroupSize; unsigned m_batchSize = c_searchBatchSize; bool m_openclOnePointOne; /// Allow CPU to appear as an OpenCL device or not. Default is false static bool s_allowCPU; /// GPU memory required for other things, like window rendering e.t.c. /// User can set it via the --cl-extragpu-mem argument. static unsigned s_extraRequiredGPUMem; };