Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit de9dc77

Browse files
committedApr 21, 2018
Use ethash lib in CUDA Miner
1 parent 451fa11 commit de9dc77

File tree

4 files changed

+25
-42
lines changed

4 files changed

+25
-42
lines changed
 

‎ethminer/MinerAux.h

-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,6 @@ class MinerCLI
721721
m_cudaGridSize,
722722
m_numStreams,
723723
m_cudaSchedule,
724-
0,
725724
m_dagLoadMode,
726725
m_dagCreateDevice,
727726
m_cudaNoEval,

‎libethash-cuda/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ file(GLOB sources "*.cpp" "*.cu")
3131
file(GLOB headers "*.h" "*.cuh")
3232

3333
cuda_add_library(ethash-cuda STATIC ${sources} ${headers})
34-
target_link_libraries(ethash-cuda ethcore ethash-legacy)
34+
target_link_libraries(ethash-cuda ethcore ethash::ethash)
3535
target_include_directories(ethash-cuda PUBLIC ${CUDA_INCLUDE_DIRS})
3636
target_include_directories(ethash-cuda PRIVATE .. ${CMAKE_CURRENT_BINARY_DIR})

‎libethash-cuda/CUDAMiner.cpp

+22-31
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ You should have received a copy of the GNU General Public License
1515
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
#undef min
19-
#undef max
20-
2118
#include "CUDAMiner.h"
2219

20+
#include <ethash/ethash.hpp>
21+
2322
using namespace std;
2423
using namespace dev;
2524
using namespace eth;
@@ -65,12 +64,8 @@ bool CUDAMiner::init(int epoch)
6564

6665
cnote << "Initialising miner " << index;
6766

68-
EthashAux::LightType light;
69-
light = EthashAux::light(epoch);
70-
bytesConstRef lightData = light->data();
71-
72-
cuda_init(getNumDevices(), light->light, lightData.data(), lightData.size(),
73-
device, (s_dagLoadMode == DAG_LOAD_MODE_SINGLE), s_dagInHostMemory, s_dagCreateDevice);
67+
cuda_init(getNumDevices(), epoch, device, (s_dagLoadMode == DAG_LOAD_MODE_SINGLE),
68+
s_dagInHostMemory, s_dagCreateDevice);
7469
s_dagLoadIndex++;
7570

7671
if (s_dagLoadMode == DAG_LOAD_MODE_SINGLE)
@@ -212,7 +207,6 @@ bool CUDAMiner::configureGPU(
212207
unsigned _gridSize,
213208
unsigned _numStreams,
214209
unsigned _scheduleFlag,
215-
uint64_t _currentBlock,
216210
unsigned _dagLoadMode,
217211
unsigned _dagCreateDevice,
218212
bool _noeval,
@@ -230,7 +224,6 @@ bool CUDAMiner::configureGPU(
230224
_gridSize,
231225
_numStreams,
232226
_scheduleFlag,
233-
_currentBlock,
234227
_noeval)
235228
)
236229
{
@@ -256,7 +249,6 @@ bool CUDAMiner::cuda_configureGPU(
256249
unsigned _gridSize,
257250
unsigned _numStreams,
258251
unsigned _scheduleFlag,
259-
uint64_t _currentBlock,
260252
bool _noeval
261253
)
262254
{
@@ -271,7 +263,8 @@ bool CUDAMiner::cuda_configureGPU(
271263
cudalog << "Using grid size " << s_gridSize << ", block size " << s_blockSize;
272264

273265
// by default let's only consider the DAG of the first epoch
274-
uint64_t dagSize = ethash_get_datasize(_currentBlock);
266+
const auto dagSize =
267+
ethash::get_full_dataset_size(ethash::calculate_full_dataset_num_items(0));
275268
int devicesCount = static_cast<int>(numDevices);
276269
for (int i = 0; i < devicesCount; i++)
277270
{
@@ -310,9 +303,7 @@ bool CUDAMiner::s_noeval = false;
310303

311304
bool CUDAMiner::cuda_init(
312305
size_t numDevices,
313-
ethash_light_t _light,
314-
uint8_t const* _lightData,
315-
uint64_t _lightSize,
306+
int epoch,
316307
unsigned _deviceId,
317308
bool _cpyToHost,
318309
uint8_t* &hostDAG,
@@ -337,15 +328,15 @@ bool CUDAMiner::cuda_init(
337328
m_search_buf = new volatile search_results *[s_numStreams];
338329
m_streams = new cudaStream_t[s_numStreams];
339330

340-
uint64_t dagSize = ethash_get_datasize(_light->block_number);
341-
uint32_t dagSize128 = (unsigned)(dagSize / ETHASH_MIX_BYTES);
342-
uint32_t lightSize64 = (unsigned)(_lightSize / sizeof(node));
331+
const auto& context = ethash::managed::get_epoch_context(epoch);
332+
const auto lightNumItems = context.light_cache_num_items;
333+
const auto lightSize = ethash::get_light_cache_size(lightNumItems);
334+
const auto dagNumItems = context.full_dataset_num_items;
335+
const auto dagSize = ethash::get_full_dataset_size(dagNumItems);
343336

344-
345-
346337
CUDA_SAFE_CALL(cudaSetDevice(m_device_num));
347338
cudalog << "Set Device to current";
348-
if(dagSize128 != m_dag_size || !m_dag)
339+
if (dagNumItems != m_dag_size || !m_dag)
349340
{
350341
//Check whether the current device has sufficient memory every time we recreate the dag
351342
if (device_props.totalGlobalMem < dagSize)
@@ -368,19 +359,19 @@ bool CUDAMiner::cuda_init(
368359
hash64_t * light = m_light[m_device_num];
369360

370361
if(!light){
371-
cudalog << "Allocating light with size: " << _lightSize;
372-
CUDA_SAFE_CALL(cudaMalloc(reinterpret_cast<void**>(&light), _lightSize));
362+
cudalog << "Allocating light with size: " << lightSize;
363+
CUDA_SAFE_CALL(cudaMalloc(reinterpret_cast<void**>(&light), lightSize));
373364
}
374365
// copy lightData to device
375-
CUDA_SAFE_CALL(cudaMemcpy(reinterpret_cast<void*>(light), _lightData, _lightSize, cudaMemcpyHostToDevice));
366+
CUDA_SAFE_CALL(cudaMemcpy(reinterpret_cast<void*>(light), context.light_cache, lightSize, cudaMemcpyHostToDevice));
376367
m_light[m_device_num] = light;
377-
378-
if(dagSize128 != m_dag_size || !dag) // create buffer for dag
368+
369+
if (dagNumItems != m_dag_size || !dag) // create buffer for dag
379370
CUDA_SAFE_CALL(cudaMalloc(reinterpret_cast<void**>(&dag), dagSize));
380371

381-
set_constants(dag, dagSize128, light, lightSize64); //in ethash_cuda_miner_kernel.cu
382-
383-
if(dagSize128 != m_dag_size || !dag)
372+
set_constants(dag, dagNumItems, light, lightNumItems); //in ethash_cuda_miner_kernel.cu
373+
374+
if (dagNumItems != m_dag_size || !dag)
384375
{
385376
// create mining buffers
386377
cudalog << "Generating mining buffers";
@@ -426,7 +417,7 @@ bool CUDAMiner::cuda_init(
426417
}
427418

428419
m_dag = dag;
429-
m_dag_size = dagSize128;
420+
m_dag_size = dagNumItems;
430421
return true;
431422
}
432423
catch (runtime_error const&)

‎libethash-cuda/CUDAMiner.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
2424
#include <libethcore/EthashAux.h>
2525
#include <libethcore/Miner.h>
2626
#include "ethash_cuda_miner_kernel.h"
27-
#include "libethash/internal.h"
2827

2928
namespace dev
3029
{
@@ -50,7 +49,6 @@ class CUDAMiner: public Miner
5049
unsigned _gridSize,
5150
unsigned _numStreams,
5251
unsigned _scheduleFlag,
53-
uint64_t _currentBlock,
5452
unsigned _dagLoadMode,
5553
unsigned _dagCreateDevice,
5654
bool _noeval,
@@ -65,17 +63,12 @@ class CUDAMiner: public Miner
6563
unsigned _gridSize,
6664
unsigned _numStreams,
6765
unsigned _scheduleFlag,
68-
uint64_t _currentBlock,
6966
bool _noeval
7067
);
7168

72-
static void cuda_setParallelHash(unsigned _parallelHash);
73-
7469
bool cuda_init(
7570
size_t numDevices,
76-
ethash_light_t _light,
77-
uint8_t const* _lightData,
78-
uint64_t _lightSize,
71+
int epoch,
7972
unsigned _deviceId,
8073
bool _cpyToHost,
8174
uint8_t * &hostDAG,
@@ -115,7 +108,7 @@ class CUDAMiner: public Miner
115108
///Constants on GPU
116109
hash128_t* m_dag = nullptr;
117110
std::vector<hash64_t*> m_light;
118-
uint32_t m_dag_size = -1;
111+
int m_dag_size = -1;
119112
uint32_t m_device_num;
120113

121114
volatile search_results** m_search_buf;

0 commit comments

Comments
 (0)
This repository has been archived.