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

Commit c17c532

Browse files
authoredJan 15, 2019
Merge pull request #1808 from jean-m-cyr/cudalogic
Seems to me it's better to overlap host and GPU operations
2 parents ba8a0a2 + 68f0743 commit c17c532

File tree

7 files changed

+32
-46
lines changed

7 files changed

+32
-46
lines changed
 

‎ethminer/main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,6 @@ class MinerCLI
334334
app.add_set(
335335
"--cuda-block-size,--cu-block-size", m_CUSettings.blockSize, {32, 64, 128, 256}, "", true);
336336

337-
app.add_set(
338-
"--cuda-parallel-hash,--cu-parallel-hash", m_CUSettings.parallelHash, {1, 2, 4, 8}, "", true);
339-
340337
string sched = "sync";
341338
app.add_set(
342339
"--cuda-schedule,--cu-schedule", sched, {"auto", "spin", "yield", "sync"}, "", true);

‎libethash-cl/CLMiner.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,11 @@ void CLMiner::workLoop()
401401
m_lastNonce = nonce;
402402
h256 mix;
403403
memcpy(mix.data(), (char*)results.rslt[i].mix, sizeof(results.rslt[i].mix));
404-
auto sol = Solution{
405-
nonce, mix, current, std::chrono::steady_clock::now(), m_index};
406-
407-
cllog << EthWhite << "Job: " << w.header.abridged() << " Sol: "
408-
<< toHex(sol.nonce, HexPrefix::Add) << EthReset;
409-
410-
Farm::f().submitProof(sol);
411404

405+
Farm::f().submitProof(Solution{
406+
nonce, mix, current, std::chrono::steady_clock::now(), m_index});
407+
cllog << EthWhite << "Job: " << current.header.abridged() << " Sol: 0x"
408+
<< toHex(nonce) << EthReset;
412409
}
413410
}
414411
}

‎libethash-cuda/CUDAMiner.cpp

+22-12
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void CUDAMiner::search(
323323
buffer.count = 0;
324324

325325
// Run the batch for this stream
326-
run_ethash_search(m_settings.gridSize, m_settings.blockSize, stream, &buffer, start_nonce, m_settings.parallelHash);
326+
run_ethash_search(m_settings.gridSize, m_settings.blockSize, stream, &buffer, start_nonce);
327327
}
328328

329329
// process stream batches until we get new work.
@@ -362,33 +362,43 @@ void CUDAMiner::search(
362362
volatile Search_results& buffer(*m_search_buf[current_index]);
363363
uint32_t found_count = std::min((unsigned)buffer.count, MAX_SEARCH_RESULTS);
364364

365+
uint32_t gids[MAX_SEARCH_RESULTS];
366+
h256 mixes[MAX_SEARCH_RESULTS];
367+
365368
if (found_count)
366369
{
367370
buffer.count = 0;
368-
uint64_t nonce_base = start_nonce - m_streams_batch_size;
369371

370372
// Extract solution and pass to higer level
371373
// using io_service as dispatcher
372374

373375
for (uint32_t i = 0; i < found_count; i++)
374376
{
375-
h256 mix;
376-
uint64_t nonce = nonce_base + buffer.result[i].gid;
377-
memcpy(mix.data(), (void*)&buffer.result[i].mix, sizeof(buffer.result[i].mix));
378-
auto sol = Solution{nonce, mix, w, std::chrono::steady_clock::now(), m_index};
379-
380-
cudalog << EthWhite << "Job: " << w.header.abridged() << " Sol: "
381-
<< toHex(sol.nonce, HexPrefix::Add) << EthReset;
382-
383-
Farm::f().submitProof(sol);
377+
gids[i] = buffer.result[i].gid;
378+
memcpy(mixes[i].data(), (void*)&buffer.result[i].mix,
379+
sizeof(buffer.result[i].mix));
384380
}
385381
}
386382

387383
// restart the stream on the next batch of nonces
388384
// unless we are done for this round.
389385
if (!done)
390386
run_ethash_search(
391-
m_settings.gridSize, m_settings.blockSize, stream, &buffer, start_nonce, m_settings.parallelHash);
387+
m_settings.gridSize, m_settings.blockSize, stream, &buffer, start_nonce);
388+
389+
if (found_count)
390+
{
391+
uint64_t nonce_base = start_nonce - m_streams_batch_size;
392+
for (uint32_t i = 0; i < found_count; i++)
393+
{
394+
uint64_t nonce = nonce_base + gids[i];
395+
396+
Farm::f().submitProof(
397+
Solution{nonce, mixes[i], w, std::chrono::steady_clock::now(), m_index});
398+
cudalog << EthWhite << "Job: " << w.header.abridged() << " Sol: 0x"
399+
<< toHex(nonce) << EthReset;
400+
}
401+
}
392402
}
393403

394404
// Update the hash rate

‎libethash-cuda/dagger_shuffled.cuh

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
#include "cuda_helper.h"
66

7-
template <uint32_t _PARALLEL_HASH>
7+
#define _PARALLEL_HASH 4
8+
89
DEV_INLINE bool compute_hash(uint64_t nonce, uint2* mix_hash)
910
{
1011
// sha3_512(header .. nonce)

‎libethash-cuda/ethash_cuda_miner_kernel.cu

+3-21
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
#include "dagger_shuffled.cuh"
1818

19-
template <uint32_t _PARALLEL_HASH>
2019
__global__ void ethash_search(volatile Search_results* g_output, uint64_t start_nonce)
2120
{
2221
uint32_t const gid = blockIdx.x * blockDim.x + threadIdx.x;
2322
uint2 mix[4];
24-
if (compute_hash<_PARALLEL_HASH>(start_nonce + gid, mix))
23+
if (compute_hash(start_nonce + gid, mix))
2524
return;
2625
uint32_t index = atomicInc((uint32_t*)&g_output->count, 0xffffffff);
2726
if (index >= MAX_SEARCH_RESULTS)
@@ -38,26 +37,9 @@ __global__ void ethash_search(volatile Search_results* g_output, uint64_t start_
3837
}
3938

4039
void run_ethash_search(uint32_t gridSize, uint32_t blockSize, cudaStream_t stream,
41-
volatile Search_results* g_output, uint64_t start_nonce, uint32_t parallelHash)
40+
volatile Search_results* g_output, uint64_t start_nonce)
4241
{
43-
switch (parallelHash)
44-
{
45-
case 1:
46-
ethash_search<1><<<gridSize, blockSize, 0, stream>>>(g_output, start_nonce);
47-
break;
48-
case 2:
49-
ethash_search<2><<<gridSize, blockSize, 0, stream>>>(g_output, start_nonce);
50-
break;
51-
case 4:
52-
ethash_search<4><<<gridSize, blockSize, 0, stream>>>(g_output, start_nonce);
53-
break;
54-
case 8:
55-
ethash_search<8><<<gridSize, blockSize, 0, stream>>>(g_output, start_nonce);
56-
break;
57-
default:
58-
ethash_search<4><<<gridSize, blockSize, 0, stream>>>(g_output, start_nonce);
59-
break;
60-
}
42+
ethash_search<<<gridSize, blockSize, 0, stream>>>(g_output, start_nonce);
6143
CUDA_SAFE_CALL(cudaGetLastError());
6244
}
6345

‎libethash-cuda/ethash_cuda_miner_kernel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void set_header(hash32_t _header);
6262
void set_target(uint64_t _target);
6363

6464
void run_ethash_search(uint32_t gridSize, uint32_t blockSize, cudaStream_t stream,
65-
volatile Search_results* g_output, uint64_t start_nonce, uint32_t parallelHash);
65+
volatile Search_results* g_output, uint64_t start_nonce);
6666

6767
void ethash_generate_dag(uint64_t dag_size, uint32_t blocks, uint32_t threads, cudaStream_t stream);
6868

‎libethcore/Miner.h

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ struct CUSettings : public MinerSettings
100100
unsigned schedule = 4;
101101
unsigned gridSize = 8192;
102102
unsigned blockSize = 128;
103-
unsigned parallelHash = 4;
104103
};
105104

106105
// Holds settings for OpenCL Miner

0 commit comments

Comments
 (0)
This repository has been archived.