|
| 1 | +extern "C" { |
| 2 | +#include "sph/sph_blake.h" |
| 3 | +#include "sph/sph_bmw.h" |
| 4 | +#include "sph/sph_groestl.h" |
| 5 | +#include "sph/sph_skein.h" |
| 6 | +#include "sph/sph_jh.h" |
| 7 | +#include "sph/sph_keccak.h" |
| 8 | +#include "sph/sph_luffa.h" |
| 9 | +#include "sph/sph_cubehash.h" |
| 10 | +#include "sph/sph_shavite.h" |
| 11 | +#include "sph/sph_simd.h" |
| 12 | +#include "sph/sph_echo.h" |
| 13 | +} |
| 14 | + |
| 15 | +#include "miner.h" |
| 16 | +#include "cuda_helper.h" |
| 17 | +#include "cuda_x11.h" |
| 18 | + |
| 19 | +#include <stdio.h> |
| 20 | +#include <memory.h> |
| 21 | + |
| 22 | +static uint32_t *d_hash[MAX_GPUS]; |
| 23 | + |
| 24 | +// 0X10 CPU Hash |
| 25 | +extern "C" void hash0x10(void *output, const void *input) |
| 26 | +{ |
| 27 | + unsigned char _ALIGN(128) hash[128] = { 0 }; |
| 28 | + |
| 29 | + // blake1-skein4-bmw2-grs3-jh5-luffa7-keccak6-cubehash8-simd10-shavite9-echo11 |
| 30 | + |
| 31 | + sph_blake512_context ctx_blake; |
| 32 | + sph_bmw512_context ctx_bmw; |
| 33 | + sph_groestl512_context ctx_groestl; |
| 34 | + sph_jh512_context ctx_jh; |
| 35 | + sph_keccak512_context ctx_keccak; |
| 36 | + sph_skein512_context ctx_skein; |
| 37 | + sph_luffa512_context ctx_luffa; |
| 38 | + sph_cubehash512_context ctx_cubehash; |
| 39 | + sph_shavite512_context ctx_shavite; |
| 40 | + sph_simd512_context ctx_simd; |
| 41 | + sph_echo512_context ctx_echo; |
| 42 | + |
| 43 | + sph_blake512_init(&ctx_blake); |
| 44 | + sph_blake512 (&ctx_blake, input, 80); |
| 45 | + sph_blake512_close(&ctx_blake, (void*) hash); |
| 46 | + |
| 47 | + sph_skein512_init(&ctx_skein); |
| 48 | + sph_skein512 (&ctx_skein, (const void*) hash, 64); |
| 49 | + sph_skein512_close(&ctx_skein, (void*) hash); |
| 50 | + |
| 51 | + sph_bmw512_init(&ctx_bmw); |
| 52 | + sph_bmw512 (&ctx_bmw, (const void*) hash, 64); |
| 53 | + sph_bmw512_close(&ctx_bmw, (void*) hash); |
| 54 | + |
| 55 | + sph_groestl512_init(&ctx_groestl); |
| 56 | + sph_groestl512 (&ctx_groestl, (const void*) hash, 64); |
| 57 | + sph_groestl512_close(&ctx_groestl, (void*) hash); |
| 58 | + |
| 59 | + sph_jh512_init(&ctx_jh); |
| 60 | + sph_jh512 (&ctx_jh, (const void*) hash, 64); |
| 61 | + sph_jh512_close(&ctx_jh, (void*) hash); |
| 62 | + |
| 63 | + sph_luffa512_init(&ctx_luffa); |
| 64 | + sph_luffa512 (&ctx_luffa, (const void*) hash, 64); |
| 65 | + sph_luffa512_close (&ctx_luffa, (void*) hash); |
| 66 | + |
| 67 | + sph_keccak512_init(&ctx_keccak); |
| 68 | + sph_keccak512 (&ctx_keccak, (const void*) hash, 64); |
| 69 | + sph_keccak512_close(&ctx_keccak, (void*) hash); |
| 70 | + |
| 71 | + sph_cubehash512_init(&ctx_cubehash); |
| 72 | + sph_cubehash512 (&ctx_cubehash, (const void*) hash, 64); |
| 73 | + sph_cubehash512_close(&ctx_cubehash, (void*) hash); |
| 74 | + |
| 75 | + sph_simd512_init(&ctx_simd); |
| 76 | + sph_simd512 (&ctx_simd, (const void*) hash, 64); |
| 77 | + sph_simd512_close(&ctx_simd, (void*) hash); |
| 78 | + |
| 79 | + sph_shavite512_init(&ctx_shavite); |
| 80 | + sph_shavite512 (&ctx_shavite, (const void*) hash, 64); |
| 81 | + sph_shavite512_close(&ctx_shavite, (void*) hash); |
| 82 | + |
| 83 | + sph_echo512_init(&ctx_echo); |
| 84 | + sph_echo512 (&ctx_echo, (const void*) hash, 64); |
| 85 | + sph_echo512_close(&ctx_echo, (void*) hash); |
| 86 | + |
| 87 | + memcpy(output, hash, 32); |
| 88 | +} |
| 89 | + |
| 90 | +//#define _DEBUG |
| 91 | +#define _DEBUG_PREFIX "x11" |
| 92 | +#include "cuda_debug.cuh" |
| 93 | + |
| 94 | +static bool init[MAX_GPUS] = { 0 }; |
| 95 | + |
| 96 | +extern "C" int scanhash_hash0x10(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done) |
| 97 | +{ |
| 98 | + uint32_t *pdata = work->data; |
| 99 | + uint32_t *ptarget = work->target; |
| 100 | + const uint32_t first_nonce = pdata[19]; |
| 101 | + int intensity = (device_sm[device_map[thr_id]] >= 500 && !is_windows()) ? 20 : 19; |
| 102 | + uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity); // 19=256*256*8; |
| 103 | + //if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce); |
| 104 | + |
| 105 | + if (opt_benchmark) |
| 106 | + ptarget[7] = 0x5; |
| 107 | + |
| 108 | + if (!init[thr_id]) |
| 109 | + { |
| 110 | + cudaSetDevice(device_map[thr_id]); |
| 111 | + if (opt_cudaschedule == -1 && gpu_threads == 1) { |
| 112 | + cudaDeviceReset(); |
| 113 | + // reduce cpu usage |
| 114 | + cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); |
| 115 | + CUDA_LOG_ERROR(); |
| 116 | + } |
| 117 | + gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); |
| 118 | + |
| 119 | + quark_blake512_cpu_init(thr_id, throughput); |
| 120 | + quark_skein512_cpu_init(thr_id, throughput); |
| 121 | + quark_bmw512_cpu_init(thr_id, throughput); |
| 122 | + quark_groestl512_cpu_init(thr_id, throughput); |
| 123 | + quark_jh512_cpu_init(thr_id, throughput); |
| 124 | + x11_luffa512_cpu_init(thr_id, throughput); |
| 125 | + quark_keccak512_cpu_init(thr_id, throughput); |
| 126 | + x11_cubehash512_cpu_init(thr_id, throughput); |
| 127 | + if (x11_simd512_cpu_init(thr_id, throughput) != 0) { |
| 128 | + return 0; |
| 129 | + } |
| 130 | + x11_shavite512_cpu_init(thr_id, throughput); |
| 131 | + x11_echo512_cpu_init(thr_id, throughput); |
| 132 | + CUDA_CALL_OR_RET_X(cudaMalloc(&d_hash[thr_id], (size_t) 64 * throughput), 0); |
| 133 | + |
| 134 | + cuda_check_cpu_init(thr_id, throughput); |
| 135 | + |
| 136 | + init[thr_id] = true; |
| 137 | + } |
| 138 | + |
| 139 | + uint32_t endiandata[20]; |
| 140 | + for (int k=0; k < 20; k++) |
| 141 | + be32enc(&endiandata[k], pdata[k]); |
| 142 | + |
| 143 | + quark_blake512_cpu_setBlock_80(thr_id, endiandata); |
| 144 | + cuda_check_cpu_setTarget(ptarget); |
| 145 | + |
| 146 | + do { |
| 147 | + int order = 0; |
| 148 | + |
| 149 | + // Hash with CUDA |
| 150 | + quark_blake512_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id]); order++; |
| 151 | + TRACE("blake :"); |
| 152 | + quark_skein512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++); |
| 153 | + TRACE("skein :"); |
| 154 | + quark_bmw512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++); |
| 155 | + TRACE("bmw :"); |
| 156 | + quark_groestl512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++); |
| 157 | + TRACE("groestl:"); |
| 158 | + quark_jh512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++); |
| 159 | + TRACE("jh512 :"); |
| 160 | + x11_luffa512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++); |
| 161 | + TRACE("luffa+c:"); |
| 162 | + quark_keccak512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++); |
| 163 | + TRACE("keccak :"); |
| 164 | + x11_cubehash512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++); |
| 165 | + TRACE("cubehash :"); |
| 166 | + x11_simd512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++); |
| 167 | + TRACE("simd :"); |
| 168 | + x11_shavite512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++); |
| 169 | + TRACE("shavite:"); |
| 170 | + x11_echo512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++); |
| 171 | + TRACE("echo => "); |
| 172 | + |
| 173 | + *hashes_done = pdata[19] - first_nonce + throughput; |
| 174 | + |
| 175 | + work->nonces[0] = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]); |
| 176 | + if (work->nonces[0] != UINT32_MAX) |
| 177 | + { |
| 178 | + const uint32_t Htarg = ptarget[7]; |
| 179 | + uint32_t _ALIGN(64) vhash[8]; |
| 180 | + be32enc(&endiandata[19], work->nonces[0]); |
| 181 | + hash0x10(vhash, endiandata); |
| 182 | + |
| 183 | + if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) { |
| 184 | + work->valid_nonces = 1; |
| 185 | + work_set_target_ratio(work, vhash); |
| 186 | + work->nonces[1] = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1); |
| 187 | + if (work->nonces[1] != 0) { |
| 188 | + be32enc(&endiandata[19], work->nonces[1]); |
| 189 | + hash0x10(vhash, endiandata); |
| 190 | + bn_set_target_ratio(work, vhash, 1); |
| 191 | + work->valid_nonces++; |
| 192 | + pdata[19] = max(work->nonces[0], work->nonces[1]) + 1; |
| 193 | + } else { |
| 194 | + pdata[19] = work->nonces[0] + 1; // cursor |
| 195 | + } |
| 196 | + return work->valid_nonces; |
| 197 | + } else { |
| 198 | + gpu_increment_reject(thr_id); |
| 199 | + if (!opt_quiet) |
| 200 | + gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]); |
| 201 | + pdata[19] = work->nonces[0] + 1; |
| 202 | + continue; |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + if ((uint64_t) throughput + pdata[19] >= max_nonce) { |
| 207 | + pdata[19] = max_nonce; |
| 208 | + break; |
| 209 | + } |
| 210 | + pdata[19] += throughput; |
| 211 | + |
| 212 | + } while (!work_restart[thr_id].restart); |
| 213 | + |
| 214 | + *hashes_done = pdata[19] - first_nonce; |
| 215 | + return 0; |
| 216 | +} |
| 217 | + |
| 218 | +// cleanup |
| 219 | +extern "C" void free_hash0x10(int thr_id) |
| 220 | +{ |
| 221 | + if (!init[thr_id]) |
| 222 | + return; |
| 223 | + |
| 224 | + cudaThreadSynchronize(); |
| 225 | + |
| 226 | + cudaFree(d_hash[thr_id]); |
| 227 | + |
| 228 | + quark_blake512_cpu_free(thr_id); |
| 229 | + quark_groestl512_cpu_free(thr_id); |
| 230 | + x11_simd512_cpu_free(thr_id); |
| 231 | + |
| 232 | + cuda_check_cpu_free(thr_id); |
| 233 | + init[thr_id] = false; |
| 234 | + |
| 235 | + cudaDeviceSynchronize(); |
| 236 | +} |
0 commit comments