From 41c8e69a8f2bceba1af833bd1357f2c752b95299 Mon Sep 17 00:00:00 2001 From: davilizh Date: Tue, 27 Jun 2017 16:50:22 +0800 Subject: [PATCH] Change the code according to Chafast's suggestions in pull request #18. 1) change if..else if..else if to switch. 2)change spaces to tab. 3) add additioanl arg check. 4) delete commented out code. 5) throw any exception to avoid code duplication. --- ethminer/MinerAux.h | 7 ++--- libethash-cuda/dagger_shuffled.cuh | 2 -- libethash-cuda/ethash_cuda_miner_kernel.cu | 34 +++++++++------------- libethash-cuda/ethash_cuda_miner_kernel.h | 2 +- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index 292fd0a93..b0c6b03e8 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -309,14 +309,13 @@ public: } } } - else if (arg == "--cuda-parallel-hash") + else if (arg == "--cuda-parallel-hash" && i + 1 < argc) { try { m_parallelHash = stol(argv[++i]); - if(m_parallelHash == 0 || m_parallelHash>8) + if (m_parallelHash == 0 || m_parallelHash > 8) { - cerr << "Bad " << arg << " option: " << argv[i] << endl; - BOOST_THROW_EXCEPTION(BadArgument()); + throw BadArgument(); } } catch (...) diff --git a/libethash-cuda/dagger_shuffled.cuh b/libethash-cuda/dagger_shuffled.cuh index e841c3d92..4497ad699 100644 --- a/libethash-cuda/dagger_shuffled.cuh +++ b/libethash-cuda/dagger_shuffled.cuh @@ -2,8 +2,6 @@ #include "ethash_cuda_miner_kernel.h" #include "cuda_helper.h" -//#define PARALLEL_HASH 4 - template __device__ __forceinline__ uint64_t compute_hash( uint64_t nonce diff --git a/libethash-cuda/ethash_cuda_miner_kernel.cu b/libethash-cuda/ethash_cuda_miner_kernel.cu index 70dcad9a4..6092f267a 100644 --- a/libethash-cuda/ethash_cuda_miner_kernel.cu +++ b/libethash-cuda/ethash_cuda_miner_kernel.cu @@ -42,29 +42,21 @@ void run_ethash_search( cudaStream_t stream, volatile uint32_t* g_output, uint64_t start_nonce, - uint32_t parallelHash + uint32_t parallelHash ) { - - //printf("parallelHash = %d\n", parallelHash); - if(parallelHash == 1) - ethash_search <1> <<>>(g_output, start_nonce); - else if(parallelHash == 2) - ethash_search <2> <<>>(g_output, start_nonce); - else if(parallelHash == 3) - ethash_search <3> <<>>(g_output, start_nonce); - else if(parallelHash == 4) - ethash_search <4> <<>>(g_output, start_nonce); - else if(parallelHash == 5) - ethash_search <5> <<>>(g_output, start_nonce); - else if(parallelHash == 6) - ethash_search <6> <<>>(g_output, start_nonce); - else if(parallelHash == 7) - ethash_search <7> <<>>(g_output, start_nonce); - else if(parallelHash == 8) - ethash_search <8> <<>>(g_output, start_nonce); - else - ethash_search <1> <<>>(g_output, start_nonce); + switch (parallelHash) + { + case 1: ethash_search <1> <<>>(g_output, start_nonce); break; + case 2: ethash_search <2> <<>>(g_output, start_nonce); break; + case 3: ethash_search <3> <<>>(g_output, start_nonce); break; + case 4: ethash_search <4> <<>>(g_output, start_nonce); break; + case 5: ethash_search <5> <<>>(g_output, start_nonce); break; + case 6: ethash_search <6> <<>>(g_output, start_nonce); break; + case 7: ethash_search <7> <<>>(g_output, start_nonce); break; + case 8: ethash_search <8> <<>>(g_output, start_nonce); break; + default: ethash_search <4> <<>>(g_output, start_nonce); break; + } CUDA_SAFE_CALL(cudaGetLastError()); } diff --git a/libethash-cuda/ethash_cuda_miner_kernel.h b/libethash-cuda/ethash_cuda_miner_kernel.h index 93f83bb45..c219308ff 100644 --- a/libethash-cuda/ethash_cuda_miner_kernel.h +++ b/libethash-cuda/ethash_cuda_miner_kernel.h @@ -53,7 +53,7 @@ void run_ethash_search( cudaStream_t stream, volatile uint32_t* g_output, uint64_t start_nonce, - uint32_t parallelHash + uint32_t parallelHash ); void ethash_generate_dag(