Permalink
Browse files

make some variables local instead of global

  • Loading branch information...
1 parent cad5548 commit 42b44b716c5e6c66ef27b46737d0076d77d0400f @KlausT committed Aug 31, 2015
Showing with 362 additions and 390 deletions.
  1. +3 −4 Algo256/blake256.cu
  2. +6 −6 Algo256/keccak256.cu
  3. +46 −49 JHA/jackpotcoin.cu
  4. +5 −5 bitcoin.cu
  5. +8 −8 bitcredit/bitcredit.cu
  6. +23 −24 cuda_nist5.cu
  7. +3 −4 fuguecoin.cpp
  8. +5 −4 groestlcoin.cpp
  9. +16 −18 lyra2/lyra2REv2.cu
  10. +17 −17 myriadgroestl.cpp
  11. +10 −10 neoscrypt/neoscrypt.cu
  12. +9 −8 pentablake.cu
  13. +29 −34 quark/quarkcoin.cu
  14. +21 −22 qubit/deep.cu
  15. +7 −8 qubit/doom.cu
  16. +12 −14 qubit/qubit.cu
  17. +6 −6 skein.cu
  18. +23 −24 x11/fresh.cu
  19. +21 −23 x11/s3.cu
  20. +16 −18 x11/x11.cu
  21. +18 −18 x13/x13.cu
  22. +11 −14 x15/whirlpool.cu
  23. +3 −4 x15/whirlpoolx.cu
  24. +21 −23 x15/x14.cu
  25. +23 −25 x15/x15.cu
View
@@ -500,8 +500,6 @@ void blake256_cpu_setBlock_16(int thr_id, uint32_t *penddata, const uint32_t *mi
}
#endif
-static volatile bool init[MAX_GPUS] = { false };
-
extern int scanhash_blake256(int thr_id, uint32_t *pdata, uint32_t *ptarget,
uint32_t max_nonce, uint32_t *hashes_done, int8_t blakerounds=14)
{
@@ -531,15 +529,16 @@ extern int scanhash_blake256(int thr_id, uint32_t *pdata, uint32_t *ptarget,
pdata[k] = swab32(pdata[k]);
}
- if (!init[thr_id])
+ static THREAD volatile bool init = false;
+ if(!init)
{
CUDA_SAFE_CALL(cudaSetDevice(device_map[thr_id]));
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
CUDA_SAFE_CALL(cudaStreamCreate(&gpustream[thr_id]));
CUDA_SAFE_CALL(cudaMallocHost(&h_resNonce, NBN * sizeof(uint32_t)));
CUDA_SAFE_CALL(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t)));
- init[thr_id] = true;
+ init = true;
}
#if PRECALC64
View
@@ -14,8 +14,6 @@ extern "C"
#include "cuda_helper.h"
-static THREAD uint32_t *h_nounce;
-
extern void keccak256_cpu_init(int thr_id, uint32_t threads);
extern void keccak256_setBlock_80(int thr_id, void *pdata,const void *ptarget);
extern void keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *h_nounce);
@@ -34,12 +32,12 @@ extern "C" void keccak256_hash(void *state, const void *input)
memcpy(state, hash, 32);
}
-static volatile bool init[MAX_GPUS] = { false };
-
extern int scanhash_keccak256(int thr_id, uint32_t *pdata,
uint32_t *ptarget, uint32_t max_nonce,
uint32_t *hashes_done)
{
+ static THREAD uint32_t *h_nounce = nullptr;
+
const uint32_t first_nonce = pdata[19];
uint32_t intensity = (device_sm[device_map[thr_id]] > 500) ? 1 << 28 : 1 << 27;;
uint32_t throughput = device_intensity(device_map[thr_id], __func__, intensity); // 256*4096
@@ -49,15 +47,17 @@ extern int scanhash_keccak256(int thr_id, uint32_t *pdata,
if (opt_benchmark)
ptarget[7] = 0x0002;
- if (!init[thr_id]) {
+ static THREAD volatile bool init = false;
+ if(!init)
+ {
CUDA_SAFE_CALL(cudaSetDevice(device_map[thr_id]));
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
CUDA_SAFE_CALL(cudaStreamCreate(&gpustream[thr_id]));
CUDA_SAFE_CALL(cudaMallocHost(&h_nounce, 2 * sizeof(uint32_t)));
keccak256_cpu_init(thr_id, (int)throughput);
// CUDA_SAFE_CALL(cudaMallocHost(&h_nounce, 2 * sizeof(uint32_t)));
- init[thr_id] = true;
+ init = true;
}
uint32_t endiandata[20];
View
@@ -10,8 +10,6 @@ extern "C"
#include "miner.h"
#include "cuda_helper.h"
-static uint32_t *d_hash[MAX_GPUS];
-
extern void jackpot_keccak512_cpu_init(int thr_id, uint32_t threads);
extern void jackpot_keccak512_cpu_setBlock(int thr_id, void *pdata, size_t inlen);
extern void jackpot_keccak512_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash);
@@ -33,12 +31,6 @@ extern void jackpot_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32
extern uint32_t cuda_check_hash_branch(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_inputHash);
-// Speicher zur Generierung der Noncevektoren für die bedingten Hashes
-static uint32_t *d_jackpotNonces[MAX_GPUS];
-static uint32_t *d_branch1Nonces[MAX_GPUS];
-static uint32_t *d_branch2Nonces[MAX_GPUS];
-static uint32_t *d_branch3Nonces[MAX_GPUS];
-
// Original jackpothash Funktion aus einem miner Quelltext
extern "C" unsigned int jackpothash(void *state, const void *input)
{
@@ -82,8 +74,6 @@ extern "C" unsigned int jackpothash(void *state, const void *input)
return round;
}
-static volatile bool init[MAX_GPUS] = { false };
-
extern int scanhash_jackpot(int thr_id, uint32_t *pdata,
uint32_t *ptarget, uint32_t max_nonce,
uint32_t *hashes_done)
@@ -96,29 +86,36 @@ extern int scanhash_jackpot(int thr_id, uint32_t *pdata,
if (opt_benchmark)
ptarget[7] = 0x000f;
- if (!init[thr_id])
+ static THREAD uint32_t *d_hash = nullptr;
+ static THREAD uint32_t *d_jackpotNonces = nullptr;
+ static THREAD uint32_t *d_branch1Nonces = nullptr;
+ static THREAD uint32_t *d_branch2Nonces = nullptr;
+ static THREAD uint32_t *d_branch3Nonces = nullptr;
+ static THREAD volatile bool init = false;
+
+ if (!init)
{
CUDA_SAFE_CALL(cudaSetDevice(device_map[thr_id]));
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
CUDA_SAFE_CALL(cudaStreamCreate(&gpustream[thr_id]));
get_cuda_arch(&cuda_arch[thr_id]);
- CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], 16 * sizeof(uint32_t) * throughput));
+ CUDA_SAFE_CALL(cudaMalloc(&d_hash, 16 * sizeof(uint32_t) * throughput));
jackpot_keccak512_cpu_init(thr_id, throughput);
jackpot_compactTest_cpu_init(thr_id, throughput);
quark_groestl512_cpu_init(thr_id, throughput);
quark_skein512_cpu_init(thr_id);
cuda_check_cpu_init(thr_id, throughput);
- cudaMalloc(&d_branch1Nonces[thr_id], sizeof(uint32_t)*throughput*2);
- cudaMalloc(&d_branch2Nonces[thr_id], sizeof(uint32_t)*throughput*2);
- cudaMalloc(&d_branch3Nonces[thr_id], sizeof(uint32_t)*throughput*2);
+ cudaMalloc(&d_branch1Nonces, sizeof(uint32_t)*throughput*2);
+ cudaMalloc(&d_branch2Nonces, sizeof(uint32_t)*throughput*2);
+ cudaMalloc(&d_branch3Nonces, sizeof(uint32_t)*throughput*2);
- CUDA_SAFE_CALL(cudaMalloc(&d_jackpotNonces[thr_id], sizeof(uint32_t)*throughput*2));
+ CUDA_SAFE_CALL(cudaMalloc(&d_jackpotNonces, sizeof(uint32_t)*throughput*2));
- init[thr_id] = true;
+ init = true;
}
uint32_t endiandata[22];
@@ -130,74 +127,74 @@ extern int scanhash_jackpot(int thr_id, uint32_t *pdata,
do {
// erstes Keccak512 Hash mit CUDA
- jackpot_keccak512_cpu_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
+ jackpot_keccak512_cpu_hash(thr_id, throughput, pdata[19], d_hash);
uint32_t nrm1, nrm2, nrm3;
// Runde 1 (ohne Gröstl)
- jackpot_compactTest_cpu_hash_64(thr_id, throughput, pdata[19], d_hash[thr_id], NULL,
- d_branch1Nonces[thr_id], &nrm1,
- d_branch3Nonces[thr_id], &nrm3);
+ jackpot_compactTest_cpu_hash_64(thr_id, throughput, pdata[19], d_hash, NULL,
+ d_branch1Nonces, &nrm1,
+ d_branch3Nonces, &nrm3);
// verfolge den skein-pfad weiter
- quark_skein512_cpu_hash_64(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id]);
+ quark_skein512_cpu_hash_64(thr_id, nrm3, pdata[19], d_branch3Nonces, d_hash);
// noch schnell Blake & JH
- jackpot_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash[thr_id], d_branch3Nonces[thr_id],
- d_branch1Nonces[thr_id], &nrm1,
- d_branch2Nonces[thr_id], &nrm2);
+ jackpot_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash, d_branch3Nonces,
+ d_branch1Nonces, &nrm1,
+ d_branch2Nonces, &nrm2);
if (nrm1+nrm2 == nrm3) {
- quark_blake512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces[thr_id], d_hash[thr_id]);
- quark_jh512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces[thr_id], d_hash[thr_id]);
+ quark_blake512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces, d_hash);
+ quark_jh512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces, d_hash);
}
// Runde 3 (komplett)
// jackpotNonces in branch1/2 aufsplitten gemäss if (hash[0] & 0x01)
- jackpot_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash[thr_id], d_branch3Nonces[thr_id],
- d_branch1Nonces[thr_id], &nrm1,
- d_branch2Nonces[thr_id], &nrm2);
+ jackpot_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash, d_branch3Nonces,
+ d_branch1Nonces, &nrm1,
+ d_branch2Nonces, &nrm2);
if (nrm1+nrm2 == nrm3) {
- quark_groestl512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces[thr_id], d_hash[thr_id]);
- quark_skein512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces[thr_id], d_hash[thr_id]);
+ quark_groestl512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces, d_hash);
+ quark_skein512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces, d_hash);
}
// jackpotNonces in branch1/2 aufsplitten gemäss if (hash[0] & 0x01)
- jackpot_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash[thr_id], d_branch3Nonces[thr_id],
- d_branch1Nonces[thr_id], &nrm1,
- d_branch2Nonces[thr_id], &nrm2);
+ jackpot_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash, d_branch3Nonces,
+ d_branch1Nonces, &nrm1,
+ d_branch2Nonces, &nrm2);
if (nrm1+nrm2 == nrm3) {
- quark_blake512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces[thr_id], d_hash[thr_id]);
- quark_jh512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces[thr_id], d_hash[thr_id]);
+ quark_blake512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces, d_hash);
+ quark_jh512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces, d_hash);
}
// Runde 3 (komplett)
// jackpotNonces in branch1/2 aufsplitten gemäss if (hash[0] & 0x01)
- jackpot_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash[thr_id], d_branch3Nonces[thr_id],
- d_branch1Nonces[thr_id], &nrm1,
- d_branch2Nonces[thr_id], &nrm2);
+ jackpot_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash, d_branch3Nonces,
+ d_branch1Nonces, &nrm1,
+ d_branch2Nonces, &nrm2);
if (nrm1+nrm2 == nrm3) {
- quark_groestl512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces[thr_id], d_hash[thr_id]);
- quark_skein512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces[thr_id], d_hash[thr_id]);
+ quark_groestl512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces, d_hash);
+ quark_skein512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces, d_hash);
}
// jackpotNonces in branch1/2 aufsplitten gemäss if (hash[0] & 0x01)
- jackpot_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash[thr_id], d_branch3Nonces[thr_id],
- d_branch1Nonces[thr_id], &nrm1,
- d_branch2Nonces[thr_id], &nrm2);
+ jackpot_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash, d_branch3Nonces,
+ d_branch1Nonces, &nrm1,
+ d_branch2Nonces, &nrm2);
if (nrm1+nrm2 == nrm3) {
- quark_blake512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces[thr_id], d_hash[thr_id]);
- quark_jh512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces[thr_id], d_hash[thr_id]);
+ quark_blake512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces, d_hash);
+ quark_jh512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces, d_hash);
}
- uint32_t foundNonce = cuda_check_hash_branch(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id]);
+ uint32_t foundNonce = cuda_check_hash_branch(thr_id, nrm3, pdata[19], d_branch3Nonces, d_hash);
if(stop_mining) {mining_has_stopped[thr_id] = true; cudaStreamDestroy(gpustream[thr_id]); pthread_exit(nullptr);}
if(foundNonce != 0xffffffff)
{
@@ -211,7 +208,7 @@ extern int scanhash_jackpot(int thr_id, uint32_t *pdata,
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
int res = 1;
- uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], foundNonce);
+ uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash, foundNonce);
*hashes_done = pdata[19] - first_nonce + throughput;
if (secNonce != 0)
{
View
@@ -1,8 +1,6 @@
#include "miner.h"
#include "cuda_helper.h"
-static THREAD uint32_t *h_nounce;
-
extern void bitcoin_cpu_init(int thr_id);
extern void bitcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, const uint32_t *const ms, uint32_t merkle, uint32_t time, uint32_t compacttarget, uint32_t *const h_nounce);
extern void bitcoin_midstate(const uint32_t *data, uint32_t *midstate);
@@ -122,20 +120,22 @@ void bitcoin_hash(uint32_t *output, const uint32_t *data, uint32_t nonce, const
be32enc(&output[7], h + hc[7]);
}
-static volatile bool init[MAX_GPUS] = { false };
int scanhash_bitcoin(int thr_id, uint32_t *pdata,
uint32_t *ptarget, uint32_t max_nonce,
uint32_t *hashes_done)
{
+ static THREAD uint32_t *h_nounce = nullptr;
+
const uint32_t first_nonce = pdata[19];
uint32_t throughput = device_intensity(device_map[thr_id], __func__, 1U << 28);
throughput = min(throughput, (max_nonce - first_nonce)) & 0xfffffc00;
if (opt_benchmark)
ptarget[7] = 0x0005;
- if (!init[thr_id])
+ static THREAD volatile bool init = false;
+ if(!init)
{
CUDA_SAFE_CALL(cudaSetDevice(device_map[thr_id]));
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
@@ -144,7 +144,7 @@ int scanhash_bitcoin(int thr_id, uint32_t *pdata,
CUDA_SAFE_CALL(cudaStreamCreate(&gpustream[thr_id]));
bitcoin_cpu_init(thr_id);
CUDA_SAFE_CALL(cudaMallocHost(&h_nounce, 2 * sizeof(uint32_t)));
- init[thr_id] = true;
+ init = true;
}
uint32_t ms[8];
@@ -6,9 +6,6 @@ extern "C"
#include "miner.h"
#include "cuda_helper.h"
-static uint32_t *d_hash[MAX_GPUS];
-static uint32_t *foundNonce;
-
extern void bitcredit_setBlockTarget(int thr_id, uint32_t * data, const uint32_t * midstate, const void *ptarget);
extern void bitcredit_cpu_init(int thr_id, uint32_t threads, uint32_t* hash);
extern void bitcredit_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *result);
@@ -43,17 +40,20 @@ int scanhash_bitcredit(int thr_id, uint32_t *pdata,
int intensity = 256 * 256 * 64 * 8;
const uint32_t throughput = min(device_intensity(device_map[thr_id], __func__, intensity), (max_nonce - first_nonce)) & 0xfffffc00; // 19=256*256*8;
- static bool init[MAX_GPUS] = { false };
- if(!init[thr_id])
+ static THREAD uint32_t *d_hash = nullptr;
+ static THREAD uint32_t *foundNonce = nullptr;
+
+ static THREAD bool init = false;
+ if(!init)
{
CUDA_SAFE_CALL(cudaSetDevice(device_map[thr_id]));
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
- CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], 8 * sizeof(uint32_t) * throughput));
+ CUDA_SAFE_CALL(cudaMalloc(&d_hash, 8 * sizeof(uint32_t) * throughput));
CUDA_SAFE_CALL(cudaMallocHost(&foundNonce, 2 * sizeof(uint32_t)));
- bitcredit_cpu_init(thr_id, throughput, d_hash[thr_id]);
- init[thr_id] = true;
+ bitcredit_cpu_init(thr_id, throughput, d_hash);
+ init = true;
}
uint32_t endiandata[42];
Oops, something went wrong.

0 comments on commit 42b44b7

Please sign in to comment.