@@ -15,11 +15,10 @@ You should have received a copy of the GNU General Public License
15
15
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16
16
*/
17
17
18
- #undef min
19
- #undef max
20
-
21
18
#include " CUDAMiner.h"
22
19
20
+ #include < ethash/ethash.hpp>
21
+
23
22
using namespace std ;
24
23
using namespace dev ;
25
24
using namespace eth ;
@@ -65,12 +64,8 @@ bool CUDAMiner::init(int epoch)
65
64
66
65
cnote << " Initialising miner " << index ;
67
66
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);
74
69
s_dagLoadIndex++;
75
70
76
71
if (s_dagLoadMode == DAG_LOAD_MODE_SINGLE)
@@ -212,7 +207,6 @@ bool CUDAMiner::configureGPU(
212
207
unsigned _gridSize,
213
208
unsigned _numStreams,
214
209
unsigned _scheduleFlag,
215
- uint64_t _currentBlock,
216
210
unsigned _dagLoadMode,
217
211
unsigned _dagCreateDevice,
218
212
bool _noeval,
@@ -230,7 +224,6 @@ bool CUDAMiner::configureGPU(
230
224
_gridSize,
231
225
_numStreams,
232
226
_scheduleFlag,
233
- _currentBlock,
234
227
_noeval)
235
228
)
236
229
{
@@ -256,7 +249,6 @@ bool CUDAMiner::cuda_configureGPU(
256
249
unsigned _gridSize,
257
250
unsigned _numStreams,
258
251
unsigned _scheduleFlag,
259
- uint64_t _currentBlock,
260
252
bool _noeval
261
253
)
262
254
{
@@ -271,7 +263,8 @@ bool CUDAMiner::cuda_configureGPU(
271
263
cudalog << " Using grid size " << s_gridSize << " , block size " << s_blockSize;
272
264
273
265
// 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 ));
275
268
int devicesCount = static_cast <int >(numDevices);
276
269
for (int i = 0 ; i < devicesCount; i++)
277
270
{
@@ -310,9 +303,7 @@ bool CUDAMiner::s_noeval = false;
310
303
311
304
bool CUDAMiner::cuda_init (
312
305
size_t numDevices,
313
- ethash_light_t _light,
314
- uint8_t const * _lightData,
315
- uint64_t _lightSize,
306
+ int epoch,
316
307
unsigned _deviceId,
317
308
bool _cpyToHost,
318
309
uint8_t * &hostDAG,
@@ -337,15 +328,15 @@ bool CUDAMiner::cuda_init(
337
328
m_search_buf = new volatile search_results *[s_numStreams];
338
329
m_streams = new cudaStream_t[s_numStreams];
339
330
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);
343
336
344
-
345
-
346
337
CUDA_SAFE_CALL (cudaSetDevice (m_device_num));
347
338
cudalog << " Set Device to current" ;
348
- if (dagSize128 != m_dag_size || !m_dag)
339
+ if (dagNumItems != m_dag_size || !m_dag)
349
340
{
350
341
// Check whether the current device has sufficient memory every time we recreate the dag
351
342
if (device_props.totalGlobalMem < dagSize)
@@ -368,19 +359,19 @@ bool CUDAMiner::cuda_init(
368
359
hash64_t * light = m_light[m_device_num];
369
360
370
361
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 ));
373
364
}
374
365
// 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));
376
367
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
379
370
CUDA_SAFE_CALL (cudaMalloc (reinterpret_cast <void **>(&dag), dagSize));
380
371
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)
384
375
{
385
376
// create mining buffers
386
377
cudalog << " Generating mining buffers" ;
@@ -426,7 +417,7 @@ bool CUDAMiner::cuda_init(
426
417
}
427
418
428
419
m_dag = dag;
429
- m_dag_size = dagSize128 ;
420
+ m_dag_size = dagNumItems ;
430
421
return true ;
431
422
}
432
423
catch (runtime_error const &)
0 commit comments